类 DbBase
- java.lang.Object
-
- ai.yue.library.data.jdbc.client.DbBase
-
- 直接已知子类:
AnsiDialect,Db
public class DbBase extends Object
SQL优化型数据库操作
Created by sunJinChuan on 2016/6/6- 从以下版本开始:
- 0.0.1
- 作者:
- ylyue
-
-
构造器概要
构造器 构造器 说明 DbBase()
-
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected voidaop(String tableName, com.alibaba.fastjson.JSONObject paramJson)DataSourcegetDataSource()获得数据源StringgetDeleteWhereSql()JdbcPropertiesgetJdbcProperties()org.springframework.jdbc.core.JdbcTemplategetJdbcTemplate()org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplategetNamedParameterJdbcTemplate()<T> org.springframework.jdbc.core.RowMapper<T>getRowMapper(Class<T> mappedClass)booleanisDataSize(long dataSize)已过时。请自行条件判断booleanisUpdateAndExpectedEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 等于 预期值booleanisUpdateAndExpectedGreaterThanEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 大于等于 预期值<T> TlistResultToGetResult(List<T> list)多行查询结果转换为单行查询结果voidparamFormat(com.alibaba.fastjson.JSONObject paramJson)参数美化(对SpringJDBC不支持的类型进行转换与布尔值映射识别)StringparamToWhereSql(com.alibaba.fastjson.JSONObject paramJson)绝对条件查询参数whereSql化StringparamToWhereSql(com.alibaba.fastjson.JSONObject paramJson, String... conditions)绝对条件查询参数whereSql化protected voidparamValidate(String tableName)参数验证protected voidparamValidate(String tableName, com.alibaba.fastjson.JSONObject paramJson)参数验证protected voidparamValidate(String tableName, com.alibaba.fastjson.JSONObject[] paramJsons)参数验证protected voidparamValidate(String tableName, com.alibaba.fastjson.JSONObject paramJson, String[] conditions)参数验证protected voidparamValidate(String tableName, Long id)参数验证protected voidparamValidate(String tableName, Long id, String[] fieldName)参数验证protected voidparamValidate(String tableName, String whereSql)参数验证protected voidparamValidate(String tableName, String... columnNames)参数验证com.alibaba.fastjson.JSONObjectqueryForJson(String sql, com.alibaba.fastjson.JSONObject paramJson)查询一行数据List<com.alibaba.fastjson.JSONObject>queryForList(String sql, com.alibaba.fastjson.JSONObject paramJson)查询多行数据<T> List<T>queryForList(String sql, com.alibaba.fastjson.JSONObject paramJson, Class<T> mappedClass)查询多行数据<T> TqueryForObject(String sql, com.alibaba.fastjson.JSONObject paramJson, Class<T> mappedClass)查询一行数据org.springframework.jdbc.support.rowset.SqlRowSetqueryForRowSet(String sql, com.alibaba.fastjson.JSONObject paramJson)查询多行数据com.alibaba.fastjson.JSONObjectresultToJson(List<com.alibaba.fastjson.JSONObject> list)已过时。<T> TresultToObject(List<T> list)已过时。voidsetDataSource(DataSource dataSource)设置数据源voidupdateAndExpectedEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 等于 预期值voidupdateAndExpectedGreaterThanEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 大于等于 预期值voidupdateBatchAndExpectedEqual(int[] updateRowsNumberArray, int expectedValue)确认批量更新每组参数所影响的行数,是否 全部都等于 同一个预期值
-
-
-
字段详细资料
-
dialect
protected Dialect dialect
-
-
方法详细资料
-
getDataSource
public DataSource getDataSource()
获得数据源- 返回:
- 数据源
-
setDataSource
public void setDataSource(DataSource dataSource)
设置数据源- 参数:
dataSource- 数据源
-
getNamedParameterJdbcTemplate
public org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate getNamedParameterJdbcTemplate()
-
getJdbcTemplate
public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()
-
getJdbcProperties
public JdbcProperties getJdbcProperties()
-
getRowMapper
public <T> org.springframework.jdbc.core.RowMapper<T> getRowMapper(Class<T> mappedClass)
-
listResultToGetResult
public <T> T listResultToGetResult(List<T> list)
多行查询结果转换为单行查询结果为 queryForObject(String, JSONObject, Class) 提供安全的查询结果获取
为 queryForJson(String, JSONObject) 提供安全的查询结果获取
- 参数:
list- 多行查询结果- 返回:
- 根据如下规则,返回正确的单行查询结果:
- size < 1 return null
- size = 1 return list.get(0)
- size > 1 throw Exception
-
resultToJson
@Deprecated public com.alibaba.fastjson.JSONObject resultToJson(List<com.alibaba.fastjson.JSONObject> list)
已过时。为 queryForJson(String, JSONObject) 提供安全的查询结果获取- 参数:
list- queryForList(String, JSONObject) 查询结果- 返回:
- JSON数据
-
resultToObject
@Deprecated public <T> T resultToObject(List<T> list)
已过时。为 queryForObject(String, JSONObject, Class) 提供安全的查询结果获取- 类型参数:
T- 泛型- 参数:
list- queryForList(String, JSONObject, Class) 查询结果- 返回:
- POJO对象
-
queryForJson
public com.alibaba.fastjson.JSONObject queryForJson(String sql, com.alibaba.fastjson.JSONObject paramJson)
查询一行数据对 NamedParameterJdbcTemplate.queryForMap(String, Map) 方法的优化实现
- 参数:
sql- 要执行的SQL查询paramJson- 要绑定到查询的参数映射- 返回:
- 可以是一个正确的单行查询结果、或null、或查询结果是多条数据而引发的预期错误异常
-
queryForObject
public <T> T queryForObject(String sql, com.alibaba.fastjson.JSONObject paramJson, Class<T> mappedClass)
查询一行数据对 NamedParameterJdbcTemplate.queryForObject(String, Map, org.springframework.jdbc.core.RowMapper) 方法的优化实现
- 参数:
sql- 要执行的SQL查询paramJson- 要绑定到查询的参数映射mappedClass- 查询结果映射类型,支持JavaBean与简单类型(如:Long, String, Boolean)- 返回:
- 可以是一个正确的单行查询结果、或null、或查询结果是多条数据而引发的预期错误异常
-
queryForRowSet
public org.springframework.jdbc.support.rowset.SqlRowSet queryForRowSet(String sql, com.alibaba.fastjson.JSONObject paramJson)
查询多行数据同 NamedParameterJdbcTemplate.queryForRowSet(String, Map)
- 参数:
sql- 要执行的SQL查询paramJson- 要绑定到查询的参数映射- 返回:
- 可用于方便的获取各种数据类型的结果集
-
queryForList
public List<com.alibaba.fastjson.JSONObject> queryForList(String sql, com.alibaba.fastjson.JSONObject paramJson)
查询多行数据对
NamedParameterJdbcTemplate.queryForList(String, Map)方法的优化实现- 参数:
sql- 要执行的查询SQLparamJson- 要绑定到查询的参数映射- 返回:
- 多行查询结果
-
queryForList
public <T> List<T> queryForList(String sql, com.alibaba.fastjson.JSONObject paramJson, Class<T> mappedClass)
查询多行数据对 NamedParameterJdbcTemplate.queryForList(String, Map, Class) 方法的优化实现
- 参数:
sql- 要执行的查询SQLparamJson- 要绑定到查询的参数映射mappedClass- 查询结果映射类型,支持JavaBean与简单类型(如:Long, String, Boolean)- 返回:
- 多行查询结果
-
isDataSize
@Deprecated public boolean isDataSize(long dataSize)
已过时。请自行条件判断是否有数据- 参数:
dataSize- 数据大小- 返回:
- 是否 > 0
-
isUpdateAndExpectedEqual
public boolean isUpdateAndExpectedEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 等于 预期值若不是预期值,同时 updateRowsNumber > 0 那么将会抛出一个 DbException
- 参数:
updateRowsNumber- 更新所影响的行数expectedValue- 预期值- 返回:
- 是否 等于 预期值
-
isUpdateAndExpectedGreaterThanEqual
public boolean isUpdateAndExpectedGreaterThanEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 大于等于 预期值若不是预期结果,同时 updateRowsNumber < expectedValue 那么将会抛出一个DbException
- 参数:
updateRowsNumber- 更新所影响的行数expectedValue- 预期值- 返回:
- 是否 大于等于 预期值
-
updateAndExpectedEqual
public void updateAndExpectedEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 等于 预期值若不是预期值,那么将会抛出一个DbException
- 参数:
updateRowsNumber- 更新所影响的行数expectedValue- 预期值
-
updateAndExpectedGreaterThanEqual
public void updateAndExpectedGreaterThanEqual(long updateRowsNumber, int expectedValue)判断更新所影响的行数是否 大于等于 预期值若不是预期结果,那么将会抛出一个DbException
- 参数:
updateRowsNumber- 更新所影响的行数expectedValue- 预期值
-
updateBatchAndExpectedEqual
public void updateBatchAndExpectedEqual(int[] updateRowsNumberArray, int expectedValue)确认批量更新每组参数所影响的行数,是否 全部都等于 同一个预期值若不是预期值,那么将会抛出一个DbException
- 参数:
updateRowsNumberArray- 每组参数更新所影响的行数数组expectedValue- 预期值
-
paramToWhereSql
public String paramToWhereSql(com.alibaba.fastjson.JSONObject paramJson, String... conditions)
绝对条件查询参数whereSql化已对 NULL 值进行特殊处理(IS NULL)
已对 List 类型值进行特殊处理(IN (?, ?))
结果示例:
WHERE 1 = 1
AND
param1 = :param1
AND
param2 IS NULL :param2
AND
param3 IN :param3
AND ...- 参数:
paramJson- 参数conditions- where条件(对应paramJson key)- 返回:
- whereSql
-
paramToWhereSql
public String paramToWhereSql(com.alibaba.fastjson.JSONObject paramJson)
绝对条件查询参数whereSql化已对 NULL 值进行特殊处理(IS NULL)
已对 List 类型值进行特殊处理(IN (?, ?))
结果示例:
WHERE 1 = 1
AND
param1 = :param1
AND
param2 IS NULL :param2
AND
param3 IN :param3
AND ...- 参数:
paramJson- 参数- 返回:
- whereSql
-
getDeleteWhereSql
public String getDeleteWhereSql()
- 返回:
- 逻辑删除条件SQL
-
paramValidate
protected void paramValidate(String tableName)
参数验证- 参数:
tableName- 表名
-
paramValidate
protected void paramValidate(String tableName, String whereSql)
参数验证- 参数:
tableName- 表名whereSql- 条件sql
-
paramValidate
protected void paramValidate(String tableName, Long id)
参数验证- 参数:
tableName- 表名id- 主键ID
-
paramValidate
protected void paramValidate(String tableName, String... columnNames)
参数验证- 参数:
tableName- 表名columnNames- 列名
-
paramValidate
protected void paramValidate(String tableName, Long id, String[] fieldName)
参数验证- 参数:
tableName- 表名id- 主键IDfieldName- 字段名称
-
paramValidate
protected void paramValidate(String tableName, com.alibaba.fastjson.JSONObject paramJson)
参数验证- 参数:
tableName- 表名paramJson- 参数
-
paramValidate
protected void paramValidate(String tableName, com.alibaba.fastjson.JSONObject[] paramJsons)
参数验证- 参数:
tableName- 表名paramJsons- 参数数组
-
paramValidate
protected void paramValidate(String tableName, com.alibaba.fastjson.JSONObject paramJson, String[] conditions)
参数验证- 参数:
tableName- 表名paramJson- 参数conditions- 条件(对应paramJson key)
-
paramFormat
public void paramFormat(com.alibaba.fastjson.JSONObject paramJson)
参数美化(对SpringJDBC不支持的类型进行转换与布尔值映射识别)Character 转 String
JSONObject 转 JsonString
LocalDataTime 转 Date
- 参数:
paramJson- 需要进行类型处理的paramJson
-
aop
protected void aop(String tableName, com.alibaba.fastjson.JSONObject paramJson)
-
-