Browse Source

feat: add checkstyle (#22)

master
vran 3 years ago
committed by GitHub
parent
commit
cfedddeb9e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      api/src/main/java/com/databasir/api/DocumentController.java
  2. 8
      api/src/main/java/com/databasir/api/GroupController.java
  3. 5
      api/src/main/java/com/databasir/api/LoginController.java
  4. 3
      api/src/main/java/com/databasir/api/ProjectController.java
  5. 1
      api/src/main/java/com/databasir/api/SettingController.java
  6. 1
      api/src/main/java/com/databasir/api/advice/DatabasirExceptionAdvice.java
  7. 1
      api/src/main/java/com/databasir/api/config/SecurityConfig.java
  8. 19
      api/src/main/java/com/databasir/api/config/security/DatabasirAuthenticationSuccessHandler.java
  9. 1
      api/src/main/java/com/databasir/api/config/security/DatabasirUserDetails.java
  10. 11
      build.gradle
  11. 2
      common/src/main/java/com/databasir/common/SystemException.java
  12. 345
      config/checkstyle/checkstyle.xml
  13. 53
      core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java
  14. 1
      core/src/main/java/com/databasir/core/domain/group/data/GroupMemberRoleUpdateRequest.java
  15. 5
      core/src/main/java/com/databasir/core/domain/group/service/GroupService.java
  16. 6
      core/src/main/java/com/databasir/core/domain/project/converter/ProjectPojoConverter.java
  17. 2
      core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java
  18. 4
      core/src/main/java/com/databasir/core/domain/system/service/SystemService.java
  19. 1
      core/src/main/java/com/databasir/core/domain/user/converter/UserResponseConverter.java
  20. 2
      core/src/main/java/com/databasir/core/domain/user/data/UserLoginResponse.java
  21. 1
      core/src/main/java/com/databasir/core/domain/user/service/UserService.java
  22. 1
      core/src/main/java/com/databasir/core/infrastructure/connection/PostgresqlDatabaseConnectionFactory.java
  23. 20
      core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java
  24. 3
      core/src/main/java/com/databasir/core/infrastructure/mail/MailSender.java
  25. 4
      dao/build.gradle
  26. 5
      dao/src/main/java/com/databasir/dao/exception/DataNotExistsException.java
  27. 26
      dao/src/main/java/com/databasir/dao/impl/BaseDao.java
  28. 6
      dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java
  29. 1
      dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java
  30. 4
      dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java
  31. 8
      dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java
  32. 1
      dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java
  33. 1
      dao/src/main/java/com/databasir/dao/impl/GroupDao.java
  34. 1
      dao/src/main/java/com/databasir/dao/impl/LoginDao.java
  35. 1
      dao/src/main/java/com/databasir/dao/impl/ProjectDao.java
  36. 13
      dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java
  37. 4
      dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java
  38. 3
      dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java
  39. 1
      dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java
  40. 6
      dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java
  41. 1
      dao/src/main/java/com/databasir/dao/impl/UserDao.java
  42. 1
      dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java
  43. 5
      plugin/src/main/java/com/databasir/core/meta/provider/SqlProvider.java
  44. 1
      plugin/src/main/java/com/databasir/core/meta/repository/condition/TableCondition.java
  45. 40
      plugin/src/main/java/com/databasir/core/meta/repository/impl/extension/MysqlTableTriggerMetaRepository.java
  46. 22
      plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java
  47. 21
      plugin/src/main/java/com/databasir/core/render/RenderConfig.java

9
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<Page<DatabaseDocumentVersionResponse>> 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)

8
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<Page<GroupPageResponse>> list(@PageableDefault(sort = "id", direction = Sort.Direction.DESC)
public JsonData<Page<GroupPageResponse>> 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<Page<GroupMemberPageResponse>> 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));

5
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<AccessTokenRefreshResponse> refreshAccessTokens(@RequestBody @Valid AccessTokenRefreshRequest request,
HttpServletResponse response) {
public JsonData<AccessTokenRefreshResponse> refreshAccessTokens(@RequestBody @Valid
AccessTokenRefreshRequest request) {
try {
return JsonData.ok(loginService.refreshAccessTokens(request));
} catch (DatabasirException e) {

3
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")

1
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;

1
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;

1
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();
}

19
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<UserLoginResponse.RoleResponse> 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<UserLoginResponse.RoleResponse> 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));
}

