From f03ad784c98ed7500cc76cbab446e80eec63f4ec Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Fri, 14 Jul 2023 16:14:45 +0800 Subject: [PATCH] style: code format. --- .../com/mybatisflex/annotation/EnumValue.java | 3 +- .../com/mybatisflex/codegen/Generator.java | 2 +- .../mybatisflex/codegen/dialect/IDialect.java | 30 +- .../codegen/dialect/JdbcDialect.java | 7 +- .../mybatisflex/codegen/entity/Column.java | 50 +-- .../com/mybatisflex/codegen/entity/Table.java | 50 +-- .../generator/impl/ControllerGenerator.java | 2 +- .../generator/impl/EntityGenerator.java | 2 +- .../generator/impl/MapperGenerator.java | 4 +- .../generator/impl/MapperXmlGenerator.java | 2 +- .../generator/impl/ServiceGenerator.java | 4 +- .../generator/impl/ServiceImplGenerator.java | 4 +- .../generator/impl/TableDefGenerator.java | 4 +- .../mybatisflex/codegen/test/BaseEntity.java | 18 + .../codegen/test/GeneratorTest.java | 2 +- .../codegen/test/MyBaseMapper.java | 19 +- .../codegen/test/MyUpdateListener.java | 18 + .../codegen/test/SqliteGeneratorTest.java | 13 +- .../java/com/mybatisflex/core/FlexConsts.java | 4 +- .../mybatisflex/core/FlexGlobalConfig.java | 40 ++- .../core/MybatisFlexBootstrap.java | 45 +-- .../mybatisflex/core/audit/AuditManager.java | 2 + .../mybatisflex/core/audit/AuditMessage.java | 51 +-- .../com/mybatisflex/core/audit/Clock.java | 30 +- .../core/audit/ConsoleMessageCollector.java | 3 + .../core/audit/MessageCollector.java | 30 +- .../core/audit/MessageFactory.java | 30 +- .../core/audit/ScheduledMessageCollector.java | 1 + .../core/audit/http/HttpMessageReporter.java | 30 +- .../mybatisflex/core/audit/http/HttpUtil.java | 7 +- .../core/datasource/AbstractDataSource.java | 120 ++++--- .../core/datasource/DataSourceBuilder.java | 37 +- .../core/datasource/DataSourceKey.java | 3 +- .../core/datasource/FlexDataSource.java | 38 ++- .../mybatisflex/core/dialect/DbTypeUtil.java | 3 +- .../core/dialect/DialectFactory.java | 8 +- .../core/dialect/LimitOffsetProcessor.java | 5 +- .../core/dialect/impl/OracleDialect.java | 93 ++--- .../core/exception/FlexExceptions.java | 29 +- .../core/exception/MybatisFlexException.java | 30 +- .../mybatisflex/core/field/FieldQuery.java | 29 +- .../core/field/FieldQueryBuilder.java | 35 +- .../mybatisflex/core/field/QueryBuilder.java | 30 +- .../core/handler/BaseJsonTypeHandler.java | 31 +- .../handler/CompositeEnumTypeHandler.java | 29 +- .../core/handler/Fastjson2TypeHandler.java | 37 +- .../core/handler/FastjsonTypeHandler.java | 33 +- .../core/handler/GsonTypeHandler.java | 31 +- .../core/handler/JacksonTypeHandler.java | 31 +- .../core/keygen/CustomKeyGenerator.java | 37 +- .../core/keygen/IMultiKeyGenerator.java | 29 +- .../core/keygen/KeyGeneratorFactory.java | 3 +- .../core/keygen/KeyGenerators.java | 4 +- .../core/keygen/MultiEntityKeyGenerator.java | 29 +- .../core/keygen/MultiRowKeyGenerator.java | 29 +- .../core/keygen/MybatisKeyGeneratorUtil.java | 41 +-- .../core/keygen/RowCustomKeyGenerator.java | 29 +- .../core/keygen/RowJdbc3KeyGenerator.java | 61 ++-- .../core/keygen/RowKeyGenerator.java | 34 +- .../keygen/impl/SnowFlakeIDKeyGenerator.java | 40 +-- .../core/keygen/impl/UUIDKeyGenerator.java | 29 +- .../AbstractLogicDeleteProcessor.java | 4 +- .../logicdelete/LogicDeleteProcessor.java | 10 +- .../impl/DefaultLogicDeleteProcessor.java | 6 +- .../mybatisflex/core/mask/MaskManager.java | 3 +- .../mybatisflex/core/mask/MaskProcessor.java | 29 +- .../core/mask/MaskTypeHandler.java | 37 +- .../java/com/mybatisflex/core/mask/Masks.java | 11 +- .../core/mybatis/FlexConfiguration.java | 121 +++---- .../core/mybatis/FlexResultSetHandler.java | 4 +- .../mybatis/FlexSqlSessionFactoryBuilder.java | 38 +-- .../core/mybatis/FlexStatementHandler.java | 6 +- .../core/mybatis/MappedStatementTypes.java | 9 +- .../core/mybatis/SqlArgsParameterHandler.java | 29 +- .../core/mybatis/TypeHandlerObject.java | 29 +- .../mybatis/executor/CacheKeyBuilder.java | 33 +- .../mybatis/executor/FlexBatchExecutor.java | 43 +-- .../mybatis/executor/FlexReuseExecutor.java | 31 +- .../mybatis/executor/FlexSimpleExecutor.java | 31 +- .../com/mybatisflex/core/paginate/Page.java | 14 +- .../core/provider/EntitySqlProvider.java | 2 +- .../core/provider/RowSqlProvider.java | 2 +- .../core/query/ArithmeticQueryColumn.java | 2 + .../core/query/BaseQueryWrapper.java | 19 +- .../com/mybatisflex/core/query/Brackets.java | 5 +- .../java/com/mybatisflex/core/query/CPI.java | 10 +- .../core/query/CaseQueryColumn.java | 5 + .../core/query/CaseSearchQueryColumn.java | 5 + .../core/query/DistinctQueryColumn.java | 5 +- .../core/query/FunctionQueryColumn.java | 13 +- .../core/query/HasParamsColumn.java | 17 + .../core/query/IfFunctionQueryColumn.java | 6 +- .../java/com/mybatisflex/core/query/Join.java | 1 + .../com/mybatisflex/core/query/Joiner.java | 29 +- .../core/query/OperatorQueryCondition.java | 7 +- .../core/query/OperatorSelectCondition.java | 8 +- .../mybatisflex/core/query/QueryColumn.java | 9 +- .../core/query/QueryCondition.java | 23 +- .../mybatisflex/core/query/QueryOrderBy.java | 1 + .../mybatisflex/core/query/QueryTable.java | 13 +- .../mybatisflex/core/query/QueryWrapper.java | 3 +- .../mybatisflex/core/query/RawFragment.java | 1 + .../core/query/SelectQueryColumn.java | 1 + .../core/query/SelectQueryTable.java | 1 + .../mybatisflex/core/query/SqlConnector.java | 30 +- .../core/query/StringFunctionQueryColumn.java | 7 +- .../core/query/StringQueryColumn.java | 5 +- .../core/query/StringQueryOrderBy.java | 1 + .../mybatisflex/core/query/UnionWrapper.java | 7 +- .../mybatisflex/core/query/WithBuilder.java | 4 +- .../mybatisflex/core/query/WithDetail.java | 1 + .../com/mybatisflex/core/query/WithItem.java | 2 +- .../core/query/WithValuesDetail.java | 2 +- .../mybatisflex/core/query/WrapperUtil.java | 10 +- .../core/relation/AbstractRelation.java | 2 +- .../mybatisflex/core/relation/ManyToOne.java | 16 +- .../mybatisflex/core/relation/OneToOne.java | 16 +- .../core/relation/RelationManager.java | 1 + .../core/relation/ToManyRelation.java | 1 + .../core/relation/ToOneRelation.java | 1 + .../java/com/mybatisflex/core/row/Db.java | 3 +- .../java/com/mybatisflex/core/row/Row.java | 34 +- .../java/com/mybatisflex/core/row/RowCPI.java | 2 +- .../com/mybatisflex/core/row/RowMapper.java | 4 +- .../core/row/RowMapperInvoker.java | 105 +++--- .../com/mybatisflex/core/row/RowUtil.java | 16 +- .../mybatisflex/core/service/IService.java | 10 +- .../mybatisflex/core/table/ColumnInfo.java | 1 + .../core/table/DynamicSchemaProcessor.java | 30 +- .../core/table/DynamicTableProcessor.java | 30 +- .../core/table/EntityWrapperFactory.java | 32 +- .../com/mybatisflex/core/table/IdInfo.java | 1 + .../com/mybatisflex/core/table/TableInfo.java | 1 + .../core/table/TableInfoFactory.java | 51 +-- .../mybatisflex/core/table/TableManager.java | 3 +- .../core/tenant/TenantManager.java | 3 +- .../core/transaction/Propagation.java | 32 +- .../transaction/TransactionalManager.java | 3 +- .../core/update/ModifyAttrsRecordHandler.java | 6 +- .../update/ModifyAttrsRecordProxyFactory.java | 37 +- .../com/mybatisflex/core/update/RawValue.java | 1 + .../com/mybatisflex/core/util/ArrayUtil.java | 3 +- .../com/mybatisflex/core/util/ClassUtil.java | 22 +- .../mybatisflex/core/util/CollectionUtil.java | 1 - .../mybatisflex/core/util/ConvertUtil.java | 6 +- .../com/mybatisflex/core/util/DateUtil.java | 5 +- .../mybatisflex/core/util/EnumWrapper.java | 29 +- .../mybatisflex/core/util/FieldWrapper.java | 39 +-- .../mybatisflex/core/util/LambdaGetter.java | 30 +- .../com/mybatisflex/core/util/MapperUtil.java | 6 +- .../com/mybatisflex/core/util/ObjectUtil.java | 4 +- .../com/mybatisflex/core/util/Reflectors.java | 7 +- .../com/mybatisflex/core/util/SqlUtil.java | 1 - .../mybatisflex/core/util/UpdateEntity.java | 5 +- .../com/mybatisflex/coretest/Account.java | 19 +- .../com/mybatisflex/coretest/Account01.java | 19 +- .../coretest/AccountSqlTester.java | 319 +++++++++--------- .../com/mybatisflex/coretest/Article.java | 19 +- .../coretest/ArticleSqlTester.java | 24 +- .../mybatisflex/coretest/DbTypeUtilTest.java | 19 +- .../mybatisflex/coretest/FunctionSqlTest.java | 22 +- .../mybatisflex/coretest/IfFunctionTest.java | 26 +- .../coretest/OracleDialectTester.java | 42 ++- .../coretest/SqlServer2005DialectTester.java | 26 +- .../mybatisflex/coretest/StringUtilTest.java | 17 + .../mybatisflex/coretest/WithSQLTester.java | 88 +++-- .../query/ArithmeticQueryColumnTest.java | 86 +++-- .../MultiDataSourceAutoConfiguration.java | 2 +- .../MybatisFlexAdminAutoConfiguration.java | 8 +- .../boot/MybatisFlexAutoConfiguration.java | 20 +- ...pendsOnDatabaseInitializationDetector.java | 30 +- .../spring/boot/MybatisFlexProperties.java | 3 +- ...ybatisLanguageDriverAutoConfiguration.java | 9 + .../spring/boot/SpringBootVFS.java | 6 +- .../spring/FlexSqlSessionFactoryBean.java | 31 +- .../spring/FlexTransactionManager.java | 1 + .../java/com/mybatisflex/test/Account.java | 19 +- .../java/com/mybatisflex/test/Account05.java | 33 +- .../java/com/mybatisflex/test/Account1.java | 3 +- .../java/com/mybatisflex/test/Account3.java | 3 +- .../java/com/mybatisflex/test/AccountDTO.java | 35 +- ...AccountInsertWithArrayAttrTestStarter.java | 47 +-- .../com/mybatisflex/test/AccountMapper.java | 17 + .../test/AccountOnSetListener.java | 18 + .../com/mybatisflex/test/AccountTester.java | 52 ++- .../java/com/mybatisflex/test/AgeAware.java | 17 + .../mybatisflex/test/AgeHandleListener.java | 17 + .../java/com/mybatisflex/test/Article.java | 27 +- .../java/com/mybatisflex/test/ArticleDTO.java | 33 +- .../com/mybatisflex/test/ArticleDTO01.java | 29 +- .../java/com/mybatisflex/test/BaseEntity.java | 17 + .../test/DataSourceDecipherTester.java | 24 +- .../com/mybatisflex/test/DbTestStarter.java | 49 +-- .../com/mybatisflex/test/DocWordsCount.java | 19 +- .../java/com/mybatisflex/test/Entity04.java | 35 +- .../mybatisflex/test/Entity04TestStarter.java | 43 +-- .../mybatisflex/test/EntityTestStarter.java | 81 ++--- .../test/InsertWithPkTestStarter.java | 16 +- .../java/com/mybatisflex/test/JavaTester.java | 17 + .../com/mybatisflex/test/JoinTestStarter.java | 47 +-- .../java/com/mybatisflex/test/JoinTester.java | 43 +-- .../test/JoinWithDeleteColumnTestStarter.java | 75 ++-- .../test/MapperProxyCacheTestStarter.java | 50 +-- .../com/mybatisflex/test/MaskManagerTest.java | 33 +- .../test/MultiDataSourceTester.java | 51 +-- .../com/mybatisflex/test/MyAccountMapper.java | 19 +- .../com/mybatisflex/test/MyBaseMapper.java | 17 + .../com/mybatisflex/test/RowTestStarter.java | 41 +-- .../java/com/mybatisflex/test/SexEnum.java | 22 +- .../com/mybatisflex/test/TenantAccount.java | 32 +- .../mybatisflex/test/TenantManagerTester.java | 30 +- .../com/mybatisflex/test/TenantTester.java | 59 ++-- .../java/com/mybatisflex/test/TypeEnum.java | 22 +- .../mybatisflex/test/UpdateWrapperTest.java | 31 +- .../java/com/mybatisflex/test/UserDto.java | 18 + .../test/WrapperSerializeTest.java | 26 +- .../test/relation/onetoone/Account.java | 6 +- .../test/relation/onetoone/AccountDTO.java | 21 +- .../test/relation/onetoone/Book.java | 15 +- .../test/relation/onetoone/IDCard.java | 9 +- .../test/relation/onetoone/Menu.java | 17 +- .../relation/onetoone/RelationsTester.java | 50 +-- .../test/relation/onetoone/Role.java | 15 +- .../com/mybatisflex/test/ListenerTest.java | 31 +- .../test/DataSourceInitListener.java | 18 +- .../test/MyConfigurationCustomizer.java | 19 +- .../mybatisflex/test/SampleApplication.java | 47 ++- .../test/controller/AccountController.java | 45 ++- .../com/mybatisflex/test/entity/Inner.java | 9 +- .../com/mybatisflex/test/entity/Outer.java | 11 +- .../mybatisflex/test/entity/TestEntity.java | 3 +- .../test/mapper/MyAccountMapper.java | 17 + .../com/mybatisflex/test/model/Account.java | 1 + .../test/model/AccountOnSetListener.java | 20 +- .../com/mybatisflex/test/model/AccountVO.java | 11 +- .../mybatisflex/test/model/AccountVO2.java | 12 +- .../com/mybatisflex/test/model/Article.java | 27 +- .../mybatisflex/test/model/BaseEntity.java | 1 + .../com/mybatisflex/test/model/IdEntity.java | 1 + .../com/mybatisflex/test/model/Order.java | 9 +- .../com/mybatisflex/test/model/OrderGood.java | 3 +- .../com/mybatisflex/test/model/RoleKey.java | 3 +- .../com/mybatisflex/test/model/RoleVO1.java | 12 +- .../com/mybatisflex/test/model/RoleVO2.java | 9 +- .../com/mybatisflex/test/model/RoleVO3.java | 11 +- .../java/com/mybatisflex/test/model/User.java | 13 +- .../com/mybatisflex/test/model/UserOrder.java | 3 +- .../com/mybatisflex/test/model/UserRole.java | 3 +- .../com/mybatisflex/test/model/UserVO.java | 11 +- .../com/mybatisflex/test/model/UserVO1.java | 11 +- .../com/mybatisflex/test/model/UserVO2.java | 13 +- .../com/mybatisflex/test/model/UserVO3.java | 11 +- .../com/mybatisflex/test/model/UserVO4.java | 9 +- .../test/service/AccountService.java | 17 + .../mybatisflex/test/common/CloneTest.java | 22 +- .../mybatisflex/test/common/FieldTest.java | 6 +- .../test/common/MapperUtilTest.java | 16 +- .../test/common/QueryWrapperTest.java | 72 ++-- .../mybatisflex/test/common/ReflectTest.java | 4 +- .../mybatisflex/test/common/SerialUtil.java | 10 +- .../test/mapper/AccountMapperTest.java | 70 ++-- .../test/mapper/MyAccountMapperTest.java | 19 +- .../test/mapper/OuterMapperTest.java | 14 +- .../com/mybatisflex/test/entity/Account.java | 13 +- .../java/com/mybatisflex/test/AppConfig.java | 37 +- .../test/mapper/AccountMapper.java | 3 +- .../com/mybatisflex/test/model/Account.java | 39 +-- .../test/model/AccountOnSetListener.java | 20 +- .../com/mybatisflex/test/AccountTest.java | 14 +- 269 files changed, 3427 insertions(+), 2448 deletions(-) diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/EnumValue.java b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/EnumValue.java index ca70acb2..50ef61cd 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/EnumValue.java +++ b/mybatis-flex-annotation/src/main/java/com/mybatisflex/annotation/EnumValue.java @@ -24,4 +24,5 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD}) public @interface EnumValue { -} \ No newline at end of file + +} diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java index 13861e77..05599048 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java @@ -107,7 +107,7 @@ public class Generator { buildPrimaryKey(table); - dialect.buildTableColumns(schemaName,table, globalConfig, dbMeta, conn); + dialect.buildTableColumns(schemaName, table, globalConfig, dbMeta, conn); tables.add(table); } diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/IDialect.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/IDialect.java index eb0763fd..543f98eb 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/IDialect.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/IDialect.java @@ -70,26 +70,26 @@ public interface IDialect { @Override protected ResultSet forRemarks(String schema, Table table, DatabaseMetaData dbMeta, Connection conn) throws SQLException { - if (conn instanceof OracleConnection){ + if (conn instanceof OracleConnection) { ((OracleConnection) conn).setRemarksReporting(true); return dbMeta.getColumns(conn.getCatalog(), StringUtil.isNotBlank(schema) ? schema : dbMeta.getUserName(), table.getName(), null); - }else if ("com.zaxxer.hikari.pool.HikariProxyConnection".equals(conn.getClass().getName())){ - return forRemarks(schema,table,dbMeta,getOriginalConn(HikariProxyConnection.class,"delegate",conn)); - }else if ("com.alibaba.druid.pool.DruidPooledConnection".equals(conn.getClass().getName())){ - return forRemarks(schema,table,dbMeta,getOriginalConn(DruidPooledConnection.class,"conn",conn)); + } else if ("com.zaxxer.hikari.pool.HikariProxyConnection".equals(conn.getClass().getName())) { + return forRemarks(schema, table, dbMeta, getOriginalConn(HikariProxyConnection.class, "delegate", conn)); + } else if ("com.alibaba.druid.pool.DruidPooledConnection".equals(conn.getClass().getName())) { + return forRemarks(schema, table, dbMeta, getOriginalConn(DruidPooledConnection.class, "conn", conn)); } return null; - } + } - private Connection getOriginalConn(Class clazz,String attr,Connection conn){ - Field delegate = ClassUtil.getFirstField(clazz, field -> field.getName().equals(attr)); - try { - delegate.setAccessible(true); - return (Connection) delegate.get(conn); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } + private Connection getOriginalConn(Class clazz, String attr, Connection conn) { + Field delegate = ClassUtil.getFirstField(clazz, field -> field.getName().equals(attr)); + try { + delegate.setAccessible(true); + return (Connection) delegate.get(conn); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } }; /** diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java index 29d2c907..d58d27f3 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java @@ -30,7 +30,7 @@ public abstract class JdbcDialect implements IDialect { @Override public void buildTableColumns(String schemaName, Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException { - Map columnRemarks = buildColumnRemarks(schemaName,table, dbMeta, conn); + Map columnRemarks = buildColumnRemarks(schemaName, table, dbMeta, conn); String sql = forBuildColumnsSql(table.getSchema(), table.getName()); try (Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(sql)) { @@ -58,7 +58,7 @@ public abstract class JdbcDialect implements IDialect { private Map buildColumnRemarks(String schemaName, Table table, DatabaseMetaData dbMeta, Connection conn) { Map columnRemarks = new HashMap<>(); - try (ResultSet colRs = forRemarks(schemaName,table, dbMeta, conn)) { + try (ResultSet colRs = forRemarks(schemaName, table, dbMeta, conn)) { while (colRs.next()) { columnRemarks.put(colRs.getString("COLUMN_NAME"), colRs.getString("REMARKS")); } @@ -99,7 +99,4 @@ public abstract class JdbcDialect implements IDialect { } - - - } diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java index 4c22a873..4544f55b 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java @@ -153,8 +153,8 @@ public class Column { return ""; } else { return "/**\n" + - " * " + comment + "\n" + - " */"; + " * " + comment + "\n" + + " */"; } } @@ -199,14 +199,14 @@ public class Column { //@Column 注解 if (columnConfig.getOnInsertValue() != null - || columnConfig.getOnUpdateValue() != null - || columnConfig.getLarge() != null - || columnConfig.getLogicDelete() != null - || columnConfig.getVersion() != null - || columnConfig.getJdbcType() != null - || columnConfig.getTypeHandler() != null - || columnConfig.getTenantId() != null - || needGenColumnAnnotation + || columnConfig.getOnUpdateValue() != null + || columnConfig.getLarge() != null + || columnConfig.getLogicDelete() != null + || columnConfig.getVersion() != null + || columnConfig.getJdbcType() != null + || columnConfig.getTypeHandler() != null + || columnConfig.getTenantId() != null + || needGenColumnAnnotation ) { annotations.append("@Column("); boolean needComma = false; @@ -280,8 +280,8 @@ public class Column { //lang 包不需要显式导入 if (!propertyType.startsWith("java.lang.") - && !"byte[]".equals(propertyType) - && !"Byte[]".equals(propertyType) + && !"byte[]".equals(propertyType) + && !"Byte[]".equals(propertyType) ) { importClasses.add(propertyType); } @@ -308,14 +308,14 @@ public class Column { } if (columnConfig.getOnInsertValue() != null - || columnConfig.getOnUpdateValue() != null - || columnConfig.getLarge() != null - || columnConfig.getLogicDelete() != null - || columnConfig.getVersion() != null - || columnConfig.getJdbcType() != null - || columnConfig.getTypeHandler() != null - || Boolean.TRUE.equals(columnConfig.getTenantId()) - || needGenColumnAnnotation + || columnConfig.getOnUpdateValue() != null + || columnConfig.getLarge() != null + || columnConfig.getLogicDelete() != null + || columnConfig.getVersion() != null + || columnConfig.getJdbcType() != null + || columnConfig.getTypeHandler() != null + || Boolean.TRUE.equals(columnConfig.getTenantId()) + || needGenColumnAnnotation ) { importClasses.add(com.mybatisflex.annotation.Column.class.getName()); } @@ -336,11 +336,11 @@ public class Column { @Override public String toString() { return "Column{" + - "name='" + name + '\'' + - ", className='" + propertyType + '\'' + - ", remarks='" + comment + '\'' + - ", isAutoIncrement=" + isAutoIncrement + - '}'; + "name='" + name + '\'' + + ", className='" + propertyType + '\'' + + ", remarks='" + comment + '\'' + + ", isAutoIncrement=" + isAutoIncrement + + '}'; } } diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java index 4ad6fbe1..92f02760 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java @@ -92,10 +92,10 @@ public class Table { public String getPrimaryKey() { // 这里默认表中一定会有字段,就不做空判断了 return columns.stream() - .filter(Column::isPrimaryKey) - .findFirst() - .map(Column::getProperty) - .orElse(null); + .filter(Column::isPrimaryKey) + .findFirst() + .map(Column::getProperty) + .orElse(null); } public Set getPrimaryKeys() { @@ -271,7 +271,7 @@ public class Table { Class[] entityInterfaces = globalConfig.getEntityConfig().getImplInterfaces(); if (entityInterfaces != null && entityInterfaces.length > 0) { return " implements " + StringUtil.join(", ", Arrays.stream(entityInterfaces) - .map(Class::getSimpleName).collect(Collectors.toList())); + .map(Class::getSimpleName).collect(Collectors.toList())); } else { return ""; } @@ -305,8 +305,8 @@ public class Table { String entityJavaFileName = getEntityJavaFileName(); EntityConfig entityConfig = globalConfig.getEntityConfig(); return entityConfig.getClassPrefix() - + entityJavaFileName - + entityConfig.getClassSuffix(); + + entityJavaFileName + + entityConfig.getClassSuffix(); } /** @@ -316,8 +316,8 @@ public class Table { String tableDefJavaFileName = getEntityJavaFileName(); TableDefConfig tableDefConfig = globalConfig.getTableDefConfig(); return tableDefConfig.getClassPrefix() - + tableDefJavaFileName - + tableDefConfig.getClassSuffix(); + + tableDefJavaFileName + + tableDefConfig.getClassSuffix(); } /** @@ -327,8 +327,8 @@ public class Table { String entityJavaFileName = getEntityJavaFileName(); MapperConfig mapperConfig = globalConfig.getMapperConfig(); return mapperConfig.getClassPrefix() - + entityJavaFileName - + mapperConfig.getClassSuffix(); + + entityJavaFileName + + mapperConfig.getClassSuffix(); } /** @@ -338,8 +338,8 @@ public class Table { String entityJavaFileName = getEntityJavaFileName(); ServiceConfig serviceConfig = globalConfig.getServiceConfig(); return serviceConfig.getClassPrefix() - + entityJavaFileName - + serviceConfig.getClassSuffix(); + + entityJavaFileName + + serviceConfig.getClassSuffix(); } /** @@ -349,8 +349,8 @@ public class Table { String entityJavaFileName = getEntityJavaFileName(); ServiceImplConfig serviceImplConfig = globalConfig.getServiceImplConfig(); return serviceImplConfig.getClassPrefix() - + entityJavaFileName - + serviceImplConfig.getClassSuffix(); + + entityJavaFileName + + serviceImplConfig.getClassSuffix(); } /** @@ -360,8 +360,8 @@ public class Table { String entityJavaFileName = getEntityJavaFileName(); ControllerConfig controllerConfig = globalConfig.getControllerConfig(); return controllerConfig.getClassPrefix() - + entityJavaFileName - + controllerConfig.getClassSuffix(); + + entityJavaFileName + + controllerConfig.getClassSuffix(); } /** @@ -371,19 +371,19 @@ public class Table { String tableDefJavaFileName = getEntityJavaFileName(); MapperXmlConfig mapperXmlConfig = globalConfig.getMapperXmlConfig(); return mapperXmlConfig.getFilePrefix() - + tableDefJavaFileName - + mapperXmlConfig.getFileSuffix(); + + tableDefJavaFileName + + mapperXmlConfig.getFileSuffix(); } @Override public String toString() { return "Table{" + - "schema'" + schema + '\'' + - "name='" + name + '\'' + - ", remarks='" + comment + '\'' + - ", primaryKeys='" + primaryKeys + '\'' + - ", columns=" + columns + - '}'; + "schema'" + schema + '\'' + + "name='" + name + '\'' + + ", remarks='" + comment + '\'' + + ", primaryKeys='" + primaryKeys + '\'' + + ", columns=" + columns + + '}'; } } diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ControllerGenerator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ControllerGenerator.java index 0265a043..47db2408 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ControllerGenerator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ControllerGenerator.java @@ -56,7 +56,7 @@ public class ControllerGenerator implements IGenerator { String controllerPackagePath = packageConfig.getControllerPackage().replace(".", "/"); File controllerJavaFile = new File(packageConfig.getSourceDir(), controllerPackagePath + "/" + - table.buildControllerClassName() + ".java"); + table.buildControllerClassName() + ".java"); if (controllerJavaFile.exists() && !controllerConfig.isOverwriteEnable()) { diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/EntityGenerator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/EntityGenerator.java index ac892bd8..b7f87bf5 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/EntityGenerator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/EntityGenerator.java @@ -56,7 +56,7 @@ public class EntityGenerator implements IGenerator { String entityPackagePath = packageConfig.getEntityPackage().replace(".", "/"); File entityJavaFile = new File(packageConfig.getSourceDir(), entityPackagePath + "/" + - table.buildEntityClassName() + ".java"); + table.buildEntityClassName() + ".java"); if (entityJavaFile.exists() && !entityConfig.isOverwriteEnable()) { diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperGenerator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperGenerator.java index 5204d02e..baa73240 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperGenerator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperGenerator.java @@ -53,10 +53,10 @@ public class MapperGenerator implements IGenerator { PackageConfig packageConfig = globalConfig.getPackageConfig(); MapperConfig mapperConfig = globalConfig.getMapperConfig(); - + String mapperPackagePath = packageConfig.getMapperPackage().replace(".", "/"); File mapperJavaFile = new File(packageConfig.getSourceDir(), mapperPackagePath + "/" + - table.buildMapperClassName() + ".java"); + table.buildMapperClassName() + ".java"); if (mapperJavaFile.exists() && !mapperConfig.isOverwriteEnable()) { diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperXmlGenerator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperXmlGenerator.java index a03cb7df..7c18c0eb 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperXmlGenerator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/MapperXmlGenerator.java @@ -55,7 +55,7 @@ public class MapperXmlGenerator implements IGenerator { MapperXmlConfig mapperXmlConfig = globalConfig.getMapperXmlConfig(); File mapperXmlFile = new File(packageConfig.getMapperXmlPath() + "/" + - table.buildMapperXmlFileName() + ".xml"); + table.buildMapperXmlFileName() + ".xml"); if (mapperXmlFile.exists() && !mapperXmlConfig.isOverwriteEnable()) { diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceGenerator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceGenerator.java index 2c7d0079..34d156ed 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceGenerator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceGenerator.java @@ -53,10 +53,10 @@ public class ServiceGenerator implements IGenerator { PackageConfig packageConfig = globalConfig.getPackageConfig(); ServiceConfig serviceConfig = globalConfig.getServiceConfig(); - + String servicePackagePath = packageConfig.getServicePackage().replace(".", "/"); File serviceJavaFile = new File(packageConfig.getSourceDir(), servicePackagePath + "/" + - table.buildServiceClassName() + ".java"); + table.buildServiceClassName() + ".java"); if (serviceJavaFile.exists() && !serviceConfig.isOverwriteEnable()) { diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceImplGenerator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceImplGenerator.java index 147c4477..71ec4610 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceImplGenerator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/ServiceImplGenerator.java @@ -53,10 +53,10 @@ public class ServiceImplGenerator implements IGenerator { PackageConfig packageConfig = globalConfig.getPackageConfig(); ServiceImplConfig serviceImplConfig = globalConfig.getServiceImplConfig(); - + String serviceImplPackagePath = packageConfig.getServiceImplPackage().replace(".", "/"); File serviceImplJavaFile = new File(packageConfig.getSourceDir(), serviceImplPackagePath + "/" + - table.buildServiceImplClassName() + ".java"); + table.buildServiceImplClassName() + ".java"); if (serviceImplJavaFile.exists() && !serviceImplConfig.isOverwriteEnable()) { diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/TableDefGenerator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/TableDefGenerator.java index 8ea25e78..1bf83d06 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/TableDefGenerator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/TableDefGenerator.java @@ -47,7 +47,7 @@ public class TableDefGenerator implements IGenerator { @Override public void generate(Table table, GlobalConfig globalConfig) { - if (!globalConfig.isTableDefGenerateEnable()){ + if (!globalConfig.isTableDefGenerateEnable()) { return; } @@ -56,7 +56,7 @@ public class TableDefGenerator implements IGenerator { String tableDefPackagePath = packageConfig.getTableDefPackage().replace(".", "/"); File tableDefJavaFile = new File(packageConfig.getSourceDir(), tableDefPackagePath + "/" + - table.buildTableDefClassName() + ".java"); + table.buildTableDefClassName() + ".java"); if (tableDefJavaFile.exists() && !tableDefConfig.isOverwriteEnable()) { diff --git a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/BaseEntity.java b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/BaseEntity.java index bfc6d36b..1863ec20 100644 --- a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/BaseEntity.java +++ b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/BaseEntity.java @@ -1,8 +1,25 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.codegen.test; import java.util.Date; public class BaseEntity { + private Date createTime; public Date getCreateTime() { @@ -12,4 +29,5 @@ public class BaseEntity { public void setCreateTime(Date createTime) { this.createTime = createTime; } + } diff --git a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java index 24081993..42de4953 100644 --- a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java +++ b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/GeneratorTest.java @@ -148,7 +148,7 @@ public class GeneratorTest { generator.generate(); } -// @Test + // @Test public void testCodeGen3() { //配置数据源 HikariDataSource dataSource = new HikariDataSource(); diff --git a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyBaseMapper.java b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyBaseMapper.java index 057a5a93..ea398945 100644 --- a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyBaseMapper.java +++ b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyBaseMapper.java @@ -1,6 +1,23 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.codegen.test; import com.mybatisflex.core.BaseMapper; -public interface MyBaseMapper extends BaseMapper { +public interface MyBaseMapper extends BaseMapper { + } diff --git a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyUpdateListener.java b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyUpdateListener.java index 65bfd013..7ae55d16 100644 --- a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyUpdateListener.java +++ b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/MyUpdateListener.java @@ -1,10 +1,28 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.codegen.test; import com.mybatisflex.annotation.UpdateListener; public class MyUpdateListener implements UpdateListener { + @Override public void onUpdate(Object entity) { } + } diff --git a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/SqliteGeneratorTest.java b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/SqliteGeneratorTest.java index 62c9f0b1..e41ede44 100644 --- a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/SqliteGeneratorTest.java +++ b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/test/SqliteGeneratorTest.java @@ -17,11 +17,9 @@ package com.mybatisflex.codegen.test; import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.pool.DruidPooledConnection; import com.mybatisflex.codegen.Generator; import com.mybatisflex.codegen.config.GlobalConfig; import com.mybatisflex.codegen.dialect.IDialect; -import org.junit.Test; import javax.sql.DataSource; import java.sql.Connection; @@ -29,7 +27,7 @@ import java.sql.Statement; public class SqliteGeneratorTest { -// @Test + // @Test public void testGenerator3() { //配置数据源 @@ -50,15 +48,15 @@ public class SqliteGeneratorTest { //配置生成文件目录与根包 globalConfig.getPackageConfig() - .setSourceDir(System.getProperty("user.dir") + "/src/test/java") - .setBasePackage("com.test"); + .setSourceDir(System.getProperty("user.dir") + "/src/test/java") + .setBasePackage("com.test"); //设置只生成哪些表 globalConfig.getStrategyConfig() - .setGenerateTable("person"); + .setGenerateTable("person"); globalConfig.enableEntity() - .setWithLombok(true); + .setWithLombok(true); //设置生成 mapper 类 globalConfig.enableMapper(); @@ -85,4 +83,5 @@ public class SqliteGeneratorTest { e.printStackTrace(); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexConsts.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexConsts.java index 5c838955..1e081c11 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexConsts.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexConsts.java @@ -20,7 +20,8 @@ package com.mybatisflex.core; */ public class FlexConsts { - private FlexConsts() {} + private FlexConsts() { + } public static final String NAME = "MyBatis-Flex"; public static final String VERSION = "1.4.9"; @@ -57,4 +58,5 @@ public class FlexConsts { * 当 entity 使用逻辑删除时,1 为 entity 的删除状态 */ public static final int LOGIC_DELETE_DELETED = 1; + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java index 8913de1b..b518aa08 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core; @@ -23,7 +23,10 @@ import com.mybatisflex.core.dialect.DbType; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSessionFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** @@ -317,6 +320,7 @@ public class FlexGlobalConfig { * 对应的是 注解 {@link com.mybatisflex.annotation.Id} 的配置 */ public static class KeyConfig { + private KeyType keyType; private String value; private boolean before = true; @@ -344,6 +348,7 @@ public class FlexGlobalConfig { public void setBefore(boolean before) { this.before = before; } + } @@ -390,7 +395,7 @@ public class FlexGlobalConfig { defaultConfig.setConfiguration(config.configuration); if (defaultConfig.getKeyConfig() == null - && config.keyConfig != null) { + && config.keyConfig != null) { defaultConfig.setKeyConfig(config.keyConfig); } @@ -399,4 +404,5 @@ public class FlexGlobalConfig { globalConfigs.put(id, config); } -} \ No newline at end of file + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/MybatisFlexBootstrap.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/MybatisFlexBootstrap.java index 122479f2..ab310c62 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/MybatisFlexBootstrap.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/MybatisFlexBootstrap.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core; @@ -156,14 +156,14 @@ public class MybatisFlexBootstrap { */ public T getMapper(Class mapperClass) { Object mapperObject = MapUtil.computeIfAbsent(mapperObjects, mapperClass, clazz -> - Proxy.newProxyInstance(mapperClass.getClassLoader() - , new Class[]{mapperClass} - , (proxy, method, args) -> { - try (SqlSession sqlSession = openSession()) { - T mapper1 = sqlSession.getMapper(mapperClass); - return method.invoke(mapper1, args); - } - })); + Proxy.newProxyInstance(mapperClass.getClassLoader() + , new Class[]{mapperClass} + , (proxy, method, args) -> { + try (SqlSession sqlSession = openSession()) { + T mapper1 = sqlSession.getMapper(mapperClass); + return method.invoke(mapper1, args); + } + })); return (T) mapperObject; } @@ -241,4 +241,5 @@ public class MybatisFlexBootstrap { this.logImpl = logImpl; return this; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java index 741dc581..f2a8e298 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java @@ -151,7 +151,9 @@ public class AuditManager { @FunctionalInterface public interface AuditRunnable { + T execute() throws SQLException; + } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java index d8335e33..fbae302d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java @@ -25,7 +25,10 @@ import java.lang.reflect.Proxy; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * SQL 审计详细消息。 @@ -207,15 +210,15 @@ public class AuditMessage implements Serializable { private PreparedStatement createPreparedStatement(Statement statement) { return (PreparedStatement) Proxy.newProxyInstance( - AuditMessage.class.getClassLoader(), - new Class[]{PreparedStatement.class}, (proxy, method, args) -> { - if (args != null && (args.length == 2 || args.length == 3)) { - doAddParam(statement, args[1]); - } else if ("getConnection".equals(method.getName())) { - return statement.getConnection(); - } - return null; - }); + AuditMessage.class.getClassLoader(), + new Class[]{PreparedStatement.class}, (proxy, method, args) -> { + if (args != null && (args.length == 2 || args.length == 3)) { + doAddParam(statement, args[1]); + } else if ("getConnection".equals(method.getName())) { + return statement.getConnection(); + } + return null; + }); } public int getQueryCount() { @@ -260,20 +263,20 @@ public class AuditMessage implements Serializable { @Override public String toString() { return "AuditMessage{" + - "platform='" + platform + '\'' + - ", module='" + module + '\'' + - ", url='" + url + '\'' + - ", bizId='" + bizId + '\'' + - ", user='" + user + '\'' + - ", userIp='" + userIp + '\'' + - ", hostIp='" + hostIp + '\'' + - ", query='" + query + '\'' + - ", queryParams=" + queryParams + - ", queryCount=" + queryCount + - ", queryTime=" + queryTime + - ", elapsedTime=" + elapsedTime + - ", metas=" + metas + - '}'; + "platform='" + platform + '\'' + + ", module='" + module + '\'' + + ", url='" + url + '\'' + + ", bizId='" + bizId + '\'' + + ", user='" + user + '\'' + + ", userIp='" + userIp + '\'' + + ", hostIp='" + hostIp + '\'' + + ", query='" + query + '\'' + + ", queryParams=" + queryParams + + ", queryCount=" + queryCount + + ", queryTime=" + queryTime + + ", elapsedTime=" + elapsedTime + + ", metas=" + metas + + '}'; } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/Clock.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/Clock.java index 9539ac0e..ea235bbf 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/Clock.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/Clock.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.audit; @@ -20,6 +20,6 @@ package com.mybatisflex.core.audit; */ public interface Clock { - long getTick(); + long getTick(); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ConsoleMessageCollector.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ConsoleMessageCollector.java index f07208b4..bceb48a1 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ConsoleMessageCollector.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ConsoleMessageCollector.java @@ -39,6 +39,9 @@ public class ConsoleMessageCollector implements MessageCollector { } public interface SqlDebugPrinter { + void print(String sql, Long tookTimeMillis); + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageCollector.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageCollector.java index 2764f758..301c0dae 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageCollector.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageCollector.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.audit; @@ -19,5 +19,7 @@ package com.mybatisflex.core.audit; * 审计消息收集器 */ public interface MessageCollector { + void collect(AuditMessage message); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageFactory.java index 9b4f1104..66e72d89 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/MessageFactory.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.audit; @@ -21,6 +21,6 @@ package com.mybatisflex.core.audit; */ public interface MessageFactory { - AuditMessage create(); + AuditMessage create(); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java index 063b9686..81d8eaba 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java @@ -81,4 +81,5 @@ public class ScheduledMessageCollector implements MessageCollector, Runnable { run(); //clear the messages scheduler.shutdown(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java index c2bb87bc..2dcd7955 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.audit.http; @@ -41,7 +41,9 @@ public class HttpMessageReporter implements MessageReporter { } public interface JSONFormatter { + String toJSONString(Object object); + } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpUtil.java index d91195ca..e81cf060 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpUtil.java @@ -38,7 +38,8 @@ import java.util.Map.Entry; */ public class HttpUtil { - private HttpUtil() {} + private HttpUtil() { + } private static final String POST = "POST"; @@ -74,16 +75,19 @@ public class HttpUtil { * https 域名校验 */ private static class TrustAnyHostnameVerifier implements HostnameVerifier { + @Override public boolean verify(String hostname, SSLSession session) { return true; } + } /** * https 证书管理 */ private static class TrustAnyTrustManager implements X509TrustManager { + @Override public X509Certificate[] getAcceptedIssuers() { return null; @@ -96,6 +100,7 @@ public class HttpUtil { @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/AbstractDataSource.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/AbstractDataSource.java index 6fcb3ac0..66f05ba6 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/AbstractDataSource.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/AbstractDataSource.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.datasource; @@ -25,60 +25,58 @@ import java.util.logging.Logger; public abstract class AbstractDataSource implements DataSource { - /** - * Returns 0, indicating the default system timeout is to be used. - */ - @Override - public int getLoginTimeout() throws SQLException { - return 0; - } + /** + * Returns 0, indicating the default system timeout is to be used. + */ + @Override + public int getLoginTimeout() throws SQLException { + return 0; + } - /** - * Setting a login timeout is not supported. - */ - @Override - public void setLoginTimeout(int timeout) throws SQLException { - throw new UnsupportedOperationException("setLoginTimeout"); - } + /** + * Setting a login timeout is not supported. + */ + @Override + public void setLoginTimeout(int timeout) throws SQLException { + throw new UnsupportedOperationException("setLoginTimeout"); + } - /** - * LogWriter methods are not supported. - */ - @Override - public PrintWriter getLogWriter() { - throw new UnsupportedOperationException("getLogWriter"); - } + /** + * LogWriter methods are not supported. + */ + @Override + public PrintWriter getLogWriter() { + throw new UnsupportedOperationException("getLogWriter"); + } - /** - * LogWriter methods are not supported. - */ - @Override - public void setLogWriter(PrintWriter pw) throws SQLException { - throw new UnsupportedOperationException("setLogWriter"); - } + /** + * LogWriter methods are not supported. + */ + @Override + public void setLogWriter(PrintWriter pw) throws SQLException { + throw new UnsupportedOperationException("setLogWriter"); + } + @Override + @SuppressWarnings("unchecked") + public T unwrap(Class iface) throws SQLException { + if (iface.isInstance(this)) { + return (T) this; + } + throw new SQLException("DataSource of type [" + getClass().getName() + + "] cannot be unwrapped as [" + iface.getName() + "]"); + } - @Override - @SuppressWarnings("unchecked") - public T unwrap(Class iface) throws SQLException { - if (iface.isInstance(this)) { - return (T) this; - } - throw new SQLException("DataSource of type [" + getClass().getName() + - "] cannot be unwrapped as [" + iface.getName() + "]"); - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return iface.isInstance(this); - } + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return iface.isInstance(this); + } - - @Override - public Logger getParentLogger() { - return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); - } + @Override + public Logger getParentLogger() { + return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java index 5e718d70..949b487b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.datasource; @@ -113,10 +113,10 @@ public class DataSourceBuilder { private String detectDataSourceClass() { String[] detectClassNames = new String[]{ - "com.alibaba.druid.pool.DruidDataSource", - "com.zaxxer.hikari.HikariDataSource", - "cn.beecp.BeeDataSource", - "org.apache.commons.dbcp2.BasicDataSource", + "com.alibaba.druid.pool.DruidDataSource", + "com.zaxxer.hikari.HikariDataSource", + "cn.beecp.BeeDataSource", + "org.apache.commons.dbcp2.BasicDataSource", }; for (String detectClassName : detectClassNames) { @@ -138,4 +138,5 @@ public class DataSourceBuilder { return null; } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java index c7379059..bc87eb83 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java @@ -19,7 +19,8 @@ import java.util.function.Supplier; public class DataSourceKey { - private DataSourceKey() {} + private DataSourceKey() { + } private static final ThreadLocal keyThreadLocal = new ThreadLocal<>(); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/FlexDataSource.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/FlexDataSource.java index ea3c32a6..ad8f3ba8 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/FlexDataSource.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/FlexDataSource.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.datasource; @@ -139,7 +139,7 @@ public class FlexDataSource extends AbstractDataSource { } catch (SQLException e) { if (log.isDebugEnabled()) { log.debug("Error resetting autocommit to true " - + "before closing the connection. Cause: " + e); + + "before closing the connection. Cause: " + e); } } } @@ -147,8 +147,8 @@ public class FlexDataSource extends AbstractDataSource { public Connection proxy(Connection connection, String xid) { return (Connection) Proxy.newProxyInstance(FlexDataSource.class.getClassLoader() - , new Class[]{Connection.class} - , new ConnectionHandler(connection, xid)); + , new Class[]{Connection.class} + , new ConnectionHandler(connection, xid)); } /** @@ -188,6 +188,7 @@ public class FlexDataSource extends AbstractDataSource { } private static class ConnectionHandler implements InvocationHandler { + private static final String[] proxyMethods = new String[]{"commit", "rollback", "close", "setAutoCommit"}; private final Connection original; private final String xid; @@ -203,7 +204,7 @@ public class FlexDataSource extends AbstractDataSource { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ArrayUtil.contains(proxyMethods, method.getName()) - && isTransactional()) { + && isTransactional()) { //do nothing return null; } @@ -219,6 +220,7 @@ public class FlexDataSource extends AbstractDataSource { private boolean isTransactional() { return Objects.equals(xid, TransactionContext.getXID()); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java index de760598..c9796de0 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java @@ -160,7 +160,7 @@ public class DbTypeUtil { return DbType.TDENGINE; } else if (jdbcUrl.contains(":informix")) { return DbType.INFORMIX; - }else if (jdbcUrl.contains(":sinodb")) { + } else if (jdbcUrl.contains(":sinodb")) { return DbType.SINODB; } else if (jdbcUrl.contains(":uxdb:")) { return DbType.UXDB; @@ -180,4 +180,5 @@ public class DbTypeUtil { } return Pattern.compile(regex).matcher(jdbcUrl).find(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DialectFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DialectFactory.java index f7578246..5a146f57 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DialectFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DialectFactory.java @@ -30,7 +30,8 @@ import java.util.Map; */ public class DialectFactory { - private DialectFactory() {} + private DialectFactory() { + } /** * 数据库类型和方言的映射关系,可以通过其读取指定的方言,亦可能通过其扩展其他方言 @@ -134,8 +135,8 @@ public class DialectFactory { return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.DERBY); case SQLSERVER: return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.SQLSERVER); - case SQLSERVER_2005: - return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.SQLSERVER_2005); + case SQLSERVER_2005: + return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.SQLSERVER_2005); case INFORMIX: return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.INFORMIX); case SINODB: @@ -146,4 +147,5 @@ public class DialectFactory { return new CommonsDialectImpl(); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/LimitOffsetProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/LimitOffsetProcessor.java index 3140019b..3c47893b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/LimitOffsetProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/LimitOffsetProcessor.java @@ -15,7 +15,10 @@ */ package com.mybatisflex.core.dialect; -import com.mybatisflex.core.query.*; +import com.mybatisflex.core.query.CPI; +import com.mybatisflex.core.query.QueryOrderBy; +import com.mybatisflex.core.query.QueryTable; +import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.util.CollectionUtil; import java.util.List; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/OracleDialect.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/OracleDialect.java index 54678350..e3ed6437 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/OracleDialect.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/OracleDialect.java @@ -36,50 +36,50 @@ public class OracleDialect extends CommonsDialectImpl { //https://docs.oracle.com/cd/A97630_01/appdev.920/a42525/apb.htm public static final Set keywords = CollectionUtil.newHashSet( - "ACCESS", "ELSE", "MODIFY", "START", "ADD", "EXCLUSIVE", "NOAUDIT", "SELECT", - "ALL", "EXISTS", "NOCOMPRESS", "SESSION", "ALTER", "FILE", "NOT", "SET", "AND", "FLOAT", - "NOTFOUND", "SHARE", "ANY", "FOR", "NOWAIT", "SIZE", "ARRAYLEN", "FROM", "NULL", "SMALLINT", - "AS", "GRANT", "NUMBER", "SQLBUF", "ASC", "GROUP", "OF", "SUCCESSFUL", "AUDIT", "HAVING", - "OFFLINE", "SYNONYM", "BETWEEN", "IDENTIFIED", "ON", "SYSDATE", "BY", "IMMEDIATE", "ONLINE", - "TABLE", "CHAR", "IN", "OPTION", "THEN", "CHECK", "INCREMENT", "OR", "TO", "CLUSTER", "INDEX", - "ORDER", "TRIGGER", "COLUMN", "INITIAL", "PCTFREE", "UID", "COMMENT", "INSERT", "PRIOR", - "UNION", "COMPRESS", "INTEGER", "PRIVILEGES", "UNIQUE", "CONNECT", "INTERSECT", "PUBLIC", - "UPDATE", "CREATE", "INTO", "RAW", "USER", "CURRENT", "IS", "RENAME", "VALIDATE", "DATE", "LEVEL", - "RESOURCE", "VALUES", "DECIMAL", "LIKE", "REVOKE", "VARCHAR", "DEFAULT", "LOCK", "ROW", "VARCHAR2", - "DELETE", "LONG", "ROWID", "VIEW", "DESC", "MAXEXTENTS", "ROWLABEL", "WHENEVER", "DISTINCT", "MINUS", - "ROWNUM", "WHERE", "DROP", "MODE", "ROWS", "WITH", "ADMIN", "CURSOR", "FOUND", "MOUNT", "AFTER", "CYCLE", - "FUNCTION", "NEXT", "ALLOCATE", "DATABASE", "GO", "NEW", "ANALYZE", "DATAFILE", "GOTO", "NOARCHIVELOG", - "ARCHIVE", "DBA", "GROUPS", "NOCACHE", "ARCHIVELOG", "DEC", "INCLUDING", "NOCYCLE", "AUTHORIZATION", - "DECLARE", "INDICATOR", "NOMAXVALUE", "AVG", "DISABLE", "INITRANS", "NOMINVALUE", "BACKUP", "DISMOUNT", - "INSTANCE", "NONE", "BEGIN", "DOUBLE", "INT", "NOORDER", "BECOME", "DUMP", "KEY", "NORESETLOGS", "BEFORE", - "EACH", "LANGUAGE", "NORMAL", "BLOCK", "ENABLE", "LAYER", "NOSORT", "BODY", "END", "LINK", "NUMERIC", "CACHE", - "ESCAPE", "LISTS", "OFF", "CANCEL", "EVENTS", "LOGFILE", "OLD", "CASCADE", "EXCEPT", "MANAGE", "ONLY", "CHANGE", - "EXCEPTIONS", "MANUAL", "OPEN", "CHARACTER", "EXEC", "MAX", "OPTIMAL", "CHECKPOINT", "EXPLAIN", "MAXDATAFILES", - "OWN", "CLOSE", "EXECUTE", "MAXINSTANCES", "PACKAGE", "COBOL", "EXTENT", "MAXLOGFILES", "PARALLEL", "COMMIT", - "EXTERNALLY", "MAXLOGHISTORY", "PCTINCREASE", "COMPILE", "FETCH", "MAXLOGMEMBERS", "PCTUSED", "CONSTRAINT", - "FLUSH", "MAXTRANS", "PLAN", "CONSTRAINTS", "FREELIST", "MAXVALUE", "PLI", "CONTENTS", "FREELISTS", "MIN", - "PRECISION", "CONTINUE", "FORCE", "MINEXTENTS", "PRIMARY", "CONTROLFILE", "FOREIGN", "MINVALUE", "PRIVATE", - "COUNT", "FORTRAN", "MODULE", "PROCEDURE", "PROFILE", "SAVEPOINT", "SQLSTATE", "TRACING", "QUOTA", "SCHEMA", - "STATEMENT_ID", "TRANSACTION", "READ", "SCN", "STATISTICS", "TRIGGERS", "REAL", "SECTION", "STOP", "TRUNCATE", - "RECOVER", "SEGMENT", "STORAGE", "UNDER", "REFERENCES", "SEQUENCE", "SUM", "UNLIMITED", "REFERENCING", "SHARED", - "SWITCH", "UNTIL", "RESETLOGS", "SNAPSHOT", "SYSTEM", "USE", "RESTRICTED", "SOME", "TABLES", "USING", "REUSE", - "SORT", "TABLESPACE", "WHEN", "ROLE", "SQL", "TEMPORARY", "WRITE", "ROLES", "SQLCODE", "THREAD", "WORK", "ROLLBACK", - "SQLERROR", "TIME", "ABORT", "BETWEEN", "CRASH", "DIGITS", "ACCEPT", "BINARY_INTEGER", "CREATE", "DISPOSE", "ACCESS", - "BODY", "CURRENT", "DISTINCT", "ADD", "BOOLEAN", "CURRVAL", "DO", "ALL", "BY", "CURSOR", "DROP", "ALTER", "CASE", "DATABASE", - "ELSE", "AND", "CHAR", "DATA_BASE", "ELSIF", "ANY", "CHAR_BASE", "DATE", "END", "ARRAY", "CHECK", "DBA", "ENTRY", "ARRAYLEN", - "CLOSE", "DEBUGOFF", "EXCEPTION", "AS", "CLUSTER", "DEBUGON", "EXCEPTION_INIT", "ASC", "CLUSTERS", "DECLARE", "EXISTS", - "ASSERT", "COLAUTH", "DECIMAL", "EXIT", "ASSIGN", "COLUMNS", "DEFAULT", "FALSE", "AT", "COMMIT", "DEFINITION", "FETCH", - "AUTHORIZATION", "COMPRESS", "DELAY", "FLOAT", "AVG", "CONNECT", "DELETE", "FOR", "BASE_TABLE", "CONSTANT", "DELTA", "FORM", - "BEGIN", "COUNT", "DESC", "FROM", "FUNCTION", "NEW", "RELEASE", "SUM", "GENERIC", "NEXTVAL", "REMR", "TABAUTH", - "GOTO", "NOCOMPRESS", "RENAME", "TABLE", "GRANT", "NOT", "RESOURCE", "TABLES", "GROUP", "NULL", "RETURN", "TASK", "HAVING", - "NUMBER", "REVERSE", "TERMINATE", "IDENTIFIED", "NUMBER_BASE", "REVOKE", "THEN", "IF", "OF", "ROLLBACK", "TO", "IN", "ON", - "ROWID", "TRUE", "INDEX", "OPEN", "ROWLABEL", "TYPE", "INDEXES", "OPTION", "ROWNUM", "UNION", "INDICATOR", "OR", "ROWTYPE", - "UNIQUE", "INSERT", "ORDER", "RUN", "UPDATE", "INTEGER", "OTHERS", "SAVEPOINT", "USE", "INTERSECT", "OUT", "SCHEMA", "VALUES", - "INTO", "PACKAGE", "SELECT", "VARCHAR", "IS", "PARTITION", "SEPARATE", "VARCHAR2", "LEVEL", "PCTFREE", "SET", "VARIANCE", - "LIKE", "POSITIVE", "SIZE", "VIEW", "LIMITED", "PRAGMA", "SMALLINT", "VIEWS", "LOOP", "PRIOR", "SPACE", "WHEN", "MAX", "PRIVATE", - "SQL", "WHERE", "MIN", "PROCEDURE", "SQLCODE", "WHILE", "MINUS", "PUBLIC", "SQLERRM", "WITH", "MLSLABEL", "RAISE", "START", - "WORK", "MOD", "RANGE", "STATEMENT", "XOR", "MODE", "REAL", "STDDEV", "NATURAL", "RECORD", "SUBTYPE", "GEN", "KP", "L", - "NA", "NC", "ND", "NL", "NM", "NR", "NS", "NT", "NZ", "TTC", "UPI", "O", "S", "XA" + "ACCESS", "ELSE", "MODIFY", "START", "ADD", "EXCLUSIVE", "NOAUDIT", "SELECT", + "ALL", "EXISTS", "NOCOMPRESS", "SESSION", "ALTER", "FILE", "NOT", "SET", "AND", "FLOAT", + "NOTFOUND", "SHARE", "ANY", "FOR", "NOWAIT", "SIZE", "ARRAYLEN", "FROM", "NULL", "SMALLINT", + "AS", "GRANT", "NUMBER", "SQLBUF", "ASC", "GROUP", "OF", "SUCCESSFUL", "AUDIT", "HAVING", + "OFFLINE", "SYNONYM", "BETWEEN", "IDENTIFIED", "ON", "SYSDATE", "BY", "IMMEDIATE", "ONLINE", + "TABLE", "CHAR", "IN", "OPTION", "THEN", "CHECK", "INCREMENT", "OR", "TO", "CLUSTER", "INDEX", + "ORDER", "TRIGGER", "COLUMN", "INITIAL", "PCTFREE", "UID", "COMMENT", "INSERT", "PRIOR", + "UNION", "COMPRESS", "INTEGER", "PRIVILEGES", "UNIQUE", "CONNECT", "INTERSECT", "PUBLIC", + "UPDATE", "CREATE", "INTO", "RAW", "USER", "CURRENT", "IS", "RENAME", "VALIDATE", "DATE", "LEVEL", + "RESOURCE", "VALUES", "DECIMAL", "LIKE", "REVOKE", "VARCHAR", "DEFAULT", "LOCK", "ROW", "VARCHAR2", + "DELETE", "LONG", "ROWID", "VIEW", "DESC", "MAXEXTENTS", "ROWLABEL", "WHENEVER", "DISTINCT", "MINUS", + "ROWNUM", "WHERE", "DROP", "MODE", "ROWS", "WITH", "ADMIN", "CURSOR", "FOUND", "MOUNT", "AFTER", "CYCLE", + "FUNCTION", "NEXT", "ALLOCATE", "DATABASE", "GO", "NEW", "ANALYZE", "DATAFILE", "GOTO", "NOARCHIVELOG", + "ARCHIVE", "DBA", "GROUPS", "NOCACHE", "ARCHIVELOG", "DEC", "INCLUDING", "NOCYCLE", "AUTHORIZATION", + "DECLARE", "INDICATOR", "NOMAXVALUE", "AVG", "DISABLE", "INITRANS", "NOMINVALUE", "BACKUP", "DISMOUNT", + "INSTANCE", "NONE", "BEGIN", "DOUBLE", "INT", "NOORDER", "BECOME", "DUMP", "KEY", "NORESETLOGS", "BEFORE", + "EACH", "LANGUAGE", "NORMAL", "BLOCK", "ENABLE", "LAYER", "NOSORT", "BODY", "END", "LINK", "NUMERIC", "CACHE", + "ESCAPE", "LISTS", "OFF", "CANCEL", "EVENTS", "LOGFILE", "OLD", "CASCADE", "EXCEPT", "MANAGE", "ONLY", "CHANGE", + "EXCEPTIONS", "MANUAL", "OPEN", "CHARACTER", "EXEC", "MAX", "OPTIMAL", "CHECKPOINT", "EXPLAIN", "MAXDATAFILES", + "OWN", "CLOSE", "EXECUTE", "MAXINSTANCES", "PACKAGE", "COBOL", "EXTENT", "MAXLOGFILES", "PARALLEL", "COMMIT", + "EXTERNALLY", "MAXLOGHISTORY", "PCTINCREASE", "COMPILE", "FETCH", "MAXLOGMEMBERS", "PCTUSED", "CONSTRAINT", + "FLUSH", "MAXTRANS", "PLAN", "CONSTRAINTS", "FREELIST", "MAXVALUE", "PLI", "CONTENTS", "FREELISTS", "MIN", + "PRECISION", "CONTINUE", "FORCE", "MINEXTENTS", "PRIMARY", "CONTROLFILE", "FOREIGN", "MINVALUE", "PRIVATE", + "COUNT", "FORTRAN", "MODULE", "PROCEDURE", "PROFILE", "SAVEPOINT", "SQLSTATE", "TRACING", "QUOTA", "SCHEMA", + "STATEMENT_ID", "TRANSACTION", "READ", "SCN", "STATISTICS", "TRIGGERS", "REAL", "SECTION", "STOP", "TRUNCATE", + "RECOVER", "SEGMENT", "STORAGE", "UNDER", "REFERENCES", "SEQUENCE", "SUM", "UNLIMITED", "REFERENCING", "SHARED", + "SWITCH", "UNTIL", "RESETLOGS", "SNAPSHOT", "SYSTEM", "USE", "RESTRICTED", "SOME", "TABLES", "USING", "REUSE", + "SORT", "TABLESPACE", "WHEN", "ROLE", "SQL", "TEMPORARY", "WRITE", "ROLES", "SQLCODE", "THREAD", "WORK", "ROLLBACK", + "SQLERROR", "TIME", "ABORT", "BETWEEN", "CRASH", "DIGITS", "ACCEPT", "BINARY_INTEGER", "CREATE", "DISPOSE", "ACCESS", + "BODY", "CURRENT", "DISTINCT", "ADD", "BOOLEAN", "CURRVAL", "DO", "ALL", "BY", "CURSOR", "DROP", "ALTER", "CASE", "DATABASE", + "ELSE", "AND", "CHAR", "DATA_BASE", "ELSIF", "ANY", "CHAR_BASE", "DATE", "END", "ARRAY", "CHECK", "DBA", "ENTRY", "ARRAYLEN", + "CLOSE", "DEBUGOFF", "EXCEPTION", "AS", "CLUSTER", "DEBUGON", "EXCEPTION_INIT", "ASC", "CLUSTERS", "DECLARE", "EXISTS", + "ASSERT", "COLAUTH", "DECIMAL", "EXIT", "ASSIGN", "COLUMNS", "DEFAULT", "FALSE", "AT", "COMMIT", "DEFINITION", "FETCH", + "AUTHORIZATION", "COMPRESS", "DELAY", "FLOAT", "AVG", "CONNECT", "DELETE", "FOR", "BASE_TABLE", "CONSTANT", "DELTA", "FORM", + "BEGIN", "COUNT", "DESC", "FROM", "FUNCTION", "NEW", "RELEASE", "SUM", "GENERIC", "NEXTVAL", "REMR", "TABAUTH", + "GOTO", "NOCOMPRESS", "RENAME", "TABLE", "GRANT", "NOT", "RESOURCE", "TABLES", "GROUP", "NULL", "RETURN", "TASK", "HAVING", + "NUMBER", "REVERSE", "TERMINATE", "IDENTIFIED", "NUMBER_BASE", "REVOKE", "THEN", "IF", "OF", "ROLLBACK", "TO", "IN", "ON", + "ROWID", "TRUE", "INDEX", "OPEN", "ROWLABEL", "TYPE", "INDEXES", "OPTION", "ROWNUM", "UNION", "INDICATOR", "OR", "ROWTYPE", + "UNIQUE", "INSERT", "ORDER", "RUN", "UPDATE", "INTEGER", "OTHERS", "SAVEPOINT", "USE", "INTERSECT", "OUT", "SCHEMA", "VALUES", + "INTO", "PACKAGE", "SELECT", "VARCHAR", "IS", "PARTITION", "SEPARATE", "VARCHAR2", "LEVEL", "PCTFREE", "SET", "VARIANCE", + "LIKE", "POSITIVE", "SIZE", "VIEW", "LIMITED", "PRAGMA", "SMALLINT", "VIEWS", "LOOP", "PRIOR", "SPACE", "WHEN", "MAX", "PRIVATE", + "SQL", "WHERE", "MIN", "PROCEDURE", "SQLCODE", "WHILE", "MINUS", "PUBLIC", "SQLERRM", "WITH", "MLSLABEL", "RAISE", "START", + "WORK", "MOD", "RANGE", "STATEMENT", "XOR", "MODE", "REAL", "STDDEV", "NATURAL", "RECORD", "SUBTYPE", "GEN", "KP", "L", + "NA", "NC", "ND", "NL", "NM", "NR", "NS", "NT", "NZ", "TTC", "UPI", "O", "S", "XA" ); @@ -166,8 +166,8 @@ public class OracleDialect extends CommonsDialectImpl { sql.append(INSERT_ALL); String tableNameWrap = StringUtil.isNotBlank(schema) - ? wrap(getRealSchema(schema)) + REFERENCE + wrap(getRealTable(tableName)) - : wrap(getRealTable(tableName)); + ? wrap(getRealSchema(schema)) + REFERENCE + wrap(getRealTable(tableName)) + : wrap(getRealTable(tableName)); String questionStrings = SqlUtil.buildSqlParamPlaceholder(attrs.size()); for (int i = 0; i < rows.size(); i++) { @@ -178,4 +178,5 @@ public class OracleDialect extends CommonsDialectImpl { return sql.append(INSERT_ALL_END).toString(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java index de415f7d..cf335bf2 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.exception; @@ -97,4 +97,5 @@ public final class FlexExceptions { } } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java index 278897b6..a18b3f13 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.exception; @@ -31,5 +31,5 @@ public class MybatisFlexException extends RuntimeException { super(cause); } - + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQuery.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQuery.java index 22514290..31b91e80 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQuery.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQuery.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.field; @@ -39,4 +39,5 @@ public class FieldQuery implements Serializable { public void setQueryWrapper(QueryWrapper queryWrapper) { this.queryWrapper = queryWrapper; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQueryBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQueryBuilder.java index 097637fa..d91b9769 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQueryBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/FieldQueryBuilder.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.field; @@ -29,16 +29,16 @@ public class FieldQueryBuilder implements Serializable { this.entity = entity; } - public FieldQueryBuilder field(String field){ + public FieldQueryBuilder field(String field) { fieldQuery.setField(field); return this; } - public FieldQueryBuilder field(LambdaGetter fn){ + public FieldQueryBuilder field(LambdaGetter fn) { return field(LambdaUtil.getFieldName(fn)); } - public FieldQueryBuilder queryWrapper(QueryBuilder fun){ + public FieldQueryBuilder queryWrapper(QueryBuilder fun) { fieldQuery.setQueryWrapper(fun.build(entity)); return this; } @@ -46,4 +46,5 @@ public class FieldQueryBuilder implements Serializable { public FieldQuery build() { return fieldQuery; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/QueryBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/QueryBuilder.java index ff41c86e..04250848 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/QueryBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/field/QueryBuilder.java @@ -1,22 +1,24 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.field; import com.mybatisflex.core.query.QueryWrapper; public interface QueryBuilder { + QueryWrapper build(T entity); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/BaseJsonTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/BaseJsonTypeHandler.java index 094ca938..b44cde19 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/BaseJsonTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/BaseJsonTypeHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.handler; @@ -52,4 +52,5 @@ public abstract class BaseJsonTypeHandler extends BaseTypeHandler { protected abstract T parseJson(String json); protected abstract String toJson(T object); -} \ No newline at end of file + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java index 9695009b..7a4276c6 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.handler; @@ -60,4 +60,5 @@ public class CompositeEnumTypeHandler> implements TypeHandler< public E getResult(CallableStatement cs, int columnIndex) throws SQLException { return delegate.getResult(cs, columnIndex); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/Fastjson2TypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/Fastjson2TypeHandler.java index 47eebbe2..b5913cbc 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/Fastjson2TypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/Fastjson2TypeHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.handler; @@ -34,9 +34,10 @@ public class Fastjson2TypeHandler extends BaseJsonTypeHandler { @Override protected String toJson(Object object) { return JSON.toJSONString(object - , JSONWriter.Feature.WriteMapNullValue - , JSONWriter.Feature.WriteNullListAsEmpty - , JSONWriter.Feature.WriteNullStringAsEmpty + , JSONWriter.Feature.WriteMapNullValue + , JSONWriter.Feature.WriteNullListAsEmpty + , JSONWriter.Feature.WriteNullStringAsEmpty ); } -} \ No newline at end of file + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java index e20fef5e..9edf5738 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.handler; @@ -34,6 +34,7 @@ public class FastjsonTypeHandler extends BaseJsonTypeHandler { @Override protected String toJson(Object object) { return JSON.toJSONString(object, SerializerFeature.WriteMapNullValue, - SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty); + SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty); } -} \ No newline at end of file + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/GsonTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/GsonTypeHandler.java index 9f6aea65..15498380 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/GsonTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/GsonTypeHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.handler; @@ -47,4 +47,5 @@ public class GsonTypeHandler extends BaseJsonTypeHandler { public static void setGson(Gson gson) { GsonTypeHandler.gson = gson; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/JacksonTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/JacksonTypeHandler.java index fa656193..7984387f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/JacksonTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/JacksonTypeHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.handler; @@ -58,4 +58,5 @@ public class JacksonTypeHandler extends BaseJsonTypeHandler { public static void setObjectMapper(ObjectMapper objectMapper) { JacksonTypeHandler.objectMapper = objectMapper; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/CustomKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/CustomKeyGenerator.java index ed7a7105..5079f6b0 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/CustomKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/CustomKeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen; @@ -60,8 +60,8 @@ public class CustomKeyGenerator implements KeyGenerator { private void ensuresKeyGeneratorNotNull() { if (keyGenerator == null) { throw FlexExceptions.wrap("The name of \"%s\" key generator not exist.\n" + - "please check annotation @Id(value=\"%s\") at field: %s#%s" - , idInfo.getValue(), idInfo.getValue(), tableInfo.getEntityClass().getName(), idInfo.getProperty()); + "please check annotation @Id(value=\"%s\") at field: %s#%s" + , idInfo.getValue(), idInfo.getValue(), tableInfo.getEntityClass().getName(), idInfo.getProperty()); } } @@ -73,10 +73,10 @@ public class CustomKeyGenerator implements KeyGenerator { MetaObject metaParam = configuration.newMetaObject(parameter); Object generateId = keyGenerator.generate(entity, idInfo.getColumn()); try { - MetaObject metaObjectForProperty= metaParam.metaObjectForProperty(FlexConsts.ENTITY); + MetaObject metaObjectForProperty = metaParam.metaObjectForProperty(FlexConsts.ENTITY); Invoker setInvoker = tableInfo.getReflector().getSetInvoker(idInfo.getProperty()); Object id = ConvertUtil.convert(generateId, setInvoker.getType()); - this.setValue(metaObjectForProperty,this.idInfo.getProperty(),id); + this.setValue(metaObjectForProperty, this.idInfo.getProperty(), id); } catch (Exception e) { throw FlexExceptions.wrap(e); } @@ -95,4 +95,5 @@ public class CustomKeyGenerator implements KeyGenerator { metaParam.setValue(property, value); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/IMultiKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/IMultiKeyGenerator.java index 8bfefd17..a39f56d0 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/IMultiKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/IMultiKeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen; @@ -30,4 +30,5 @@ public interface IMultiKeyGenerator { * @return 列名数组 */ String[] getKeyColumnNames(); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java index d7995bed..f79354e9 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java @@ -24,7 +24,8 @@ import java.util.Map; public class KeyGeneratorFactory { - private KeyGeneratorFactory() {} + private KeyGeneratorFactory() { + } private static final Map KEY_GENERATOR_MAP = new HashMap<>(); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGenerators.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGenerators.java index 1c39a4f6..96266a0d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGenerators.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGenerators.java @@ -17,7 +17,8 @@ package com.mybatisflex.core.keygen; public class KeyGenerators { - private KeyGenerators() {} + private KeyGenerators() { + } /** * uuid 主键生成器 @@ -36,4 +37,5 @@ public class KeyGenerators { * {@link com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator} */ public static final String snowFlakeId = "snowFlakeId"; + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiEntityKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiEntityKeyGenerator.java index d95aafb5..b7c640e5 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiEntityKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiEntityKeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen; @@ -54,4 +54,5 @@ public class MultiEntityKeyGenerator implements KeyGenerator { // 多条数据批量插入的场景下,不支持后设置主键 // 比如 INSERT INTO `tb_account`(uuid,name,sex) VALUES (?, ?, ?), (?, ?, ?) } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiRowKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiRowKeyGenerator.java index 3be78252..5a45d068 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiRowKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MultiRowKeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen; @@ -55,4 +55,5 @@ public class MultiRowKeyGenerator implements KeyGenerator { // 多条数据批量插入的场景下,不支持后设置主键 // 比如 INSERT INTO `tb_account`(uuid,name,sex) VALUES (?, ?, ?), (?, ?, ?) } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java index 228013ab..b165c25c 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java @@ -35,7 +35,8 @@ import java.util.List; public class MybatisKeyGeneratorUtil { - private MybatisKeyGeneratorUtil() {} + private MybatisKeyGeneratorUtil() { + } public static KeyGenerator createTableKeyGenerator(TableInfo tableInfo, MappedStatement ms) { List primaryKeyList = tableInfo.getPrimaryKeyList(); @@ -76,30 +77,30 @@ public class MybatisKeyGeneratorUtil { String sequence = getKeyValue(idInfo, globalKeyConfig); if (StringUtil.isBlank(sequence)) { throw FlexExceptions.wrap("Please config sequence by @Id(value=\"...\") for field: %s in class: %s" - , idInfo.getProperty() - , tableInfo.getEntityClass().getName()); + , idInfo.getProperty() + , tableInfo.getEntityClass().getName()); } String selectId = ms.getId() + SelectKeyGenerator.SELECT_KEY_SUFFIX; SqlSource sqlSource = ms.getLang().createSqlSource(ms.getConfiguration(), sequence.trim(), idInfo.getPropertyType()); MappedStatement.Builder msBuilder = new MappedStatement.Builder(ms.getConfiguration(), selectId, sqlSource, SqlCommandType.SELECT) - .resource(ms.getResource()) - .fetchSize(null) - .timeout(null) - .statementType(StatementType.PREPARED) - .keyGenerator(NoKeyGenerator.INSTANCE) - .keyProperty(FlexConsts.ENTITY + "." + idInfo.getProperty()) - .keyColumn(idInfo.getColumn()) - .databaseId(ms.getDatabaseId()) - .lang(ms.getLang()) - .resultOrdered(false) - .resultSets(null) - .resultMaps(createIdResultMaps(ms.getConfiguration(), selectId + "-Inline", idInfo.getPropertyType(), new ArrayList<>())) - .resultSetType(null) - .flushCacheRequired(false) - .useCache(false) - .cache(ms.getCache()); + .resource(ms.getResource()) + .fetchSize(null) + .timeout(null) + .statementType(StatementType.PREPARED) + .keyGenerator(NoKeyGenerator.INSTANCE) + .keyProperty(FlexConsts.ENTITY + "." + idInfo.getProperty()) + .keyColumn(idInfo.getColumn()) + .databaseId(ms.getDatabaseId()) + .lang(ms.getLang()) + .resultOrdered(false) + .resultSets(null) + .resultMaps(createIdResultMaps(ms.getConfiguration(), selectId + "-Inline", idInfo.getPropertyType(), new ArrayList<>())) + .resultSetType(null) + .flushCacheRequired(false) + .useCache(false) + .cache(ms.getCache()); MappedStatement keyMappedStatement = msBuilder.build(); ms.getConfiguration().addMappedStatement(keyMappedStatement); @@ -115,7 +116,7 @@ public class MybatisKeyGeneratorUtil { private static List createIdResultMaps(Configuration configuration, String statementId, Class resultType, List resultMappings) { ResultMap resultMap = new ResultMap.Builder(configuration, statementId, resultType, resultMappings, null) - .build(); + .build(); return Arrays.asList(resultMap); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowCustomKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowCustomKeyGenerator.java index e286b2d3..47e29bf5 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowCustomKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowCustomKeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen; @@ -68,4 +68,5 @@ public class RowCustomKeyGenerator implements KeyGenerator { public void processAfter(Executor executor, MappedStatement ms, Statement stmt, Object parameter) { //do nothing } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowJdbc3KeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowJdbc3KeyGenerator.java index 793f5116..735e7f03 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowJdbc3KeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowJdbc3KeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen; @@ -48,7 +48,7 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { private static final String SECOND_GENERIC_PARAM_NAME = ParamNameResolver.GENERIC_NAME_PREFIX + "2"; private static final String MSG_TOO_MANY_KEYS = "Too many keys are generated. There are only %d target objects. " - + "You either specified a wrong 'keyProperty' or encountered a driver bug like #1523."; + + "You either specified a wrong 'keyProperty' or encountered a driver bug like #1523."; public RowJdbc3KeyGenerator(String keyProperty) { @@ -87,7 +87,7 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { // Multi-param or single param with @Param assignKeysToParamMap(configuration, rs, rsmd, keyProperties, (Map) parameter); } else if (parameter instanceof ArrayList && !((ArrayList) parameter).isEmpty() - && ((ArrayList) parameter).get(0) instanceof ParamMap) { + && ((ArrayList) parameter).get(0) instanceof ParamMap) { // Multi-param or single param with @Param in batch operation assignKeysToParamMapList(configuration, rs, rsmd, keyProperties, (ArrayList>) parameter); } else { @@ -129,8 +129,8 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { if (assignerList.isEmpty()) { for (int i = 0; i < keyProperties.length; i++) { assignerList - .add(getAssignerForParamMap(configuration, rsmd, i + 1, paramMap, keyProperties[i], keyProperties, false) - .getValue()); + .add(getAssignerForParamMap(configuration, rsmd, i + 1, paramMap, keyProperties[i], keyProperties, false) + .getValue()); } } assignerList.forEach(x -> x.assign(rs, paramMap)); @@ -146,9 +146,9 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { Map, List>> assignerMap = new HashMap<>(); for (int i = 0; i < keyProperties.length; i++) { Entry entry = getAssignerForParamMap(configuration, rsmd, i + 1, paramMap, keyProperties[i], - keyProperties, true); + keyProperties, true); Entry, List> iteratorPair = MapUtil.computeIfAbsent(assignerMap, entry.getKey(), - k -> MapUtil.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>())); + k -> MapUtil.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>())); iteratorPair.getValue().add(entry.getValue()); } long counter = 0; @@ -176,9 +176,9 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { return getAssignerForSingleParam(config, rsmd, columnPosition, paramMap, keyProperty, omitParamName); } throw new ExecutorException("Could not determine which parameter to assign generated keys to. " - + "Note that when there are multiple parameters, 'keyProperty' must include the parameter name (e.g. 'param.id'). " - + "Specified key properties are " + ArrayUtil.toString(keyProperties) + " and available parameters are " - + keySet); + + "Note that when there are multiple parameters, 'keyProperty' must include the parameter name (e.g. 'param.id'). " + + "Specified key properties are " + ArrayUtil.toString(keyProperties) + " and available parameters are " + + keySet); } String paramName = keyProperty.substring(0, firstDot); if (keySet.contains(paramName)) { @@ -189,9 +189,9 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { return getAssignerForSingleParam(config, rsmd, columnPosition, paramMap, keyProperty, omitParamName); } else { throw new ExecutorException("Could not find parameter '" + paramName + "'. " - + "Note that when there are multiple parameters, 'keyProperty' must include the parameter name (e.g. 'param.id'). " - + "Specified key properties are " + ArrayUtil.toString(keyProperties) + " and available parameters are " - + keySet); + + "Note that when there are multiple parameters, 'keyProperty' must include the parameter name (e.g. 'param.id'). " + + "Specified key properties are " + ArrayUtil.toString(keyProperties) + " and available parameters are " + + keySet); } } @@ -219,6 +219,7 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { } private class KeyAssigner { + private final Configuration configuration; private final ResultSetMetaData rsmd; private final TypeHandlerRegistry typeHandlerRegistry; @@ -249,10 +250,10 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { if (metaParam.hasSetter(propertyName)) { Class propertyType = metaParam.getSetterType(propertyName); typeHandler = typeHandlerRegistry.getTypeHandler(propertyType, - JdbcType.forCode(rsmd.getColumnType(columnPosition))); + JdbcType.forCode(rsmd.getColumnType(columnPosition))); } else { throw new ExecutorException("No setter found for the keyProperty '" + propertyName + "' in '" - + metaParam.getOriginalObject().getClass().getName() + "'."); + + metaParam.getOriginalObject().getClass().getName() + "'."); } } if (typeHandler == null) { @@ -263,8 +264,10 @@ public class RowJdbc3KeyGenerator implements KeyGenerator { } } catch (SQLException e) { throw new ExecutorException("Error getting generated key or setting result to parameter object. Cause: " + e, - e); + e); } } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowKeyGenerator.java index 53d3feb0..3e80b862 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/RowKeyGenerator.java @@ -40,6 +40,7 @@ import java.util.Map; * 为 row 的主键生成器 */ public class RowKeyGenerator implements KeyGenerator, IMultiKeyGenerator { + private static final KeyGenerator[] NO_KEY_GENERATORS = new KeyGenerator[0]; private final MappedStatement ms; @@ -104,23 +105,23 @@ public class RowKeyGenerator implements KeyGenerator, IMultiKeyGenerator { String sequence = rowKey.getValue(); SqlSource sqlSource = ms.getLang().createSqlSource(ms.getConfiguration(), sequence.trim(), Object.class); MappedStatement.Builder msBuilder = new MappedStatement.Builder(ms.getConfiguration(), selectId, sqlSource, SqlCommandType.SELECT) - .resource(ms.getResource()) - .fetchSize(null) - .timeout(null) - .statementType(StatementType.PREPARED) - .keyGenerator(NoKeyGenerator.INSTANCE) - .keyProperty(FlexConsts.ROW + "." + rowKey.getKeyColumn()) + .resource(ms.getResource()) + .fetchSize(null) + .timeout(null) + .statementType(StatementType.PREPARED) + .keyGenerator(NoKeyGenerator.INSTANCE) + .keyProperty(FlexConsts.ROW + "." + rowKey.getKeyColumn()) // .keyColumn(FlexConsts.ROW + "." + rowKey.getKeyColumn()) - .keyColumn(rowKey.getKeyColumn()) - .databaseId(ms.getDatabaseId()) - .lang(ms.getLang()) - .resultOrdered(false) - .resultSets(null) - .resultMaps(new ArrayList<>()) - .resultSetType(null) - .flushCacheRequired(false) - .useCache(false) - .cache(ms.getCache()); + .keyColumn(rowKey.getKeyColumn()) + .databaseId(ms.getDatabaseId()) + .lang(ms.getLang()) + .resultOrdered(false) + .resultSets(null) + .resultMaps(new ArrayList<>()) + .resultSetType(null) + .flushCacheRequired(false) + .useCache(false) + .cache(ms.getCache()); MappedStatement keyMappedStatement = msBuilder.build(); ms.getConfiguration().addMappedStatement(keyMappedStatement); @@ -153,4 +154,5 @@ public class RowKeyGenerator implements KeyGenerator, IMultiKeyGenerator { public String[] getKeyColumnNames() { return autoKeyGeneratorNames.toArray(new String[0]); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/SnowFlakeIDKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/SnowFlakeIDKeyGenerator.java index 7850ab20..472b1a69 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/SnowFlakeIDKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/SnowFlakeIDKeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen.impl; @@ -132,11 +132,11 @@ public class SnowFlakeIDKeyGenerator implements IKeyGenerator { public SnowFlakeIDKeyGenerator(long workerId, long dataCenterId) { if (workerId > MAX_WORKER_ID || workerId < 0) { throw new IllegalArgumentException( - String.format("workerId must be greater than 0 and less than %d.", MAX_WORKER_ID)); + String.format("workerId must be greater than 0 and less than %d.", MAX_WORKER_ID)); } if (dataCenterId > MAX_DATA_CENTER_ID || dataCenterId < 0) { throw new IllegalArgumentException( - String.format("dataCenterId must be greater than 0 and less than %d.", MAX_DATA_CENTER_ID)); + String.format("dataCenterId must be greater than 0 and less than %d.", MAX_DATA_CENTER_ID)); } this.workerId = workerId; this.dataCenterId = dataCenterId; @@ -228,9 +228,9 @@ public class SnowFlakeIDKeyGenerator implements IKeyGenerator { // 时间戳部分 | 数据中心部分 | 机器标识部分 | 序列号部分 return ((currentTimeMillis - twepoch) << TIMESTAMP_SHIFT) - | (dataCenterId << DATA_CENTER_ID_SHIFT) - | (workerId << WORK_ID_SHIFT) - | sequence; + | (dataCenterId << DATA_CENTER_ID_SHIFT) + | (workerId << WORK_ID_SHIFT) + | sequence; } /** @@ -244,4 +244,4 @@ public class SnowFlakeIDKeyGenerator implements IKeyGenerator { return currentTimeMillis; } -} \ No newline at end of file +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/UUIDKeyGenerator.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/UUIDKeyGenerator.java index fe006d79..0a841294 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/UUIDKeyGenerator.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/impl/UUIDKeyGenerator.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.keygen.impl; @@ -25,4 +25,5 @@ public class UUIDKeyGenerator implements IKeyGenerator { public Object generate(Object entity, String keyColumn) { return UUID.randomUUID().toString().replace("-", ""); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java index 5b188f89..60dc6904 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java @@ -43,8 +43,8 @@ public abstract class AbstractLogicDeleteProcessor implements LogicDeleteProcess @Override public void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo) { queryWrapper.and(QueryCondition.create(tableInfo.getSchema(), tableInfo.getTableName(), tableInfo.getLogicDeleteColumn() - , EQUALS - , getLogicNormalValue())); + , EQUALS + , getLogicNormalValue())); } /** diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java index c7a7c13d..8e343786 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java @@ -26,7 +26,8 @@ public interface LogicDeleteProcessor { /** * 用户构建查询正常数据的条件。 - * @param logicColumn 逻辑删除列 + * + * @param logicColumn 逻辑删除列 * @param tableInfo * @param dialect 数据库方言 */ @@ -34,9 +35,10 @@ public interface LogicDeleteProcessor { /** * 用户与构建删除数据时的内容。 - * @param logicColumn 逻辑删除列 + * + * @param logicColumn 逻辑删除列 * @param tableInfo - * @param dialect 数据库方言 + * @param dialect 数据库方言 */ String buildLogicDeletedSet(String logicColumn, TableInfo tableInfo, IDialect dialect); @@ -44,7 +46,7 @@ public interface LogicDeleteProcessor { * 用于构建通过 {@link QueryWrapper} 查询数据时的内容。 * * @param queryWrapper 条件构造器 - * @param tableInfo 表信息 + * @param tableInfo 表信息 */ void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DefaultLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DefaultLogicDeleteProcessor.java index 6ac25eba..33ea24ef 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DefaultLogicDeleteProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DefaultLogicDeleteProcessor.java @@ -32,7 +32,7 @@ public class DefaultLogicDeleteProcessor extends AbstractLogicDeleteProcessor { @Override public void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo) { queryWrapper.where(QueryCondition.create(tableInfo.getSchema(), tableInfo.getTableName(), tableInfo.getLogicDeleteColumn() - , EQUALS, FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete())); + , EQUALS, FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete())); } @@ -40,7 +40,7 @@ public class DefaultLogicDeleteProcessor extends AbstractLogicDeleteProcessor { protected Object getLogicNormalValue() { Object normalValueOfLogicDelete = FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete(); if (normalValueOfLogicDelete instanceof Number - || normalValueOfLogicDelete instanceof Boolean) { + || normalValueOfLogicDelete instanceof Boolean) { return normalValueOfLogicDelete; } return SINGLE_QUOTE + normalValueOfLogicDelete + SINGLE_QUOTE; @@ -51,7 +51,7 @@ public class DefaultLogicDeleteProcessor extends AbstractLogicDeleteProcessor { protected Object getLogicDeletedValue() { Object deletedValueOfLogicDelete = FlexGlobalConfig.getDefaultConfig().getDeletedValueOfLogicDelete(); if (deletedValueOfLogicDelete instanceof Number - || deletedValueOfLogicDelete instanceof Boolean) { + || deletedValueOfLogicDelete instanceof Boolean) { return deletedValueOfLogicDelete; } return SINGLE_QUOTE + deletedValueOfLogicDelete + SINGLE_QUOTE; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskManager.java index 5736878a..c69dfc66 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskManager.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskManager.java @@ -24,7 +24,8 @@ import java.util.function.Supplier; */ public class MaskManager { - private MaskManager() {} + private MaskManager() { + } /** * 脱敏处理器,type : processor diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskProcessor.java index 321accc3..f95b170b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskProcessor.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mask; @@ -21,4 +21,5 @@ package com.mybatisflex.core.mask; public interface MaskProcessor { Object mask(Object data); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskTypeHandler.java index 73f70e2e..8fa48ff0 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/MaskTypeHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mask; @@ -33,25 +33,26 @@ public class MaskTypeHandler extends BaseTypeHandler { @Override public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException { - ps.setString(i,parameter.toString()); + ps.setString(i, parameter.toString()); } @Override public Object getNullableResult(ResultSet rs, String columnName) throws SQLException { String data = rs.getString(columnName); - return MaskManager.mask(maskType,data); + return MaskManager.mask(maskType, data); } @Override public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException { String data = rs.getString(columnIndex); - return MaskManager.mask(maskType,data); + return MaskManager.mask(maskType, data); } @Override public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { String data = cs.getString(columnIndex); - return MaskManager.mask(maskType,data); + return MaskManager.mask(maskType, data); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/Masks.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/Masks.java index 9021abcf..1aebe978 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/Masks.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mask/Masks.java @@ -20,7 +20,8 @@ package com.mybatisflex.core.mask; */ public class Masks { - private Masks() {} + private Masks() { + } /** * 手机号脱敏 @@ -79,8 +80,8 @@ public class Masks { private static String mask(String needToMaskString, int keepFirstCount, int keepLastCount, int maskCount) { return needToMaskString.substring(0, keepFirstCount) - + createMask(maskCount) - + needToMaskString.substring(needToMaskString.length() - keepLastCount); + + createMask(maskCount) + + needToMaskString.substring(needToMaskString.length() - keepLastCount); } @@ -183,8 +184,8 @@ public class Masks { * 密码 脱敏 */ static MaskProcessor PASSWORD_PROCESSOR = data -> { - if (data instanceof String ) { - return mask((String) data, 0, 0, ((String) data).length()) ; + if (data instanceof String) { + return mask((String) data, 0, 0, ((String) data).length()); } return data; }; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java index d412d023..659d7008 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java @@ -90,8 +90,8 @@ public class FlexConfiguration extends Configuration { * {@link SelectKeyGenerator#SELECT_KEY_SUFFIX} */ if (!mappedStatementId.endsWith(SelectKeyGenerator.SELECT_KEY_SUFFIX) - && parameterObject instanceof Map - && ((Map) parameterObject).containsKey(FlexConsts.SQL_ARGS)) { + && parameterObject instanceof Map + && ((Map) parameterObject).containsKey(FlexConsts.SQL_ARGS)) { SqlArgsParameterHandler sqlArgsParameterHandler = new SqlArgsParameterHandler(mappedStatement, (Map) parameterObject, boundSql); return (ParameterHandler) interceptorChain.pluginAll(sqlArgsParameterHandler); } else { @@ -102,9 +102,9 @@ public class FlexConfiguration extends Configuration { @Override public ResultSetHandler newResultSetHandler(Executor executor, MappedStatement mappedStatement - , RowBounds rowBounds, ParameterHandler parameterHandler, ResultHandler resultHandler, BoundSql boundSql) { + , RowBounds rowBounds, ParameterHandler parameterHandler, ResultHandler resultHandler, BoundSql boundSql) { ResultSetHandler resultSetHandler = new FlexResultSetHandler(executor, mappedStatement, parameterHandler, - resultHandler, boundSql, rowBounds); + resultHandler, boundSql, rowBounds); return (ResultSetHandler) interceptorChain.pluginAll(resultSetHandler); } @@ -151,7 +151,7 @@ public class FlexConfiguration extends Configuration { Class asType = MappedStatementTypes.getCurrentType(); if (asType != null) { return MapUtil.computeIfAbsent(dynamicMappedStatementCache, id + ":" + asType.getName(), - clazz -> replaceResultMap(ms, TableInfoFactory.ofEntityClass(asType)) + clazz -> replaceResultMap(ms, TableInfoFactory.ofEntityClass(asType)) ); } @@ -168,12 +168,12 @@ public class FlexConfiguration extends Configuration { } //entity insert methods else if (StringUtil.endsWithAny(ms.getId(), "insert", FlexConsts.METHOD_INSERT_BATCH) - && ms.getKeyGenerator() == NoKeyGenerator.INSTANCE) { + && ms.getKeyGenerator() == NoKeyGenerator.INSTANCE) { ms = replaceEntityKeyGenerator(ms); } //entity select else if (StringUtil.endsWithAny(ms.getId(), "selectOneById", "selectListByIds" - , "selectListByQuery")) { + , "selectListByQuery")) { ms = replaceResultMap(ms, getTableInfo(ms)); } @@ -200,23 +200,23 @@ public class FlexConfiguration extends Configuration { } return new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), ms.getSqlSource(), ms.getSqlCommandType()) - .resource(ms.getResource()) - .fetchSize(ms.getFetchSize()) - .timeout(ms.getTimeout()) - .statementType(ms.getStatementType()) - .keyGenerator(NoKeyGenerator.INSTANCE) - .keyProperty(ms.getKeyProperties() == null ? null : String.join(",", ms.getKeyProperties())) - .keyColumn(ms.getKeyColumns() == null ? null : String.join(",", ms.getKeyColumns())) - .databaseId(databaseId) - .lang(ms.getLang()) - .resultOrdered(ms.isResultOrdered()) - .resultSets(ms.getResultSets() == null ? null : String.join(",", ms.getResultSets())) - .resultMaps(Collections.singletonList(resultMap)) - .resultSetType(ms.getResultSetType()) - .flushCacheRequired(ms.isFlushCacheRequired()) - .useCache(ms.isUseCache()) - .cache(ms.getCache()) - .build(); + .resource(ms.getResource()) + .fetchSize(ms.getFetchSize()) + .timeout(ms.getTimeout()) + .statementType(ms.getStatementType()) + .keyGenerator(NoKeyGenerator.INSTANCE) + .keyProperty(ms.getKeyProperties() == null ? null : String.join(",", ms.getKeyProperties())) + .keyColumn(ms.getKeyColumns() == null ? null : String.join(",", ms.getKeyColumns())) + .databaseId(databaseId) + .lang(ms.getLang()) + .resultOrdered(ms.isResultOrdered()) + .resultSets(ms.getResultSets() == null ? null : String.join(",", ms.getResultSets())) + .resultMaps(Collections.singletonList(resultMap)) + .resultSetType(ms.getResultSetType()) + .flushCacheRequired(ms.isFlushCacheRequired()) + .useCache(ms.isUseCache()) + .cache(ms.getCache()) + .build(); } /** @@ -238,23 +238,23 @@ public class FlexConfiguration extends Configuration { } return new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), ms.getSqlSource(), ms.getSqlCommandType()) - .resource(ms.getResource()) - .fetchSize(ms.getFetchSize()) - .timeout(ms.getTimeout()) - .statementType(ms.getStatementType()) - .keyGenerator(keyGenerator) // 替换主键生成器 - .keyProperty(ms.getKeyProperties() == null ? null : String.join(",", ms.getKeyProperties())) - .keyColumn(ms.getKeyColumns() == null ? null : String.join(",", ms.getKeyColumns())) - .databaseId(databaseId) - .lang(ms.getLang()) - .resultOrdered(ms.isResultOrdered()) - .resultSets(ms.getResultSets() == null ? null : String.join(",", ms.getResultSets())) - .resultMaps(ms.getResultMaps()) - .resultSetType(ms.getResultSetType()) - .flushCacheRequired(ms.isFlushCacheRequired()) - .useCache(ms.isUseCache()) - .cache(ms.getCache()) - .build(); + .resource(ms.getResource()) + .fetchSize(ms.getFetchSize()) + .timeout(ms.getTimeout()) + .statementType(ms.getStatementType()) + .keyGenerator(keyGenerator) // 替换主键生成器 + .keyProperty(ms.getKeyProperties() == null ? null : String.join(",", ms.getKeyProperties())) + .keyColumn(ms.getKeyColumns() == null ? null : String.join(",", ms.getKeyColumns())) + .databaseId(databaseId) + .lang(ms.getLang()) + .resultOrdered(ms.isResultOrdered()) + .resultSets(ms.getResultSets() == null ? null : String.join(",", ms.getResultSets())) + .resultMaps(ms.getResultMaps()) + .resultSetType(ms.getResultSetType()) + .flushCacheRequired(ms.isFlushCacheRequired()) + .useCache(ms.isUseCache()) + .cache(ms.getCache()) + .build(); } /** @@ -281,23 +281,23 @@ public class FlexConfiguration extends Configuration { } return new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), ms.getSqlSource(), ms.getSqlCommandType()) - .resource(ms.getResource()) - .fetchSize(ms.getFetchSize()) - .timeout(ms.getTimeout()) - .statementType(ms.getStatementType()) - .keyGenerator(keyGenerator) // 替换主键生成器 - .keyProperty(tableInfo.getKeyProperties()) - .keyColumn(tableInfo.getKeyColumns()) - .databaseId(databaseId) - .lang(ms.getLang()) - .resultOrdered(ms.isResultOrdered()) - .resultSets(ms.getResultSets() == null ? null : String.join(",", ms.getResultSets())) - .resultMaps(ms.getResultMaps()) - .resultSetType(ms.getResultSetType()) - .flushCacheRequired(ms.isFlushCacheRequired()) - .useCache(ms.isUseCache()) - .cache(ms.getCache()) - .build(); + .resource(ms.getResource()) + .fetchSize(ms.getFetchSize()) + .timeout(ms.getTimeout()) + .statementType(ms.getStatementType()) + .keyGenerator(keyGenerator) // 替换主键生成器 + .keyProperty(tableInfo.getKeyProperties()) + .keyColumn(tableInfo.getKeyColumns()) + .databaseId(databaseId) + .lang(ms.getLang()) + .resultOrdered(ms.isResultOrdered()) + .resultSets(ms.getResultSets() == null ? null : String.join(",", ms.getResultSets())) + .resultMaps(ms.getResultMaps()) + .resultSetType(ms.getResultSetType()) + .flushCacheRequired(ms.isFlushCacheRequired()) + .useCache(ms.isUseCache()) + .cache(ms.getCache()) + .build(); } @@ -337,8 +337,9 @@ public class FlexConfiguration extends Configuration { public T getMapper(Class type, SqlSession sqlSession) { T mapper = super.getMapper(type, sqlSession); return (T) Proxy.newProxyInstance(type.getClassLoader() - , new Class[]{type} - , new MapperInvocationHandler(mapper, this)); + , new Class[]{type} + , new MapperInvocationHandler(mapper, this)); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexResultSetHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexResultSetHandler.java index 905eb881..4e64a27e 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexResultSetHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexResultSetHandler.java @@ -32,7 +32,7 @@ import java.util.Iterator; public class FlexResultSetHandler extends DefaultResultSetHandler { public FlexResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler - , ResultHandler resultHandler, BoundSql boundSql, RowBounds rowBounds) { + , ResultHandler resultHandler, BoundSql boundSql, RowBounds rowBounds) { super(executor, mappedStatement, parameterHandler, resultHandler, boundSql, rowBounds); } @@ -87,5 +87,7 @@ public class FlexResultSetHandler extends DefaultResultSetHandler { public Iterator iterator() { return originalCursor.iterator(); } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java index 9a0f43d8..7275dc27 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mybatis; @@ -101,11 +101,11 @@ public class FlexSqlSessionFactoryBuilder extends SqlSessionFactoryBuilder { return; } String banner = " __ __ _ _ _ _____ _ \n" + - " | \\/ |_ _| |__ __ _| |_(_)___ | ___| | _____ __\n" + - " | |\\/| | | | | '_ \\ / _` | __| / __| | |_ | |/ _ \\ \\/ /\n" + - " | | | | |_| | |_) | (_| | |_| \\__ \\ | _| | | __/> < \n" + - " |_| |_|\\__, |_.__/ \\__,_|\\__|_|___/ |_| |_|\\___/_/\\_\\\n" + - " |___/ v" + FlexConsts.VERSION + " https://mybatis-flex.com"; + " | \\/ |_ _| |__ __ _| |_(_)___ | ___| | _____ __\n" + + " | |\\/| | | | | '_ \\ / _` | __| / __| | |_ | |/ _ \\ \\/ /\n" + + " | | | | |_| | |_) | (_| | |_| \\__ \\ | _| | | __/> < \n" + + " |_| |_|\\__, |_.__/ \\__,_|\\__|_|___/ |_| |_|\\___/_/\\_\\\n" + + " |___/ v" + FlexConsts.VERSION + " https://mybatis-flex.com"; System.out.println(banner); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java index 2cca38b1..bfbb0a73 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java @@ -92,19 +92,19 @@ public class FlexStatementHandler implements StatementHandler { @Override public int update(Statement statement) throws SQLException { return auditEnable ? AuditManager.startAudit(() -> delegate.update(statement), statement, boundSql, configuration) - : delegate.update(statement); + : delegate.update(statement); } @Override public List query(Statement statement, ResultHandler resultHandler) throws SQLException { return auditEnable ? AuditManager.startAudit(() -> delegate.query(statement, resultHandler), statement, boundSql, configuration) - : delegate.query(statement, resultHandler); + : delegate.query(statement, resultHandler); } @Override public Cursor queryCursor(Statement statement) throws SQLException { return auditEnable ? AuditManager.startAudit(() -> delegate.queryCursor(statement), statement, boundSql, configuration) - : delegate.queryCursor(statement); + : delegate.queryCursor(statement); } @Override diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MappedStatementTypes.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MappedStatementTypes.java index 0b70c402..96bafd73 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MappedStatementTypes.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MappedStatementTypes.java @@ -17,19 +17,20 @@ package com.mybatisflex.core.mybatis; public class MappedStatementTypes { - private MappedStatementTypes() {} + private MappedStatementTypes() { + } private static ThreadLocal> currentTypeTL = new ThreadLocal<>(); - public static void setCurrentType(Class type){ + public static void setCurrentType(Class type) { currentTypeTL.set(type); } - public static Class getCurrentType(){ + public static Class getCurrentType() { return currentTypeTL.get(); } - public static void clear(){ + public static void clear() { currentTypeTL.remove(); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/SqlArgsParameterHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/SqlArgsParameterHandler.java index 26e77152..c286f32b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/SqlArgsParameterHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/SqlArgsParameterHandler.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mybatis; @@ -90,4 +90,5 @@ public class SqlArgsParameterHandler extends DefaultParameterHandler { ps.setTimestamp(index, new java.sql.Timestamp(value.getTime())); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/TypeHandlerObject.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/TypeHandlerObject.java index dcf7bbf9..39c18df2 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/TypeHandlerObject.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/TypeHandlerObject.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mybatis; @@ -37,4 +37,5 @@ public class TypeHandlerObject implements Serializable { public void setParameter(PreparedStatement ps, int i) throws SQLException { typeHandler.setParameter(ps, i, value, jdbcType); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/CacheKeyBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/CacheKeyBuilder.java index c3757a2a..0d76346c 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/CacheKeyBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/CacheKeyBuilder.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mybatis.executor; @@ -23,10 +23,11 @@ import java.util.Map; public interface CacheKeyBuilder { - default CacheKey buildCacheKey(CacheKey cacheKey, Object parameterObject){ - if (parameterObject instanceof Map && ((Map) parameterObject).containsKey(FlexConsts.SQL_ARGS)){ + default CacheKey buildCacheKey(CacheKey cacheKey, Object parameterObject) { + if (parameterObject instanceof Map && ((Map) parameterObject).containsKey(FlexConsts.SQL_ARGS)) { cacheKey.update(Arrays.toString((Object[]) ((Map) parameterObject).get(FlexConsts.SQL_ARGS))); } return cacheKey; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexBatchExecutor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexBatchExecutor.java index 0c1414b7..97a0d553 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexBatchExecutor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexBatchExecutor.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mybatis.executor; @@ -106,7 +106,7 @@ public class FlexBatchExecutor extends BatchExecutor implements CacheKeyBuilder // 修复批量插入并设置主键时出错 // fixed https://gitee.com/mybatis-flex/mybatis-flex/issues/I6Y8ZU else if (RowKeyGenerator.class.equals(keyGenerator.getClass()) - && ((RowKeyGenerator) keyGenerator).hasGeneratedKeys()) { + && ((RowKeyGenerator) keyGenerator).hasGeneratedKeys()) { keyGenerator.processAfter(this, ms, stmt, parameterObjects); } // issue #141 @@ -120,14 +120,14 @@ public class FlexBatchExecutor extends BatchExecutor implements CacheKeyBuilder } catch (BatchUpdateException e) { StringBuilder message = new StringBuilder(); message.append(batchResult.getMappedStatement().getId()) - .append(" (batch index #") - .append(i + 1) - .append(")") - .append(" failed."); + .append(" (batch index #") + .append(i + 1) + .append(")") + .append(" failed."); if (i > 0) { message.append(" ") - .append(i) - .append(" prior sub executor(s) completed successfully, but will be rolled back."); + .append(i) + .append(" prior sub executor(s) completed successfully, but will be rolled back."); } throw new BatchExecutorException(message.toString(), e, results, batchResult); } @@ -143,4 +143,5 @@ public class FlexBatchExecutor extends BatchExecutor implements CacheKeyBuilder batchResultList.clear(); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexReuseExecutor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexReuseExecutor.java index 474ef692..9f23baf3 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexReuseExecutor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexReuseExecutor.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mybatis.executor; @@ -31,6 +31,7 @@ public class FlexReuseExecutor extends ReuseExecutor implements CacheKeyBuilder @Override public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) { - return buildCacheKey(super.createCacheKey(ms, parameterObject, rowBounds, boundSql),parameterObject); + return buildCacheKey(super.createCacheKey(ms, parameterObject, rowBounds, boundSql), parameterObject); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexSimpleExecutor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexSimpleExecutor.java index 8942230d..343eab61 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexSimpleExecutor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/executor/FlexSimpleExecutor.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.mybatis.executor; @@ -31,6 +31,7 @@ public class FlexSimpleExecutor extends SimpleExecutor implements CacheKeyBuilde @Override public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) { - return buildCacheKey(super.createCacheKey(ms, parameterObject, rowBounds, boundSql),parameterObject); + return buildCacheKey(super.createCacheKey(ms, parameterObject, rowBounds, boundSql), parameterObject); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java index d115f40a..69a6a878 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java @@ -70,7 +70,6 @@ public class Page implements Serializable { } - /** * 获取当前页的数据。 * @@ -270,11 +269,12 @@ public class Page implements Serializable { @Override public String toString() { return "Page{" + - "pageNumber=" + pageNumber + - ", pageSize=" + pageSize + - ", totalPage=" + totalPage + - ", totalRow=" + totalRow + - ", records=" + records + - '}'; + "pageNumber=" + pageNumber + + ", pageSize=" + pageSize + + ", totalPage=" + totalPage + + ", totalRow=" + totalRow + + ", records=" + records + + '}'; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java index 55347b93..fb8dc5a9 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java @@ -303,7 +303,7 @@ public class EntitySqlProvider { //优先构建 sql,再构建参数 String sql = DialectFactory.getDialect().forUpdateNumberAddByQuery(tableInfo.getSchema() - , tableInfo.getTableName(), fieldName, value, queryWrapper); + , tableInfo.getTableName(), fieldName, value, queryWrapper); Object[] queryParams = CPI.getValueArray(queryWrapper); ProviderUtil.setSqlArgs(params, queryParams); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java index cb3624e0..5f036516 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java @@ -270,7 +270,7 @@ public class RowSqlProvider { //优先构建 sql,再构建参数 String sql = DialectFactory.getDialect().forUpdateNumberAddByQuery(schema - , tableName, fieldName, value, queryWrapper); + , tableName, fieldName, value, queryWrapper); Object[] queryParams = CPI.getValueArray(queryWrapper); ProviderUtil.setSqlArgs(params, queryParams); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/ArithmeticQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/ArithmeticQueryColumn.java index 83ca776a..35ae3cf4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/ArithmeticQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/ArithmeticQueryColumn.java @@ -147,5 +147,7 @@ public class ArithmeticQueryColumn extends QueryColumn { throw FlexExceptions.wrap(e); } } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java index 96621c54..1198fa65 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/BaseQueryWrapper.java @@ -127,8 +127,8 @@ public class BaseQueryWrapper> implements CloneSup joinTables.add(queryTable); } - protected void addEndFragment(String fragment){ - if (endFragments == null){ + protected void addEndFragment(String fragment) { + if (endFragments == null) { endFragments = new ArrayList<>(); } endFragments.add(fragment); @@ -251,14 +251,14 @@ public class BaseQueryWrapper> implements CloneSup this.context = context; } - protected void putContext(String key, Object value){ - if (context == null){ + protected void putContext(String key, Object value) { + if (context == null) { context = new HashMap<>(); } - context.put(key,value); + context.put(key, value); } - protected R getContext(String key){ + protected R getContext(String key) { return context == null ? null : (R) context.get(key); } @@ -278,11 +278,11 @@ public class BaseQueryWrapper> implements CloneSup clone.orderBys = CollectionUtil.cloneArrayList(this.orderBys); clone.unions = CollectionUtil.cloneArrayList(this.unions); // copy List if necessary ... - if (this.endFragments != null){ + if (this.endFragments != null) { clone.endFragments = CollectionUtil.newArrayList(this.endFragments); } // copy Map if necessary ... - if (this.context != null){ + if (this.context != null) { clone.context = CollectionUtil.newHashMap(this.context); } return clone; @@ -290,4 +290,5 @@ public class BaseQueryWrapper> implements CloneSup throw FlexExceptions.wrap(e); } } -} \ No newline at end of file + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java index 1f2059b1..0d6344ee 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java @@ -112,8 +112,8 @@ public class Brackets extends QueryCondition { @Override public String toString() { return "Brackets{" + - "childCondition=" + childCondition + - '}'; + "childCondition=" + childCondition + + '}'; } @Override @@ -123,4 +123,5 @@ public class Brackets extends QueryCondition { clone.childCondition = ObjectUtil.clone(this.childCondition); return clone; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java index 3496e6e1..a5a45278 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java @@ -42,7 +42,6 @@ public class CPI { } - public static With getWith(QueryWrapper queryWrapper) { return queryWrapper.with; } @@ -81,8 +80,8 @@ public class CPI { public static void setSelectColumnsIfNecessary(QueryWrapper queryWrapper, List selectColumns) { if (CollectionUtil.isEmpty(queryWrapper.getSelectColumns()) - && CollectionUtil.isNotEmpty(selectColumns) - && CollectionUtil.isEmpty(CPI.getJoinTables(queryWrapper)) + && CollectionUtil.isNotEmpty(selectColumns) + && CollectionUtil.isEmpty(CPI.getJoinTables(queryWrapper)) ) { queryWrapper.setSelectColumns(selectColumns); } @@ -212,14 +211,14 @@ public class CPI { public static void setFromIfNecessary(QueryWrapper queryWrapper, String tableName) { if (StringUtil.isNotBlank(tableName) - && CollectionUtil.isEmpty(queryWrapper.getQueryTables())) { + && CollectionUtil.isEmpty(queryWrapper.getQueryTables())) { queryWrapper.from(tableName); } } public static void setFromIfNecessary(QueryWrapper queryWrapper, String schema, String tableName) { if (StringUtil.isNotBlank(tableName) - && CollectionUtil.isEmpty(queryWrapper.getQueryTables())) { + && CollectionUtil.isEmpty(queryWrapper.getQueryTables())) { queryWrapper.from(new QueryTable(schema, tableName)); } } @@ -235,4 +234,5 @@ public class CPI { public static boolean isSameTable(QueryTable queryTable, QueryTable otherTable) { return queryTable.isSameTable(otherTable); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseQueryColumn.java index ea312c9b..105de2d9 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseQueryColumn.java @@ -91,6 +91,7 @@ public class CaseQueryColumn extends QueryColumn implements HasParamsColumn { public static class When implements CloneSupport { + private QueryCondition whenCondition; private Object thenValue; @@ -114,6 +115,7 @@ public class CaseQueryColumn extends QueryColumn implements HasParamsColumn { throw FlexExceptions.wrap(e); } } + } public static class Builder { @@ -148,6 +150,9 @@ public class CaseQueryColumn extends QueryColumn implements HasParamsColumn { this.builder.caseQueryColumn.addWhen(builder.lastWhen); return builder; } + } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseSearchQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseSearchQueryColumn.java index faa82c6a..8266a912 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseSearchQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CaseSearchQueryColumn.java @@ -91,6 +91,7 @@ public class CaseSearchQueryColumn extends QueryColumn implements HasParamsColum public static class When implements CloneSupport { + private Object searchValue; private Object thenValue; @@ -114,6 +115,7 @@ public class CaseSearchQueryColumn extends QueryColumn implements HasParamsColum throw FlexExceptions.wrap(e); } } + } @@ -153,6 +155,9 @@ public class CaseSearchQueryColumn extends QueryColumn implements HasParamsColum this.builder.caseQueryColumn.addWhen(builder.lastWhen); return builder; } + } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/DistinctQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/DistinctQueryColumn.java index 0eba34f6..d6e03ebb 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/DistinctQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/DistinctQueryColumn.java @@ -37,7 +37,7 @@ public class DistinctQueryColumn extends QueryColumn { } String sql = SqlConsts.DISTINCT + StringUtil.join(SqlConsts.DELIMITER, queryColumns, queryColumn -> - queryColumn.toSelectSql(queryTables, dialect)); + queryColumn.toSelectSql(queryTables, dialect)); return sql + WrapperUtil.buildAlias(alias, dialect); } @@ -50,7 +50,7 @@ public class DistinctQueryColumn extends QueryColumn { } return SqlConsts.DISTINCT + StringUtil.join(SqlConsts.DELIMITER, queryColumns, queryColumn -> - queryColumn.toSelectSql(queryTables, dialect)); + queryColumn.toSelectSql(queryTables, dialect)); } @@ -61,4 +61,5 @@ public class DistinctQueryColumn extends QueryColumn { clone.queryColumns = CollectionUtil.cloneArrayList(this.queryColumns); return clone; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FunctionQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FunctionQueryColumn.java index 1d75286e..f226ba04 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FunctionQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FunctionQueryColumn.java @@ -121,9 +121,9 @@ public class FunctionQueryColumn extends QueryColumn implements HasParamsColumn } String sql = columns.stream() - .filter(Objects::nonNull) - .map(c -> c.toSelectSql(queryTables, dialect)) - .collect(Collectors.joining(SqlConsts.DELIMITER)); + .filter(Objects::nonNull) + .map(c -> c.toSelectSql(queryTables, dialect)) + .collect(Collectors.joining(SqlConsts.DELIMITER)); if (StringUtil.isBlank(sql)) { return SqlConsts.EMPTY; @@ -133,13 +133,12 @@ public class FunctionQueryColumn extends QueryColumn implements HasParamsColumn } - @Override public String toString() { return "FunctionQueryColumn{" + - "fnName='" + fnName + '\'' + - ", columns=" + columns + - '}'; + "fnName='" + fnName + '\'' + + ", columns=" + columns + + '}'; } @Override diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/HasParamsColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/HasParamsColumn.java index f4d4fccd..a019e031 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/HasParamsColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/HasParamsColumn.java @@ -1,6 +1,23 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.core.query; public interface HasParamsColumn { Object[] getParamValues(); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/IfFunctionQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/IfFunctionQueryColumn.java index c11e3f52..1b6b87a3 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/IfFunctionQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/IfFunctionQueryColumn.java @@ -42,8 +42,8 @@ public class IfFunctionQueryColumn extends QueryColumn implements HasParamsColum @Override String toConditionSql(List queryTables, IDialect dialect) { return "IF(" + condition.toSql(queryTables, dialect) + ", " + - trueValue.toConditionSql(queryTables, dialect) + ", " + - falseValue.toConditionSql(queryTables, dialect) + ")"; + trueValue.toConditionSql(queryTables, dialect) + ", " + + falseValue.toConditionSql(queryTables, dialect) + ")"; } @Override @@ -71,4 +71,4 @@ public class IfFunctionQueryColumn extends QueryColumn implements HasParamsColum return clone; } -} \ No newline at end of file +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Join.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Join.java index 6dcd16c7..2082e408 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Join.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Join.java @@ -100,4 +100,5 @@ public class Join implements CloneSupport { throw FlexExceptions.wrap(e); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Joiner.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Joiner.java index 9abaca4c..80340026 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Joiner.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Joiner.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.query; @@ -52,5 +52,6 @@ public class Joiner { join.on(newWrapper.whereQueryCondition); return queryWrapper; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorQueryCondition.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorQueryCondition.java index 7eb6769a..a425e888 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorQueryCondition.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorQueryCondition.java @@ -49,9 +49,9 @@ public class OperatorQueryCondition extends QueryCondition { sql.append(prevEffectiveCondition.connector); } sql.append(operator) - .append(SqlConsts.BRACKET_LEFT) - .append(childSql) - .append(SqlConsts.BRACKET_RIGHT); + .append(SqlConsts.BRACKET_LEFT) + .append(childSql) + .append(SqlConsts.BRACKET_RIGHT); } } @@ -82,4 +82,5 @@ public class OperatorQueryCondition extends QueryCondition { clone.childCondition = ObjectUtil.clone(this.childCondition); return clone; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java index 8d690475..00cd5d03 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java @@ -28,6 +28,7 @@ import java.util.List; * 示例2:and not EXISTS (select ... from ... where ....) */ public class OperatorSelectCondition extends QueryCondition { + //操作符,例如 exist, not exist private final String operator; private QueryWrapper queryWrapper; @@ -51,9 +52,9 @@ public class OperatorSelectCondition extends QueryCondition { sql.append(prevEffectiveCondition.connector); } sql.append(operator) - .append(SqlConsts.BRACKET_LEFT) - .append(childSql) - .append(SqlConsts.BRACKET_RIGHT); + .append(SqlConsts.BRACKET_LEFT) + .append(childSql) + .append(SqlConsts.BRACKET_RIGHT); } } @@ -82,4 +83,5 @@ public class OperatorSelectCondition extends QueryCondition { clone.queryWrapper = ObjectUtil.clone(this.queryWrapper); return clone; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java index bc5ad6d6..acdc0ca7 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java @@ -571,10 +571,10 @@ public class QueryColumn implements CloneSupport { @Override public String toString() { return "QueryColumn{" + - "table=" + table + - ", name='" + name + '\'' + - ", alias='" + alias + '\'' + - '}'; + "table=" + table + + ", name='" + name + '\'' + + ", alias='" + alias + '\'' + + '}'; } @@ -589,4 +589,5 @@ public class QueryColumn implements CloneSupport { throw FlexExceptions.wrap(e); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java index c8397d1e..60bce81f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java @@ -182,8 +182,8 @@ public class QueryCondition implements CloneSupport { //子查询 else if (value instanceof QueryWrapper) { sql.append(SqlConsts.BRACKET_LEFT) - .append(dialect.buildSelectSql((QueryWrapper) value)) - .append(SqlConsts.BRACKET_RIGHT); + .append(dialect.buildSelectSql((QueryWrapper) value)) + .append(SqlConsts.BRACKET_RIGHT); } //原生sql else if (value instanceof RawFragment) { @@ -214,10 +214,10 @@ public class QueryCondition implements CloneSupport { protected void appendQuestionMark(StringBuilder sqlBuilder) { //noinspection StatementWithEmptyBody if (SqlConsts.IS_NULL.equals(logic) - || SqlConsts.IS_NOT_NULL.equals(logic) - || value instanceof QueryColumn - || value instanceof QueryWrapper - || value instanceof RawFragment) { + || SqlConsts.IS_NOT_NULL.equals(logic) + || value instanceof QueryColumn + || value instanceof QueryWrapper + || value instanceof RawFragment) { //do nothing } @@ -278,11 +278,11 @@ public class QueryCondition implements CloneSupport { @Override public String toString() { return "QueryCondition{" + - "column=" + column + - ", logic='" + logic + '\'' + - ", value=" + value + - ", effective=" + effective + - '}'; + "column=" + column + + ", logic='" + logic + '\'' + + ", value=" + value + + ", effective=" + effective + + '}'; } @Override @@ -302,4 +302,5 @@ public class QueryCondition implements CloneSupport { throw FlexExceptions.wrap(e); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java index 79028c98..83ded506 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java @@ -84,4 +84,5 @@ public class QueryOrderBy implements CloneSupport { throw FlexExceptions.wrap(e); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java index abe1860f..a1528645 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java @@ -86,8 +86,8 @@ public class QueryTable implements CloneSupport { return false; } if (StringUtil.isNotBlank(alias) - && StringUtil.isNotBlank(table.alias) - && (Objects.equals(alias, table.alias))) { + && StringUtil.isNotBlank(table.alias) + && (Objects.equals(alias, table.alias))) { return false; } return Objects.equals(name, table.name); @@ -112,10 +112,10 @@ public class QueryTable implements CloneSupport { @Override public String toString() { return "QueryTable{" + - "schema='" + schema + '\'' + - ", name='" + name + '\'' + - ", alias='" + alias + '\'' + - '}'; + "schema='" + schema + '\'' + + ", name='" + name + '\'' + + ", alias='" + alias + '\'' + + '}'; } @Override @@ -126,4 +126,5 @@ public class QueryTable implements CloneSupport { throw FlexExceptions.wrap(e); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java index c2a876f4..0a3591c7 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java @@ -713,7 +713,7 @@ public class QueryWrapper extends BaseQueryWrapper { List childQueryWrappers = tableChildQuery == null - ? new ArrayList<>() : new ArrayList<>(tableChildQuery); + ? new ArrayList<>() : new ArrayList<>(tableChildQuery); childQueryWrappers.addAll(whereChildQuery); childQueryWrappers.addAll(havingChildQuery); @@ -731,4 +731,5 @@ public class QueryWrapper extends BaseQueryWrapper { public QueryWrapper clone() { return super.clone(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RawFragment.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RawFragment.java index 583ca38e..70eb4fda 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RawFragment.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RawFragment.java @@ -68,4 +68,5 @@ public class RawFragment extends QueryCondition { public String getContent() { return content; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryColumn.java index 5bacd887..b251f145 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryColumn.java @@ -60,4 +60,5 @@ public class SelectQueryColumn extends QueryColumn implements HasParamsColumn { public Object[] getParamValues() { return queryWrapper.getValueArray(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryTable.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryTable.java index 1433bafc..1bd83e2a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryTable.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SelectQueryTable.java @@ -62,4 +62,5 @@ public class SelectQueryTable extends QueryTable { clone.queryWrapper = this.queryWrapper.clone(); return clone; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SqlConnector.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SqlConnector.java index ec93bec1..cfe2ab79 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SqlConnector.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/SqlConnector.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.query; @@ -19,7 +19,7 @@ public enum SqlConnector { AND(" AND "), -// AND_NOT(" AND NOT "), + // AND_NOT(" AND NOT "), // AND_EXISTS(" AND EXISTS "), // AND_NOT_EXISTS(" AND NOT EXISTS "), OR(" OR "), diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringFunctionQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringFunctionQueryColumn.java index ed7dcc7f..ef9c56fd 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringFunctionQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringFunctionQueryColumn.java @@ -81,9 +81,9 @@ public class StringFunctionQueryColumn extends QueryColumn { @Override public String toString() { return "StringFunctionQueryColumn{" + - "fnName='" + fnName + '\'' + - ", params=" + params + - '}'; + "fnName='" + fnName + '\'' + + ", params=" + params + + '}'; } @Override @@ -93,4 +93,5 @@ public class StringFunctionQueryColumn extends QueryColumn { clone.params = CollectionUtil.newArrayList(this.params); return clone; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryColumn.java index 12af733c..65e52450 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryColumn.java @@ -45,12 +45,13 @@ public class StringQueryColumn extends QueryColumn { @Override public String toString() { return "StringQueryColumn{" + - "content='" + content + '\'' + - '}'; + "content='" + content + '\'' + + '}'; } @Override public StringQueryColumn clone() { return (StringQueryColumn) super.clone(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryOrderBy.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryOrderBy.java index a1fdbb60..0e197c69 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryOrderBy.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/StringQueryOrderBy.java @@ -42,4 +42,5 @@ public class StringQueryOrderBy extends QueryOrderBy { public StringQueryOrderBy clone() { return (StringQueryOrderBy) super.clone(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/UnionWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/UnionWrapper.java index 1b794a6d..7bf0160f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/UnionWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/UnionWrapper.java @@ -61,9 +61,9 @@ public class UnionWrapper implements CloneSupport { public void buildSql(StringBuilder sqlBuilder, IDialect dialect) { sqlBuilder.append(key) - .append(SqlConsts.BRACKET_LEFT) - .append(dialect.buildSelectSql(queryWrapper)) - .append(SqlConsts.BRACKET_RIGHT); + .append(SqlConsts.BRACKET_LEFT) + .append(dialect.buildSelectSql(queryWrapper)) + .append(SqlConsts.BRACKET_RIGHT); } @Override @@ -77,4 +77,5 @@ public class UnionWrapper implements CloneSupport { throw FlexExceptions.wrap(e); } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithBuilder.java index 2efedbbd..06437dea 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithBuilder.java @@ -17,7 +17,9 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.util.CollectionUtil; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; public class WithBuilder { diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java index 9b649557..8a02d173 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithDetail.java @@ -22,4 +22,5 @@ public interface WithDetail extends CloneSupport { String toSql(IDialect dialect); Object[] getParamValues(); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java index 14c666ee..5543a732 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithItem.java @@ -66,7 +66,7 @@ public class WithItem implements CloneSupport { public String toSql(IDialect dialect) { StringBuilder sql = new StringBuilder(name); - if (CollectionUtil.isNotEmpty(params)){ + if (CollectionUtil.isNotEmpty(params)) { sql.append(BRACKET_LEFT).append(StringUtil.join(DELIMITER, params)).append(BRACKET_RIGHT); } sql.append(AS).append(BRACKET_LEFT); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java index 033ad642..22ef21c4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WithValuesDetail.java @@ -51,7 +51,7 @@ public class WithValuesDetail implements WithDetail { stringValues.add(String.valueOf(value)); } StringBuilder sql = new StringBuilder("VALUES (") - .append(StringUtil.join(", ", stringValues)).append(") "); + .append(StringUtil.join(", ", stringValues)).append(") "); return sql.append(dialect.buildNoSelectSql(queryWrapper)).toString(); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java index b0c452b9..29470fd2 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java @@ -33,7 +33,8 @@ import java.util.List; class WrapperUtil { - private WrapperUtil() {} + private WrapperUtil() { + } static List getChildQueryWrapper(QueryCondition condition) { List list = null; @@ -96,8 +97,8 @@ class WrapperUtil { Object value = condition.getValue(); if (value == null - || value instanceof QueryColumn - || value instanceof RawFragment) { + || value instanceof QueryColumn + || value instanceof RawFragment) { getValues(condition.next, params); return; } @@ -154,7 +155,8 @@ class WrapperUtil { return StringUtil.isBlank(alias) ? SqlConsts.EMPTY : getAsKeyWord(dialect) + dialect.wrap(alias); } - private static String getAsKeyWord(IDialect dialect){ + private static String getAsKeyWord(IDialect dialect) { return dialect instanceof OracleDialect ? SqlConsts.BLANK : SqlConsts.AS; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/AbstractRelation.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/AbstractRelation.java index 7a30a829..ab61abc7 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/AbstractRelation.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/AbstractRelation.java @@ -62,7 +62,7 @@ abstract class AbstractRelation { String dataSource, Class entityClass, Field relationField, String extraCondition ) { - this.name = entityClass.getSimpleName()+"."+relationField.getName(); + this.name = entityClass.getSimpleName() + "." + relationField.getName(); this.simpleName = relationField.getName(); this.selfEntityClass = entityClass; this.relationField = relationField; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ManyToOne.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ManyToOne.java index 06e81f57..05fe5262 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ManyToOne.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ManyToOne.java @@ -21,19 +21,19 @@ import java.lang.reflect.Field; class ManyToOne extends ToOneRelation { - public ManyToOne(RelationManyToOne annotation, Class entityClass, Field relationField) { - super(annotation.selfField() + public ManyToOne(RelationManyToOne annotation, Class entityClass, Field relationField) { + super(annotation.selfField() , annotation.targetSchema() , annotation.targetTable() - , getDefaultPrimaryProperty(annotation.targetField(), getTargetEntityClass(entityClass, relationField) - , "@RelationManyToOne.selfField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"") + , getDefaultPrimaryProperty(annotation.targetField(), getTargetEntityClass(entityClass, relationField) + , "@RelationManyToOne.selfField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"") , annotation.joinTable() , annotation.joinSelfColumn() , annotation.joinTargetColumn() - , annotation.dataSource() - , entityClass - , relationField); - } + , annotation.dataSource() + , entityClass + , relationField); + } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToOne.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToOne.java index 267ffa65..2cd38c37 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToOne.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/OneToOne.java @@ -21,18 +21,18 @@ import java.lang.reflect.Field; class OneToOne extends ToOneRelation { - public OneToOne(RelationOneToOne annotation, Class entityClass, Field relationField) { - super(getDefaultPrimaryProperty(annotation.selfField(), entityClass - , "@RelationOneToOne.selfField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"") + public OneToOne(RelationOneToOne annotation, Class entityClass, Field relationField) { + super(getDefaultPrimaryProperty(annotation.selfField(), entityClass + , "@RelationOneToOne.selfField can not be empty in field: \"" + entityClass.getName() + "." + relationField.getName() + "\"") , annotation.targetSchema() , annotation.targetTable() - , annotation.targetField() + , annotation.targetField() , annotation.joinTable() , annotation.joinSelfColumn() , annotation.joinTargetColumn() - , annotation.dataSource() - , entityClass - , relationField); - } + , annotation.dataSource() + , entityClass + , relationField); + } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/RelationManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/RelationManager.java index cc07becd..ab8a63af 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/RelationManager.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/RelationManager.java @@ -292,4 +292,5 @@ public class RelationManager { } } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java index 662f7812..cc95dc8d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToManyRelation.java @@ -77,4 +77,5 @@ class ToManyRelation extends AbstractRelation { } }); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToOneRelation.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToOneRelation.java index 0eaaa777..324e9efb 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToOneRelation.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/relation/ToOneRelation.java @@ -73,4 +73,5 @@ class ToOneRelation extends AbstractRelation { } return null; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java index e6073263..17633dc4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java @@ -332,7 +332,7 @@ public class Db { public static int[] updateBatch(String sql, BatchArgsSetter batchArgsSetter) { int batchSize = batchArgsSetter.getBatchSize(); return executeBatch(batchSize, batchSize, RowMapper.class - , (mapper, index) -> mapper.updateBySql(sql, batchArgsSetter.getSqlArgs(index))); + , (mapper, index) -> mapper.updateBySql(sql, batchArgsSetter.getSqlArgs(index))); } @@ -1139,4 +1139,5 @@ public class Db { public static T txWithResult(Supplier supplier, Propagation propagation) { return TransactionalManager.exec(supplier, propagation, true); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Row.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Row.java index bdfeee6b..d23301ae 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Row.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Row.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.row; @@ -130,9 +130,9 @@ public class Row extends LinkedHashMap implements UpdateWrapper return result != null ? result : defaultValue; } - public Object getIgnoreCase(String key){ + public Object getIgnoreCase(String key) { for (String innerKey : keySet()) { - if (innerKey.equalsIgnoreCase(key)){ + if (innerKey.equalsIgnoreCase(key)) { return super.get(innerKey); } } @@ -140,7 +140,7 @@ public class Row extends LinkedHashMap implements UpdateWrapper } - public Object getIgnoreCase(String key, Object defaultValue){ + public Object getIgnoreCase(String key, Object defaultValue) { Object result = getIgnoreCase(key); return result != null ? result : defaultValue; } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowCPI.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowCPI.java index d9e52ef0..7b35a060 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowCPI.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowCPI.java @@ -52,7 +52,7 @@ public class RowCPI { return row.getModifyAttrs(); } - public static Map getRawValueMap(Row row){ + public static Map getRawValueMap(Row row) { return row.getRawValueMap(); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java index 816661cb..6ed9d166 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java @@ -224,7 +224,7 @@ public interface RowMapper { */ @UpdateProvider(type = RowSqlProvider.class, method = "updateNumberAddByQuery") int updateNumberAddByQuery(@Param(FlexConsts.SCHEMA_NAME) String schema, @Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.FIELD_NAME) String fieldName - , @Param(FlexConsts.VALUE) Number value, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper); + , @Param(FlexConsts.VALUE) Number value, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper); default int updateNumberAddByQuery(String tableName, String fieldName, Number value, QueryWrapper queryWrapper) { @@ -403,7 +403,7 @@ public interface RowMapper { */ @SelectProvider(type = RowSqlProvider.class, method = "selectListByQuery") List selectObjectListByQuery(@Param(FlexConsts.SCHEMA_NAME) String schema - , @Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper); + , @Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper); /** diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java index 87c72b78..c2372230 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.row; @@ -42,8 +42,8 @@ public class RowMapperInvoker { } } - public int insert(String schema,String tableName, Row row) { - return execute(mapper -> mapper.insert(schema,tableName, row)); + public int insert(String schema, String tableName, Row row) { + return execute(mapper -> mapper.insert(schema, tableName, row)); } @@ -51,29 +51,29 @@ public class RowMapperInvoker { return execute(mapper -> mapper.insertBySql(sql, args)); } - public int insertBatchWithFirstRowColumns(String schema,String tableName, List rows) { - return execute(mapper -> mapper.insertBatchWithFirstRowColumns(schema,tableName, rows)); + public int insertBatchWithFirstRowColumns(String schema, String tableName, List rows) { + return execute(mapper -> mapper.insertBatchWithFirstRowColumns(schema, tableName, rows)); } public int deleteBySql(String sql, Object... args) { return execute(mapper -> mapper.deleteBySql(sql, args)); } - public int deleteById(String schema,String tableName, Row row) { - return execute(mapper -> mapper.deleteById(schema,tableName, row)); + public int deleteById(String schema, String tableName, Row row) { + return execute(mapper -> mapper.deleteById(schema, tableName, row)); } - public int deleteById(String schema,String tableName, String primaryKey, Object id) { - return execute(mapper -> mapper.deleteById(schema,tableName, primaryKey, id)); + public int deleteById(String schema, String tableName, String primaryKey, Object id) { + return execute(mapper -> mapper.deleteById(schema, tableName, primaryKey, id)); } - public int deleteBatchByIds(String schema,String tableName, String primaryKey, Collection ids) { - return execute(mapper -> mapper.deleteBatchByIds(schema,tableName, primaryKey, ids)); + public int deleteBatchByIds(String schema, String tableName, String primaryKey, Collection ids) { + return execute(mapper -> mapper.deleteBatchByIds(schema, tableName, primaryKey, ids)); } - public int deleteByQuery(String schema,String tableName, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.deleteByQuery(schema,tableName, queryWrapper)); + public int deleteByQuery(String schema, String tableName, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.deleteByQuery(schema, tableName, queryWrapper)); } public int updateBySql(String sql, Object... args) { @@ -115,52 +115,52 @@ public class RowMapperInvoker { return results; } - public int updateById(String schema,String tableName, Row row) { - return execute(mapper -> mapper.updateById(schema,tableName, row)); + public int updateById(String schema, String tableName, Row row) { + return execute(mapper -> mapper.updateById(schema, tableName, row)); } - public int updateByQuery(String schema,String tableName, Row data, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.updateByQuery(schema,tableName, data, queryWrapper)); + public int updateByQuery(String schema, String tableName, Row data, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.updateByQuery(schema, tableName, data, queryWrapper)); } - public int updateBatchById(String schema,String tableName, List rows) { - return execute(mapper -> mapper.updateBatchById(schema,tableName, rows)); + public int updateBatchById(String schema, String tableName, List rows) { + return execute(mapper -> mapper.updateBatchById(schema, tableName, rows)); } public Row selectOneBySql(String sql, Object... args) { return execute(mapper -> mapper.selectOneBySql(sql, args)); } - public Row selectOneById(String schema,String tableName, Row row) { - return execute(mapper -> mapper.selectOneById(schema,tableName, row)); + public Row selectOneById(String schema, String tableName, Row row) { + return execute(mapper -> mapper.selectOneById(schema, tableName, row)); } - public Row selectOneById(String schema,String tableName, String primaryKey, Object id) { - return execute(mapper -> mapper.selectOneById(schema,tableName, primaryKey, id)); + public Row selectOneById(String schema, String tableName, String primaryKey, Object id) { + return execute(mapper -> mapper.selectOneById(schema, tableName, primaryKey, id)); } - public Row selectOneByQuery(String schema,String tableName, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.selectOneByQuery(schema,tableName, queryWrapper)); + public Row selectOneByQuery(String schema, String tableName, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.selectOneByQuery(schema, tableName, queryWrapper)); } public List selectListBySql(String sql, Object... args) { return execute(mapper -> mapper.selectListBySql(sql, args)); } - public List selectListByQuery(String schema,String tableName, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.selectListByQuery(schema,tableName, queryWrapper)); + public List selectListByQuery(String schema, String tableName, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.selectListByQuery(schema, tableName, queryWrapper)); } - public List selectAll(String schema,String tableName) { - return execute(mapper -> mapper.selectAll(schema,tableName)); + public List selectAll(String schema, String tableName) { + return execute(mapper -> mapper.selectAll(schema, tableName)); } - public Object selectObjectByQuery(String schema,String tableName, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.selectObjectByQuery(schema,tableName, queryWrapper)); + public Object selectObjectByQuery(String schema, String tableName, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.selectObjectByQuery(schema, tableName, queryWrapper)); } - public List selectObjectListByQuery(String schema,String tableName, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.selectObjectListByQuery(schema,tableName, queryWrapper)); + public List selectObjectListByQuery(String schema, String tableName, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.selectObjectListByQuery(schema, tableName, queryWrapper)); } public Object selectObject(String sql, Object... args) { @@ -176,16 +176,17 @@ public class RowMapperInvoker { } - public long selectCountByQuery(String schema,String tableName, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.selectCountByQuery(schema,tableName, queryWrapper)); + public long selectCountByQuery(String schema, String tableName, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.selectCountByQuery(schema, tableName, queryWrapper)); } - public Page paginate(String schema,String tableName, Page page, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.paginate(schema,tableName, page, queryWrapper)); + public Page paginate(String schema, String tableName, Page page, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.paginate(schema, tableName, page, queryWrapper)); } - public int updateNumberAddByQuery(String schema,String tableName, String fieldName, Number value, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.updateNumberAddByQuery(schema,tableName, fieldName, value, queryWrapper)); + public int updateNumberAddByQuery(String schema, String tableName, String fieldName, Number value, QueryWrapper queryWrapper) { + return execute(mapper -> mapper.updateNumberAddByQuery(schema, tableName, fieldName, value, queryWrapper)); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowUtil.java index 9cdb84d9..ccd943e0 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowUtil.java @@ -29,7 +29,8 @@ import java.util.concurrent.ConcurrentHashMap; public class RowUtil { - private RowUtil() {} + private RowUtil() { + } static final String INDEX_SEPARATOR = "$"; @@ -201,9 +202,9 @@ public class RowUtil { private static boolean isCJK(char c) { Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS - || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B - || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS - || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION; + || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B + || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS + || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION; } @@ -211,9 +212,9 @@ public class RowUtil { return MapUtil.computeIfAbsent(classSettersCache, aClass, aClass1 -> { Map columnSetterMapping = new HashMap<>(); List setters = ClassUtil.getAllMethods(aClass1, - method -> method.getName().startsWith("set") - && method.getParameterCount() == 1 - && Modifier.isPublic(method.getModifiers()) + method -> method.getName().startsWith("set") + && method.getParameterCount() == 1 + && Modifier.isPublic(method.getModifiers()) ); for (Method setter : setters) { String column = setter.getName().substring(3); @@ -224,4 +225,5 @@ public class RowUtil { return columnSetterMapping; }); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java index de421970..e6624c99 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java @@ -233,10 +233,10 @@ public interface IService { // BaseMapper 是经过 Mybatis 动态代理处理过的对象,需要获取原始 BaseMapper 类型 Class> usefulClass = (Class>) ClassUtil.getUsefulClass(getMapper().getClass()); return SqlUtil.toBool(Arrays.stream(Db.executeBatch( - entityList.size() - , batchSize - , usefulClass - , (mapper, index) -> mapper.update(entityList.get(index))) + entityList.size() + , batchSize + , usefulClass + , (mapper, index) -> mapper.update(entityList.get(index))) ).sum()); }); } @@ -491,4 +491,4 @@ public interface IService { return QueryWrapper.create(); } -} \ No newline at end of file +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java index c08715ce..7ecc81b5 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/ColumnInfo.java @@ -128,4 +128,5 @@ public class ColumnInfo { public void setMaskType(String maskType) { this.maskType = maskType; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicSchemaProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicSchemaProcessor.java index 80dc13ce..e6853c9b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicSchemaProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicSchemaProcessor.java @@ -1,20 +1,22 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.table; public interface DynamicSchemaProcessor { + String process(String schema); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicTableProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicTableProcessor.java index e33b29e8..00c50c75 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicTableProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicTableProcessor.java @@ -1,20 +1,22 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.table; public interface DynamicTableProcessor { + String process(String tableName); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/EntityWrapperFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/EntityWrapperFactory.java index 882acc5b..6198fdf4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/EntityWrapperFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/EntityWrapperFactory.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.table; @@ -30,7 +30,7 @@ public class EntityWrapperFactory implements ObjectWrapperFactory { public boolean hasWrapperFor(Object object) { Class objectClass = object.getClass(); if (Map.class.isAssignableFrom(objectClass) || - Collection.class.isAssignableFrom(objectClass)) { + Collection.class.isAssignableFrom(objectClass)) { return false; } return TableInfoFactory.ofEntityClass(objectClass) != null; @@ -57,5 +57,7 @@ public class EntityWrapperFactory implements ObjectWrapperFactory { Object v = tableInfo.invokeOnSetListener(entity, prop.getName(), value); super.set(prop, v); } + } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java index cc028afc..0561fa4a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/IdInfo.java @@ -86,4 +86,5 @@ public class IdInfo extends ColumnInfo { public void setBefore(Boolean before) { this.before = before; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index ae46eec5..92d6434e 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -1208,4 +1208,5 @@ public class TableInfo { String column = getColumnByProperty(property); return columnQueryMapping.get(column); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java index abe4b96e..ffe7181f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java @@ -51,18 +51,18 @@ public class TableInfoFactory { } static final Set> defaultSupportColumnTypes = CollectionUtil.newHashSet( - int.class, Integer.class, - short.class, Short.class, - long.class, Long.class, - float.class, Float.class, - double.class, Double.class, - boolean.class, Boolean.class, - Date.class, java.sql.Date.class, Time.class, Timestamp.class, - Instant.class, LocalDate.class, LocalDateTime.class, LocalTime.class, OffsetDateTime.class, OffsetTime.class, ZonedDateTime.class, - Year.class, Month.class, YearMonth.class, JapaneseDate.class, - byte[].class, Byte[].class, Byte.class, - BigInteger.class, BigDecimal.class, - char.class, String.class, Character.class + int.class, Integer.class, + short.class, Short.class, + long.class, Long.class, + float.class, Float.class, + double.class, Double.class, + boolean.class, Boolean.class, + Date.class, java.sql.Date.class, Time.class, Timestamp.class, + Instant.class, LocalDate.class, LocalDateTime.class, LocalTime.class, OffsetDateTime.class, OffsetTime.class, ZonedDateTime.class, + Year.class, Month.class, YearMonth.class, JapaneseDate.class, + byte[].class, Byte[].class, Byte.class, + BigInteger.class, BigDecimal.class, + char.class, String.class, Character.class ); @@ -144,25 +144,25 @@ public class TableInfoFactory { if (table.onInsert().length > 0) { List insertListeners = Arrays.stream(table.onInsert()) - .filter(listener -> listener != NoneListener.class) - .map(ClassUtil::newInstance) - .collect(Collectors.toList()); + .filter(listener -> listener != NoneListener.class) + .map(ClassUtil::newInstance) + .collect(Collectors.toList()); tableInfo.setOnInsertListeners(insertListeners); } if (table.onUpdate().length > 0) { List updateListeners = Arrays.stream(table.onUpdate()) - .filter(listener -> listener != NoneListener.class) - .map(ClassUtil::newInstance) - .collect(Collectors.toList()); + .filter(listener -> listener != NoneListener.class) + .map(ClassUtil::newInstance) + .collect(Collectors.toList()); tableInfo.setOnUpdateListeners(updateListeners); } if (table.onSet().length > 0) { List setListeners = Arrays.stream(table.onSet()) - .filter(listener -> listener != NoneListener.class) - .map(ClassUtil::newInstance) - .collect(Collectors.toList()); + .filter(listener -> listener != NoneListener.class) + .map(ClassUtil::newInstance) + .collect(Collectors.toList()); tableInfo.setOnSetListeners(setListeners); } @@ -210,8 +210,8 @@ public class TableInfoFactory { //满足以下 3 种情况,不支持该类型 if ((column == null || column.typeHandler() == UnknownTypeHandler.class) // 未配置 typeHandler - && !fieldType.isEnum() // 类型不是枚举 - && !defaultSupportColumnTypes.contains(fieldType) //默认的自动类型不包含该类型 + && !fieldType.isEnum() // 类型不是枚举 + && !defaultSupportColumnTypes.contains(fieldType) //默认的自动类型不包含该类型 ) { // 集合嵌套 if (Collection.class.isAssignableFrom(fieldType)) { @@ -223,7 +223,7 @@ public class TableInfoFactory { } // 实体类嵌套 else if (!Map.class.isAssignableFrom(fieldType) - && !fieldType.isArray()) { + && !fieldType.isArray()) { tableInfo.addAssociationType(field.getName(), fieldType); } // 不支持的类型直接跳过 @@ -401,7 +401,7 @@ public class TableInfoFactory { Field[] declaredFields = entityClass.getDeclaredFields(); for (Field declaredField : declaredFields) { if (Modifier.isStatic(declaredField.getModifiers()) - || existName(fields, declaredField)) { + || existName(fields, declaredField)) { continue; } fields.add(declaredField); @@ -419,4 +419,5 @@ public class TableInfoFactory { } return false; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableManager.java index b1715ede..b0328564 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableManager.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableManager.java @@ -22,7 +22,8 @@ import java.util.Map; public class TableManager { - private TableManager() {} + private TableManager() { + } private static DynamicTableProcessor dynamicTableProcessor; private static DynamicSchemaProcessor dynamicSchemaProcessor; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/tenant/TenantManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/tenant/TenantManager.java index 95f2ab9f..d6a6a591 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/tenant/TenantManager.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/tenant/TenantManager.java @@ -19,7 +19,8 @@ import java.util.function.Supplier; public class TenantManager { - private TenantManager() {} + private TenantManager() { + } private static final ThreadLocal ignoreFlags = new ThreadLocal<>(); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/Propagation.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/Propagation.java index 42570f8d..b043c0db 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/Propagation.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/Propagation.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.transaction; @@ -38,8 +38,8 @@ public enum Propagation { //以非事务的方式运行,若存在当前事务,则抛出异常。 NEVER(5), - //如果存在当前事务,则在嵌套事务中执行,否则行为类似于 PROPAGATION_REQUIRED - NESTED(6), + //如果存在当前事务,则在嵌套事务中执行,否则行为类似于 PROPAGATION_REQUIRED + NESTED(6), ; private int value; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/TransactionalManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/TransactionalManager.java index 598ee768..ae12a4cd 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/TransactionalManager.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/transaction/TransactionalManager.java @@ -37,7 +37,7 @@ public class TransactionalManager { //> private static final ThreadLocal>> CONNECTION_HOLDER - = ThreadLocal.withInitial(ConcurrentHashMap::new); + = ThreadLocal.withInitial(ConcurrentHashMap::new); public static void hold(String xid, String ds, Connection connection) { @@ -206,4 +206,5 @@ public class TransactionalManager { } } } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordHandler.java index c7b19635..d76b083d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordHandler.java @@ -38,9 +38,9 @@ class ModifyAttrsRecordHandler implements MethodHandler { String methodName = originalMethod.getName(); if (methodName.startsWith("set") - && methodName.length() > 3 - && Character.isUpperCase(methodName.charAt(3)) - && originalMethod.getParameterCount() == 1) { + && methodName.length() > 3 + && Character.isUpperCase(methodName.charAt(3)) + && originalMethod.getParameterCount() == 1) { String property = StringUtil.firstCharToLowerCase(originalMethod.getName().substring(3)); updates.put(property, args[0]); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java index 8a1d2674..29d65d6f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/ModifyAttrsRecordProxyFactory.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.update; @@ -26,11 +26,12 @@ public class ModifyAttrsRecordProxyFactory { private static final ModifyAttrsRecordProxyFactory instance = new ModifyAttrsRecordProxyFactory(); - public static ModifyAttrsRecordProxyFactory getInstance(){ + public static ModifyAttrsRecordProxyFactory getInstance() { return instance; } - private ModifyAttrsRecordProxyFactory(){} + private ModifyAttrsRecordProxyFactory() { + } public T get(Class target) { ProxyFactory factory = new ProxyFactory(); @@ -48,15 +49,13 @@ public class ModifyAttrsRecordProxyFactory { proxyObject = (T) proxyClass.newInstance(); ((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler()); } catch (Throwable e) { - LogFactory.getLog(ModifyAttrsRecordProxyFactory.class).error(e.toString(),e); + LogFactory.getLog(ModifyAttrsRecordProxyFactory.class).error(e.toString(), e); } return proxyObject; } - - } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/RawValue.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/RawValue.java index 64b373ec..aaa72325 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/RawValue.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/RawValue.java @@ -52,4 +52,5 @@ public class RawValue implements Serializable { return object.toString(); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java index 412dcb14..c0e0ab68 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java @@ -20,7 +20,8 @@ import java.util.Objects; public class ArrayUtil { - private ArrayUtil() {} + private ArrayUtil() { + } /** diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ClassUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ClassUtil.java index 21b6fa38..98926274 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ClassUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ClassUtil.java @@ -33,12 +33,12 @@ public class ClassUtil { //proxy frameworks private static final List PROXY_CLASS_NAMES = Arrays.asList("net.sf.cglib.proxy.Factory" - // cglib - , "org.springframework.cglib.proxy.Factory" + // cglib + , "org.springframework.cglib.proxy.Factory" - // javassist - , "javassist.util.proxy.ProxyObject" - , "org.apache.ibatis.javassist.util.proxy.ProxyObject"); + // javassist + , "javassist.util.proxy.ProxyObject" + , "org.apache.ibatis.javassist.util.proxy.ProxyObject"); private static final String ENHANCER_BY = "$$EnhancerBy"; private static final String JAVASSIST_BY = "_$$_"; @@ -99,11 +99,11 @@ public class ClassUtil { public static boolean isArray(Class clazz) { return clazz.isArray() - || clazz == int[].class - || clazz == long[].class - || clazz == short[].class - || clazz == float[].class - || clazz == double[].class; + || clazz == int[].class + || clazz == long[].class + || clazz == short[].class + || clazz == float[].class + || clazz == double[].class; } public static boolean canInstance(int mod) { @@ -169,7 +169,7 @@ public class ClassUtil { } if (constructor.getParameterCount() > 0 - && (paras == null || paras.length != constructor.getParameterCount())) { + && (paras == null || paras.length != constructor.getParameterCount())) { return false; } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java index dbe40921..6aa595c5 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java @@ -79,7 +79,6 @@ public class CollectionUtil { } - public static List toList(Collection collection) { if (collection instanceof List) { return (List) collection; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ConvertUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ConvertUtil.java index 82c21738..87527f86 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ConvertUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ConvertUtil.java @@ -25,7 +25,8 @@ import java.util.Date; public class ConvertUtil { - private ConvertUtil() {} + private ConvertUtil() { + } public static Object convert(Object value, Class targetClass) { return convert(value, targetClass, false); @@ -36,7 +37,7 @@ public class ConvertUtil { return getPrimitiveDefaultValue(targetClass); } if (value == null || (targetClass != String.class && value.getClass() == String.class - && StringUtil.isBlank((String) value))) { + && StringUtil.isBlank((String) value))) { return null; } if (value.getClass().isAssignableFrom(targetClass)) { @@ -300,4 +301,5 @@ public class ConvertUtil { return (LocalDateTime) o; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/DateUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/DateUtil.java index 35ef5754..ded74b61 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/DateUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/DateUtil.java @@ -30,7 +30,8 @@ import java.util.concurrent.ConcurrentHashMap; public class DateUtil { - private DateUtil() {} + private DateUtil() { + } public static String datePatternWithoutDividing = "yyyyMMdd"; public static String datePattern = "yyyy-MM-dd"; @@ -91,7 +92,6 @@ public class DateUtil { } - public static Date parseDate(String dateString) { if (StringUtil.isBlank(dateString)) { return null; @@ -133,7 +133,6 @@ public class DateUtil { } - public static LocalDateTime parseLocalDateTime(String dateString) { if (StringUtil.isBlank(dateString)) { return null; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java index 4a465dd2..d185950c 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.util; @@ -117,4 +117,5 @@ public class EnumWrapper> { public Method getGetterMethod() { return getterMethod; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java index 2695b1cb..a896c3af 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.util; @@ -54,9 +54,9 @@ public class FieldWrapper { String setterName = "set" + StringUtil.firstCharToUpperCase(fieldName); Method setter = ClassUtil.getFirstMethod(clazz, method -> - method.getParameterCount() == 1 - && Modifier.isPublic(method.getModifiers()) - && method.getName().equals(setterName)); + method.getParameterCount() == 1 + && Modifier.isPublic(method.getModifiers()) + && method.getName().equals(setterName)); if (setter == null) { throw new IllegalStateException("Can not find method \"set" + StringUtil.firstCharToUpperCase(fieldName) + "\" in class: " + clazz); @@ -69,8 +69,8 @@ public class FieldWrapper { String[] getterNames = new String[]{"get" + StringUtil.firstCharToUpperCase(fieldName), "is" + StringUtil.firstCharToUpperCase(fieldName)}; fieldWrapper.getterMethod = ClassUtil.getFirstMethod(clazz, method -> method.getParameterCount() == 0 - && Modifier.isPublic(method.getModifiers()) - && ArrayUtil.contains(getterNames, method.getName())); + && Modifier.isPublic(method.getModifiers()) + && ArrayUtil.contains(getterNames, method.getName())); wrapperMap.put(fieldName, fieldWrapper); } @@ -119,4 +119,5 @@ public class FieldWrapper { public Class getMappingType() { return mappingType; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/LambdaGetter.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/LambdaGetter.java index ede3a678..c828fef1 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/LambdaGetter.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/LambdaGetter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.core.util; @@ -19,6 +19,8 @@ import java.io.Serializable; @FunctionalInterface public interface LambdaGetter extends Serializable { + Object get(T source); + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapperUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapperUtil.java index 5f664f83..629e2426 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapperUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapperUtil.java @@ -53,8 +53,8 @@ public class MapperUtil { */ public static QueryWrapper rawCountQueryWrapper(QueryWrapper queryWrapper) { return QueryWrapper.create() - .select(count().as("total")) - .from(queryWrapper).as("t"); + .select(count().as("total")) + .from(queryWrapper).as("t"); } /** @@ -254,7 +254,7 @@ public class MapperUtil { return list.get(0); } throw new TooManyResultsException( - "Expected one result (or null) to be returned by selectOne(), but found: " + size); + "Expected one result (or null) to be returned by selectOne(), but found: " + size); } public static long getLongNumber(List objects) { diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ObjectUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ObjectUtil.java index dab98e22..f673fad3 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ObjectUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ObjectUtil.java @@ -21,7 +21,8 @@ import java.util.Objects; public class ObjectUtil { - private ObjectUtil() {} + private ObjectUtil() { + } public static Object cloneObject(Object value) { // ROLE.ROLE_ID.ge(USER.USER_ID) @@ -71,4 +72,5 @@ public class ObjectUtil { } return false; } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/Reflectors.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/Reflectors.java index 0fc85ca0..7f8435a8 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/Reflectors.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/Reflectors.java @@ -23,9 +23,10 @@ import java.util.concurrent.ConcurrentMap; public class Reflectors { - private static final ConcurrentMap, Reflector> reflectorMap = new ConcurrentHashMap<>(); + private static final ConcurrentMap, Reflector> reflectorMap = new ConcurrentHashMap<>(); - public static Reflector of(Class type){ - return MapUtil.computeIfAbsent(reflectorMap, type, Reflector::new); + public static Reflector of(Class type) { + return MapUtil.computeIfAbsent(reflectorMap, type, Reflector::new); } + } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/SqlUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/SqlUtil.java index b1774ca8..4a5e0196 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/SqlUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/SqlUtil.java @@ -22,7 +22,6 @@ import java.util.StringJoiner; import java.util.regex.Matcher; import static com.mybatisflex.core.constant.SqlConsts.*; -import static com.mybatisflex.core.constant.SqlConsts.BRACKET_RIGHT; public class SqlUtil { diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/UpdateEntity.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/UpdateEntity.java index 2ce27733..eb4eb1da 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/UpdateEntity.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/UpdateEntity.java @@ -27,7 +27,8 @@ import java.util.List; public class UpdateEntity { - private UpdateEntity() {} + private UpdateEntity() { + } public static T of(Class clazz) { @@ -84,7 +85,7 @@ public class UpdateEntity { for (String propertyName : propertyNames) { try { Object value = reflector.getGetInvoker(propertyName) - .invoke(entity, null); + .invoke(entity, null); if (value != null) { reflector.getSetInvoker(propertyName).invoke(newEntity, new Object[]{value}); } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account.java index 1ec065d0..39a665af 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.annotation.Column; @@ -7,7 +23,7 @@ import com.mybatisflex.annotation.Table; import java.util.Date; -@Table(value = "tb_account",onUpdate = NoneListener.class) +@Table(value = "tb_account", onUpdate = NoneListener.class) public class Account { @Id @@ -82,4 +98,5 @@ public class Account { public void setDelete(Boolean delete) { isDelete = delete; } + } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java index d33ffc95..28c1099c 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.annotation.Column; @@ -6,7 +22,7 @@ import com.mybatisflex.annotation.Table; import java.util.Date; -@Table(value = "tb_a01",schema = "flex") +@Table(value = "tb_a01", schema = "flex") public class Account01 { @Id @@ -81,4 +97,5 @@ public class Account01 { public void setDelete(Boolean delete) { isDelete = delete; } + } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java index 817b1862..6add1ca0 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.core.dialect.IDialect; @@ -25,8 +41,8 @@ public class AccountSqlTester { @Test public void testSelectSql() { QueryWrapper query = new QueryWrapper() - .select() - .from(ACCOUNT); + .select() + .from(ACCOUNT); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(query); @@ -36,8 +52,8 @@ public class AccountSqlTester { @Test public void testSelectWithSchemaSql() { QueryWrapper query = new QueryWrapper() - .select() - .from(ACCOUNT01); + .select() + .from(ACCOUNT01); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(query); @@ -47,10 +63,10 @@ public class AccountSqlTester { @Test public void testSelectWithSchemaSql01() { QueryWrapper query = new QueryWrapper() - .select() - .from(ACCOUNT01).leftJoin(ACCOUNT).on(ACCOUNT01.ID.eq(ACCOUNT.ID)) - .where(ACCOUNT01.ID.ge(100)) - .and(ACCOUNT.SEX.eq(1)); + .select() + .from(ACCOUNT01).leftJoin(ACCOUNT).on(ACCOUNT01.ID.eq(ACCOUNT.ID)) + .where(ACCOUNT01.ID.ge(100)) + .and(ACCOUNT.SEX.eq(1)); TableManager.setDynamicTableProcessor(new DynamicTableProcessor() { @Override @@ -67,10 +83,10 @@ public class AccountSqlTester { @Test public void testSelectWithSchemaSql02() { QueryWrapper query = new QueryWrapper() - .select() - .from(ACCOUNT01).as("a1").leftJoin(ACCOUNT).on(ACCOUNT01.ID.eq(ACCOUNT.ID)) - .where(ACCOUNT01.ID.ge(100)) - .and(ACCOUNT.SEX.eq(1)); + .select() + .from(ACCOUNT01).as("a1").leftJoin(ACCOUNT).on(ACCOUNT01.ID.eq(ACCOUNT.ID)) + .where(ACCOUNT01.ID.ge(100)) + .and(ACCOUNT.SEX.eq(1)); TableManager.setDynamicTableProcessor(original -> original + "_01"); TableManager.setDynamicTableProcessor(original -> original + "_01"); @@ -82,8 +98,8 @@ public class AccountSqlTester { @Test public void testSelectColumnsSql() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID, ACCOUNT.USER_NAME) - .from(ACCOUNT); + .select(ACCOUNT.ID, ACCOUNT.USER_NAME) + .from(ACCOUNT); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(query); @@ -93,10 +109,10 @@ public class AccountSqlTester { @Test public void testSelect1ColumnsSql() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID, ACCOUNT.USER_NAME, - ARTICLE.ID.as("articleId"), ARTICLE.TITLE) - .from(ACCOUNT.as("a"), ARTICLE.as("b")) - .where(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID)); + .select(ACCOUNT.ID, ACCOUNT.USER_NAME, + ARTICLE.ID.as("articleId"), ARTICLE.TITLE) + .from(ACCOUNT.as("a"), ARTICLE.as("b")) + .where(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID)); IDialect dialect = new CommonsDialectImpl(KeywordWrap.NONE, LimitOffsetProcessor.MYSQL); String sql = dialect.forSelectByQuery(query); @@ -106,8 +122,8 @@ public class AccountSqlTester { @Test public void testSelectColumnsAndFunctionsSql() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID, ACCOUNT.USER_NAME, max(ACCOUNT.BIRTHDAY), avg(ACCOUNT.SEX).as("sex_avg")) - .from(ACCOUNT); + .select(ACCOUNT.ID, ACCOUNT.USER_NAME, max(ACCOUNT.BIRTHDAY), avg(ACCOUNT.SEX).as("sex_avg")) + .from(ACCOUNT); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(query); @@ -118,8 +134,8 @@ public class AccountSqlTester { @Test public void testSelectAllColumnsSql() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ALL_COLUMNS) - .from(ACCOUNT); + .select(ACCOUNT.ALL_COLUMNS) + .from(ACCOUNT); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(query); @@ -130,11 +146,11 @@ public class AccountSqlTester { @Test public void testUnionSql() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID) - .from(ACCOUNT) - .orderBy(ACCOUNT.ID.desc()) - .union(select(ARTICLE.ID).from(ARTICLE)) - .unionAll(select(ARTICLE.ID).from(ARTICLE)); + .select(ACCOUNT.ID) + .from(ACCOUNT) + .orderBy(ACCOUNT.ID.desc()) + .union(select(ARTICLE.ID).from(ARTICLE)) + .unionAll(select(ARTICLE.ID).from(ARTICLE)); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(query); @@ -145,10 +161,10 @@ public class AccountSqlTester { @Test public void testWhereSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .where(ACCOUNT.ID.ge(100)) - .and(ACCOUNT.USER_NAME.like("michael")); + .select() + .from(ACCOUNT) + .where(ACCOUNT.ID.ge(100)) + .and(ACCOUNT.USER_NAME.like("michael")); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -158,10 +174,10 @@ public class AccountSqlTester { @Test public void testWhere2Sql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(column("A.*"), column("b.x")) - .from(ACCOUNT) - .where(ACCOUNT.ID.ge(100)) - .and(column("aaa").in("michael", "aaa")); + .select(column("A.*"), column("b.x")) + .from(ACCOUNT) + .where(ACCOUNT.ID.ge(100)) + .and(column("aaa").in("michael", "aaa")); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -173,10 +189,10 @@ public class AccountSqlTester { public void testWhereCond1Sql() { boolean flag = false; QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .where(ACCOUNT.ID.ge(100).when(flag)) - .and(ACCOUNT.USER_NAME.like("michael")); + .select() + .from(ACCOUNT) + .where(ACCOUNT.ID.ge(100).when(flag)) + .and(ACCOUNT.USER_NAME.like("michael")); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -191,10 +207,10 @@ public class AccountSqlTester { public void testWhereCond2Sql() { boolean flag = false; QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .where(flag ? ACCOUNT.ID.ge(100) : noCondition()) - .and(ACCOUNT.USER_NAME.like("michael")); + .select() + .from(ACCOUNT) + .where(flag ? ACCOUNT.ID.ge(100) : noCondition()) + .and(ACCOUNT.USER_NAME.like("michael")); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -208,14 +224,14 @@ public class AccountSqlTester { @Test public void testWhereExistSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .where(ACCOUNT.ID.ge(100)) - .and( - exists( - selectOne().from(ARTICLE).as("a").where(ARTICLE.ID.ge(100)) - ) - ); + .select() + .from(ACCOUNT) + .where(ACCOUNT.ID.ge(100)) + .and( + exists( + selectOne().from(ARTICLE).as("a").where(ARTICLE.ID.ge(100)) + ) + ); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -226,11 +242,11 @@ public class AccountSqlTester { @Test public void testWhereAndOrSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .where(ACCOUNT.ID.ge(100)) - .and(ACCOUNT.SEX.eq(1).or(ACCOUNT.SEX.eq(2))) - .or(ACCOUNT.AGE.in(18, 19, 20).or(ACCOUNT.USER_NAME.like("michael"))); + .select() + .from(ACCOUNT) + .where(ACCOUNT.ID.ge(100)) + .and(ACCOUNT.SEX.eq(1).or(ACCOUNT.SEX.eq(2))) + .or(ACCOUNT.AGE.in(18, 19, 20).or(ACCOUNT.USER_NAME.like("michael"))); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -240,11 +256,11 @@ public class AccountSqlTester { @Test public void testWhereSelectSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .where(ACCOUNT.ID.ge( - select(ARTICLE.ACCOUNT_ID).from(ARTICLE).where(ARTICLE.ID.ge(100)) - )); + .select() + .from(ACCOUNT) + .where(ACCOUNT.ID.ge( + select(ARTICLE.ACCOUNT_ID).from(ARTICLE).where(ARTICLE.ID.ge(100)) + )); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -254,9 +270,9 @@ public class AccountSqlTester { @Test public void testGroupSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .groupBy(ACCOUNT.USER_NAME); + .select() + .from(ACCOUNT) + .groupBy(ACCOUNT.USER_NAME); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -268,19 +284,19 @@ public class AccountSqlTester { @Test public void testGroup_I7EAY9() { QueryWrapper query = QueryWrapper.create() - .from(ACCOUNT).as("a") - .from(ACCOUNT01).as("b") - .groupBy(year(ACCOUNT.BIRTHDAY)); + .from(ACCOUNT).as("a") + .from(ACCOUNT01).as("b") + .groupBy(year(ACCOUNT.BIRTHDAY)); System.out.println(query.toSQL()); } @Test public void testHavingSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .groupBy(ACCOUNT.USER_NAME) - .having(ACCOUNT.AGE.between(18, 25)); + .select() + .from(ACCOUNT) + .groupBy(ACCOUNT.USER_NAME) + .having(ACCOUNT.AGE.between(18, 25)); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -290,10 +306,10 @@ public class AccountSqlTester { @Test public void testJoinSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .leftJoin(ARTICLE).on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID)) - .where(ACCOUNT.AGE.ge(10)); + .select() + .from(ACCOUNT) + .leftJoin(ARTICLE).on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID)) + .where(ACCOUNT.AGE.ge(10)); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -303,12 +319,12 @@ public class AccountSqlTester { @Test public void testJoin2Sql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .leftJoin(ARTICLE).on( - ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID).and(ACCOUNT.AGE.eq(18)) - ) - .where(ACCOUNT.AGE.ge(10)); + .select() + .from(ACCOUNT) + .leftJoin(ARTICLE).on( + ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID).and(ACCOUNT.AGE.eq(18)) + ) + .where(ACCOUNT.AGE.ge(10)); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -318,14 +334,14 @@ public class AccountSqlTester { @Test public void testJoin3Sql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .leftJoin( - select().from(ARTICLE).where(ARTICLE.ID.ge(100)) - ).as("a").on( - ACCOUNT.ID.eq(raw("a.id")) - ) - .where(ACCOUNT.AGE.ge(10)); + .select() + .from(ACCOUNT) + .leftJoin( + select().from(ARTICLE).where(ARTICLE.ID.ge(100)) + ).as("a").on( + ACCOUNT.ID.eq(raw("a.id")) + ) + .where(ACCOUNT.AGE.ge(10)); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -333,15 +349,12 @@ public class AccountSqlTester { } - - - @Test public void testOrderBySql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .orderBy(ACCOUNT.AGE.asc(), ACCOUNT.USER_NAME.desc().nullsLast()); + .select() + .from(ACCOUNT) + .orderBy(ACCOUNT.AGE.asc(), ACCOUNT.USER_NAME.desc().nullsLast()); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(queryWrapper); @@ -361,10 +374,10 @@ public class AccountSqlTester { IDialect dialect = new CommonsDialectImpl(); QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .and(ACCOUNT.USER_NAME.like("michael")) - .forUpdate(); + .select() + .from(ACCOUNT) + .and(ACCOUNT.USER_NAME.like("michael")) + .forUpdate(); String sql = dialect.forSelectByQuery(queryWrapper); System.out.println(sql); @@ -375,12 +388,12 @@ public class AccountSqlTester { IDialect dialect = new CommonsDialectImpl(); QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ALL_COLUMNS, convert("NVARCHAR(30)", "GETDATE()", "126").as("result")) - .from(ACCOUNT) - .and(ACCOUNT.USER_NAME.like("michael")) - .and(convert("NVARCHAR(30)", "GETDATE()", "126").in( - select(ACCOUNT.ID).from(ACCOUNT).where(ACCOUNT.ID.ge(100))) - ); + .select(ACCOUNT.ALL_COLUMNS, convert("NVARCHAR(30)", "GETDATE()", "126").as("result")) + .from(ACCOUNT) + .and(ACCOUNT.USER_NAME.like("michael")) + .and(convert("NVARCHAR(30)", "GETDATE()", "126").in( + select(ACCOUNT.ID).from(ACCOUNT).where(ACCOUNT.ID.ge(100))) + ); String sql = dialect.forSelectByQuery(queryWrapper); System.out.println(sql); @@ -390,14 +403,14 @@ public class AccountSqlTester { @Test public void testCase1() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ALL_COLUMNS, - case_() - .when(ACCOUNT.ID.eq(100)).then(100) - .when(ACCOUNT.ID.ge(200)).then(200) - .else_(300) - .end().as("result")) - .from(ACCOUNT) - .and(ACCOUNT.USER_NAME.like("michael")); + .select(ACCOUNT.ALL_COLUMNS, + case_() + .when(ACCOUNT.ID.eq(100)).then(100) + .when(ACCOUNT.ID.ge(200)).then(200) + .else_(300) + .end().as("result")) + .from(ACCOUNT) + .and(ACCOUNT.USER_NAME.like("michael")); System.out.println(queryWrapper.toSQL()); } @@ -407,14 +420,14 @@ public class AccountSqlTester { IDialect dialect = new CommonsDialectImpl(); QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ALL_COLUMNS, - case_(ACCOUNT.ID) - .when(100).then(100) - .when(200).then(200) - .else_(300) - .end().as("result")) - .from(ACCOUNT) - .and(ACCOUNT.USER_NAME.like("michael")); + .select(ACCOUNT.ALL_COLUMNS, + case_(ACCOUNT.ID) + .when(100).then(100) + .when(200).then(200) + .else_(300) + .end().as("result")) + .from(ACCOUNT) + .and(ACCOUNT.USER_NAME.like("michael")); String sql = dialect.forSelectByQuery(queryWrapper); System.out.println(sql); @@ -426,14 +439,14 @@ public class AccountSqlTester { IDialect dialect = new CommonsDialectImpl(); QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ALL_COLUMNS, - case_(ACCOUNT.ID) - .when(100).then(100) - .when(200).then(200) - .else_(convert("varchar", "GETDATE()", "126")) - .end().as("result")) - .from(ACCOUNT) - .and(ACCOUNT.USER_NAME.like("michael")); + .select(ACCOUNT.ALL_COLUMNS, + case_(ACCOUNT.ID) + .when(100).then(100) + .when(200).then(200) + .else_(convert("varchar", "GETDATE()", "126")) + .end().as("result")) + .from(ACCOUNT) + .and(ACCOUNT.USER_NAME.like("michael")); String sql = dialect.forSelectByQuery(queryWrapper); System.out.println(sql); @@ -444,11 +457,11 @@ public class AccountSqlTester { public void testLimitOffset() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .orderBy(ACCOUNT.ID.desc()) - .limit(10) - .offset(20); + .select() + .from(ACCOUNT) + .orderBy(ACCOUNT.ID.desc()) + .limit(10) + .offset(20); IDialect dialect1 = new CommonsDialectImpl(); String sql1 = dialect1.buildSelectSql(queryWrapper); @@ -484,28 +497,28 @@ public class AccountSqlTester { @Test public void testSelectLimitSql() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(distinct(ARTICLE.ID)) - .select(ACCOUNT.ALL_COLUMNS) - .select(ARTICLE.ID.as("article_id")) - .select(max(ACCOUNT.SEX)) - .select(count(distinct(ARTICLE.ID))) - .from(ACCOUNT).as("a1") + .select(distinct(ARTICLE.ID)) + .select(ACCOUNT.ALL_COLUMNS) + .select(ARTICLE.ID.as("article_id")) + .select(max(ACCOUNT.SEX)) + .select(count(distinct(ARTICLE.ID))) + .from(ACCOUNT).as("a1") // .leftJoin(newWrapper().select().from(ARTICLE).where(ARTICLE.ID.ge(100))).as("aaa") - .leftJoin(ARTICLE).as("b1") - .on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) - .where(ACCOUNT.ID.ge(select(ARTICLE.ID).from(ARTICLE).as("cc").where(ARTICLE.ID.eq(111)))) - .and((true ? noCondition() : ARTICLE.ID.ge(22211)).and(ACCOUNT.ID.eq(10011)).when(false)) - .and(ACCOUNT.USER_NAME.like("michael")) - .and(ARTICLE.ID.in(select(ARTICLE.ID).from("aaa"))) - .and( - notExists( - selectOne().from("aaa").where(ARTICLE.ID.ge(333)) - ) + .leftJoin(ARTICLE).as("b1") + .on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) + .where(ACCOUNT.ID.ge(select(ARTICLE.ID).from(ARTICLE).as("cc").where(ARTICLE.ID.eq(111)))) + .and((true ? noCondition() : ARTICLE.ID.ge(22211)).and(ACCOUNT.ID.eq(10011)).when(false)) + .and(ACCOUNT.USER_NAME.like("michael")) + .and(ARTICLE.ID.in(select(ARTICLE.ID).from("aaa"))) + .and( + notExists( + selectOne().from("aaa").where(ARTICLE.ID.ge(333)) ) - .groupBy(ACCOUNT.ID).having(ARTICLE.ID.ge(0)) + ) + .groupBy(ACCOUNT.ID).having(ARTICLE.ID.ge(0)) // .and("bbb.id > ?",100) - .orderBy(ACCOUNT.ID.desc()) - .limit(10, 10); + .orderBy(ACCOUNT.ID.desc()) + .limit(10, 10); System.out.println(queryWrapper.toSQL()); diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Article.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Article.java index 9262d8da..e7801a54 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Article.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Article.java @@ -1,9 +1,25 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Id; -import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; import java.util.Date; @@ -116,4 +132,5 @@ public class Article { public void setAccount(Account account) { this.account = account; } + } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/ArticleSqlTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/ArticleSqlTester.java index e6d84a4c..477761a7 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/ArticleSqlTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/ArticleSqlTester.java @@ -1,7 +1,23 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; -import com.mybatisflex.core.dialect.impl.CommonsDialectImpl; import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.dialect.impl.CommonsDialectImpl; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.table.TableInfo; import com.mybatisflex.core.table.TableInfoFactory; @@ -17,8 +33,8 @@ public class ArticleSqlTester { @Test public void testSelectSql() { QueryWrapper query = new QueryWrapper() - .select() - .from(ARTICLE); + .select() + .from(ARTICLE); IDialect dialect = new CommonsDialectImpl(); String sql = dialect.forSelectByQuery(query); @@ -108,7 +124,7 @@ public class ArticleSqlTester { article.setVersion(1L); QueryWrapper queryWrapper = new QueryWrapper() - .where(ARTICLE.ID.ge(100)); + .where(ARTICLE.ID.ge(100)); IDialect dialect = new CommonsDialectImpl(); TableInfo tableInfo = TableInfoFactory.ofEntityClass(Article.class); diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/DbTypeUtilTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/DbTypeUtilTest.java index 36048f51..7ae940ca 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/DbTypeUtilTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/DbTypeUtilTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.core.dialect.DbType; @@ -7,9 +23,10 @@ import org.junit.Test; public class DbTypeUtilTest { @Test - public void testParseUrl(){ + public void testParseUrl() { String url01 = "jdbc:sqlserver://127.0.0.1"; DbType dbType01 = DbTypeUtil.parseDbType(url01); System.out.println(dbType01); } + } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/FunctionSqlTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/FunctionSqlTest.java index dc087f22..790fed6c 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/FunctionSqlTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/FunctionSqlTest.java @@ -33,23 +33,23 @@ public class FunctionSqlTest { @Test public void test() { String sql = QueryWrapper.create() - .select(new FunctionQueryColumn("NOW").as("n1")) - .select(new FunctionQueryColumn("NOW", new StringQueryColumn("")).as("n2")) - .select(new FunctionQueryColumn("CONCAT", ACCOUNT.USER_NAME, ACCOUNT.AGE).as("c1")) - .from(ACCOUNT) - .toSQL(); + .select(new FunctionQueryColumn("NOW").as("n1")) + .select(new FunctionQueryColumn("NOW", new StringQueryColumn("")).as("n2")) + .select(new FunctionQueryColumn("CONCAT", ACCOUNT.USER_NAME, ACCOUNT.AGE).as("c1")) + .from(ACCOUNT) + .toSQL(); System.out.println(sql); } @Test public void test02() { String sql = QueryWrapper.create() - .select(concatWs(string("abc"), ACCOUNT.USER_NAME, ACCOUNT.BIRTHDAY)) - .select(abs(number(-3))) - .from(ACCOUNT) - .where(not(ACCOUNT.ID.eq(1))) - .toSQL(); + .select(concatWs(string("abc"), ACCOUNT.USER_NAME, ACCOUNT.BIRTHDAY)) + .select(abs(number(-3))) + .from(ACCOUNT) + .where(not(ACCOUNT.ID.eq(1))) + .toSQL(); System.out.println(sql); } -} \ No newline at end of file +} diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java index 27f2783d..7d342edf 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java @@ -31,37 +31,37 @@ public class IfFunctionTest { @Test public void test01() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(if_(ACCOUNT.AGE.ge(6), ACCOUNT.IS_NORMAL, ACCOUNT.IS_DELETE).as("type")) - .from(ACCOUNT) - .where(ACCOUNT.ID.eq(1)); + .select(if_(ACCOUNT.AGE.ge(6), ACCOUNT.IS_NORMAL, ACCOUNT.IS_DELETE).as("type")) + .from(ACCOUNT) + .where(ACCOUNT.ID.eq(1)); System.out.println(queryWrapper.toSQL()); } @Test public void test02() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(if_(ACCOUNT.AGE.ge(18), string("成年人"), - if_(ACCOUNT.AGE.le(8), string("未上学"), string("已上学"))).as("type")) - .from(ACCOUNT) - .where(ACCOUNT.ID.eq(1)); + .select(if_(ACCOUNT.AGE.ge(18), string("成年人"), + if_(ACCOUNT.AGE.le(8), string("未上学"), string("已上学"))).as("type")) + .from(ACCOUNT) + .where(ACCOUNT.ID.eq(1)); System.out.println(queryWrapper.toSQL()); } @Test public void test03() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(ifNull(ACCOUNT.ID, number(0))) - .from(ACCOUNT) - .where(ACCOUNT.ID.eq(1)); + .select(ifNull(ACCOUNT.ID, number(0))) + .from(ACCOUNT) + .where(ACCOUNT.ID.eq(1)); System.out.println(queryWrapper.toSQL()); } @Test public void test04() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(ifNull(null_(), number(0))) - .from(ACCOUNT); + .select(ifNull(null_(), number(0))) + .from(ACCOUNT); System.out.println(queryWrapper.toSQL()); } -} \ No newline at end of file +} diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/OracleDialectTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/OracleDialectTester.java index e875716e..ba55a480 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/OracleDialectTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/OracleDialectTester.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.core.dialect.IDialect; @@ -18,8 +34,8 @@ public class OracleDialectTester { @Test public void testSelectSql() { QueryWrapper query = new QueryWrapper() - .select() - .from(ACCOUNT); + .select() + .from(ACCOUNT); IDialect dialect = new OracleDialect(); String sql = dialect.forSelectByQuery(query); @@ -49,7 +65,7 @@ public class OracleDialectTester { IDialect dialect = new OracleDialect(); - String sql = dialect.forInsertEntityBatch(TableInfoFactory.ofEntityClass(Account.class),accounts); + String sql = dialect.forInsertEntityBatch(TableInfoFactory.ofEntityClass(Account.class), accounts); System.out.println(sql); } @@ -58,26 +74,26 @@ public class OracleDialectTester { public void testInsertRowBatchSql() { List accounts = new ArrayList<>(); Row account1 = new Row(); - account1.set("username","michael1"); - account1.set("age",18); - account1.set("sex",1); + account1.set("username", "michael1"); + account1.set("age", 18); + account1.set("sex", 1); accounts.add(account1); Row account2 = new Row(); - account2.set("username","michael2"); - account2.set("age",18); - account2.set("sex",1); + account2.set("username", "michael2"); + account2.set("age", 18); + account2.set("sex", 1); accounts.add(account2); Row account3 = new Row(); - account3.set("username","michael3"); - account3.set("age",18); - account3.set("sex",1); + account3.set("username", "michael3"); + account3.set("age", 18); + account3.set("sex", 1); accounts.add(account3); IDialect dialect = new OracleDialect(); - String sql = dialect.forInsertBatchWithFirstRowColumns(null,"tb_account",accounts); + String sql = dialect.forInsertBatchWithFirstRowColumns(null, "tb_account", accounts); System.out.println(sql); } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/SqlServer2005DialectTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/SqlServer2005DialectTester.java index 2c2ee75e..4aeaa2e1 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/SqlServer2005DialectTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/SqlServer2005DialectTester.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.core.dialect.IDialect; @@ -15,14 +31,14 @@ public class SqlServer2005DialectTester { @Test public void testSelectSql() { QueryWrapper query = new QueryWrapper() - .select() - .from(ACCOUNT) - .where(ACCOUNT.ID.in("100","200")) + .select() + .from(ACCOUNT) + .where(ACCOUNT.ID.in("100", "200")) .and(ACCOUNT.SEX.eq(1)) .orderBy(ACCOUNT.ID.desc()) - .limit(10,10); + .limit(10, 10); - IDialect dialect = new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS,LimitOffsetProcessor.SQLSERVER_2005); + IDialect dialect = new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.SQLSERVER_2005); String sql = dialect.forSelectByQuery(query); System.out.println(sql); } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java index 03211599..1c0e0fb3 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/StringUtilTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.core.util.StringUtil; @@ -14,4 +30,5 @@ public class StringUtilTest { String underline = StringUtil.camelToUnderline(underlineToCamel); System.out.println(underline); } + } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/WithSQLTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/WithSQLTester.java index c264506c..d5e725ac 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/WithSQLTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/WithSQLTester.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.coretest; import com.mybatisflex.core.query.QueryWrapper; @@ -16,12 +32,12 @@ public class WithSQLTester { @Test public void testWithSql1() { QueryWrapper query = new QueryWrapper() - .with("CTE").asSelect( - select().from(ARTICLE).where(ARTICLE.ID.ge(100)) - ) - .select() - .from(ACCOUNT) - .where(ACCOUNT.SEX.eq(1)); + .with("CTE").asSelect( + select().from(ARTICLE).where(ARTICLE.ID.ge(100)) + ) + .select() + .from(ACCOUNT) + .where(ACCOUNT.SEX.eq(1)); System.out.println(query.toSQL()); } @@ -30,11 +46,11 @@ public class WithSQLTester { @Test public void testWithSql2() { QueryWrapper query = new QueryWrapper() - .withRecursive("CTE").asSelect( - select().from(ARTICLE).where(ARTICLE.ID.ge(100)) - ) - .from(ACCOUNT) - .where(ACCOUNT.SEX.eq(1)); + .withRecursive("CTE").asSelect( + select().from(ARTICLE).where(ARTICLE.ID.ge(100)) + ) + .from(ACCOUNT) + .where(ACCOUNT.SEX.eq(1)); System.out.println(query.toSQL()); } @@ -42,12 +58,12 @@ public class WithSQLTester { @Test public void testWithSql3() { QueryWrapper query = new QueryWrapper() - .withRecursive("CTE", "id", "value").asSelect( - QueryWrapper.create().from(ARTICLE).where(ARTICLE.ID.ge(100)) - ) - .select() - .from(ACCOUNT) - .where(ACCOUNT.SEX.eq(1)); + .withRecursive("CTE", "id", "value").asSelect( + QueryWrapper.create().from(ARTICLE).where(ARTICLE.ID.ge(100)) + ) + .select() + .from(ACCOUNT) + .where(ACCOUNT.SEX.eq(1)); System.out.println(query.toSQL()); } @@ -56,15 +72,15 @@ public class WithSQLTester { @Test public void testWithSql4() { QueryWrapper query = new QueryWrapper() - .with("CTE").asSelect( - select().from(ARTICLE).where(ARTICLE.ID.ge(100)) - ) - .with("xxx").asSelect( - select().from(ARTICLE).where(ARTICLE.ID.ge(200)) - ) - .select() - .from(ACCOUNT) - .where(ACCOUNT.SEX.eq(1)); + .with("CTE").asSelect( + select().from(ARTICLE).where(ARTICLE.ID.ge(100)) + ) + .with("xxx").asSelect( + select().from(ARTICLE).where(ARTICLE.ID.ge(200)) + ) + .select() + .from(ACCOUNT) + .where(ACCOUNT.SEX.eq(1)); System.out.println(query.toSQL()); } @@ -72,18 +88,18 @@ public class WithSQLTester { @Test public void testWithSql5() { QueryWrapper query = new QueryWrapper() - .withRecursive("CTE").asSelect( - select().from(ARTICLE).where(ARTICLE.ID.ge(100)) + .withRecursive("CTE").asSelect( + select().from(ARTICLE).where(ARTICLE.ID.ge(100)) + ) + .with("xxx", "id", "name").asValues( + Arrays.asList("a", "b"), + union( + select().from(ARTICLE).where(ARTICLE.ID.ge(200)) ) - .with("xxx", "id", "name").asValues( - Arrays.asList("a", "b"), - union( - select().from(ARTICLE).where(ARTICLE.ID.ge(200)) - ) - ) - .from(ACCOUNT) - .where(ACCOUNT.SEX.eq(1)); + ) + .from(ACCOUNT) + .where(ACCOUNT.SEX.eq(1)); System.out.println(query.toSQL()); } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/query/ArithmeticQueryColumnTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/query/ArithmeticQueryColumnTest.java index 977bcdd7..f84439d3 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/query/ArithmeticQueryColumnTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/query/ArithmeticQueryColumnTest.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.coretest.query; @@ -26,7 +26,7 @@ import static com.mybatisflex.coretest.table.AccountTableDef.ACCOUNT; public class ArithmeticQueryColumnTest { - private static String toSql(QueryWrapper queryWrapper){ + private static String toSql(QueryWrapper queryWrapper) { IDialect dialect = new CommonsDialectImpl(); return dialect.forSelectByQuery(queryWrapper); } @@ -35,114 +35,112 @@ public class ArithmeticQueryColumnTest { @Test public void testAdd() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.add(100).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.add(100).as("x100")) + .from(ACCOUNT); String sql = query.toSQL(); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` + 100) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` + 100) AS `x100` FROM `tb_account`"); } @Test public void testAdd1() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.add(100).add(200).add(300).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.add(100).add(200).add(300).as("x100")) + .from(ACCOUNT); String sql = query.toSQL(); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` + 100 + 200 + 300) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` + 100 + 200 + 300) AS `x100` FROM `tb_account`"); } @Test public void testAdd2() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.add(ACCOUNT.AGE).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.add(ACCOUNT.AGE).as("x100")) + .from(ACCOUNT); String sql = toSql(query); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` + `age`) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` + `age`) AS `x100` FROM `tb_account`"); } @Test public void testAdd3() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.add(ACCOUNT.AGE.add(100)).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.add(ACCOUNT.AGE.add(100)).as("x100")) + .from(ACCOUNT); String sql = query.toSQL(); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` + (`age` + 100)) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` + (`age` + 100)) AS `x100` FROM `tb_account`"); } @Test public void testAdd4() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.add(ACCOUNT.ID.add(100)).multiply(100).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.add(ACCOUNT.ID.add(100)).multiply(100).as("x100")) + .from(ACCOUNT); String sql = toSql(query); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` + (`id` + 100) * 100) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` + (`id` + 100) * 100) AS `x100` FROM `tb_account`"); } @Test public void testAdd5() { QueryWrapper query = new QueryWrapper() - .select(sum(ACCOUNT.ID.multiply(ACCOUNT.AGE)).as("total_x")) - .from(ACCOUNT); + .select(sum(ACCOUNT.ID.multiply(ACCOUNT.AGE)).as("total_x")) + .from(ACCOUNT); String sql = toSql(query); System.out.println(sql); - Assert.assertEquals(sql,"SELECT SUM(`id` * `age`) AS `total_x` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT SUM(`id` * `age`) AS `total_x` FROM `tb_account`"); } @Test public void testSubtract() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.subtract(100).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.subtract(100).as("x100")) + .from(ACCOUNT); String sql = toSql(query); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` - 100) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` - 100) AS `x100` FROM `tb_account`"); } @Test public void testMultiply() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.multiply(100).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.multiply(100).as("x100")) + .from(ACCOUNT); String sql = toSql(query); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` * 100) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` * 100) AS `x100` FROM `tb_account`"); } @Test public void testDivide() { QueryWrapper query = new QueryWrapper() - .select(ACCOUNT.ID.divide(100).as("x100")) - .from(ACCOUNT); + .select(ACCOUNT.ID.divide(100).as("x100")) + .from(ACCOUNT); String sql = toSql(query); System.out.println(sql); - Assert.assertEquals(sql,"SELECT (`id` / 100) AS `x100` FROM `tb_account`"); + Assert.assertEquals(sql, "SELECT (`id` / 100) AS `x100` FROM `tb_account`"); } - - } diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java index 1ff89fba..814420bc 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java @@ -41,7 +41,7 @@ import java.util.Map; @EnableConfigurationProperties(MybatisFlexProperties.class) @ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class}) @AutoConfigureBefore(value = DataSourceAutoConfiguration.class - , name = "com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure") + , name = "com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure") public class MultiDataSourceAutoConfiguration { private final Map> dataSourceProperties; diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAdminAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAdminAutoConfiguration.java index 88fc907b..587d99e7 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAdminAutoConfiguration.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAdminAutoConfiguration.java @@ -59,11 +59,11 @@ public class MybatisFlexAdminAutoConfiguration implements InitializingBean { } MybatisFlexProperties.AdminConfig adminConfig = properties.getAdminConfig(); MessageReporter messageReporter = new HttpMessageReporter( - adminConfig.getEndpoint(), - adminConfig.getSecretKey(), - jsonFormatter + adminConfig.getEndpoint(), + adminConfig.getSecretKey(), + jsonFormatter ); AuditManager.setMessageReporter(messageReporter); } -} \ No newline at end of file +} diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAutoConfiguration.java index a4c94521..5f65428d 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAutoConfiguration.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexAutoConfiguration.java @@ -213,7 +213,7 @@ public class MybatisFlexAutoConfiguration implements InitializingBean { if (this.properties.isCheckConfigLocation() && StringUtils.hasText(this.properties.getConfigLocation())) { Resource resource = this.resourceLoader.getResource(this.properties.getConfigLocation()); Assert.state(resource.exists(), - "Cannot find config location: " + resource + " (please add config file or check your Mybatis configuration)"); + "Cannot find config location: " + resource + " (please add config file or check your Mybatis configuration)"); } } @@ -263,8 +263,8 @@ public class MybatisFlexAutoConfiguration implements InitializingBean { factory.setMapperLocations(mapperLocations); } Set factoryPropertyNames = Stream - .of(new BeanWrapperImpl(SqlSessionFactoryBean.class).getPropertyDescriptors()).map(PropertyDescriptor::getName) - .collect(Collectors.toSet()); + .of(new BeanWrapperImpl(SqlSessionFactoryBean.class).getPropertyDescriptors()).map(PropertyDescriptor::getName) + .collect(Collectors.toSet()); Class defaultLanguageDriver = this.properties.getDefaultScriptingLanguageDriver(); if (factoryPropertyNames.contains("scriptingLanguageDrivers") && !ObjectUtils.isEmpty(this.languageDrivers)) { // Need to mybatis-spring 2.0.2+ @@ -323,7 +323,7 @@ public class MybatisFlexAutoConfiguration implements InitializingBean { * similar to using Spring Data JPA repositories. */ public static class AutoConfiguredMapperScannerRegistrar - implements BeanFactoryAware, EnvironmentAware, ImportBeanDefinitionRegistrar { + implements BeanFactoryAware, EnvironmentAware, ImportBeanDefinitionRegistrar { private BeanFactory beanFactory; private Environment environment; @@ -349,7 +349,7 @@ public class MybatisFlexAutoConfiguration implements InitializingBean { builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(packages)); BeanWrapper beanWrapper = new BeanWrapperImpl(MapperScannerConfigurer.class); Set propertyNames = Stream.of(beanWrapper.getPropertyDescriptors()).map(PropertyDescriptor::getName) - .collect(Collectors.toSet()); + .collect(Collectors.toSet()); if (propertyNames.contains("lazyInitialization")) { // Need to mybatis-spring 2.0.2+ builder.addPropertyValue("lazyInitialization", "${mybatis.lazy-initialization:false}"); @@ -361,16 +361,16 @@ public class MybatisFlexAutoConfiguration implements InitializingBean { // for spring-native boolean injectSqlSession = environment.getProperty("mybatis.inject-sql-session-on-mapper-scan", Boolean.class, - Boolean.TRUE); + Boolean.TRUE); if (injectSqlSession && this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory; Optional sqlSessionTemplateBeanName = Optional - .ofNullable(getBeanNameForType(SqlSessionTemplate.class, listableBeanFactory)); + .ofNullable(getBeanNameForType(SqlSessionTemplate.class, listableBeanFactory)); Optional sqlSessionFactoryBeanName = Optional - .ofNullable(getBeanNameForType(SqlSessionFactory.class, listableBeanFactory)); + .ofNullable(getBeanNameForType(SqlSessionFactory.class, listableBeanFactory)); if (sqlSessionTemplateBeanName.isPresent() || !sqlSessionFactoryBeanName.isPresent()) { builder.addPropertyValue("sqlSessionTemplateBeanName", - sqlSessionTemplateBeanName.orElse("sqlSessionTemplate")); + sqlSessionTemplateBeanName.orElse("sqlSessionTemplate")); } else { builder.addPropertyValue("sqlSessionFactoryBeanName", sqlSessionFactoryBeanName.get()); } @@ -409,7 +409,7 @@ public class MybatisFlexAutoConfiguration implements InitializingBean { @Override public void afterPropertiesSet() { logger.debug( - "Not found configuration for registering mapper bean using @MapperScan, MapperFactoryBean and MapperScannerConfigurer."); + "Not found configuration for registering mapper bean using @MapperScan, MapperFactoryBean and MapperScannerConfigurer."); } } diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexDependsOnDatabaseInitializationDetector.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexDependsOnDatabaseInitializationDetector.java index 90981229..c527714c 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexDependsOnDatabaseInitializationDetector.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexDependsOnDatabaseInitializationDetector.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.spring.boot; @@ -26,7 +26,7 @@ import java.util.Set; * {@link DependsOnDatabaseInitializationDetector} for Mybatis-Flex. */ class MybatisFlexDependsOnDatabaseInitializationDetector - extends AbstractBeansOfTypeDependsOnDatabaseInitializationDetector { + extends AbstractBeansOfTypeDependsOnDatabaseInitializationDetector { @Override protected Set> getDependsOnDatabaseInitializationBeanTypes() { diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java index e2d02426..0f1a3882 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java @@ -247,7 +247,7 @@ public class MybatisFlexProperties { public Resource[] resolveMapperLocations() { return Stream.of(Optional.ofNullable(this.mapperLocations).orElse(new String[0])) - .flatMap(location -> Stream.of(getResources(location))).toArray(Resource[]::new); + .flatMap(location -> Stream.of(getResources(location))).toArray(Resource[]::new); } private Resource[] getResources(String location) { @@ -852,6 +852,7 @@ public class MybatisFlexProperties { public void setSecretKey(String secretKey) { this.secretKey = secretKey; } + } } diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java index 4453c82e..5526cba7 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java @@ -45,11 +45,13 @@ public class MybatisLanguageDriverAutoConfiguration { @ConditionalOnClass(FreeMarkerLanguageDriver.class) @ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig") public static class LegacyFreeMarkerConfiguration { + @Bean @ConditionalOnMissingBean FreeMarkerLanguageDriver freeMarkerLanguageDriver() { return new FreeMarkerLanguageDriver(); } + } /** @@ -58,6 +60,7 @@ public class MybatisLanguageDriverAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnClass({FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class}) public static class FreeMarkerConfiguration { + @Bean @ConditionalOnMissingBean FreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) { @@ -70,6 +73,7 @@ public class MybatisLanguageDriverAutoConfiguration { public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() { return FreeMarkerLanguageDriverConfig.newInstance(); } + } /** @@ -80,11 +84,13 @@ public class MybatisLanguageDriverAutoConfiguration { @ConditionalOnMissingClass("org.mybatis.scripting.velocity.VelocityLanguageDriverConfig") @SuppressWarnings("deprecation") public static class LegacyVelocityConfiguration { + @Bean @ConditionalOnMissingBean org.mybatis.scripting.velocity.Driver velocityLanguageDriver() { return new org.mybatis.scripting.velocity.Driver(); } + } /** @@ -93,6 +99,7 @@ public class MybatisLanguageDriverAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnClass({VelocityLanguageDriver.class, VelocityLanguageDriverConfig.class}) public static class VelocityConfiguration { + @Bean @ConditionalOnMissingBean VelocityLanguageDriver velocityLanguageDriver(VelocityLanguageDriverConfig config) { @@ -105,11 +112,13 @@ public class MybatisLanguageDriverAutoConfiguration { public VelocityLanguageDriverConfig velocityLanguageDriverConfig() { return VelocityLanguageDriverConfig.newInstance(); } + } @Configuration(proxyBeanMethods = false) @ConditionalOnClass(ThymeleafLanguageDriver.class) public static class ThymeleafConfiguration { + @Bean @ConditionalOnMissingBean ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) { diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java index a6d81953..db11b6e6 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java @@ -64,8 +64,8 @@ public class SpringBootVFS extends VFS { final String rootPath) { try { return rootPath + (rootPath.endsWith("/") ? "" : "/") + Normalizer - .normalize(URLDecoder.decode(resource.getURL().toString(), urlDecodingCharset.name()), Normalizer.Form.NFC) - .substring(baseUrlString.length()); + .normalize(URLDecoder.decode(resource.getURL().toString(), urlDecodingCharset.name()), Normalizer.Form.NFC) + .substring(baseUrlString.length()); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -82,7 +82,7 @@ public class SpringBootVFS extends VFS { String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/"); Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class"); return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path)) - .collect(Collectors.toList()); + .collect(Collectors.toList()); } } diff --git a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java index 35bae23c..92fc0117 100644 --- a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java +++ b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java @@ -80,7 +80,7 @@ import static org.springframework.util.StringUtils.tokenizeToStringArray; *

此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分。 */ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean - implements FactoryBean, InitializingBean, ApplicationListener { + implements FactoryBean, InitializingBean, ApplicationListener { private static final Logger LOGGER = LoggerFactory.getLogger(SqlSessionFactoryBean.class); @@ -294,7 +294,7 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean */ @Override public void setDefaultEnumTypeHandler( - @SuppressWarnings("rawtypes") Class defaultEnumTypeHandler) { + @SuppressWarnings("rawtypes") Class defaultEnumTypeHandler) { this.defaultEnumTypeHandler = defaultEnumTypeHandler; } @@ -474,7 +474,7 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean notNull(dataSource, "Property 'dataSource' is required"); notNull(sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required"); state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null), - "Property 'configuration' and 'configLocation' can not specified with together"); + "Property 'configuration' and 'configLocation' can not specified with together"); this.sqlSessionFactory = buildSqlSessionFactory(); } @@ -507,7 +507,7 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean targetConfiguration = xmlConfigBuilder.getConfiguration(); } else { LOGGER.debug( - () -> "Property 'configuration' or 'configLocation' not specified, using default Flex Configuration"); + () -> "Property 'configuration' or 'configLocation' not specified, using default Flex Configuration"); // targetConfiguration = new Configuration(); targetConfiguration = new FlexConfiguration(); Optional.ofNullable(this.configurationProperties).ifPresent(targetConfiguration::setVariables); @@ -519,8 +519,8 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean if (hasLength(this.typeAliasesPackage)) { scanClasses(this.typeAliasesPackage, this.typeAliasesSuperType).stream() - .filter(clazz -> !clazz.isAnonymousClass()).filter(clazz -> !clazz.isInterface()) - .filter(clazz -> !clazz.isMemberClass()).forEach(targetConfiguration.getTypeAliasRegistry()::registerAlias); + .filter(clazz -> !clazz.isAnonymousClass()).filter(clazz -> !clazz.isInterface()) + .filter(clazz -> !clazz.isMemberClass()).forEach(targetConfiguration.getTypeAliasRegistry()::registerAlias); } if (!isEmpty(this.typeAliases)) { @@ -539,8 +539,8 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean if (hasLength(this.typeHandlersPackage)) { scanClasses(this.typeHandlersPackage, TypeHandler.class).stream().filter(clazz -> !clazz.isAnonymousClass()) - .filter(clazz -> !clazz.isInterface()).filter(clazz -> !Modifier.isAbstract(clazz.getModifiers())) - .forEach(targetConfiguration.getTypeHandlerRegistry()::register); + .filter(clazz -> !clazz.isInterface()).filter(clazz -> !Modifier.isAbstract(clazz.getModifiers())) + .forEach(targetConfiguration.getTypeHandlerRegistry()::register); } if (!isEmpty(this.typeHandlers)) { @@ -559,7 +559,7 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean }); } Optional.ofNullable(this.defaultScriptingLanguageDriver) - .ifPresent(targetConfiguration::setDefaultScriptingLanguage); + .ifPresent(targetConfiguration::setDefaultScriptingLanguage); if (this.databaseIdProvider != null) {// fix #64 set databaseId before parse mapper xmls try { @@ -586,8 +586,8 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean // fixed https://gitee.com/mybatis-flex/mybatis-flex/issues/I70QWU targetConfiguration.setEnvironment(new Environment(this.environment, // this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory, - this.transactionFactory == null ? new JdbcTransactionFactory() : this.transactionFactory, - dataSource instanceof FlexDataSource ? dataSource : new FlexDataSource(FlexConsts.NAME, dataSource))); + this.transactionFactory == null ? new JdbcTransactionFactory() : this.transactionFactory, + dataSource instanceof FlexDataSource ? dataSource : new FlexDataSource(FlexConsts.NAME, dataSource))); // 需先构建 sqlSessionFactory,再去初始化 mapperLocations @@ -605,7 +605,7 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean } try { XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(), - targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments()); + targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments()); xmlMapperBuilder.parse(); } catch (Exception e) { throw new IOException("Failed to parse mapping resource: '" + mapperLocation + "'", e); @@ -665,10 +665,10 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean private Set> scanClasses(String packagePatterns, Class assignableType) throws IOException { Set> classes = new HashSet<>(); String[] packagePatternArray = tokenizeToStringArray(packagePatterns, - ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); + ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); for (String packagePattern : packagePatternArray) { Resource[] resources = RESOURCE_PATTERN_RESOLVER.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX - + ClassUtils.convertClassNameToResourcePath(packagePattern) + "/**/*.class"); + + ClassUtils.convertClassNameToResourcePath(packagePattern) + "/**/*.class"); for (Resource resource : resources) { try { ClassMetadata classMetadata = METADATA_READER_FACTORY.getMetadataReader(resource).getClassMetadata(); @@ -683,4 +683,5 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean } return classes; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexTransactionManager.java b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexTransactionManager.java index 944da5a6..797b4515 100644 --- a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexTransactionManager.java +++ b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexTransactionManager.java @@ -79,6 +79,7 @@ public class FlexTransactionManager extends AbstractPlatformTransactionManager { public TransactionObject(String prevXid) { this.prevXid = prevXid; } + } } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java index c473a3b0..6c1ec522 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java @@ -32,7 +32,7 @@ public class Account extends BaseEntity implements Serializable, AgeAware { private static final long serialVersionUID = 1L; -// @Id(keyType = KeyType.Generator,value = "uuid") + // @Id(keyType = KeyType.Generator,value = "uuid") @Id(keyType = KeyType.Auto) @ColumnAlias("account_id") private Long id; @@ -123,13 +123,14 @@ public class Account extends BaseEntity implements Serializable, AgeAware { @Override public String toString() { return "Account{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", birthday=" + birthday + - ", options=" + options + - ", isDelete=" + isDelete + - ", articles=" + articles + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", birthday=" + birthday + + ", options=" + options + + ", isDelete=" + isDelete + + ", articles=" + articles + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account05.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account05.java index c54993dd..c7acf71b 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account05.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account05.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.*; @@ -116,13 +132,14 @@ public class Account05 extends BaseEntity implements Serializable, AgeAware { @Override public String toString() { return "Account{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", birthday=" + birthday + - ", options=" + options + - ", isDelete=" + isDelete + - ", articles=" + articles + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", birthday=" + birthday + + ", options=" + options + + ", isDelete=" + isDelete + + ", articles=" + articles + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account1.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account1.java index 655f1361..a7343bba 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account1.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account1.java @@ -41,4 +41,5 @@ public class Account1 extends Account implements Serializable { public Long getId() { return id; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account3.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account3.java index b3cb9d22..4b5a9747 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account3.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account3.java @@ -31,4 +31,5 @@ public class Account3 extends Account2 implements Serializable { public Long getId() { return super.getId(); } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountDTO.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountDTO.java index 3756e50c..1505f680 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountDTO.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountDTO.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.Column; @@ -11,7 +27,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class AccountDTO { +public class AccountDTO { private Long id; @@ -92,13 +108,14 @@ public class AccountDTO { @Override public String toString() { return "AccountDTO{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", birthday=" + birthday + - ", options=" + options + - ", isDelete=" + isDelete + - ", articles=" + articles + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", birthday=" + birthday + + ", options=" + options + + ", isDelete=" + isDelete + + ", articles=" + articles + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountInsertWithArrayAttrTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountInsertWithArrayAttrTestStarter.java index c37158af..8e082ce4 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountInsertWithArrayAttrTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountInsertWithArrayAttrTestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -29,15 +29,15 @@ public class AccountInsertWithArrayAttrTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema05.sql") - .addScript("data05.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema05.sql") + .addScript("data05.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(Account05Mapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(Account05Mapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -55,9 +55,10 @@ public class AccountInsertWithArrayAttrTestStarter { Account05 account = new Account05(); account.setId(3L); account.setUserName("lisi"); - account.setDataScope(new Long[]{1L,2L}); + account.setDataScope(new Long[]{1L, 2L}); - accountMapper.insertWithPk(account,false); + accountMapper.insertWithPk(account, false); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountMapper.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountMapper.java index 1ea07b93..5a3b8ba6 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountMapper.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountMapper.java @@ -1,4 +1,21 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; public interface AccountMapper extends MyBaseMapper { + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountOnSetListener.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountOnSetListener.java index 2f440d7a..aa0ee156 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountOnSetListener.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountOnSetListener.java @@ -1,11 +1,29 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.SetListener; public class AccountOnSetListener implements SetListener { + @Override public Object onSet(Object entity, String property, Object value) { // System.out.println(">>>>>>> property: " + property +" value:" + value); return value; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java index e132db96..e1d29f1c 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -39,15 +39,15 @@ public class AccountTester { @BeforeClass public static void init() { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -65,8 +65,8 @@ public class AccountTester { public void testLambda() { QueryWrapper queryWrapper = QueryWrapper.create(); queryWrapper.where(Account::getId).ge(100) - .and(Account::getUserName).like("michael") - .or(Account::getUserName).like(null, If::notNull); + .and(Account::getUserName).like("michael") + .or(Account::getUserName).like(null, If::notNull); System.out.println(queryWrapper.toSQL()); } @@ -79,7 +79,6 @@ public class AccountTester { } - @Test public void testSelectAsToDTO() { List accountDTOS = accountMapper.selectListByQueryAs(QueryWrapper.create(), AccountDTO.class); @@ -87,18 +86,17 @@ public class AccountTester { } - @Test public void testUpdate() { List accounts = accountMapper.selectAll(); System.out.println(accounts); - Account account = UpdateEntity.of(Account.class,1); + Account account = UpdateEntity.of(Account.class, 1); account.setUserName("lisi"); UpdateWrapper.of(account) - .setRaw("age","age + 1"); + .setRaw("age", "age + 1"); accountMapper.update(account); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeAware.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeAware.java index 0fbbc019..f55197bb 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeAware.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeAware.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; /** @@ -11,4 +27,5 @@ public interface AgeAware { void setAge(int age); int getAge(); + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeHandleListener.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeHandleListener.java index 9a62df19..2cb2324e 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeHandleListener.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AgeHandleListener.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.InsertListener; @@ -25,4 +41,5 @@ public class AgeHandleListener implements InsertListener { public int order() { return 10; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Article.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Article.java index 2e77de9e..2a512686 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Article.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Article.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.Column; @@ -59,10 +75,11 @@ public class Article extends BaseAccount implements Serializable { @Override public String toString() { return "Article{" + - "id=" + id + - ", accountId=" + accountId + - ", title='" + title + '\'' + - ", content='" + content + '\'' + - '}'; + "id=" + id + + ", accountId=" + accountId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO.java index b6edca9b..4000f55f 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import java.util.Date; @@ -78,13 +94,14 @@ public class ArticleDTO { @Override public String toString() { return "ArticleDTO{" + - "id=" + id + - ", accountId=" + accountId + - ", title='" + title + '\'' + - ", content='" + content + '\'' + - ", authorName='" + authorName + '\'' + - ", authorAge=" + authorAge + - ", birthday=" + birthday + - '}'; + "id=" + id + + ", accountId=" + accountId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", authorName='" + authorName + '\'' + + ", authorAge=" + authorAge + + ", birthday=" + birthday + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO01.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO01.java index 4185a8ea..26ff63e4 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO01.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/ArticleDTO01.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; public class ArticleDTO01 { @@ -55,11 +71,12 @@ public class ArticleDTO01 { @Override public String toString() { return "ArticleDTO01{" + - "id=" + id + - ", accountId=" + accountId + - ", title='" + title + '\'' + - ", content='" + content + '\'' + - ", account=" + account + - '}'; + "id=" + id + + ", accountId=" + accountId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", account=" + account + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/BaseEntity.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/BaseEntity.java index 0ced2518..f1769776 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/BaseEntity.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/BaseEntity.java @@ -1,4 +1,21 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; public class BaseEntity { + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java index 71d24bf2..f72d49e6 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java @@ -1,10 +1,26 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.alibaba.druid.pool.DruidDataSource; import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.datasource.DataSourceDecipher; -import com.mybatisflex.core.datasource.DataSourceProperty; import com.mybatisflex.core.datasource.DataSourceManager; +import com.mybatisflex.core.datasource.DataSourceProperty; import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.RowUtil; @@ -33,9 +49,9 @@ public class DataSourceDecipherTester { }); MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(TenantAccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(TenantAccountMapper.class) + .start(); List rowList = Db.selectAll("tb_account"); RowUtil.printPretty(rowList); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTestStarter.java index da844803..27971d50 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DbTestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -28,20 +28,20 @@ public class DbTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") // .addScript("data.sql") - .build(); + .build(); MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .start(); + .setDataSource(dataSource) + .start(); - Row row1 = Db.selectOneById(null,"tb_account", "id", 1); + Row row1 = Db.selectOneById(null, "tb_account", "id", 1); RowUtil.printPretty(row1); //查询全部 - List rows = Db.selectAll(null,"tb_account"); + List rows = Db.selectAll(null, "tb_account"); RowUtil.printPretty(rows); @@ -53,7 +53,7 @@ public class DbTestStarter { row.set("user_name", "michael yang"); row.set("age", 18); row.set("birthday", new Date()); - Db.insert(null,"tb_account", row); + Db.insert(null, "tb_account", row); //查看刚刚插入数据的主键 id System.out.println(">>>>>>>>>id: " + row.get("id")); @@ -79,7 +79,7 @@ public class DbTestStarter { //再次查询全部数据 - rows = Db.selectAll(null,"tb_account"); + rows = Db.selectAll(null, "tb_account"); RowUtil.printPretty(rows); // for (Row row2 : rows) { @@ -99,7 +99,8 @@ public class DbTestStarter { // Db.insertBatch(null,"tb_account", rows, 100); //再次查询全部数据 - rows = Db.selectAll(null,"tb_account"); + rows = Db.selectAll(null, "tb_account"); RowUtil.printPretty(rows); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DocWordsCount.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DocWordsCount.java index fe526910..c01bfad5 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DocWordsCount.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DocWordsCount.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import java.io.*; @@ -14,7 +30,7 @@ public class DocWordsCount { } - private static void calculate(File dir){ + private static void calculate(File dir) { File[] files = dir.listFiles(pathname -> !"node_modules".equals(pathname.getName())); if (files != null) { for (File file : files) { @@ -62,4 +78,5 @@ public class DocWordsCount { } } } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java index 27aaf109..cdf99009 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.*; @@ -15,7 +31,7 @@ public class Entity04 extends BaseAccount implements Serializable { private static final long serialVersionUID = 1L; - @Id(keyType = KeyType.Generator,value = "uuid") + @Id(keyType = KeyType.Generator, value = "uuid") private String id; @ColumnMask(Masks.CHINESE_NAME) @@ -26,7 +42,7 @@ public class Entity04 extends BaseAccount implements Serializable { @NotBlank private Date birthday; - @Column(typeHandler = Fastjson2TypeHandler.class,isLarge = true) + @Column(typeHandler = Fastjson2TypeHandler.class, isLarge = true) private Map options; @Column(isLogicDelete = true) @@ -83,12 +99,13 @@ public class Entity04 extends BaseAccount implements Serializable { @Override public String toString() { return "Account{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", birthday=" + birthday + - ", options=" + options + - ", isDelete=" + isDelete + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", birthday=" + birthday + + ", options=" + options + + ", isDelete=" + isDelete + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04TestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04TestStarter.java index feac1b6a..218819db 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04TestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Entity04TestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -31,15 +31,15 @@ public class Entity04TestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema04.sql") - .addScript("data04.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema04.sql") + .addScript("data04.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(Entity04Mapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(Entity04Mapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -69,4 +69,5 @@ public class Entity04TestStarter { System.out.println(entity04s); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java index 50d2cbc8..79e2dec8 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -38,16 +38,16 @@ public class EntityTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .addMapper(MyAccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .addMapper(MyAccountMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -121,8 +121,8 @@ public class EntityTestStarter { QueryWrapper query1 = QueryWrapper.create(); query1.where(Account::getId).ge(100) - .and(Account::getUserName).like("michael") - .or(Account::getUserName).like(null,If::notNull); + .and(Account::getUserName).like("michael") + .or(Account::getUserName).like(null, If::notNull); System.out.println(query1.toSQL()); QueryWrapper query = QueryWrapper.create() @@ -131,19 +131,19 @@ public class EntityTestStarter { // , ACCOUNT.AGE.as(ArticleDTO::getAuthorAge) // , ACCOUNT.BIRTHDAY // ) - .from(Article.class) + .from(Article.class) // .leftJoin(Account.class).as("a").on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) - .leftJoin(Account.class).as("a").on(wrapper -> wrapper.where(Account::getId).eq(Article::getAccountId)) - .where(Account::getId).ge(100, If::notEmpty) - .and(wrapper -> { - wrapper.where(Account::getId).ge(100) - .or(Account::getAge).gt(200) - .and(Article::getAccountId).eq(200) - .or(wrapper1 -> { - wrapper1.where(Account::getId).like("a", If::notEmpty); - }) - ; - }); + .leftJoin(Account.class).as("a").on(wrapper -> wrapper.where(Account::getId).eq(Article::getAccountId)) + .where(Account::getId).ge(100, If::notEmpty) + .and(wrapper -> { + wrapper.where(Account::getId).ge(100) + .or(Account::getAge).gt(200) + .and(Article::getAccountId).eq(200) + .or(wrapper1 -> { + wrapper1.where(Account::getId).like("a", If::notEmpty); + }) + ; + }); System.out.println(query.toSQL()); // .and(query->query.and); // .andEq(Account::getId,100); @@ -164,10 +164,10 @@ public class EntityTestStarter { // // QueryWrapper asWrapper = QueryWrapper.create() - .select(ARTICLE.ALL_COLUMNS,ACCOUNT.ALL_COLUMNS) - .from(ARTICLE) - .leftJoin(ACCOUNT).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) - .where(ARTICLE.ID.ge(0).or(ACCOUNT.ID.ge(0))); + .select(ARTICLE.ALL_COLUMNS, ACCOUNT.ALL_COLUMNS) + .from(ARTICLE) + .leftJoin(ACCOUNT).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) + .where(ARTICLE.ID.ge(0).or(ACCOUNT.ID.ge(0))); RowUtil.printPretty(Db.selectListByQuery(asWrapper)); // @@ -361,4 +361,5 @@ public class EntityTestStarter { // System.out.println(selectOptionsAccount); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/InsertWithPkTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/InsertWithPkTestStarter.java index fb3a7078..f3e8a5ad 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/InsertWithPkTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/InsertWithPkTestStarter.java @@ -30,16 +30,16 @@ public class InsertWithPkTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .addMapper(MyAccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .addMapper(MyAccountMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JavaTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JavaTester.java index c52ca153..e81373a5 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JavaTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JavaTester.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; public class JavaTester { @@ -5,4 +21,5 @@ public class JavaTester { public static void main(String[] args) { } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTestStarter.java index 667ac684..07b25d4d 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -30,16 +30,16 @@ public class JoinTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .addMapper(MyAccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .addMapper(MyAccountMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -55,7 +55,7 @@ public class JoinTestStarter { // List accounts = accountMapper.selectListByQuery(QueryWrapper.create()); // System.out.println(accounts); - List accountDTOS = accountMapper.selectListByQueryAs(QueryWrapper.create(),AccountDTO.class); + List accountDTOS = accountMapper.selectListByQueryAs(QueryWrapper.create(), AccountDTO.class); System.out.println(accountDTOS); // @@ -66,4 +66,5 @@ public class JoinTestStarter { // Page paginate = accountMapper.paginateAs(Page.of(1, 10), QueryWrapper.create(), ArticleDTO01.class); // System.out.println(paginate); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTester.java index 7d0bd438..4af6ffde 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinTester.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -31,15 +31,15 @@ public class JoinTester { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -59,4 +59,5 @@ public class JoinTester { } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinWithDeleteColumnTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinWithDeleteColumnTestStarter.java index 23366109..29770156 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinWithDeleteColumnTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/JoinWithDeleteColumnTestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -39,17 +39,17 @@ public class JoinWithDeleteColumnTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .addMapper(MyAccountMapper.class) - .addMapper(ArticleMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .addMapper(MyAccountMapper.class) + .addMapper(ArticleMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -62,12 +62,12 @@ public class JoinWithDeleteColumnTestStarter { AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class); QueryWrapper query1 = QueryWrapper.create() - .select() - .from(ACCOUNT) - .leftJoin(ARTICLE).as("a").on( - ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID) - ) - .where(ACCOUNT.AGE.ge(10)); + .select() + .from(ACCOUNT) + .leftJoin(ARTICLE).as("a").on( + ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID) + ) + .where(ACCOUNT.AGE.ge(10)); List accountDTOS1 = accountMapper.selectListByQueryAs(query1, AccountDTO.class); System.out.println(accountDTOS1); @@ -75,17 +75,18 @@ public class JoinWithDeleteColumnTestStarter { System.out.println(">>>>>>>>>"); QueryWrapper query2 = QueryWrapper.create() - .select() - .from(ACCOUNT) - .leftJoin( - select().from(ARTICLE).where(ARTICLE.ID.ge(100)) - ).as("a").on( - ACCOUNT.ID.eq(raw("a.id")) - ) - .where(ACCOUNT.AGE.ge(10)); + .select() + .from(ACCOUNT) + .leftJoin( + select().from(ARTICLE).where(ARTICLE.ID.ge(100)) + ).as("a").on( + ACCOUNT.ID.eq(raw("a.id")) + ) + .where(ACCOUNT.AGE.ge(10)); List accountDTOS2 = accountMapper.selectListByQueryAs(query2, AccountDTO.class); System.out.println(accountDTOS2); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MapperProxyCacheTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MapperProxyCacheTestStarter.java index be2798af..f8045bbb 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MapperProxyCacheTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MapperProxyCacheTestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -31,18 +31,18 @@ public class MapperProxyCacheTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(MyBaseMapper.class) - .addMapper(ArticleMapper.class) - .addMapper(AccountMapper.class) - .addMapper(AccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(MyBaseMapper.class) + .addMapper(ArticleMapper.class) + .addMapper(AccountMapper.class) + .addMapper(AccountMapper.class) + .start(); //开启审计功能 @@ -62,9 +62,9 @@ public class MapperProxyCacheTestStarter { } - System.out.println(">>>>>>finished!!!"); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MaskManagerTest.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MaskManagerTest.java index 39cd6c57..4870cb62 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MaskManagerTest.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MaskManagerTest.java @@ -1,7 +1,22 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.core.MybatisFlexBootstrap; -import com.mybatisflex.core.mask.MaskManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @@ -12,16 +27,16 @@ public class MaskManagerTest { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .setName("db1") - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .setName("db1") + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .start(); //获取 mapper AccountMapper mapper = MybatisFlexBootstrap.getInstance().getMapper(AccountMapper.class); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java index 236b47db..1134226b 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -34,11 +34,11 @@ public class MultiDataSourceTester { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .setName("db1") - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .setName("db1") + .addScript("schema.sql") + .addScript("data.sql") + .build(); HikariDataSource dataSource2 = new HikariDataSource(); dataSource2.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/flex_test?characterEncoding=utf-8"); @@ -46,10 +46,10 @@ public class MultiDataSourceTester { dataSource2.setPassword("123456"); MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .addDataSource("ds2", dataSource2) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .addDataSource("ds2", dataSource2) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -61,7 +61,7 @@ public class MultiDataSourceTester { //默认查询 db1 System.out.println("\n------ds1"); - List rows1 = Db.selectAll(null,"tb_account"); + List rows1 = Db.selectAll(null, "tb_account"); RowUtil.printPretty(rows1); @@ -74,7 +74,7 @@ public class MultiDataSourceTester { // //查询数据源 ds2 System.out.println("\n------ds2"); DataSourceKey.use("ds2"); - List rows = Db.selectAll(null,"tb_account"); + List rows = Db.selectAll(null, "tb_account"); RowUtil.printPretty(rows); // // boolean success = Db.tx(() -> { @@ -90,4 +90,5 @@ public class MultiDataSourceTester { // System.out.println(accounts); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyAccountMapper.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyAccountMapper.java index 0d59e484..47e45db2 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyAccountMapper.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyAccountMapper.java @@ -1,4 +1,21 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; -public interface MyAccountMapper extends AccountMapper{ +public interface MyAccountMapper extends AccountMapper { + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyBaseMapper.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyBaseMapper.java index c3bbd859..b66fd269 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyBaseMapper.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MyBaseMapper.java @@ -1,6 +1,23 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.core.BaseMapper; public interface MyBaseMapper extends BaseMapper { + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/RowTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/RowTestStarter.java index 06a3f1f6..2f26371e 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/RowTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/RowTestStarter.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -36,15 +36,15 @@ public class RowTestStarter { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) + .setDataSource(dataSource) // .setLogImpl(StdOutImpl.class) - .start(); + .start(); AuditManager.setAuditEnable(true); AuditManager.setMessageCollector(new ConsoleMessageCollector()); @@ -115,4 +115,5 @@ public class RowTestStarter { } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/SexEnum.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/SexEnum.java index 91bb4986..cb7cc661 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/SexEnum.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/SexEnum.java @@ -1,11 +1,27 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.EnumValue; public enum SexEnum { - TYPE1(0,"女"), - TYPE2(1,"男"), - TYPE3(2,"未知"), + TYPE1(0, "女"), + TYPE2(1, "男"), + TYPE3(2, "未知"), ; diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantAccount.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantAccount.java index 3d8d6339..1c19ec49 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantAccount.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantAccount.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.*; @@ -6,7 +22,8 @@ import com.mybatisflex.core.mask.Masks; import java.util.Date; @Table("tb_account") -public class TenantAccount{ +public class TenantAccount { + @Id(keyType = KeyType.Auto) private Long id; @@ -63,11 +80,12 @@ public class TenantAccount{ @Override public String toString() { return "TenantAccount{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", birthday=" + birthday + - ", tenantId=" + tenantId + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", birthday=" + birthday + + ", tenantId=" + tenantId + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java index 1ce6fc6b..67b03cb8 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.core.MybatisFlexBootstrap; @@ -16,15 +32,15 @@ public class TenantManagerTester { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema03.sql") - .addScript("data03.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema03.sql") + .addScript("data03.sql") + .build(); MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(TenantAccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(TenantAccountMapper.class) + .start(); //输出日志 AuditManager.setAuditEnable(true); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantTester.java index e268e947..da4b5539 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantTester.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -36,15 +36,15 @@ public class TenantTester { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema03.sql") - .addScript("data03.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema03.sql") + .addScript("data03.sql") + .build(); MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(TenantAccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(TenantAccountMapper.class) + .start(); //输出日志 @@ -55,20 +55,20 @@ public class TenantTester { TenantManager.setTenantFactory(new TenantFactory() { @Override public Object[] getTenantIds() { - return new Object[]{1,2}; + return new Object[]{1, 2}; } }); TenantAccountMapper mapper = MybatisFlexBootstrap.getInstance().getMapper(TenantAccountMapper.class); mapper.selectListByQuery(QueryWrapper.create() - .select(TENANT_ACCOUNT.ALL_COLUMNS) - .from(TENANT_ACCOUNT.as("c"), ACCOUNT.as("b")) - .where(TENANT_ACCOUNT.ID.eq(ACCOUNT.ID)) - .and(TENANT_ACCOUNT.ID.eq(1)) - .unionAll(select(TENANT_ACCOUNT.ALL_COLUMNS).from(TENANT_ACCOUNT) - .where(TENANT_ACCOUNT.ID.eq(2)) - ) + .select(TENANT_ACCOUNT.ALL_COLUMNS) + .from(TENANT_ACCOUNT.as("c"), ACCOUNT.as("b")) + .where(TENANT_ACCOUNT.ID.eq(ACCOUNT.ID)) + .and(TENANT_ACCOUNT.ID.eq(1)) + .unionAll(select(TENANT_ACCOUNT.ALL_COLUMNS).from(TENANT_ACCOUNT) + .where(TENANT_ACCOUNT.ID.eq(2)) + ) ); // mapper.deleteBatchByIds(Arrays.asList(1, 2)); @@ -100,4 +100,5 @@ public class TenantTester { // //SELECT * FROM `tb_account` WHERE `id` >= 100 AND `tenant_id` = 1 LIMIT 10 // mapper.selectListByCondition(TENANT_ACCOUNT.ID.ge(100),10); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TypeEnum.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TypeEnum.java index d75b36c1..98b30b82 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TypeEnum.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TypeEnum.java @@ -1,11 +1,27 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.EnumValue; public enum TypeEnum { - TYPE1(1,"类型1"), - TYPE2(2,"类型2"), - TYPE3(3,"类型3"), + TYPE1(1, "类型1"), + TYPE2(2, "类型2"), + TYPE3(3, "类型3"), ; diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UpdateWrapperTest.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UpdateWrapperTest.java index 2f2faa9a..336844b8 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UpdateWrapperTest.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UpdateWrapperTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.core.MybatisFlexBootstrap; @@ -18,15 +34,15 @@ public class UpdateWrapperTest { public static void main(String[] args) { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -74,4 +90,5 @@ public class UpdateWrapperTest { List accounts4 = accountMapper.selectAll(); System.out.println(accounts4); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UserDto.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UserDto.java index 8a2ac1cb..6ab0835a 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UserDto.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/UserDto.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.annotation.Column; @@ -5,6 +21,7 @@ import com.mybatisflex.annotation.Table; @Table("sys_user") public class UserDto { + @Column private Long id; @@ -15,4 +32,5 @@ public class UserDto { public void setId(Long id) { this.id = id; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/WrapperSerializeTest.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/WrapperSerializeTest.java index bb1bde4e..6239a791 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/WrapperSerializeTest.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/WrapperSerializeTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.alibaba.fastjson2.JSON; @@ -12,10 +28,10 @@ public class WrapperSerializeTest { public static void main(String[] args) throws Exception { QueryWrapper wrapper = QueryWrapper.create() - .select().from(ACCOUNT) - .where(ACCOUNT.ID.eq("michael")) - .and(ACCOUNT.AGE.ge(18)) - .orderBy(ACCOUNT.ID.desc()); + .select().from(ACCOUNT) + .where(ACCOUNT.ID.eq("michael")) + .and(ACCOUNT.AGE.ge(18)) + .orderBy(ACCOUNT.ID.desc()); byFst(wrapper); @@ -23,7 +39,6 @@ public class WrapperSerializeTest { } - private static void byFst(QueryWrapper wrapper) { FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration(); byte[] bytes = fst.asByteArray(wrapper); @@ -40,4 +55,5 @@ public class WrapperSerializeTest { String s2 = JSON.toJSONString(newWrapper, JSONWriter.Feature.FieldBased, JSONWriter.Feature.WriteClassName, JSONWriter.Feature.ReferenceDetection); System.out.println(s2); } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Account.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Account.java index 7269a304..ff56b899 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Account.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Account.java @@ -16,7 +16,10 @@ package com.mybatisflex.test.relation.onetoone; -import com.mybatisflex.annotation.*; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.RelationManyToMany; +import com.mybatisflex.annotation.Table; import java.io.Serializable; import java.util.List; @@ -114,4 +117,5 @@ public class Account implements Serializable { ", roles=" + roles + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/AccountDTO.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/AccountDTO.java index c097953e..13644a27 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/AccountDTO.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/AccountDTO.java @@ -43,9 +43,9 @@ public class AccountDTO implements Serializable { // targetField = "id", joinTargetColumn = "role_id" // ) @RelationManyToMany( - joinTable = "tb_role_mapping", - joinSelfColumn = "account_id", - joinTargetColumn = "role_id" + joinTable = "tb_role_mapping", + joinSelfColumn = "account_id", + joinTargetColumn = "role_id" ) private List roles; @@ -101,12 +101,13 @@ public class AccountDTO implements Serializable { @Override public String toString() { return "AccountDTO{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", idCard=" + idCard + - ", books=" + books + - ", roles=" + roles + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", idCard=" + idCard + + ", books=" + books + + ", roles=" + roles + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Book.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Book.java index ec2487c9..3d60989b 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Book.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Book.java @@ -32,7 +32,7 @@ public class Book implements Serializable { private String content; - @RelationManyToOne(selfField = "accountId",targetField = "id") + @RelationManyToOne(selfField = "accountId", targetField = "id") private Account account; public Long getId() { @@ -78,11 +78,12 @@ public class Book implements Serializable { @Override public String toString() { return "Book{" + - "id=" + id + - ", accountId=" + accountId + - ", title='" + title + '\'' + - ", content='" + content + '\'' + - ", account=" + account + - '}'; + "id=" + id + + ", accountId=" + accountId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", account=" + account + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/IDCard.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/IDCard.java index 9ace096a..d7bbdc9a 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/IDCard.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/IDCard.java @@ -56,9 +56,10 @@ public class IDCard implements Serializable { @Override public String toString() { return "IDCard{" + - "accountId=" + accountId + - ", cardNo='" + cardNo + '\'' + - ", content='" + content + '\'' + - '}'; + "accountId=" + accountId + + ", cardNo='" + cardNo + '\'' + + ", content='" + content + '\'' + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Menu.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Menu.java index ac6708a4..bb3ad5a8 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Menu.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Menu.java @@ -32,10 +32,10 @@ public class Menu implements Serializable { private String name; - @RelationManyToOne(selfField = "parentId",targetField = "id") + @RelationManyToOne(selfField = "parentId", targetField = "id") private Menu parent; - @RelationOneToMany(selfField = "id",targetField = "parentId") + @RelationOneToMany(selfField = "id", targetField = "parentId") private List

children; public Long getId() { @@ -81,11 +81,12 @@ public class Menu implements Serializable { @Override public String toString() { return "Menu{" + - "id=" + id + - ", parentId=" + parentId + - ", name='" + name + '\'' + - ", parent=" + parent + - ", children=" + children + - '}'; + "id=" + id + + ", parentId=" + parentId + + ", name='" + name + '\'' + + ", parent=" + parent + + ", children=" + children + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/RelationsTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/RelationsTester.java index df32034a..ea72106a 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/RelationsTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/RelationsTester.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test.relation.onetoone; @@ -46,17 +46,17 @@ public class RelationsTester { @BeforeClass public static void init() { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("relation/onetoone/schema.sql") - .addScript("relation/onetoone/data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("relation/onetoone/schema.sql") + .addScript("relation/onetoone/data.sql") + .build(); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .addMapper(BookMapper.class) - .addMapper(MenuMapper.class) - .start(); + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .addMapper(BookMapper.class) + .addMapper(MenuMapper.class) + .start(); //开启审计功能 AuditManager.setAuditEnable(true); @@ -100,7 +100,7 @@ public class RelationsTester { qw.where(MENU.PARENT_ID.eq(0)); List

menus = menuMapper.selectListWithRelationsByQuery(qw); - System.out.println( JSON.toJSONString(menus)); + System.out.println(JSON.toJSONString(menus)); } @Test @@ -110,7 +110,7 @@ public class RelationsTester { RelationManager.addIgnoreRelations("parent"); List menus = menuMapper.selectListWithRelationsByQuery(qw); - System.out.println( JSON.toJSONString(menus)); + System.out.println(JSON.toJSONString(menus)); } @Test diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Role.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Role.java index f94fe99c..100e3c81 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Role.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/relation/onetoone/Role.java @@ -30,9 +30,9 @@ public class Role implements Serializable { @RelationManyToMany( - joinTable = "tb_role_mapping", - selfField = "id", joinSelfColumn = "role_id", - targetField = "id", joinTargetColumn = "account_id" + joinTable = "tb_role_mapping", + selfField = "id", joinSelfColumn = "role_id", + targetField = "id", joinTargetColumn = "account_id" ) private List accounts; @@ -63,9 +63,10 @@ public class Role implements Serializable { @Override public String toString() { return "Role{" + - "id=" + id + - ", name='" + name + '\'' + - ", accounts=" + accounts + - '}'; + "id=" + id + + ", name='" + name + '\'' + + ", accounts=" + accounts + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/ListenerTest.java b/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/ListenerTest.java index db4e3af6..12d13f03 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/ListenerTest.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/ListenerTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.core.FlexGlobalConfig; @@ -22,18 +38,18 @@ public class ListenerTest implements WithAssertions { // @Test public void onInsertInterface() throws Exception { DataSource dataSource = new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .build(); // 注册全局监听器 FlexGlobalConfig defaultConfig = FlexGlobalConfig.getDefaultConfig(); defaultConfig.registerInsertListener(new AgeHandleListener(), AgeAware.class); MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() - .setLogImpl(StdOutImpl.class) - .setDataSource(dataSource) - .addMapper(AccountMapper.class) - .start(); + .setLogImpl(StdOutImpl.class) + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .start(); AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class); Account account = new Account(); @@ -46,4 +62,5 @@ public class ListenerTest implements WithAssertions { System.out.println(one); // assertThat(one.getAge()).isEqualTo(1); } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/DataSourceInitListener.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/DataSourceInitListener.java index 276c872b..d88298ff 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/DataSourceInitListener.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/DataSourceInitListener.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.core.FlexGlobalConfig; @@ -12,7 +28,7 @@ public class DataSourceInitListener implements ApplicationListener>>> datasource:" + dataSource); } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java index e5ab0a97..7b14022d 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test; import com.mybatisflex.core.datasource.DataSourceDecipher; @@ -18,7 +34,7 @@ public class MyConfigurationCustomizer implements ConfigurationCustomizer { } @Bean - public DataSourceDecipher decipher(){ + public DataSourceDecipher decipher() { DataSourceDecipher decipher = new DataSourceDecipher() { @Override public String decrypt(DataSourceProperty property, String value) { @@ -28,4 +44,5 @@ public class MyConfigurationCustomizer implements ConfigurationCustomizer { }; return decipher; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/SampleApplication.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/SampleApplication.java index 4e211840..31632080 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/SampleApplication.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/SampleApplication.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -47,18 +47,15 @@ public class SampleApplication implements CommandLineRunner, ApplicationListener } - - - - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - System.out.println("onApplicationEvent"); - //开启审计功能 - AuditManager.setAuditEnable(true); + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + System.out.println("onApplicationEvent"); + //开启审计功能 + AuditManager.setAuditEnable(true); //设置 SQL 审计收集器 - MessageCollector collector = new ConsoleMessageCollector(); - AuditManager.setMessageCollector(collector); - } + MessageCollector collector = new ConsoleMessageCollector(); + AuditManager.setMessageCollector(collector); + } } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/controller/AccountController.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/controller/AccountController.java index 678529bf..2574fa48 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/controller/AccountController.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/controller/AccountController.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test.controller; @@ -45,21 +45,20 @@ public class AccountController { @PostMapping("/account/add") - String add(@RequestBody Account account){ + String add(@RequestBody Account account) { accountMapper.insert(account); return "add ok!"; } - @GetMapping("/account/byName/{name}") - Account selectName(@PathVariable("name") String name){ + Account selectName(@PathVariable("name") String name) { return myAccountMapper.selectByName(name); } @GetMapping("/account/byId/{id}") - Account selectId(@PathVariable("id") Object id){ + Account selectId(@PathVariable("id") Object id) { return myAccountMapper.selectById(id); } @@ -73,10 +72,10 @@ public class AccountController { // account.setUserName("heihei"); // accountMapper.update(account); - Row row1 = Db.selectOneById(null,"tb_account", "id", 1); + Row row1 = Db.selectOneById(null, "tb_account", "id", 1); System.out.println(">>>>>>> row1: " + row1); - Row row2 = Db.selectOneById(null,"tb_account", "id", 2); + Row row2 = Db.selectOneById(null, "tb_account", "id", 2); System.out.println(">>>>>>> row2: " + row2); // Account account1 = accountMapper.selectOneById(1L); @@ -95,7 +94,6 @@ public class AccountController { } - @GetMapping("/all") List all() { return accountMapper.selectAll(); @@ -103,7 +101,8 @@ public class AccountController { @GetMapping("/paginate") - Page paginate(@RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "10") int pageSize) { - return accountMapper.paginate(pageNumber,pageSize, QueryWrapper.create()); + Page paginate(@RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "10") int pageSize) { + return accountMapper.paginate(pageNumber, pageSize, QueryWrapper.create()); } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java index f6a7ba06..ca989c06 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Inner.java @@ -47,8 +47,9 @@ public class Inner { @Override public String toString() { return "Inner{" + - "id=" + id + - ", type='" + type + '\'' + - '}'; + "id=" + id + + ", type='" + type + '\'' + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java index df897d29..f40c99fe 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/Outer.java @@ -55,9 +55,10 @@ public class Outer extends IdEntity { @Override public String toString() { return "Outer{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", inner=" + inner + - '}'; + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", inner=" + inner + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/TestEntity.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/TestEntity.java index 95f5a8ec..30f9e092 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/TestEntity.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/entity/TestEntity.java @@ -24,4 +24,5 @@ import com.mybatisflex.annotation.Table; */ @Table("test") public class TestEntity { -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/MyAccountMapper.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/MyAccountMapper.java index 9ba13aea..f111c014 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/MyAccountMapper.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/mapper/MyAccountMapper.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test.mapper; import com.mybatisflex.test.model.Account; @@ -11,4 +27,5 @@ public interface MyAccountMapper extends AccountMapper { @Select("select * from tb_account where id = #{id} and id =#{id}") Account selectById(@Param("id") Object id); + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java index 49c87d8b..21fc7edb 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java @@ -106,4 +106,5 @@ public class Account extends BaseEntity { // ", roles=" + roles + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java index a09fa49f..907f22b2 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java @@ -1,11 +1,29 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test.model; import com.mybatisflex.annotation.SetListener; public class AccountOnSetListener implements SetListener { + @Override public Object onSet(Object entity, String property, Object value) { - System.out.println(">>>>>>> property: " + property +" value:" + value); + System.out.println(">>>>>>> property: " + property + " value:" + value); return value; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO.java index 42c4db7b..4addae82 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO.java @@ -60,10 +60,11 @@ public class AccountVO extends IdEntity { @Override public String toString() { return "Account{" + - "id=" + id + - ", age=" + age + - ", birthday=" + birthday + - ", roleName=" + role + - '}'; + "id=" + id + + ", age=" + age + + ", birthday=" + birthday + + ", roleName=" + role + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO2.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO2.java index 439e49a8..ad87c048 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO2.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO2.java @@ -66,11 +66,11 @@ public class AccountVO2 extends IdEntity { @Override public String toString() { return "AccountVO2{" + - "id=" + id + - ", age=" + age + - ", userName='" + userName + '\'' + - ", user='" + user + '\'' + - '}'; + "id=" + id + + ", age=" + age + + ", userName='" + userName + '\'' + + ", user='" + user + '\'' + + '}'; } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Article.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Article.java index 1a94ed49..e8f87b1f 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Article.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Article.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test.model; import com.mybatisflex.annotation.Column; @@ -45,10 +61,11 @@ public class Article extends IdEntity { @Override public String toString() { return "Article{" + - "id=" + id + - ", accountId=" + accountId + - ", title='" + title + '\'' + - ", content='" + content + '\'' + - '}'; + "id=" + id + + ", accountId=" + accountId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java index c8bf48ff..1447e3b4 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java @@ -53,4 +53,5 @@ public class BaseEntity extends IdEntity { public void setUserName(T userName) { this.userName = userName; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java index 4ddd1d02..67a0cfe6 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java @@ -40,4 +40,5 @@ public class IdEntity implements Serializable { public void setId(T id) { this.id = id; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Order.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Order.java index 5e59747b..e040f8d8 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Order.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Order.java @@ -53,8 +53,9 @@ public class Order { @Override public String toString() { return "Order{" + - "orderId=" + orderId + - ", createTime=" + createTime + - '}'; + "orderId=" + orderId + + ", createTime=" + createTime + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/OrderGood.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/OrderGood.java index 8999a10c..589deaa3 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/OrderGood.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/OrderGood.java @@ -45,4 +45,5 @@ public class OrderGood { public void setGoodId(Integer goodId) { this.goodId = goodId; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleKey.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleKey.java index 7849fabe..d49c8659 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleKey.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleKey.java @@ -36,4 +36,5 @@ public class RoleKey { public String toString() { return roleKey.toString(); } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO1.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO1.java index b1726ee6..35547cb2 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO1.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO1.java @@ -64,11 +64,11 @@ public class RoleVO1 { @Override public String toString() { return "Role{" + - "roleId=" + roleId + - ", roleKey='" + roleKey + '\'' + - ", roleName='" + roleName + '\'' + - ", userVO1='" + user + '\'' + - '}'; + "roleId=" + roleId + + ", roleKey='" + roleKey + '\'' + + ", roleName='" + roleName + '\'' + + ", userVO1='" + user + '\'' + + '}'; } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO2.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO2.java index 90d194a6..7178eb79 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO2.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO2.java @@ -44,8 +44,9 @@ public class RoleVO2 { @Override public String toString() { return "RoleName{" + - "roleName=" + roleName + - ", roleKey=" + roleKey + - '}'; + "roleName=" + roleName + + ", roleKey=" + roleKey + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO3.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO3.java index 0f91eebc..73993c62 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO3.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/RoleVO3.java @@ -53,9 +53,10 @@ public class RoleVO3 { @Override public String toString() { return "RoleVO3{" + - "roleId=" + roleId + - ", roleKey='" + roleKey + '\'' + - ", roleName='" + userName + '\'' + - '}'; + "roleId=" + roleId + + ", roleKey='" + roleKey + '\'' + + ", roleName='" + userName + '\'' + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/User.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/User.java index 1d928e86..13b89f01 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/User.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/User.java @@ -73,10 +73,11 @@ public class User { @Override public String toString() { return "User{" + - "userId=" + userId + - ", userName='" + userName + '\'' + - ", password='" + password + '\'' + - ", roleList=" + roleList + - '}'; + "userId=" + userId + + ", userName='" + userName + '\'' + + ", password='" + password + '\'' + + ", roleList=" + roleList + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserOrder.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserOrder.java index 71defc00..7dfc9ee3 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserOrder.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserOrder.java @@ -45,4 +45,5 @@ public class UserOrder { public void setOrderId(Integer orderId) { this.orderId = orderId; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserRole.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserRole.java index 4ae2bb28..33684ddf 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserRole.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserRole.java @@ -45,4 +45,5 @@ public class UserRole { public void setRoleId(Integer roleId) { this.roleId = roleId; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO.java index a392157b..5ef336af 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO.java @@ -59,9 +59,10 @@ public class UserVO { @Override public String toString() { return "UserVO{" + - "userId='" + userId + '\'' + - ", userName='" + userName + '\'' + - ", roleList=" + roleList + - '}'; + "userId='" + userId + '\'' + + ", userName='" + userName + '\'' + + ", roleList=" + roleList + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO1.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO1.java index ea999659..563083fd 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO1.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO1.java @@ -53,9 +53,10 @@ public class UserVO1 { @Override public String toString() { return "UserVO1{" + - "userId='" + userId + '\'' + - ", userName='" + userName + '\'' + - ", roleVO1=" + role + - '}'; + "userId='" + userId + '\'' + + ", userName='" + userName + '\'' + + ", roleVO1=" + role + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO2.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO2.java index ec816797..c3102c34 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO2.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO2.java @@ -65,10 +65,11 @@ public class UserVO2 { @Override public String toString() { return "UserVO2{" + - "userId='" + userId + '\'' + - ", userName='" + userName + '\'' + - ", roles=" + roles + - ", roleIds=" + roleIds + - '}'; + "userId='" + userId + '\'' + + ", userName='" + userName + '\'' + + ", roles=" + roles + + ", roleIds=" + roleIds + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO3.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO3.java index 503dfd1d..83ad0ca3 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO3.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO3.java @@ -57,9 +57,10 @@ public class UserVO3 { @Override public String toString() { return "UserVO3{" + - "userId='" + userId + '\'' + - ", userName='" + userName + '\'' + - ", roleVO3=" + roleVO3 + - '}'; + "userId='" + userId + '\'' + + ", userName='" + userName + '\'' + + ", roleVO3=" + roleVO3 + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO4.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO4.java index f5e6be07..d893cf7a 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO4.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/UserVO4.java @@ -48,8 +48,9 @@ public class UserVO4 { @Override public String toString() { return "UserVO{" + - "userId='" + userId + '\'' + - ", userName='" + userName + '\'' + - '}'; + "userId='" + userId + '\'' + + ", userName='" + userName + '\'' + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/service/AccountService.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/service/AccountService.java index 961d4945..16a66250 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/service/AccountService.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/service/AccountService.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test.service; import com.mybatisflex.test.mapper.AccountMapper; @@ -23,4 +39,5 @@ public class AccountService { account.setUserName("haha"); accountMapper.update(account); } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/CloneTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/CloneTest.java index 4a59fe0b..c8b98bb1 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/CloneTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/CloneTest.java @@ -89,22 +89,22 @@ class CloneTest { private QueryWrapper newQueryWrapper() { return QueryWrapper.create() - .select(count(distinct(USER.USER_ID))/*case_() + .select(count(distinct(USER.USER_ID))/*case_() .when(USER.USER_ID.eq(3)).then("x3") .when(USER.USER_ID.eq(5)).then("x4") .end(), distinct(USER.USER_ID.add(4)), USER.USER_NAME, ROLE.ALL_COLUMNS*/) - .from(USER.as("u")) - .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) - .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) - .where(USER.USER_ID.eq(3)) - .and(ROLE.ROLE_NAME.in(Arrays.asList(1, 2, 3))) - .or(ROLE.ROLE_ID.ge(USER.USER_ID)) - .groupBy(ROLE.ROLE_NAME) - .having(ROLE.ROLE_ID.ge(7)) - .orderBy(ROLE.ROLE_NAME.asc()); + .from(USER.as("u")) + .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) + .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) + .where(USER.USER_ID.eq(3)) + .and(ROLE.ROLE_NAME.in(Arrays.asList(1, 2, 3))) + .or(ROLE.ROLE_ID.ge(USER.USER_ID)) + .groupBy(ROLE.ROLE_NAME) + .having(ROLE.ROLE_ID.ge(7)) + .orderBy(ROLE.ROLE_NAME.asc()); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java index c3ef93c3..7e101f5b 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java @@ -42,8 +42,8 @@ class FieldTest { Class accountClass = Account.class; Method[] declaredMethods = accountClass.getMethods(); Arrays.stream(declaredMethods) - .filter(e -> e.getName().startsWith("get")) - .forEach(System.out::println); + .filter(e -> e.getName().startsWith("get")) + .forEach(System.out::println); } @Test @@ -64,4 +64,4 @@ class FieldTest { System.out.println(roleList); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/MapperUtilTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/MapperUtilTest.java index ea1f2705..1cbe8f89 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/MapperUtilTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/MapperUtilTest.java @@ -33,16 +33,16 @@ class MapperUtilTest { @Test void testOptimizeCountQueryWrapper() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(USER.USER_ID, USER.USER_NAME, ROLE.ALL_COLUMNS) - .from(USER.as("u")) - .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) - .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) - .where(USER.USER_ID.eq(3)) - .and(USER_ROLE.ROLE_ID.eq(6)) - .groupBy(ROLE.ROLE_ID); + .select(USER.USER_ID, USER.USER_NAME, ROLE.ALL_COLUMNS) + .from(USER.as("u")) + .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) + .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) + .where(USER.USER_ID.eq(3)) + .and(USER_ROLE.ROLE_ID.eq(6)) + .groupBy(ROLE.ROLE_ID); System.out.println(queryWrapper.toSQL()); System.out.println(MapperUtil.rawCountQueryWrapper(queryWrapper).toSQL()); System.out.println(MapperUtil.optimizeCountQueryWrapper(queryWrapper).toSQL()); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/QueryWrapperTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/QueryWrapperTest.java index 18b01ffc..27a281ae 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/QueryWrapperTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/QueryWrapperTest.java @@ -38,57 +38,57 @@ class QueryWrapperTest { @Test void test01() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(USER.USER_ID, ROLE.ALL_COLUMNS) - .hint("hint") - .from(USER.as("u")) - .leftJoin(USER_ROLE).as("ur").on(USER.USER_ID.eq(USER_ROLE.USER_ID)) - .leftJoin(ROLE).as("r").on(ROLE.ROLE_ID.eq(USER_ROLE.ROLE_ID)) - .where(USER.USER_ID.eq(3)) - .and(USER.USER_ID.eq(ROLE.ROLE_ID)) - .or(USER.USER_ID.in(4, 5, 6)) - .groupBy(ROLE.ROLE_KEY) - .having(ROLE.ROLE_ID.eq(USER_ROLE.ROLE_ID)) - .orderBy(ROLE.ROLE_NAME.asc()); + .select(USER.USER_ID, ROLE.ALL_COLUMNS) + .hint("hint") + .from(USER.as("u")) + .leftJoin(USER_ROLE).as("ur").on(USER.USER_ID.eq(USER_ROLE.USER_ID)) + .leftJoin(ROLE).as("r").on(ROLE.ROLE_ID.eq(USER_ROLE.ROLE_ID)) + .where(USER.USER_ID.eq(3)) + .and(USER.USER_ID.eq(ROLE.ROLE_ID)) + .or(USER.USER_ID.in(4, 5, 6)) + .groupBy(ROLE.ROLE_KEY) + .having(ROLE.ROLE_ID.eq(USER_ROLE.ROLE_ID)) + .orderBy(ROLE.ROLE_NAME.asc()); System.out.println(queryWrapper.toSQL()); } @Test void test02() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(count(distinct(USER.USER_ID)), case_() - .when(USER.USER_ID.eq(3)).then("x3") - .when(USER.USER_ID.eq(5)).then("x4") - .end(), - distinct(USER.USER_ID.add(4)), - USER.USER_NAME, - ROLE.ALL_COLUMNS) - .from(USER.as("u")) - .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) - .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) - .where(USER.USER_ID.eq(3)) - .and(ROLE.ROLE_NAME.in(Arrays.asList(1, 2, 3))) - .or(ROLE.ROLE_ID.ge(USER.USER_ID)) - .groupBy(ROLE.ROLE_NAME) - .having(ROLE.ROLE_ID.ge(7)) - .orderBy(ROLE.ROLE_NAME.asc()); + .select(count(distinct(USER.USER_ID)), case_() + .when(USER.USER_ID.eq(3)).then("x3") + .when(USER.USER_ID.eq(5)).then("x4") + .end(), + distinct(USER.USER_ID.add(4)), + USER.USER_NAME, + ROLE.ALL_COLUMNS) + .from(USER.as("u")) + .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) + .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) + .where(USER.USER_ID.eq(3)) + .and(ROLE.ROLE_NAME.in(Arrays.asList(1, 2, 3))) + .or(ROLE.ROLE_ID.ge(USER.USER_ID)) + .groupBy(ROLE.ROLE_NAME) + .having(ROLE.ROLE_ID.ge(7)) + .orderBy(ROLE.ROLE_NAME.asc()); System.out.println(queryWrapper.toSQL()); } @Test void test03() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(USER.as("u")) - .leftJoin(USER_ROLE).as("ur").on(USER.USER_ID.eq(USER_ROLE.USER_ID)) - .where(QueryCondition.createEmpty()) - .and(USER.USER_ID.eq(1).or(USER.USER_ID.in( - QueryWrapper.create().select(USER_ROLE.USER_ID).from(USER_ROLE))) - ) - .and(USER_ROLE.USER_ID.eq(1)); + .select() + .from(USER.as("u")) + .leftJoin(USER_ROLE).as("ur").on(USER.USER_ID.eq(USER_ROLE.USER_ID)) + .where(QueryCondition.createEmpty()) + .and(USER.USER_ID.eq(1).or(USER.USER_ID.in( + QueryWrapper.create().select(USER_ROLE.USER_ID).from(USER_ROLE))) + ) + .and(USER_ROLE.USER_ID.eq(1)); System.out.println(queryWrapper.toSQL()); QueryCondition whereQueryCondition = CPI.getWhereQueryCondition(queryWrapper); boolean contained = CPI.containsTable(whereQueryCondition, "tb_user_role"); Assertions.assertTrue(contained); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ReflectTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ReflectTest.java index b2f83cc5..63343a64 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ReflectTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ReflectTest.java @@ -36,9 +36,9 @@ class ReflectTest { List allFields = ClassUtil.getAllFields(Account.class); for (Field field : allFields) { Type type = TypeParameterResolver.resolveFieldType(field, Account.class); - System.out.println("field: " + field+"----->Type:" + type); + System.out.println("field: " + field + "----->Type:" + type); } } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/SerialUtil.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/SerialUtil.java index 3eb135ed..eed874b5 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/SerialUtil.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/SerialUtil.java @@ -57,18 +57,18 @@ public class SerialUtil { public static String toJSONString(Object obj) { return JSON.toJSONString(obj, JSONWriter.Feature.FieldBased, - JSONWriter.Feature.WriteClassName, - JSONWriter.Feature.NotWriteRootClassName, - JSONWriter.Feature.ReferenceDetection); + JSONWriter.Feature.WriteClassName, + JSONWriter.Feature.NotWriteRootClassName, + JSONWriter.Feature.ReferenceDetection); } public static T parseObject(String str, Class tClass) { return JSON.parseObject(str, tClass, JSONReader.Feature.FieldBased, - JSONReader.Feature.SupportClassForName); + JSONReader.Feature.SupportClassForName); } public static T cloneObject(Object obj, Class tClass) { return parseObject(toJSONString(obj), tClass); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java index 0034d507..fd07d473 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java @@ -50,17 +50,17 @@ class AccountMapperTest { @Test void testCount() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .groupBy(ACCOUNT.AGE); + .select() + .from(ACCOUNT) + .groupBy(ACCOUNT.AGE); long count = accountMapper.selectCountByQuery(queryWrapper); Assertions.assertEquals(2, count); queryWrapper = QueryWrapper.create() - .select(distinct(ACCOUNT.AGE)) - .from(ACCOUNT); + .select(distinct(ACCOUNT.AGE)) + .from(ACCOUNT); count = accountMapper.selectCountByQuery(queryWrapper); @@ -97,10 +97,10 @@ class AccountMapperTest { @Test void testGenericEntity() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ALL_COLUMNS, ROLE.ALL_COLUMNS) - .from(ACCOUNT) - .leftJoin(USER_ROLE).on(USER_ROLE.USER_ID.eq(ACCOUNT.ID)) - .leftJoin(ROLE).on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)); + .select(ACCOUNT.ALL_COLUMNS, ROLE.ALL_COLUMNS) + .from(ACCOUNT) + .leftJoin(USER_ROLE).on(USER_ROLE.USER_ID.eq(ACCOUNT.ID)) + .leftJoin(ROLE).on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)); accountMapper.selectListByQueryAs(queryWrapper, AccountVO.class).forEach(System.err::println); } @@ -125,25 +125,25 @@ class AccountMapperTest { Account account = new Account(); account.setAge(10); Assertions.assertThrows(Exception.class, () -> - accountMapper.updateByQuery(account, QueryWrapper.create())); + accountMapper.updateByQuery(account, QueryWrapper.create())); } @Test void testDeleteAll() { Assertions.assertThrows(Exception.class, () -> - accountMapper.deleteByQuery(QueryWrapper.create())); + accountMapper.deleteByQuery(QueryWrapper.create())); } @Test void testAs() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ID, - ACCOUNT.AGE, - USER.USER_ID, - USER.USER_NAME) - .from(ACCOUNT.as("a"), USER.as("u")) - .where(ACCOUNT.ID.eq(1)) - .limit(1); + .select(ACCOUNT.ID, + ACCOUNT.AGE, + USER.USER_ID, + USER.USER_NAME) + .from(ACCOUNT.as("a"), USER.as("u")) + .where(ACCOUNT.ID.eq(1)) + .limit(1); AccountVO2 account = accountMapper.selectOneByQueryAs(queryWrapper, AccountVO2.class); System.out.println(account); } @@ -151,14 +151,14 @@ class AccountMapperTest { @Test void testAs0() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ID.as("account_id"), - ACCOUNT.AGE, - concat(column("'account name: '"), ACCOUNT.USER_NAME).as("user_name"), - USER.USER_ID, - concat(column("'user name: '"), USER.USER_NAME).as("1_account_name")) - .from(ACCOUNT.as("a"), USER.as("u")) - .where(ACCOUNT.ID.eq(1)) - .limit(1); + .select(ACCOUNT.ID.as("account_id"), + ACCOUNT.AGE, + concat(column("'account name: '"), ACCOUNT.USER_NAME).as("user_name"), + USER.USER_ID, + concat(column("'user name: '"), USER.USER_NAME).as("1_account_name")) + .from(ACCOUNT.as("a"), USER.as("u")) + .where(ACCOUNT.ID.eq(1)) + .limit(1); AccountVO2 account = accountMapper.selectOneByQueryAs(queryWrapper, AccountVO2.class); System.out.println(account); } @@ -166,16 +166,16 @@ class AccountMapperTest { @Test void testAs1() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(ACCOUNT.ID.as(AccountVO2::getId), - ACCOUNT.AGE, - concat(column("'account name: '"), ACCOUNT.USER_NAME).as(AccountVO2::getUserName), - USER.USER_ID, - concat(column("'user name: '"), USER.USER_NAME).as("1_account_name")) - .from(ACCOUNT.as("a"), USER.as("u")) - .where(ACCOUNT.ID.eq(1)) - .limit(1); + .select(ACCOUNT.ID.as(AccountVO2::getId), + ACCOUNT.AGE, + concat(column("'account name: '"), ACCOUNT.USER_NAME).as(AccountVO2::getUserName), + USER.USER_ID, + concat(column("'user name: '"), USER.USER_NAME).as("1_account_name")) + .from(ACCOUNT.as("a"), USER.as("u")) + .where(ACCOUNT.ID.eq(1)) + .limit(1); AccountVO2 account = accountMapper.selectOneByQueryAs(queryWrapper, AccountVO2.class); System.out.println(account); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/MyAccountMapperTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/MyAccountMapperTest.java index be6e06d1..2fcf380f 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/MyAccountMapperTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/MyAccountMapperTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test.mapper; import com.mybatisflex.test.model.Account; @@ -17,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ @SpringBootTest class MyAccountMapperTest { + @Autowired private MyAccountMapper mapper; @@ -42,4 +59,4 @@ class MyAccountMapperTest { assertEquals(33334, i); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/OuterMapperTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/OuterMapperTest.java index fa9c439a..6cbbef3c 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/OuterMapperTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/OuterMapperTest.java @@ -54,14 +54,14 @@ class OuterMapperTest { @Test void testSelect() { QueryWrapper queryWrapper = QueryWrapper.create() - .select(OUTER.ID, - OUTER.NAME, - INNER.ID, - INNER.TYPE) - .from(OUTER.as("o")) - .leftJoin(INNER).as("i").on(INNER.ID.eq(2)); + .select(OUTER.ID, + OUTER.NAME, + INNER.ID, + INNER.TYPE) + .from(OUTER.as("o")) + .leftJoin(INNER).as("i").on(INNER.ID.eq(2)); Outer outer = outerMapper.selectOneByQuery(queryWrapper); System.out.println(outer); } -} \ No newline at end of file +} diff --git a/mybatis-flex-test/mybatis-flex-spring-cloud-test/src/main/java/com/mybatisflex/test/entity/Account.java b/mybatis-flex-test/mybatis-flex-spring-cloud-test/src/main/java/com/mybatisflex/test/entity/Account.java index 571bd153..37a87163 100644 --- a/mybatis-flex-test/mybatis-flex-spring-cloud-test/src/main/java/com/mybatisflex/test/entity/Account.java +++ b/mybatis-flex-test/mybatis-flex-spring-cloud-test/src/main/java/com/mybatisflex/test/entity/Account.java @@ -70,10 +70,11 @@ public class Account { @Override public String toString() { return "Account{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", birthday=" + birthday + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", birthday=" + birthday + + '}'; } -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/AppConfig.java b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/AppConfig.java index d8d89983..6ad474c5 100644 --- a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/AppConfig.java +++ b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/AppConfig.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test; @@ -39,10 +39,10 @@ public class AppConfig implements ApplicationListener { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.H2) - .addScript("schema.sql") - .addScript("data.sql") - .build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); } @Bean @@ -65,4 +65,5 @@ public class AppConfig implements ApplicationListener { public void onApplicationEvent(ContextRefreshedEvent event) { System.out.println("onApplicationEvent"); } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java index 6764840e..9442b83a 100644 --- a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java +++ b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java @@ -24,4 +24,5 @@ import com.mybatisflex.test.model.Account; * @since 2023-06-23 */ public interface AccountMapper extends BaseMapper { -} \ No newline at end of file + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/Account.java b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/Account.java index 72f2cc92..8370fd04 100644 --- a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/Account.java +++ b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/Account.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mybatisflex.test.model; @@ -64,10 +64,11 @@ public class Account { @Override public String toString() { return "Account{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", age=" + age + - ", birthday=" + birthday + - '}'; + "id=" + id + + ", userName='" + userName + '\'' + + ", age=" + age + + ", birthday=" + birthday + + '}'; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java index a09fa49f..907f22b2 100644 --- a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java +++ b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/model/AccountOnSetListener.java @@ -1,11 +1,29 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.mybatisflex.test.model; import com.mybatisflex.annotation.SetListener; public class AccountOnSetListener implements SetListener { + @Override public Object onSet(Object entity, String property, Object value) { - System.out.println(">>>>>>> property: " + property +" value:" + value); + System.out.println(">>>>>>> property: " + property + " value:" + value); return value; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AccountTest.java b/mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AccountTest.java index 8295ac2e..32c78dd8 100644 --- a/mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AccountTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AccountTest.java @@ -43,13 +43,13 @@ public class AccountTest implements WithAssertions { public void testSelectOne() { Account account = accountMapper.selectOneById(1); assertThat(account).isNotNull() - .satisfies(a -> assertThat(a.getId()).isEqualTo(1)); + .satisfies(a -> assertThat(a.getId()).isEqualTo(1)); } @Test public void testSelectByQuery() { QueryWrapper queryWrapper = QueryWrapper.create() - .where(ACCOUNT.AGE.eq(18)); + .where(ACCOUNT.AGE.eq(18)); List accounts = accountMapper.selectListByQuery(queryWrapper); assertThat(accounts.size()).isEqualTo(1); assertThat(accounts.get(0).getAge()).isEqualTo(18); @@ -64,11 +64,11 @@ public class AccountTest implements WithAssertions { @Test public void testLambda() { QueryWrapper queryWrapper = QueryWrapper.create() - .select() - .from(ACCOUNT) - .where(Account::getAge).in( - QueryWrapper.create().select(ACCOUNT.AGE).from(ACCOUNT).where(ACCOUNT.AGE.ge(18)) - ); + .select() + .from(ACCOUNT) + .where(Account::getAge).in( + QueryWrapper.create().select(ACCOUNT.AGE).from(ACCOUNT).where(ACCOUNT.AGE.ge(18)) + ); System.out.println(queryWrapper.toSQL()); }