From cfedddeb9ec595d613c6266a838d65de38470db4 Mon Sep 17 00:00:00 2001 From: vran Date: Mon, 21 Feb 2022 21:55:56 +0800 Subject: [PATCH] feat: add checkstyle (#22) --- .../com/databasir/api/DocumentController.java | 9 +- .../com/databasir/api/GroupController.java | 8 +- .../com/databasir/api/LoginController.java | 5 +- .../com/databasir/api/ProjectController.java | 3 +- .../com/databasir/api/SettingController.java | 1 - .../api/advice/DatabasirExceptionAdvice.java | 1 - .../databasir/api/config/SecurityConfig.java | 1 + ...DatabasirAuthenticationSuccessHandler.java | 19 +- .../config/security/DatabasirUserDetails.java | 1 - build.gradle | 11 + .../com/databasir/common/SystemException.java | 2 +- config/checkstyle/checkstyle.xml | 345 ++++++++++++++++++ .../document/service/DocumentService.java | 53 +-- .../data/GroupMemberRoleUpdateRequest.java | 1 - .../domain/group/service/GroupService.java | 5 +- .../converter/ProjectPojoConverter.java | 6 - .../project/service/ProjectService.java | 2 +- .../domain/system/service/SystemService.java | 4 +- .../user/converter/UserResponseConverter.java | 1 - .../domain/user/data/UserLoginResponse.java | 2 + .../core/domain/user/service/UserService.java | 1 + .../PostgresqlDatabaseConnectionFactory.java | 1 - .../converter/JsonConverter.java | 20 +- .../core/infrastructure/mail/MailSender.java | 3 +- dao/build.gradle | 4 +- .../dao/exception/DataNotExistsException.java | 5 +- .../java/com/databasir/dao/impl/BaseDao.java | 26 +- .../com/databasir/dao/impl/DataSourceDao.java | 6 +- .../dao/impl/DataSourcePropertyDao.java | 1 - .../dao/impl/DatabaseDocumentDao.java | 4 +- .../dao/impl/DatabaseDocumentHistoryDao.java | 8 +- .../databasir/dao/impl/DocumentRemarkDao.java | 1 - .../java/com/databasir/dao/impl/GroupDao.java | 1 - .../java/com/databasir/dao/impl/LoginDao.java | 1 - .../com/databasir/dao/impl/ProjectDao.java | 1 - .../dao/impl/ProjectSyncRuleDao.java | 13 +- .../dao/impl/TableColumnDocumentDao.java | 4 +- .../databasir/dao/impl/TableDocumentDao.java | 3 +- .../dao/impl/TableIndexDocumentDao.java | 1 - .../dao/impl/TableTriggerDocumentDao.java | 6 +- .../java/com/databasir/dao/impl/UserDao.java | 1 - .../com/databasir/dao/impl/UserRoleDao.java | 1 - .../core/meta/provider/SqlProvider.java | 5 - .../repository/condition/TableCondition.java | 1 - .../MysqlTableTriggerMetaRepository.java | 40 +- .../impl/jdbc/JdbcColumnMetaRepository.java | 22 +- .../databasir/core/render/RenderConfig.java | 21 +- 47 files changed, 522 insertions(+), 159 deletions(-) create mode 100644 config/checkstyle/checkstyle.xml diff --git a/api/src/main/java/com/databasir/api/DocumentController.java b/api/src/main/java/com/databasir/api/DocumentController.java index b42a307..665a327 100644 --- a/api/src/main/java/com/databasir/api/DocumentController.java +++ b/api/src/main/java/com/databasir/api/DocumentController.java @@ -9,7 +9,6 @@ import com.databasir.core.domain.log.annotation.Operation; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; import org.springframework.http.ContentDisposition; import org.springframework.http.HttpHeaders; @@ -26,6 +25,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.UUID; +import static org.springframework.data.domain.Sort.Direction.DESC; + @RequiredArgsConstructor @Validated @RestController @@ -50,7 +51,8 @@ public class DocumentController { @GetMapping(Routes.Document.LIST_VERSIONS) public JsonData> getVersionsByProjectId(@PathVariable Integer projectId, - @PageableDefault(sort = "id", direction = Sort.Direction.DESC) + @PageableDefault(sort = "id", + direction = DESC) Pageable page) { return JsonData.ok(documentService.getVersionsBySchemaSourceId(projectId, page)); } @@ -60,7 +62,8 @@ public class DocumentController { @RequestParam(required = false) Long version) { String data = documentService.toMarkdown(projectId, version).get(); try { - Path path = Files.writeString(Paths.get(UUID.randomUUID().toString() + ".md"), data, StandardCharsets.UTF_8); + Path path = Files.writeString(Paths.get(UUID.randomUUID().toString() + ".md"), data, + StandardCharsets.UTF_8); HttpHeaders headers = new HttpHeaders(); headers.setContentDisposition(ContentDisposition.attachment() .filename("demo.md", StandardCharsets.UTF_8) diff --git a/api/src/main/java/com/databasir/api/GroupController.java b/api/src/main/java/com/databasir/api/GroupController.java index cff4eb8..1860da3 100644 --- a/api/src/main/java/com/databasir/api/GroupController.java +++ b/api/src/main/java/com/databasir/api/GroupController.java @@ -8,7 +8,6 @@ import com.databasir.core.domain.log.annotation.Operation; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -18,6 +17,8 @@ import javax.validation.Valid; import java.util.Arrays; import java.util.List; +import static org.springframework.data.domain.Sort.Direction.DESC; + @RestController @RequiredArgsConstructor @Validated @@ -46,7 +47,7 @@ public class GroupController { } @GetMapping(Routes.Group.LIST) - public JsonData> list(@PageableDefault(sort = "id", direction = Sort.Direction.DESC) + public JsonData> list(@PageableDefault(sort = "id", direction = DESC) Pageable page, GroupPageCondition condition) { return JsonData.ok(groupService.list(page, condition)); @@ -69,7 +70,8 @@ public class GroupController { @GetMapping(Routes.Group.MEMBERS) public JsonData> listGroupMembers(@PathVariable Integer groupId, - @PageableDefault(sort = "user_role.create_at", direction = Sort.Direction.DESC) + @PageableDefault(sort = "user_role.create_at", + direction = DESC) Pageable pageable, GroupMemberPageCondition condition) { return JsonData.ok(groupService.listGroupMembers(groupId, pageable, condition)); diff --git a/api/src/main/java/com/databasir/api/LoginController.java b/api/src/main/java/com/databasir/api/LoginController.java index 64b1244..bb319d5 100644 --- a/api/src/main/java/com/databasir/api/LoginController.java +++ b/api/src/main/java/com/databasir/api/LoginController.java @@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.util.Objects; @@ -40,8 +39,8 @@ public class LoginController { } @PostMapping(Routes.Login.REFRESH_ACCESS_TOKEN) - public JsonData refreshAccessTokens(@RequestBody @Valid AccessTokenRefreshRequest request, - HttpServletResponse response) { + public JsonData refreshAccessTokens(@RequestBody @Valid + AccessTokenRefreshRequest request) { try { return JsonData.ok(loginService.refreshAccessTokens(request)); } catch (DatabasirException e) { diff --git a/api/src/main/java/com/databasir/api/ProjectController.java b/api/src/main/java/com/databasir/api/ProjectController.java index 3c82a4b..c390f7b 100644 --- a/api/src/main/java/com/databasir/api/ProjectController.java +++ b/api/src/main/java/com/databasir/api/ProjectController.java @@ -26,7 +26,8 @@ public class ProjectController { private final CronExpressionValidator cronExpressionValidator; @PostMapping(Routes.GroupProject.CREATE) - @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#request.groupId, 'GROUP_MEMBER?groupId='+#request.groupId)") + @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#request.groupId, " + + "'GROUP_MEMBER?groupId='+#request.groupId)") @Operation(module = Operation.Modules.PROJECT, name = "创建项目", involvedGroupId = "#request.groupId") diff --git a/api/src/main/java/com/databasir/api/SettingController.java b/api/src/main/java/com/databasir/api/SettingController.java index 910f2a5..4884a17 100644 --- a/api/src/main/java/com/databasir/api/SettingController.java +++ b/api/src/main/java/com/databasir/api/SettingController.java @@ -1,6 +1,5 @@ package com.databasir.api; - import com.databasir.common.JsonData; import com.databasir.core.domain.log.annotation.Operation; import com.databasir.core.domain.system.data.SystemEmailResponse; diff --git a/api/src/main/java/com/databasir/api/advice/DatabasirExceptionAdvice.java b/api/src/main/java/com/databasir/api/advice/DatabasirExceptionAdvice.java index 8893170..f9be04a 100644 --- a/api/src/main/java/com/databasir/api/advice/DatabasirExceptionAdvice.java +++ b/api/src/main/java/com/databasir/api/advice/DatabasirExceptionAdvice.java @@ -1,6 +1,5 @@ package com.databasir.api.advice; - import com.databasir.common.DatabasirException; import com.databasir.common.JsonData; import com.databasir.common.SystemException; diff --git a/api/src/main/java/com/databasir/api/config/SecurityConfig.java b/api/src/main/java/com/databasir/api/config/SecurityConfig.java index c82291c..79d634d 100644 --- a/api/src/main/java/com/databasir/api/config/SecurityConfig.java +++ b/api/src/main/java/com/databasir/api/config/SecurityConfig.java @@ -69,6 +69,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { } @Bean + @SuppressWarnings("checkstyle:all") public PasswordEncoder bCryptPasswordEncoder() { return new BCryptPasswordEncoder(); } diff --git a/api/src/main/java/com/databasir/api/config/security/DatabasirAuthenticationSuccessHandler.java b/api/src/main/java/com/databasir/api/config/security/DatabasirAuthenticationSuccessHandler.java index 220bd73..884601f 100644 --- a/api/src/main/java/com/databasir/api/config/security/DatabasirAuthenticationSuccessHandler.java +++ b/api/src/main/java/com/databasir/api/config/security/DatabasirAuthenticationSuccessHandler.java @@ -33,15 +33,6 @@ public class DatabasirAuthenticationSuccessHandler implements AuthenticationSucc HttpServletResponse response, Authentication authentication) throws IOException, ServletException { DatabasirUserDetails user = (DatabasirUserDetails) authentication.getPrincipal(); - List roles = user.getRoles() - .stream() - .map(ur -> { - UserLoginResponse.RoleResponse data = new UserLoginResponse.RoleResponse(); - data.setRole(ur.getRole()); - data.setGroupId(ur.getGroupId()); - return data; - }) - .collect(Collectors.toList()); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setContentType(MediaType.APPLICATION_JSON_VALUE); UserLoginResponse data = new UserLoginResponse(); @@ -55,6 +46,16 @@ public class DatabasirAuthenticationSuccessHandler implements AuthenticationSucc long expireAt = loginKey.getAccessTokenExpireAt().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); data.setAccessTokenExpireAt(expireAt); data.setRefreshToken(loginKey.getRefreshToken()); + + List roles = user.getRoles() + .stream() + .map(ur -> { + UserLoginResponse.RoleResponse roleResponse = new UserLoginResponse.RoleResponse(); + roleResponse.setRole(ur.getRole()); + roleResponse.setGroupId(ur.getGroupId()); + return roleResponse; + }) + .collect(Collectors.toList()); data.setRoles(roles); objectMapper.writeValue(response.getWriter(), JsonData.ok(data)); } diff --git a/api/src/main/java/com/databasir/api/config/security/DatabasirUserDetails.java b/api/src/main/java/com/databasir/api/config/security/DatabasirUserDetails.java index 8d8be63..f419a3d 100644 --- a/api/src/main/java/com/databasir/api/config/security/DatabasirUserDetails.java +++ b/api/src/main/java/com/databasir/api/config/security/DatabasirUserDetails.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; - @RequiredArgsConstructor public class DatabasirUserDetails implements UserDetails { diff --git a/build.gradle b/build.gradle index 6be041b..78dfd38 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,7 @@ subprojects { apply plugin: 'io.spring.dependency-management' apply plugin: 'org.springframework.boot' apply plugin: 'nu.studer.jooq' + apply plugin: 'checkstyle' group 'com.databasir' version '1.0.0' @@ -51,6 +52,16 @@ subprojects { test { useJUnitPlatform() } + + tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + } + + checkstyle { + toolVersion = '8.42' + ignoreFailures = false + maxWarnings = 0 + } } diff --git a/common/src/main/java/com/databasir/common/SystemException.java b/common/src/main/java/com/databasir/common/SystemException.java index 678a1c8..f7381b5 100644 --- a/common/src/main/java/com/databasir/common/SystemException.java +++ b/common/src/main/java/com/databasir/common/SystemException.java @@ -1,6 +1,6 @@ package com.databasir.common; -public class SystemException extends RuntimeException{ +public class SystemException extends RuntimeException { private static final String MSG_INTERNAL_SERVER_ERROR = "服务器开小差了,请稍后再试"; diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..37e5f67 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java b/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java index 1c48a26..9c42979 100644 --- a/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java +++ b/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java @@ -121,10 +121,11 @@ public class DocumentService { Integer currentDatabaseDocumentId = databaseDocumentId; if (databaseDocumentId == null) { - currentDatabaseDocumentId = - databaseDocumentDao.insertAndReturnId(documentPojoConverter.toDatabasePojo(projectId, meta, 1L)); + var pojo = documentPojoConverter.toDatabasePojo(projectId, meta, 1L); + currentDatabaseDocumentId = databaseDocumentDao.insertAndReturnId(pojo); } else { - databaseDocumentDao.update(documentPojoConverter.toDatabasePojo(projectId, meta, databaseDocumentId, version)); + var pojo = documentPojoConverter.toDatabasePojo(projectId, meta, databaseDocumentId, version); + databaseDocumentDao.update(pojo); } final Integer docId = currentDatabaseDocumentId; @@ -132,11 +133,14 @@ public class DocumentService { TableDocumentPojo tableMeta = documentPojoConverter.toTablePojo(docId, table); Integer tableMetaId = tableDocumentDao.insertAndReturnId(tableMeta); - List tableColumnMetas = documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns()); + List tableColumnMetas = + documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns()); tableColumnDocumentDao.batchInsert(tableColumnMetas); - List tableIndexMetas = documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes()); + List tableIndexMetas = + documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes()); tableIndexDocumentDao.batchInsert(tableIndexMetas); - List tableTriggerMetas = documentPojoConverter.toTriggerPojo(docId, tableMetaId, table.getTriggers()); + List tableTriggerMetas = + documentPojoConverter.toTriggerPojo(docId, tableMetaId, table.getTriggers()); tableTriggerDocumentDao.batchInsert(tableTriggerMetas); }); log.info("save new meta info success"); @@ -147,21 +151,25 @@ public class DocumentService { return databaseDocumentDao.selectOptionalByProjectId(projectId) .map(document -> { Integer id = document.getId(); - List tables = tableDocumentDao.selectByDatabaseDocumentId(id); - List columns = tableColumnDocumentDao.selectByDatabaseDocumentId(id); - List indexes = tableIndexDocumentDao.selectByDatabaseMetaId(id); - List triggers = tableTriggerDocumentDao.selectByDatabaseDocumentId(id); + var tables = tableDocumentDao.selectByDatabaseDocumentId(id); + var columns = tableColumnDocumentDao.selectByDatabaseDocumentId(id); + var indexes = tableIndexDocumentDao.selectByDatabaseMetaId(id); + var triggers = tableTriggerDocumentDao.selectByDatabaseDocumentId(id); Map> columnsGroupByTableMetaId = columns.stream() .collect(Collectors.groupingBy(TableColumnDocumentPojo::getTableDocumentId)); Map> indexesGroupByTableMetaId = indexes.stream() .collect(Collectors.groupingBy(TableIndexDocumentPojo::getTableDocumentId)); Map> triggersGroupByTableMetaId = triggers.stream() .collect(Collectors.groupingBy(TableTriggerDocumentPojo::getTableDocumentId)); - List tableDocumentResponseList = tables.stream() + var tableDocumentResponseList = tables.stream() .map(table -> { - List subColumns = columnsGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList()); - List subIndexes = indexesGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList()); - List subTriggers = triggersGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList()); + Integer tableId = table.getId(); + var subColumns = + columnsGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList()); + var subIndexes = + indexesGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList()); + var subTriggers = + triggersGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList()); return documentResponseConverter.of(table, subColumns, subIndexes, subTriggers); }) .collect(Collectors.toList()); @@ -175,11 +183,12 @@ public class DocumentService { public Page getVersionsBySchemaSourceId(Integer projectId, Pageable page) { return databaseDocumentDao.selectOptionalByProjectId(projectId) - .map(schemaMeta -> databaseDocumentHistoryDao.selectVersionPageByDatabaseDocumentId(page, schemaMeta.getId()) - .map(history -> DatabaseDocumentVersionResponse.builder() - .version(history.getVersion()) - .createAt(history.getCreateAt()) - .build())) + .map(schemaMeta -> + databaseDocumentHistoryDao.selectVersionPageByDatabaseDocumentId(page, schemaMeta.getId()) + .map(history -> DatabaseDocumentVersionResponse.builder() + .version(history.getVersion()) + .createAt(history.getCreateAt()) + .build())) .orElseGet(Page::empty); } @@ -193,11 +202,13 @@ public class DocumentService { List> overviewContent = new ArrayList<>(); for (int i = 0; i < doc.getTables().size(); i++) { DatabaseDocumentResponse.TableDocumentResponse table = doc.getTables().get(i); - overviewContent.add(List.of((i + 1) + "", table.getName(), table.getType(), table.getComment())); + overviewContent.add(List.of((i + 1) + "", table.getName(), table.getType(), + table.getComment())); } builder.table(List.of("", "表名", "类型", "备注"), overviewContent); - Function columnDefaultValueMapping = column -> { + Function + columnDefaultValueMapping = column -> { if (Objects.equals(column.getNullable(), "YES")) { return Objects.requireNonNullElse(column.getDefaultValue(), "null"); } else { diff --git a/core/src/main/java/com/databasir/core/domain/group/data/GroupMemberRoleUpdateRequest.java b/core/src/main/java/com/databasir/core/domain/group/data/GroupMemberRoleUpdateRequest.java index 46f43df..da25421 100644 --- a/core/src/main/java/com/databasir/core/domain/group/data/GroupMemberRoleUpdateRequest.java +++ b/core/src/main/java/com/databasir/core/domain/group/data/GroupMemberRoleUpdateRequest.java @@ -3,7 +3,6 @@ package com.databasir.core.domain.group.data; import lombok.Data; import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Pattern; @Data public class GroupMemberRoleUpdateRequest { diff --git a/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java b/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java index 8fd84bb..91e3515 100644 --- a/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java +++ b/core/src/main/java/com/databasir/core/domain/group/service/GroupService.java @@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; @Service @@ -88,10 +87,10 @@ public class GroupService { .stream() .map(GroupPojo::getId) .collect(Collectors.toList()); - Map> ownersGroupByGroupId = userRoleDao.selectOwnerNamesByGroupIdIn(groupIdList) + var ownersGroupByGroupId = userRoleDao.selectOwnerNamesByGroupIdIn(groupIdList) .stream() .collect(Collectors.groupingBy(GroupMemberSimplePojo::getGroupId)); - Map projectCountMapByGroupId = projectDao.selectCountByGroupIds(groupIdList) + var projectCountMapByGroupId = projectDao.selectCountByGroupIds(groupIdList) .stream() .collect(Collectors.toMap(GroupProjectCountPojo::getGroupId, v -> v)); return page.map(groupPojo -> { diff --git a/core/src/main/java/com/databasir/core/domain/project/converter/ProjectPojoConverter.java b/core/src/main/java/com/databasir/core/domain/project/converter/ProjectPojoConverter.java index dba4e9d..38f4e3e 100644 --- a/core/src/main/java/com/databasir/core/domain/project/converter/ProjectPojoConverter.java +++ b/core/src/main/java/com/databasir/core/domain/project/converter/ProjectPojoConverter.java @@ -1,20 +1,14 @@ package com.databasir.core.domain.project.converter; import com.databasir.core.domain.project.data.ProjectCreateRequest; -import com.databasir.core.domain.project.data.ProjectDetailResponse; -import com.databasir.core.domain.project.data.ProjectSimpleResponse; import com.databasir.core.domain.project.data.ProjectUpdateRequest; import com.databasir.core.infrastructure.converter.JsonConverter; -import com.databasir.dao.tables.pojos.DataSourcePojo; -import com.databasir.dao.tables.pojos.DataSourcePropertyPojo; import com.databasir.dao.tables.pojos.ProjectPojo; import com.databasir.dao.tables.pojos.ProjectSyncRulePojo; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.ReportingPolicy; -import java.util.List; - @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = JsonConverter.class) public interface ProjectPojoConverter { diff --git a/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java b/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java index 027c58a..d201fa2 100644 --- a/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java +++ b/core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java @@ -119,7 +119,7 @@ public class ProjectService { return Optional.empty(); } SysKeyPojo sysKey = sysKeyDao.selectTopOne(); -// String decryptedPassword = Rsa.decryptFromBase64DataByPrivateKey(password, sysKey.getRsaPrivateKey()); + // String decryptedPassword = Rsa.decryptFromBase64DataByPrivateKey(password, sysKey.getRsaPrivateKey()); return Optional.of(Aes.encryptToBase64Data(password, sysKey.getAesKey())); } diff --git a/core/src/main/java/com/databasir/core/domain/system/service/SystemService.java b/core/src/main/java/com/databasir/core/domain/system/service/SystemService.java index fb74170..967aae4 100644 --- a/core/src/main/java/com/databasir/core/domain/system/service/SystemService.java +++ b/core/src/main/java/com/databasir/core/domain/system/service/SystemService.java @@ -33,6 +33,7 @@ public class SystemService { private final UserRoleDao userRoleDao; + @SuppressWarnings("checkstyle:all") private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); @PostConstruct @@ -83,11 +84,12 @@ public class SystemService { } public void updateEmailSetting(SystemEmailUpdateRequest request) { - Optional idOpt = sysMailDao.selectOptionTopOne().map(SysMailPojo::getId); SysMailPojo sysMailPojo = new SysMailPojo(); sysMailPojo.setSmtpHost(request.getSmtpHost()); sysMailPojo.setSmtpPort(request.getSmtpPort()); sysMailPojo.setUsername(request.getUsername()); + + Optional idOpt = sysMailDao.selectOptionTopOne().map(SysMailPojo::getId); idOpt.ifPresent(sysMailPojo::setId); if (request.getPassword() != null) { // TODO encrypt password ? diff --git a/core/src/main/java/com/databasir/core/domain/user/converter/UserResponseConverter.java b/core/src/main/java/com/databasir/core/domain/user/converter/UserResponseConverter.java index fe225b7..b0b942d 100644 --- a/core/src/main/java/com/databasir/core/domain/user/converter/UserResponseConverter.java +++ b/core/src/main/java/com/databasir/core/domain/user/converter/UserResponseConverter.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; @Mapper(componentModel = "spring") public interface UserResponseConverter { - default UserDetailResponse detailResponse(UserPojo user, List userRoles, Map groupNameMapById) { diff --git a/core/src/main/java/com/databasir/core/domain/user/data/UserLoginResponse.java b/core/src/main/java/com/databasir/core/domain/user/data/UserLoginResponse.java index 2d87871..a5176a8 100644 --- a/core/src/main/java/com/databasir/core/domain/user/data/UserLoginResponse.java +++ b/core/src/main/java/com/databasir/core/domain/user/data/UserLoginResponse.java @@ -25,7 +25,9 @@ public class UserLoginResponse { @Data public static class RoleResponse { + private String role; + private Integer groupId; } } diff --git a/core/src/main/java/com/databasir/core/domain/user/service/UserService.java b/core/src/main/java/com/databasir/core/domain/user/service/UserService.java index aedb69f..5cbff1e 100644 --- a/core/src/main/java/com/databasir/core/domain/user/service/UserService.java +++ b/core/src/main/java/com/databasir/core/domain/user/service/UserService.java @@ -42,6 +42,7 @@ public class UserService { private final MailSender mailSender; + @SuppressWarnings("checkstyle:all") private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); public Page list(Pageable pageable, UserPageCondition condition) { diff --git a/core/src/main/java/com/databasir/core/infrastructure/connection/PostgresqlDatabaseConnectionFactory.java b/core/src/main/java/com/databasir/core/infrastructure/connection/PostgresqlDatabaseConnectionFactory.java index ea7bd16..6d0bca1 100644 --- a/core/src/main/java/com/databasir/core/infrastructure/connection/PostgresqlDatabaseConnectionFactory.java +++ b/core/src/main/java/com/databasir/core/infrastructure/connection/PostgresqlDatabaseConnectionFactory.java @@ -1,6 +1,5 @@ package com.databasir.core.infrastructure.connection; - import org.springframework.stereotype.Component; import java.sql.Connection; diff --git a/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java b/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java index ff6e404..61b4456 100644 --- a/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java +++ b/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java @@ -20,11 +20,6 @@ public class JsonConverter { @Autowired private ObjectMapper objectMapper; - public JSON toJson(List array) { - String json = objToJson(array); - return JSON.valueOf(json); - } - public List fromJson(JSON json) { String data = json.data(); if (data == null) { @@ -40,11 +35,21 @@ public class JsonConverter { } } + public JSON toJson(List array) { + String json = objToJson(array); + return JSON.valueOf(json); + } + public JSON toJson(DatabaseDocumentResponse response) { String json = objToJson(response); return JSON.valueOf(json); } + public JSON toJson(JsonData data) { + String json = objToJson(data); + return JSON.valueOf(json); + } + public DatabaseDocumentResponse of(JSON json) { try { if (json == null) { @@ -67,11 +72,6 @@ public class JsonConverter { } } - public JSON toJson(JsonData data) { - String json = objToJson(data); - return JSON.valueOf(json); - } - public JSON objToJsonData(Object obj) { String json = objToJson(obj); return JSON.valueOf(json); diff --git a/core/src/main/java/com/databasir/core/infrastructure/mail/MailSender.java b/core/src/main/java/com/databasir/core/infrastructure/mail/MailSender.java index 398b3a6..6ac829c 100644 --- a/core/src/main/java/com/databasir/core/infrastructure/mail/MailSender.java +++ b/core/src/main/java/com/databasir/core/infrastructure/mail/MailSender.java @@ -12,12 +12,13 @@ import java.nio.charset.StandardCharsets; public class MailSender { public void send(SysMailPojo mail, String to, String subject, String content) { - JavaMailSender sender = initJavaMailSender(mail); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(mail.getUsername()); message.setTo(to); message.setSubject(subject); message.setText(content); + + JavaMailSender sender = initJavaMailSender(mail); sender.send(message); } diff --git a/dao/build.gradle b/dao/build.gradle index 68f4020..51b9a6b 100644 --- a/dao/build.gradle +++ b/dao/build.gradle @@ -74,4 +74,6 @@ jooq { } } } -} \ No newline at end of file +} + +checkstyleMain.source = "src/main/java" diff --git a/dao/src/main/java/com/databasir/dao/exception/DataNotExistsException.java b/dao/src/main/java/com/databasir/dao/exception/DataNotExistsException.java index 1c3c923..e7820d0 100644 --- a/dao/src/main/java/com/databasir/dao/exception/DataNotExistsException.java +++ b/dao/src/main/java/com/databasir/dao/exception/DataNotExistsException.java @@ -18,7 +18,10 @@ public class DataNotExistsException extends RuntimeException { super(cause); } - protected DataNotExistsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + protected DataNotExistsException(String message, + Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } } diff --git a/dao/src/main/java/com/databasir/dao/impl/BaseDao.java b/dao/src/main/java/com/databasir/dao/impl/BaseDao.java index 0f16889..ab81128 100644 --- a/dao/src/main/java/com/databasir/dao/impl/BaseDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/BaseDao.java @@ -1,6 +1,5 @@ package com.databasir.dao.impl; - import com.databasir.dao.exception.DataNotExistsException; import org.jooq.*; import org.springframework.data.domain.Page; @@ -12,13 +11,13 @@ import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; -public abstract class BaseDao { +public abstract class BaseDao { private final Table table; - private final Class pojoType; + private final Class pojoType; - public BaseDao(Table table, Class pojoType) { + public BaseDao(Table table, Class pojoType) { this.table = table; this.pojoType = pojoType; } @@ -29,7 +28,7 @@ public abstract class BaseDao { return getDslContext().fetchExists(table, identity().eq(id)); } - public T insertAndReturnId(PO pojo) { + public T insertAndReturnId(R pojo) { Record record = getDslContext().newRecord(table, pojo); UpdatableRecord updatableRecord = (UpdatableRecord) record; updatableRecord.store(); @@ -37,7 +36,7 @@ public abstract class BaseDao { return (T) identityType().cast(value); } - public int batchInsert(Collection pojoList) { + public int batchInsert(Collection pojoList) { List> records = pojoList.stream() .map(pojo -> { Record record = getDslContext().newRecord(table, pojo); @@ -53,24 +52,25 @@ public abstract class BaseDao { .execute(); } - public int updateById(PO pojo) { + public int updateById(R pojo) { Record record = getDslContext().newRecord(table, pojo); record.changed(table.getIdentity().getField(), false); return getDslContext().executeUpdate((UpdatableRecord) record); } - public Optional selectOptionalById(T id) { + public Optional selectOptionalById(T id) { return getDslContext() .select(table.fields()).from(table).where(identity().eq(id)) .fetchOptionalInto(pojoType); } - public PO selectById(T id) { + public R selectById(T id) { return selectOptionalById(id) - .orElseThrow(() -> new DataNotExistsException("data not exists in " + table.getName() + " with id = " + id)); + .orElseThrow(() -> + new DataNotExistsException("data not exists in " + table.getName() + " with id = " + id)); } - public List selectInIds(List ids) { + public List selectInIds(List ids) { if (ids == null || ids.isEmpty()) { return Collections.emptyList(); } @@ -80,12 +80,12 @@ public abstract class BaseDao { .fetchInto(pojoType); } - public Page selectByPage(Pageable request, Condition condition) { + public Page selectByPage(Pageable request, Condition condition) { Integer count = getDslContext() .selectCount().from(table).where(condition) .fetchOne(0, int.class); int total = count == null ? 0 : count; - List data = getDslContext() + List data = getDslContext() .selectFrom(table).where(condition) .orderBy(getSortFields(request.getSort())) .offset(request.getOffset()).limit(request.getPageSize()) diff --git a/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java b/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java index 217574a..f8d944e 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java @@ -14,7 +14,6 @@ import java.util.Optional; import static com.databasir.dao.Tables.DATA_SOURCE; - @Repository public class DataSourceDao extends BaseDao { @@ -36,7 +35,10 @@ public class DataSourceDao extends BaseDao { return getDslContext() .select(DATA_SOURCE.fields()).from(DATA_SOURCE).where(DATA_SOURCE.PROJECT_ID.eq(projectId)) .fetchOptionalInto(DataSourcePojo.class) - .orElseThrow(() -> new DataNotExistsException("data not exists in " + table().getName() + " with schemaSourceId = " + projectId)); + .orElseThrow(() -> new DataNotExistsException("data not exists in " + + table().getName() + + " with schemaSourceId = " + + projectId)); } public int updateByProjectId(DataSourcePojo dataSource) { diff --git a/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java b/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java index 99eccc7..56eb5a6 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java @@ -10,7 +10,6 @@ import java.util.List; import static com.databasir.dao.Tables.DATA_SOURCE_PROPERTY; - @Repository public class DataSourcePropertyDao extends BaseDao { diff --git a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java index 6732561..d1dab8d 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java @@ -11,7 +11,6 @@ import java.util.Optional; import static com.databasir.dao.Tables.DATABASE_DOCUMENT; - @Repository public class DatabaseDocumentDao extends BaseDao { @@ -25,7 +24,8 @@ public class DatabaseDocumentDao extends BaseDao { public Optional selectOptionalByProjectId(Integer projectId) { return getDslContext() - .select(DATABASE_DOCUMENT.fields()).from(DATABASE_DOCUMENT).where(DATABASE_DOCUMENT.PROJECT_ID.eq(projectId)) + .select(DATABASE_DOCUMENT.fields()).from(DATABASE_DOCUMENT) + .where(DATABASE_DOCUMENT.PROJECT_ID.eq(projectId)) .fetchOptionalInto(DatabaseDocumentPojo.class); } diff --git a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java index 4fa97d1..186d022 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java @@ -16,7 +16,6 @@ import java.util.Optional; import static com.databasir.dao.Tables.DATABASE_DOCUMENT_HISTORY; - @Repository public class DatabaseDocumentHistoryDao extends BaseDao { @@ -30,11 +29,14 @@ public class DatabaseDocumentHistoryDao extends BaseDao selectOptionalByProjectIdAndVersion(Integer projectId, Long version) { return dslContext - .selectFrom(DATABASE_DOCUMENT_HISTORY).where(DATABASE_DOCUMENT_HISTORY.PROJECT_ID.eq(projectId).and(DATABASE_DOCUMENT_HISTORY.VERSION.eq(version))) + .selectFrom(DATABASE_DOCUMENT_HISTORY) + .where(DATABASE_DOCUMENT_HISTORY.PROJECT_ID.eq(projectId) + .and(DATABASE_DOCUMENT_HISTORY.VERSION.eq(version))) .fetchOptionalInto(DatabaseDocumentHistoryPojo.class); } - public Page selectVersionPageByDatabaseDocumentId(Pageable request, Integer schemaDocumentId) { + public Page selectVersionPageByDatabaseDocumentId(Pageable request, + Integer schemaDocumentId) { Condition condition = DATABASE_DOCUMENT_HISTORY.DATABASE_DOCUMENT_ID.eq(schemaDocumentId); Integer count = getDslContext() .selectCount().from(DATABASE_DOCUMENT_HISTORY).where(condition) diff --git a/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java b/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java index 0e6d958..1a8f640 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java @@ -10,7 +10,6 @@ import java.util.Optional; import static com.databasir.dao.Tables.DOCUMENT_REMARK; - @Repository public class DocumentRemarkDao extends BaseDao { diff --git a/dao/src/main/java/com/databasir/dao/impl/GroupDao.java b/dao/src/main/java/com/databasir/dao/impl/GroupDao.java index b996f7d..e843d17 100644 --- a/dao/src/main/java/com/databasir/dao/impl/GroupDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/GroupDao.java @@ -27,7 +27,6 @@ public class GroupDao extends BaseDao { super(GROUP, GroupPojo.class); } - @Override public int deleteById(T id) { return dslContext diff --git a/dao/src/main/java/com/databasir/dao/impl/LoginDao.java b/dao/src/main/java/com/databasir/dao/impl/LoginDao.java index 972e3a6..fc5f6ed 100644 --- a/dao/src/main/java/com/databasir/dao/impl/LoginDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/LoginDao.java @@ -11,7 +11,6 @@ import java.util.Optional; import static com.databasir.dao.Tables.LOGIN; - @Repository public class LoginDao extends BaseDao { diff --git a/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java b/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java index bf0f9a9..11f7599 100644 --- a/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java @@ -20,7 +20,6 @@ import java.util.stream.Collectors; import static com.databasir.dao.Tables.DATA_SOURCE; import static com.databasir.dao.Tables.PROJECT; - @Repository public class ProjectDao extends BaseDao { diff --git a/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java b/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java index b347d00..ea39486 100644 --- a/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java @@ -28,15 +28,19 @@ public class ProjectSyncRuleDao extends BaseDao { public Optional selectOptionalByProjectId(Integer projectId) { return getDslContext() - .select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE).where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId)) + .select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE) + .where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId)) .fetchOptionalInto(ProjectSyncRulePojo.class); } public ProjectSyncRulePojo selectByProjectId(Integer projectId) { return getDslContext() - .select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE).where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId)) + .select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE) + .where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId)) .fetchOptionalInto(ProjectSyncRulePojo.class) - .orElseThrow(() -> new DataNotExistsException("data not exists in " + table().getName() + " with projectId = " + projectId)); + .orElseThrow(() -> new DataNotExistsException("data not exists in " + + table().getName() + + " with projectId = " + projectId)); } public int updateByProjectId(ProjectSyncRulePojo rule) { @@ -76,7 +80,8 @@ public class ProjectSyncRuleDao extends BaseDao { .fetchInto(ProjectSyncRulePojo.class); } - public List selectByIsAutoSyncAndNotInProjectIds(boolean isAutoSync, List projectIds) { + public List selectByIsAutoSyncAndNotInProjectIds(boolean isAutoSync, + List projectIds) { if (projectIds == null || projectIds.isEmpty()) { return getDslContext() .selectFrom(PROJECT_SYNC_RULE) diff --git a/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java index ce14aaf..f313358 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java @@ -10,7 +10,6 @@ import java.util.List; import static com.databasir.dao.Tables.TABLE_COLUMN_DOCUMENT; - @Repository public class TableColumnDocumentDao extends BaseDao { @@ -31,7 +30,8 @@ public class TableColumnDocumentDao extends BaseDao { public void deleteByDatabaseDocumentId(Integer schemaDocumentId) { getDslContext() - .deleteFrom(TABLE_COLUMN_DOCUMENT).where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) + .deleteFrom(TABLE_COLUMN_DOCUMENT) + .where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) .execute(); } } diff --git a/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java index dbed662..38fd3c8 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java @@ -23,7 +23,8 @@ public class TableDocumentDao extends BaseDao { public List selectByDatabaseDocumentId(Integer schemaDocumentId) { return getDslContext() - .select(TABLE_DOCUMENT.fields()).from(TABLE_DOCUMENT).where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) + .select(TABLE_DOCUMENT.fields()).from(TABLE_DOCUMENT) + .where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) .fetchInto(TableDocumentPojo.class); } diff --git a/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java index 7eeb1f0..d5f8fdf 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java @@ -10,7 +10,6 @@ import java.util.List; import static com.databasir.dao.Tables.TABLE_INDEX_DOCUMENT; - @Repository public class TableIndexDocumentDao extends BaseDao { diff --git a/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java index ee761a8..dd264c0 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java @@ -23,13 +23,15 @@ public class TableTriggerDocumentDao extends BaseDao { public List selectByDatabaseDocumentId(Integer schemaDocumentId) { return getDslContext() - .select(TABLE_TRIGGER_DOCUMENT.fields()).from(TABLE_TRIGGER_DOCUMENT).where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) + .select(TABLE_TRIGGER_DOCUMENT.fields()).from(TABLE_TRIGGER_DOCUMENT) + .where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) .fetchInto(TableTriggerDocumentPojo.class); } public void deleteByDatabaseDocumentId(Integer schemaDocumentId) { getDslContext() - .deleteFrom(TABLE_TRIGGER_DOCUMENT).where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) + .deleteFrom(TABLE_TRIGGER_DOCUMENT) + .where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)) .execute(); } } diff --git a/dao/src/main/java/com/databasir/dao/impl/UserDao.java b/dao/src/main/java/com/databasir/dao/impl/UserDao.java index 0ba5db4..6463630 100644 --- a/dao/src/main/java/com/databasir/dao/impl/UserDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/UserDao.java @@ -20,7 +20,6 @@ import java.util.*; import static com.databasir.dao.Tables.USER; import static com.databasir.dao.Tables.USER_ROLE; - @Repository public class UserDao extends BaseDao { diff --git a/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java b/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java index 606fa37..a3c8899 100644 --- a/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java @@ -16,7 +16,6 @@ import java.util.List; import static com.databasir.dao.Tables.USER; import static com.databasir.dao.Tables.USER_ROLE; - @Repository public class UserRoleDao extends BaseDao { diff --git a/plugin/src/main/java/com/databasir/core/meta/provider/SqlProvider.java b/plugin/src/main/java/com/databasir/core/meta/provider/SqlProvider.java index 16b8a60..d19cc43 100644 --- a/plugin/src/main/java/com/databasir/core/meta/provider/SqlProvider.java +++ b/plugin/src/main/java/com/databasir/core/meta/provider/SqlProvider.java @@ -30,8 +30,6 @@ public interface SqlProvider { * *
* - * @param databaseName - * @return */ default Optional databaseMetaSql(String databaseName) { return Optional.empty(); @@ -54,9 +52,6 @@ public interface SqlProvider { * * * - * @param databaseName - * @param tableName - * @return */ default Optional tableMetaSql(String databaseName, String tableName) { return Optional.empty(); diff --git a/plugin/src/main/java/com/databasir/core/meta/repository/condition/TableCondition.java b/plugin/src/main/java/com/databasir/core/meta/repository/condition/TableCondition.java index 2d601ec..753aa51 100644 --- a/plugin/src/main/java/com/databasir/core/meta/repository/condition/TableCondition.java +++ b/plugin/src/main/java/com/databasir/core/meta/repository/condition/TableCondition.java @@ -20,5 +20,4 @@ public class TableCondition extends Condition { .build(); } - } diff --git a/plugin/src/main/java/com/databasir/core/meta/repository/impl/extension/MysqlTableTriggerMetaRepository.java b/plugin/src/main/java/com/databasir/core/meta/repository/impl/extension/MysqlTableTriggerMetaRepository.java index 6abd039..b29cccb 100644 --- a/plugin/src/main/java/com/databasir/core/meta/repository/impl/extension/MysqlTableTriggerMetaRepository.java +++ b/plugin/src/main/java/com/databasir/core/meta/repository/impl/extension/MysqlTableTriggerMetaRepository.java @@ -18,26 +18,26 @@ public class MysqlTableTriggerMetaRepository implements TriggerMetaRepository { @Override public List selectTriggers(Connection connection, TableCondition condition) { - String sql = "SELECT TRIGGER_CATALOG,\n" + - " TRIGGER_SCHEMA,\n" + - " TRIGGER_NAME,\n" + - " EVENT_MANIPULATION,\n" + - " EVENT_OBJECT_CATALOG,\n" + - " EVENT_OBJECT_SCHEMA,\n" + - " EVENT_OBJECT_TABLE,\n" + - " ACTION_ORDER,\n" + - " ACTION_CONDITION,\n" + - " ACTION_STATEMENT,\n" + - " ACTION_ORIENTATION,\n" + - " ACTION_TIMING,\n" + - " ACTION_REFERENCE_OLD_TABLE,\n" + - " ACTION_REFERENCE_NEW_TABLE,\n" + - " ACTION_REFERENCE_OLD_ROW,\n" + - " ACTION_REFERENCE_NEW_ROW,\n" + - " CREATED,\n" + - " SQL_MODE,\n" + - " DEFINER\n " + - "FROM information_schema.TRIGGERS WHERE EVENT_OBJECT_SCHEMA = ? AND EVENT_OBJECT_TABLE = ?"; + String sql = "SELECT TRIGGER_CATALOG,\n" + + " TRIGGER_SCHEMA,\n" + + " TRIGGER_NAME,\n" + + " EVENT_MANIPULATION,\n" + + " EVENT_OBJECT_CATALOG,\n" + + " EVENT_OBJECT_SCHEMA,\n" + + " EVENT_OBJECT_TABLE,\n" + + " ACTION_ORDER,\n" + + " ACTION_CONDITION,\n" + + " ACTION_STATEMENT,\n" + + " ACTION_ORIENTATION,\n" + + " ACTION_TIMING,\n" + + " ACTION_REFERENCE_OLD_TABLE,\n" + + " ACTION_REFERENCE_NEW_TABLE,\n" + + " ACTION_REFERENCE_OLD_ROW,\n" + + " ACTION_REFERENCE_NEW_ROW,\n" + + " CREATED,\n" + + " SQL_MODE,\n" + + " DEFINER\n " + + "FROM information_schema.TRIGGERS WHERE EVENT_OBJECT_SCHEMA = ? AND EVENT_OBJECT_TABLE = ?"; try { PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setObject(1, condition.getDatabaseName()); diff --git a/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java b/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java index 054307a..3d11acb 100644 --- a/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java +++ b/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java @@ -45,14 +45,6 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository { log.warn("ignore column: " + columnName); } } else { - String columnType = columnsResult.getString("TYPE_NAME"); - Integer columnSize = columnsResult.getInt("COLUMN_SIZE"); - Integer decimalDigits; - if (columnsResult.getObject("DECIMAL_DIGITS") == null) { - decimalDigits = null; - } else { - decimalDigits = columnsResult.getInt("DECIMAL_DIGITS"); - } String defaultValue = columnsResult.getString("COLUMN_DEF"); String isNullable = columnsResult.getString("IS_NULLABLE"); if (isNullable.trim().equals("")) { @@ -62,10 +54,18 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository { if (isAutoIncrement.trim().equals("")) { isAutoIncrement = "UNKNOWN"; } - String columnComment = columnsResult.getString("REMARKS"); if (defaultValue != null && defaultValue.trim().equals("")) { defaultValue = "'" + defaultValue + "'"; } + Integer decimalDigits; + if (columnsResult.getObject("DECIMAL_DIGITS") == null) { + decimalDigits = null; + } else { + decimalDigits = columnsResult.getInt("DECIMAL_DIGITS"); + } + Integer columnSize = columnsResult.getInt("COLUMN_SIZE"); + String columnType = columnsResult.getString("TYPE_NAME"); + String columnComment = columnsResult.getString("REMARKS"); ColumnMeta columnMeta = ColumnMeta.builder() .name(columnName) .type(columnType) @@ -84,7 +84,9 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository { return columnDocs; } - private List selectPrimaryKeyColumns(DatabaseMetaData meta, String catalog, String tableName) throws SQLException { + private List selectPrimaryKeyColumns(DatabaseMetaData meta, + String catalog, + String tableName) throws SQLException { ResultSet result = meta.getPrimaryKeys(catalog, null, tableName); List columns = new ArrayList<>(); while (result.next()) { diff --git a/plugin/src/main/java/com/databasir/core/render/RenderConfig.java b/plugin/src/main/java/com/databasir/core/render/RenderConfig.java index 237c8fa..185f832 100644 --- a/plugin/src/main/java/com/databasir/core/render/RenderConfig.java +++ b/plugin/src/main/java/com/databasir/core/render/RenderConfig.java @@ -19,11 +19,14 @@ public class RenderConfig { private Boolean renderTriggers = true; - private LinkedHashMap> columnTitleAndValueMapping = columnTitleAndValueMapping(); + private LinkedHashMap> columnTitleAndValueMapping = + columnTitleAndValueMapping(); - private LinkedHashMap> indexTitleAndValueMapping = indexTitleAndValueMapping(); + private LinkedHashMap> indexTitleAndValueMapping = + indexTitleAndValueMapping(); - private LinkedHashMap> triggerTitleAndValueMapping = triggerTitleAndValueMapping(); + private LinkedHashMap> triggerTitleAndValueMapping = + triggerTitleAndValueMapping(); protected LinkedHashMap> columnTitleAndValueMapping() { LinkedHashMap> mapping = new LinkedHashMap<>(); @@ -39,18 +42,6 @@ public class RenderConfig { } return type; }); -// mapping.put("Not Null", column -> column.getIsNullable() ? "" : "YES"); -// mapping.put("Auto Increment", column -> column.getIsAutoIncrement() ? "YES" : ""); -// mapping.put("Default", column -> { -// if (column.getDefaultValue() == null) { -// return ""; -// } -// if (column.getDefaultValue().trim().equals("")) { -// return "'" + column.getDefaultValue() + "'"; -// } -// return column.getDefaultValue(); -// }); -// mapping.put("Comment", ColumnMeta::getComment); return mapping; }