1
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 {

11
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
}
}

2
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 = "服务器开小差了,请稍后再试";

345
config/checkstyle/checkstyle.xml

@ -0,0 +1,345 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the Google coding conventions from Google Java Style
that can be found at https://google.github.io/styleguide/javaguide.html
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.org (or in your downloaded distribution).
To completely disable a check, just comment it out or delete it from the file.
To suppress certain violations please review suppression filters.
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.google.suppressionfilter.config}"
default="checkstyle-suppressions.xml"/>
<property name="optional" value="true"/>
</module>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.org/config_whitespace.html -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="SuppressWarningsFilter" />
<module name="TreeWalker">
<module name="SuppressWarningsHolder"/>
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message"
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap">
<property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/>
</module>
<module name="EmptyBlock">
<property name="option" value="TEXT"/>
<property name="tokens"
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="NeedBraces">
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
</module>
<module name="LeftCurly">
<property name="tokens"
value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF,
INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, LITERAL_DEFAULT,
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF,
OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="tokens"
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
LITERAL_DO"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlyAlone"/>
<property name="option" value="alone"/>
<property name="tokens"
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF, INTERFACE_DEF, RECORD_DEF,
COMPACT_CTOR_DEF"/>
</module>
<module name="SuppressionXpathSingleFilter">
<!-- suppresion is required till https://github.com/checkstyle/checkstyle/issues/7541 -->
<property name="id" value="RightCurlyAlone"/>
<property name="query" value="//RCURLY[parent::SLIST[count(./*)=1]
or preceding-sibling::*[last()][self::LCURLY]]"/>
</module>
<module name="WhitespaceAfter">
<property name="tokens"
value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE,
LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<property name="ignoreEnhancedForColon" value="false"/>
<property name="tokens"
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded"
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
</module>
<module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>
<module name="MissingSwitchDefault"/>
<module name="FallThrough"/>
<module name="UpperEll"/>
<module name="ModifierOrder"/>
<module name="EmptyLineSeparator">
<property name="tokens"
value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF,
COMPACT_CTOR_DEF"/>
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapDot"/>
<property name="tokens" value="DOT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapComma"/>
<property name="tokens" value="COMMA"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/259 -->
<property name="id" value="SeparatorWrapEllipsis"/>
<property name="tokens" value="ELLIPSIS"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/258 -->
<property name="id" value="SeparatorWrapArrayDeclarator"/>
<property name="tokens" value="ARRAY_DECLARATOR"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapMethodRef"/>
<property name="tokens" value="METHOD_REF"/>
<property name="option" value="nl"/>
</module>
<module name="PackageName">
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
<message key="name.invalidPattern"
value="Package name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="TypeName">
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
ANNOTATION_DEF, RECORD_DEF"/>
<message key="name.invalidPattern"
value="Type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LambdaParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="CatchParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="PatternVariableName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Pattern variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ClassTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Class type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="RecordComponentName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Record component name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="RecordTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Record type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MethodTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Method type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="InterfaceTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="NoFinalizer"/>
<module name="GenericWhitespace">
<message key="ws.followed"
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
<message key="ws.preceded"
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
<message key="ws.illegalFollow"
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
<message key="ws.notPreceded"
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="3"/>
<property name="tokens"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF,
RECORD_COMPONENT_DEF"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
<module name="MethodParamPad">
<property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF, RECORD_DEF"/>
</module>
<module name="NoWhitespaceBefore">
<property name="tokens"
value="COMMA, SEMI, POST_INC, POST_DEC, DOT,
LABELED_STAT, METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="ParenPad">
<property name="tokens"
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL,
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA,
RECORD_DEF"/>
</module>
<module name="OperatorWrap">
<property name="option" value="NL"/>
<property name="tokens"
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF,
TYPE_EXTENSION_AND "/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationMostCases"/>
<property name="tokens"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF,
RECORD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationVariables"/>
<property name="tokens" value="VARIABLE_DEF"/>
<property name="allowSamelineMultipleAnnotations" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="InvalidJavadocPosition"/>
<module name="JavadocTagContinuationIndentation"/>
<module name="JavadocParagraph"/>
<module name="RequireEmptyLineBeforeBlockTagGroup"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="JavadocMethod">
<property name="accessModifiers" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="SingleLineJavadoc"/>
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected"/>
</module>
<module name="CommentsIndentation">
<property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/>
</module>
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml"/>
<property name="optional" value="true"/>
</module>
<!-- prettyZoo extra rule -->
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<module name="EmptyLineSeparator">
<property name="allowMultipleEmptyLines" value="false"/>
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
</module>
<module name="RegexpSinglelineJava">
<!-- Check for e.printStackTrace() in catch clauses.-->
<property name="format" value="e\.printStackTrace.*"/>
<property name="message" value="使用 log.error() 替代 e.printStackTrace()"/>
<property name="ignoreComments" value="true"/>
</module>
</module>
</module>

