feat: add checkstyle (#22)

This commit is contained in:
vran
2022-02-21 21:55:56 +08:00
committed by GitHub
parent dde3c09e3e
commit cfedddeb9e
47 changed files with 522 additions and 159 deletions

View File

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

View File

@@ -18,7 +18,10 @@ public class DataNotExistsException extends RuntimeException {
super(cause);
}
protected DataNotExistsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
protected DataNotExistsException(String message,
Throwable cause,
boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@@ -1,6 +1,5 @@
package com.databasir.dao.impl;
import com.databasir.dao.exception.DataNotExistsException;
import org.jooq.*;
import org.springframework.data.domain.Page;
@@ -12,13 +11,13 @@ import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
public abstract class BaseDao<PO> {
public abstract class BaseDao<R> {
private final Table<?> table;
private final Class<PO> pojoType;
private final Class<R> pojoType;
public BaseDao(Table<?> table, Class<PO> pojoType) {
public BaseDao(Table<?> table, Class<R> pojoType) {
this.table = table;
this.pojoType = pojoType;
}
@@ -29,7 +28,7 @@ public abstract class BaseDao<PO> {
return getDslContext().fetchExists(table, identity().eq(id));
}
public <T> T insertAndReturnId(PO pojo) {
public <T> T insertAndReturnId(R pojo) {
Record record = getDslContext().newRecord(table, pojo);
UpdatableRecord<?> updatableRecord = (UpdatableRecord<?>) record;
updatableRecord.store();
@@ -37,7 +36,7 @@ public abstract class BaseDao<PO> {
return (T) identityType().cast(value);
}
public int batchInsert(Collection<PO> pojoList) {
public int batchInsert(Collection<R> pojoList) {
List<TableRecord<?>> records = pojoList.stream()
.map(pojo -> {
Record record = getDslContext().newRecord(table, pojo);
@@ -53,24 +52,25 @@ public abstract class BaseDao<PO> {
.execute();
}
public int updateById(PO pojo) {
public int updateById(R pojo) {
Record record = getDslContext().newRecord(table, pojo);
record.changed(table.getIdentity().getField(), false);
return getDslContext().executeUpdate((UpdatableRecord<?>) record);
}
public <T extends Serializable> Optional<PO> selectOptionalById(T id) {
public <T extends Serializable> Optional<R> selectOptionalById(T id) {
return getDslContext()
.select(table.fields()).from(table).where(identity().eq(id))
.fetchOptionalInto(pojoType);
}
public <T extends Serializable> PO selectById(T id) {
public <T extends Serializable> R selectById(T id) {
return selectOptionalById(id)
.orElseThrow(() -> new DataNotExistsException("data not exists in " + table.getName() + " with id = " + id));
.orElseThrow(() ->
new DataNotExistsException("data not exists in " + table.getName() + " with id = " + id));
}
public List<PO> selectInIds(List<? extends Serializable> ids) {
public List<R> selectInIds(List<? extends Serializable> ids) {
if (ids == null || ids.isEmpty()) {
return Collections.emptyList();
}
@@ -80,12 +80,12 @@ public abstract class BaseDao<PO> {
.fetchInto(pojoType);
}
public Page<PO> selectByPage(Pageable request, Condition condition) {
public Page<R> selectByPage(Pageable request, Condition condition) {
Integer count = getDslContext()
.selectCount().from(table).where(condition)
.fetchOne(0, int.class);
int total = count == null ? 0 : count;
List<PO> data = getDslContext()
List<R> data = getDslContext()
.selectFrom(table).where(condition)
.orderBy(getSortFields(request.getSort()))
.offset(request.getOffset()).limit(request.getPageSize())

View File

@@ -14,7 +14,6 @@ import java.util.Optional;
import static com.databasir.dao.Tables.DATA_SOURCE;
@Repository
public class DataSourceDao extends BaseDao<DataSourcePojo> {
@@ -36,7 +35,10 @@ public class DataSourceDao extends BaseDao<DataSourcePojo> {
return getDslContext()
.select(DATA_SOURCE.fields()).from(DATA_SOURCE).where(DATA_SOURCE.PROJECT_ID.eq(projectId))
.fetchOptionalInto(DataSourcePojo.class)
.orElseThrow(() -> new DataNotExistsException("data not exists in " + table().getName() + " with schemaSourceId = " + projectId));
.orElseThrow(() -> new DataNotExistsException("data not exists in "
+ table().getName()
+ " with schemaSourceId = "
+ projectId));
}
public int updateByProjectId(DataSourcePojo dataSource) {

View File

@@ -10,7 +10,6 @@ import java.util.List;
import static com.databasir.dao.Tables.DATA_SOURCE_PROPERTY;
@Repository
public class DataSourcePropertyDao extends BaseDao<DataSourcePropertyPojo> {

View File

@@ -11,7 +11,6 @@ import java.util.Optional;
import static com.databasir.dao.Tables.DATABASE_DOCUMENT;
@Repository
public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentPojo> {
@@ -25,7 +24,8 @@ public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentPojo> {
public Optional<DatabaseDocumentPojo> selectOptionalByProjectId(Integer projectId) {
return getDslContext()
.select(DATABASE_DOCUMENT.fields()).from(DATABASE_DOCUMENT).where(DATABASE_DOCUMENT.PROJECT_ID.eq(projectId))
.select(DATABASE_DOCUMENT.fields()).from(DATABASE_DOCUMENT)
.where(DATABASE_DOCUMENT.PROJECT_ID.eq(projectId))
.fetchOptionalInto(DatabaseDocumentPojo.class);
}

View File

@@ -16,7 +16,6 @@ import java.util.Optional;
import static com.databasir.dao.Tables.DATABASE_DOCUMENT_HISTORY;
@Repository
public class DatabaseDocumentHistoryDao extends BaseDao<DatabaseDocumentHistoryPojo> {
@@ -30,11 +29,14 @@ public class DatabaseDocumentHistoryDao extends BaseDao<DatabaseDocumentHistoryP
public Optional<DatabaseDocumentHistoryPojo> selectOptionalByProjectIdAndVersion(Integer projectId, Long version) {
return dslContext
.selectFrom(DATABASE_DOCUMENT_HISTORY).where(DATABASE_DOCUMENT_HISTORY.PROJECT_ID.eq(projectId).and(DATABASE_DOCUMENT_HISTORY.VERSION.eq(version)))
.selectFrom(DATABASE_DOCUMENT_HISTORY)
.where(DATABASE_DOCUMENT_HISTORY.PROJECT_ID.eq(projectId)
.and(DATABASE_DOCUMENT_HISTORY.VERSION.eq(version)))
.fetchOptionalInto(DatabaseDocumentHistoryPojo.class);
}
public Page<DatabaseDocumentVersionPojo> selectVersionPageByDatabaseDocumentId(Pageable request, Integer schemaDocumentId) {
public Page<DatabaseDocumentVersionPojo> selectVersionPageByDatabaseDocumentId(Pageable request,
Integer schemaDocumentId) {
Condition condition = DATABASE_DOCUMENT_HISTORY.DATABASE_DOCUMENT_ID.eq(schemaDocumentId);
Integer count = getDslContext()
.selectCount().from(DATABASE_DOCUMENT_HISTORY).where(condition)

View File

@@ -10,7 +10,6 @@ import java.util.Optional;
import static com.databasir.dao.Tables.DOCUMENT_REMARK;
@Repository
public class DocumentRemarkDao extends BaseDao<DocumentRemarkPojo> {

View File

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

View File

@@ -11,7 +11,6 @@ import java.util.Optional;
import static com.databasir.dao.Tables.LOGIN;
@Repository
public class LoginDao extends BaseDao<LoginPojo> {

View File

@@ -20,7 +20,6 @@ import java.util.stream.Collectors;
import static com.databasir.dao.Tables.DATA_SOURCE;
import static com.databasir.dao.Tables.PROJECT;
@Repository
public class ProjectDao extends BaseDao<ProjectPojo> {

View File

@@ -28,15 +28,19 @@ public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRulePojo> {
public Optional<ProjectSyncRulePojo> selectOptionalByProjectId(Integer projectId) {
return getDslContext()
.select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE).where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId))
.select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE)
.where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId))
.fetchOptionalInto(ProjectSyncRulePojo.class);
}
public ProjectSyncRulePojo selectByProjectId(Integer projectId) {
return getDslContext()
.select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE).where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId))
.select(PROJECT_SYNC_RULE.fields()).from(PROJECT_SYNC_RULE)
.where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId))
.fetchOptionalInto(ProjectSyncRulePojo.class)
.orElseThrow(() -> new DataNotExistsException("data not exists in " + table().getName() + " with projectId = " + projectId));
.orElseThrow(() -> new DataNotExistsException("data not exists in "
+ table().getName()
+ " with projectId = " + projectId));
}
public int updateByProjectId(ProjectSyncRulePojo rule) {
@@ -76,7 +80,8 @@ public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRulePojo> {
.fetchInto(ProjectSyncRulePojo.class);
}
public List<ProjectSyncRulePojo> selectByIsAutoSyncAndNotInProjectIds(boolean isAutoSync, List<Integer> projectIds) {
public List<ProjectSyncRulePojo> selectByIsAutoSyncAndNotInProjectIds(boolean isAutoSync,
List<Integer> projectIds) {
if (projectIds == null || projectIds.isEmpty()) {
return getDslContext()
.selectFrom(PROJECT_SYNC_RULE)

View File

@@ -10,7 +10,6 @@ import java.util.List;
import static com.databasir.dao.Tables.TABLE_COLUMN_DOCUMENT;
@Repository
public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentPojo> {
@@ -31,7 +30,8 @@ public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentPojo> {
public void deleteByDatabaseDocumentId(Integer schemaDocumentId) {
getDslContext()
.deleteFrom(TABLE_COLUMN_DOCUMENT).where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.deleteFrom(TABLE_COLUMN_DOCUMENT)
.where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.execute();
}
}

View File

@@ -23,7 +23,8 @@ public class TableDocumentDao extends BaseDao<TableDocumentPojo> {
public List<TableDocumentPojo> selectByDatabaseDocumentId(Integer schemaDocumentId) {
return getDslContext()
.select(TABLE_DOCUMENT.fields()).from(TABLE_DOCUMENT).where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.select(TABLE_DOCUMENT.fields()).from(TABLE_DOCUMENT)
.where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.fetchInto(TableDocumentPojo.class);
}

View File

@@ -10,7 +10,6 @@ import java.util.List;
import static com.databasir.dao.Tables.TABLE_INDEX_DOCUMENT;
@Repository
public class TableIndexDocumentDao extends BaseDao<TableIndexDocumentPojo> {

View File

@@ -23,13 +23,15 @@ public class TableTriggerDocumentDao extends BaseDao<TableTriggerDocumentPojo> {
public List<TableTriggerDocumentPojo> selectByDatabaseDocumentId(Integer schemaDocumentId) {
return getDslContext()
.select(TABLE_TRIGGER_DOCUMENT.fields()).from(TABLE_TRIGGER_DOCUMENT).where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.select(TABLE_TRIGGER_DOCUMENT.fields()).from(TABLE_TRIGGER_DOCUMENT)
.where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.fetchInto(TableTriggerDocumentPojo.class);
}
public void deleteByDatabaseDocumentId(Integer schemaDocumentId) {
getDslContext()
.deleteFrom(TABLE_TRIGGER_DOCUMENT).where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.deleteFrom(TABLE_TRIGGER_DOCUMENT)
.where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
.execute();
}
}

View File

@@ -20,7 +20,6 @@ import java.util.*;
import static com.databasir.dao.Tables.USER;
import static com.databasir.dao.Tables.USER_ROLE;
@Repository
public class UserDao extends BaseDao<UserPojo> {

View File

@@ -16,7 +16,6 @@ import java.util.List;
import static com.databasir.dao.Tables.USER;
import static com.databasir.dao.Tables.USER_ROLE;
@Repository
public class UserRoleDao extends BaseDao<UserRolePojo> {