mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
commit
1c67e8656d
@ -53,20 +53,14 @@ public abstract class JdbcDialect implements IDialect {
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> buildColumnRemarks(Table table, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
|
||||
private Map<String, String> buildColumnRemarks(Table table, DatabaseMetaData dbMeta, Connection conn) {
|
||||
Map<String, String> columnRemarks = new HashMap<>();
|
||||
ResultSet colRs = null;
|
||||
try {
|
||||
colRs = dbMeta.getColumns(conn.getCatalog(), null, table.getName(), null);
|
||||
try (ResultSet colRs = dbMeta.getColumns(conn.getCatalog(), null, table.getName(), null)) {
|
||||
while (colRs.next()) {
|
||||
columnRemarks.put(colRs.getString("COLUMN_NAME"), colRs.getString("REMARKS"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("无法获取字段的备注内容:" + e.getMessage());
|
||||
} finally {
|
||||
if (colRs != null) {
|
||||
colRs.close();
|
||||
}
|
||||
}
|
||||
return columnRemarks;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ import java.util.Map;
|
||||
|
||||
public class JdbcTypeMapping {
|
||||
|
||||
private static Map<String, String> mapping = new HashMap<>();
|
||||
private static final Map<String, String> mapping = new HashMap<>();
|
||||
|
||||
static {
|
||||
registerMapping("[B", "byte[]");
|
||||
|
||||
@ -23,7 +23,7 @@ import java.util.*;
|
||||
|
||||
public class GeneratorFactory {
|
||||
|
||||
private static Map<String, IGenerator> generators = new HashMap<>();
|
||||
private static final Map<String, IGenerator> generators = new HashMap<>();
|
||||
|
||||
static {
|
||||
registerGenerator("entity", new EntityGenerator());
|
||||
|
||||
@ -24,7 +24,7 @@ import java.util.Map;
|
||||
|
||||
public class EnjoyTemplate implements ITemplate {
|
||||
|
||||
private Engine engine;
|
||||
private final Engine engine;
|
||||
|
||||
public EnjoyTemplate() {
|
||||
engine = Engine.create("mybatis-flex", engine -> {
|
||||
|
||||
@ -25,8 +25,8 @@ import java.util.Enumeration;
|
||||
*/
|
||||
public class DefaultMessageFactory implements MessageFactory {
|
||||
|
||||
private String platform = "mybatis-flex";
|
||||
private String hostIp = getHostIp();
|
||||
private final String platform = "mybatis-flex";
|
||||
private final String hostIp = getHostIp();
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@ -28,12 +28,12 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
*/
|
||||
public class ScheduledMessageCollector implements MessageCollector, Runnable {
|
||||
|
||||
private long period;
|
||||
private ScheduledExecutorService scheduler;
|
||||
private MessageReporter messageSender;
|
||||
private final long period;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
private final MessageReporter messageSender;
|
||||
|
||||
private List<AuditMessage> messages = Collections.synchronizedList(new ArrayList<>());
|
||||
private ReentrantReadWriteLock rrwLock = new ReentrantReadWriteLock();
|
||||
private final List<AuditMessage> messages = Collections.synchronizedList(new ArrayList<>());
|
||||
private final ReentrantReadWriteLock rrwLock = new ReentrantReadWriteLock();
|
||||
|
||||
public ScheduledMessageCollector() {
|
||||
this(10, new ConsoleMessageReporter());
|
||||
|
||||
@ -22,9 +22,9 @@ import java.util.List;
|
||||
|
||||
public class HttpMessageReporter implements MessageReporter {
|
||||
|
||||
private String endpoint;
|
||||
private String secretKey;
|
||||
private JSONFormatter jsonFormatter;
|
||||
private final String endpoint;
|
||||
private final String secretKey;
|
||||
private final JSONFormatter jsonFormatter;
|
||||
|
||||
public HttpMessageReporter(String endpoint, String secretKey, JSONFormatter jsonFormatter) {
|
||||
this.endpoint = endpoint;
|
||||
|
||||
@ -27,7 +27,7 @@ import java.util.Map;
|
||||
|
||||
public class DataSourceBuilder {
|
||||
|
||||
private static Map<String, String> dataSourceAlias = new HashMap<>();
|
||||
private static final Map<String, String> dataSourceAlias = new HashMap<>();
|
||||
|
||||
static {
|
||||
dataSourceAlias.put("druid", "com.alibaba.druid.pool.DruidDataSource");
|
||||
@ -39,7 +39,7 @@ public class DataSourceBuilder {
|
||||
dataSourceAlias.put("dbcp2", "org.apache.commons.dbcp2.BasicDataSource");
|
||||
}
|
||||
|
||||
private Map<String, String> dataSourceProperties;
|
||||
private final Map<String, String> dataSourceProperties;
|
||||
|
||||
public DataSourceBuilder(Map<String, String> dataSourceProperties) {
|
||||
this.dataSourceProperties = dataSourceProperties;
|
||||
@ -49,11 +49,7 @@ public class DataSourceBuilder {
|
||||
String dataSourceClassName = null;
|
||||
String type = dataSourceProperties.get("type");
|
||||
if (StringUtil.isNotBlank(type)) {
|
||||
if (dataSourceAlias.containsKey(type)) {
|
||||
dataSourceClassName = dataSourceAlias.get(type);
|
||||
} else {
|
||||
dataSourceClassName = type;
|
||||
}
|
||||
dataSourceClassName = dataSourceAlias.getOrDefault(type, type);
|
||||
} else {
|
||||
dataSourceClassName = detectDataSourceClass();
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ import java.util.function.Supplier;
|
||||
|
||||
public class DataSourceKey {
|
||||
|
||||
private static ThreadLocal<String> keyThreadLocal = new ThreadLocal<>();
|
||||
private static final ThreadLocal<String> keyThreadLocal = new ThreadLocal<>();
|
||||
|
||||
public static void use(String dataSourceKey) {
|
||||
keyThreadLocal.set(dataSourceKey);
|
||||
|
||||
@ -35,12 +35,12 @@ public class DialectFactory {
|
||||
* 比如,在 mybatis-flex 实现的方言中有 bug 或者 有自己的独立实现,可以添加自己的方言实现到
|
||||
* 此 map 中,用于覆盖系统的方言实现
|
||||
*/
|
||||
private static Map<DbType, IDialect> dialectMap = new EnumMap<>(DbType.class);
|
||||
private static final Map<DbType, IDialect> dialectMap = new EnumMap<>(DbType.class);
|
||||
|
||||
/**
|
||||
* 通过设置当前线程的数据库类型,以达到在代码执行时随时切换方言的功能
|
||||
*/
|
||||
private static ThreadLocal<DbType> dbTypeThreadLocal = new ThreadLocal<>();
|
||||
private static final ThreadLocal<DbType> dbTypeThreadLocal = new ThreadLocal<>();
|
||||
|
||||
|
||||
/**
|
||||
@ -104,12 +104,12 @@ public class DialectFactory {
|
||||
case CUBRID:
|
||||
case GOLDILOCKS:
|
||||
case CSIIDB:
|
||||
return new CommonsDialectImpl(KeywordWrap.BACKQUOTE, LimitOffsetProcesser.MYSQL);
|
||||
return new CommonsDialectImpl(KeywordWrap.BACKQUOTE, LimitOffsetProcessor.MYSQL);
|
||||
case ORACLE:
|
||||
return new OracleDialect(LimitOffsetProcesser.ORACLE);
|
||||
return new OracleDialect(LimitOffsetProcessor.ORACLE);
|
||||
case DM:
|
||||
case GAUSS:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.ORACLE);
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.ORACLE);
|
||||
case POSTGRE_SQL:
|
||||
case SQLITE:
|
||||
case HSQL:
|
||||
@ -123,21 +123,21 @@ public class DialectFactory {
|
||||
case OPENGAUSS:
|
||||
case TDENGINE:
|
||||
case UXDB:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.POSTGRESQL);
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.POSTGRESQL);
|
||||
case ORACLE_12C:
|
||||
return new OracleDialect(LimitOffsetProcesser.DERBY);
|
||||
return new OracleDialect(LimitOffsetProcessor.DERBY);
|
||||
case FIREBIRD:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.DERBY);
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.DERBY);
|
||||
case SQLSERVER:
|
||||
return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcesser.DERBY);
|
||||
return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.DERBY);
|
||||
case SQLSERVER_2005:
|
||||
return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcesser.DB2);
|
||||
return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.DB2);
|
||||
case INFORMIX:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.INFORMIX);
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.INFORMIX);
|
||||
case DB2:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.DB2);
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.DB2);
|
||||
case SYBASE:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.SYBASE);
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.SYBASE);
|
||||
default:
|
||||
return new CommonsDialectImpl();
|
||||
}
|
||||
|
||||
@ -20,13 +20,13 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||
/**
|
||||
* limit 和 offset 参数的处理器
|
||||
*/
|
||||
public interface LimitOffsetProcesser {
|
||||
public interface LimitOffsetProcessor {
|
||||
|
||||
/**
|
||||
* MySql 的处理器
|
||||
* 适合 {@link DbType#MYSQL,DbType#MARIADB,DbType#H2,DbType#CLICK_HOUSE,DbType#XCloud}
|
||||
*/
|
||||
LimitOffsetProcesser MYSQL = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor MYSQL = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
sql.append(" LIMIT ").append(limitOffset).append(", ").append(limitRows);
|
||||
} else if (limitRows != null) {
|
||||
@ -41,7 +41,7 @@ public interface LimitOffsetProcesser {
|
||||
* 适合 {@link DbType#SAP_HANA,DbType#IMPALA,DbType#HIGH_GO,DbType#VERTICA,DbType#REDSHIFT}
|
||||
* 适合 {@link DbType#OPENGAUSS,DbType#TDENGINE,DbType#UXDB}
|
||||
*/
|
||||
LimitOffsetProcesser POSTGRESQL = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor POSTGRESQL = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
sql.append(" LIMIT ").append(limitRows).append(" OFFSET ").append(limitOffset);
|
||||
} else if (limitRows != null) {
|
||||
@ -54,7 +54,7 @@ public interface LimitOffsetProcesser {
|
||||
* derby 的处理器
|
||||
* 适合 {@link DbType#DERBY,DbType#ORACLE_12C,DbType#SQLSERVER ,DbType#POSTGRE_SQL}
|
||||
*/
|
||||
LimitOffsetProcesser DERBY = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor DERBY = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
// OFFSET ** ROWS FETCH NEXT ** ROWS ONLY")
|
||||
sql.append(" OFFSET ").append(limitOffset).append(" ROWS FETCH NEXT ").append(limitRows).append(" ROWS ONLY");
|
||||
@ -69,7 +69,7 @@ public interface LimitOffsetProcesser {
|
||||
* db2 的处理器
|
||||
* 适合 {@link DbType#DB2,DbType#SQLSERVER_2005}
|
||||
*/
|
||||
LimitOffsetProcesser DB2 = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor DB2 = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
// OFFSET ** ROWS FETCH NEXT ** ROWS ONLY")
|
||||
sql.append(" OFFSET ").append(limitOffset).append(" ROWS FETCH NEXT ").append(limitRows).append(" ROWS ONLY");
|
||||
@ -85,7 +85,7 @@ public interface LimitOffsetProcesser {
|
||||
* 适合 {@link DbType#INFORMIX}
|
||||
* 文档 {@link <a href="https://www.ibm.com/docs/en/informix-servers/14.10?topic=clause-restricting-return-values-skip-limit-first-options">https://www.ibm.com/docs/en/informix-servers/14.10?topic=clause-restricting-return-values-skip-limit-first-options</a>}
|
||||
*/
|
||||
LimitOffsetProcesser INFORMIX = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor INFORMIX = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
// SELECT SKIP 2 FIRST 1 * FROM
|
||||
sql.insert(6, " SKIP " + limitOffset + " FIRST " + limitRows);
|
||||
@ -99,7 +99,7 @@ public interface LimitOffsetProcesser {
|
||||
* Firebird 的处理器
|
||||
* 适合 {@link DbType#FIREBIRD}
|
||||
*/
|
||||
LimitOffsetProcesser FIREBIRD = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor FIREBIRD = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
// ROWS 2 TO 3
|
||||
sql.append(" ROWS ").append(limitOffset).append(" TO ").append(limitOffset + limitRows);
|
||||
@ -113,7 +113,7 @@ public interface LimitOffsetProcesser {
|
||||
* Oracle11g及以下数据库的处理器
|
||||
* 适合 {@link DbType#ORACLE,DbType#DM,DbType#GAUSS}
|
||||
*/
|
||||
LimitOffsetProcesser ORACLE = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor ORACLE = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null) {
|
||||
if (limitOffset == null) {
|
||||
limitOffset = 0;
|
||||
@ -130,7 +130,7 @@ public interface LimitOffsetProcesser {
|
||||
* Sybase 处理器
|
||||
* 适合 {@link DbType#SYBASE}
|
||||
*/
|
||||
LimitOffsetProcesser SYBASE = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
LimitOffsetProcessor SYBASE = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
//SELECT TOP 1 START AT 3 * FROM
|
||||
sql.insert(6, " TOP " + limitRows + " START AT " + (limitOffset + 1));
|
||||
@ -18,7 +18,7 @@ package com.mybatisflex.core.dialect.impl;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.dialect.KeywordWrap;
|
||||
import com.mybatisflex.core.dialect.LimitOffsetProcesser;
|
||||
import com.mybatisflex.core.dialect.LimitOffsetProcessor;
|
||||
import com.mybatisflex.core.exception.FlexExceptions;
|
||||
import com.mybatisflex.core.query.*;
|
||||
import com.mybatisflex.core.row.Row;
|
||||
@ -40,18 +40,18 @@ import java.util.StringJoiner;
|
||||
public class CommonsDialectImpl implements IDialect {
|
||||
|
||||
protected KeywordWrap keywordWrap = KeywordWrap.BACKQUOTE;
|
||||
private LimitOffsetProcesser limitOffsetProcesser = LimitOffsetProcesser.MYSQL;
|
||||
private LimitOffsetProcessor limitOffsetProcessor = LimitOffsetProcessor.MYSQL;
|
||||
|
||||
public CommonsDialectImpl() {
|
||||
}
|
||||
|
||||
public CommonsDialectImpl(LimitOffsetProcesser limitOffsetProcesser) {
|
||||
this.limitOffsetProcesser = limitOffsetProcesser;
|
||||
public CommonsDialectImpl(LimitOffsetProcessor limitOffsetProcessor) {
|
||||
this.limitOffsetProcessor = limitOffsetProcessor;
|
||||
}
|
||||
|
||||
public CommonsDialectImpl(KeywordWrap keywordWrap, LimitOffsetProcesser limitOffsetProcesser) {
|
||||
public CommonsDialectImpl(KeywordWrap keywordWrap, LimitOffsetProcessor limitOffsetProcessor) {
|
||||
this.keywordWrap = keywordWrap;
|
||||
this.limitOffsetProcesser = limitOffsetProcesser;
|
||||
this.limitOffsetProcessor = limitOffsetProcessor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -827,7 +827,7 @@ public class CommonsDialectImpl implements IDialect {
|
||||
* 构建 limit 和 offset 的参数
|
||||
*/
|
||||
protected StringBuilder buildLimitOffsetSql(StringBuilder sqlBuilder, QueryWrapper queryWrapper, Integer limitRows, Integer limitOffset) {
|
||||
return limitOffsetProcesser.process(sqlBuilder, queryWrapper, limitRows, limitOffset);
|
||||
return limitOffsetProcessor.process(sqlBuilder, queryWrapper, limitRows, limitOffset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
package com.mybatisflex.core.dialect.impl;
|
||||
|
||||
import com.mybatisflex.core.dialect.KeywordWrap;
|
||||
import com.mybatisflex.core.dialect.LimitOffsetProcesser;
|
||||
import com.mybatisflex.core.dialect.LimitOffsetProcessor;
|
||||
import com.mybatisflex.core.util.CollectionUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
@ -55,8 +55,8 @@ public class OracleDialect extends CommonsDialectImpl {
|
||||
"VALIDATE", "VALUES", "VARCHAR", "VARCHAR2"
|
||||
);
|
||||
|
||||
public OracleDialect(LimitOffsetProcesser limitOffsetProcesser) {
|
||||
super(KeywordWrap.NONE, limitOffsetProcesser);
|
||||
public OracleDialect(LimitOffsetProcessor limitOffsetProcessor) {
|
||||
super(KeywordWrap.NONE, limitOffsetProcessor);
|
||||
}
|
||||
|
||||
public boolean isCaseSensitive() {
|
||||
|
||||
@ -33,8 +33,8 @@ import java.util.List;
|
||||
|
||||
public class FlexEnumTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {
|
||||
|
||||
private Class<?> enumPropertyType;
|
||||
private E[] enums;
|
||||
private final Class<?> enumPropertyType;
|
||||
private final E[] enums;
|
||||
private Field property;
|
||||
private Method getter;
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ import java.util.Set;
|
||||
|
||||
public class ModifyAttrsRecordHandler implements MethodHandler {
|
||||
|
||||
private Set<String> modifyAttrs = new LinkedHashSet<>();
|
||||
private final Set<String> modifyAttrs = new LinkedHashSet<>();
|
||||
|
||||
public Set<String> getModifyAttrs() {
|
||||
return modifyAttrs;
|
||||
|
||||
@ -24,7 +24,7 @@ import java.util.Arrays;
|
||||
|
||||
public class ModifyAttrsRecordProxyFactory {
|
||||
|
||||
private static ModifyAttrsRecordProxyFactory instance = new ModifyAttrsRecordProxyFactory();
|
||||
private static final ModifyAttrsRecordProxyFactory instance = new ModifyAttrsRecordProxyFactory();
|
||||
|
||||
public static ModifyAttrsRecordProxyFactory getInstance(){
|
||||
return instance;
|
||||
|
||||
@ -30,7 +30,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class MultiEntityKeyGenerator implements KeyGenerator {
|
||||
|
||||
private KeyGenerator keyGenerator;
|
||||
private final KeyGenerator keyGenerator;
|
||||
|
||||
public MultiEntityKeyGenerator(KeyGenerator keyGenerator) {
|
||||
this.keyGenerator = keyGenerator;
|
||||
|
||||
@ -31,10 +31,10 @@ import java.util.List;
|
||||
*/
|
||||
public class MultiPrimaryKeyGenerator implements KeyGenerator, IMultiKeyGenerator {
|
||||
|
||||
private List<KeyGenerator> keyGenerators;
|
||||
private final List<KeyGenerator> keyGenerators;
|
||||
|
||||
//所有自增字段的名称
|
||||
private String[] autoGenKeyColumnNames;
|
||||
private final String[] autoGenKeyColumnNames;
|
||||
|
||||
public MultiPrimaryKeyGenerator(MappedStatement mappedStatement, TableInfo tableInfo, List<IdInfo> primaryKeyList) {
|
||||
this.keyGenerators = new ArrayList<>();
|
||||
|
||||
@ -31,7 +31,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class MultiRowKeyGenerator implements KeyGenerator {
|
||||
|
||||
private KeyGenerator keyGenerator;
|
||||
private final KeyGenerator keyGenerator;
|
||||
|
||||
public MultiRowKeyGenerator(KeyGenerator keyGenerator) {
|
||||
this.keyGenerator = keyGenerator;
|
||||
|
||||
@ -43,7 +43,7 @@ import java.util.Map.Entry;
|
||||
*/
|
||||
public class RowJdbc3KeyGenerator implements KeyGenerator {
|
||||
|
||||
private String keyProperty;
|
||||
private final String keyProperty;
|
||||
|
||||
|
||||
private static final String SECOND_GENERIC_PARAM_NAME = ParamNameResolver.GENERIC_NAME_PREFIX + "2";
|
||||
|
||||
@ -40,9 +40,9 @@ import java.util.Map;
|
||||
* 为 row 的主键生成器
|
||||
*/
|
||||
public class RowKeyGenerator implements KeyGenerator, IMultiKeyGenerator {
|
||||
private static KeyGenerator[] NO_KEY_GENERATORS = new KeyGenerator[0];
|
||||
private static final KeyGenerator[] NO_KEY_GENERATORS = new KeyGenerator[0];
|
||||
|
||||
private MappedStatement ms;
|
||||
private final MappedStatement ms;
|
||||
private KeyGenerator[] keyGenerators;
|
||||
private List<String> autoKeyGeneratorNames;
|
||||
|
||||
|
||||
@ -26,21 +26,23 @@ public class MaskManager {
|
||||
|
||||
|
||||
/**
|
||||
* 脱敏处理器,type : processer
|
||||
* 脱敏处理器,type : processor
|
||||
*/
|
||||
private static Map<String, MaskProcesser> processerMap = new HashMap<>();
|
||||
private static final Map<String, MaskProcessor> processorMap = new HashMap<>();
|
||||
|
||||
private static final ThreadLocal<Boolean> skipFlags = new ThreadLocal<>();
|
||||
|
||||
|
||||
static {
|
||||
registerMaskProcesser(Masks.MOBILE, Masks.MOBILE_PROCESSER);
|
||||
registerMaskProcesser(Masks.FIXED_PHONE, Masks.FIXED_PHONE_PROCESSER);
|
||||
registerMaskProcesser(Masks.ID_CARD_NUMBER, Masks.ID_CARD_NUMBER_PROCESSER);
|
||||
registerMaskProcesser(Masks.CHINESE_NAME, Masks.CHINESE_NAME_PROCESSER);
|
||||
registerMaskProcesser(Masks.ADDRESS, Masks.ADDRESS_PROCESSER);
|
||||
registerMaskProcesser(Masks.EMAIL, Masks.EMAIL_PROCESSER);
|
||||
registerMaskProcesser(Masks.PASSWORD, Masks.PASSWORD_PROCESSER);
|
||||
registerMaskProcesser(Masks.CAR_LICENSE, Masks.CAR_LICENSE_PROCESSER);
|
||||
registerMaskProcesser(Masks.BANK_CARD_NUMBER, Masks.BANK_CARD_PROCESSER);
|
||||
registerMaskProcessor(Masks.MOBILE, Masks.MOBILE_PROCESSOR);
|
||||
registerMaskProcessor(Masks.FIXED_PHONE, Masks.FIXED_PHONE_PROCESSOR);
|
||||
registerMaskProcessor(Masks.ID_CARD_NUMBER, Masks.ID_CARD_NUMBER_PROCESSOR);
|
||||
registerMaskProcessor(Masks.CHINESE_NAME, Masks.CHINESE_NAME_PROCESSOR);
|
||||
registerMaskProcessor(Masks.ADDRESS, Masks.ADDRESS_PROCESSOR);
|
||||
registerMaskProcessor(Masks.EMAIL, Masks.EMAIL_PROCESSOR);
|
||||
registerMaskProcessor(Masks.PASSWORD, Masks.PASSWORD_PROCESSOR);
|
||||
registerMaskProcessor(Masks.CAR_LICENSE, Masks.CAR_LICENSE_PROCESSOR);
|
||||
registerMaskProcessor(Masks.BANK_CARD_NUMBER, Masks.BANK_CARD_PROCESSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -48,15 +50,13 @@ public class MaskManager {
|
||||
* 注册处理器,用户可以注册新的脱敏处理器 或者 覆盖内置的处理器
|
||||
*
|
||||
* @param type 处理器类型
|
||||
* @param processer 脱敏处理器
|
||||
* @param processor 脱敏处理器
|
||||
*/
|
||||
public static void registerMaskProcesser(String type, MaskProcesser processer) {
|
||||
processerMap.put(type, processer);
|
||||
public static void registerMaskProcessor(String type, MaskProcessor processor) {
|
||||
processorMap.put(type, processor);
|
||||
}
|
||||
|
||||
|
||||
private static ThreadLocal<Boolean> skipFlags = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 跳过脱敏处理
|
||||
*/
|
||||
@ -91,12 +91,12 @@ public class MaskManager {
|
||||
return data;
|
||||
}
|
||||
|
||||
MaskProcesser maskProcesser = processerMap.get(type);
|
||||
if (maskProcesser == null) {
|
||||
throw new IllegalStateException("Can not get mask processer for by type: " + type);
|
||||
MaskProcessor maskProcessor = processorMap.get(type);
|
||||
if (maskProcessor == null) {
|
||||
throw new IllegalStateException("Can not get mask processor for by type: " + type);
|
||||
}
|
||||
|
||||
return maskProcesser.mask(data);
|
||||
return maskProcessor.mask(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ package com.mybatisflex.core.mask;
|
||||
/**
|
||||
* 数据脱敏处理器
|
||||
*/
|
||||
public interface MaskProcesser {
|
||||
public interface MaskProcessor {
|
||||
|
||||
Object mask(Object data);
|
||||
}
|
||||
@ -25,7 +25,7 @@ import java.sql.SQLException;
|
||||
|
||||
public class MaskTypeHandler extends BaseTypeHandler<Object> {
|
||||
|
||||
private String maskType;
|
||||
private final String maskType;
|
||||
|
||||
public MaskTypeHandler(String maskType) {
|
||||
this.maskType = maskType;
|
||||
|
||||
@ -86,7 +86,7 @@ public class Masks {
|
||||
* 手机号脱敏处理器
|
||||
* 保留前三后四,中间的为星号 "*"
|
||||
*/
|
||||
static MaskProcesser MOBILE_PROCESSER = data -> {
|
||||
static MaskProcessor MOBILE_PROCESSOR = data -> {
|
||||
if (data instanceof String && ((String) data).startsWith("1") && ((String) data).length() == 11) {
|
||||
return mask((String) data, 3, 4, 4);
|
||||
}
|
||||
@ -98,7 +98,7 @@ public class Masks {
|
||||
* 固定电话脱敏
|
||||
* 保留前三后四,中间的为星号 "*"
|
||||
*/
|
||||
static MaskProcesser FIXED_PHONE_PROCESSER = data -> {
|
||||
static MaskProcessor FIXED_PHONE_PROCESSOR = data -> {
|
||||
if (data instanceof String && ((String) data).length() > 5) {
|
||||
return mask((String) data, 3, 2, ((String) data).length() - 5);
|
||||
}
|
||||
@ -110,7 +110,7 @@ public class Masks {
|
||||
* 身份证号脱敏处理器
|
||||
* 身份证号的保留前三后四,中间的数为星号 "*"
|
||||
*/
|
||||
static MaskProcesser ID_CARD_NUMBER_PROCESSER = data -> {
|
||||
static MaskProcessor ID_CARD_NUMBER_PROCESSOR = data -> {
|
||||
if (data instanceof String && ((String) data).length() >= 15) {
|
||||
return mask((String) data, 3, 4, ((String) data).length() - 7);
|
||||
}
|
||||
@ -121,7 +121,7 @@ public class Masks {
|
||||
/**
|
||||
* 姓名脱敏
|
||||
*/
|
||||
static MaskProcesser CHINESE_NAME_PROCESSER = data -> {
|
||||
static MaskProcessor CHINESE_NAME_PROCESSOR = data -> {
|
||||
if (data instanceof String) {
|
||||
String name = (String) data;
|
||||
if (name.length() == 2) {
|
||||
@ -141,7 +141,7 @@ public class Masks {
|
||||
/**
|
||||
* 地址脱敏
|
||||
*/
|
||||
static MaskProcesser ADDRESS_PROCESSER = data -> {
|
||||
static MaskProcessor ADDRESS_PROCESSOR = data -> {
|
||||
if (data instanceof String) {
|
||||
String address = (String) data;
|
||||
if (address.length() > 6) {
|
||||
@ -157,7 +157,7 @@ public class Masks {
|
||||
/**
|
||||
* email 脱敏
|
||||
*/
|
||||
static MaskProcesser EMAIL_PROCESSER = data -> {
|
||||
static MaskProcessor EMAIL_PROCESSOR = data -> {
|
||||
if (data instanceof String && ((String) data).contains("@")) {
|
||||
String fullEmail = (String) data;
|
||||
int indexOf = fullEmail.lastIndexOf("@");
|
||||
@ -180,7 +180,7 @@ public class Masks {
|
||||
/**
|
||||
* 密码 脱敏
|
||||
*/
|
||||
static MaskProcesser PASSWORD_PROCESSER = data -> {
|
||||
static MaskProcessor PASSWORD_PROCESSOR = data -> {
|
||||
if (data instanceof String ) {
|
||||
return mask((String) data, 0, 0, ((String) data).length()) ;
|
||||
}
|
||||
@ -191,7 +191,7 @@ public class Masks {
|
||||
/**
|
||||
* 车牌号 脱敏
|
||||
*/
|
||||
static MaskProcesser CAR_LICENSE_PROCESSER = data -> {
|
||||
static MaskProcessor CAR_LICENSE_PROCESSOR = data -> {
|
||||
if (data instanceof String) {
|
||||
return mask((String) data, 3, 1, ((String) data).length() - 4);
|
||||
}
|
||||
@ -202,7 +202,7 @@ public class Masks {
|
||||
/**
|
||||
* 银行卡号 脱敏
|
||||
*/
|
||||
static MaskProcesser BANK_CARD_PROCESSER = data -> {
|
||||
static MaskProcessor BANK_CARD_PROCESSOR = data -> {
|
||||
if (data instanceof String && ((String) data).length() >= 8) {
|
||||
return mask((String) data, 4, 4, 4);
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ import java.util.List;
|
||||
*/
|
||||
public class Brackets extends QueryCondition {
|
||||
|
||||
private QueryCondition childCondition;
|
||||
private final QueryCondition childCondition;
|
||||
|
||||
|
||||
public Brackets(QueryCondition childCondition) {
|
||||
|
||||
@ -23,7 +23,7 @@ import java.util.List;
|
||||
|
||||
public class DistinctQueryColumn extends QueryColumn {
|
||||
|
||||
private List<QueryColumn> queryColumns;
|
||||
private final List<QueryColumn> queryColumns;
|
||||
|
||||
public DistinctQueryColumn(QueryColumn... queryColumns) {
|
||||
this.queryColumns = CollectionUtil.newArrayList(queryColumns);
|
||||
|
||||
@ -37,8 +37,8 @@ public class Join implements Serializable {
|
||||
static final String TYPE_CROSS = " CROSS JOIN ";
|
||||
|
||||
|
||||
private String type;
|
||||
private QueryTable queryTable;
|
||||
private final String type;
|
||||
private final QueryTable queryTable;
|
||||
private QueryCondition on;
|
||||
private boolean effective;
|
||||
|
||||
|
||||
@ -21,8 +21,8 @@ package com.mybatisflex.core.query;
|
||||
*/
|
||||
public class Joiner<M> {
|
||||
|
||||
private M queryWrapper;
|
||||
private Join join;
|
||||
private final M queryWrapper;
|
||||
private final Join join;
|
||||
|
||||
public Joiner(M queryWrapper, Join join) {
|
||||
this.queryWrapper = queryWrapper;
|
||||
|
||||
@ -26,8 +26,8 @@ import java.util.List;
|
||||
*/
|
||||
public class OperatorQueryCondition extends QueryCondition {
|
||||
|
||||
private String operator;
|
||||
private QueryCondition child;
|
||||
private final String operator;
|
||||
private final QueryCondition child;
|
||||
|
||||
public OperatorQueryCondition(String operator, QueryCondition child) {
|
||||
this.operator = operator;
|
||||
|
||||
@ -27,8 +27,8 @@ import java.util.List;
|
||||
*/
|
||||
public class OperatorSelectCondition extends QueryCondition {
|
||||
//操作符,例如 exist, not exist
|
||||
private String operator;
|
||||
private QueryWrapper queryWrapper;
|
||||
private final String operator;
|
||||
private final QueryWrapper queryWrapper;
|
||||
|
||||
public OperatorSelectCondition(String operator, QueryWrapper queryWrapper) {
|
||||
this.operator = operator;
|
||||
|
||||
@ -30,7 +30,7 @@ public enum SqlConnector {
|
||||
;
|
||||
|
||||
|
||||
private String value;
|
||||
private final String value;
|
||||
|
||||
SqlConnector(String value) {
|
||||
this.value = value;
|
||||
|
||||
@ -26,7 +26,7 @@ import java.util.List;
|
||||
*/
|
||||
public class StringQueryOrderBy extends QueryOrderBy {
|
||||
|
||||
private String orderBy;
|
||||
private final String orderBy;
|
||||
|
||||
public StringQueryOrderBy(String orderBy) {
|
||||
SqlUtil.keepOrderBySqlSafely(orderBy);
|
||||
|
||||
@ -42,7 +42,7 @@ public class Row extends LinkedHashMap<String, Object> implements ModifyAttrsRec
|
||||
}
|
||||
|
||||
|
||||
private Set<String> modifyAttrs = new LinkedHashSet<>();
|
||||
private final Set<String> modifyAttrs = new LinkedHashSet<>();
|
||||
|
||||
@Override
|
||||
public Set<String> getModifyAttrs() {
|
||||
|
||||
@ -53,8 +53,7 @@ public class RowMapperInvoker {
|
||||
|
||||
public int[] insertBatch(String tableName, Collection<Row> rows, int batchSize) {
|
||||
int[] results = new int[rows.size()];
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,true);
|
||||
try {
|
||||
try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, true)) {
|
||||
RowMapper mapper = sqlSession.getMapper(RowMapper.class);
|
||||
int counter = 0;
|
||||
int resultsPos = 0;
|
||||
@ -73,7 +72,7 @@ public class RowMapperInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
if (counter != 0){
|
||||
if (counter != 0) {
|
||||
List<BatchResult> batchResults = sqlSession.flushStatements();
|
||||
for (BatchResult batchResult : batchResults) {
|
||||
int[] updateCounts = batchResult.getUpdateCounts();
|
||||
@ -82,8 +81,6 @@ public class RowMapperInvoker {
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
sqlSession.close();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -43,8 +43,8 @@ public class EntityWrapperFactory implements ObjectWrapperFactory {
|
||||
|
||||
static class FlexBeanWrapper extends BeanWrapper {
|
||||
|
||||
private Object entity;
|
||||
private TableInfo tableInfo;
|
||||
private final Object entity;
|
||||
private final TableInfo tableInfo;
|
||||
|
||||
public FlexBeanWrapper(MetaObject metaObject, Object object) {
|
||||
super(metaObject, object);
|
||||
|
||||
@ -21,7 +21,7 @@ import java.io.Serializable;
|
||||
|
||||
public class TableDef implements Serializable {
|
||||
|
||||
private String tableName;
|
||||
private final String tableName;
|
||||
|
||||
public TableDef(String tableName) {
|
||||
this.tableName = tableName;
|
||||
|
||||
@ -88,8 +88,8 @@ public class TableInfo {
|
||||
private List<IdInfo> primaryKeyList;
|
||||
|
||||
//column 和 java 属性的称的关系映射
|
||||
private Map<String, ColumnInfo> columnInfoMapping = new HashMap<>();
|
||||
private Map<String, String> propertyColumnMapping = new HashMap<>();
|
||||
private final Map<String, ColumnInfo> columnInfoMapping = new HashMap<>();
|
||||
private final Map<String, String> propertyColumnMapping = new HashMap<>();
|
||||
|
||||
private List<InsertListener> onInsertListeners;
|
||||
private List<UpdateListener> onUpdateListeners;
|
||||
@ -809,7 +809,7 @@ public class TableInfo {
|
||||
}
|
||||
|
||||
|
||||
private static Map<Class<?>, List<InsertListener>> insertListenerCache = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, List<InsertListener>> insertListenerCache = new ConcurrentHashMap<>();
|
||||
|
||||
public void invokeOnInsertListener(Object entity) {
|
||||
List<InsertListener> listeners = MapUtil.computeIfAbsent(insertListenerCache, entityClass, aClass -> {
|
||||
@ -823,7 +823,7 @@ public class TableInfo {
|
||||
}
|
||||
|
||||
|
||||
private static Map<Class<?>, List<UpdateListener>> updateListenerCache = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, List<UpdateListener>> updateListenerCache = new ConcurrentHashMap<>();
|
||||
|
||||
public void invokeOnUpdateListener(Object entity) {
|
||||
List<UpdateListener> listeners = MapUtil.computeIfAbsent(updateListenerCache, entityClass, aClass -> {
|
||||
@ -837,7 +837,7 @@ public class TableInfo {
|
||||
}
|
||||
|
||||
|
||||
private static Map<Class<?>, List<SetListener>> setListenerCache = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, List<SetListener>> setListenerCache = new ConcurrentHashMap<>();
|
||||
|
||||
public Object invokeOnSetListener(Object entity, String property, Object value) {
|
||||
List<SetListener> listeners = MapUtil.computeIfAbsent(setListenerCache, entityClass, aClass -> {
|
||||
|
||||
@ -19,7 +19,7 @@ import java.util.function.Supplier;
|
||||
|
||||
public class TenantManager {
|
||||
|
||||
private static ThreadLocal<Boolean> ignoreFlags = new ThreadLocal<>();
|
||||
private static final ThreadLocal<Boolean> ignoreFlags = new ThreadLocal<>();
|
||||
|
||||
private static TenantFactory tenantFactory;
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ import java.util.List;
|
||||
|
||||
public class UpdateEntity {
|
||||
|
||||
private static ReflectorFactory reflectorFactory = new DefaultReflectorFactory();
|
||||
private static final ReflectorFactory reflectorFactory = new DefaultReflectorFactory();
|
||||
|
||||
|
||||
public static <T> T of(Class<T> clazz) {
|
||||
|
||||
@ -3,7 +3,7 @@ package com.mybatisflex.coretest;
|
||||
import com.mybatisflex.core.dialect.impl.CommonsDialectImpl;
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.dialect.KeywordWrap;
|
||||
import com.mybatisflex.core.dialect.LimitOffsetProcesser;
|
||||
import com.mybatisflex.core.dialect.LimitOffsetProcessor;
|
||||
import com.mybatisflex.core.query.CPI;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.table.TableInfo;
|
||||
@ -49,7 +49,7 @@ public class AccountSqlTester {
|
||||
.from(ACCOUNT.as("a"), ARTICLE.as("b"))
|
||||
.where(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID));
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl(KeywordWrap.NONE, LimitOffsetProcesser.MYSQL);
|
||||
IDialect dialect = new CommonsDialectImpl(KeywordWrap.NONE, LimitOffsetProcessor.MYSQL);
|
||||
String sql = dialect.forSelectListByQuery(query);
|
||||
System.out.println(sql);
|
||||
}
|
||||
@ -321,28 +321,28 @@ public class AccountSqlTester {
|
||||
String sql1 = dialect1.buildSelectSql(queryWrapper);
|
||||
System.out.println(sql1);
|
||||
|
||||
IDialect dialect2 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.ORACLE);
|
||||
IDialect dialect2 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.ORACLE);
|
||||
String sql2 = dialect2.buildSelectSql(queryWrapper);
|
||||
System.out.println(sql2);
|
||||
|
||||
IDialect dialect3 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.DB2);
|
||||
IDialect dialect3 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.DB2);
|
||||
String sql3 = dialect3.buildSelectSql(queryWrapper);
|
||||
System.out.println(sql3);
|
||||
|
||||
IDialect dialect4 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.POSTGRESQL);
|
||||
IDialect dialect4 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.POSTGRESQL);
|
||||
String sql4 = dialect4.buildSelectSql(queryWrapper);
|
||||
System.out.println(sql4);
|
||||
|
||||
IDialect dialect5 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.INFORMIX);
|
||||
IDialect dialect5 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.INFORMIX);
|
||||
String sql5 = dialect5.buildSelectSql(queryWrapper);
|
||||
System.out.println(sql5);
|
||||
|
||||
IDialect dialect6 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.SYBASE);
|
||||
IDialect dialect6 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.SYBASE);
|
||||
String sql6 = dialect6.buildSelectSql(queryWrapper);
|
||||
System.out.println(sql6);
|
||||
|
||||
|
||||
IDialect dialect7 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcesser.FIREBIRD);
|
||||
IDialect dialect7 = new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.FIREBIRD);
|
||||
String sql7 = dialect7.buildSelectSql(queryWrapper);
|
||||
System.out.println(sql7);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ import java.util.Map;
|
||||
@AutoConfigureBefore({DataSourceAutoConfiguration.class})
|
||||
public class MultiDataSourceAutoConfiguration {
|
||||
|
||||
private Map<String, Map<String, String>> dataSourceProperties;
|
||||
private final Map<String, Map<String, String>> dataSourceProperties;
|
||||
|
||||
|
||||
public MultiDataSourceAutoConfiguration(MybatisFlexProperties properties) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user