53
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<TableColumnDocumentPojo> tableColumnMetas = documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns());
List<TableColumnDocumentPojo> tableColumnMetas =
documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns());
tableColumnDocumentDao.batchInsert(tableColumnMetas);
List<TableIndexDocumentPojo> tableIndexMetas = documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes());
List<TableIndexDocumentPojo> tableIndexMetas =
documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes());
tableIndexDocumentDao.batchInsert(tableIndexMetas);
List<TableTriggerDocumentPojo> tableTriggerMetas = documentPojoConverter.toTriggerPojo(docId, tableMetaId, table.getTriggers());
List<TableTriggerDocumentPojo> 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<TableDocumentPojo> tables = tableDocumentDao.selectByDatabaseDocumentId(id);
List<TableColumnDocumentPojo> columns = tableColumnDocumentDao.selectByDatabaseDocumentId(id);
List<TableIndexDocumentPojo> indexes = tableIndexDocumentDao.selectByDatabaseMetaId(id);
List<TableTriggerDocumentPojo> 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<Integer, List<TableColumnDocumentPojo>> columnsGroupByTableMetaId = columns.stream()
.collect(Collectors.groupingBy(TableColumnDocumentPojo::getTableDocumentId));
Map<Integer, List<TableIndexDocumentPojo>> indexesGroupByTableMetaId = indexes.stream()
.collect(Collectors.groupingBy(TableIndexDocumentPojo::getTableDocumentId));
Map<Integer, List<TableTriggerDocumentPojo>> triggersGroupByTableMetaId = triggers.stream()
.collect(Collectors.groupingBy(TableTriggerDocumentPojo::getTableDocumentId));
List<DatabaseDocumentResponse.TableDocumentResponse> tableDocumentResponseList = tables.stream()
var tableDocumentResponseList = tables.stream()
.map(table -> {
List<TableColumnDocumentPojo> subColumns = columnsGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList());
List<TableIndexDocumentPojo> subIndexes = indexesGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList());
List<TableTriggerDocumentPojo> 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<DatabaseDocumentVersionResponse> 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<List<String>> 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<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse, String> columnDefaultValueMapping = column -> {
Function<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse, String>
columnDefaultValueMapping = column -> {
if (Objects.equals(column.getNullable(), "YES")) {
return Objects.requireNonNullElse(column.getDefaultValue(), "null");
} else {

1
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 {

5
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<Integer, List<GroupMemberSimplePojo>> ownersGroupByGroupId = userRoleDao.selectOwnerNamesByGroupIdIn(groupIdList)
var ownersGroupByGroupId = userRoleDao.selectOwnerNamesByGroupIdIn(groupIdList)
.stream()
.collect(Collectors.groupingBy(GroupMemberSimplePojo::getGroupId));
Map<Integer, GroupProjectCountPojo> projectCountMapByGroupId = projectDao.selectCountByGroupIds(groupIdList)
var projectCountMapByGroupId = projectDao.selectCountByGroupIds(groupIdList)
.stream()
.collect(Collectors.toMap(GroupProjectCountPojo::getGroupId, v -> v));
return page.map(groupPojo -> {

6
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 {

2
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()));
}

4
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<Integer> idOpt = sysMailDao.selectOptionTopOne().map(SysMailPojo::getId);
SysMailPojo sysMailPojo = new SysMailPojo();
sysMailPojo.setSmtpHost(request.getSmtpHost());
sysMailPojo.setSmtpPort(request.getSmtpPort());
sysMailPojo.setUsername(request.getUsername());
Optional<Integer> idOpt = sysMailDao.selectOptionTopOne().map(SysMailPojo::getId);
idOpt.ifPresent(sysMailPojo::setId);
if (request.getPassword() != null) {
// TODO encrypt password ?

1
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<UserRolePojo> userRoles,
Map<Integer, String> groupNameMapById) {

2
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;
}
}

1
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<UserPageResponse> list(Pageable pageable, UserPageCondition condition) {

1
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;

20
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<String> array) {
String json = objToJson(array);
return JSON.valueOf(json);
}
public List<String> fromJson(JSON json) {
String data = json.data();
if (data == null) {
@ -40,11 +35,21 @@ public class JsonConverter {
}
}
public JSON toJson(List<String> 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<Object> 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<Object> data) {
String json = objToJson(data);
return JSON.valueOf(json);
}
public JSON objToJsonData(Object obj) {
String json = objToJson(obj);
return JSON.valueOf(json);

3
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);
}

4
dao/build.gradle

@ -74,4 +74,6 @@ jooq {
}
}
}
}
}
checkstyleMain.source = "src/main/java"

