public class TSQL extends Object
Modifier and Type | Field and Description |
---|---|
static Map<String,Object> |
EMPTE_MAP |
static ConcurrentHashMap<Integer,List<String[]>> |
PARSED_CONDICTIONS |
static AtomicInteger |
size |
Constructor and Description |
---|
TSQL() |
Modifier and Type | Method and Description |
---|---|
static String |
assembleSQLWithArray(String sqlStr,
Object[] args)
使用数组参数的属性组装SQL
|
static String |
assembleSQLWithMap(String sqlStr,
Map<String,Object> argMap)
使用argMap参数的KV组装SQL
SQL字符串中以:开始的相同字符串将被替换
|
static String |
assembleSQLWithObject(String sqlStr,
Object argObjectj)
使用argObjectj参数的属性组装SQL
|
static CallableStatement |
createCallableStatement(Connection conn,
String sqlStr,
Map<String,Object> params,
CallType[] callTypes)
创建PreparedStatement
|
static PreparedStatement |
createPreparedStatement(Connection conn,
String sqlStr,
Map<String,Object> params)
创建PreparedStatement
|
static String |
genMysqlPageSql(String sql,
int pageNumber,
int pageSize)
生成 Mysql 分页的 sql
|
static String |
genOraclePageSql(String sql,
int pageNumber,
int pageSize)
生成Oracle 分页的 sql
|
static String |
genPostgrePageSql(String sql,
int pageNumber,
int pageSize)
生成 Postgre 分页的 sql
|
static List<Map<String,Object>> |
getAllRowWithMapList(ResultSet resultSet)
包装resultSet中所有记录成List,单行元素为Map
|
static List<Object> |
getAllRowWithObjectList(Class<?> clazz,
ResultSet resultSet)
包装resultSet中所有记录成List,单行元素为指定对象
|
static List<Object> |
getCallableStatementResult(CallableStatement callableStatement)
解析存储过程结果集
|
static DataBaseType |
getDataBaseType(DataSource dataSource) |
static String |
getDataMethod(int databaseType)
根据 SQL 类型判断 Result 该使用什么方法取值
|
static Map<String,Object> |
getOneRowWithMap(ResultSet resultset)
包装resultSet中单行记录成Map
|
static Object |
getOneRowWithObject(Class<?> clazz,
ResultSet resultset)
包装resultSet中单行记录成指定对象
|
static List<String> |
getSqlParamNames(String sqlStr)
从 SQL 字符串中,取 SQL 参数表
|
static String |
getSQLString(Object argObj)
SQL的参数,将 JAVA 的类型转换成可在SQL中进行封装的字符串
例如:String类型的对象转换成 'chs'
|
static int |
getSqlTypes(Object obj)
根据 JAVA 类型判断该使用什么 SQL 数据类型
|
static List<String[]> |
parseSQLCondiction(String sqlText)
获取解析后的 SQL 的条件
|
static String |
preparedSql(String sqlStr)
转换preparedStatement对象为可用的 sql 字符串(参数用?表示)
|
static String |
removeEmptyCondiction(String sqlText,
Map<String,Object> params)
将SQL 语句中,没有提供查询参数的条件移除
|
static void |
setPreparedParams(PreparedStatement preparedStatement,
List<String> sqlParamNames,
Map<String,?> params)
给preparedStatement对象设置参数
|
static String |
wrapSqlField(JdbcOperate jdbcOperate,
String sqlField)
包括 SQL 关键字
|
public static ConcurrentHashMap<Integer,List<String[]>> PARSED_CONDICTIONS
public static AtomicInteger size
public static List<String> getSqlParamNames(String sqlStr)
sqlStr
- 原始 sql 字符串 (select * from table where x=::x and y=::y)public static String preparedSql(String sqlStr)
sqlStr
- 原始 sql 字符串 (select * from table where x=:x and y=::y)public static void setPreparedParams(PreparedStatement preparedStatement, List<String> sqlParamNames, Map<String,?> params) throws SQLException
preparedStatement
- preparedStatement对象sqlParamNames
- sql 参数表params
- 参数键值 MapSQLException
- SQL 异常public static PreparedStatement createPreparedStatement(Connection conn, String sqlStr, Map<String,Object> params) throws SQLException
conn
- 数据库连接sqlStr
- sql 自负穿params
- Map 参数SQLException
- SQL 异常public static CallableStatement createCallableStatement(Connection conn, String sqlStr, Map<String,Object> params, CallType[] callTypes) throws SQLException
conn
- 数据库连接sqlStr
- sql 自负穿params
- Map 参数callTypes
- 调用参数类型SQLException
- SQL 异常public static List<Object> getCallableStatementResult(CallableStatement callableStatement) throws SQLException
callableStatement
- callableStatement对象SQLException
- SQL 异常public static String assembleSQLWithArray(String sqlStr, Object[] args)
sqlStr
- SQL 字符串args
- 拼装参数public static String assembleSQLWithObject(String sqlStr, Object argObjectj) throws ReflectiveOperationException
sqlStr
- SQL 字符串argObjectj
- 拼装对象ReflectiveOperationException
- 反射异常public static String assembleSQLWithMap(String sqlStr, Map<String,Object> argMap)
sqlStr
- SQL 字符串argMap
- 拼装的 Mappublic static Map<String,Object> getOneRowWithMap(ResultSet resultset) throws SQLException, ReflectiveOperationException
resultset
- 查询结果集SQLException
- SQL 异常ReflectiveOperationException
- 反射异常public static Object getOneRowWithObject(Class<?> clazz, ResultSet resultset) throws SQLException, ReflectiveOperationException, ParseException
clazz
- 类对象resultset
- 查询结果集ReflectiveOperationException
- 反射异常SQLException
- SQL 异常ParseException
- 解析异常public static List<Map<String,Object>> getAllRowWithMapList(ResultSet resultSet) throws SQLException, ReflectiveOperationException
resultSet
- 查询结果集ReflectiveOperationException
- 反射异常SQLException
- SQL 异常public static List<Object> getAllRowWithObjectList(Class<?> clazz, ResultSet resultSet) throws SQLException, ReflectiveOperationException, ParseException
clazz
- 类resultSet
- 查询结果集ParseException
- 解析异常ReflectiveOperationException
- 反射异常SQLException
- SQL 异常public static String removeEmptyCondiction(String sqlText, Map<String,Object> params)
sqlText
- SQL 字符串params
- 参数集合public static List<String[]> parseSQLCondiction(String sqlText)
sqlText
- SQL 字符串public static String getSQLString(Object argObj)
argObj
- 转换前的对象public static String getDataMethod(int databaseType)
databaseType
- 数据库中的数据类型public static int getSqlTypes(Object obj)
obj
- 对象public static DataBaseType getDataBaseType(DataSource dataSource)
public static String wrapSqlField(JdbcOperate jdbcOperate, String sqlField)
jdbcOperate
- jdbcOperate 对象sqlField
- sql 关键字public static String genMysqlPageSql(String sql, int pageNumber, int pageSize)
sql
- Sql语句pageNumber
- 页码pageSize
- 页面记录数public static String genPostgrePageSql(String sql, int pageNumber, int pageSize)
sql
- Sql语句pageNumber
- 页码pageSize
- 页面记录数Copyright © 2020 Voovan. All rights reserved.