From 497ad6b58aedb0e45cd2ebfaa335a0be14a33b10 Mon Sep 17 00:00:00 2001 From: vran Date: Sun, 29 May 2022 17:30:01 +0800 Subject: [PATCH] feat: support search table, column --- .../com/databasir/api/SearchController.java | 7 +- .../databasir/core/config/AsyncConfig.java | 12 + .../DocumentFullTextPojoConverter.java | 36 + .../document/service/DocumentService.java | 29 +- .../core/domain/group/event/GroupCreated.java | 17 + .../core/domain/group/event/GroupDeleted.java | 12 + .../core/domain/group/event/GroupUpdated.java | 17 + .../domain/group/service/GroupService.java | 9 + .../domain/project/event/ProjectDeleted.java | 12 + .../domain/project/event/ProjectSaved.java | 24 + .../project/service/ProjectService.java | 28 + .../core/domain/search/SearchService.java | 60 +- .../converter/SearchResponseConverter.java | 36 +- .../domain/search/data/SearchResponse.java | 53 +- .../subscriber/GroupEventSubscriber.java | 61 ++ .../subscriber/ProjectEventSubscriber.java | 59 ++ .../java/com/databasir/dao/Databasir.java | 7 + .../main/java/com/databasir/dao/Indexes.java | 8 + .../main/java/com/databasir/dao/Keys.java | 3 + .../main/java/com/databasir/dao/Tables.java | 6 + .../dao/tables/DocumentFullText.java | 258 +++++ .../tables/pojos/DocumentFullTextPojo.java | 456 +++++++++ .../records/DocumentFullTextRecord.java | 901 ++++++++++++++++++ .../java/com/databasir/dao/impl/BaseDao.java | 2 +- .../dao/impl/DocumentFullTextDao.java | 201 ++++ .../java/com/databasir/dao/impl/GroupDao.java | 3 +- .../com/databasir/dao/impl/ProjectDao.java | 27 +- .../value/FullTextProjectInfoUpdatePojo.java | 21 + dao/src/main/resources/db/init/init.sql | 36 +- .../db/init/v1.0.5~v1.0.6 data migration.sql | 55 ++ .../migration/V1.4.4__document_full_text.sql | 33 + databasir-frontend | 2 +- 32 files changed, 2424 insertions(+), 67 deletions(-) create mode 100644 core/src/main/java/com/databasir/core/domain/document/converter/DocumentFullTextPojoConverter.java create mode 100644 core/src/main/java/com/databasir/core/domain/group/event/GroupCreated.java create mode 100644 core/src/main/java/com/databasir/core/domain/group/event/GroupDeleted.java create mode 100644 core/src/main/java/com/databasir/core/domain/group/event/GroupUpdated.java create mode 100644 core/src/main/java/com/databasir/core/domain/project/event/ProjectDeleted.java create mode 100644 core/src/main/java/com/databasir/core/domain/project/event/ProjectSaved.java create mode 100644 core/src/main/java/com/databasir/core/infrastructure/event/subscriber/GroupEventSubscriber.java create mode 100644 core/src/main/java/com/databasir/core/infrastructure/event/subscriber/ProjectEventSubscriber.java create mode 100644 dao/generated-src/jooq/main/java/com/databasir/dao/tables/DocumentFullText.java create mode 100644 dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/DocumentFullTextPojo.java create mode 100644 dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/DocumentFullTextRecord.java create mode 100644 dao/src/main/java/com/databasir/dao/impl/DocumentFullTextDao.java create mode 100644 dao/src/main/java/com/databasir/dao/value/FullTextProjectInfoUpdatePojo.java create mode 100644 dao/src/main/resources/db/init/v1.0.5~v1.0.6 data migration.sql create mode 100644 dao/src/main/resources/db/migration/V1.4.4__document_full_text.sql diff --git a/api/src/main/java/com/databasir/api/SearchController.java b/api/src/main/java/com/databasir/api/SearchController.java index 1cb9a1f..6a03f00 100644 --- a/api/src/main/java/com/databasir/api/SearchController.java +++ b/api/src/main/java/com/databasir/api/SearchController.java @@ -6,6 +6,8 @@ import com.databasir.core.domain.search.data.SearchResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -21,7 +23,8 @@ public class SearchController { @GetMapping(Routes.Search.SEARCH) @Operation(summary = "搜索") - public JsonData search(@RequestParam(name = "query") String keyword) { - return JsonData.ok(searchService.search(keyword)); + public JsonData search(@PageableDefault(size = 50) Pageable pageable, + @RequestParam(name = "query") String keyword) { + return JsonData.ok(searchService.search(pageable, keyword)); } } diff --git a/core/src/main/java/com/databasir/core/config/AsyncConfig.java b/core/src/main/java/com/databasir/core/config/AsyncConfig.java index c6b83e9..41de735 100644 --- a/core/src/main/java/com/databasir/core/config/AsyncConfig.java +++ b/core/src/main/java/com/databasir/core/config/AsyncConfig.java @@ -28,4 +28,16 @@ public class AsyncConfig implements AsyncConfigurer { executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); return executor; } + + @Bean + public Executor fullTextRefreshThreadPoolTaskExecutor() { + final int maxCorePoolSize = 8; + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + int availableProcessorCount = Runtime.getRuntime().availableProcessors(); + int corePoolSize = Math.min(maxCorePoolSize, availableProcessorCount); + executor.setCorePoolSize(corePoolSize); + executor.setAllowCoreThreadTimeOut(true); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); + return executor; + } } diff --git a/core/src/main/java/com/databasir/core/domain/document/converter/DocumentFullTextPojoConverter.java b/core/src/main/java/com/databasir/core/domain/document/converter/DocumentFullTextPojoConverter.java new file mode 100644 index 0000000..9630814 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/document/converter/DocumentFullTextPojoConverter.java @@ -0,0 +1,36 @@ +package com.databasir.core.domain.document.converter; + +import com.databasir.dao.tables.pojos.*; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(componentModel = "spring") +public interface DocumentFullTextPojoConverter { + + /** + * groupName、groupDescription, projectName, projectDescription 等信息需要动态获取,所以不保存 + */ + @Mapping(target = "groupId", source = "group.id") + @Mapping(target = "projectId", source = "db.projectId") + @Mapping(target = "databaseDocumentId", source = "db.id") + @Mapping(target = "databaseDocumentVersion", source = "db.version") + @Mapping(target = "databaseProductName", source = "db.productName") + @Mapping(target = "tableDocumentId", source = "table.id") + @Mapping(target = "tableColumnDocumentId", source = "column.id") + @Mapping(target = "tableName", source = "table.name") + @Mapping(target = "tableComment", source = "table.comment") + @Mapping(target = "colName", source = "column.name") + @Mapping(target = "colComment", source = "column.comment") + @Mapping(target = "id", ignore = true) + @Mapping(target = "createAt", ignore = true) + @Mapping(target = "updateAt", ignore = true) + @Mapping(target = "groupName", ignore = true) + @Mapping(target = "groupDescription", ignore = true) + @Mapping(target = "projectName", ignore = true) + @Mapping(target = "projectDescription", ignore = true) + DocumentFullTextPojo toPojo(GroupPojo group, + ProjectPojo project, + DatabaseDocumentPojo db, + TableDocumentPojo table, + TableColumnDocumentPojo column); +} 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 4d8f963..5c7b110 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 @@ -49,6 +49,8 @@ import static java.util.Collections.emptyList; @Slf4j public class DocumentService { + private final GroupDao groupDao; + private final ProjectDao projectDao; private final ProjectSyncRuleDao projectSyncRuleDao; @@ -73,10 +75,14 @@ public class DocumentService { private final DocumentDiscussionDao documentDiscussionDao; + private final DocumentFullTextDao documentFullTextDao; + private final DocumentDescriptionDao documentDescriptionDao; private final DocumentPojoConverter documentPojoConverter; + private final DocumentFullTextPojoConverter documentFullTextPojoConverter; + private final DocumentResponseConverter documentResponseConverter; private final DocumentSimpleResponseConverter documentSimpleResponseConverter; @@ -166,10 +172,11 @@ public class DocumentService { Long version, Integer projectId) { - var pojo = documentPojoConverter.toDatabasePojo(projectId, meta, version); + var dbDocPojo = documentPojoConverter.toDatabasePojo(projectId, meta, version); final Integer docId; try { - docId = databaseDocumentDao.insertAndReturnId(pojo); + docId = databaseDocumentDao.insertAndReturnId(dbDocPojo); + dbDocPojo.setId(docId); } catch (DuplicateKeyException e) { log.warn("ignore insert database document projectId={} version={}", projectId, version); throw new DatabasirException(DomainErrors.DATABASE_DOCUMENT_DUPLICATE_KEY); @@ -178,6 +185,7 @@ public class DocumentService { TableDocumentPojo tableMeta = documentPojoConverter.toTablePojo(docId, table); Integer tableMetaId = tableDocumentDao.insertAndReturnId(tableMeta); + tableMeta.setId(tableMetaId); // column var columns = documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns()); tableColumnDocumentDao.batchInsert(columns); @@ -201,11 +209,28 @@ public class DocumentService { // trigger var triggers = documentPojoConverter.toTriggerPojo(docId, tableMetaId, table.getTriggers()); tableTriggerDocumentDao.batchInsert(triggers); + + // save full text + saveDocumentFullText(projectId, dbDocPojo, tableMeta); }); log.info("save new version document success: projectId = {}, name = {}, version = {}", projectId, meta.getDatabaseName(), version); } + private void saveDocumentFullText(Integer projectId, + DatabaseDocumentPojo database, + TableDocumentPojo table) { + ProjectPojo project = projectDao.selectById(projectId); + GroupPojo group = groupDao.selectById(project.getGroupId()); + List columns = tableColumnDocumentDao.selectByTableDocumentId(table.getId()); + // clear outdated data before save + documentFullTextDao.deleteByTableId(table.getId()); + List fullTextPojoList = columns.stream() + .map(column -> documentFullTextPojoConverter.toPojo(group, project, database, table, column)) + .collect(Collectors.toList()); + documentFullTextDao.batchInsert(fullTextPojoList); + } + public Optional getSimpleOneByProjectId(Integer projectId, Long version, Long originalVersion) { diff --git a/core/src/main/java/com/databasir/core/domain/group/event/GroupCreated.java b/core/src/main/java/com/databasir/core/domain/group/event/GroupCreated.java new file mode 100644 index 0000000..38b4c71 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/group/event/GroupCreated.java @@ -0,0 +1,17 @@ +package com.databasir.core.domain.group.event; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class GroupCreated { + + private Integer groupId; + + private String groupName; + + private String groupDescription; +} diff --git a/core/src/main/java/com/databasir/core/domain/group/event/GroupDeleted.java b/core/src/main/java/com/databasir/core/domain/group/event/GroupDeleted.java new file mode 100644 index 0000000..cfcc2c3 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/group/event/GroupDeleted.java @@ -0,0 +1,12 @@ +package com.databasir.core.domain.group.event; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class GroupDeleted { + + private Integer groupId; + +} diff --git a/core/src/main/java/com/databasir/core/domain/group/event/GroupUpdated.java b/core/src/main/java/com/databasir/core/domain/group/event/GroupUpdated.java new file mode 100644 index 0000000..3869137 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/group/event/GroupUpdated.java @@ -0,0 +1,17 @@ +package com.databasir.core.domain.group.event; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class GroupUpdated { + + private Integer groupId; + + private String groupName; + + private String groupDescription; +} 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 7d99092..2dcf5ac 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 @@ -4,6 +4,10 @@ import com.databasir.core.domain.DomainErrors; import com.databasir.core.domain.group.converter.GroupPojoConverter; import com.databasir.core.domain.group.converter.GroupResponseConverter; import com.databasir.core.domain.group.data.*; +import com.databasir.core.domain.group.event.GroupCreated; +import com.databasir.core.domain.group.event.GroupDeleted; +import com.databasir.core.domain.group.event.GroupUpdated; +import com.databasir.core.infrastructure.event.EventPublisher; import com.databasir.dao.impl.*; import com.databasir.dao.tables.pojos.GroupPojo; import com.databasir.dao.tables.pojos.UserPojo; @@ -34,6 +38,8 @@ public class GroupService { private final ProjectDao projectDao; + private final EventPublisher eventPublisher; + private final ProjectSyncRuleDao projectSyncRuleDao; private final GroupPojoConverter groupPojoConverter; @@ -55,6 +61,7 @@ public class GroupService { }) .collect(Collectors.toList()); userRoleDao.batchInsert(roles); + eventPublisher.publish(new GroupCreated(groupId, request.getName(), request.getDescription())); return groupId; } @@ -74,6 +81,7 @@ public class GroupService { }) .collect(Collectors.toList()); userRoleDao.batchInsert(roles); + eventPublisher.publish(new GroupUpdated(request.getId(), request.getName(), request.getDescription())); } public void delete(Integer groupId) { @@ -82,6 +90,7 @@ public class GroupService { List projectIds = projectDao.selectProjectIdsByGroupId(groupId); projectSyncRuleDao.disableAutoSyncByProjectIds(projectIds); projectDao.deleteByGroupId(groupId); + eventPublisher.publish(new GroupDeleted(groupId)); } public Page list(Pageable pageable, GroupPageCondition condition) { diff --git a/core/src/main/java/com/databasir/core/domain/project/event/ProjectDeleted.java b/core/src/main/java/com/databasir/core/domain/project/event/ProjectDeleted.java new file mode 100644 index 0000000..8489eae --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/project/event/ProjectDeleted.java @@ -0,0 +1,12 @@ +package com.databasir.core.domain.project.event; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ProjectDeleted { + + private Integer projectId; + +} diff --git a/core/src/main/java/com/databasir/core/domain/project/event/ProjectSaved.java b/core/src/main/java/com/databasir/core/domain/project/event/ProjectSaved.java new file mode 100644 index 0000000..eb06ec3 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/project/event/ProjectSaved.java @@ -0,0 +1,24 @@ +package com.databasir.core.domain.project.event; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class ProjectSaved { + + private Integer groupId; + + private Integer projectId; + + private String projectName; + + private String projectDescription; + + private String databaseType; + + private String databaseName; + + private String schemaName; + +} 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 ced03bf..de611fc 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 @@ -9,7 +9,10 @@ import com.databasir.core.domain.project.converter.ProjectSimpleTaskResponseConv import com.databasir.core.domain.project.data.*; import com.databasir.core.domain.project.data.task.ProjectSimpleTaskResponse; import com.databasir.core.domain.project.data.task.ProjectTaskListCondition; +import com.databasir.core.domain.project.event.ProjectDeleted; +import com.databasir.core.domain.project.event.ProjectSaved; import com.databasir.core.infrastructure.connection.DatabaseConnectionService; +import com.databasir.core.infrastructure.event.EventPublisher; import com.databasir.dao.enums.ProjectSyncTaskStatus; import com.databasir.dao.impl.*; import com.databasir.dao.tables.pojos.*; @@ -55,6 +58,8 @@ public class ProjectService { private final ProjectSimpleTaskResponseConverter projectSimpleTaskResponseConverter; + private final EventPublisher eventPublisher; + public ProjectDetailResponse getOne(Integer id) { return projectDao.selectOptionalById(id) .map(schemaSource -> { @@ -88,6 +93,17 @@ public class ProjectService { ProjectSyncRulePojo syncRule = projectPojoConverter.of(request.getProjectSyncRule(), projectId); projectSyncRuleDao.insertAndReturnId(syncRule); + + var event = ProjectSaved.builder() + .groupId(project.getGroupId()) + .projectId(projectId) + .projectName(project.getName()) + .projectDescription(project.getDescription()) + .databaseType(request.getDataSource().getDatabaseType()) + .databaseName(dataSource.getDatabaseName()) + .schemaName(dataSource.getSchemaName()) + .build(); + eventPublisher.publish(event); return projectId; } @@ -119,6 +135,17 @@ public class ProjectService { // update project info ProjectPojo project = projectPojoConverter.of(request); projectDao.updateById(project); + + ProjectSaved event = ProjectSaved.builder() + .groupId(project.getGroupId()) + .projectId(project.getId()) + .projectName(project.getName()) + .projectDescription(project.getDescription()) + .databaseType(request.getDataSource().getDatabaseType()) + .databaseName(dataSource.getDatabaseName()) + .schemaName(dataSource.getSchemaName()) + .build(); + eventPublisher.publish(event); } else { throw DomainErrors.PROJECT_NOT_FOUND.exception(); } @@ -137,6 +164,7 @@ public class ProjectService { public void delete(Integer projectId) { projectDao.updateDeletedById(true, projectId); projectSyncRuleDao.disableAutoSyncByProjectId(projectId); + eventPublisher.publish(new ProjectDeleted(projectId)); } public Page list(Integer userId, Pageable page, ProjectListCondition condition) { diff --git a/core/src/main/java/com/databasir/core/domain/search/SearchService.java b/core/src/main/java/com/databasir/core/domain/search/SearchService.java index 3e9414e..36b4a2f 100644 --- a/core/src/main/java/com/databasir/core/domain/search/SearchService.java +++ b/core/src/main/java/com/databasir/core/domain/search/SearchService.java @@ -2,32 +2,72 @@ package com.databasir.core.domain.search; import com.databasir.core.domain.search.converter.SearchResponseConverter; import com.databasir.core.domain.search.data.SearchResponse; +import com.databasir.dao.impl.DocumentFullTextDao; import com.databasir.dao.impl.GroupDao; import com.databasir.dao.impl.ProjectDao; +import com.databasir.dao.tables.pojos.DocumentFullTextPojo; +import com.databasir.dao.tables.pojos.GroupPojo; +import com.databasir.dao.tables.pojos.ProjectPojo; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor public class SearchService { - private final ProjectDao projectDao; + private final SearchResponseConverter searchResponseConverter; + + private final DocumentFullTextDao documentFullTextDao; private final GroupDao groupDao; - private final SearchResponseConverter searchResponseConverter; + private final ProjectDao projectDao; - public SearchResponse search(String query) { - var groupPojoList = groupDao.selectByName(query); - var groupResults = searchResponseConverter.toGroupResults(groupPojoList); - var projectList = projectDao.selectByProjectNameOrDatabaseOrSchemaOrGroup(query); - var projectResults = searchResponseConverter.toProjectResults(projectList); + public SearchResponse search(Pageable pageable, String query) { + Page columnPageData = documentFullTextDao.selectColumnPage(pageable, query); + Page tablePageData = documentFullTextDao.selectTablePage(pageable, query); + // table 和 column 的项目名、组名等信息需要从关联表取 + Set projectIds = new HashSet<>(); + projectIds.addAll(columnPageData.getContent() + .stream().map(o -> o.getProjectId()).collect(Collectors.toList())); + projectIds.addAll(tablePageData.getContent() + .stream().map(o -> o.getProjectId()).collect(Collectors.toList())); + Map projectMapById = projectDao.selectInIds(projectIds) + .stream() + .collect(Collectors.toMap(o -> o.getId(), o -> o)); + + Page projectPageData = documentFullTextDao.selectProjectPage(pageable, query); + Set groupIds = new HashSet<>(); + groupIds.addAll(columnPageData.getContent() + .stream().map(o -> o.getGroupId()).collect(Collectors.toList())); + groupIds.addAll(tablePageData.getContent() + .stream().map(o -> o.getGroupId()).collect(Collectors.toList())); + groupIds.addAll(projectPageData.getContent() + .stream().map(o -> o.getGroupId()).collect(Collectors.toList())); + Map groupMapById = groupDao.selectInIds(groupIds) + .stream() + .collect(Collectors.toMap(o -> o.getId(), o -> o)); + + // convert + var columns = columnPageData.map(item -> searchResponseConverter.toItem(item, projectMapById, groupMapById)); + var tables = tablePageData.map(item -> searchResponseConverter.toItem(item, projectMapById, groupMapById)); + var projects = projectPageData.map(item -> searchResponseConverter.toItem(item, groupMapById)); + var groups = documentFullTextDao.selectGroupPage(pageable, query) + .map(searchResponseConverter::toItem); // build response SearchResponse response = new SearchResponse(); - response.setGroups(groupResults); - response.setProjects(projectResults); - // TODO support Table search + response.setColumnPageData(columns); + response.setProjectPageData(projects); + response.setTablePageData(tables); + response.setGroupPageData(groups); return response; } } diff --git a/core/src/main/java/com/databasir/core/domain/search/converter/SearchResponseConverter.java b/core/src/main/java/com/databasir/core/domain/search/converter/SearchResponseConverter.java index 942082a..aa62d23 100644 --- a/core/src/main/java/com/databasir/core/domain/search/converter/SearchResponseConverter.java +++ b/core/src/main/java/com/databasir/core/domain/search/converter/SearchResponseConverter.java @@ -1,16 +1,44 @@ package com.databasir.core.domain.search.converter; import com.databasir.core.domain.search.data.SearchResponse; +import com.databasir.dao.tables.pojos.DocumentFullTextPojo; import com.databasir.dao.tables.pojos.GroupPojo; -import com.databasir.dao.value.ProjectQueryPojo; +import com.databasir.dao.tables.pojos.ProjectPojo; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; -import java.util.List; +import java.util.Map; @Mapper(componentModel = "spring") public interface SearchResponseConverter { - List toGroupResults(List groups); + default SearchResponse.Item toItem(DocumentFullTextPojo pojo, + Map projectMapById, + Map groupMapById) { + ProjectPojo project = projectMapById.get(pojo.getProjectId()); + GroupPojo group = groupMapById.get(pojo.getGroupId()); + return toItem(pojo, group.getName(), group.getDescription(), project.getName(), project.getDescription()); + } - List toProjectResults(List projects); + default SearchResponse.Item toItem(DocumentFullTextPojo pojo, + Map groupMapById) { + var group = groupMapById.get(pojo.getGroupId()); + return toItem(pojo, + group.getName(), + group.getDescription(), + pojo.getProjectName(), + pojo.getProjectDescription()); + } + + @Mapping(target = "groupName", source = "groupName") + @Mapping(target = "groupDescription", source = "groupDescription") + @Mapping(target = "projectName", source = "projectName") + @Mapping(target = "projectDescription", source = "projectDescription") + SearchResponse.Item toItem(DocumentFullTextPojo item, + String groupName, + String groupDescription, + String projectName, + String projectDescription); + + SearchResponse.Item toItem(DocumentFullTextPojo pojo); } diff --git a/core/src/main/java/com/databasir/core/domain/search/data/SearchResponse.java b/core/src/main/java/com/databasir/core/domain/search/data/SearchResponse.java index 0eea330..f3bb726 100644 --- a/core/src/main/java/com/databasir/core/domain/search/data/SearchResponse.java +++ b/core/src/main/java/com/databasir/core/domain/search/data/SearchResponse.java @@ -4,9 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; - -import java.util.Collections; -import java.util.List; +import org.springframework.data.domain.Page; @Data @NoArgsConstructor @@ -14,31 +12,33 @@ import java.util.List; @Builder public class SearchResponse { - @Builder.Default - private List groups = Collections.emptyList(); + private Page groupPageData; - @Builder.Default - private List projects = Collections.emptyList(); + private Page projectPageData; + + private Page tablePageData; + + private Page columnPageData; @Data - public static class GroupSearchResult { - - private Integer id; - - private String name; - - private String description; - } - - @Data - public static class ProjectSearchResult { - - private Integer projectId; + public static class Item { private Integer groupId; + private Integer projectId; + + private Integer databaseDocumentId; + + private Integer databaseDocumentVersion; + + private Integer tableDocumentId; + + private Integer tableColumnDocumentId; + private String groupName; + private String groupDescription; + private String projectName; private String projectDescription; @@ -47,5 +47,18 @@ public class SearchResponse { private String schemaName; + private String databaseProductName; + + private String databaseType; + + private String tableName; + + private String tableComment; + + private String colName; + + private String colComment; + } + } diff --git a/core/src/main/java/com/databasir/core/infrastructure/event/subscriber/GroupEventSubscriber.java b/core/src/main/java/com/databasir/core/infrastructure/event/subscriber/GroupEventSubscriber.java new file mode 100644 index 0000000..733a585 --- /dev/null +++ b/core/src/main/java/com/databasir/core/infrastructure/event/subscriber/GroupEventSubscriber.java @@ -0,0 +1,61 @@ +package com.databasir.core.infrastructure.event.subscriber; + +import com.databasir.core.domain.group.event.GroupCreated; +import com.databasir.core.domain.group.event.GroupDeleted; +import com.databasir.core.domain.group.event.GroupUpdated; +import com.databasir.dao.Tables; +import com.databasir.dao.impl.DocumentFullTextDao; +import com.databasir.dao.tables.pojos.DocumentFullTextPojo; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +@Async("fullTextRefreshThreadPoolTaskExecutor") +public class GroupEventSubscriber { + + private final DocumentFullTextDao documentFullTextDao; + + @EventListener(classes = GroupUpdated.class) + public void refreshFullTextWhenUpdated(GroupUpdated event) { + if (!documentFullTextDao.exists(Tables.DOCUMENT_FULL_TEXT.GROUP_ID.eq(event.getGroupId()) + .and(Tables.DOCUMENT_FULL_TEXT.PROJECT_ID.isNull()))) { + DocumentFullTextPojo pojo = new DocumentFullTextPojo(); + pojo.setGroupId(event.getGroupId()); + pojo.setGroupName(event.getGroupName()); + pojo.setGroupDescription(event.getGroupDescription()); + documentFullTextDao.insertAndReturnId(pojo); + log.info("group not exists, save new full text by event({}) success", event); + } else { + int result = documentFullTextDao.updateGroupInfoByGroupId(event.getGroupName(), + event.getGroupDescription(), + event.getGroupId()); + log.info("update full text group({}) info success, effect rows {}", event.getGroupId(), result); + } + } + + @EventListener(classes = GroupDeleted.class) + public void deleteFullTextWhenDeleted(GroupDeleted event) { + int result = documentFullTextDao.deleteByGroupId(event.getGroupId()); + log.info("delete full text by group({}) success, effect rows {}", event.getGroupId(), result); + } + + @EventListener(classes = GroupCreated.class) + public void addFullTextWhenCreated(GroupCreated event) { + if (!documentFullTextDao.exists(Tables.DOCUMENT_FULL_TEXT.GROUP_ID.eq(event.getGroupId()) + .and(Tables.DOCUMENT_FULL_TEXT.PROJECT_ID.isNull()))) { + DocumentFullTextPojo pojo = new DocumentFullTextPojo(); + pojo.setGroupId(event.getGroupId()); + pojo.setGroupName(event.getGroupName()); + pojo.setGroupDescription(event.getGroupDescription()); + documentFullTextDao.insertAndReturnId(pojo); + log.info("save full text by event({}) success", event); + } else { + log.warn("ignore event {} because document already exists", event); + } + } +} diff --git a/core/src/main/java/com/databasir/core/infrastructure/event/subscriber/ProjectEventSubscriber.java b/core/src/main/java/com/databasir/core/infrastructure/event/subscriber/ProjectEventSubscriber.java new file mode 100644 index 0000000..cc6b884 --- /dev/null +++ b/core/src/main/java/com/databasir/core/infrastructure/event/subscriber/ProjectEventSubscriber.java @@ -0,0 +1,59 @@ +package com.databasir.core.infrastructure.event.subscriber; + +import com.databasir.core.domain.project.event.ProjectDeleted; +import com.databasir.core.domain.project.event.ProjectSaved; +import com.databasir.dao.Tables; +import com.databasir.dao.impl.DocumentFullTextDao; +import com.databasir.dao.tables.pojos.DocumentFullTextPojo; +import com.databasir.dao.value.FullTextProjectInfoUpdatePojo; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component +@RequiredArgsConstructor +@Slf4j +@Async("fullTextRefreshThreadPoolTaskExecutor") +public class ProjectEventSubscriber { + + private final DocumentFullTextDao documentFullTextDao; + + @EventListener(classes = ProjectSaved.class) + @Transactional + public void refreshFullTextWhenUpdated(ProjectSaved event) { + if (!documentFullTextDao.exists(Tables.DOCUMENT_FULL_TEXT.PROJECT_ID.eq(event.getProjectId()) + .and(Tables.DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID.isNull()))) { + DocumentFullTextPojo pojo = new DocumentFullTextPojo(); + pojo.setGroupId(event.getGroupId()); + pojo.setProjectId(event.getProjectId()); + pojo.setProjectName(event.getProjectName()); + pojo.setProjectDescription(event.getProjectDescription()); + pojo.setDatabaseName(event.getDatabaseName()); + pojo.setSchemaName(event.getSchemaName()); + pojo.setDatabaseType(event.getDatabaseType()); + documentFullTextDao.insertAndReturnId(pojo); + log.info("save full text by event ({}) success", event); + } else { + FullTextProjectInfoUpdatePojo updatePojo = FullTextProjectInfoUpdatePojo.builder() + .projectId(event.getProjectId()) + .projectName(event.getProjectName()) + .projectDescription(event.getProjectDescription()) + .databaseType(event.getDatabaseType()) + .databaseName(event.getDatabaseName()) + .schemaName(event.getSchemaName()) + .build(); + int result = documentFullTextDao.updateProjectInfoByProjectId(updatePojo); + log.info("update full text project({}) info success, effect rows {}", event, result); + } + } + + @EventListener(classes = ProjectDeleted.class) + public void deleteFullTextWhenDeleted(ProjectDeleted event) { + int result = documentFullTextDao.deleteByProjectId(event.getProjectId()); + log.info("delete full text by project({}) success, effect rows {}", event.getProjectId(), result); + } + +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java index 019bac4..ba98d75 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java @@ -10,6 +10,7 @@ import com.databasir.dao.tables.DatabaseDocument; import com.databasir.dao.tables.DatabaseType; import com.databasir.dao.tables.DocumentDescription; import com.databasir.dao.tables.DocumentDiscussion; +import com.databasir.dao.tables.DocumentFullText; import com.databasir.dao.tables.DocumentTemplateProperty; import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Login; @@ -81,6 +82,11 @@ public class Databasir extends SchemaImpl { */ public final DocumentDiscussion DOCUMENT_DISCUSSION = DocumentDiscussion.DOCUMENT_DISCUSSION; + /** + * The table databasir.document_full_text. + */ + public final DocumentFullText DOCUMENT_FULL_TEXT = DocumentFullText.DOCUMENT_FULL_TEXT; + /** * template property */ @@ -198,6 +204,7 @@ public class Databasir extends SchemaImpl { DatabaseType.DATABASE_TYPE, DocumentDescription.DOCUMENT_DESCRIPTION, DocumentDiscussion.DOCUMENT_DISCUSSION, + DocumentFullText.DOCUMENT_FULL_TEXT, DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY, Group.GROUP, Login.LOGIN, diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java index 36802cd..1bdeb5c 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java @@ -6,6 +6,7 @@ package com.databasir.dao; import com.databasir.dao.tables.DataSourceProperty; import com.databasir.dao.tables.DocumentDiscussion; +import com.databasir.dao.tables.DocumentFullText; import com.databasir.dao.tables.ProjectSyncTask; import com.databasir.dao.tables.TableColumnDocument; import com.databasir.dao.tables.TableDocument; @@ -29,14 +30,21 @@ public class Indexes { // INDEX definitions // ------------------------------------------------------------------------- + public static final Index DOCUMENT_FULL_TEXT_FIDX_COLUMN = Internal.createIndex(DSL.name("fidx_column"), DocumentFullText.DOCUMENT_FULL_TEXT, new OrderField[] { DocumentFullText.DOCUMENT_FULL_TEXT.COL_NAME, DocumentFullText.DOCUMENT_FULL_TEXT.COL_COMMENT, DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_PRODUCT_NAME }, false); + public static final Index DOCUMENT_FULL_TEXT_FIDX_GROUP = Internal.createIndex(DSL.name("fidx_group"), DocumentFullText.DOCUMENT_FULL_TEXT, new OrderField[] { DocumentFullText.DOCUMENT_FULL_TEXT.GROUP_NAME, DocumentFullText.DOCUMENT_FULL_TEXT.GROUP_DESCRIPTION }, false); + public static final Index DOCUMENT_FULL_TEXT_FIDX_PROJECT = Internal.createIndex(DSL.name("fidx_project"), DocumentFullText.DOCUMENT_FULL_TEXT, new OrderField[] { DocumentFullText.DOCUMENT_FULL_TEXT.PROJECT_NAME, DocumentFullText.DOCUMENT_FULL_TEXT.PROJECT_DESCRIPTION, DocumentFullText.DOCUMENT_FULL_TEXT.SCHEMA_NAME, DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_NAME, DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_TYPE }, false); + public static final Index DOCUMENT_FULL_TEXT_FIDX_TABLE = Internal.createIndex(DSL.name("fidx_table"), DocumentFullText.DOCUMENT_FULL_TEXT, new OrderField[] { DocumentFullText.DOCUMENT_FULL_TEXT.TABLE_NAME, DocumentFullText.DOCUMENT_FULL_TEXT.TABLE_COMMENT, DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_PRODUCT_NAME }, false); public static final Index DATA_SOURCE_PROPERTY_IDX_DATA_SOURCE_ID = Internal.createIndex(DSL.name("idx_data_source_id"), DataSourceProperty.DATA_SOURCE_PROPERTY, new OrderField[] { DataSourceProperty.DATA_SOURCE_PROPERTY.DATA_SOURCE_ID }, false); public static final Index TABLE_COLUMN_DOCUMENT_IDX_DATABASE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_database_document_id"), TableColumnDocument.TABLE_COLUMN_DOCUMENT, new OrderField[] { TableColumnDocument.TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID }, false); public static final Index TABLE_DOCUMENT_IDX_DATABASE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_database_document_id"), TableDocument.TABLE_DOCUMENT, new OrderField[] { TableDocument.TABLE_DOCUMENT.DATABASE_DOCUMENT_ID }, false); public static final Index TABLE_FOREIGN_KEY_DOCUMENT_IDX_DATABASE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_database_document_id"), TableForeignKeyDocument.TABLE_FOREIGN_KEY_DOCUMENT, new OrderField[] { TableForeignKeyDocument.TABLE_FOREIGN_KEY_DOCUMENT.DATABASE_DOCUMENT_ID }, false); public static final Index TABLE_INDEX_DOCUMENT_IDX_DATABASE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_database_document_id"), TableIndexDocument.TABLE_INDEX_DOCUMENT, new OrderField[] { TableIndexDocument.TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID }, false); public static final Index TABLE_TRIGGER_DOCUMENT_IDX_DATABASE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_database_document_id"), TableTriggerDocument.TABLE_TRIGGER_DOCUMENT, new OrderField[] { TableTriggerDocument.TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID }, false); + public static final Index DOCUMENT_FULL_TEXT_IDX_GROUP_ID = Internal.createIndex(DSL.name("idx_group_id"), DocumentFullText.DOCUMENT_FULL_TEXT, new OrderField[] { DocumentFullText.DOCUMENT_FULL_TEXT.GROUP_ID }, false); public static final Index DOCUMENT_DISCUSSION_IDX_PROJECT_ID = Internal.createIndex(DSL.name("idx_project_id"), DocumentDiscussion.DOCUMENT_DISCUSSION, new OrderField[] { DocumentDiscussion.DOCUMENT_DISCUSSION.PROJECT_ID }, false); + public static final Index DOCUMENT_FULL_TEXT_IDX_PROJECT_ID = Internal.createIndex(DSL.name("idx_project_id"), DocumentFullText.DOCUMENT_FULL_TEXT, new OrderField[] { DocumentFullText.DOCUMENT_FULL_TEXT.PROJECT_ID }, false); public static final Index PROJECT_SYNC_TASK_IDX_PROJECT_ID = Internal.createIndex(DSL.name("idx_project_id"), ProjectSyncTask.PROJECT_SYNC_TASK, new OrderField[] { ProjectSyncTask.PROJECT_SYNC_TASK.PROJECT_ID }, false); + public static final Index DOCUMENT_FULL_TEXT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), DocumentFullText.DOCUMENT_FULL_TEXT, new OrderField[] { DocumentFullText.DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID }, false); public static final Index TABLE_COLUMN_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableColumnDocument.TABLE_COLUMN_DOCUMENT, new OrderField[] { TableColumnDocument.TABLE_COLUMN_DOCUMENT.TABLE_DOCUMENT_ID }, false); public static final Index TABLE_FOREIGN_KEY_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableForeignKeyDocument.TABLE_FOREIGN_KEY_DOCUMENT, new OrderField[] { TableForeignKeyDocument.TABLE_FOREIGN_KEY_DOCUMENT.TABLE_DOCUMENT_ID }, false); public static final Index TABLE_INDEX_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableIndexDocument.TABLE_INDEX_DOCUMENT, new OrderField[] { TableIndexDocument.TABLE_INDEX_DOCUMENT.TABLE_DOCUMENT_ID }, false); diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java index 3c580c1..073ecc8 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java @@ -10,6 +10,7 @@ import com.databasir.dao.tables.DatabaseDocument; import com.databasir.dao.tables.DatabaseType; import com.databasir.dao.tables.DocumentDescription; import com.databasir.dao.tables.DocumentDiscussion; +import com.databasir.dao.tables.DocumentFullText; import com.databasir.dao.tables.DocumentTemplateProperty; import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Login; @@ -35,6 +36,7 @@ import com.databasir.dao.tables.records.DatabaseDocumentRecord; import com.databasir.dao.tables.records.DatabaseTypeRecord; import com.databasir.dao.tables.records.DocumentDescriptionRecord; import com.databasir.dao.tables.records.DocumentDiscussionRecord; +import com.databasir.dao.tables.records.DocumentFullTextRecord; import com.databasir.dao.tables.records.DocumentTemplatePropertyRecord; import com.databasir.dao.tables.records.GroupRecord; import com.databasir.dao.tables.records.LoginRecord; @@ -82,6 +84,7 @@ public class Keys { public static final UniqueKey KEY_DOCUMENT_DESCRIPTION_PRIMARY = Internal.createUniqueKey(DocumentDescription.DOCUMENT_DESCRIPTION, DSL.name("KEY_document_description_PRIMARY"), new TableField[] { DocumentDescription.DOCUMENT_DESCRIPTION.ID }, true); public static final UniqueKey KEY_DOCUMENT_DESCRIPTION_UK_PROJECT_ID_TABLE_NAME_COLUMN_NAME = Internal.createUniqueKey(DocumentDescription.DOCUMENT_DESCRIPTION, DSL.name("KEY_document_description_uk_project_id_table_name_column_name"), new TableField[] { DocumentDescription.DOCUMENT_DESCRIPTION.PROJECT_ID, DocumentDescription.DOCUMENT_DESCRIPTION.TABLE_NAME, DocumentDescription.DOCUMENT_DESCRIPTION.COLUMN_NAME }, true); public static final UniqueKey KEY_DOCUMENT_DISCUSSION_PRIMARY = Internal.createUniqueKey(DocumentDiscussion.DOCUMENT_DISCUSSION, DSL.name("KEY_document_discussion_PRIMARY"), new TableField[] { DocumentDiscussion.DOCUMENT_DISCUSSION.ID }, true); + public static final UniqueKey KEY_DOCUMENT_FULL_TEXT_PRIMARY = Internal.createUniqueKey(DocumentFullText.DOCUMENT_FULL_TEXT, DSL.name("KEY_document_full_text_PRIMARY"), new TableField[] { DocumentFullText.DOCUMENT_FULL_TEXT.ID }, true); public static final UniqueKey KEY_DOCUMENT_TEMPLATE_PROPERTY_PRIMARY = Internal.createUniqueKey(DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY, DSL.name("KEY_document_template_property_PRIMARY"), new TableField[] { DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY.ID }, true); public static final UniqueKey KEY_DOCUMENT_TEMPLATE_PROPERTY_UK_TYPE_KEY = Internal.createUniqueKey(DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY, DSL.name("KEY_document_template_property_uk_type_key"), new TableField[] { DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY.TYPE, DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY.KEY }, true); public static final UniqueKey KEY_GROUP_PRIMARY = Internal.createUniqueKey(Group.GROUP, DSL.name("KEY_group_PRIMARY"), new TableField[] { Group.GROUP.ID }, true); diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java index 9631e01..5e29e5e 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java @@ -10,6 +10,7 @@ import com.databasir.dao.tables.DatabaseDocument; import com.databasir.dao.tables.DatabaseType; import com.databasir.dao.tables.DocumentDescription; import com.databasir.dao.tables.DocumentDiscussion; +import com.databasir.dao.tables.DocumentFullText; import com.databasir.dao.tables.DocumentTemplateProperty; import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Login; @@ -67,6 +68,11 @@ public class Tables { */ public static final DocumentDiscussion DOCUMENT_DISCUSSION = DocumentDiscussion.DOCUMENT_DISCUSSION; + /** + * The table databasir.document_full_text. + */ + public static final DocumentFullText DOCUMENT_FULL_TEXT = DocumentFullText.DOCUMENT_FULL_TEXT; + /** * template property */ diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/DocumentFullText.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/DocumentFullText.java new file mode 100644 index 0000000..d97b282 --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/DocumentFullText.java @@ -0,0 +1,258 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables; + + +import com.databasir.dao.Databasir; +import com.databasir.dao.Indexes; +import com.databasir.dao.Keys; +import com.databasir.dao.tables.records.DocumentFullTextRecord; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; + +import org.jooq.Field; +import org.jooq.ForeignKey; +import org.jooq.Identity; +import org.jooq.Index; +import org.jooq.Name; +import org.jooq.Record; +import org.jooq.Row21; +import org.jooq.Schema; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.TableOptions; +import org.jooq.UniqueKey; +import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; +import org.jooq.impl.TableImpl; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class DocumentFullText extends TableImpl { + + private static final long serialVersionUID = 1L; + + /** + * The reference instance of databasir.document_full_text + */ + public static final DocumentFullText DOCUMENT_FULL_TEXT = new DocumentFullText(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return DocumentFullTextRecord.class; + } + + /** + * The column databasir.document_full_text.id. + */ + public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, ""); + + /** + * The column databasir.document_full_text.group_id. ref to + * group.id + */ + public final TableField GROUP_ID = createField(DSL.name("group_id"), SQLDataType.INTEGER.nullable(false), this, "ref to group.id"); + + /** + * The column databasir.document_full_text.project_id. ref to + * project.id, may null + */ + public final TableField PROJECT_ID = createField(DSL.name("project_id"), SQLDataType.INTEGER, this, "ref to project.id, may null"); + + /** + * The column + * databasir.document_full_text.database_document_id. ref to + * database_document.id, may null + */ + public final TableField DATABASE_DOCUMENT_ID = createField(DSL.name("database_document_id"), SQLDataType.INTEGER, this, "ref to database_document.id, may null"); + + /** + * The column + * databasir.document_full_text.database_document_version. rf + * to database_document.version, may null + */ + public final TableField DATABASE_DOCUMENT_VERSION = createField(DSL.name("database_document_version"), SQLDataType.INTEGER, this, "rf to database_document.version, may null"); + + /** + * The column databasir.document_full_text.table_document_id. + * ref to table_document.id, may null + */ + public final TableField TABLE_DOCUMENT_ID = createField(DSL.name("table_document_id"), SQLDataType.INTEGER, this, "ref to table_document.id, may null"); + + /** + * The column + * databasir.document_full_text.table_column_document_id. ref + * to table_column_document.id, may null + */ + public final TableField TABLE_COLUMN_DOCUMENT_ID = createField(DSL.name("table_column_document_id"), SQLDataType.INTEGER, this, "ref to table_column_document.id, may null"); + + /** + * The column databasir.document_full_text.group_name. + */ + public final TableField GROUP_NAME = createField(DSL.name("group_name"), SQLDataType.VARCHAR(255), this, ""); + + /** + * The column databasir.document_full_text.group_description. + */ + public final TableField GROUP_DESCRIPTION = createField(DSL.name("group_description"), SQLDataType.VARCHAR(512), this, ""); + + /** + * The column databasir.document_full_text.project_name. + */ + public final TableField PROJECT_NAME = createField(DSL.name("project_name"), SQLDataType.VARCHAR(255), this, ""); + + /** + * The column databasir.document_full_text.project_description. + */ + public final TableField PROJECT_DESCRIPTION = createField(DSL.name("project_description"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.database_name. + */ + public final TableField DATABASE_NAME = createField(DSL.name("database_name"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.schema_name. + */ + public final TableField SCHEMA_NAME = createField(DSL.name("schema_name"), SQLDataType.CLOB, this, ""); + + /** + * The column + * databasir.document_full_text.database_product_name. + */ + public final TableField DATABASE_PRODUCT_NAME = createField(DSL.name("database_product_name"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.database_type. + */ + public final TableField DATABASE_TYPE = createField(DSL.name("database_type"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.table_name. + */ + public final TableField TABLE_NAME = createField(DSL.name("table_name"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.table_comment. + */ + public final TableField TABLE_COMMENT = createField(DSL.name("table_comment"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.col_name. + */ + public final TableField COL_NAME = createField(DSL.name("col_name"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.col_comment. + */ + public final TableField COL_COMMENT = createField(DSL.name("col_comment"), SQLDataType.CLOB, this, ""); + + /** + * The column databasir.document_full_text.update_at. + */ + public final TableField UPDATE_AT = createField(DSL.name("update_at"), SQLDataType.LOCALDATETIME(0).nullable(false).defaultValue(DSL.field("CURRENT_TIMESTAMP", SQLDataType.LOCALDATETIME)), this, ""); + + /** + * The column databasir.document_full_text.create_at. + */ + public final TableField CREATE_AT = createField(DSL.name("create_at"), SQLDataType.LOCALDATETIME(0).nullable(false).defaultValue(DSL.field("CURRENT_TIMESTAMP", SQLDataType.LOCALDATETIME)), this, ""); + + private DocumentFullText(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private DocumentFullText(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + } + + /** + * Create an aliased databasir.document_full_text table + * reference + */ + public DocumentFullText(String alias) { + this(DSL.name(alias), DOCUMENT_FULL_TEXT); + } + + /** + * Create an aliased databasir.document_full_text table + * reference + */ + public DocumentFullText(Name alias) { + this(alias, DOCUMENT_FULL_TEXT); + } + + /** + * Create a databasir.document_full_text table reference + */ + public DocumentFullText() { + this(DSL.name("document_full_text"), null); + } + + public DocumentFullText(Table child, ForeignKey key) { + super(child, key, DOCUMENT_FULL_TEXT); + } + + @Override + public Schema getSchema() { + return aliased() ? null : Databasir.DATABASIR; + } + + @Override + public List getIndexes() { + return Arrays.asList(Indexes.DOCUMENT_FULL_TEXT_FIDX_COLUMN, Indexes.DOCUMENT_FULL_TEXT_FIDX_GROUP, Indexes.DOCUMENT_FULL_TEXT_FIDX_PROJECT, Indexes.DOCUMENT_FULL_TEXT_FIDX_TABLE, Indexes.DOCUMENT_FULL_TEXT_IDX_GROUP_ID, Indexes.DOCUMENT_FULL_TEXT_IDX_PROJECT_ID, Indexes.DOCUMENT_FULL_TEXT_IDX_TABLE_DOCUMENT_ID); + } + + @Override + public Identity getIdentity() { + return (Identity) super.getIdentity(); + } + + @Override + public UniqueKey getPrimaryKey() { + return Keys.KEY_DOCUMENT_FULL_TEXT_PRIMARY; + } + + @Override + public DocumentFullText as(String alias) { + return new DocumentFullText(DSL.name(alias), this); + } + + @Override + public DocumentFullText as(Name alias) { + return new DocumentFullText(alias, this); + } + + /** + * Rename this table + */ + @Override + public DocumentFullText rename(String name) { + return new DocumentFullText(DSL.name(name), null); + } + + /** + * Rename this table + */ + @Override + public DocumentFullText rename(Name name) { + return new DocumentFullText(name, null); + } + + // ------------------------------------------------------------------------- + // Row21 type methods + // ------------------------------------------------------------------------- + + @Override + public Row21 fieldsRow() { + return (Row21) super.fieldsRow(); + } +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/DocumentFullTextPojo.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/DocumentFullTextPojo.java new file mode 100644 index 0000000..a45a203 --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/DocumentFullTextPojo.java @@ -0,0 +1,456 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables.pojos; + + +import java.io.Serializable; +import java.time.LocalDateTime; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class DocumentFullTextPojo implements Serializable { + + private static final long serialVersionUID = 1L; + + private Integer id; + private Integer groupId; + private Integer projectId; + private Integer databaseDocumentId; + private Integer databaseDocumentVersion; + private Integer tableDocumentId; + private Integer tableColumnDocumentId; + private String groupName; + private String groupDescription; + private String projectName; + private String projectDescription; + private String databaseName; + private String schemaName; + private String databaseProductName; + private String databaseType; + private String tableName; + private String tableComment; + private String colName; + private String colComment; + private LocalDateTime updateAt; + private LocalDateTime createAt; + + public DocumentFullTextPojo() {} + + public DocumentFullTextPojo(DocumentFullTextPojo value) { + this.id = value.id; + this.groupId = value.groupId; + this.projectId = value.projectId; + this.databaseDocumentId = value.databaseDocumentId; + this.databaseDocumentVersion = value.databaseDocumentVersion; + this.tableDocumentId = value.tableDocumentId; + this.tableColumnDocumentId = value.tableColumnDocumentId; + this.groupName = value.groupName; + this.groupDescription = value.groupDescription; + this.projectName = value.projectName; + this.projectDescription = value.projectDescription; + this.databaseName = value.databaseName; + this.schemaName = value.schemaName; + this.databaseProductName = value.databaseProductName; + this.databaseType = value.databaseType; + this.tableName = value.tableName; + this.tableComment = value.tableComment; + this.colName = value.colName; + this.colComment = value.colComment; + this.updateAt = value.updateAt; + this.createAt = value.createAt; + } + + public DocumentFullTextPojo( + Integer id, + Integer groupId, + Integer projectId, + Integer databaseDocumentId, + Integer databaseDocumentVersion, + Integer tableDocumentId, + Integer tableColumnDocumentId, + String groupName, + String groupDescription, + String projectName, + String projectDescription, + String databaseName, + String schemaName, + String databaseProductName, + String databaseType, + String tableName, + String tableComment, + String colName, + String colComment, + LocalDateTime updateAt, + LocalDateTime createAt + ) { + this.id = id; + this.groupId = groupId; + this.projectId = projectId; + this.databaseDocumentId = databaseDocumentId; + this.databaseDocumentVersion = databaseDocumentVersion; + this.tableDocumentId = tableDocumentId; + this.tableColumnDocumentId = tableColumnDocumentId; + this.groupName = groupName; + this.groupDescription = groupDescription; + this.projectName = projectName; + this.projectDescription = projectDescription; + this.databaseName = databaseName; + this.schemaName = schemaName; + this.databaseProductName = databaseProductName; + this.databaseType = databaseType; + this.tableName = tableName; + this.tableComment = tableComment; + this.colName = colName; + this.colComment = colComment; + this.updateAt = updateAt; + this.createAt = createAt; + } + + /** + * Getter for databasir.document_full_text.id. + */ + public Integer getId() { + return this.id; + } + + /** + * Setter for databasir.document_full_text.id. + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * Getter for databasir.document_full_text.group_id. ref to + * group.id + */ + public Integer getGroupId() { + return this.groupId; + } + + /** + * Setter for databasir.document_full_text.group_id. ref to + * group.id + */ + public void setGroupId(Integer groupId) { + this.groupId = groupId; + } + + /** + * Getter for databasir.document_full_text.project_id. ref to + * project.id, may null + */ + public Integer getProjectId() { + return this.projectId; + } + + /** + * Setter for databasir.document_full_text.project_id. ref to + * project.id, may null + */ + public void setProjectId(Integer projectId) { + this.projectId = projectId; + } + + /** + * Getter for + * databasir.document_full_text.database_document_id. ref to + * database_document.id, may null + */ + public Integer getDatabaseDocumentId() { + return this.databaseDocumentId; + } + + /** + * Setter for + * databasir.document_full_text.database_document_id. ref to + * database_document.id, may null + */ + public void setDatabaseDocumentId(Integer databaseDocumentId) { + this.databaseDocumentId = databaseDocumentId; + } + + /** + * Getter for + * databasir.document_full_text.database_document_version. rf + * to database_document.version, may null + */ + public Integer getDatabaseDocumentVersion() { + return this.databaseDocumentVersion; + } + + /** + * Setter for + * databasir.document_full_text.database_document_version. rf + * to database_document.version, may null + */ + public void setDatabaseDocumentVersion(Integer databaseDocumentVersion) { + this.databaseDocumentVersion = databaseDocumentVersion; + } + + /** + * Getter for databasir.document_full_text.table_document_id. + * ref to table_document.id, may null + */ + public Integer getTableDocumentId() { + return this.tableDocumentId; + } + + /** + * Setter for databasir.document_full_text.table_document_id. + * ref to table_document.id, may null + */ + public void setTableDocumentId(Integer tableDocumentId) { + this.tableDocumentId = tableDocumentId; + } + + /** + * Getter for + * databasir.document_full_text.table_column_document_id. ref + * to table_column_document.id, may null + */ + public Integer getTableColumnDocumentId() { + return this.tableColumnDocumentId; + } + + /** + * Setter for + * databasir.document_full_text.table_column_document_id. ref + * to table_column_document.id, may null + */ + public void setTableColumnDocumentId(Integer tableColumnDocumentId) { + this.tableColumnDocumentId = tableColumnDocumentId; + } + + /** + * Getter for databasir.document_full_text.group_name. + */ + public String getGroupName() { + return this.groupName; + } + + /** + * Setter for databasir.document_full_text.group_name. + */ + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + /** + * Getter for databasir.document_full_text.group_description. + */ + public String getGroupDescription() { + return this.groupDescription; + } + + /** + * Setter for databasir.document_full_text.group_description. + */ + public void setGroupDescription(String groupDescription) { + this.groupDescription = groupDescription; + } + + /** + * Getter for databasir.document_full_text.project_name. + */ + public String getProjectName() { + return this.projectName; + } + + /** + * Setter for databasir.document_full_text.project_name. + */ + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + /** + * Getter for databasir.document_full_text.project_description. + */ + public String getProjectDescription() { + return this.projectDescription; + } + + /** + * Setter for databasir.document_full_text.project_description. + */ + public void setProjectDescription(String projectDescription) { + this.projectDescription = projectDescription; + } + + /** + * Getter for databasir.document_full_text.database_name. + */ + public String getDatabaseName() { + return this.databaseName; + } + + /** + * Setter for databasir.document_full_text.database_name. + */ + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; + } + + /** + * Getter for databasir.document_full_text.schema_name. + */ + public String getSchemaName() { + return this.schemaName; + } + + /** + * Setter for databasir.document_full_text.schema_name. + */ + public void setSchemaName(String schemaName) { + this.schemaName = schemaName; + } + + /** + * Getter for + * databasir.document_full_text.database_product_name. + */ + public String getDatabaseProductName() { + return this.databaseProductName; + } + + /** + * Setter for + * databasir.document_full_text.database_product_name. + */ + public void setDatabaseProductName(String databaseProductName) { + this.databaseProductName = databaseProductName; + } + + /** + * Getter for databasir.document_full_text.database_type. + */ + public String getDatabaseType() { + return this.databaseType; + } + + /** + * Setter for databasir.document_full_text.database_type. + */ + public void setDatabaseType(String databaseType) { + this.databaseType = databaseType; + } + + /** + * Getter for databasir.document_full_text.table_name. + */ + public String getTableName() { + return this.tableName; + } + + /** + * Setter for databasir.document_full_text.table_name. + */ + public void setTableName(String tableName) { + this.tableName = tableName; + } + + /** + * Getter for databasir.document_full_text.table_comment. + */ + public String getTableComment() { + return this.tableComment; + } + + /** + * Setter for databasir.document_full_text.table_comment. + */ + public void setTableComment(String tableComment) { + this.tableComment = tableComment; + } + + /** + * Getter for databasir.document_full_text.col_name. + */ + public String getColName() { + return this.colName; + } + + /** + * Setter for databasir.document_full_text.col_name. + */ + public void setColName(String colName) { + this.colName = colName; + } + + /** + * Getter for databasir.document_full_text.col_comment. + */ + public String getColComment() { + return this.colComment; + } + + /** + * Setter for databasir.document_full_text.col_comment. + */ + public void setColComment(String colComment) { + this.colComment = colComment; + } + + /** + * Getter for databasir.document_full_text.update_at. + */ + public LocalDateTime getUpdateAt() { + return this.updateAt; + } + + /** + * Setter for databasir.document_full_text.update_at. + */ + public void setUpdateAt(LocalDateTime updateAt) { + this.updateAt = updateAt; + } + + /** + * Getter for databasir.document_full_text.create_at. + */ + public LocalDateTime getCreateAt() { + return this.createAt; + } + + /** + * Setter for databasir.document_full_text.create_at. + */ + public void setCreateAt(LocalDateTime createAt) { + this.createAt = createAt; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("DocumentFullTextPojo ("); + + sb.append(id); + sb.append(", ").append(groupId); + sb.append(", ").append(projectId); + sb.append(", ").append(databaseDocumentId); + sb.append(", ").append(databaseDocumentVersion); + sb.append(", ").append(tableDocumentId); + sb.append(", ").append(tableColumnDocumentId); + sb.append(", ").append(groupName); + sb.append(", ").append(groupDescription); + sb.append(", ").append(projectName); + sb.append(", ").append(projectDescription); + sb.append(", ").append(databaseName); + sb.append(", ").append(schemaName); + sb.append(", ").append(databaseProductName); + sb.append(", ").append(databaseType); + sb.append(", ").append(tableName); + sb.append(", ").append(tableComment); + sb.append(", ").append(colName); + sb.append(", ").append(colComment); + sb.append(", ").append(updateAt); + sb.append(", ").append(createAt); + + sb.append(")"); + return sb.toString(); + } +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/DocumentFullTextRecord.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/DocumentFullTextRecord.java new file mode 100644 index 0000000..ea16551 --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/DocumentFullTextRecord.java @@ -0,0 +1,901 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables.records; + + +import com.databasir.dao.tables.DocumentFullText; +import com.databasir.dao.tables.pojos.DocumentFullTextPojo; + +import java.time.LocalDateTime; + +import org.jooq.Field; +import org.jooq.Record1; +import org.jooq.Record21; +import org.jooq.Row21; +import org.jooq.impl.UpdatableRecordImpl; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class DocumentFullTextRecord extends UpdatableRecordImpl implements Record21 { + + private static final long serialVersionUID = 1L; + + /** + * Setter for databasir.document_full_text.id. + */ + public void setId(Integer value) { + set(0, value); + } + + /** + * Getter for databasir.document_full_text.id. + */ + public Integer getId() { + return (Integer) get(0); + } + + /** + * Setter for databasir.document_full_text.group_id. ref to + * group.id + */ + public void setGroupId(Integer value) { + set(1, value); + } + + /** + * Getter for databasir.document_full_text.group_id. ref to + * group.id + */ + public Integer getGroupId() { + return (Integer) get(1); + } + + /** + * Setter for databasir.document_full_text.project_id. ref to + * project.id, may null + */ + public void setProjectId(Integer value) { + set(2, value); + } + + /** + * Getter for databasir.document_full_text.project_id. ref to + * project.id, may null + */ + public Integer getProjectId() { + return (Integer) get(2); + } + + /** + * Setter for + * databasir.document_full_text.database_document_id. ref to + * database_document.id, may null + */ + public void setDatabaseDocumentId(Integer value) { + set(3, value); + } + + /** + * Getter for + * databasir.document_full_text.database_document_id. ref to + * database_document.id, may null + */ + public Integer getDatabaseDocumentId() { + return (Integer) get(3); + } + + /** + * Setter for + * databasir.document_full_text.database_document_version. rf + * to database_document.version, may null + */ + public void setDatabaseDocumentVersion(Integer value) { + set(4, value); + } + + /** + * Getter for + * databasir.document_full_text.database_document_version. rf + * to database_document.version, may null + */ + public Integer getDatabaseDocumentVersion() { + return (Integer) get(4); + } + + /** + * Setter for databasir.document_full_text.table_document_id. + * ref to table_document.id, may null + */ + public void setTableDocumentId(Integer value) { + set(5, value); + } + + /** + * Getter for databasir.document_full_text.table_document_id. + * ref to table_document.id, may null + */ + public Integer getTableDocumentId() { + return (Integer) get(5); + } + + /** + * Setter for + * databasir.document_full_text.table_column_document_id. ref + * to table_column_document.id, may null + */ + public void setTableColumnDocumentId(Integer value) { + set(6, value); + } + + /** + * Getter for + * databasir.document_full_text.table_column_document_id. ref + * to table_column_document.id, may null + */ + public Integer getTableColumnDocumentId() { + return (Integer) get(6); + } + + /** + * Setter for databasir.document_full_text.group_name. + */ + public void setGroupName(String value) { + set(7, value); + } + + /** + * Getter for databasir.document_full_text.group_name. + */ + public String getGroupName() { + return (String) get(7); + } + + /** + * Setter for databasir.document_full_text.group_description. + */ + public void setGroupDescription(String value) { + set(8, value); + } + + /** + * Getter for databasir.document_full_text.group_description. + */ + public String getGroupDescription() { + return (String) get(8); + } + + /** + * Setter for databasir.document_full_text.project_name. + */ + public void setProjectName(String value) { + set(9, value); + } + + /** + * Getter for databasir.document_full_text.project_name. + */ + public String getProjectName() { + return (String) get(9); + } + + /** + * Setter for databasir.document_full_text.project_description. + */ + public void setProjectDescription(String value) { + set(10, value); + } + + /** + * Getter for databasir.document_full_text.project_description. + */ + public String getProjectDescription() { + return (String) get(10); + } + + /** + * Setter for databasir.document_full_text.database_name. + */ + public void setDatabaseName(String value) { + set(11, value); + } + + /** + * Getter for databasir.document_full_text.database_name. + */ + public String getDatabaseName() { + return (String) get(11); + } + + /** + * Setter for databasir.document_full_text.schema_name. + */ + public void setSchemaName(String value) { + set(12, value); + } + + /** + * Getter for databasir.document_full_text.schema_name. + */ + public String getSchemaName() { + return (String) get(12); + } + + /** + * Setter for + * databasir.document_full_text.database_product_name. + */ + public void setDatabaseProductName(String value) { + set(13, value); + } + + /** + * Getter for + * databasir.document_full_text.database_product_name. + */ + public String getDatabaseProductName() { + return (String) get(13); + } + + /** + * Setter for databasir.document_full_text.database_type. + */ + public void setDatabaseType(String value) { + set(14, value); + } + + /** + * Getter for databasir.document_full_text.database_type. + */ + public String getDatabaseType() { + return (String) get(14); + } + + /** + * Setter for databasir.document_full_text.table_name. + */ + public void setTableName(String value) { + set(15, value); + } + + /** + * Getter for databasir.document_full_text.table_name. + */ + public String getTableName() { + return (String) get(15); + } + + /** + * Setter for databasir.document_full_text.table_comment. + */ + public void setTableComment(String value) { + set(16, value); + } + + /** + * Getter for databasir.document_full_text.table_comment. + */ + public String getTableComment() { + return (String) get(16); + } + + /** + * Setter for databasir.document_full_text.col_name. + */ + public void setColName(String value) { + set(17, value); + } + + /** + * Getter for databasir.document_full_text.col_name. + */ + public String getColName() { + return (String) get(17); + } + + /** + * Setter for databasir.document_full_text.col_comment. + */ + public void setColComment(String value) { + set(18, value); + } + + /** + * Getter for databasir.document_full_text.col_comment. + */ + public String getColComment() { + return (String) get(18); + } + + /** + * Setter for databasir.document_full_text.update_at. + */ + public void setUpdateAt(LocalDateTime value) { + set(19, value); + } + + /** + * Getter for databasir.document_full_text.update_at. + */ + public LocalDateTime getUpdateAt() { + return (LocalDateTime) get(19); + } + + /** + * Setter for databasir.document_full_text.create_at. + */ + public void setCreateAt(LocalDateTime value) { + set(20, value); + } + + /** + * Getter for databasir.document_full_text.create_at. + */ + public LocalDateTime getCreateAt() { + return (LocalDateTime) get(20); + } + + // ------------------------------------------------------------------------- + // Primary key information + // ------------------------------------------------------------------------- + + @Override + public Record1 key() { + return (Record1) super.key(); + } + + // ------------------------------------------------------------------------- + // Record21 type implementation + // ------------------------------------------------------------------------- + + @Override + public Row21 fieldsRow() { + return (Row21) super.fieldsRow(); + } + + @Override + public Row21 valuesRow() { + return (Row21) super.valuesRow(); + } + + @Override + public Field field1() { + return DocumentFullText.DOCUMENT_FULL_TEXT.ID; + } + + @Override + public Field field2() { + return DocumentFullText.DOCUMENT_FULL_TEXT.GROUP_ID; + } + + @Override + public Field field3() { + return DocumentFullText.DOCUMENT_FULL_TEXT.PROJECT_ID; + } + + @Override + public Field field4() { + return DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_DOCUMENT_ID; + } + + @Override + public Field field5() { + return DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_DOCUMENT_VERSION; + } + + @Override + public Field field6() { + return DocumentFullText.DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID; + } + + @Override + public Field field7() { + return DocumentFullText.DOCUMENT_FULL_TEXT.TABLE_COLUMN_DOCUMENT_ID; + } + + @Override + public Field field8() { + return DocumentFullText.DOCUMENT_FULL_TEXT.GROUP_NAME; + } + + @Override + public Field field9() { + return DocumentFullText.DOCUMENT_FULL_TEXT.GROUP_DESCRIPTION; + } + + @Override + public Field field10() { + return DocumentFullText.DOCUMENT_FULL_TEXT.PROJECT_NAME; + } + + @Override + public Field field11() { + return DocumentFullText.DOCUMENT_FULL_TEXT.PROJECT_DESCRIPTION; + } + + @Override + public Field field12() { + return DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_NAME; + } + + @Override + public Field field13() { + return DocumentFullText.DOCUMENT_FULL_TEXT.SCHEMA_NAME; + } + + @Override + public Field field14() { + return DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_PRODUCT_NAME; + } + + @Override + public Field field15() { + return DocumentFullText.DOCUMENT_FULL_TEXT.DATABASE_TYPE; + } + + @Override + public Field field16() { + return DocumentFullText.DOCUMENT_FULL_TEXT.TABLE_NAME; + } + + @Override + public Field field17() { + return DocumentFullText.DOCUMENT_FULL_TEXT.TABLE_COMMENT; + } + + @Override + public Field field18() { + return DocumentFullText.DOCUMENT_FULL_TEXT.COL_NAME; + } + + @Override + public Field field19() { + return DocumentFullText.DOCUMENT_FULL_TEXT.COL_COMMENT; + } + + @Override + public Field field20() { + return DocumentFullText.DOCUMENT_FULL_TEXT.UPDATE_AT; + } + + @Override + public Field field21() { + return DocumentFullText.DOCUMENT_FULL_TEXT.CREATE_AT; + } + + @Override + public Integer component1() { + return getId(); + } + + @Override + public Integer component2() { + return getGroupId(); + } + + @Override + public Integer component3() { + return getProjectId(); + } + + @Override + public Integer component4() { + return getDatabaseDocumentId(); + } + + @Override + public Integer component5() { + return getDatabaseDocumentVersion(); + } + + @Override + public Integer component6() { + return getTableDocumentId(); + } + + @Override + public Integer component7() { + return getTableColumnDocumentId(); + } + + @Override + public String component8() { + return getGroupName(); + } + + @Override + public String component9() { + return getGroupDescription(); + } + + @Override + public String component10() { + return getProjectName(); + } + + @Override + public String component11() { + return getProjectDescription(); + } + + @Override + public String component12() { + return getDatabaseName(); + } + + @Override + public String component13() { + return getSchemaName(); + } + + @Override + public String component14() { + return getDatabaseProductName(); + } + + @Override + public String component15() { + return getDatabaseType(); + } + + @Override + public String component16() { + return getTableName(); + } + + @Override + public String component17() { + return getTableComment(); + } + + @Override + public String component18() { + return getColName(); + } + + @Override + public String component19() { + return getColComment(); + } + + @Override + public LocalDateTime component20() { + return getUpdateAt(); + } + + @Override + public LocalDateTime component21() { + return getCreateAt(); + } + + @Override + public Integer value1() { + return getId(); + } + + @Override + public Integer value2() { + return getGroupId(); + } + + @Override + public Integer value3() { + return getProjectId(); + } + + @Override + public Integer value4() { + return getDatabaseDocumentId(); + } + + @Override + public Integer value5() { + return getDatabaseDocumentVersion(); + } + + @Override + public Integer value6() { + return getTableDocumentId(); + } + + @Override + public Integer value7() { + return getTableColumnDocumentId(); + } + + @Override + public String value8() { + return getGroupName(); + } + + @Override + public String value9() { + return getGroupDescription(); + } + + @Override + public String value10() { + return getProjectName(); + } + + @Override + public String value11() { + return getProjectDescription(); + } + + @Override + public String value12() { + return getDatabaseName(); + } + + @Override + public String value13() { + return getSchemaName(); + } + + @Override + public String value14() { + return getDatabaseProductName(); + } + + @Override + public String value15() { + return getDatabaseType(); + } + + @Override + public String value16() { + return getTableName(); + } + + @Override + public String value17() { + return getTableComment(); + } + + @Override + public String value18() { + return getColName(); + } + + @Override + public String value19() { + return getColComment(); + } + + @Override + public LocalDateTime value20() { + return getUpdateAt(); + } + + @Override + public LocalDateTime value21() { + return getCreateAt(); + } + + @Override + public DocumentFullTextRecord value1(Integer value) { + setId(value); + return this; + } + + @Override + public DocumentFullTextRecord value2(Integer value) { + setGroupId(value); + return this; + } + + @Override + public DocumentFullTextRecord value3(Integer value) { + setProjectId(value); + return this; + } + + @Override + public DocumentFullTextRecord value4(Integer value) { + setDatabaseDocumentId(value); + return this; + } + + @Override + public DocumentFullTextRecord value5(Integer value) { + setDatabaseDocumentVersion(value); + return this; + } + + @Override + public DocumentFullTextRecord value6(Integer value) { + setTableDocumentId(value); + return this; + } + + @Override + public DocumentFullTextRecord value7(Integer value) { + setTableColumnDocumentId(value); + return this; + } + + @Override + public DocumentFullTextRecord value8(String value) { + setGroupName(value); + return this; + } + + @Override + public DocumentFullTextRecord value9(String value) { + setGroupDescription(value); + return this; + } + + @Override + public DocumentFullTextRecord value10(String value) { + setProjectName(value); + return this; + } + + @Override + public DocumentFullTextRecord value11(String value) { + setProjectDescription(value); + return this; + } + + @Override + public DocumentFullTextRecord value12(String value) { + setDatabaseName(value); + return this; + } + + @Override + public DocumentFullTextRecord value13(String value) { + setSchemaName(value); + return this; + } + + @Override + public DocumentFullTextRecord value14(String value) { + setDatabaseProductName(value); + return this; + } + + @Override + public DocumentFullTextRecord value15(String value) { + setDatabaseType(value); + return this; + } + + @Override + public DocumentFullTextRecord value16(String value) { + setTableName(value); + return this; + } + + @Override + public DocumentFullTextRecord value17(String value) { + setTableComment(value); + return this; + } + + @Override + public DocumentFullTextRecord value18(String value) { + setColName(value); + return this; + } + + @Override + public DocumentFullTextRecord value19(String value) { + setColComment(value); + return this; + } + + @Override + public DocumentFullTextRecord value20(LocalDateTime value) { + setUpdateAt(value); + return this; + } + + @Override + public DocumentFullTextRecord value21(LocalDateTime value) { + setCreateAt(value); + return this; + } + + @Override + public DocumentFullTextRecord values(Integer value1, Integer value2, Integer value3, Integer value4, Integer value5, Integer value6, Integer value7, String value8, String value9, String value10, String value11, String value12, String value13, String value14, String value15, String value16, String value17, String value18, String value19, LocalDateTime value20, LocalDateTime value21) { + value1(value1); + value2(value2); + value3(value3); + value4(value4); + value5(value5); + value6(value6); + value7(value7); + value8(value8); + value9(value9); + value10(value10); + value11(value11); + value12(value12); + value13(value13); + value14(value14); + value15(value15); + value16(value16); + value17(value17); + value18(value18); + value19(value19); + value20(value20); + value21(value21); + return this; + } + + // ------------------------------------------------------------------------- + // Constructors + // ------------------------------------------------------------------------- + + /** + * Create a detached DocumentFullTextRecord + */ + public DocumentFullTextRecord() { + super(DocumentFullText.DOCUMENT_FULL_TEXT); + } + + /** + * Create a detached, initialised DocumentFullTextRecord + */ + public DocumentFullTextRecord(Integer id, Integer groupId, Integer projectId, Integer databaseDocumentId, Integer databaseDocumentVersion, Integer tableDocumentId, Integer tableColumnDocumentId, String groupName, String groupDescription, String projectName, String projectDescription, String databaseName, String schemaName, String databaseProductName, String databaseType, String tableName, String tableComment, String colName, String colComment, LocalDateTime updateAt, LocalDateTime createAt) { + super(DocumentFullText.DOCUMENT_FULL_TEXT); + + setId(id); + setGroupId(groupId); + setProjectId(projectId); + setDatabaseDocumentId(databaseDocumentId); + setDatabaseDocumentVersion(databaseDocumentVersion); + setTableDocumentId(tableDocumentId); + setTableColumnDocumentId(tableColumnDocumentId); + setGroupName(groupName); + setGroupDescription(groupDescription); + setProjectName(projectName); + setProjectDescription(projectDescription); + setDatabaseName(databaseName); + setSchemaName(schemaName); + setDatabaseProductName(databaseProductName); + setDatabaseType(databaseType); + setTableName(tableName); + setTableComment(tableComment); + setColName(colName); + setColComment(colComment); + setUpdateAt(updateAt); + setCreateAt(createAt); + } + + /** + * Create a detached, initialised DocumentFullTextRecord + */ + public DocumentFullTextRecord(DocumentFullTextPojo value) { + super(DocumentFullText.DOCUMENT_FULL_TEXT); + + if (value != null) { + setId(value.getId()); + setGroupId(value.getGroupId()); + setProjectId(value.getProjectId()); + setDatabaseDocumentId(value.getDatabaseDocumentId()); + setDatabaseDocumentVersion(value.getDatabaseDocumentVersion()); + setTableDocumentId(value.getTableDocumentId()); + setTableColumnDocumentId(value.getTableColumnDocumentId()); + setGroupName(value.getGroupName()); + setGroupDescription(value.getGroupDescription()); + setProjectName(value.getProjectName()); + setProjectDescription(value.getProjectDescription()); + setDatabaseName(value.getDatabaseName()); + setSchemaName(value.getSchemaName()); + setDatabaseProductName(value.getDatabaseProductName()); + setDatabaseType(value.getDatabaseType()); + setTableName(value.getTableName()); + setTableComment(value.getTableComment()); + setColName(value.getColName()); + setColComment(value.getColComment()); + setUpdateAt(value.getUpdateAt()); + setCreateAt(value.getCreateAt()); + } + } +} 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 1780078..f3401c0 100644 --- a/dao/src/main/java/com/databasir/dao/impl/BaseDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/BaseDao.java @@ -100,7 +100,7 @@ public abstract class BaseDao { + condition)); } - public List selectInIds(List ids) { + public List selectInIds(Collection ids) { if (ids == null || ids.isEmpty()) { return Collections.emptyList(); } diff --git a/dao/src/main/java/com/databasir/dao/impl/DocumentFullTextDao.java b/dao/src/main/java/com/databasir/dao/impl/DocumentFullTextDao.java new file mode 100644 index 0000000..61c81ab --- /dev/null +++ b/dao/src/main/java/com/databasir/dao/impl/DocumentFullTextDao.java @@ -0,0 +1,201 @@ +package com.databasir.dao.impl; + +import com.databasir.dao.tables.pojos.DocumentFullTextPojo; +import com.databasir.dao.value.FullTextProjectInfoUpdatePojo; +import lombok.Getter; +import org.jooq.DSLContext; +import org.jooq.TableField; +import org.jooq.impl.DSL; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Objects; + +import static com.databasir.dao.Tables.DOCUMENT_FULL_TEXT; + +@Repository +public class DocumentFullTextDao extends BaseDao { + + public static final String[] EMPTY = new String[0]; + + @Autowired + @Getter + private DSLContext dslContext; + + public DocumentFullTextDao() { + super(DOCUMENT_FULL_TEXT, DocumentFullTextPojo.class); + } + + public Page selectColumnPage(Pageable pageable, String keyword) { + + String[] fullTextMatchCols = new String[]{ + DOCUMENT_FULL_TEXT.COL_NAME.getName(), + DOCUMENT_FULL_TEXT.COL_COMMENT.getName(), + DOCUMENT_FULL_TEXT.DATABASE_PRODUCT_NAME.getName() + }; + String colSegment = String.join(",", fullTextMatchCols); + // sample: match(col_name, col_comment) against('+databasir' in boolean mode) + String fullTextMatchSqlSegment = new StringBuilder(64) + .append("MATCH(").append(colSegment).append(") ") + .append("AGAINST('+").append(keyword).append("' IN BOOLEAN MODE)") + .toString(); + // count + Integer total = dslContext.selectDistinct(DSL.count(DOCUMENT_FULL_TEXT.TABLE_COLUMN_DOCUMENT_ID)) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.TABLE_COLUMN_DOCUMENT_ID.isNotNull().and(fullTextMatchSqlSegment)) + .fetchOne(0, int.class); + // content + List content = dslContext.select(DOCUMENT_FULL_TEXT.fields()) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.TABLE_COLUMN_DOCUMENT_ID.isNotNull().and(fullTextMatchSqlSegment)) + .limit(pageable.getOffset(), pageable.getPageSize()) + .fetchInto(DocumentFullTextPojo.class); + return new PageImpl<>(content, pageable, total.longValue()); + } + + public Page selectTablePage(Pageable pageable, String keyword) { + String[] matchCols = new String[]{ + DOCUMENT_FULL_TEXT.TABLE_NAME.getName(), + DOCUMENT_FULL_TEXT.TABLE_COMMENT.getName(), + DOCUMENT_FULL_TEXT.DATABASE_PRODUCT_NAME.getName() + }; + TableField[] groupColumns = new TableField[]{ + DOCUMENT_FULL_TEXT.GROUP_ID, + DOCUMENT_FULL_TEXT.GROUP_NAME, + DOCUMENT_FULL_TEXT.GROUP_DESCRIPTION, + DOCUMENT_FULL_TEXT.PROJECT_ID, + DOCUMENT_FULL_TEXT.PROJECT_NAME, + DOCUMENT_FULL_TEXT.PROJECT_DESCRIPTION, + DOCUMENT_FULL_TEXT.DATABASE_NAME, + DOCUMENT_FULL_TEXT.SCHEMA_NAME, + DOCUMENT_FULL_TEXT.DATABASE_PRODUCT_NAME, + DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID, + DOCUMENT_FULL_TEXT.TABLE_NAME, + DOCUMENT_FULL_TEXT.TABLE_COMMENT, + }; + String colSegment = String.join(",", matchCols); + + // sample: match(col_name, col_comment) against('+databasir' in boolean mode) + String fullTextMatchSqlSegment = new StringBuilder(64) + .append("MATCH(").append(colSegment).append(") ") + .append("AGAINST('+").append(keyword).append("' IN BOOLEAN MODE)") + .toString(); + // count + Integer total = dslContext.selectDistinct(DSL.count(DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID)) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.PROJECT_ID.isNotNull() + .and(DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID.isNull()) + .and(fullTextMatchSqlSegment)) + .fetchOne(0, int.class); + // content + List content = dslContext.select(groupColumns) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.PROJECT_ID.isNotNull() + .and(DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID.isNotNull()) + .and(fullTextMatchSqlSegment)) + .groupBy(groupColumns) + .limit(pageable.getOffset(), pageable.getPageSize()) + .fetchInto(DocumentFullTextPojo.class); + return new PageImpl<>(content, pageable, total.longValue()); + } + + public Page selectProjectPage(Pageable pageable, String keyword) { + String[] matchCols = new String[]{ + DOCUMENT_FULL_TEXT.PROJECT_NAME.getName(), + DOCUMENT_FULL_TEXT.PROJECT_DESCRIPTION.getName(), + DOCUMENT_FULL_TEXT.SCHEMA_NAME.getName(), + DOCUMENT_FULL_TEXT.DATABASE_NAME.getName(), + DOCUMENT_FULL_TEXT.DATABASE_TYPE.getName(), + }; + String colSegment = String.join(",", matchCols); + // sample: match(col_name, col_comment) against('+databasir' in boolean mode) + String fullTextMatchSqlSegment = new StringBuilder(64) + .append("MATCH(").append(colSegment).append(") ") + .append("AGAINST('+").append(keyword).append("' IN BOOLEAN MODE)") + .toString(); + // count + Integer total = dslContext.selectDistinct(DSL.count(DOCUMENT_FULL_TEXT.PROJECT_ID)) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.PROJECT_ID.isNotNull() + .and(DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID.isNull()) + .and(fullTextMatchSqlSegment)) + .fetchOne(0, int.class); + // content + List content = dslContext.select(DOCUMENT_FULL_TEXT.fields()) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.PROJECT_ID.isNotNull() + .and(DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID.isNull()) + .and(fullTextMatchSqlSegment)) + .limit(pageable.getOffset(), pageable.getPageSize()) + .fetchInto(DocumentFullTextPojo.class); + return new PageImpl<>(content, pageable, total.longValue()); + } + + public Page selectGroupPage(Pageable pageable, String keyword) { + String[] matchCols = new String[]{ + DOCUMENT_FULL_TEXT.GROUP_NAME.getName(), + DOCUMENT_FULL_TEXT.GROUP_DESCRIPTION.getName() + }; + String colSegment = String.join(",", matchCols); + + String fullTextMatchSqlSegment = new StringBuilder(64) + .append("MATCH(").append(colSegment).append(") ") + .append("AGAINST('+").append(keyword).append("' IN BOOLEAN MODE)") + .toString(); + // count + Integer total = dslContext.selectDistinct(DSL.count(DOCUMENT_FULL_TEXT.GROUP_ID)) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.GROUP_ID.isNotNull() + .and(DOCUMENT_FULL_TEXT.PROJECT_ID.isNull()) + .and(fullTextMatchSqlSegment)) + .fetchOne(0, int.class); + // content + List content = dslContext.select(DOCUMENT_FULL_TEXT.fields()) + .from(DOCUMENT_FULL_TEXT) + .where(DOCUMENT_FULL_TEXT.GROUP_ID.isNotNull() + .and(DOCUMENT_FULL_TEXT.PROJECT_ID.isNull()) + .and(fullTextMatchSqlSegment)) + .limit(pageable.getOffset(), pageable.getPageSize()) + .fetchInto(DocumentFullTextPojo.class); + return new PageImpl<>(content, pageable, total.longValue()); + } + + public int deleteByTableId(Integer tableDocumentId) { + return this.delete(DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID.eq(tableDocumentId)); + } + + public int deleteByGroupId(Integer groupId) { + return this.delete(DOCUMENT_FULL_TEXT.GROUP_ID.eq(groupId)); + } + + public int deleteByProjectId(Integer projectId) { + return this.delete(DOCUMENT_FULL_TEXT.PROJECT_ID.eq(projectId)); + } + + public int updateGroupInfoByGroupId(String groupName, String groupDescription, Integer groupId) { + String description = Objects.requireNonNullElse(groupDescription, ""); + return this.getDslContext() + .update(DOCUMENT_FULL_TEXT) + .set(DOCUMENT_FULL_TEXT.GROUP_NAME, groupName) + .set(DOCUMENT_FULL_TEXT.GROUP_DESCRIPTION, description) + .where(DOCUMENT_FULL_TEXT.GROUP_ID.eq(groupId).and(DOCUMENT_FULL_TEXT.PROJECT_ID.isNull())) + .execute(); + } + + public int updateProjectInfoByProjectId(FullTextProjectInfoUpdatePojo updatePojo) { + return this.getDslContext() + .update(DOCUMENT_FULL_TEXT) + .set(DOCUMENT_FULL_TEXT.PROJECT_NAME, updatePojo.getProjectName()) + .set(DOCUMENT_FULL_TEXT.PROJECT_DESCRIPTION, updatePojo.getProjectDescription()) + .set(DOCUMENT_FULL_TEXT.DATABASE_NAME, updatePojo.getDatabaseName()) + .set(DOCUMENT_FULL_TEXT.SCHEMA_NAME, updatePojo.getSchemaName()) + .set(DOCUMENT_FULL_TEXT.DATABASE_TYPE, updatePojo.getDatabaseType()) + .where(DOCUMENT_FULL_TEXT.PROJECT_ID.eq(updatePojo.getProjectId()) + .and(DOCUMENT_FULL_TEXT.TABLE_DOCUMENT_ID.isNull())) + .execute(); + } +} 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 c9985fd..b53e91b 100644 --- a/dao/src/main/java/com/databasir/dao/impl/GroupDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/GroupDao.java @@ -10,6 +10,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.io.Serializable; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -47,7 +48,7 @@ public class GroupDao extends BaseDao { } @Override - public List selectInIds(List ids) { + public List selectInIds(Collection ids) { if (ids == null || ids.isEmpty()) { return Collections.emptyList(); } 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 bcdf419..85b3f62 100644 --- a/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java @@ -2,7 +2,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.ProjectPojo; import com.databasir.dao.value.GroupProjectCountPojo; -import com.databasir.dao.value.ProjectQueryPojo; import lombok.Getter; import org.jooq.Condition; import org.jooq.DSLContext; @@ -20,7 +19,8 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import static com.databasir.dao.Tables.*; +import static com.databasir.dao.Tables.DATA_SOURCE; +import static com.databasir.dao.Tables.PROJECT; @Repository public class ProjectDao extends BaseDao { @@ -127,27 +127,4 @@ public class ProjectDao extends BaseDao { .fetchMap(PROJECT.ID, PROJECT.GROUP_ID); } - public List selectByProjectNameOrDatabaseOrSchemaOrGroup(String query) { - return getDslContext() - .select( - PROJECT.ID.as("project_id"), - PROJECT.NAME.as("project_name"), - PROJECT.DESCRIPTION.as("project_description"), - DATA_SOURCE.DATABASE_NAME, - DATA_SOURCE.SCHEMA_NAME, - GROUP.NAME.as("group_name"), - GROUP.ID.as("group_id") - ) - .from(PROJECT) - .leftJoin(DATA_SOURCE).on(DATA_SOURCE.PROJECT_ID.eq(PROJECT.ID)) - .leftJoin(GROUP).on(GROUP.ID.eq(PROJECT.GROUP_ID)) - .where(PROJECT.DELETED.eq(false) - .and(GROUP.DELETED.eq(false)) - .and(PROJECT.NAME.contains(query) - .or(DATA_SOURCE.DATABASE_NAME.contains(query)) - .or(DATA_SOURCE.SCHEMA_NAME.contains(query)) - .or(GROUP.NAME.contains(query))) - ) - .fetchInto(ProjectQueryPojo.class); - } } diff --git a/dao/src/main/java/com/databasir/dao/value/FullTextProjectInfoUpdatePojo.java b/dao/src/main/java/com/databasir/dao/value/FullTextProjectInfoUpdatePojo.java new file mode 100644 index 0000000..c9e5a33 --- /dev/null +++ b/dao/src/main/java/com/databasir/dao/value/FullTextProjectInfoUpdatePojo.java @@ -0,0 +1,21 @@ +package com.databasir.dao.value; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class FullTextProjectInfoUpdatePojo { + + private Integer projectId; + + private String projectName; + + private String projectDescription; + + private String databaseType; + + private String databaseName; + + private String schemaName; +} diff --git a/dao/src/main/resources/db/init/init.sql b/dao/src/main/resources/db/init/init.sql index db47cd5..64db82d 100644 --- a/dao/src/main/resources/db/init/init.sql +++ b/dao/src/main/resources/db/init/init.sql @@ -378,4 +378,38 @@ CREATE TABLE IF NOT EXISTS project_sync_task INDEX idx_project_id (project_id), INDEX idx_user_id (user_id) ) CHARSET utf8mb4 - COLLATE utf8mb4_unicode_ci; \ No newline at end of file + COLLATE utf8mb4_unicode_ci; + +CREATE TABLE document_full_text +( + id INT PRIMARY KEY AUTO_INCREMENT, + `group_id` INT NOT NULL COMMENT 'ref to group.id', + `project_id` INT COMMENT 'ref to project.id, may null', + `database_document_id` INT COMMENT 'ref to database_document.id, may null', + `database_document_version` INT COMMENT 'rf to database_document.version, may null', + `table_document_id` INT COMMENT 'ref to table_document.id, may null', + `table_column_document_id` INT COMMENT 'ref to table_column_document.id, may null', + `group_name` VARCHAR(255), + `group_description` VARCHAR(512), + `project_name` VARCHAR(255), + `project_description` TEXT, + `database_name` TEXT, + `schema_name` TEXT, + `database_product_name` TEXT, + `database_type` TEXT, + `table_name` TEXT, + `table_comment` TEXT, + `col_name` TEXT, + `col_comment` TEXT, + update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + INDEX idx_group_id (group_id), + INDEX idx_project_id (project_id), + INDEX idx_table_document_id (table_document_id), + FULLTEXT fidx_column (col_name, col_comment, database_product_name) WITH PARSER ngram, + FULLTEXT fidx_table (`table_name`, table_comment, database_product_name) WITH PARSER ngram, + FULLTEXT fidx_project (project_name, project_description, schema_name, database_name, + database_type) WITH PARSER ngram, + FULLTEXT fidx_group (group_name, group_description) WITH PARSER ngram +) CHARSET utf8mb4 + COLLATE utf8mb4_unicode_ci; diff --git a/dao/src/main/resources/db/init/v1.0.5~v1.0.6 data migration.sql b/dao/src/main/resources/db/init/v1.0.5~v1.0.6 data migration.sql new file mode 100644 index 0000000..982ca47 --- /dev/null +++ b/dao/src/main/resources/db/init/v1.0.5~v1.0.6 data migration.sql @@ -0,0 +1,55 @@ +-- migration group info +INSERT INTO document_full_text(group_id, group_name, group_description) +SELECT `group`.id, `group`.name, `group`.description +FROM `group` + LEFT JOIN document_full_text dft ON `group`.id = dft.group_id +WHERE dft.group_id IS NULL + AND `group`.deleted = FALSE; + +-- migration project info +INSERT INTO document_full_text(group_id, project_id, project_name, project_description, database_name, schema_name, + database_type) +SELECT project.group_id, + project.id, + project.name, + project.description, + ds.database_name, + ds.schema_name, + ds.database_type +FROM project + LEFT JOIN document_full_text ON project.id = document_full_text.project_id + LEFT JOIN `group` g ON project.group_id = g.id + LEFT JOIN data_source ds ON project.id = ds.project_id +WHERE project.deleted = FALSE + AND g.deleted = FALSE + AND document_full_text.table_document_id IS NULL + AND document_full_text.project_id IS NULL; + + +-- migration column +INSERT INTO document_full_text(group_id, project_id, database_document_id, database_document_version, + table_document_id, table_column_document_id, database_name, schema_name, + database_product_name, table_name, table_comment, col_name, col_comment) +SELECT pj.group_id, + pj.id, + dd.id, + dd.version, + td.id, + tcd.id, + ds.database_type, + ds.schema_name, + dd.product_name, + td.name, + td.comment, + tcd.name, + tcd.comment +FROM table_column_document tcd + LEFT JOIN document_full_text dft ON dft.table_column_document_id = tcd.id + INNER JOIN table_document td ON tcd.table_document_id = td.id + INNER JOIN database_document dd ON tcd.database_document_id = dd.id + INNER JOIN project pj ON dd.project_id = pj.id + INNER JOIN data_source ds ON pj.id = ds.project_id +WHERE pj.deleted = FALSE + AND dd.is_archive = FALSE + AND dft.table_column_document_id IS NULL + AND dft.project_id IS NULL \ No newline at end of file diff --git a/dao/src/main/resources/db/migration/V1.4.4__document_full_text.sql b/dao/src/main/resources/db/migration/V1.4.4__document_full_text.sql new file mode 100644 index 0000000..7f5376e --- /dev/null +++ b/dao/src/main/resources/db/migration/V1.4.4__document_full_text.sql @@ -0,0 +1,33 @@ +CREATE TABLE document_full_text +( + id INT PRIMARY KEY AUTO_INCREMENT, + `group_id` INT NOT NULL COMMENT 'ref to group.id', + `project_id` INT COMMENT 'ref to project.id, may null', + `database_document_id` INT COMMENT 'ref to database_document.id, may null', + `database_document_version` INT COMMENT 'rf to database_document.version, may null', + `table_document_id` INT COMMENT 'ref to table_document.id, may null', + `table_column_document_id` INT COMMENT 'ref to table_column_document.id, may null', + `group_name` VARCHAR(255), + `group_description` VARCHAR(512), + `project_name` VARCHAR(255), + `project_description` TEXT, + `database_name` TEXT, + `schema_name` TEXT, + `database_product_name` TEXT, + `database_type` TEXT, + `table_name` TEXT, + `table_comment` TEXT, + `col_name` TEXT, + `col_comment` TEXT, + update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + INDEX IDX_GROUP_ID (group_id), + INDEX IDX_PROJECT_ID (project_id), + INDEX IDX_TABLE_DOCUMENT_ID (table_document_id), + FULLTEXT FIDX_COLUMN (col_name, col_comment, database_product_name) WITH PARSER ngram, + FULLTEXT FIDX_TABLE (`table_name`, table_comment, database_product_name) WITH PARSER ngram, + FULLTEXT FIDX_PROJECT (project_name, project_description, SCHEMA_NAME, database_name, + database_type) WITH PARSER ngram, + FULLTEXT FIDX_GROUP (group_name, group_description) WITH PARSER ngram +) CHARSET utf8mb4 + COLLATE utf8mb4_unicode_ci; \ No newline at end of file diff --git a/databasir-frontend b/databasir-frontend index f67d6b7..7c6bacd 160000 --- a/databasir-frontend +++ b/databasir-frontend @@ -1 +1 @@ -Subproject commit f67d6b70df557fe7f156c23c5b81922bd2fab404 +Subproject commit 7c6bacd74e5a82e754afa4ea26d648e491e5f129