Package com.imyeyu.spring.util
Class BaseSQLProvider
java.lang.Object
com.imyeyu.spring.util.BaseSQLProvider
- Direct Known Subclasses:
DynamicTableSQLProvider,SQLProvider
SQL 提供器基类
包含所有 SQL 构建逻辑和实体元数据管理
- Since:
- 2026-01-07 11:20
- Author:
- 夜雨
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class实体元数据protected static class实体字段属性 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendOrderBy(StringBuilder sql, BaseSQLProvider.EntityMeta meta, Page<?> page) 添加排序子句protected voidappendPageConditions(StringBuilder sql, Page<?> page) 添加 Page 查询条件(精准查询和模糊查询)protected void添加软删除条件protected StringbuildCountByPageSQL(BaseSQLProvider.EntityMeta meta, String tableName, Page<?> page) 构建分页统计 SQLprotected StringbuildDeleteAllByExampleSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix, Logic logic) 构建批量逻辑删除 SQLprotected StringbuildDeleteSQL(BaseSQLProvider.EntityMeta meta, String tableName, String idParam) 构建软删除 SQLprotected StringbuildDestroyAllByExampleSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix, Logic logic) 构建批量物理删除 SQLprotected StringbuildDestroySQL(BaseSQLProvider.EntityMeta meta, String tableName, String idParam) 构建硬删除 SQLprotected StringbuildExampleConditions(BaseSQLProvider.EntityMeta meta, Object entity, String paramPrefix, Logic logic) 构建示例查询条件子句protected StringbuildInsertSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix) 构建插入 SQLprotected StringbuildSelectAllByExampleSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix, Logic logic) 构建根据示例查询全部 SQLprotected StringbuildSelectByIdSQL(BaseSQLProvider.EntityMeta meta, String tableName, String idParam) 构建根据 ID 查询 SQLprotected StringbuildSelectByPageSQL(BaseSQLProvider.EntityMeta meta, String tableName, Page<?> page, String offset, String limit) 构建分页查询 SQLprotected StringbuildUpdateSelectiveSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix) 构建选择性更新 SQLprotected StringbuildUpdateSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix) 构建更新 SQLprotected BaseSQLProvider.EntityMetagetEntityMeta(Class<?> entityClass) 获取实体类元数据protected BaseSQLProvider.EntityMetagetEntityMeta(org.apache.ibatis.builder.annotation.ProviderContext context) 根据代理器上下文获取 Mapper 实体类元数据
-
Constructor Details
-
BaseSQLProvider
public BaseSQLProvider()
-
-
Method Details
-
getEntityMeta
protected BaseSQLProvider.EntityMeta getEntityMeta(org.apache.ibatis.builder.annotation.ProviderContext context) 根据代理器上下文获取 Mapper 实体类元数据- Parameters:
context- 代理器上下文- Returns:
- 实体类元数据
-
getEntityMeta
获取实体类元数据- Parameters:
entityClass- 实体类- Returns:
- 元数据
-
buildSelectByPageSQL
protected String buildSelectByPageSQL(BaseSQLProvider.EntityMeta meta, String tableName, Page<?> page, String offset, String limit) 构建分页查询 SQL- Parameters:
meta- 实体元数据tableName- 表名page- 分页参数offset- 偏移量占位符limit- 限制数量占位符- Returns:
- SQL
-
buildCountByPageSQL
protected String buildCountByPageSQL(BaseSQLProvider.EntityMeta meta, String tableName, Page<?> page) 构建分页统计 SQL- Parameters:
meta- 实体元数据tableName- 表名page- 分页参数- Returns:
- SQL
-
appendSoftDeleteCondition
添加软删除条件- Parameters:
sql- SQL 构建器meta- 实体元数据
-
appendPageConditions
添加 Page 查询条件(精准查询和模糊查询)- Parameters:
sql- SQL 构建器page- 分页参数
-
appendOrderBy
添加排序子句- Parameters:
sql- SQL 构建器meta- 实体元数据page- 分页参数
-
buildExampleConditions
protected String buildExampleConditions(BaseSQLProvider.EntityMeta meta, Object entity, String paramPrefix, Logic logic) 构建示例查询条件子句- Parameters:
meta- 实体元数据entity- 示例实体paramPrefix- 参数前缀(如 "entity."),空字符串表示无前缀logic- 条件连接逻辑- Returns:
- 条件子句
-
buildInsertSQL
protected String buildInsertSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix) 构建插入 SQL- Parameters:
meta- 实体元数据tableName- 表名entity- 实体对象paramPrefix- 参数前缀(如 "entity."),空字符串表示无前缀- Returns:
- SQL
-
buildSelectByIdSQL
protected String buildSelectByIdSQL(BaseSQLProvider.EntityMeta meta, String tableName, String idParam) 构建根据 ID 查询 SQL- Parameters:
meta- 实体元数据tableName- 表名idParam- ID 参数占位符(如 "id")- Returns:
- SQL
-
buildSelectAllByExampleSQL
protected String buildSelectAllByExampleSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix, Logic logic) 构建根据示例查询全部 SQL- Parameters:
meta- 实体元数据tableName- 表名entity- 示例实体paramPrefix- 参数前缀(如 "entity."),空字符串表示无前缀logic- 条件连接逻辑- Returns:
- SQL
-
buildUpdateSQL
protected String buildUpdateSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix) 构建更新 SQL- Parameters:
meta- 实体元数据tableName- 表名entity- 实体对象paramPrefix- 参数前缀(如 "entity."),空字符串表示无前缀- Returns:
- SQL
-
buildUpdateSelectiveSQL
protected String buildUpdateSelectiveSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix) 构建选择性更新 SQL- Parameters:
meta- 实体元数据tableName- 表名entity- 实体对象paramPrefix- 参数前缀(如 "entity."),空字符串表示无前缀- Returns:
- SQL
-
buildDeleteSQL
构建软删除 SQL- Parameters:
meta- 实体元数据tableName- 表名idParam- ID 参数占位符(如 "id")- Returns:
- SQL
-
buildDeleteAllByExampleSQL
protected String buildDeleteAllByExampleSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix, Logic logic) 构建批量逻辑删除 SQL- Parameters:
meta- 实体元数据tableName- 表名entity- 示例实体paramPrefix- 参数前缀(如 "entity."),空字符串表示无前缀logic- 条件连接逻辑- Returns:
- SQL
-
buildDestroySQL
构建硬删除 SQL- Parameters:
meta- 实体元数据tableName- 表名idParam- ID 参数占位符(如 "id")- Returns:
- SQL
-
buildDestroyAllByExampleSQL
protected String buildDestroyAllByExampleSQL(BaseSQLProvider.EntityMeta meta, String tableName, Object entity, String paramPrefix, Logic logic) 构建批量物理删除 SQL- Parameters:
meta- 实体元数据tableName- 表名entity- 示例实体paramPrefix- 参数前缀(如 "entity."),空字符串表示无前缀logic- 条件连接逻辑- Returns:
- SQL
-