public class JdbcOperate extends Object implements Closeable
Constructor and Description |
---|
JdbcOperate(DataSource dataSource)
构造函数
|
JdbcOperate(DataSource dataSource,
boolean isTrancation)
构造函数
|
JdbcOperate(DataSource dataSource,
TranscationType transcationType)
构造函数
|
Modifier and Type | Method and Description |
---|---|
boolean |
addBind(JdbcOperate subJdbcOperate,
boolean bothway)
增加连接事务关联绑定
只能绑定 TranscationType 为 NEST 的事务
|
int[] |
batch(String[] sqlTexts)
执行数据库批量更新
|
int[] |
batchMap(String sqlText,
Collection<Map<String,Object>> maps)
执行数据库批量更新
|
int[] |
batchObject(String sqlText,
Collection<?> objects)
执行数据库批量更新 字段名和对象属性名大消息必须大小写一致
|
boolean |
beginTransaction()
开启事务
|
List<Object> |
call(String sqlText)
调用存储过程,无参数
|
List<Object> |
call(String sqlText,
CallType[] callTypes,
Map<String,Object> maps)
调用存储过程,map作为参数,字段名和Map键名大消息必须大小写一致
|
List<Object> |
call(String sqlText,
CallType[] callTypes,
Object... args)
调用存储过程,Array作为参数
|
List<Object> |
call(String sqlText,
CallType[] callTypes,
Object arg)
调用存储过程,对象作为参数
|
void |
close() |
protected static void |
closeConnection(ResultSet resultSet)
关闭连接
|
protected static void |
closeConnection(Statement statement)
关闭连接
|
protected static void |
closeResult(ResultSet resultSet)
关闭结果集
|
protected static void |
closeStatement(Statement statement)
关闭 Statement
|
void |
commit()
提交事务不关闭连接
|
void |
commit(boolean isClose)
提交事务
|
Connection |
getConnection()
获取连接
|
DataBaseType |
getDataBaseType()
获取数据库类型g
|
TranscationType |
getTranscationType()
返回当前事务形式
|
Map<String,Object> |
queryMap(String sqlText)
查询单行,返回 Map,无参数
|
Map<String,Object> |
queryMap(String sqlText,
Map<String,Object> mapArg)
查询单行,返回 Map,map作为参数,字段名和Map键名大消息必须大小写一致
|
Map<String,Object> |
queryMap(String sqlText,
Object... args)
查询单行,返回 Map,Array作为参数
|
Map<String,Object> |
queryMap(String sqlText,
Object arg)
查询单行,返回 Map,Object作为参数
|
List<Map<String,Object>> |
queryMapList(String sqlText)
查询对象集合,无参数
|
List<Map<String,Object>> |
queryMapList(String sqlText,
Map<String,Object> mapArg)
查询对象集合,map作为参数,字段名和Map键名大消息必须大小写一致
|
List<Map<String,Object>> |
queryMapList(String sqlText,
Object... args)
查询单个对象,Object作为参数
|
List<Map<String,Object>> |
queryMapList(String sqlText,
Object arg)
查询单个对象,Object作为参数
|
<T> T |
queryObject(String sqlText,
Class<T> t)
查询单个对象,无参数
|
<T> T |
queryObject(String sqlText,
Class<T> t,
Map<String,Object> mapArg)
查询单个对象,map作为参数,字段名和Map键名大消息必须大小写一致
|
<T> T |
queryObject(String sqlText,
Class<T> t,
Object... args)
查询单个对象,map作为参数,字段名和Map键名大消息必须大小写一致
|
<T> T |
queryObject(String sqlText,
Class<T> t,
Object arg)
查询单个对象,Object作为参数 字段名和对象属性名大消息必须大小写一致
|
<T> List<T> |
queryObjectList(String sqlText,
Class<T> t)
查询对象集合,无参数 字段名和对象属性名大消息必须大小写一致
|
<T> List<T> |
queryObjectList(String sqlText,
Class<T> t,
Map<String,Object> mapArg)
查询对象集合,map作为参数,字段名和Map键名大消息必须大小写一致
|
<T> List<T> |
queryObjectList(String sqlText,
Class<T> t,
Object... args)
查询对象集合,map作为参数,字段名和Map键名大消息必须大小写一致
|
<T> List<T> |
queryObjectList(String sqlText,
Class<T> t,
Object arg)
查询单个对象,Object作为参数 字段名和对象属性名大消息必须大小写一致
|
boolean |
removeBind(JdbcOperate subJdbcOperate,
boolean bothway)
移除连接事务绑定
|
void |
rollback()
回滚事务不关闭连接
|
void |
rollback(boolean isClose)
回滚事务
|
JdbcOperate |
setTranscationType(TranscationType transcationType)
设置当前事务类型
|
int |
update(String sqlText)
执行数据库更新
|
int |
update(String sqlText,
Map<String,Object> mapArg)
执行数据库更新,Map作为参数,字段名和Map键名大消息必须大小写一致
|
int |
update(String sqlText,
Object... args)
执行数据库更新,Map作为参数,字段名和Map键名大消息必须大小写一致
|
int |
update(String sqlText,
Object arg)
执行数据库更新,Object作为参数 字段名和对象属性名大消息必须大小写一致
|
int |
updateAndCheck(String sqlText,
int updateCount)
执行数据库更新
|
int |
updateAndCheck(String sqlText,
int updateCount,
Map<String,Object> mapArg)
执行数据库更新,Map作为参数,字段名和Map键名大消息必须大小写一致
|
int |
updateAndCheck(String sqlText,
int updateCount,
Object... args)
执行数据库更新,Map作为参数,字段名和Map键名大消息必须大小写一致
|
int |
updateAndCheck(String sqlText,
int updateCount,
Object arg)
执行数据库更新,Object作为参数 字段名和对象属性名大消息必须大小写一致
|
public JdbcOperate(DataSource dataSource)
dataSource
- 数据源public JdbcOperate(DataSource dataSource, boolean isTrancation)
dataSource
- 数据源isTrancation
- 是否启用事物支持, 默认使用的`NEST`(嵌套事务)的事物方式public JdbcOperate(DataSource dataSource, TranscationType transcationType)
dataSource
- 数据源transcationType
- 是否启用事务支持, 设置事务模式public DataBaseType getDataBaseType()
public boolean addBind(JdbcOperate subJdbcOperate, boolean bothway)
subJdbcOperate
- 连接操作对象bothway
- true: 双向绑定, false: 单向绑定,只建立当前连接和目标连接的绑定关系
双向绑定意味这任意一个节点的 commit 或者 rollback 操作都会直接联动所有的事物同时操作(提交/回滚), 如果是单向绑定,只会联动下级事物同时操作(提交/回滚)public boolean removeBind(JdbcOperate subJdbcOperate, boolean bothway)
subJdbcOperate
- 连接操作对象bothway
- true: 双向绑定, 解除当前连接和目标连接两个连接相互的绑定关系, : 单向绑定, 只解除当前连接和目标连接的绑定关系public Connection getConnection() throws SQLException
SQLException
- SQL 异常public boolean beginTransaction() throws SQLException
SQLException
- SQL 异常public TranscationType getTranscationType()
public JdbcOperate setTranscationType(TranscationType transcationType)
transcationType
- TranscationType 对象事务类型public void commit(boolean isClose) throws SQLException
isClose
- 是否关闭数据库连接SQLException
- SQL 异常public void rollback(boolean isClose) throws SQLException
isClose
- 是否关闭数据库连接SQLException
- SQL 异常public void commit() throws SQLException
SQLException
- SQL 异常public void rollback() throws SQLException
SQLException
- SQL 异常public int update(String sqlText) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idSQLException
- SQL 异常public int update(String sqlText, Object arg) throws SQLException, ReflectiveOperationException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idarg
- object为参数的对象ReflectiveOperationException
- 反射异常SQLException
- SQL 异常public int update(String sqlText, Map<String,Object> mapArg) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idmapArg
- map为参数的对象SQLException
- SQL 异常public int update(String sqlText, Object... args) throws SQLException
sqlText
- sql字符串 参数使用"::"作为索引标识,引导一个索引标识,索引标识从1开始,例如where id=::1args
- 多参数SQLException
- SQL 异常public int updateAndCheck(String sqlText, int updateCount) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idupdateCount
- 期望的更新记录数, 如果不符合会抛出异常SQLException
- SQL 异常public int updateAndCheck(String sqlText, int updateCount, Object arg) throws SQLException, ReflectiveOperationException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idupdateCount
- 期望的更新记录数, 如果不符合会抛出异常arg
- object为参数的对象ReflectiveOperationException
- 反射异常SQLException
- SQL 异常public int updateAndCheck(String sqlText, int updateCount, Map<String,Object> mapArg) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idupdateCount
- 期望的更新记录数, 如果不符合会抛出异常mapArg
- map为参数的对象SQLException
- SQL 异常public int updateAndCheck(String sqlText, int updateCount, Object... args) throws SQLException
sqlText
- sql字符串 参数使用"::"作为索引标识,引导一个索引标识,索引标识从1开始,例如where id=::1updateCount
- 期望的更新记录数, 如果不符合会抛出异常args
- 多参数SQLException
- SQL 异常public <T> List<T> queryObjectList(String sqlText, Class<T> t) throws SQLException
T
- 范型sqlText
- sql字符串t
- 对象模型SQLException
- SQL 异常public <T> List<T> queryObjectList(String sqlText, Class<T> t, Object arg) throws SQLException, ReflectiveOperationException
T
- 范型sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idarg
- Object参数t
- 对象模型ReflectiveOperationException
- 反射异常SQLException
- SQL 异常public <T> List<T> queryObjectList(String sqlText, Class<T> t, Map<String,Object> mapArg) throws SQLException
T
- 范型sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idmapArg
- map参数t
- 对象模型SQLException
- SQL 异常public <T> List<T> queryObjectList(String sqlText, Class<T> t, Object... args) throws SQLException
T
- 范型sqlText
- sql字符串 参数使用"::"作为索引标识,引导一个索引标识,索引标识从1开始,例如where id=::1args
- map参数t
- 对象模型SQLException
- SQL 异常public List<Map<String,Object>> queryMapList(String sqlText) throws SQLException
sqlText
- sql字符串SQLException
- SQL 异常public List<Map<String,Object>> queryMapList(String sqlText, Object arg) throws SQLException, ReflectiveOperationException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idarg
- Object参数ReflectiveOperationException
- 反射异常SQLException
- SQL 异常public List<Map<String,Object>> queryMapList(String sqlText, Map<String,Object> mapArg) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idmapArg
- map参数SQLException
- SQL 异常public List<Map<String,Object>> queryMapList(String sqlText, Object... args) throws SQLException
sqlText
- sql字符串 参数使用"::"作为索引标识,引导一个索引标识,索引标识从1开始,例如where id=::1args
- Object参数SQLException
- SQL 异常public <T> T queryObject(String sqlText, Class<T> t) throws SQLException
T
- 范型sqlText
- sql字符串t
- 对象模型SQLException
- SQL 异常public <T> T queryObject(String sqlText, Class<T> t, Object arg) throws SQLException, ReflectiveOperationException, ParseException
T
- 范型sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idt
- 对象模型arg
- Object参数ReflectiveOperationException
- 反射异常SQLException
- SQL 异常ParseException
- 解析异常public <T> T queryObject(String sqlText, Class<T> t, Map<String,Object> mapArg) throws SQLException
T
- 范型sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idmapArg
- map参数t
- 对象模型SQLException
- SQL 异常public <T> T queryObject(String sqlText, Class<T> t, Object... args) throws SQLException
T
- 范型sqlText
- sql字符串 参数使用"::"作为索引标识,引导一个索引标识,索引标识从1开始,例如where id=::1args
- map参数t
- 对象模型SQLException
- SQL 异常public Map<String,Object> queryMap(String sqlText) throws SQLException
sqlText
- sql字符串SQLException
- SQL 异常public Map<String,Object> queryMap(String sqlText, Object arg) throws SQLException, ReflectiveOperationException
sqlText
- sql字符串 参数使用"::"引导一个标识,例如where id=::id,中 id 就是标识。arg
- arg参数 属性指代SQL字符串的标识,属性值用于在SQL字符串中替换标识。SQLException
- SQL 异常ReflectiveOperationException
- 反射异常public Map<String,Object> queryMap(String sqlText, Map<String,Object> mapArg) throws SQLException
sqlText
- sql字符串 参数使用"::"引导一个标识,例如where id=::id,中 id 就是标识。mapArg
- map参数,key指代SQL字符串的标识,value用于在SQL字符串中替换标识。SQLException
- SQL 异常public Map<String,Object> queryMap(String sqlText, Object... args) throws SQLException
sqlText
- sql字符串 参数使用"::"引导一个索引标识,引导一个索引标识,索引标识从1开始,例如where id=::1args
- args参数SQLException
- SQL 异常public int[] batchObject(String sqlText, Collection<?> objects) throws SQLException, ReflectiveOperationException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idobjects
- 模型对象SQLException
- SQL 异常ReflectiveOperationException
- 反射异常public int[] batchMap(String sqlText, Collection<Map<String,Object>> maps) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idmaps
- 批量处理SQL的参数SQLException
- SQL 异常public int[] batch(String[] sqlTexts) throws SQLException
sqlTexts
- sql字符串SQLException
- SQL 异常public List<Object> call(String sqlText) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idSQLException
- SQL 异常public List<Object> call(String sqlText, CallType[] callTypes, Map<String,Object> maps) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idcallTypes
- 参数类型 IN,OUT,INOUT 可选maps
- map参数SQLException
- SQL 异常public List<Object> call(String sqlText, CallType[] callTypes, Object arg) throws SQLException, ReflectiveOperationException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idcallTypes
- 参数类型 IN,OUT,INOUT 可选arg
- 对象参数SQLException
- SQL 异常ReflectiveOperationException
- 反射异常public List<Object> call(String sqlText, CallType[] callTypes, Object... args) throws SQLException
sqlText
- sql字符串 参数使用"::"作为标识,例如where id=::idcallTypes
- 参数类型 IN,OUT,INOUT 可选args
- 多个连续参数SQLException
- SQL 异常protected static void closeConnection(ResultSet resultSet)
resultSet
- 结果集protected static void closeConnection(Statement statement)
statement
- Statement 对象protected static void closeResult(ResultSet resultSet)
resultSet
- 结果集protected static void closeStatement(Statement statement)
statement
- Statement 对象public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2020 Voovan. All rights reserved.