├── LICENSE.txt ├── README.md ├── drink-base ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── github │ └── kiryu1223 │ └── drink │ └── base │ ├── DbType.java │ ├── Filter.java │ ├── IConfig.java │ ├── IDbSupport.java │ ├── IDialect.java │ ├── SqlCalculates.java │ ├── annotation │ ├── Column.java │ ├── Empty.java │ ├── EmptyTable.java │ ├── IgnoreColumn.java │ ├── Navigate.java │ ├── RelationType.java │ ├── Table.java │ └── UseTypeHandler.java │ ├── converter │ ├── NameConverter.java │ └── SnakeNameConverter.java │ ├── dataSource │ ├── DataSourceManager.java │ └── DefaultDataSourceManager.java │ ├── exception │ ├── DrinkException.java │ ├── SqlFunctionInvokeException.java │ └── Winner.java │ ├── expression │ ├── AsNameManager.java │ ├── ExKey.java │ ├── ExKeys.java │ ├── ExValue.java │ ├── ExValues.java │ ├── ISqlAsExpression.java │ ├── ISqlBinaryExpression.java │ ├── ISqlCollectedValueExpression.java │ ├── ISqlColumnExpression.java │ ├── ISqlConditionsExpression.java │ ├── ISqlConstStringExpression.java │ ├── ISqlDeleteExpression.java │ ├── ISqlDynamicColumnExpression.java │ ├── ISqlExpression.java │ ├── ISqlFromExpression.java │ ├── ISqlGroupByExpression.java │ ├── ISqlHavingExpression.java │ ├── ISqlJoinExpression.java │ ├── ISqlJoinsExpression.java │ ├── ISqlLimitExpression.java │ ├── ISqlOrderByExpression.java │ ├── ISqlOrderExpression.java │ ├── ISqlParensExpression.java │ ├── ISqlQueryableExpression.java │ ├── ISqlRealTableExpression.java │ ├── ISqlRecursionExpression.java │ ├── ISqlSelectExpression.java │ ├── ISqlSetExpression.java │ ├── ISqlSetsExpression.java │ ├── ISqlSingleValueExpression.java │ ├── ISqlStarExpression.java │ ├── ISqlTableExpression.java │ ├── ISqlTableRefExpression.java │ ├── ISqlTemplateExpression.java │ ├── ISqlTypeCastExpression.java │ ├── ISqlUnaryExpression.java │ ├── ISqlUnionQueryableExpression.java │ ├── ISqlUpdateExpression.java │ ├── ISqlValueExpression.java │ ├── ISqlWhereExpression.java │ ├── ISqlWithExpression.java │ ├── JoinType.java │ ├── SqlExpressionFactory.java │ ├── SqlOperator.java │ ├── SqlTreeTransformer.java │ ├── SqlTreeVisitor.java │ ├── SubQueryBuilder.java │ ├── SubQueryValue.java │ └── impl │ │ ├── DefaultSqlExpressionFactory.java │ │ ├── SqlAsExpression.java │ │ ├── SqlBinaryExpression.java │ │ ├── SqlCollectedValueExpression.java │ │ ├── SqlColumnExpression.java │ │ ├── SqlConditionsExpression.java │ │ ├── SqlConstStringExpression.java │ │ ├── SqlDeleteExpression.java │ │ ├── SqlDynamicColumnExpression.java │ │ ├── SqlFromExpression.java │ │ ├── SqlGroupByExpression.java │ │ ├── SqlHavingExpression.java │ │ ├── SqlJoinExpression.java │ │ ├── SqlJoinsExpression.java │ │ ├── SqlLimitExpression.java │ │ ├── SqlOrderByExpression.java │ │ ├── SqlOrderExpression.java │ │ ├── SqlParensExpression.java │ │ ├── SqlQueryableExpression.java │ │ ├── SqlRealTableExpression.java │ │ ├── SqlRecursionExpression.java │ │ ├── SqlSelectExpression.java │ │ ├── SqlSetExpression.java │ │ ├── SqlSetsExpression.java │ │ ├── SqlSingleValueExpression.java │ │ ├── SqlStarExpression.java │ │ ├── SqlTableRefExpression.java │ │ ├── SqlTemplateExpression.java │ │ ├── SqlTypeCastExpression.java │ │ ├── SqlUnaryExpression.java │ │ ├── SqlUnionQueryableExpression.java │ │ ├── SqlUpdateExpression.java │ │ ├── SqlValueExpression.java │ │ ├── SqlWhereExpression.java │ │ └── SqlWithExpression.java │ ├── metaData │ ├── FieldMetaData.java │ ├── IMappingTable.java │ ├── MetaData.java │ └── NavigateData.java │ ├── page │ ├── DefaultPagedResult.java │ ├── DefaultPager.java │ ├── PagedResult.java │ └── Pager.java │ ├── session │ ├── DefaultSqlSession.java │ ├── DefaultSqlSessionFactory.java │ ├── SqlSession.java │ ├── SqlSessionFactory.java │ └── SqlValue.java │ ├── sqlExt │ ├── BaseSqlExtension.java │ ├── GroupJoinExtension.java │ ├── IAggregation.java │ ├── ISqlKeywords.java │ ├── Over.java │ ├── Range.java │ ├── Rows.java │ ├── SqlExtensionExpression.java │ ├── SqlExtensionExpressions.java │ ├── SqlOperatorMethod.java │ └── SqlTimeUnit.java │ ├── table │ └── TreeCte.java │ ├── toBean │ ├── beancreator │ │ ├── AbsBeanCreator.java │ │ ├── BeanCreatorFactory.java │ │ ├── DefaultBeanCreator.java │ │ ├── IGetterCaller.java │ │ ├── ISetterCaller.java │ │ └── IVoidSetter.java │ ├── build │ │ ├── ExtensionField.java │ │ ├── ExtensionObject.java │ │ ├── JdbcResult.java │ │ └── ObjectBuilder.java │ └── handler │ │ ├── ITypeHandler.java │ │ ├── TypeHandlerManager.java │ │ ├── UnKnowTypeHandler.java │ │ └── impl │ │ ├── datetime │ │ ├── DateTypeHandler.java │ │ ├── LocalDateTimeTypeHandler.java │ │ ├── LocalDateTypeHandler.java │ │ ├── LocalTimeTypeHandler.java │ │ ├── TimeTypeHandler.java │ │ ├── TimestampTypeHandler.java │ │ └── UtilDateHandler.java │ │ ├── list │ │ ├── ListBoolHandler.java │ │ ├── ListByteHandler.java │ │ ├── ListCharHandler.java │ │ ├── ListDoubleHandler.java │ │ ├── ListFloatHandler.java │ │ ├── ListIntHandler.java │ │ ├── ListLongHandler.java │ │ ├── ListShortHandler.java │ │ └── ListStringHandler.java │ │ ├── number │ │ ├── BigDecimalTypeHandler.java │ │ ├── BigIntegerTypeHandler.java │ │ ├── BoolTypeHandler.java │ │ ├── ByteTypeHandler.java │ │ ├── DoubleTypeHandler.java │ │ ├── FloatTypeHandler.java │ │ ├── IntTypeHandler.java │ │ ├── LongTypeHandler.java │ │ └── ShortTypeHandler.java │ │ ├── other │ │ └── URLTypeHandler.java │ │ └── varchar │ │ ├── CharTypeHandler.java │ │ └── StringTypeHandler.java │ ├── transaction │ ├── DefaultTransaction.java │ ├── DefaultTransactionManager.java │ ├── Transaction.java │ └── TransactionManager.java │ ├── transform │ ├── IAggregateMethods.java │ ├── IDateTimeMethods.java │ ├── ILogic.java │ ├── IMathMethods.java │ ├── INumberMethods.java │ ├── IObjectsMethods.java │ ├── IStringMethods.java │ └── Transformer.java │ ├── util │ └── DrinkUtil.java │ └── visitor │ └── ISqlVisitor.java ├── drink-core ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── github │ └── kiryu1223 │ └── drink │ └── core │ ├── Config.java │ ├── Option.java │ ├── SqlBuilder.java │ ├── SqlClient.java │ ├── api │ ├── ITable.java │ ├── IView.java │ ├── Result.java │ ├── StopWatch.java │ └── crud │ │ ├── CRUD.java │ │ ├── create │ │ ├── InsertBase.java │ │ ├── LInsert.java │ │ └── ObjectInsert.java │ │ ├── delete │ │ ├── DeleteBase.java │ │ ├── LDelete.java │ │ ├── LDelete10.java │ │ ├── LDelete2.java │ │ ├── LDelete3.java │ │ ├── LDelete4.java │ │ ├── LDelete5.java │ │ ├── LDelete6.java │ │ ├── LDelete7.java │ │ ├── LDelete8.java │ │ └── LDelete9.java │ │ ├── read │ │ ├── Aggregate.java │ │ ├── EmptyQuery.java │ │ ├── EndQuery.java │ │ ├── IDynamicTable.java │ │ ├── LQuery.java │ │ ├── LQuery10.java │ │ ├── LQuery2.java │ │ ├── LQuery3.java │ │ ├── LQuery4.java │ │ ├── LQuery5.java │ │ ├── LQuery6.java │ │ ├── LQuery7.java │ │ ├── LQuery8.java │ │ ├── LQuery9.java │ │ ├── QueryBase.java │ │ ├── UnionQuery.java │ │ └── group │ │ │ ├── Group.java │ │ │ ├── Group10.java │ │ │ ├── Group2.java │ │ │ ├── Group3.java │ │ │ ├── Group4.java │ │ │ ├── Group5.java │ │ │ ├── Group6.java │ │ │ ├── Group7.java │ │ │ ├── Group8.java │ │ │ ├── Group9.java │ │ │ ├── GroupedQuery.java │ │ │ ├── GroupedQuery10.java │ │ │ ├── GroupedQuery2.java │ │ │ ├── GroupedQuery3.java │ │ │ ├── GroupedQuery4.java │ │ │ ├── GroupedQuery5.java │ │ │ ├── GroupedQuery6.java │ │ │ ├── GroupedQuery7.java │ │ │ ├── GroupedQuery8.java │ │ │ ├── GroupedQuery9.java │ │ │ ├── Grouper.java │ │ │ └── IGroup.java │ │ └── update │ │ ├── LUpdate.java │ │ ├── LUpdate10.java │ │ ├── LUpdate2.java │ │ ├── LUpdate3.java │ │ ├── LUpdate4.java │ │ ├── LUpdate5.java │ │ ├── LUpdate6.java │ │ ├── LUpdate7.java │ │ ├── LUpdate8.java │ │ ├── LUpdate9.java │ │ └── UpdateBase.java │ ├── exception │ ├── NotCompiledException.java │ ├── SqLinkException.java │ ├── SqLinkIllegalExpressionException.java │ ├── SqLinkIntervalException.java │ ├── SqLinkLimitNotFoundOrderByException.java │ ├── SqLinkNotFoundFieldException.java │ ├── SqlCalculatesInvokeException.java │ └── SqlFuncExtNotFoundException.java │ ├── sqlBuilder │ ├── DeleteSqlBuilder.java │ ├── ISqlBuilder.java │ ├── IncludeBuilder.java │ ├── InsertSqlBuilder.java │ ├── QuerySqlBuilder.java │ ├── UnionBuilder.java │ └── UpdateSqlBuilder.java │ ├── util │ ├── ExpressionUtil.java │ └── List.java │ └── visitor │ ├── BaseSqlVisitor.java │ ├── ParamMatcher.java │ ├── QuerySqlVisitor.java │ └── UpdateSqlVisitor.java ├── drink-support ├── drink-support-db │ ├── pom.xml │ ├── support-db-h2 │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── drink │ │ │ │ └── db │ │ │ │ └── h2 │ │ │ │ ├── H2Dialect.java │ │ │ │ ├── H2ExpressionFactory.java │ │ │ │ ├── H2Support.java │ │ │ │ └── H2Transformer.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── io.github.kiryu1223.drink.base.IDbSupport │ ├── support-db-mysql │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── drink │ │ │ │ └── db │ │ │ │ └── mysql │ │ │ │ ├── MySQLDialect.java │ │ │ │ ├── MySQLExpressionFactory.java │ │ │ │ ├── MySQLRecursionExpression.java │ │ │ │ ├── MySQLSupport.java │ │ │ │ └── MySQLTransformer.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── io.github.kiryu1223.drink.base.IDbSupport │ ├── support-db-oracle │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── drink │ │ │ │ └── db │ │ │ │ └── oracle │ │ │ │ ├── OracleDialect.java │ │ │ │ ├── OracleExpressionFactory.java │ │ │ │ ├── OracleFromExpression.java │ │ │ │ ├── OracleJoinExpression.java │ │ │ │ ├── OracleLimitExpression.java │ │ │ │ ├── OracleQueryableExpression.java │ │ │ │ ├── OracleSupport.java │ │ │ │ └── OracleTransformer.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── io.github.kiryu1223.drink.base.IDbSupport │ ├── support-db-pg │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── drink │ │ │ │ └── db │ │ │ │ └── pg │ │ │ │ ├── PostgreSQLDialect.java │ │ │ │ ├── PostgreSQLExpressionFactory.java │ │ │ │ ├── PostgreSQLSupport.java │ │ │ │ └── PostgreSQLTransformer.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── io.github.kiryu1223.drink.base.IDbSupport │ ├── support-db-sqlite │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── drink │ │ │ │ └── db │ │ │ │ └── sqlite │ │ │ │ ├── SQLiteDialect.java │ │ │ │ ├── SQLiteSupport.java │ │ │ │ ├── SQLiteTransformer.java │ │ │ │ └── SqliteExpressionFactory.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── io.github.kiryu1223.drink.base.IDbSupport │ └── support-db-sqlserver │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── kiryu1223 │ │ │ └── drink │ │ │ └── db │ │ │ └── sqlserver │ │ │ ├── SQLServerDialect.java │ │ │ ├── SQLServerExpressionFactory.java │ │ │ ├── SQLServerLimitExpression.java │ │ │ ├── SQLServerQueryableExpression.java │ │ │ ├── SQLServerSupport.java │ │ │ └── SQLServerTransformer.java │ │ └── resources │ │ └── META-INF │ │ └── services │ │ └── io.github.kiryu1223.drink.base.IDbSupport ├── drink-support-framework │ ├── drink-aot │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── aot │ │ │ │ ├── data │ │ │ │ ├── AnonymousClassData.java │ │ │ │ ├── ClassData.java │ │ │ │ └── NormalClassData.java │ │ │ │ └── service │ │ │ │ └── DrinkExtensionService.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── io.github.kiryu1223.expressionTree.ext.IExtensionService │ ├── drink-solon-plugin │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── plugin │ │ │ │ ├── XPluginImpl.java │ │ │ │ ├── aot │ │ │ │ └── DrinkRuntimeNativeRegistrar.java │ │ │ │ ├── builder │ │ │ │ ├── AotBeanCreatorFactory.java │ │ │ │ └── AotFastCreator.java │ │ │ │ ├── configuration │ │ │ │ └── DrinkProperties.java │ │ │ │ ├── datasource │ │ │ │ ├── SolonDataSourceManager.java │ │ │ │ └── SolonDataSourceManagerWrap.java │ │ │ │ └── transaction │ │ │ │ ├── SolonTransaction.java │ │ │ │ └── SolonTransactionManager.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── solon │ │ │ └── drink-solon-plugin.properties │ ├── drink-spring-boot-starter │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── kiryu1223 │ │ │ │ └── drink │ │ │ │ └── starter │ │ │ │ ├── configuration │ │ │ │ ├── DrinkAutoConfiguration.java │ │ │ │ ├── DrinkProperties.java │ │ │ │ └── NameConversionType.java │ │ │ │ ├── dataSource │ │ │ │ └── SpringDataSourceManager.java │ │ │ │ └── transaction │ │ │ │ ├── SpringTransaction.java │ │ │ │ └── SpringTransactionManager.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ ├── spring.factories │ │ │ └── spring │ │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ └── pom.xml ├── drink-support-func │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── kiryu1223 │ │ └── drink │ │ └── func │ │ ├── SqlFunctions.java │ │ ├── mysql │ │ └── MySqlDateTimeDiffExtension.java │ │ ├── oracle │ │ ├── OracleAddOrSubDateExtension.java │ │ ├── OracleDateTimeDiffExtension.java │ │ └── OracleJoinExtension.java │ │ ├── pgsql │ │ ├── PostgreSQLAddOrSubDateExtension.java │ │ └── PostgreSQLDateTimeDiffExtension.java │ │ ├── sqlite │ │ ├── SqliteAddOrSubDateExtension.java │ │ ├── SqliteDateTimeDiffExtension.java │ │ └── SqliteJoinExtension.java │ │ └── types │ │ ├── Char.java │ │ ├── SqlTypes.java │ │ ├── TypeCastExtension.java │ │ └── Varchar.java └── pom.xml ├── drink-test ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── github │ │ └── kiryu1223 │ │ └── drink │ │ ├── handler │ │ └── GenderHandler.java │ │ ├── oldtest │ │ ├── BaseTest.java │ │ ├── DeleteTest.java │ │ ├── DepartmentTest.java │ │ ├── DisplayTest.java │ │ ├── InsertTest.java │ │ ├── QueryTest.java │ │ ├── SQLTest.java │ │ └── UpdateTest.java │ │ ├── pojos │ │ ├── Area.java │ │ ├── Department.java │ │ ├── DeptEmp.java │ │ ├── DeptManager.java │ │ ├── Employee.java │ │ ├── Gender.java │ │ ├── Salary.java │ │ ├── School.java │ │ ├── Titles.java │ │ ├── Top.java │ │ ├── Topic.java │ │ ├── UserAddress.java │ │ ├── UserDo.java │ │ └── UserDto.java │ │ └── test │ │ ├── DBConnectionTest.java │ │ ├── mssql │ │ ├── BaseTest.java │ │ ├── ControlTest.java │ │ ├── DateTimeTest.java │ │ ├── IncludeTest.java │ │ ├── JavaMethodsTest.java │ │ ├── LimitTest.java │ │ ├── LogicTest.java │ │ ├── MathTest.java │ │ └── StringTest.java │ │ ├── mysql │ │ ├── BaseTest.java │ │ ├── ControlTest.java │ │ ├── DateTimeTest.java │ │ ├── IncludeTest.java │ │ ├── JavaMethodsTest.java │ │ ├── LimitTest.java │ │ ├── LogicTest.java │ │ ├── MathTest.java │ │ ├── RunSpeedTest.java │ │ └── StringTest.java │ │ ├── oracle │ │ ├── BaseTest.java │ │ ├── ControlTest.java │ │ ├── DateTimeTest.java │ │ ├── IncludeTest.java │ │ ├── JavaMethodsTest.java │ │ ├── LimitTest.java │ │ ├── LogicTest.java │ │ ├── MathTest.java │ │ ├── RawSqlTest.java │ │ └── StringTest.java │ │ ├── pgsql │ │ ├── BaseTest.java │ │ ├── ControlTest.java │ │ ├── DateTimeTest.java │ │ ├── IncludeTest.java │ │ ├── JavaMethodsTest.java │ │ ├── LimitTest.java │ │ ├── LogicTest.java │ │ ├── MathTest.java │ │ ├── RunSpeedTest.java │ │ └── StringTest.java │ │ └── sqlite │ │ ├── BaseTest.java │ │ ├── ControlTest.java │ │ ├── DateTimeTest.java │ │ ├── IncludeTest.java │ │ ├── JavaMethodsTest.java │ │ ├── LimitTest.java │ │ ├── LogicTest.java │ │ ├── MathTest.java │ │ └── StringTest.java │ └── resources │ ├── logback.xml │ └── xxx.sql ├── pom.xml └── sample ├── pom.xml ├── project ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── github │ │ └── kiryu1223 │ │ └── project │ │ ├── Main.java │ │ ├── handler │ │ └── GenderHandler.java │ │ └── pojos │ │ ├── Course.java │ │ ├── Department.java │ │ ├── DeptEmp.java │ │ ├── DeptManager.java │ │ ├── Employee.java │ │ ├── Gender.java │ │ ├── ITenant.java │ │ ├── Klass.java │ │ ├── Salary.java │ │ ├── Student.java │ │ ├── StudentCourse.java │ │ └── Titles.java │ └── resources │ └── logback.xml ├── solon ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── github │ │ └── kiryu1223 │ │ └── app │ │ ├── SolonApp.java │ │ ├── config │ │ └── MyConfig.java │ │ ├── controller │ │ └── MyController.java │ │ ├── handler │ │ └── JsonTypeHandler.java │ │ ├── pojos │ │ ├── Department.java │ │ ├── DeptEmp.java │ │ ├── DeptManager.java │ │ ├── Employee.java │ │ ├── Gender.java │ │ ├── GenderConverter.java │ │ ├── Salary.java │ │ ├── Titles.java │ │ └── User.java │ │ └── service │ │ ├── EmployeeService.java │ │ └── MyService.java │ └── resources │ └── app.yml └── springboot ├── pom.xml └── src └── main ├── java └── io │ └── github │ └── kiryu1223 │ └── app │ ├── SpringApp.java │ ├── controller │ └── MyController.java │ ├── pojos │ ├── Department.java │ ├── DeptEmp.java │ ├── DeptManager.java │ ├── Employee.java │ ├── Gender.java │ ├── GenderConverter.java │ ├── Salary.java │ └── Titles.java │ └── service │ ├── EmployeeService.java │ └── MyService.java └── resources └── application.yml /drink-base/src/main/java/io/github/kiryu1223/drink/base/DbType.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base; 2 | 3 | public enum DbType 4 | { 5 | Any, 6 | MySQL, 7 | SQLServer, 8 | H2, 9 | Oracle, 10 | SQLite, 11 | PostgreSQL, 12 | } -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/IConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base; 2 | 3 | import io.github.kiryu1223.drink.base.converter.NameConverter; 4 | import io.github.kiryu1223.drink.base.dataSource.DataSourceManager; 5 | import io.github.kiryu1223.drink.base.expression.SqlExpressionFactory; 6 | import io.github.kiryu1223.drink.base.metaData.MetaData; 7 | import io.github.kiryu1223.drink.base.page.Pager; 8 | import io.github.kiryu1223.drink.base.session.SqlSessionFactory; 9 | import io.github.kiryu1223.drink.base.toBean.beancreator.BeanCreatorFactory; 10 | import io.github.kiryu1223.drink.base.transaction.TransactionManager; 11 | import io.github.kiryu1223.drink.base.transform.Transformer; 12 | 13 | public interface IConfig 14 | { 15 | SqlExpressionFactory getSqlExpressionFactory(); 16 | 17 | IDialect getDisambiguation(); 18 | 19 | DataSourceManager getDataSourceManager(); 20 | 21 | TransactionManager getTransactionManager(); 22 | 23 | SqlSessionFactory getSqlSessionFactory(); 24 | 25 | BeanCreatorFactory getBeanCreatorFactory(); 26 | 27 | Transformer getTransformer(); 28 | 29 | Pager getPager(); 30 | 31 | NameConverter getNameConverter(); 32 | 33 | MetaData getMetaData(Class c); 34 | 35 | Filter getFilter(); 36 | 37 | DbType getDbType(); 38 | 39 | boolean isPrintSql(); 40 | 41 | boolean isPrintBatch(); 42 | 43 | boolean isIgnoreDeleteNoWhere(); 44 | 45 | boolean isIgnoreUpdateNoWhere(); 46 | } 47 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/IDbSupport.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base; 2 | 3 | import io.github.kiryu1223.drink.base.expression.ISqlExpression; 4 | import io.github.kiryu1223.drink.base.expression.SqlExpressionFactory; 5 | import io.github.kiryu1223.drink.base.transform.Transformer; 6 | 7 | public interface IDbSupport 8 | { 9 | DbType getDbType(); 10 | IDialect getIDialect(); 11 | SqlExpressionFactory getSqlExpressionFactory(IConfig config); 12 | Transformer getTransformer(IConfig config); 13 | } 14 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/IDialect.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base; 2 | 3 | public interface IDialect 4 | { 5 | String disambiguation(String property); 6 | 7 | default String disambiguationTableName(String table) 8 | { 9 | return disambiguation(table); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/Column.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.annotation; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target(ElementType.FIELD) 11 | public @interface Column 12 | { 13 | /** 14 | * 是否为主键 15 | */ 16 | boolean primaryKey() default false; 17 | 18 | /** 19 | * 数据库列名 20 | */ 21 | String value() default ""; 22 | 23 | /** 24 | * 是否是数据库生成列(自增or默认值等) 25 | */ 26 | boolean generatedKey() default false; 27 | 28 | /** 29 | * 是否不为空 30 | */ 31 | boolean notNull() default false; 32 | } 33 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.annotation; 17 | 18 | 19 | /** 20 | * @author kiryu1223 21 | * @since 3.0 22 | */ 23 | @EmptyTable 24 | public final class Empty { 25 | } 26 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/EmptyTable.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface EmptyTable {} 11 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/IgnoreColumn.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.FIELD) 10 | public @interface IgnoreColumn 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/Navigate.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.annotation; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.metaData.IMappingTable; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.FIELD) 13 | public @interface Navigate 14 | { 15 | /** 16 | * 关联关系 17 | */ 18 | RelationType value(); 19 | 20 | /** 21 | * 目标类型(仅少数场合需要手动填写) 22 | */ 23 | Class targetType() default Empty.class; 24 | 25 | /** 26 | * 自身对应java字段名 27 | */ 28 | String self(); 29 | 30 | /** 31 | * 目标对应java字段名 32 | */ 33 | String target(); 34 | 35 | /** 36 | * 中间表,需要继承{@link io.github.kiryu1223.drink.base.metaData.ITable} 37 | */ 38 | Class mappingTable() default IMappingTable.class; 39 | 40 | /** 41 | * self对应的mapping表java字段名 42 | */ 43 | String selfMapping() default ""; 44 | 45 | /** 46 | * target对应的mapping表java字段名 47 | */ 48 | String targetMapping() default ""; 49 | } 50 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/RelationType.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.annotation; 2 | 3 | public enum RelationType 4 | { 5 | OneToOne, 6 | OneToMany, 7 | ManyToOne, 8 | ManyToMany; 9 | 10 | public boolean toMany() 11 | { 12 | return this == OneToMany || this == ManyToMany; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/Table.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface Table 11 | { 12 | /** 13 | * 所属 14 | */ 15 | String schema() default ""; 16 | /** 17 | * 数据库表名 18 | */ 19 | String value() default ""; 20 | } 21 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/annotation/UseTypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.annotation; 17 | 18 | 19 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 指定使用的TypeHandler,此处指定的TypeHandler优先级高于根据类型匹配的 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface UseTypeHandler { 32 | /** 33 | * 使用的TypeHandler的实现类(必须完全实现泛型) 34 | */ 35 | Class> value(); 36 | } 37 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/converter/NameConverter.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.converter; 2 | 3 | public class NameConverter 4 | { 5 | public String convertFieldName(String fieldName) 6 | { 7 | return fieldName; 8 | } 9 | 10 | public String convertTableName(String className) 11 | { 12 | return convertFieldName(className); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/converter/SnakeNameConverter.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.converter; 2 | 3 | public class SnakeNameConverter extends NameConverter 4 | { 5 | @Override 6 | public String convertFieldName(String fieldName) 7 | { 8 | return camelToSnake(fieldName); 9 | } 10 | 11 | public String camelToSnake(String str) { 12 | if (str == null || str.isEmpty()) { 13 | return str; 14 | } 15 | 16 | StringBuilder result = new StringBuilder(); 17 | result.append(Character.toLowerCase(str.charAt(0))); 18 | 19 | for (int i = 1; i < str.length(); i++) { 20 | char ch = str.charAt(i); 21 | if (Character.isUpperCase(ch)) { 22 | result.append('_'); 23 | result.append(Character.toLowerCase(ch)); 24 | } else { 25 | result.append(ch); 26 | } 27 | } 28 | 29 | return result.toString(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/dataSource/DataSourceManager.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.dataSource; 2 | 3 | import javax.sql.DataSource; 4 | import java.sql.Connection; 5 | import java.sql.SQLException; 6 | import java.util.Map; 7 | 8 | public interface DataSourceManager 9 | { 10 | /** 11 | * 获取连接 12 | */ 13 | Connection getConnection() throws SQLException; 14 | 15 | /** 16 | * 获取数据源 17 | */ 18 | DataSource getDataSource(); 19 | } -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/dataSource/DefaultDataSourceManager.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.dataSource; 2 | 3 | import javax.sql.DataSource; 4 | import java.sql.Connection; 5 | import java.sql.SQLException; 6 | import java.util.Map; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | 9 | public class DefaultDataSourceManager implements DataSourceManager 10 | { 11 | private final DataSource dataSource; 12 | 13 | public DefaultDataSourceManager(DataSource dataSource) { 14 | this.dataSource = dataSource; 15 | } 16 | 17 | @Override 18 | public Connection getConnection() throws SQLException { 19 | return getDataSource().getConnection(); 20 | } 21 | 22 | @Override 23 | public DataSource getDataSource() { 24 | return dataSource; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/exception/DrinkException.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.exception; 2 | 3 | public class DrinkException extends RuntimeException { 4 | public DrinkException(String message) { 5 | super(message); 6 | } 7 | 8 | public DrinkException() { 9 | } 10 | 11 | public DrinkException(Throwable cause) { 12 | super(cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/exception/SqlFunctionInvokeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.exception; 17 | 18 | /** 19 | * SQL函数调用异常 20 | * 21 | * @author kiryu1223 22 | * @since 3.0 23 | */ 24 | public class SqlFunctionInvokeException extends RuntimeException { 25 | public SqlFunctionInvokeException() { 26 | super("SqlFunction cannot be called from outside an expression"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/exception/Winner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.exception; 17 | 18 | /** 19 | * 报错工具(用于绕过idea的检查) 20 | * 21 | * @author kiryu1223 22 | * @since 3.0 23 | */ 24 | public final class Winner { 25 | private final static boolean win = true; 26 | 27 | public static void boom() { 28 | if (win) { 29 | throw new SqlFunctionInvokeException(); 30 | } 31 | } 32 | 33 | public static E error() { 34 | boom(); 35 | return (E) new Object(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/AsNameManager.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.util.DrinkUtil; 4 | 5 | import java.util.*; 6 | import java.util.stream.Collectors; 7 | 8 | public class AsNameManager { 9 | private static final ThreadLocal> displayNameMap = new ThreadLocal<>(); 10 | public static void start() { 11 | if (displayNameMap.get() == null) { 12 | displayNameMap.set(new HashMap<>()); 13 | } 14 | } 15 | 16 | public static void clear() { 17 | displayNameMap.remove(); 18 | } 19 | 20 | public static Map get() { 21 | return displayNameMap.get(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ExKey.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.metaData.FieldMetaData; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class ExKey { 9 | private final FieldMetaData fieldMetaData; 10 | private final String keyName; 11 | 12 | public ExKey(FieldMetaData fieldMetaData, String keyName) { 13 | this.fieldMetaData = fieldMetaData; 14 | this.keyName = keyName; 15 | } 16 | 17 | public FieldMetaData getFieldMetaData() { 18 | return fieldMetaData; 19 | } 20 | 21 | public String getKeyName() { 22 | return keyName; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ExKeys.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import java.util.*; 4 | 5 | public class ExKeys { 6 | private final ExKey[] exKeys; 7 | // hashcode key 8 | private final Map> valueMap=new HashMap<>(); 9 | 10 | public ExKeys(List exKeys) { 11 | this.exKeys = exKeys.toArray(new ExKey[0]); 12 | } 13 | 14 | public ExKey[] getExKeys() { 15 | return exKeys; 16 | } 17 | 18 | public void addValue(Integer key, Object value) { 19 | List objects = valueMap.computeIfAbsent(key, k -> new ArrayList<>()); 20 | objects.add(value); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ExValue.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.metaData.FieldMetaData; 4 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class ExValue { 10 | private final FieldMetaData fieldMetaData; 11 | private final List values = new ArrayList<>(); 12 | 13 | public ExValue(FieldMetaData fieldMetaData) { 14 | this.fieldMetaData = fieldMetaData; 15 | } 16 | 17 | public FieldMetaData getFieldMetaData() { 18 | return fieldMetaData; 19 | } 20 | 21 | public List getValues() { 22 | return values; 23 | } 24 | 25 | public void addValue(Object value) { 26 | values.add(value); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ExValues.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.metaData.FieldMetaData; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class ExValues { 11 | // key = value:xx 12 | private final Map exValueMap=new HashMap<>(); 13 | private final Map exKeyMap=new HashMap<>(); 14 | 15 | public Map getExValueMap() { 16 | return exValueMap; 17 | } 18 | 19 | public void addExValue(String key,FieldMetaData exValue){ 20 | exValueMap.put(key,exValue); 21 | } 22 | 23 | public Map getExKeyMap() { 24 | return exKeyMap; 25 | } 26 | 27 | public void addExKey(String key,FieldMetaData exKey){ 28 | exKeyMap.put(key,exKey); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlAsExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | 19 | import io.github.kiryu1223.drink.base.IConfig; 20 | 21 | /** 22 | * 别名表达式 23 | * 24 | * @author kiryu1223 25 | * @since 3.0 26 | */ 27 | public interface ISqlAsExpression extends ISqlExpression { 28 | /** 29 | * 获取被别名包裹的表达式 30 | */ 31 | ISqlExpression getExpression(); 32 | 33 | /** 34 | * 获取别名 35 | */ 36 | String getAsName(); 37 | 38 | @Override 39 | default ISqlAsExpression copy(IConfig config) { 40 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 41 | return factory.as(getExpression().copy(config), getAsName()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlConstStringExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | import io.github.kiryu1223.drink.base.IConfig; 19 | 20 | /** 21 | * 常量字符串 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public interface ISqlConstStringExpression extends ISqlExpression { 27 | /** 28 | * 获取常量字符串 29 | */ 30 | String getString(); 31 | 32 | @Override 33 | default ISqlConstStringExpression copy(IConfig config) { 34 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 35 | return factory.constString(getString()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlDeleteExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | public interface ISqlDeleteExpression extends ISqlExpression { 6 | ISqlFromExpression getFrom(); 7 | 8 | ISqlJoinsExpression getJoins(); 9 | 10 | ISqlWhereExpression getWhere(); 11 | 12 | void addJoin(ISqlJoinExpression join); 13 | 14 | void addWhere(ISqlExpression where); 15 | 16 | default void setWhere(ISqlConditionsExpression conditions) { 17 | getWhere().setConditions(conditions); 18 | } 19 | 20 | @Override 21 | default ISqlDeleteExpression copy(IConfig config) { 22 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 23 | return factory.delete(getFrom().copy(config), getJoins().copy(config), getWhere().copy(config)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlDynamicColumnExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.IDialect; 5 | 6 | public interface ISqlDynamicColumnExpression extends ISqlExpression { 7 | 8 | ISqlTableRefExpression getTableRefExpression(); 9 | 10 | String getColumn(); 11 | 12 | Class getColumnType(); 13 | 14 | default Class getType() { 15 | return getColumnType(); 16 | } 17 | 18 | @Override 19 | default ISqlDynamicColumnExpression copy(IConfig config) { 20 | IDialect dialect = config.getDisambiguation(); 21 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 22 | return factory.dynamicColumn(getColumn(), getColumnType(), getTableRefExpression()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlOrderExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | import io.github.kiryu1223.drink.base.IConfig; 19 | 20 | /** 21 | * 单个order(因为可能会指定升降序) 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public interface ISqlOrderExpression extends ISqlExpression { 27 | /** 28 | * 获取排序的目标 29 | */ 30 | ISqlExpression getExpression(); 31 | 32 | /** 33 | * 是否为升序 34 | */ 35 | boolean isAsc(); 36 | 37 | @Override 38 | default ISqlOrderExpression copy(IConfig config) { 39 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 40 | return factory.order(getExpression().copy(config), isAsc()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlParensExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | 19 | import io.github.kiryu1223.drink.base.IConfig; 20 | 21 | /** 22 | * 括号表达式 23 | * 24 | * @author kiryu1223 25 | * @since 3.0 26 | */ 27 | public interface ISqlParensExpression extends ISqlExpression { 28 | /** 29 | * 获取表达式 30 | */ 31 | ISqlExpression getExpression(); 32 | 33 | @Override 34 | default ISqlParensExpression copy(IConfig config) { 35 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 36 | return factory.parens(getExpression().copy(config)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlRealTableExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | import io.github.kiryu1223.drink.base.IConfig; 19 | 20 | /** 21 | * 实体table表达式 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public interface ISqlRealTableExpression extends ISqlTableExpression { 27 | @Override 28 | default ISqlRealTableExpression copy(IConfig config) { 29 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 30 | return factory.table(getMainTableClass()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlRecursionExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.metaData.FieldMetaData; 5 | 6 | public interface ISqlRecursionExpression extends ISqlWithExpression { 7 | ISqlQueryableExpression getQueryable(); 8 | 9 | String withTableName(); 10 | 11 | FieldMetaData parentId(); 12 | 13 | FieldMetaData childId(); 14 | 15 | int level(); 16 | 17 | @Override 18 | default ISqlRecursionExpression copy(IConfig config) { 19 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 20 | return factory.recursion(getQueryable().copy(config),parentId(),childId(),level()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlSetExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | 19 | import io.github.kiryu1223.drink.base.IConfig; 20 | 21 | /** 22 | * set表达式 23 | * 24 | * @author kiryu1223 25 | * @since 3.0 26 | */ 27 | public interface ISqlSetExpression extends ISqlExpression { 28 | /** 29 | * 获取列 30 | */ 31 | ISqlColumnExpression getColumn(); 32 | 33 | /** 34 | * 获取值 35 | */ 36 | ISqlExpression getValue(); 37 | 38 | @Override 39 | default ISqlSetExpression copy(IConfig config) { 40 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 41 | return factory.set(getColumn().copy(config), getValue().copy(config)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlStarExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | public interface ISqlStarExpression extends ISqlExpression 6 | { 7 | ISqlTableRefExpression getTableRefExpression(); 8 | 9 | @Override 10 | default ISqlStarExpression copy(IConfig config) 11 | { 12 | return config.getSqlExpressionFactory().star(getTableRefExpression()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlTableExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | /** 19 | * 抽象table表达式(可能是实体表也可能是虚拟表) 20 | * 21 | * @author kiryu1223 22 | * @since 3.0 23 | */ 24 | public interface ISqlTableExpression extends ISqlExpression { 25 | /** 26 | * 获取表类 27 | */ 28 | Class getMainTableClass(); 29 | 30 | default Class getType() { 31 | return getMainTableClass(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlTableRefExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | import java.util.Map; 6 | 7 | public interface ISqlTableRefExpression extends ISqlExpression { 8 | void setName(String name); 9 | String getName(); 10 | String getDisPlayName(); 11 | @Override 12 | default ISqlTableRefExpression copy(IConfig config) { 13 | return this; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlTypeCastExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | import io.github.kiryu1223.drink.base.IConfig; 19 | import io.github.kiryu1223.drink.base.session.SqlValue; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * 承载java类型,一般不调用他的getSql函数 25 | * 26 | * @author kiryu1223 27 | * @since 3.0 28 | */ 29 | public interface ISqlTypeCastExpression extends ISqlExpression { 30 | /** 31 | * 获取java类型 32 | */ 33 | Class getType(); 34 | ISqlExpression getExpression(); 35 | 36 | @Override 37 | default ISqlTypeCastExpression copy(IConfig config) { 38 | return config.getSqlExpressionFactory().typeCast(getType(),getExpression()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlUnaryExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | import io.github.kiryu1223.drink.base.IConfig; 19 | 20 | /** 21 | * 一元运算表达式 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public interface ISqlUnaryExpression extends ISqlExpression { 27 | /** 28 | * SQL运算符 29 | */ 30 | SqlOperator getOperator(); 31 | 32 | /** 33 | * 表达式 34 | */ 35 | ISqlExpression getExpression(); 36 | 37 | @Override 38 | default ISqlUnaryExpression copy(IConfig config) { 39 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 40 | return factory.unary(getOperator(), getExpression().copy(config)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlUnionQueryableExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.metaData.FieldMetaData; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public interface ISqlUnionQueryableExpression extends ISqlTableExpression { 10 | List getQueryable(); 11 | 12 | List getUnions(); 13 | 14 | @Override 15 | default Class getMainTableClass() { 16 | return getQueryable().get(0).getMainTableClass(); 17 | } 18 | 19 | default void addQueryable(ISqlQueryableExpression queryable, boolean union) { 20 | getQueryable().add(queryable); 21 | getUnions().add(union); 22 | } 23 | 24 | List getMappingData(IConfig config); 25 | 26 | default ISqlUnionQueryableExpression copy(IConfig config) { 27 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 28 | List copyQuery = new ArrayList<>(getQueryable().size()); 29 | List copyUnions = new ArrayList<>(getUnions().size()); 30 | for (ISqlQueryableExpression iSqlQueryableExpression : getQueryable()) { 31 | copyQuery.add(iSqlQueryableExpression.copy(config)); 32 | } 33 | copyUnions.addAll(getUnions()); 34 | return factory.unionQueryable(copyQuery, copyUnions); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlUpdateExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | public interface ISqlUpdateExpression extends ISqlExpression { 6 | ISqlFromExpression getFrom(); 7 | 8 | ISqlJoinsExpression getJoins(); 9 | 10 | ISqlSetsExpression getSets(); 11 | 12 | ISqlWhereExpression getWhere(); 13 | 14 | void addJoin(ISqlJoinExpression join); 15 | 16 | void addSet(ISqlSetExpression set); 17 | 18 | void addWhere(ISqlExpression where); 19 | 20 | default void setWhere(ISqlConditionsExpression conditions) { 21 | getWhere().setConditions(conditions); 22 | } 23 | 24 | @Override 25 | default ISqlUpdateExpression copy(IConfig config) { 26 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 27 | return factory.update(getFrom().copy(config), getJoins().copy(config), getSets().copy(config), getWhere().copy(config)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlValueExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | /** 19 | * 抽象值表达式 20 | * 21 | * @author kiryu1223 22 | * @since 3.0 23 | */ 24 | public interface ISqlValueExpression extends ISqlExpression { 25 | } 26 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/ISqlWithExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | import io.github.kiryu1223.drink.base.IConfig; 19 | 20 | /** 21 | * @author kiryu1223 22 | * @since 3.0 23 | */ 24 | public interface ISqlWithExpression extends ISqlTableExpression { 25 | ISqlQueryableExpression getQueryable(); 26 | 27 | String withTableName(); 28 | 29 | @Override 30 | default Class getMainTableClass() { 31 | return getQueryable().getMainTableClass(); 32 | } 33 | 34 | @Override 35 | default ISqlWithExpression copy(IConfig config) { 36 | SqlExpressionFactory factory = config.getSqlExpressionFactory(); 37 | return factory.with(getQueryable().copy(config), withTableName()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/JoinType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression; 17 | 18 | /** 19 | * Join类型 20 | * 21 | * @author kiryu1223 22 | * @since 3.0 23 | */ 24 | public enum JoinType { 25 | INNER, 26 | LEFT, 27 | RIGHT, 28 | ; 29 | 30 | public String getJoin() { 31 | return name() + " JOIN"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/impl/SqlConstStringExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression.impl; 17 | 18 | import io.github.kiryu1223.drink.base.IConfig; 19 | import io.github.kiryu1223.drink.base.expression.ISqlConstStringExpression; 20 | import io.github.kiryu1223.drink.base.session.SqlValue; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author kiryu1223 26 | * @since 3.0 27 | */ 28 | public class SqlConstStringExpression implements ISqlConstStringExpression { 29 | private final String string; 30 | 31 | protected SqlConstStringExpression(String string) { 32 | this.string = string; 33 | } 34 | 35 | public String getString() { 36 | return string; 37 | } 38 | 39 | @Override 40 | public String getSqlAndValue(IConfig config, List values) { 41 | return string; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/impl/SqlStarExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression.impl; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.expression.ISqlStarExpression; 5 | import io.github.kiryu1223.drink.base.expression.ISqlTableRefExpression; 6 | import io.github.kiryu1223.drink.base.session.SqlValue; 7 | 8 | import java.util.List; 9 | 10 | public class SqlStarExpression implements ISqlStarExpression 11 | { 12 | private final ISqlTableRefExpression tableRefExpression; 13 | 14 | public SqlStarExpression(ISqlTableRefExpression tableRefExpression) 15 | { 16 | this.tableRefExpression = tableRefExpression; 17 | } 18 | 19 | @Override 20 | public ISqlTableRefExpression getTableRefExpression() 21 | { 22 | return tableRefExpression; 23 | } 24 | 25 | @Override 26 | public String getSqlAndValue(IConfig config, List values) 27 | { 28 | if (tableRefExpression == null) 29 | { 30 | return "*"; 31 | } 32 | else 33 | { 34 | return tableRefExpression.getDisPlayName()+".*"; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/impl/SqlValueExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.expression.impl; 17 | 18 | 19 | import io.github.kiryu1223.drink.base.expression.ISqlValueExpression; 20 | 21 | /** 22 | * @author kiryu1223 23 | * @since 3.0 24 | */ 25 | public abstract class SqlValueExpression implements ISqlValueExpression { 26 | } 27 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/expression/impl/SqlWithExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.expression.impl; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.IDialect; 5 | import io.github.kiryu1223.drink.base.expression.ISqlQueryableExpression; 6 | import io.github.kiryu1223.drink.base.expression.ISqlWithExpression; 7 | import io.github.kiryu1223.drink.base.session.SqlValue; 8 | 9 | import java.util.List; 10 | 11 | public class SqlWithExpression implements ISqlWithExpression { 12 | 13 | protected final ISqlQueryableExpression queryable; 14 | protected final String name; 15 | 16 | protected SqlWithExpression(ISqlQueryableExpression queryable, String name) { 17 | this.queryable = queryable; 18 | this.name = name; 19 | } 20 | 21 | @Override 22 | public ISqlQueryableExpression getQueryable() { 23 | return queryable; 24 | } 25 | 26 | @Override 27 | public String withTableName() { 28 | return name; 29 | } 30 | 31 | @Override 32 | public String getSqlAndValue(IConfig config, List values) { 33 | IDialect disambiguation = config.getDisambiguation(); 34 | return disambiguation.disambiguationTableName(name) + " AS (" + queryable.getSqlAndValue(config, values) + ")"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/metaData/IMappingTable.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.metaData; 2 | 3 | public interface IMappingTable 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/page/DefaultPagedResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.page; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 默认分页结果 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public class DefaultPagedResult implements PagedResult { 27 | private final long total; 28 | private final List data; 29 | 30 | public DefaultPagedResult(long total, List data) { 31 | this.total = total; 32 | this.data = data; 33 | } 34 | 35 | @Override 36 | public long getTotal() { 37 | return total; 38 | } 39 | 40 | @Override 41 | public List getData() { 42 | return data; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/page/DefaultPager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.page; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 默认分页器 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public class DefaultPager implements Pager { 27 | @Override 28 | public PagedResult getPagedResult(long total, List data) { 29 | return new DefaultPagedResult<>(total, data); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/page/PagedResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.page; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 分页结果 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public interface PagedResult { 27 | /** 28 | * 获取总数 29 | */ 30 | long getTotal(); 31 | 32 | /** 33 | * 获取数据 34 | */ 35 | List getData(); 36 | } 37 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/page/Pager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 noear.org and authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kiryu1223.drink.base.page; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 分页器 22 | * 23 | * @author kiryu1223 24 | * @since 3.0 25 | */ 26 | public interface Pager { 27 | /** 28 | * 获取分页结果 29 | * 30 | * @param total 总数 31 | * @param data 数据 32 | */ 33 | PagedResult getPagedResult(long total, List data); 34 | } 35 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/session/DefaultSqlSessionFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.session; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.IConfig; 5 | import io.github.kiryu1223.drink.base.dataSource.DataSourceManager; 6 | import io.github.kiryu1223.drink.base.transaction.TransactionManager; 7 | 8 | public class DefaultSqlSessionFactory implements SqlSessionFactory 9 | { 10 | protected final DataSourceManager dataSourceManager; 11 | protected final TransactionManager transactionManager; 12 | 13 | public DefaultSqlSessionFactory(DataSourceManager dataSourceManager, TransactionManager transactionManager) 14 | { 15 | this.dataSourceManager = dataSourceManager; 16 | this.transactionManager = transactionManager; 17 | } 18 | 19 | @Override 20 | public SqlSession getSession(IConfig config) 21 | { 22 | return new DefaultSqlSession(dataSourceManager, transactionManager); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/session/SqlSession.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.session; 2 | 3 | 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.sql.*; 6 | import java.util.Collection; 7 | import java.util.List; 8 | 9 | public interface SqlSession 10 | { 11 | interface Function 12 | { 13 | R invoke(T t) throws SQLException, NoSuchFieldException, IllegalAccessException, InvocationTargetException; 14 | } 15 | 16 | /** 17 | * 执行查询,并返回结果 18 | * 19 | * @param func 对ResultSet进行操作并且返回结果 20 | * @param sql sql语句 21 | * @param sqlValues 参数 22 | */ 23 | R executeQuery(Function func, String sql, Collection sqlValues); 24 | 25 | /** 26 | * 执行插入,并返回影响行数 27 | * 28 | * @param sql sql语句 29 | * @param sqlValues 参数 30 | * @param length 批量下每轮的长度 31 | */ 32 | long executeInsert(String sql, Collection sqlValues, int length); 33 | 34 | /** 35 | * 执行更新,并返回影响行数 36 | * 37 | * @param sql sql语句 38 | * @param sqlValues 参数 39 | */ 40 | long executeUpdate(String sql, Collection sqlValues); 41 | 42 | /** 43 | * 执行删除,并返回影响行数 44 | * 45 | * @param sql sql语句 46 | * @param sqlValues 参数 47 | */ 48 | long executeDelete(String sql, Collection sqlValues); 49 | } 50 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/session/SqlSessionFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.session; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | public interface SqlSessionFactory 6 | { 7 | SqlSession getSession(IConfig config); 8 | } 9 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/session/SqlValue.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.session; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 5 | import io.github.kiryu1223.drink.base.toBean.handler.TypeHandlerManager; 6 | 7 | import java.sql.PreparedStatement; 8 | import java.sql.SQLException; 9 | 10 | import static com.sun.jmx.mbeanserver.Util.cast; 11 | 12 | public class SqlValue 13 | { 14 | /** 15 | * 值 16 | */ 17 | private final Object value; 18 | /** 19 | * 类型处理器 20 | */ 21 | private final ITypeHandler typeHandler; 22 | 23 | public SqlValue(Object value) { 24 | this(value, value == null ? TypeHandlerManager.getUnKnowTypeHandler() : TypeHandlerManager.get(value.getClass())); 25 | } 26 | 27 | public SqlValue(Object value, ITypeHandler typeHandler) { 28 | this.value = value; 29 | this.typeHandler = typeHandler; 30 | } 31 | 32 | /** 33 | * 设置进sql 34 | */ 35 | public void preparedStatementSetValue(PreparedStatement preparedStatement, int index) throws SQLException { 36 | typeHandler.setValue(preparedStatement, index, cast(value)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/BaseSqlExtension.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.expression.ISqlExpression; 5 | 6 | import java.lang.reflect.Method; 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | 11 | public abstract class BaseSqlExtension { 12 | public abstract ISqlExpression parse(IConfig config, Method sqlFunc, List args, boolean[] useSuper); 13 | 14 | public ISqlExpression callSuper(ISqlExpression superValue, ISqlExpression thisValue) { 15 | return thisValue; 16 | } 17 | 18 | private static final Map, BaseSqlExtension> sqlExtensionCache = new ConcurrentHashMap<>(); 19 | 20 | public static BaseSqlExtension getCache(Class c) { 21 | BaseSqlExtension baseSqlExtension = sqlExtensionCache.get(c); 22 | if (baseSqlExtension == null) { 23 | try { 24 | baseSqlExtension = c.newInstance(); 25 | sqlExtensionCache.put(c, baseSqlExtension); 26 | } catch (InstantiationException | IllegalAccessException e) { 27 | throw new RuntimeException(e); 28 | } 29 | } 30 | return baseSqlExtension; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/GroupJoinExtension.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | import io.github.kiryu1223.drink.base.expression.ISqlExpression; 5 | 6 | import java.lang.reflect.Method; 7 | import java.util.List; 8 | 9 | public class GroupJoinExtension extends BaseSqlExtension { 10 | @Override 11 | public ISqlExpression parse(IConfig config, Method sqlFunc, List args, boolean[] useSuper) { 12 | return config.getTransformer().groupJoin(args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/ISqlKeywords.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | public interface ISqlKeywords 6 | { 7 | String getKeyword(IConfig config); 8 | } 9 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/Range.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import io.github.kiryu1223.drink.base.exception.Winner; 4 | 5 | public final class Range { 6 | private Range() { 7 | } 8 | 9 | @SqlExtensionExpression(template = "CURRENT ROW") 10 | public static Range current() { 11 | return Winner.error(); 12 | } 13 | 14 | @SqlExtensionExpression(template = "UNBOUNDED PRECEDING") 15 | public static Range first() { 16 | return Winner.error(); 17 | } 18 | 19 | @SqlExtensionExpression(template = "{n} PRECEDING") 20 | public static Range prev(long n) { 21 | return Winner.error(); 22 | } 23 | 24 | @SqlExtensionExpression(template = "UNBOUNDED FOLLOWING") 25 | public static Range last() { 26 | return Winner.error(); 27 | } 28 | 29 | @SqlExtensionExpression(template = "{n} FOLLOWING") 30 | public static Range next(long n) { 31 | return Winner.error(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/Rows.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import io.github.kiryu1223.drink.base.exception.Winner; 4 | 5 | public final class Rows { 6 | private Rows() { 7 | } 8 | 9 | @SqlExtensionExpression(template = "CURRENT ROW") 10 | public static Rows current() { 11 | return Winner.error(); 12 | } 13 | 14 | @SqlExtensionExpression(template = "UNBOUNDED PRECEDING") 15 | public static Rows first() { 16 | return Winner.error(); 17 | } 18 | 19 | @SqlExtensionExpression(template = "{n} PRECEDING") 20 | public static Rows prev(long n) { 21 | return Winner.error(); 22 | } 23 | 24 | @SqlExtensionExpression(template = "UNBOUNDED FOLLOWING") 25 | public static Rows last() { 26 | return Winner.error(); 27 | } 28 | 29 | @SqlExtensionExpression(template = "{n} FOLLOWING") 30 | public static Rows next(long n) { 31 | return Winner.error(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/SqlExtensionExpression.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import io.github.kiryu1223.drink.base.DbType; 4 | 5 | import java.lang.annotation.*; 6 | 7 | @Retention(RetentionPolicy.RUNTIME) 8 | @Target(ElementType.METHOD) 9 | @Repeatable(SqlExtensionExpressions.class) 10 | public @interface SqlExtensionExpression 11 | { 12 | DbType dbType() default DbType.Any; 13 | 14 | String template(); 15 | 16 | String separator() default ","; 17 | 18 | Class extension() default BaseSqlExtension.class; 19 | } 20 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/SqlExtensionExpressions.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.METHOD) 10 | public @interface SqlExtensionExpressions 11 | { 12 | SqlExtensionExpression[] value(); 13 | } 14 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/SqlOperatorMethod.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.expression.SqlOperator; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface SqlOperatorMethod 14 | { 15 | SqlOperator value(); 16 | } 17 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/sqlExt/SqlTimeUnit.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.sqlExt; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | public enum SqlTimeUnit implements ISqlKeywords 6 | { 7 | YEAR, 8 | MONTH, 9 | WEEK, 10 | DAY, 11 | HOUR, 12 | MINUTE, 13 | SECOND, 14 | MILLISECOND, 15 | MICROSECOND, 16 | NANOSECOND, 17 | ; 18 | 19 | @Override 20 | public String getKeyword(IConfig config) 21 | { 22 | return name(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/table/TreeCte.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.table; 2 | 3 | import io.github.kiryu1223.drink.base.annotation.Table; 4 | 5 | @Table("as_tree_cte") 6 | public class TreeCte { 7 | } 8 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/beancreator/BeanCreatorFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.beancreator; 2 | 3 | import io.github.kiryu1223.drink.base.IConfig; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.ConcurrentHashMap; 7 | 8 | public class BeanCreatorFactory 9 | { 10 | private final IConfig config; 11 | 12 | private static final Map, AbsBeanCreator> cache = new ConcurrentHashMap<>(); 13 | 14 | public BeanCreatorFactory(IConfig config) 15 | { 16 | this.config = config; 17 | } 18 | 19 | protected AbsBeanCreator create(Class target) 20 | { 21 | return new DefaultBeanCreator<>(target,config); 22 | } 23 | 24 | public AbsBeanCreator get(Class target) 25 | { 26 | AbsBeanCreator creator = (AbsBeanCreator) cache.get(target); 27 | if (creator == null) 28 | { 29 | creator = create(target); 30 | cache.put(target, creator); 31 | } 32 | return creator; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/beancreator/IGetterCaller.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.beancreator; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | 5 | public interface IGetterCaller { 6 | R apply(T t)throws InvocationTargetException, IllegalAccessException; 7 | } 8 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/beancreator/ISetterCaller.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.beancreator; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | 5 | public interface ISetterCaller 6 | { 7 | void call(T t, Object value) throws InvocationTargetException, IllegalAccessException; 8 | } 9 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/beancreator/IVoidSetter.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.beancreator; 2 | 3 | public interface IVoidSetter 4 | { 5 | void apply(T1 t,T2 value); 6 | } 7 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/build/ExtensionField.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.build; 2 | 3 | import io.github.kiryu1223.drink.base.metaData.FieldMetaData; 4 | 5 | public class ExtensionField { 6 | private final FieldMetaData fieldMetaData; 7 | private final Object value; 8 | 9 | public ExtensionField(FieldMetaData fieldMetaData, Object value) { 10 | this.fieldMetaData = fieldMetaData; 11 | this.value = value; 12 | } 13 | 14 | public FieldMetaData getFieldMetaData() { 15 | return fieldMetaData; 16 | } 17 | 18 | public Object getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/build/ExtensionObject.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.build; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class ExtensionObject 8 | { 9 | private final List objects = new ArrayList<>(); 10 | private final Map extensionFieldMap; 11 | 12 | public ExtensionObject(Map extensionValueFieldMap) 13 | { 14 | this.extensionFieldMap = extensionValueFieldMap; 15 | } 16 | 17 | public List getObjects() 18 | { 19 | return objects; 20 | } 21 | 22 | public void addObject(Object o) 23 | { 24 | objects.add(o); 25 | } 26 | 27 | public Map getExtensionFieldMap() 28 | { 29 | return extensionFieldMap; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/handler/ITypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.handler; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | 9 | public interface ITypeHandler 10 | { 11 | T getValue(ResultSet resultSet, int index, Type type) throws SQLException; 12 | 13 | void setValue(PreparedStatement preparedStatement, int index, T value) throws SQLException; 14 | 15 | default Type getActualType() 16 | { 17 | Type[] genericInterfaces = this.getClass().getGenericInterfaces(); 18 | for (Type genericInterface : genericInterfaces) 19 | { 20 | if (genericInterface instanceof ParameterizedType) 21 | { 22 | ParameterizedType anInterface = (ParameterizedType) genericInterface; 23 | if (anInterface.getRawType() == ITypeHandler.class) 24 | { 25 | return anInterface.getActualTypeArguments()[0]; 26 | } 27 | } 28 | } 29 | throw new RuntimeException("未知的ITypeHandler实现类:" + this.getClass()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/handler/UnKnowTypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.handler; 2 | 3 | import java.lang.reflect.Type; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | public class UnKnowTypeHandler implements ITypeHandler 9 | { 10 | @Override 11 | public T getValue(ResultSet resultSet, int index, Type type) throws SQLException 12 | { 13 | if (type instanceof Class) { 14 | Class aClass = (Class) type; 15 | if (aClass.isEnum()) { 16 | return (T) Enum.valueOf((Class) type, resultSet.getString(index)); 17 | } 18 | else { 19 | return (T) resultSet.getObject(index, aClass); 20 | } 21 | } 22 | else { 23 | return (T) resultSet.getObject(index); 24 | } 25 | } 26 | 27 | @Override 28 | public void setValue(PreparedStatement preparedStatement, int index, T value) throws SQLException 29 | { 30 | preparedStatement.setObject(index, value); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/handler/impl/datetime/DateTypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.handler.impl.datetime; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 5 | 6 | import java.lang.reflect.Type; 7 | import java.sql.*; 8 | 9 | public class DateTypeHandler implements ITypeHandler { 10 | @Override 11 | public Date getValue(ResultSet resultSet, int index, Type type) throws SQLException { 12 | return resultSet.getDate(index); 13 | } 14 | 15 | @Override 16 | public void setValue(PreparedStatement preparedStatement, int index, Date date) throws SQLException { 17 | if (date == null) { 18 | preparedStatement.setNull(index, JDBCType.DATE.getVendorTypeNumber()); 19 | } 20 | else { 21 | preparedStatement.setDate(index, date); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/handler/impl/datetime/LocalDateTimeTypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.handler.impl.datetime; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 5 | 6 | import java.lang.reflect.Type; 7 | import java.sql.*; 8 | import java.time.LocalDateTime; 9 | 10 | public class LocalDateTimeTypeHandler implements ITypeHandler 11 | { 12 | @Override 13 | public LocalDateTime getValue(ResultSet resultSet, int index, Type type) throws SQLException 14 | { 15 | Timestamp timestamp = resultSet.getTimestamp(index); 16 | return timestamp == null ? null : timestamp.toLocalDateTime(); 17 | } 18 | 19 | @Override 20 | public void setValue(PreparedStatement preparedStatement, int index, LocalDateTime localDateTime) throws SQLException 21 | { 22 | if (localDateTime == null) { 23 | preparedStatement.setNull(index, JDBCType.TIMESTAMP.getVendorTypeNumber()); 24 | } 25 | else { 26 | preparedStatement.setTimestamp(index, Timestamp.valueOf(localDateTime)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/handler/impl/datetime/LocalDateTypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.handler.impl.datetime; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 5 | 6 | import java.lang.reflect.Type; 7 | import java.sql.*; 8 | import java.time.LocalDate; 9 | 10 | public class LocalDateTypeHandler implements ITypeHandler 11 | { 12 | @Override 13 | public LocalDate getValue(ResultSet resultSet, int index, Type type) throws SQLException 14 | { 15 | Date date = resultSet.getDate(index); 16 | return date == null ? null : date.toLocalDate(); 17 | } 18 | 19 | @Override 20 | public void setValue(PreparedStatement preparedStatement, int index, LocalDate localDate) throws SQLException 21 | { 22 | if (localDate == null) { 23 | preparedStatement.setNull(index, JDBCType.DATE.getVendorTypeNumber()); 24 | } 25 | else { 26 | preparedStatement.setDate(index, Date.valueOf(localDate)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/handler/impl/datetime/LocalTimeTypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.handler.impl.datetime; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 5 | 6 | import java.lang.reflect.Type; 7 | import java.sql.*; 8 | import java.time.LocalTime; 9 | 10 | public class LocalTimeTypeHandler implements ITypeHandler 11 | { 12 | @Override 13 | public LocalTime getValue(ResultSet resultSet, int index, Type type) throws SQLException 14 | { 15 | Time time = resultSet.getTime(index); 16 | return time == null ? null : time.toLocalTime(); 17 | } 18 | 19 | @Override 20 | public void setValue(PreparedStatement preparedStatement, int index, LocalTime localTime) throws SQLException 21 | { 22 | if (localTime == null) { 23 | preparedStatement.setNull(index, JDBCType.TIME.getVendorTypeNumber()); 24 | } 25 | else { 26 | preparedStatement.setTime(index, Time.valueOf(localTime)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /drink-base/src/main/java/io/github/kiryu1223/drink/base/toBean/handler/impl/datetime/TimeTypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kiryu1223.drink.base.toBean.handler.impl.datetime; 2 | 3 | 4 | import io.github.kiryu1223.drink.base.toBean.handler.ITypeHandler; 5 | 6 | import java.lang.reflect.Type; 7 | import java.sql.*; 8 | 9 | public class TimeTypeHandler implements ITypeHandler