5
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);
}
}

26
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<PO> {
public abstract class BaseDao<R> {
private final Table<?> table;
private final Class<PO> pojoType;
private final Class<R> pojoType;
public BaseDao(Table<?> table, Class<PO> pojoType) {
public BaseDao(Table<?> table, Class<R> pojoType) {
this.table = table;
this.pojoType = pojoType;
}
@ -29,7 +28,7 @@ public abstract class BaseDao<PO> {
return getDslContext().fetchExists(table, identity().eq(id));
}
public <T> T insertAndReturnId(PO pojo) {
public <T> T insertAndReturnId(R pojo) {
Record record = getDslContext().newRecord(table, pojo);
UpdatableRecord<?> updatableRecord = (UpdatableRecord<?>) record;
updatableRecord.store();
@ -37,7 +36,7 @@ public abstract class BaseDao<PO> {
return (T) identityType().cast(value);
}
public int batchInsert(Collection<PO> pojoList) {
public int batchInsert(Collection<R> pojoList) {
List<TableRecord<?>> records = pojoList.stream()
.map(pojo -> {
Record record = getDslContext().newRecord(table, pojo);
@ -53,24 +52,25 @@ public abstract class BaseDao<PO> {
.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 <T extends Serializable> Optional<PO> selectOptionalById(T id) {
public <T extends Serializable> Optional<R> selectOptionalById(T id) {
return getDslContext()
.select(table.fields()).from(table).where(identity().eq(id))
.fetchOptionalInto(pojoType);
}
public <T extends Serializable> PO selectById(T id) {
public <T extends Serializable> 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<PO> selectInIds(List<? extends Serializable> ids) {
public List<R> selectInIds(List<? extends Serializable> ids) {
if (ids == null || ids.isEmpty()) {
return Collections.emptyList();
}
@ -80,12 +80,12 @@ public abstract class BaseDao<PO> {
.fetchInto(pojoType);
}
public Page<PO> selectByPage(Pageable request, Condition condition) {
public Page<R> selectByPage(Pageable request, Condition condition) {
Integer count = getDslContext()
.selectCount().from(table).where(condition)
.fetchOne(0, int.class);
int total = count == null ? 0 : count;
List<PO> data = getDslContext()
List<R> data = getDslContext()
.selectFrom(table).where(condition)
.orderBy(getSortFields(request.getSort()))
.offset(request.getOffset()).limit(request.getPageSize())

6
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<DataSourcePojo> {
@ -36,7 +35,10 @@ public class DataSourceDao extends BaseDao<DataSourcePojo> {
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) {

1
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<DataSourcePropertyPojo> {

4
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<DatabaseDocumentPojo> {
@ -25,7 +24,8 @@ public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentPojo> {
public Optional<DatabaseDocumentPojo> 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);
}

8
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<DatabaseDocumentHistoryPojo> {
@ -30,11 +29,14 @@ public class DatabaseDocumentHistoryDao extends BaseDao<DatabaseDocumentHistoryP
public Optional<DatabaseDocumentHistoryPojo> 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<DatabaseDocumentVersionPojo> selectVersionPageByDatabaseDocumentId(Pageable request, Integer schemaDocumentId) {
public Page<DatabaseDocumentVersionPojo> 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)

1
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<DocumentRemarkPojo> {

1
dao/src/main/java/com/databasir/dao/impl/GroupDao.java

@ -27,7 +27,6 @@ public class GroupDao extends BaseDao<GroupPojo> {
super(GROUP, GroupPojo.class);
}
@Override
public <T extends Serializable> int deleteById(T id) {
return dslContext

1
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<LoginPojo> {

1
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<ProjectPojo> {

13
dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java

@ -28,15 +28,19 @@ public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRulePojo> {
public Optional<ProjectSyncRulePojo> 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<ProjectSyncRulePojo> {
.fetchInto(ProjectSyncRulePojo.class);
}
public List<ProjectSyncRulePojo> selectByIsAutoSyncAndNotInProjectIds(boolean isAutoSync, List<Integer> projectIds) {
public List<ProjectSyncRulePojo> selectByIsAutoSyncAndNotInProjectIds(boolean isAutoSync,
List<Integer> projectIds) {
if (projectIds == null || projectIds.isEmpty()) {
return getDslContext()
.selectFrom(PROJECT_SYNC_RULE)

4
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<TableColumnDocumentPojo> {
@ -31,7 +30,8 @@ public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentPojo> {
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();
}
}

3
dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java

@ -23,7 +23,8 @@ public class TableDocumentDao extends BaseDao<TableDocumentPojo> {
public List<TableDocumentPojo> 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);
}

1
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<TableIndexDocumentPojo> {

6
dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java

@ -23,13 +23,15 @@ public class TableTriggerDocumentDao extends BaseDao<TableTriggerDocumentPojo> {
public List<TableTriggerDocumentPojo> 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();
}
}

1
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<UserPojo> {

1
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<UserRolePojo> {

5
plugin/src/main/java/com/databasir/core/meta/provider/SqlProvider.java

@ -30,8 +30,6 @@ public interface SqlProvider {
* </table>
* <br>
*
* @param databaseName
* @return
*/
default Optional<String> databaseMetaSql(String databaseName) {
return Optional.empty();
@ -54,9 +52,6 @@ public interface SqlProvider {
* </tr>
* </table>
*
* @param databaseName
* @param tableName
* @return
*/
default Optional<String> tableMetaSql(String databaseName, String tableName) {
return Optional.empty();

1
plugin/src/main/java/com/databasir/core/meta/repository/condition/TableCondition.java

@ -20,5 +20,4 @@ public class TableCondition extends Condition {
.build();
}
}

40
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<TriggerMeta> 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());

22
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<String> selectPrimaryKeyColumns(DatabaseMetaData meta, String catalog, String tableName) throws SQLException {
private List<String> selectPrimaryKeyColumns(DatabaseMetaData meta,
String catalog,
String tableName) throws SQLException {
ResultSet result = meta.getPrimaryKeys(catalog, null, tableName);
List<String> columns = new ArrayList<>();
while (result.next()) {

21
plugin/src/main/java/com/databasir/core/render/RenderConfig.java

@ -19,11 +19,14 @@ public class RenderConfig {
private Boolean renderTriggers = true;
private LinkedHashMap<String, Function<ColumnMeta, String>> columnTitleAndValueMapping = columnTitleAndValueMapping();
private LinkedHashMap<String, Function<ColumnMeta, String>> columnTitleAndValueMapping =
columnTitleAndValueMapping();
private LinkedHashMap<String, Function<IndexMeta, String>> indexTitleAndValueMapping = indexTitleAndValueMapping();
private LinkedHashMap<String, Function<IndexMeta, String>> indexTitleAndValueMapping =
indexTitleAndValueMapping();
private LinkedHashMap<String, Function<TriggerMeta, String>> triggerTitleAndValueMapping = triggerTitleAndValueMapping();
private LinkedHashMap<String, Function<TriggerMeta, String>> triggerTitleAndValueMapping =
triggerTitleAndValueMapping();
protected LinkedHashMap<String, Function<ColumnMeta, String>> columnTitleAndValueMapping() {
LinkedHashMap<String, Function<ColumnMeta, String>> 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;
}

Loading…
Cancel
Save