feature: support add description to table or column (#46)

* feat: generate document description model

* feat: add description field to document

* fix: checkstyle

* feat:update frontend resources
This commit is contained in:
vran 2022-03-13 19:52:15 +08:00 committed by GitHub
parent e85e0e6e70
commit 6e798f4d97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 1051 additions and 40 deletions

View File

@ -0,0 +1,41 @@
package com.databasir.api;
import com.databasir.api.config.security.DatabasirUserDetails;
import com.databasir.common.JsonData;
import com.databasir.core.domain.description.data.DocumentDescriptionSaveRequest;
import com.databasir.core.domain.description.service.DocumentDescriptionService;
import com.databasir.core.domain.log.annotation.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RestController
@Validated
@RequiredArgsConstructor
public class DocumentDescriptionController {
private final DocumentDescriptionService documentDescriptionService;
@PostMapping(Routes.DocumentDescription.SAVE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)")
@Operation(module = Operation.Modules.PROJECT,
name = "更新描述",
involvedProjectId = "#projectId")
public JsonData<Void> save(@PathVariable Integer groupId,
@PathVariable Integer projectId,
@RequestBody @Valid DocumentDescriptionSaveRequest request) {
DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext()
.getAuthentication()
.getPrincipal();
Integer userId = principal.getUserPojo().getId();
documentDescriptionService.save(groupId, projectId, userId, request);
return JsonData.ok();
}
}

View File

@ -96,6 +96,13 @@ public interface Routes {
String DELETE = DISCUSSION_BASE + "/{discussionId}";
}
interface DocumentDescription {
String DISCUSSION_BASE = BASE + "/groups/{groupId}/projects/{projectId}/descriptions";
String SAVE = DISCUSSION_BASE;
}
interface Setting {
String GET_SYS_EMAIL = BASE + "/settings/sys_email";

View File

@ -1 +1 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><script defer="defer" type="module" src="/js/chunk-vendors.45746587.js"></script><script defer="defer" type="module" src="/js/app.6aec33ce.js"></script><link href="/css/chunk-vendors.8e1003a6.css" rel="stylesheet"><link href="/css/app.757c1ef3.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.54c3660b.js" nomodule></script><script defer="defer" src="/js/app-legacy.b19c33c1.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><script defer="defer" type="module" src="/js/chunk-vendors.45746587.js"></script><script defer="defer" type="module" src="/js/app.92d4b356.js"></script><link href="/css/chunk-vendors.8e1003a6.css" rel="stylesheet"><link href="/css/app.757c1ef3.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.54c3660b.js" nomodule></script><script defer="defer" src="/js/app-legacy.8031b9be.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,17 @@
package com.databasir.core.domain.description.converter;
import com.databasir.core.domain.description.data.DocumentDescriptionSaveRequest;
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(componentModel = "spring")
public interface DocumentDescriptionPojoConverter {
@Mapping(target = "id", ignore = true)
@Mapping(target = "createAt", ignore = true)
@Mapping(target = "updateAt", ignore = true)
DocumentDescriptionPojo of(Integer projectId,
Integer updateBy,
DocumentDescriptionSaveRequest request);
}

View File

@ -0,0 +1,14 @@
package com.databasir.core.domain.description.data;
import lombok.Data;
@Data
public class DocumentDescriptionSaveRequest {
private String tableName;
private String columnName;
private String content;
}

View File

@ -0,0 +1,32 @@
package com.databasir.core.domain.description.service;
import com.databasir.core.domain.description.converter.DocumentDescriptionPojoConverter;
import com.databasir.core.domain.description.data.DocumentDescriptionSaveRequest;
import com.databasir.dao.impl.DocumentDescriptionDao;
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
public class DocumentDescriptionService {
private final DocumentDescriptionDao documentDescriptionDao;
private final DocumentDescriptionPojoConverter documentDescriptionPojoConverter;
@Transactional
public void save(Integer groupId,
Integer projectId,
Integer userId,
DocumentDescriptionSaveRequest request) {
DocumentDescriptionPojo pojo = documentDescriptionPojoConverter.of(projectId, userId, request);
if (!documentDescriptionDao.exists(projectId, request.getTableName(), request.getColumnName())) {
documentDescriptionDao.insertAndReturnId(pojo);
} else {
documentDescriptionDao.update(pojo);
}
}
}

View File

@ -28,21 +28,25 @@ public interface DocumentResponseConverter {
@SuppressWarnings("checkstyle:all")
DatabaseDocumentResponse.TableDocumentResponse of(TableDocumentPojo tableDocument,
Integer discussionCount,
String description,
List<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse> columns,
List<TableIndexDocumentPojo> indexes,
List<TableTriggerDocumentPojo> triggers);
DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse of(TableColumnDocumentPojo pojo,
Integer discussionCount);
Integer discussionCount,
String description);
default List<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse> of(
List<TableColumnDocumentPojo> columns,
String tableName,
Map<String, Integer> discussionCountMapByJoinName) {
Map<String, Integer> discussionCountMapByJoinName,
Map<String, String> descriptionMapByJoinName) {
return columns.stream()
.map(column -> {
Integer count = discussionCountMapByJoinName.get(tableName + "." + column.getName());
return of(column, count);
String description = descriptionMapByJoinName.get(tableName + "." + column.getName());
return of(column, count, description);
})
.collect(Collectors.toList());
}

View File

@ -21,14 +21,18 @@ public interface DocumentSimpleResponseConverter {
DatabaseDocumentSimpleResponse of(DatabaseDocumentPojo databaseDocument,
List<DatabaseDocumentSimpleResponse.TableData> tables);
DatabaseDocumentSimpleResponse.TableData of(TableDocumentPojo tables, Integer discussionCount);
DatabaseDocumentSimpleResponse.TableData of(TableDocumentPojo tables,
Integer discussionCount,
String description);
default List<DatabaseDocumentSimpleResponse.TableData> of(List<TableDocumentPojo> tables,
Map<String, Integer> discussionCountMapByTableName) {
Map<String, Integer> discussionCountMapByTableName,
Map<String, String> descriptionMapByTableName) {
return tables.stream()
.map(table -> {
Integer count = discussionCountMapByTableName.get(table.getName());
return of(table, count);
String description = descriptionMapByTableName.get(table.getName());
return of(table, count, description);
})
.collect(Collectors.toList());
}

View File

@ -48,6 +48,8 @@ public class DatabaseDocumentResponse {
private Integer discussionCount;
private String description;
@Builder.Default
private List<ColumnDocumentResponse> columns = new ArrayList<>();
@ -76,6 +78,8 @@ public class DatabaseDocumentResponse {
private String comment;
private String description;
private Boolean isPrimaryKey;
private String nullable;

View File

@ -37,5 +37,7 @@ public class DatabaseDocumentSimpleResponse {
private String comment;
private Integer discussionCount;
private String description;
}
}

View File

@ -59,6 +59,8 @@ public class DocumentService {
private final DocumentDiscussionDao documentDiscussionDao;
private final DocumentDescriptionDao documentDescriptionDao;
private final DocumentPojoConverter documentPojoConverter;
private final DocumentResponseConverter documentResponseConverter;
@ -146,7 +148,15 @@ public class DocumentService {
documentDiscussionDao.selectTableDiscussionCount(projectId)
.stream()
.collect(Collectors.toMap(d -> d.getTableName(), d -> d.getCount(), (a, b) -> a));
var tableMetas = documentSimpleResponseConverter.of(tables, discussionCountMapByTableName);
Map<String, String> descriptionMapByTableName =
documentDescriptionDao.selectTableDescriptionByProjectId(projectId)
.stream()
.collect(Collectors.toMap(d -> d.getTableName(), d -> d.getContent(), (a, b) -> a));
var tableMetas = documentSimpleResponseConverter.of(
tables,
discussionCountMapByTableName,
descriptionMapByTableName
);
return documentSimpleResponseConverter.of(document, tableMetas);
});
}
@ -206,19 +216,26 @@ public class DocumentService {
}
var tables =
tableDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
// column
var columns =
tableColumnDocumentDao.selectByDatabaseDocumentIdAndTableIdIn(databaseDocumentId, tableIds);
var indexes =
tableIndexDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
var triggers =
tableTriggerDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
var discussions = documentDiscussionDao.selectAllDiscussionCount(projectId);
Map<Integer, List<TableColumnDocumentPojo>> columnsGroupByTableMetaId = columns.stream()
.collect(Collectors.groupingBy(TableColumnDocumentPojo::getTableDocumentId));
// index
var indexes =
tableIndexDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
Map<Integer, List<TableIndexDocumentPojo>> indexesGroupByTableMetaId = indexes.stream()
.collect(Collectors.groupingBy(TableIndexDocumentPojo::getTableDocumentId));
// trigger
var triggers =
tableTriggerDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
Map<Integer, List<TableTriggerDocumentPojo>> triggersGroupByTableMetaId = triggers.stream()
.collect(Collectors.groupingBy(TableTriggerDocumentPojo::getTableDocumentId));
// discussion
var discussions = documentDiscussionDao.selectAllDiscussionCount(projectId);
Map<String, Integer> discussionCountMapByJoinName = discussions.stream()
.collect(Collectors.toMap(
d -> String.join(".",
@ -226,6 +243,17 @@ public class DocumentService {
StringUtils.defaultIfBlank(d.getColumnName(), "")),
DocumentDiscussionCountPojo::getCount,
(a, b) -> a));
// description
var descriptions = documentDescriptionDao.selectByProjectId(projectId);
Map<String, String> descriptionMapByJoinName = descriptions.stream()
.collect(Collectors.toMap(
d -> String.join(".",
d.getTableName(),
StringUtils.defaultIfBlank(d.getColumnName(), "")),
DocumentDescriptionPojo::getContent,
(a, b) -> a));
return tables.stream()
.map(table -> {
Integer tableId = table.getId();
@ -233,9 +261,15 @@ public class DocumentService {
var subIndexes = indexesGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
var subTriggers = triggersGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
var discussionCount = discussionCountMapByJoinName.get(table.getName());
var description = descriptionMapByJoinName.get(table.getName());
var columnResponses =
documentResponseConverter.of(subColumns, table.getName(), discussionCountMapByJoinName);
return documentResponseConverter.of(table, discussionCount, columnResponses, subIndexes,
documentResponseConverter.of(
subColumns,
table.getName(),
discussionCountMapByJoinName,
descriptionMapByJoinName);
return documentResponseConverter.of(table, discussionCount, description, columnResponses,
subIndexes,
subTriggers);
})
.collect(Collectors.toList());

View File

@ -8,6 +8,7 @@ import com.databasir.dao.tables.DataSource;
import com.databasir.dao.tables.DataSourceProperty;
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.Group;
import com.databasir.dao.tables.Login;
@ -66,6 +67,11 @@ public class Databasir extends SchemaImpl {
*/
public final DatabaseType DATABASE_TYPE = DatabaseType.DATABASE_TYPE;
/**
* custom document description
*/
public final DocumentDescription DOCUMENT_DESCRIPTION = DocumentDescription.DOCUMENT_DESCRIPTION;
/**
* The table <code>databasir.document_discussion</code>.
*/
@ -166,6 +172,7 @@ public class Databasir extends SchemaImpl {
DataSourceProperty.DATA_SOURCE_PROPERTY,
DatabaseDocument.DATABASE_DOCUMENT,
DatabaseType.DATABASE_TYPE,
DocumentDescription.DOCUMENT_DESCRIPTION,
DocumentDiscussion.DOCUMENT_DISCUSSION,
Group.GROUP,
Login.LOGIN,

View File

@ -8,6 +8,7 @@ import com.databasir.dao.tables.DataSource;
import com.databasir.dao.tables.DataSourceProperty;
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.Group;
import com.databasir.dao.tables.Login;
@ -28,6 +29,7 @@ import com.databasir.dao.tables.records.DataSourcePropertyRecord;
import com.databasir.dao.tables.records.DataSourceRecord;
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.GroupRecord;
import com.databasir.dao.tables.records.LoginRecord;
@ -68,6 +70,8 @@ public class Keys {
public static final UniqueKey<DatabaseDocumentRecord> KEY_DATABASE_DOCUMENT_PRIMARY = Internal.createUniqueKey(DatabaseDocument.DATABASE_DOCUMENT, DSL.name("KEY_database_document_PRIMARY"), new TableField[] { DatabaseDocument.DATABASE_DOCUMENT.ID }, true);
public static final UniqueKey<DatabaseTypeRecord> KEY_DATABASE_TYPE_PRIMARY = Internal.createUniqueKey(DatabaseType.DATABASE_TYPE, DSL.name("KEY_database_type_PRIMARY"), new TableField[] { DatabaseType.DATABASE_TYPE.ID }, true);
public static final UniqueKey<DatabaseTypeRecord> KEY_DATABASE_TYPE_UK_DATABASE_TYPE_DELETED_DELETED_TOKEN = Internal.createUniqueKey(DatabaseType.DATABASE_TYPE, DSL.name("KEY_database_type_uk_database_type_deleted_deleted_token"), new TableField[] { DatabaseType.DATABASE_TYPE.DATABASE_TYPE_, DatabaseType.DATABASE_TYPE.DELETED, DatabaseType.DATABASE_TYPE.DELETED_TOKEN }, true);
public static final UniqueKey<DocumentDescriptionRecord> 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<DocumentDescriptionRecord> 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<DocumentDiscussionRecord> 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<GroupRecord> KEY_GROUP_PRIMARY = Internal.createUniqueKey(Group.GROUP, DSL.name("KEY_group_PRIMARY"), new TableField[] { Group.GROUP.ID }, true);
public static final UniqueKey<LoginRecord> KEY_LOGIN_PRIMARY = Internal.createUniqueKey(Login.LOGIN, DSL.name("KEY_login_PRIMARY"), new TableField[] { Login.LOGIN.ID }, true);

View File

@ -8,6 +8,7 @@ import com.databasir.dao.tables.DataSource;
import com.databasir.dao.tables.DataSourceProperty;
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.Group;
import com.databasir.dao.tables.Login;
@ -52,6 +53,11 @@ public class Tables {
*/
public static final DatabaseType DATABASE_TYPE = DatabaseType.DATABASE_TYPE;
/**
* custom document description
*/
public static final DocumentDescription DOCUMENT_DESCRIPTION = DocumentDescription.DOCUMENT_DESCRIPTION;
/**
* The table <code>databasir.document_discussion</code>.
*/

View File

@ -0,0 +1,181 @@
/*
* This file is generated by jOOQ.
*/
package com.databasir.dao.tables;
import com.databasir.dao.Databasir;
import com.databasir.dao.Keys;
import com.databasir.dao.tables.records.DocumentDescriptionRecord;
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.Name;
import org.jooq.Record;
import org.jooq.Row8;
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;
/**
* custom document description
*/
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class DocumentDescription extends TableImpl<DocumentDescriptionRecord> {
private static final long serialVersionUID = 1L;
/**
* The reference instance of <code>databasir.document_description</code>
*/
public static final DocumentDescription DOCUMENT_DESCRIPTION = new DocumentDescription();
/**
* The class holding records for this type
*/
@Override
public Class<DocumentDescriptionRecord> getRecordType() {
return DocumentDescriptionRecord.class;
}
/**
* The column <code>databasir.document_description.id</code>.
*/
public final TableField<DocumentDescriptionRecord, Integer> ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, "");
/**
* The column <code>databasir.document_description.content</code>.
*/
public final TableField<DocumentDescriptionRecord, String> CONTENT = createField(DSL.name("content"), SQLDataType.CLOB.nullable(false), this, "");
/**
* The column <code>databasir.document_description.project_id</code>.
*/
public final TableField<DocumentDescriptionRecord, Integer> PROJECT_ID = createField(DSL.name("project_id"), SQLDataType.INTEGER.nullable(false), this, "");
/**
* The column <code>databasir.document_description.table_name</code>.
*/
public final TableField<DocumentDescriptionRecord, String> TABLE_NAME = createField(DSL.name("table_name"), SQLDataType.VARCHAR(255).nullable(false), this, "");
/**
* The column <code>databasir.document_description.column_name</code>.
*/
public final TableField<DocumentDescriptionRecord, String> COLUMN_NAME = createField(DSL.name("column_name"), SQLDataType.VARCHAR(255), this, "");
/**
* The column <code>databasir.document_description.update_by</code>.
*/
public final TableField<DocumentDescriptionRecord, Integer> UPDATE_BY = createField(DSL.name("update_by"), SQLDataType.INTEGER.nullable(false), this, "");
/**
* The column <code>databasir.document_description.update_at</code>.
*/
public final TableField<DocumentDescriptionRecord, LocalDateTime> UPDATE_AT = createField(DSL.name("update_at"), SQLDataType.LOCALDATETIME(0).nullable(false).defaultValue(DSL.field("CURRENT_TIMESTAMP", SQLDataType.LOCALDATETIME)), this, "");
/**
* The column <code>databasir.document_description.create_at</code>.
*/
public final TableField<DocumentDescriptionRecord, LocalDateTime> CREATE_AT = createField(DSL.name("create_at"), SQLDataType.LOCALDATETIME(0).nullable(false).defaultValue(DSL.field("CURRENT_TIMESTAMP", SQLDataType.LOCALDATETIME)), this, "");
private DocumentDescription(Name alias, Table<DocumentDescriptionRecord> aliased) {
this(alias, aliased, null);
}
private DocumentDescription(Name alias, Table<DocumentDescriptionRecord> aliased, Field<?>[] parameters) {
super(alias, null, aliased, parameters, DSL.comment("custom document description"), TableOptions.table());
}
/**
* Create an aliased <code>databasir.document_description</code> table
* reference
*/
public DocumentDescription(String alias) {
this(DSL.name(alias), DOCUMENT_DESCRIPTION);
}
/**
* Create an aliased <code>databasir.document_description</code> table
* reference
*/
public DocumentDescription(Name alias) {
this(alias, DOCUMENT_DESCRIPTION);
}
/**
* Create a <code>databasir.document_description</code> table reference
*/
public DocumentDescription() {
this(DSL.name("document_description"), null);
}
public <O extends Record> DocumentDescription(Table<O> child, ForeignKey<O, DocumentDescriptionRecord> key) {
super(child, key, DOCUMENT_DESCRIPTION);
}
@Override
public Schema getSchema() {
return aliased() ? null : Databasir.DATABASIR;
}
@Override
public Identity<DocumentDescriptionRecord, Integer> getIdentity() {
return (Identity<DocumentDescriptionRecord, Integer>) super.getIdentity();
}
@Override
public UniqueKey<DocumentDescriptionRecord> getPrimaryKey() {
return Keys.KEY_DOCUMENT_DESCRIPTION_PRIMARY;
}
@Override
public List<UniqueKey<DocumentDescriptionRecord>> getUniqueKeys() {
return Arrays.asList(Keys.KEY_DOCUMENT_DESCRIPTION_UK_PROJECT_ID_TABLE_NAME_COLUMN_NAME);
}
@Override
public DocumentDescription as(String alias) {
return new DocumentDescription(DSL.name(alias), this);
}
@Override
public DocumentDescription as(Name alias) {
return new DocumentDescription(alias, this);
}
/**
* Rename this table
*/
@Override
public DocumentDescription rename(String name) {
return new DocumentDescription(DSL.name(name), null);
}
/**
* Rename this table
*/
@Override
public DocumentDescription rename(Name name) {
return new DocumentDescription(name, null);
}
// -------------------------------------------------------------------------
// Row8 type methods
// -------------------------------------------------------------------------
@Override
public Row8<Integer, String, Integer, String, String, Integer, LocalDateTime, LocalDateTime> fieldsRow() {
return (Row8) super.fieldsRow();
}
}

View File

@ -0,0 +1,189 @@
/*
* This file is generated by jOOQ.
*/
package com.databasir.dao.tables.pojos;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* custom document description
*/
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class DocumentDescriptionPojo implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String content;
private Integer projectId;
private String tableName;
private String columnName;
private Integer updateBy;
private LocalDateTime updateAt;
private LocalDateTime createAt;
public DocumentDescriptionPojo() {}
public DocumentDescriptionPojo(DocumentDescriptionPojo value) {
this.id = value.id;
this.content = value.content;
this.projectId = value.projectId;
this.tableName = value.tableName;
this.columnName = value.columnName;
this.updateBy = value.updateBy;
this.updateAt = value.updateAt;
this.createAt = value.createAt;
}
public DocumentDescriptionPojo(
Integer id,
String content,
Integer projectId,
String tableName,
String columnName,
Integer updateBy,
LocalDateTime updateAt,
LocalDateTime createAt
) {
this.id = id;
this.content = content;
this.projectId = projectId;
this.tableName = tableName;
this.columnName = columnName;
this.updateBy = updateBy;
this.updateAt = updateAt;
this.createAt = createAt;
}
/**
* Getter for <code>databasir.document_description.id</code>.
*/
public Integer getId() {
return this.id;
}
/**
* Setter for <code>databasir.document_description.id</code>.
*/
public void setId(Integer id) {
this.id = id;
}
/**
* Getter for <code>databasir.document_description.content</code>.
*/
public String getContent() {
return this.content;
}
/**
* Setter for <code>databasir.document_description.content</code>.
*/
public void setContent(String content) {
this.content = content;
}
/**
* Getter for <code>databasir.document_description.project_id</code>.
*/
public Integer getProjectId() {
return this.projectId;
}
/**
* Setter for <code>databasir.document_description.project_id</code>.
*/
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
/**
* Getter for <code>databasir.document_description.table_name</code>.
*/
public String getTableName() {
return this.tableName;
}
/**
* Setter for <code>databasir.document_description.table_name</code>.
*/
public void setTableName(String tableName) {
this.tableName = tableName;
}
/**
* Getter for <code>databasir.document_description.column_name</code>.
*/
public String getColumnName() {
return this.columnName;
}
/**
* Setter for <code>databasir.document_description.column_name</code>.
*/
public void setColumnName(String columnName) {
this.columnName = columnName;
}
/**
* Getter for <code>databasir.document_description.update_by</code>.
*/
public Integer getUpdateBy() {
return this.updateBy;
}
/**
* Setter for <code>databasir.document_description.update_by</code>.
*/
public void setUpdateBy(Integer updateBy) {
this.updateBy = updateBy;
}
/**
* Getter for <code>databasir.document_description.update_at</code>.
*/
public LocalDateTime getUpdateAt() {
return this.updateAt;
}
/**
* Setter for <code>databasir.document_description.update_at</code>.
*/
public void setUpdateAt(LocalDateTime updateAt) {
this.updateAt = updateAt;
}
/**
* Getter for <code>databasir.document_description.create_at</code>.
*/
public LocalDateTime getCreateAt() {
return this.createAt;
}
/**
* Setter for <code>databasir.document_description.create_at</code>.
*/
public void setCreateAt(LocalDateTime createAt) {
this.createAt = createAt;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("DocumentDescriptionPojo (");
sb.append(id);
sb.append(", ").append(content);
sb.append(", ").append(projectId);
sb.append(", ").append(tableName);
sb.append(", ").append(columnName);
sb.append(", ").append(updateBy);
sb.append(", ").append(updateAt);
sb.append(", ").append(createAt);
sb.append(")");
return sb.toString();
}
}

View File

@ -0,0 +1,387 @@
/*
* This file is generated by jOOQ.
*/
package com.databasir.dao.tables.records;
import com.databasir.dao.tables.DocumentDescription;
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
import java.time.LocalDateTime;
import org.jooq.Field;
import org.jooq.Record1;
import org.jooq.Record8;
import org.jooq.Row8;
import org.jooq.impl.UpdatableRecordImpl;
/**
* custom document description
*/
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class DocumentDescriptionRecord extends UpdatableRecordImpl<DocumentDescriptionRecord> implements Record8<Integer, String, Integer, String, String, Integer, LocalDateTime, LocalDateTime> {
private static final long serialVersionUID = 1L;
/**
* Setter for <code>databasir.document_description.id</code>.
*/
public void setId(Integer value) {
set(0, value);
}
/**
* Getter for <code>databasir.document_description.id</code>.
*/
public Integer getId() {
return (Integer) get(0);
}
/**
* Setter for <code>databasir.document_description.content</code>.
*/
public void setContent(String value) {
set(1, value);
}
/**
* Getter for <code>databasir.document_description.content</code>.
*/
public String getContent() {
return (String) get(1);
}
/**
* Setter for <code>databasir.document_description.project_id</code>.
*/
public void setProjectId(Integer value) {
set(2, value);
}
/**
* Getter for <code>databasir.document_description.project_id</code>.
*/
public Integer getProjectId() {
return (Integer) get(2);
}
/**
* Setter for <code>databasir.document_description.table_name</code>.
*/
public void setTableName(String value) {
set(3, value);
}
/**
* Getter for <code>databasir.document_description.table_name</code>.
*/
public String getTableName() {
return (String) get(3);
}
/**
* Setter for <code>databasir.document_description.column_name</code>.
*/
public void setColumnName(String value) {
set(4, value);
}
/**
* Getter for <code>databasir.document_description.column_name</code>.
*/
public String getColumnName() {
return (String) get(4);
}
/**
* Setter for <code>databasir.document_description.update_by</code>.
*/
public void setUpdateBy(Integer value) {
set(5, value);
}
/**
* Getter for <code>databasir.document_description.update_by</code>.
*/
public Integer getUpdateBy() {
return (Integer) get(5);
}
/**
* Setter for <code>databasir.document_description.update_at</code>.
*/
public void setUpdateAt(LocalDateTime value) {
set(6, value);
}
/**
* Getter for <code>databasir.document_description.update_at</code>.
*/
public LocalDateTime getUpdateAt() {
return (LocalDateTime) get(6);
}
/**
* Setter for <code>databasir.document_description.create_at</code>.
*/
public void setCreateAt(LocalDateTime value) {
set(7, value);
}
/**
* Getter for <code>databasir.document_description.create_at</code>.
*/
public LocalDateTime getCreateAt() {
return (LocalDateTime) get(7);
}
// -------------------------------------------------------------------------
// Primary key information
// -------------------------------------------------------------------------
@Override
public Record1<Integer> key() {
return (Record1) super.key();
}
// -------------------------------------------------------------------------
// Record8 type implementation
// -------------------------------------------------------------------------
@Override
public Row8<Integer, String, Integer, String, String, Integer, LocalDateTime, LocalDateTime> fieldsRow() {
return (Row8) super.fieldsRow();
}
@Override
public Row8<Integer, String, Integer, String, String, Integer, LocalDateTime, LocalDateTime> valuesRow() {
return (Row8) super.valuesRow();
}
@Override
public Field<Integer> field1() {
return DocumentDescription.DOCUMENT_DESCRIPTION.ID;
}
@Override
public Field<String> field2() {
return DocumentDescription.DOCUMENT_DESCRIPTION.CONTENT;
}
@Override
public Field<Integer> field3() {
return DocumentDescription.DOCUMENT_DESCRIPTION.PROJECT_ID;
}
@Override
public Field<String> field4() {
return DocumentDescription.DOCUMENT_DESCRIPTION.TABLE_NAME;
}
@Override
public Field<String> field5() {
return DocumentDescription.DOCUMENT_DESCRIPTION.COLUMN_NAME;
}
@Override
public Field<Integer> field6() {
return DocumentDescription.DOCUMENT_DESCRIPTION.UPDATE_BY;
}
@Override
public Field<LocalDateTime> field7() {
return DocumentDescription.DOCUMENT_DESCRIPTION.UPDATE_AT;
}
@Override
public Field<LocalDateTime> field8() {
return DocumentDescription.DOCUMENT_DESCRIPTION.CREATE_AT;
}
@Override
public Integer component1() {
return getId();
}
@Override
public String component2() {
return getContent();
}
@Override
public Integer component3() {
return getProjectId();
}
@Override
public String component4() {
return getTableName();
}
@Override
public String component5() {
return getColumnName();
}
@Override
public Integer component6() {
return getUpdateBy();
}
@Override
public LocalDateTime component7() {
return getUpdateAt();
}
@Override
public LocalDateTime component8() {
return getCreateAt();
}
@Override
public Integer value1() {
return getId();
}
@Override
public String value2() {
return getContent();
}
@Override
public Integer value3() {
return getProjectId();
}
@Override
public String value4() {
return getTableName();
}
@Override
public String value5() {
return getColumnName();
}
@Override
public Integer value6() {
return getUpdateBy();
}
@Override
public LocalDateTime value7() {
return getUpdateAt();
}
@Override
public LocalDateTime value8() {
return getCreateAt();
}
@Override
public DocumentDescriptionRecord value1(Integer value) {
setId(value);
return this;
}
@Override
public DocumentDescriptionRecord value2(String value) {
setContent(value);
return this;
}
@Override
public DocumentDescriptionRecord value3(Integer value) {
setProjectId(value);
return this;
}
@Override
public DocumentDescriptionRecord value4(String value) {
setTableName(value);
return this;
}
@Override
public DocumentDescriptionRecord value5(String value) {
setColumnName(value);
return this;
}
@Override
public DocumentDescriptionRecord value6(Integer value) {
setUpdateBy(value);
return this;
}
@Override
public DocumentDescriptionRecord value7(LocalDateTime value) {
setUpdateAt(value);
return this;
}
@Override
public DocumentDescriptionRecord value8(LocalDateTime value) {
setCreateAt(value);
return this;
}
@Override
public DocumentDescriptionRecord values(Integer value1, String value2, Integer value3, String value4, String value5, Integer value6, LocalDateTime value7, LocalDateTime value8) {
value1(value1);
value2(value2);
value3(value3);
value4(value4);
value5(value5);
value6(value6);
value7(value7);
value8(value8);
return this;
}
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
/**
* Create a detached DocumentDescriptionRecord
*/
public DocumentDescriptionRecord() {
super(DocumentDescription.DOCUMENT_DESCRIPTION);
}
/**
* Create a detached, initialised DocumentDescriptionRecord
*/
public DocumentDescriptionRecord(Integer id, String content, Integer projectId, String tableName, String columnName, Integer updateBy, LocalDateTime updateAt, LocalDateTime createAt) {
super(DocumentDescription.DOCUMENT_DESCRIPTION);
setId(id);
setContent(content);
setProjectId(projectId);
setTableName(tableName);
setColumnName(columnName);
setUpdateBy(updateBy);
setUpdateAt(updateAt);
setCreateAt(createAt);
}
/**
* Create a detached, initialised DocumentDescriptionRecord
*/
public DocumentDescriptionRecord(DocumentDescriptionPojo value) {
super(DocumentDescription.DOCUMENT_DESCRIPTION);
if (value != null) {
setId(value.getId());
setContent(value.getContent());
setProjectId(value.getProjectId());
setTableName(value.getTableName());
setColumnName(value.getColumnName());
setUpdateBy(value.getUpdateBy());
setUpdateAt(value.getUpdateAt());
setCreateAt(value.getCreateAt());
}
}
}

View File

@ -0,0 +1,62 @@
package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
import com.databasir.dao.tables.records.DocumentDescriptionRecord;
import lombok.Getter;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
import static com.databasir.dao.Tables.DOCUMENT_DESCRIPTION;
@Repository
public class DocumentDescriptionDao extends BaseDao<DocumentDescriptionPojo> {
@Autowired
@Getter
private DSLContext dslContext;
public DocumentDescriptionDao() {
super(DOCUMENT_DESCRIPTION, DocumentDescriptionPojo.class);
}
public boolean exists(Integer projectId, String tableName, String columnName) {
Condition condition = DOCUMENT_DESCRIPTION.PROJECT_ID.eq(projectId)
.and(DOCUMENT_DESCRIPTION.TABLE_NAME.eq(tableName));
if (columnName == null) {
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.isNull());
} else {
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.eq(columnName));
}
return this.exists(condition);
}
public void update(DocumentDescriptionPojo pojo) {
Condition condition = DOCUMENT_DESCRIPTION.TABLE_NAME.eq(pojo.getTableName());
if (pojo.getColumnName() == null) {
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.isNull());
} else {
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.eq(pojo.getColumnName()));
}
DocumentDescriptionRecord record = getDslContext().newRecord(DOCUMENT_DESCRIPTION, pojo);
getDslContext().executeUpdate(record, condition);
}
public List<DocumentDescriptionPojo> selectByProjectId(Integer projectId) {
return selectByCondition(DOCUMENT_DESCRIPTION.PROJECT_ID.eq(projectId));
}
public List<DocumentDescriptionPojo> selectTableDescriptionByProjectId(Integer projectId) {
return selectByCondition(DOCUMENT_DESCRIPTION.PROJECT_ID.eq(projectId)
.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.isNull()));
}
public List<DocumentDescriptionPojo> selectByCondition(Condition condition) {
return this.getDslContext()
.selectFrom(DOCUMENT_DESCRIPTION).where(condition)
.fetchInto(DocumentDescriptionPojo.class);
}
}

View File

@ -19,5 +19,21 @@ CREATE TABLE IF NOT EXISTS database_type
REPLACE INTO databasir.database_type (id, database_type, icon, DESCRIPTION, jdbc_driver_file_url,
jdbc_driver_class_name,
jdbc_protocol, url_pattern)
VALUES (1, 'mysql', '', 'system default mysql', 'N/A', 'com.mysql.cj.jdbc.Driver', 'jdbc:mysql', '{{jdbc.protocol}}://{{db.url}}/{{db.name}}'),
(2, 'postgresql', '', 'system default postgresql', 'N/A', 'org.postgresql.Driver', 'jdbc:postgresql', '{{jdbc.protocol}}://{{db.url}}/{{db.name}}');
VALUES (1, 'mysql', '', 'system default mysql', 'N/A', 'com.mysql.cj.jdbc.Driver', 'jdbc:mysql',
'{{jdbc.protocol}}://{{db.url}}/{{db.name}}'),
(2, 'postgresql', '', 'system default postgresql', 'N/A', 'org.postgresql.Driver', 'jdbc:postgresql',
'{{jdbc.protocol}}://{{db.url}}/{{db.name}}');
CREATE TABLE IF NOT EXISTS document_description
(
id INT PRIMARY KEY AUTO_INCREMENT,
content TEXT NOT NULL,
project_id INT NOT NULL,
table_name VARCHAR(255) NOT NULL,
column_name VARCHAR(255) DEFAULT NULL,
update_by INT NOT NULL,
update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT UNIQUE uk_project_id_table_name_column_name (project_id, table_name, column_name)
) CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT 'custom document description';