mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
c84db9070a
commit
207b7b1687
@ -78,10 +78,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql 查询语句
|
* @param sql 查询语句
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.1.1
|
* @since 3.1.1
|
||||||
*/
|
*/
|
||||||
public List<Entity> query(final String sql, final Map<String, Object> params) throws DbRuntimeException {
|
public List<Entity> query(final String sql, final Map<String, Object> params) throws DbException {
|
||||||
return query(sql, new EntityListHandler(this.caseInsensitive), params);
|
return query(sql, new EntityListHandler(this.caseInsensitive), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,10 +91,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql 查询语句
|
* @param sql 查询语句
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.1.1
|
* @since 3.1.1
|
||||||
*/
|
*/
|
||||||
public List<Entity> query(final String sql, final Object... params) throws DbRuntimeException {
|
public List<Entity> query(final String sql, final Object... params) throws DbException {
|
||||||
return query(sql, new EntityListHandler(this.caseInsensitive), params);
|
return query(sql, new EntityListHandler(this.caseInsensitive), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,10 +106,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param beanClass 元素Bean类型
|
* @param beanClass 元素Bean类型
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.2.2
|
* @since 3.2.2
|
||||||
*/
|
*/
|
||||||
public <T> List<T> query(final String sql, final Class<T> beanClass, final Object... params) throws DbRuntimeException {
|
public <T> List<T> query(final String sql, final Class<T> beanClass, final Object... params) throws DbException {
|
||||||
return query(sql, new BeanListHandler<>(beanClass), params);
|
return query(sql, new BeanListHandler<>(beanClass), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,9 +119,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql 查询语句
|
* @param sql 查询语句
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Entity queryOne(final String sql, final Object... params) throws DbRuntimeException {
|
public Entity queryOne(final String sql, final Object... params) throws DbException {
|
||||||
return query(sql, new EntityHandler(this.caseInsensitive), params);
|
return query(sql, new EntityHandler(this.caseInsensitive), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,9 +131,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql 查询语句
|
* @param sql 查询语句
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Number queryNumber(final String sql, final Object... params) throws DbRuntimeException {
|
public Number queryNumber(final String sql, final Object... params) throws DbException {
|
||||||
return query(sql, new NumberHandler(), params);
|
return query(sql, new NumberHandler(), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +143,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql 查询语句
|
* @param sql 查询语句
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public String queryString(final String sql, final Object... params) throws DbRuntimeException {
|
public String queryString(final String sql, final Object... params) throws DbException {
|
||||||
return query(sql, new StringHandler(), params);
|
return query(sql, new StringHandler(), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,9 +157,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T query(final String sql, final RsHandler<T> rsh, final Object... params) throws DbRuntimeException {
|
public <T> T query(final String sql, final RsHandler<T> rsh, final Object... params) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -177,10 +177,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param paramMap 参数
|
* @param paramMap 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.2.2
|
* @since 5.2.2
|
||||||
*/
|
*/
|
||||||
public <T> T query(final String sql, final RsHandler<T> rsh, final Map<String, Object> paramMap) throws DbRuntimeException {
|
public <T> T query(final String sql, final RsHandler<T> rsh, final Map<String, Object> paramMap) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -198,10 +198,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param statementFunc 自定义{@link PreparedStatement}创建函数
|
* @param statementFunc 自定义{@link PreparedStatement}创建函数
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.7.17
|
* @since 5.7.17
|
||||||
*/
|
*/
|
||||||
public <T> T query(final SerFunction<Connection, PreparedStatement> statementFunc, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T query(final SerFunction<Connection, PreparedStatement> statementFunc, final RsHandler<T> rsh) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -221,9 +221,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 影响行数
|
* @return 影响行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int execute(final String sql, final Object... params) throws DbRuntimeException {
|
public int execute(final String sql, final Object... params) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -240,9 +240,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 主键
|
* @return 主键
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Long executeForGeneratedKey(final String sql, final Object... params) throws DbRuntimeException {
|
public Long executeForGeneratedKey(final String sql, final Object... params) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -258,10 +258,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param paramsBatch 批量的参数
|
* @param paramsBatch 批量的参数
|
||||||
* @return 每个SQL执行影响的行数
|
* @return 每个SQL执行影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.4.2
|
* @since 5.4.2
|
||||||
*/
|
*/
|
||||||
public int[] executeBatch(final String sql, final Iterable<Object[]> paramsBatch) throws DbRuntimeException {
|
public int[] executeBatch(final String sql, final Iterable<Object[]> paramsBatch) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -276,10 +276,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param sqls SQL列表
|
* @param sqls SQL列表
|
||||||
* @return 每个SQL执行影响的行数
|
* @return 每个SQL执行影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.5.6
|
* @since 4.5.6
|
||||||
*/
|
*/
|
||||||
public int[] executeBatch(final String... sqls) throws DbRuntimeException {
|
public int[] executeBatch(final String... sqls) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -294,10 +294,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param sqls SQL列表
|
* @param sqls SQL列表
|
||||||
* @return 每个SQL执行影响的行数
|
* @return 每个SQL执行影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.4.2
|
* @since 5.4.2
|
||||||
*/
|
*/
|
||||||
public int[] executeBatch(final Iterable<String> sqls) throws DbRuntimeException {
|
public int[] executeBatch(final Iterable<String> sqls) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -317,9 +317,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int insert(final Entity record) throws DbRuntimeException {
|
public int insert(final Entity record) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -336,10 +336,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @param keys 需要检查唯一性的字段
|
* @param keys 需要检查唯一性的字段
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.0.10
|
* @since 4.0.10
|
||||||
*/
|
*/
|
||||||
public int insertOrUpdate(final Entity record, final String... keys) throws DbRuntimeException {
|
public int insertOrUpdate(final Entity record, final String... keys) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -357,10 +357,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @param keys 需要检查唯一性的字段
|
* @param keys 需要检查唯一性的字段
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.7.21
|
* @since 5.7.21
|
||||||
*/
|
*/
|
||||||
public int upsert(final Entity record, final String... keys) throws DbRuntimeException {
|
public int upsert(final Entity record, final String... keys) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -377,9 +377,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param records 记录列表
|
* @param records 记录列表
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int[] insert(final Collection<Entity> records) throws DbRuntimeException {
|
public int[] insert(final Collection<Entity> records) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -394,9 +394,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @return 主键列表
|
* @return 主键列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Object> insertForGeneratedKeys(final Entity record) throws DbRuntimeException {
|
public List<Object> insertForGeneratedKeys(final Entity record) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -411,9 +411,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @return 主键
|
* @return 主键
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Long insertForGeneratedKey(final Entity record) throws DbRuntimeException {
|
public Long insertForGeneratedKey(final Entity record) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -433,9 +433,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param field 字段名,最好是主键
|
* @param field 字段名,最好是主键
|
||||||
* @param value 值,值可以是列表或数组,被当作IN查询处理
|
* @param value 值,值可以是列表或数组,被当作IN查询处理
|
||||||
* @return 删除行数
|
* @return 删除行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int del(final String tableName, final String field, final Object value) throws DbRuntimeException {
|
public int del(final String tableName, final String field, final Object value) throws DbException {
|
||||||
return del(Entity.of(tableName).set(field, value));
|
return del(Entity.of(tableName).set(field, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,9 +444,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 影响行数
|
* @return 影响行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int del(final Entity where) throws DbRuntimeException {
|
public int del(final Entity where) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -466,9 +466,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 影响行数
|
* @return 影响行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int update(final Entity record, final Entity where) throws DbRuntimeException {
|
public int update(final Entity record, final Entity where) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -490,9 +490,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param field 字段名
|
* @param field 字段名
|
||||||
* @param value 字段值
|
* @param value 字段值
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> Entity get(final String tableName, final String field, final T value) throws DbRuntimeException {
|
public <T> Entity get(final String tableName, final String field, final T value) throws DbException {
|
||||||
return this.get(Entity.of(tableName).set(field, value));
|
return this.get(Entity.of(tableName).set(field, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,9 +501,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Entity get(final Entity where) throws DbRuntimeException {
|
public Entity get(final Entity where) throws DbException {
|
||||||
return find(where.getFieldNames(), where, new EntityHandler(this.caseInsensitive));
|
return find(where.getFieldNames(), where, new EntityHandler(this.caseInsensitive));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -520,9 +520,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T find(final Collection<String> fields, final Entity where, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T find(final Collection<String> fields, final Entity where, final RsHandler<T> rsh) throws DbException {
|
||||||
return find(Query.of(where).setFields(fields), rsh);
|
return find(Query.of(where).setFields(fields), rsh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,10 +533,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param fields 返回的字段列表,null则返回所有字段
|
* @param fields 返回的字段列表,null则返回所有字段
|
||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @return 结果Entity列表
|
* @return 结果Entity列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.5.16
|
* @since 4.5.16
|
||||||
*/
|
*/
|
||||||
public List<Entity> find(final Collection<String> fields, final Entity where) throws DbRuntimeException {
|
public List<Entity> find(final Collection<String> fields, final Entity where) throws DbException {
|
||||||
return find(fields, where, new EntityListHandler(this.caseInsensitive));
|
return find(fields, where, new EntityListHandler(this.caseInsensitive));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,10 +548,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param query {@link Query}对象,此对象中可以定义返回字段、查询条件,查询的表、分页等信息
|
* @param query {@link Query}对象,此对象中可以定义返回字段、查询条件,查询的表、分页等信息
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
public <T> T find(final Query query, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T find(final Query query, final RsHandler<T> rsh) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -570,9 +570,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param fields 字段列表,可变长参数如果无值表示查询全部字段
|
* @param fields 字段列表,可变长参数如果无值表示查询全部字段
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T find(final Entity where, final RsHandler<T> rsh, final String... fields) throws DbRuntimeException {
|
public <T> T find(final Entity where, final RsHandler<T> rsh, final String... fields) throws DbException {
|
||||||
return find(Arrays.asList(fields), where, rsh);
|
return find(Arrays.asList(fields), where, rsh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,10 +582,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.2.1
|
* @since 3.2.1
|
||||||
*/
|
*/
|
||||||
public List<Entity> find(final Entity where) throws DbRuntimeException {
|
public List<Entity> find(final Entity where) throws DbException {
|
||||||
return find(where.getFieldNames(), where, new EntityListHandler(this.caseInsensitive));
|
return find(where.getFieldNames(), where, new EntityListHandler(this.caseInsensitive));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,10 +597,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @param beanClass Bean类
|
* @param beanClass Bean类
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.2.2
|
* @since 3.2.2
|
||||||
*/
|
*/
|
||||||
public <T> List<T> find(final Entity where, final Class<T> beanClass) throws DbRuntimeException {
|
public <T> List<T> find(final Entity where, final Class<T> beanClass) throws DbException {
|
||||||
return find(where.getFieldNames(), where, BeanListHandler.of(beanClass));
|
return find(where.getFieldNames(), where, BeanListHandler.of(beanClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,9 +610,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Entity> findAll(final Entity where) throws DbRuntimeException {
|
public List<Entity> findAll(final Entity where) throws DbException {
|
||||||
return find(where, new EntityListHandler(this.caseInsensitive));
|
return find(where, new EntityListHandler(this.caseInsensitive));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,10 +624,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @param beanClass 返回的对象类型
|
* @param beanClass 返回的对象类型
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.2.2
|
* @since 3.2.2
|
||||||
*/
|
*/
|
||||||
public <T> List<T> findAll(final Entity where, final Class<T> beanClass) throws DbRuntimeException {
|
public <T> List<T> findAll(final Entity where, final Class<T> beanClass) throws DbException {
|
||||||
return find(where, BeanListHandler.of(beanClass));
|
return find(where, BeanListHandler.of(beanClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,9 +636,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Entity> findAll(final String tableName) throws DbRuntimeException {
|
public List<Entity> findAll(final String tableName) throws DbException {
|
||||||
return findAll(Entity.of(tableName));
|
return findAll(Entity.of(tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,9 +649,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param field 字段名
|
* @param field 字段名
|
||||||
* @param value 字段值
|
* @param value 字段值
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Entity> findBy(final String tableName, final String field, final Object value) throws DbRuntimeException {
|
public List<Entity> findBy(final String tableName, final String field, final Object value) throws DbException {
|
||||||
return findAll(Entity.of(tableName).set(field, value));
|
return findAll(Entity.of(tableName).set(field, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,10 +661,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @param wheres 条件,多个条件的连接逻辑使用{@link Condition#setLinkOperator(LogicalOperator)} 定义
|
* @param wheres 条件,多个条件的连接逻辑使用{@link Condition#setLinkOperator(LogicalOperator)} 定义
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
public List<Entity> findBy(final String tableName, final Condition... wheres) throws DbRuntimeException {
|
public List<Entity> findBy(final String tableName, final Condition... wheres) throws DbException {
|
||||||
final Query query = new Query(wheres, tableName);
|
final Query query = new Query(wheres, tableName);
|
||||||
return find(query, new EntityListHandler(this.caseInsensitive));
|
return find(query, new EntityListHandler(this.caseInsensitive));
|
||||||
}
|
}
|
||||||
@ -677,9 +677,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param value 字段值
|
* @param value 字段值
|
||||||
* @param likeType {@link LikeType}
|
* @param likeType {@link LikeType}
|
||||||
* @return 数据对象列表
|
* @return 数据对象列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Entity> findLike(final String tableName, final String field, final String value, final LikeType likeType) throws DbRuntimeException {
|
public List<Entity> findLike(final String tableName, final String field, final String value, final LikeType likeType) throws DbException {
|
||||||
return findAll(Entity.of(tableName).set(field, SqlUtil.buildLikeValue(value, likeType, true)));
|
return findAll(Entity.of(tableName).set(field, SqlUtil.buildLikeValue(value, likeType, true)));
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
@ -691,9 +691,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param where 查询条件
|
* @param where 查询条件
|
||||||
* @return 复合条件的结果数
|
* @return 复合条件的结果数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public long count(final Entity where) throws DbRuntimeException {
|
public long count(final Entity where) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -708,9 +708,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
*
|
*
|
||||||
* @param sql sql构造器
|
* @param sql sql构造器
|
||||||
* @return 复合条件的结果数
|
* @return 复合条件的结果数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public long count(final SqlBuilder sql) throws DbRuntimeException {
|
public long count(final SqlBuilder sql) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -726,10 +726,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param selectSql 查询SQL语句
|
* @param selectSql 查询SQL语句
|
||||||
* @param params 查询参数
|
* @param params 查询参数
|
||||||
* @return 复合条件的结果数
|
* @return 复合条件的结果数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.6.6
|
* @since 5.6.6
|
||||||
*/
|
*/
|
||||||
public long count(final CharSequence selectSql, final Object... params) throws DbRuntimeException {
|
public long count(final CharSequence selectSql, final Object... params) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -780,10 +780,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.2.2
|
* @since 3.2.2
|
||||||
*/
|
*/
|
||||||
public List<Entity> pageForEntityList(final Entity where, final Page page) throws DbRuntimeException {
|
public List<Entity> pageForEntityList(final Entity where, final Page page) throws DbException {
|
||||||
return page(where, page, new EntityListHandler(this.caseInsensitive));
|
return page(where, page, new EntityListHandler(this.caseInsensitive));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -796,10 +796,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 3.2.2
|
* @since 3.2.2
|
||||||
*/
|
*/
|
||||||
public <T> T page(final Entity where, final Page page, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T page(final Entity where, final Page page, final RsHandler<T> rsh) throws DbException {
|
||||||
return page(where.getFieldNames(), where, page, rsh);
|
return page(where.getFieldNames(), where, page, rsh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -813,9 +813,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T page(final Collection<String> fields, final Entity where, final Page page, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T page(final Collection<String> fields, final Entity where, final Page page, final RsHandler<T> rsh) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -834,10 +834,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.6.6
|
* @since 5.6.6
|
||||||
*/
|
*/
|
||||||
public <T> T page(final CharSequence sql, final Page page, final RsHandler<T> rsh, final Object... params) throws DbRuntimeException {
|
public <T> T page(final CharSequence sql, final Page page, final RsHandler<T> rsh, final Object... params) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -855,9 +855,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T page(final SqlBuilder sql, final Page page, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T page(final SqlBuilder sql, final Page page, final RsHandler<T> rsh) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -874,10 +874,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param params 参数列表
|
* @param params 参数列表
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.5.3
|
* @since 5.5.3
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final CharSequence sql, final Page page, final Object... params) throws DbRuntimeException {
|
public PageResult<Entity> page(final CharSequence sql, final Page page, final Object... params) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -896,9 +896,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param pageNumber 页码
|
* @param pageNumber 页码
|
||||||
* @param pageSize 每页结果数
|
* @param pageSize 每页结果数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final Collection<String> fields, final Entity where, final int pageNumber, final int pageSize) throws DbRuntimeException {
|
public PageResult<Entity> page(final Collection<String> fields, final Entity where, final int pageNumber, final int pageSize) throws DbException {
|
||||||
return page(fields, where, new Page(pageNumber, pageSize));
|
return page(fields, where, new Page(pageNumber, pageSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -910,9 +910,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final Collection<String> fields, final Entity where, final Page page) throws DbRuntimeException {
|
public PageResult<Entity> page(final Collection<String> fields, final Entity where, final Page page) throws DbException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -929,9 +929,9 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* @param where 条件实体类(包含表名)
|
* @param where 条件实体类(包含表名)
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @return 分页结果集
|
* @return 分页结果集
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final Entity where, final Page page) throws DbRuntimeException {
|
public PageResult<Entity> page(final Entity where, final Page page) throws DbException {
|
||||||
return this.page(where.getFieldNames(), where, page);
|
return this.page(where.getFieldNames(), where, page);
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
@ -1015,19 +1015,19 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
|||||||
* 检查数据库是否支持事务,此项检查同一个数据源只检查一次,如果不支持抛出DbRuntimeException异常
|
* 检查数据库是否支持事务,此项检查同一个数据源只检查一次,如果不支持抛出DbRuntimeException异常
|
||||||
*
|
*
|
||||||
* @param conn Connection
|
* @param conn Connection
|
||||||
* @throws DbRuntimeException 获取元数据信息失败
|
* @throws DbException 获取元数据信息失败
|
||||||
* @throws DbRuntimeException 不支持事务
|
* @throws DbException 不支持事务
|
||||||
*/
|
*/
|
||||||
protected void checkTransactionSupported(final Connection conn) throws DbRuntimeException {
|
protected void checkTransactionSupported(final Connection conn) throws DbException {
|
||||||
if (null == isSupportTransaction) {
|
if (null == isSupportTransaction) {
|
||||||
try {
|
try {
|
||||||
isSupportTransaction = conn.getMetaData().supportsTransactions();
|
isSupportTransaction = conn.getMetaData().supportsTransactions();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isSupportTransaction) {
|
if (!isSupportTransaction) {
|
||||||
throw new DbRuntimeException("Transaction not supported for current database!");
|
throw new DbException("Transaction not supported for current database!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ---------------------------------------------------------------------------- protected method end
|
// ---------------------------------------------------------------------------- protected method end
|
||||||
|
@ -25,9 +25,9 @@ public interface ConnectionHolder {
|
|||||||
* 获得链接。根据实现不同,可以自定义获取连接的方式
|
* 获得链接。根据实现不同,可以自定义获取连接的方式
|
||||||
*
|
*
|
||||||
* @return {@link Connection}
|
* @return {@link Connection}
|
||||||
* @throws DbRuntimeException 连接获取异常
|
* @throws DbException 连接获取异常
|
||||||
*/
|
*/
|
||||||
Connection getConnection() throws DbRuntimeException;
|
Connection getConnection() throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭连接<br>
|
* 关闭连接<br>
|
||||||
|
@ -110,9 +110,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param entity 实体对象
|
* @param entity 实体对象
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int add(final Entity entity) throws DbRuntimeException {
|
public int add(final Entity entity) throws DbException {
|
||||||
return db.insert(fixEntity(entity));
|
return db.insert(fixEntity(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,9 +121,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param entity 实体对象
|
* @param entity 实体对象
|
||||||
* @return 主键列表
|
* @return 主键列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Object> addForGeneratedKeys(final Entity entity) throws DbRuntimeException {
|
public List<Object> addForGeneratedKeys(final Entity entity) throws DbException {
|
||||||
return db.insertForGeneratedKeys(fixEntity(entity));
|
return db.insertForGeneratedKeys(fixEntity(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,9 +132,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param entity 实体对象
|
* @param entity 实体对象
|
||||||
* @return 自增主键
|
* @return 自增主键
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Long addForGeneratedKey(final Entity entity) throws DbRuntimeException {
|
public Long addForGeneratedKey(final Entity entity) throws DbException {
|
||||||
return db.insertForGeneratedKey(fixEntity(entity));
|
return db.insertForGeneratedKey(fixEntity(entity));
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
@ -147,9 +147,9 @@ public class DaoTemplate {
|
|||||||
* @param <T> 主键类型
|
* @param <T> 主键类型
|
||||||
* @param pk 主键
|
* @param pk 主键
|
||||||
* @return 删除行数
|
* @return 删除行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> int del(final T pk) throws DbRuntimeException {
|
public <T> int del(final T pk) throws DbException {
|
||||||
if (pk == null) {
|
if (pk == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -163,9 +163,9 @@ public class DaoTemplate {
|
|||||||
* @param field 字段名
|
* @param field 字段名
|
||||||
* @param value 字段值
|
* @param value 字段值
|
||||||
* @return 删除行数
|
* @return 删除行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> int del(final String field, final T value) throws DbRuntimeException {
|
public <T> int del(final String field, final T value) throws DbException {
|
||||||
if (StrUtil.isBlank(field)) {
|
if (StrUtil.isBlank(field)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -178,9 +178,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param where 删除条件,当条件为空时,返回0(防止误删全表)
|
* @param where 删除条件,当条件为空时,返回0(防止误删全表)
|
||||||
* @return 删除行数
|
* @return 删除行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int del(final Entity where) throws DbRuntimeException {
|
public int del(final Entity where) throws DbException {
|
||||||
if (MapUtil.isEmpty(where)) {
|
if (MapUtil.isEmpty(where)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -196,9 +196,9 @@ public class DaoTemplate {
|
|||||||
* @param record 更新的内容
|
* @param record 更新的内容
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 更新条目数
|
* @return 更新条目数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int update(final Entity record, final Entity where) throws DbRuntimeException {
|
public int update(final Entity record, final Entity where) throws DbException {
|
||||||
if (MapUtil.isEmpty(record)) {
|
if (MapUtil.isEmpty(record)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -210,16 +210,16 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param entity 实体对象,必须包含主键
|
* @param entity 实体对象,必须包含主键
|
||||||
* @return 更新行数
|
* @return 更新行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int update(Entity entity) throws DbRuntimeException {
|
public int update(Entity entity) throws DbException {
|
||||||
if (MapUtil.isEmpty(entity)) {
|
if (MapUtil.isEmpty(entity)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
entity = fixEntity(entity);
|
entity = fixEntity(entity);
|
||||||
final Object pk = entity.get(primaryKeyField);
|
final Object pk = entity.get(primaryKeyField);
|
||||||
if (null == pk) {
|
if (null == pk) {
|
||||||
throw new DbRuntimeException(StrUtil.format("Please determine `{}` for update", primaryKeyField));
|
throw new DbException(StrUtil.format("Please determine `{}` for update", primaryKeyField));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Entity where = Entity.of(tableName).set(primaryKeyField, pk);
|
final Entity where = Entity.of(tableName).set(primaryKeyField, pk);
|
||||||
@ -234,9 +234,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param entity 实体,当包含主键时更新,否则新增
|
* @param entity 实体,当包含主键时更新,否则新增
|
||||||
* @return 新增或更新条数
|
* @return 新增或更新条数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int addOrUpdate(final Entity entity) throws DbRuntimeException {
|
public int addOrUpdate(final Entity entity) throws DbException {
|
||||||
return null == entity.get(primaryKeyField) ? add(entity) : update(entity);
|
return null == entity.get(primaryKeyField) ? add(entity) : update(entity);
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
@ -248,9 +248,9 @@ public class DaoTemplate {
|
|||||||
* @param <T> 主键类型
|
* @param <T> 主键类型
|
||||||
* @param pk 主键值
|
* @param pk 主键值
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> Entity get(final T pk) throws DbRuntimeException {
|
public <T> Entity get(final T pk) throws DbException {
|
||||||
return this.get(primaryKeyField, pk);
|
return this.get(primaryKeyField, pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,9 +262,9 @@ public class DaoTemplate {
|
|||||||
* @param field 字段名
|
* @param field 字段名
|
||||||
* @param value 字段值
|
* @param value 字段值
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> Entity get(final String field, final T value) throws DbRuntimeException {
|
public <T> Entity get(final String field, final T value) throws DbException {
|
||||||
return this.get(Entity.of(tableName).set(field, value));
|
return this.get(Entity.of(tableName).set(field, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,9 +273,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Entity get(final Entity where) throws DbRuntimeException {
|
public Entity get(final Entity where) throws DbException {
|
||||||
return db.get(fixEntity(where));
|
return db.get(fixEntity(where));
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
@ -289,9 +289,9 @@ public class DaoTemplate {
|
|||||||
* @param field 字段名
|
* @param field 字段名
|
||||||
* @param value 字段值
|
* @param value 字段值
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> List<Entity> find(final String field, final T value) throws DbRuntimeException {
|
public <T> List<Entity> find(final String field, final T value) throws DbException {
|
||||||
return this.find(Entity.of(tableName).set(field, value));
|
return this.find(Entity.of(tableName).set(field, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,9 +299,9 @@ public class DaoTemplate {
|
|||||||
* 查询当前表的所有记录
|
* 查询当前表的所有记录
|
||||||
*
|
*
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Entity> findAll() throws DbRuntimeException {
|
public List<Entity> findAll() throws DbException {
|
||||||
return this.find(Entity.of(tableName));
|
return this.find(Entity.of(tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,9 +310,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param where 查询条件
|
* @param where 查询条件
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Entity> find(final Entity where) throws DbRuntimeException {
|
public List<Entity> find(final Entity where) throws DbException {
|
||||||
return db.find(null, fixEntity(where));
|
return db.find(null, fixEntity(where));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,9 +324,9 @@ public class DaoTemplate {
|
|||||||
* @param sql SQL语句
|
* @param sql SQL语句
|
||||||
* @param params SQL占位符中对应的参数
|
* @param params SQL占位符中对应的参数
|
||||||
* @return 记录
|
* @return 记录
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public List<Entity> findBySql(String sql, final Object... params) throws DbRuntimeException {
|
public List<Entity> findBySql(String sql, final Object... params) throws DbException {
|
||||||
final String selectKeyword = StrUtil.subPre(sql.trim(), 6).toLowerCase();
|
final String selectKeyword = StrUtil.subPre(sql.trim(), 6).toLowerCase();
|
||||||
if (!"select".equals(selectKeyword)) {
|
if (!"select".equals(selectKeyword)) {
|
||||||
sql = "SELECT * FROM " + this.tableName + " " + sql;
|
sql = "SELECT * FROM " + this.tableName + " " + sql;
|
||||||
@ -341,9 +341,9 @@ public class DaoTemplate {
|
|||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param selectFields 查询的字段列表
|
* @param selectFields 查询的字段列表
|
||||||
* @return 分页结果集
|
* @return 分页结果集
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final Entity where, final Page page, final String... selectFields) throws DbRuntimeException {
|
public PageResult<Entity> page(final Entity where, final Page page, final String... selectFields) throws DbException {
|
||||||
return db.page(Arrays.asList(selectFields), fixEntity(where), page);
|
return db.page(Arrays.asList(selectFields), fixEntity(where), page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,9 +353,9 @@ public class DaoTemplate {
|
|||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @return 分页结果集
|
* @return 分页结果集
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final Entity where, final Page page) throws DbRuntimeException {
|
public PageResult<Entity> page(final Entity where, final Page page) throws DbException {
|
||||||
return db.page(fixEntity(where), page);
|
return db.page(fixEntity(where), page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,9 +364,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 数量
|
* @return 数量
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public long count(final Entity where) throws DbRuntimeException {
|
public long count(final Entity where) throws DbException {
|
||||||
return db.count(fixEntity(where));
|
return db.count(fixEntity(where));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,9 +375,9 @@ public class DaoTemplate {
|
|||||||
*
|
*
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 是否存在
|
* @return 是否存在
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public boolean exist(final Entity where) throws DbRuntimeException {
|
public boolean exist(final Entity where) throws DbException {
|
||||||
return this.count(where) > 0;
|
return this.count(where) > 0;
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||||
|
* Hutool is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* https://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.dromara.hutool.db;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.exception.HutoolException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库异常
|
||||||
|
*
|
||||||
|
* @author Looly
|
||||||
|
*/
|
||||||
|
public class DbException extends HutoolException {
|
||||||
|
private static final long serialVersionUID = 3624487785708765623L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param e 异常
|
||||||
|
*/
|
||||||
|
public DbException(final Throwable e) {
|
||||||
|
super(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param message 消息
|
||||||
|
*/
|
||||||
|
public DbException(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param messageTemplate 消息模板
|
||||||
|
* @param params 参数
|
||||||
|
*/
|
||||||
|
public DbException(final String messageTemplate, final Object... params) {
|
||||||
|
super(messageTemplate, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param message 消息
|
||||||
|
* @param cause 被包装的子异常
|
||||||
|
*/
|
||||||
|
public DbException(final String message, final Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param message 消息
|
||||||
|
* @param cause 被包装的子异常
|
||||||
|
* @param enableSuppression 是否启用抑制
|
||||||
|
* @param writableStackTrace 堆栈跟踪是否应该是可写的
|
||||||
|
*/
|
||||||
|
public DbException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param cause 被包装的子异常
|
||||||
|
* @param messageTemplate 消息模板
|
||||||
|
* @param params 参数
|
||||||
|
*/
|
||||||
|
public DbException(final Throwable cause, final String messageTemplate, final Object... params) {
|
||||||
|
super(cause, messageTemplate, params);
|
||||||
|
}
|
||||||
|
}
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
|
||||||
* Hutool is licensed under Mulan PSL v2.
|
|
||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
||||||
* You may obtain a copy of Mulan PSL v2 at:
|
|
||||||
* https://license.coscl.org.cn/MulanPSL2
|
|
||||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
||||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
||||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the Mulan PSL v2 for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.dromara.hutool.db;
|
|
||||||
|
|
||||||
import org.dromara.hutool.core.exception.ExceptionUtil;
|
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库异常
|
|
||||||
*
|
|
||||||
* @author Looly
|
|
||||||
*/
|
|
||||||
public class DbRuntimeException extends RuntimeException {
|
|
||||||
private static final long serialVersionUID = 3624487785708765623L;
|
|
||||||
|
|
||||||
public DbRuntimeException(final Throwable e) {
|
|
||||||
super(ExceptionUtil.getMessage(e), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbRuntimeException(final String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbRuntimeException(final String messageTemplate, final Object... params) {
|
|
||||||
super(StrUtil.format(messageTemplate, params));
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbRuntimeException(final String message, final Throwable throwable) {
|
|
||||||
super(message, throwable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbRuntimeException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
|
|
||||||
super(message, throwable, enableSuppression, writableStackTrace);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbRuntimeException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
|
||||||
super(StrUtil.format(messageTemplate, params), throwable);
|
|
||||||
}
|
|
||||||
}
|
|
@ -35,11 +35,11 @@ public class DefaultConnectionHolder implements ConnectionHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() throws DbRuntimeException {
|
public Connection getConnection() throws DbException {
|
||||||
try {
|
try {
|
||||||
return ThreadLocalConnection.INSTANCE.get(this.ds);
|
return ThreadLocalConnection.INSTANCE.get(this.ds);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param conn 数据库连接
|
* @param conn 数据库连接
|
||||||
* @param records 记录列表,记录KV必须严格一致
|
* @param records 记录列表,记录KV必须严格一致
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int[] insert(final Connection conn, final Entity... records) throws DbRuntimeException {
|
public int[] insert(final Connection conn, final Entity... records) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (ArrayUtil.isEmpty(records)) {
|
if (ArrayUtil.isEmpty(records)) {
|
||||||
return new int[]{0};
|
return new int[]{0};
|
||||||
@ -95,7 +95,7 @@ public class DialectRunner implements Serializable {
|
|||||||
ps = dialect.psForInsertBatch(conn, records);
|
ps = dialect.psForInsertBatch(conn, records);
|
||||||
return ps.executeBatch();
|
return ps.executeBatch();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
@ -110,10 +110,10 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @param keys 需要检查唯一性的字段
|
* @param keys 需要检查唯一性的字段
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.7.20
|
* @since 5.7.20
|
||||||
*/
|
*/
|
||||||
public int upsert(final Connection conn, final Entity record, final String... keys) throws DbRuntimeException {
|
public int upsert(final Connection conn, final Entity record, final String... keys) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
ps = getDialect().psForUpsert(conn, record, keys);
|
ps = getDialect().psForUpsert(conn, record, keys);
|
||||||
@ -124,7 +124,7 @@ public class DialectRunner implements Serializable {
|
|||||||
try {
|
try {
|
||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
@ -141,9 +141,9 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @param keys 需要检查唯一性的字段
|
* @param keys 需要检查唯一性的字段
|
||||||
* @return 插入行数
|
* @return 插入行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int insertOrUpdate(final Connection conn, final Entity record, final String... keys) throws DbRuntimeException {
|
public int insertOrUpdate(final Connection conn, final Entity record, final String... keys) throws DbException {
|
||||||
final Entity where = record.filterNew(keys);
|
final Entity where = record.filterNew(keys);
|
||||||
if (MapUtil.isNotEmpty(where) && count(conn, Query.of(where)) > 0) {
|
if (MapUtil.isNotEmpty(where) && count(conn, Query.of(where)) > 0) {
|
||||||
return update(conn, record.removeNew(keys), where);
|
return update(conn, record.removeNew(keys), where);
|
||||||
@ -161,12 +161,12 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @param generatedKeysHandler 自增主键处理器,用于定义返回自增主键的范围和类型
|
* @param generatedKeysHandler 自增主键处理器,用于定义返回自增主键的范围和类型
|
||||||
* @return 主键列表
|
* @return 主键列表
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T insert(final Connection conn, final Entity record, final RsHandler<T> generatedKeysHandler) throws DbRuntimeException {
|
public <T> T insert(final Connection conn, final Entity record, final RsHandler<T> generatedKeysHandler) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (MapUtil.isEmpty(record)) {
|
if (MapUtil.isEmpty(record)) {
|
||||||
throw new DbRuntimeException("Empty entity provided!");
|
throw new DbException("Empty entity provided!");
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
@ -178,7 +178,7 @@ public class DialectRunner implements Serializable {
|
|||||||
}
|
}
|
||||||
return StatementUtil.getGeneratedKeys(ps, generatedKeysHandler);
|
return StatementUtil.getGeneratedKeys(ps, generatedKeysHandler);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
@ -191,13 +191,13 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param conn 数据库连接
|
* @param conn 数据库连接
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 影响行数
|
* @return 影响行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int del(final Connection conn, final Entity where) throws DbRuntimeException {
|
public int del(final Connection conn, final Entity where) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (MapUtil.isEmpty(where)) {
|
if (MapUtil.isEmpty(where)) {
|
||||||
//不允许做全表删除
|
//不允许做全表删除
|
||||||
throw new DbRuntimeException("Empty entity provided!");
|
throw new DbException("Empty entity provided!");
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
@ -205,7 +205,7 @@ public class DialectRunner implements Serializable {
|
|||||||
ps = dialect.psForDelete(conn, Query.of(where));
|
ps = dialect.psForDelete(conn, Query.of(where));
|
||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
@ -219,16 +219,16 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param record 记录
|
* @param record 记录
|
||||||
* @param where 条件
|
* @param where 条件
|
||||||
* @return 影响行数
|
* @return 影响行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int update(final Connection conn, final Entity record, final Entity where) throws DbRuntimeException {
|
public int update(final Connection conn, final Entity record, final Entity where) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (MapUtil.isEmpty(record)) {
|
if (MapUtil.isEmpty(record)) {
|
||||||
throw new DbRuntimeException("Empty entity provided!");
|
throw new DbException("Empty entity provided!");
|
||||||
}
|
}
|
||||||
if (MapUtil.isEmpty(where)) {
|
if (MapUtil.isEmpty(where)) {
|
||||||
//不允许做全表更新
|
//不允许做全表更新
|
||||||
throw new DbRuntimeException("Empty where provided!");
|
throw new DbException("Empty where provided!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//表名可以从被更新记录的Entity中获得,也可以从Where中获得
|
//表名可以从被更新记录的Entity中获得,也可以从Where中获得
|
||||||
@ -244,7 +244,7 @@ public class DialectRunner implements Serializable {
|
|||||||
ps = dialect.psForUpdate(conn, record, query);
|
ps = dialect.psForUpdate(conn, record, query);
|
||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
@ -259,15 +259,15 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param query {@link Query}
|
* @param query {@link Query}
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T find(final Connection conn, final Query query, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T find(final Connection conn, final Query query, final RsHandler<T> rsh) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
Assert.notNull(query, "[query] is null !");
|
Assert.notNull(query, "[query] is null !");
|
||||||
try {
|
try {
|
||||||
return SqlExecutor.queryAndClosePs(dialect.psForFind(conn, query), rsh);
|
return SqlExecutor.queryAndClosePs(dialect.psForFind(conn, query), rsh);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,14 +277,14 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param conn 数据库连接对象
|
* @param conn 数据库连接对象
|
||||||
* @param query 查询
|
* @param query 查询
|
||||||
* @return 复合条件的结果数
|
* @return 复合条件的结果数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public long count(final Connection conn, final Query query) throws DbRuntimeException {
|
public long count(final Connection conn, final Query query) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
try {
|
try {
|
||||||
return SqlExecutor.queryAndClosePs(dialect.psForCount(conn, query), new NumberHandler()).longValue();
|
return SqlExecutor.queryAndClosePs(dialect.psForCount(conn, query), new NumberHandler()).longValue();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,10 +295,10 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param conn 数据库连接对象
|
* @param conn 数据库连接对象
|
||||||
* @param sqlBuilder 查询语句
|
* @param sqlBuilder 查询语句
|
||||||
* @return 复合条件的结果数
|
* @return 复合条件的结果数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.7.2
|
* @since 5.7.2
|
||||||
*/
|
*/
|
||||||
public long count(final Connection conn, final SqlBuilder sqlBuilder) throws DbRuntimeException {
|
public long count(final Connection conn, final SqlBuilder sqlBuilder) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
String selectSql = sqlBuilder.build();
|
String selectSql = sqlBuilder.build();
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ public class DialectRunner implements Serializable {
|
|||||||
SqlBuilder.of(selectSql).addParams(sqlBuilder.getParamValueArray())),
|
SqlBuilder.of(selectSql).addParams(sqlBuilder.getParamValueArray())),
|
||||||
new NumberHandler()).longValue();
|
new NumberHandler()).longValue();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,9 +325,9 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param conn 数据库连接对象
|
* @param conn 数据库连接对象
|
||||||
* @param query 查询
|
* @param query 查询
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final Connection conn, final Query query) throws DbRuntimeException {
|
public PageResult<Entity> page(final Connection conn, final Query query) throws DbException {
|
||||||
final Page page = query.getPage();
|
final Page page = query.getPage();
|
||||||
final PageResultHandler<Entity> entityResultHandler = PageResultHandler.of(
|
final PageResultHandler<Entity> entityResultHandler = PageResultHandler.of(
|
||||||
// 分页查询中总数的查询要去掉分页信息
|
// 分页查询中总数的查询要去掉分页信息
|
||||||
@ -345,9 +345,9 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param query 查询条件(包含表名)
|
* @param query 查询条件(包含表名)
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T page(final Connection conn, final Query query, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T page(final Connection conn, final Query query, final RsHandler<T> rsh) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (null == query.getPage()) {
|
if (null == query.getPage()) {
|
||||||
return this.find(conn, query, rsh);
|
return this.find(conn, query, rsh);
|
||||||
@ -356,7 +356,7 @@ public class DialectRunner implements Serializable {
|
|||||||
try {
|
try {
|
||||||
return SqlExecutor.queryAndClosePs(dialect.psForPage(conn, query), rsh);
|
return SqlExecutor.queryAndClosePs(dialect.psForPage(conn, query), rsh);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,9 +368,9 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param sqlBuilder SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
* @param sqlBuilder SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public PageResult<Entity> page(final Connection conn, final SqlBuilder sqlBuilder, final Page page) throws DbRuntimeException {
|
public PageResult<Entity> page(final Connection conn, final SqlBuilder sqlBuilder, final Page page) throws DbException {
|
||||||
final PageResultHandler<Entity> entityResultHandler = PageResultHandler.of(
|
final PageResultHandler<Entity> entityResultHandler = PageResultHandler.of(
|
||||||
new PageResult<>(page, (int) count(conn, sqlBuilder)));
|
new PageResult<>(page, (int) count(conn, sqlBuilder)));
|
||||||
|
|
||||||
@ -387,10 +387,10 @@ public class DialectRunner implements Serializable {
|
|||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.5.3
|
* @since 5.5.3
|
||||||
*/
|
*/
|
||||||
public <T> T page(final Connection conn, final SqlBuilder sqlBuilder, final Page page, final RsHandler<T> rsh) throws DbRuntimeException {
|
public <T> T page(final Connection conn, final SqlBuilder sqlBuilder, final Page page, final RsHandler<T> rsh) throws DbException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (null == page) {
|
if (null == page) {
|
||||||
return SqlExecutor.query(conn, sqlBuilder, rsh);
|
return SqlExecutor.query(conn, sqlBuilder, rsh);
|
||||||
@ -400,7 +400,7 @@ public class DialectRunner implements Serializable {
|
|||||||
try {
|
try {
|
||||||
ps = dialect.psForPage(conn, sqlBuilder, page);
|
ps = dialect.psForPage(conn, sqlBuilder, page);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
return SqlExecutor.queryAndClosePs(ps, rsh);
|
return SqlExecutor.queryAndClosePs(ps, rsh);
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,7 @@ public class Entity extends Dict {
|
|||||||
if (obj instanceof RowId) {
|
if (obj instanceof RowId) {
|
||||||
return (RowId) obj;
|
return (RowId) obj;
|
||||||
}
|
}
|
||||||
throw new DbRuntimeException("Value of field [{}] is not a rowid!", field);
|
throw new DbException("Value of field [{}] is not a rowid!", field);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------- Get end
|
// -------------------------------------------------------------------- Get end
|
||||||
|
@ -104,28 +104,28 @@ public class Session extends AbstractDb<Session> implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* 开始事务
|
* 开始事务
|
||||||
*
|
*
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public void beginTransaction() throws DbRuntimeException {
|
public void beginTransaction() throws DbException {
|
||||||
final Connection conn = getConnection();
|
final Connection conn = getConnection();
|
||||||
checkTransactionSupported(conn);
|
checkTransactionSupported(conn);
|
||||||
try {
|
try {
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交事务
|
* 提交事务
|
||||||
*
|
*
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public void commit() throws DbRuntimeException {
|
public void commit() throws DbException {
|
||||||
try {
|
try {
|
||||||
getConnection().commit();
|
getConnection().commit();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
getConnection().setAutoCommit(true); // 事务结束,恢复自动提交
|
getConnection().setAutoCommit(true); // 事务结束,恢复自动提交
|
||||||
@ -138,13 +138,13 @@ public class Session extends AbstractDb<Session> implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* 回滚事务
|
* 回滚事务
|
||||||
*
|
*
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public void rollback() throws DbRuntimeException {
|
public void rollback() throws DbException {
|
||||||
try {
|
try {
|
||||||
getConnection().rollback();
|
getConnection().rollback();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
getConnection().setAutoCommit(true); // 事务结束,恢复自动提交
|
getConnection().setAutoCommit(true); // 事务结束,恢复自动提交
|
||||||
@ -176,13 +176,13 @@ public class Session extends AbstractDb<Session> implements Closeable {
|
|||||||
* 回滚到某个保存点,保存点的设置请使用setSavepoint方法
|
* 回滚到某个保存点,保存点的设置请使用setSavepoint方法
|
||||||
*
|
*
|
||||||
* @param savepoint 保存点
|
* @param savepoint 保存点
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public void rollback(final Savepoint savepoint) throws DbRuntimeException {
|
public void rollback(final Savepoint savepoint) throws DbException {
|
||||||
try {
|
try {
|
||||||
getConnection().rollback(savepoint);
|
getConnection().rollback(savepoint);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
getConnection().setAutoCommit(true); // 事务结束,恢复自动提交
|
getConnection().setAutoCommit(true); // 事务结束,恢复自动提交
|
||||||
@ -215,13 +215,13 @@ public class Session extends AbstractDb<Session> implements Closeable {
|
|||||||
* 设置保存点
|
* 设置保存点
|
||||||
*
|
*
|
||||||
* @return 保存点对象
|
* @return 保存点对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public Savepoint setSavepoint() throws DbRuntimeException {
|
public Savepoint setSavepoint() throws DbException {
|
||||||
try {
|
try {
|
||||||
return getConnection().setSavepoint();
|
return getConnection().setSavepoint();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,16 +246,16 @@ public class Session extends AbstractDb<Session> implements Closeable {
|
|||||||
* Connection.TRANSACTION_SERIALIZABLE 禁止脏读、不可重复读和幻读<br>
|
* Connection.TRANSACTION_SERIALIZABLE 禁止脏读、不可重复读和幻读<br>
|
||||||
*
|
*
|
||||||
* @param level 隔离级别
|
* @param level 隔离级别
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public void setTransactionIsolation(final int level) throws DbRuntimeException {
|
public void setTransactionIsolation(final int level) throws DbException {
|
||||||
try {
|
try {
|
||||||
if (getConnection().getMetaData().supportsTransactionIsolationLevel(level) == false) {
|
if (getConnection().getMetaData().supportsTransactionIsolationLevel(level) == false) {
|
||||||
throw new DbRuntimeException(StrUtil.format("Transaction isolation [{}] not support!", level));
|
throw new DbException(StrUtil.format("Transaction isolation [{}] not support!", level));
|
||||||
}
|
}
|
||||||
getConnection().setTransactionIsolation(level);
|
getConnection().setTransactionIsolation(level);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,17 +263,17 @@ public class Session extends AbstractDb<Session> implements Closeable {
|
|||||||
* 在事务中执行操作,通过实现{@link SerConsumer}接口的call方法执行多条SQL语句从而完成事务
|
* 在事务中执行操作,通过实现{@link SerConsumer}接口的call方法执行多条SQL语句从而完成事务
|
||||||
*
|
*
|
||||||
* @param func 函数抽象,在函数中执行多个SQL操作,多个操作会被合并为同一事务
|
* @param func 函数抽象,在函数中执行多个SQL操作,多个操作会被合并为同一事务
|
||||||
* @throws DbRuntimeException SQL异常
|
* @throws DbException SQL异常
|
||||||
* @since 3.2.3
|
* @since 3.2.3
|
||||||
*/
|
*/
|
||||||
public void tx(final SerConsumer<Session> func) throws DbRuntimeException {
|
public void tx(final SerConsumer<Session> func) throws DbException {
|
||||||
try {
|
try {
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
func.accept(this);
|
func.accept(this);
|
||||||
commit();
|
commit();
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
quietRollback();
|
quietRollback();
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import java.util.Properties;
|
|||||||
* <li>基本配置项,如driver、url、user、password等</li>
|
* <li>基本配置项,如driver、url、user、password等</li>
|
||||||
* <li>连接配置,如remarks、useInformationSchema等</li>
|
* <li>连接配置,如remarks、useInformationSchema等</li>
|
||||||
* <li>连接池配置,如初始容量、最大容量等,取决于连接池库具体要求</li>
|
* <li>连接池配置,如初始容量、最大容量等,取决于连接池库具体要求</li>
|
||||||
|
* <li>其它配置,如是否大小写敏感、SQL过滤器等</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
|
@ -16,7 +16,7 @@ import org.dromara.hutool.core.convert.Convert;
|
|||||||
import org.dromara.hutool.core.io.resource.NoResourceException;
|
import org.dromara.hutool.core.io.resource.NoResourceException;
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.driver.DriverUtil;
|
import org.dromara.hutool.db.driver.DriverUtil;
|
||||||
import org.dromara.hutool.setting.Setting;
|
import org.dromara.hutool.setting.Setting;
|
||||||
import org.dromara.hutool.setting.props.Props;
|
import org.dromara.hutool.setting.props.Props;
|
||||||
@ -68,7 +68,7 @@ public class SettingConfigParser implements ConfigParser {
|
|||||||
|
|
||||||
final Setting subSetting = setting.getSetting(group);
|
final Setting subSetting = setting.getSetting(group);
|
||||||
if (MapUtil.isEmpty(subSetting)) {
|
if (MapUtil.isEmpty(subSetting)) {
|
||||||
throw new DbRuntimeException("No config for group: [{}]", group);
|
throw new DbException("No config for group: [{}]", group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return toDbConfig(subSetting);
|
return toDbConfig(subSetting);
|
||||||
@ -105,7 +105,7 @@ public class SettingConfigParser implements ConfigParser {
|
|||||||
// 基本信息
|
// 基本信息
|
||||||
final String url = setting.getAndRemove(DSKeys.KEY_ALIAS_URL);
|
final String url = setting.getAndRemove(DSKeys.KEY_ALIAS_URL);
|
||||||
if (StrUtil.isBlank(url)) {
|
if (StrUtil.isBlank(url)) {
|
||||||
throw new DbRuntimeException("No JDBC URL!");
|
throw new DbException("No JDBC URL!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除用户可能误加入的show sql配置项
|
// 移除用户可能误加入的show sql配置项
|
||||||
|
@ -14,7 +14,7 @@ package org.dromara.hutool.db.dialect.impl;
|
|||||||
|
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import org.dromara.hutool.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.Entity;
|
import org.dromara.hutool.db.Entity;
|
||||||
import org.dromara.hutool.db.Page;
|
import org.dromara.hutool.db.Page;
|
||||||
import org.dromara.hutool.db.StatementUtil;
|
import org.dromara.hutool.db.StatementUtil;
|
||||||
@ -59,7 +59,7 @@ public class AnsiSqlDialect implements Dialect {
|
|||||||
@Override
|
@Override
|
||||||
public PreparedStatement psForInsertBatch(final Connection conn, final Entity... entities) {
|
public PreparedStatement psForInsertBatch(final Connection conn, final Entity... entities) {
|
||||||
if (ArrayUtil.isEmpty(entities)) {
|
if (ArrayUtil.isEmpty(entities)) {
|
||||||
throw new DbRuntimeException("Entities for batch insert is empty !");
|
throw new DbException("Entities for batch insert is empty !");
|
||||||
}
|
}
|
||||||
// 批量,根据第一行数据结构生成SQL占位符
|
// 批量,根据第一行数据结构生成SQL占位符
|
||||||
final SqlBuilder insert = SqlBuilder.of(quoteWrapper).insert(entities[0], this.dialectName());
|
final SqlBuilder insert = SqlBuilder.of(quoteWrapper).insert(entities[0], this.dialectName());
|
||||||
@ -104,7 +104,7 @@ public class AnsiSqlDialect implements Dialect {
|
|||||||
public PreparedStatement psForPage(final Connection conn, final Query query) {
|
public PreparedStatement psForPage(final Connection conn, final Query query) {
|
||||||
Assert.notNull(query, "query must be not null !");
|
Assert.notNull(query, "query must be not null !");
|
||||||
if (ArrayUtil.hasBlank(query.getTableNames())) {
|
if (ArrayUtil.hasBlank(query.getTableNames())) {
|
||||||
throw new DbRuntimeException("Table name must be not empty !");
|
throw new DbException("Table name must be not empty !");
|
||||||
}
|
}
|
||||||
|
|
||||||
final SqlBuilder find = SqlBuilder.of(quoteWrapper).query(query);
|
final SqlBuilder find = SqlBuilder.of(quoteWrapper).query(query);
|
||||||
|
@ -14,7 +14,7 @@ package org.dromara.hutool.db.driver;
|
|||||||
|
|
||||||
import org.dromara.hutool.core.io.IoUtil;
|
import org.dromara.hutool.core.io.IoUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.ds.DSWrapper;
|
import org.dromara.hutool.db.ds.DSWrapper;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -60,9 +60,9 @@ public class DriverUtil {
|
|||||||
try {
|
try {
|
||||||
conn = ds.getConnection();
|
conn = ds.getConnection();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException("Get Connection error !", e);
|
throw new DbException("Get Connection error !", e);
|
||||||
} catch (final NullPointerException e) {
|
} catch (final NullPointerException e) {
|
||||||
throw new DbRuntimeException("Unexpected NullPointException, maybe [jdbcUrl] or [url] is empty!", e);
|
throw new DbException("Unexpected NullPointException, maybe [jdbcUrl] or [url] is empty!", e);
|
||||||
}
|
}
|
||||||
driver = identifyDriver(conn);
|
driver = identifyDriver(conn);
|
||||||
} finally {
|
} finally {
|
||||||
@ -77,9 +77,9 @@ public class DriverUtil {
|
|||||||
*
|
*
|
||||||
* @param conn 数据库连接对象
|
* @param conn 数据库连接对象
|
||||||
* @return 驱动
|
* @return 驱动
|
||||||
* @throws DbRuntimeException SQL异常包装,获取元数据信息失败
|
* @throws DbException SQL异常包装,获取元数据信息失败
|
||||||
*/
|
*/
|
||||||
public static String identifyDriver(final Connection conn) throws DbRuntimeException {
|
public static String identifyDriver(final Connection conn) throws DbException {
|
||||||
String driver;
|
String driver;
|
||||||
final DatabaseMetaData meta;
|
final DatabaseMetaData meta;
|
||||||
try {
|
try {
|
||||||
@ -89,7 +89,7 @@ public class DriverUtil {
|
|||||||
driver = identifyDriver(meta.getDriverName());
|
driver = identifyDriver(meta.getDriverName());
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException("Identify driver error!", e);
|
throw new DbException("Identify driver error!", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return driver;
|
return driver;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.db.ds;
|
package org.dromara.hutool.db.ds;
|
||||||
|
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.log.LogUtil;
|
import org.dromara.hutool.log.LogUtil;
|
||||||
|
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
@ -37,7 +37,7 @@ public class DSUtil {
|
|||||||
public static DataSource getJndiDSWithLog(final String jndiName) {
|
public static DataSource getJndiDSWithLog(final String jndiName) {
|
||||||
try {
|
try {
|
||||||
return getJndiDS(jndiName);
|
return getJndiDS(jndiName);
|
||||||
} catch (final DbRuntimeException e) {
|
} catch (final DbException e) {
|
||||||
LogUtil.error(e.getCause(), "Find JNDI datasource error!");
|
LogUtil.error(e.getCause(), "Find JNDI datasource error!");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -53,7 +53,7 @@ public class DSUtil {
|
|||||||
try {
|
try {
|
||||||
return (DataSource) new InitialContext().lookup(jndiName);
|
return (DataSource) new InitialContext().lookup(jndiName);
|
||||||
} catch (final NamingException e) {
|
} catch (final NamingException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ package org.dromara.hutool.db.ds.c3p0;
|
|||||||
|
|
||||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.ds.DSFactory;
|
import org.dromara.hutool.db.ds.DSFactory;
|
||||||
import org.dromara.hutool.db.config.DbConfig;
|
import org.dromara.hutool.db.config.DbConfig;
|
||||||
import org.dromara.hutool.setting.props.Props;
|
import org.dromara.hutool.setting.props.Props;
|
||||||
@ -45,7 +45,7 @@ public class C3p0DSFactory implements DSFactory {
|
|||||||
try {
|
try {
|
||||||
ds.setDriverClass(config.getDriver());
|
ds.setDriverClass(config.getDriver());
|
||||||
} catch (final PropertyVetoException e) {
|
} catch (final PropertyVetoException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
ds.setUser(config.getUser());
|
ds.setUser(config.getUser());
|
||||||
ds.setPassword(config.getPass());
|
ds.setPassword(config.getPass());
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
package org.dromara.hutool.db.ds.jndi;
|
package org.dromara.hutool.db.ds.jndi;
|
||||||
|
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.ds.DSFactory;
|
import org.dromara.hutool.db.ds.DSFactory;
|
||||||
import org.dromara.hutool.db.ds.DSUtil;
|
import org.dromara.hutool.db.ds.DSUtil;
|
||||||
import org.dromara.hutool.db.config.DbConfig;
|
import org.dromara.hutool.db.config.DbConfig;
|
||||||
@ -43,7 +43,7 @@ public class JndiDSFactory implements DSFactory {
|
|||||||
public DataSource createDataSource(final DbConfig config) {
|
public DataSource createDataSource(final DbConfig config) {
|
||||||
final String jndiName = config.getPoolProps().getProperty("jndi");
|
final String jndiName = config.getPoolProps().getProperty("jndi");
|
||||||
if (StrUtil.isEmpty(jndiName)) {
|
if (StrUtil.isEmpty(jndiName)) {
|
||||||
throw new DbRuntimeException("No setting name [jndi] for this group.");
|
throw new DbException("No setting name [jndi] for this group.");
|
||||||
}
|
}
|
||||||
return DSUtil.getJndiDS(jndiName);
|
return DSUtil.getJndiDS(jndiName);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ package org.dromara.hutool.db.ds.pooled;
|
|||||||
|
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.core.pool.Poolable;
|
import org.dromara.hutool.core.pool.Poolable;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.config.DbConfig;
|
import org.dromara.hutool.db.config.DbConfig;
|
||||||
import org.dromara.hutool.setting.props.Props;
|
import org.dromara.hutool.setting.props.Props;
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ public class PooledConnection extends ConnectionWrapper implements Poolable<Conn
|
|||||||
try {
|
try {
|
||||||
this.raw = DriverManager.getConnection(config.getUrl(), info);
|
this.raw = DriverManager.getConnection(config.getUrl(), info);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
|
@ -17,7 +17,7 @@ import org.dromara.hutool.core.pool.ObjectFactory;
|
|||||||
import org.dromara.hutool.core.pool.ObjectPool;
|
import org.dromara.hutool.core.pool.ObjectPool;
|
||||||
import org.dromara.hutool.core.pool.partition.PartitionObjectPool;
|
import org.dromara.hutool.core.pool.partition.PartitionObjectPool;
|
||||||
import org.dromara.hutool.core.pool.partition.PartitionPoolConfig;
|
import org.dromara.hutool.core.pool.partition.PartitionPoolConfig;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.config.DbConfig;
|
import org.dromara.hutool.db.config.DbConfig;
|
||||||
import org.dromara.hutool.db.ds.simple.AbstractDataSource;
|
import org.dromara.hutool.db.ds.simple.AbstractDataSource;
|
||||||
import org.dromara.hutool.setting.props.Props;
|
import org.dromara.hutool.setting.props.Props;
|
||||||
@ -102,7 +102,7 @@ public class PooledDataSource extends AbstractDataSource {
|
|||||||
return null != connection
|
return null != connection
|
||||||
&& connection.isValid(maxWait);
|
&& connection.isValid(maxWait);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ package org.dromara.hutool.db.handler;
|
|||||||
import org.dromara.hutool.core.convert.Convert;
|
import org.dromara.hutool.core.convert.Convert;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.Entity;
|
import org.dromara.hutool.db.Entity;
|
||||||
import org.dromara.hutool.db.handler.row.*;
|
import org.dromara.hutool.db.handler.row.*;
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public class ResultSetUtil {
|
|||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
try {
|
try {
|
||||||
generatedKey = rs.getLong(1);
|
generatedKey = rs.getLong(1);
|
||||||
} catch (final DbRuntimeException e) {
|
} catch (final DbException e) {
|
||||||
// 自增主键不为数字或者为Oracle的rowid,跳过
|
// 自增主键不为数字或者为Oracle的rowid,跳过
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ package org.dromara.hutool.db.meta;
|
|||||||
|
|
||||||
import org.dromara.hutool.core.util.BooleanUtil;
|
import org.dromara.hutool.core.util.BooleanUtil;
|
||||||
import org.dromara.hutool.core.regex.ReUtil;
|
import org.dromara.hutool.core.regex.ReUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -108,7 +108,7 @@ public class Column implements Serializable, Cloneable {
|
|||||||
try {
|
try {
|
||||||
init(table, columnMetaRs);
|
init(table, columnMetaRs);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e, "Get table [{}] meta info error!", tableName);
|
throw new DbException(e, "Get table [{}] meta info error!", tableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------- Constructor end
|
// ----------------------------------------------------- Constructor end
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.db.meta;
|
package org.dromara.hutool.db.meta;
|
||||||
|
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -39,7 +39,7 @@ public class ColumnIndexInfo implements Serializable, Cloneable {
|
|||||||
rs.getString("COLUMN_NAME"),
|
rs.getString("COLUMN_NAME"),
|
||||||
rs.getString("ASC_OR_DESC"));
|
rs.getString("ASC_OR_DESC"));
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import org.dromara.hutool.core.collection.ListUtil;
|
|||||||
import org.dromara.hutool.core.convert.Convert;
|
import org.dromara.hutool.core.convert.Convert;
|
||||||
import org.dromara.hutool.core.io.IoUtil;
|
import org.dromara.hutool.core.io.IoUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.Entity;
|
import org.dromara.hutool.db.Entity;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -108,7 +108,7 @@ public class MetaUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new DbRuntimeException("Get tables error!", e);
|
throw new DbException("Get tables error!", e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(conn);
|
IoUtil.closeQuietly(conn);
|
||||||
}
|
}
|
||||||
@ -120,9 +120,9 @@ public class MetaUtil {
|
|||||||
*
|
*
|
||||||
* @param rs 结果集
|
* @param rs 结果集
|
||||||
* @return 列名数组
|
* @return 列名数组
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static String[] getColumnNames(final ResultSet rs) throws DbRuntimeException {
|
public static String[] getColumnNames(final ResultSet rs) throws DbException {
|
||||||
try {
|
try {
|
||||||
final ResultSetMetaData rsmd = rs.getMetaData();
|
final ResultSetMetaData rsmd = rs.getMetaData();
|
||||||
final int columnCount = rsmd.getColumnCount();
|
final int columnCount = rsmd.getColumnCount();
|
||||||
@ -132,7 +132,7 @@ public class MetaUtil {
|
|||||||
}
|
}
|
||||||
return labelNames;
|
return labelNames;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new DbRuntimeException("Get colunms error!", e);
|
throw new DbException("Get colunms error!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ public class MetaUtil {
|
|||||||
* @param ds 数据源
|
* @param ds 数据源
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @return 列数组
|
* @return 列数组
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static String[] getColumnNames(final DataSource ds, final String tableName) {
|
public static String[] getColumnNames(final DataSource ds, final String tableName) {
|
||||||
final List<String> columnNames = new ArrayList<>();
|
final List<String> columnNames = new ArrayList<>();
|
||||||
@ -164,7 +164,7 @@ public class MetaUtil {
|
|||||||
}
|
}
|
||||||
return columnNames.toArray(new String[0]);
|
return columnNames.toArray(new String[0]);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new DbRuntimeException("Get columns error!", e);
|
throw new DbException("Get columns error!", e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(conn);
|
IoUtil.closeQuietly(conn);
|
||||||
}
|
}
|
||||||
@ -283,7 +283,7 @@ public class MetaUtil {
|
|||||||
table.setIndexInfoList(ListUtil.of(indexInfoMap.values()));
|
table.setIndexInfoList(ListUtil.of(indexInfoMap.values()));
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException("Get columns error!", e);
|
throw new DbException("Get columns error!", e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(conn);
|
IoUtil.closeQuietly(conn);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.db.meta;
|
package org.dromara.hutool.db.meta;
|
||||||
|
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
|
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -50,9 +50,9 @@ public class ResultColumn {
|
|||||||
*
|
*
|
||||||
* @param metaData {@link ResultSetMetaData}
|
* @param metaData {@link ResultSetMetaData}
|
||||||
* @param columnIndexBase1 列序号,从1开始。即第一列为1,第二列为2。。。
|
* @param columnIndexBase1 列序号,从1开始。即第一列为1,第二列为2。。。
|
||||||
* @throws DbRuntimeException SQLException包装
|
* @throws DbException SQLException包装
|
||||||
*/
|
*/
|
||||||
public ResultColumn(final ResultSetMetaData metaData, final int columnIndexBase1) throws DbRuntimeException {
|
public ResultColumn(final ResultSetMetaData metaData, final int columnIndexBase1) throws DbException {
|
||||||
try {
|
try {
|
||||||
this.autoIncrement = metaData.isAutoIncrement(columnIndexBase1);
|
this.autoIncrement = metaData.isAutoIncrement(columnIndexBase1);
|
||||||
this.caseSensitive = metaData.isCaseSensitive(columnIndexBase1);
|
this.caseSensitive = metaData.isCaseSensitive(columnIndexBase1);
|
||||||
@ -75,7 +75,7 @@ public class ResultColumn {
|
|||||||
this.definitelyWritable = metaData.isDefinitelyWritable(columnIndexBase1);
|
this.definitelyWritable = metaData.isDefinitelyWritable(columnIndexBase1);
|
||||||
this.className = metaData.getColumnClassName(columnIndexBase1);
|
this.className = metaData.getColumnClassName(columnIndexBase1);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ package org.dromara.hutool.db.sql;
|
|||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import org.dromara.hutool.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.collection.ListUtil;
|
import org.dromara.hutool.core.collection.ListUtil;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import org.dromara.hutool.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.Entity;
|
import org.dromara.hutool.db.Entity;
|
||||||
import org.dromara.hutool.db.Page;
|
import org.dromara.hutool.db.Page;
|
||||||
|
|
||||||
@ -212,11 +212,11 @@ public class Query implements Cloneable {
|
|||||||
* 获得第一个表名
|
* 获得第一个表名
|
||||||
*
|
*
|
||||||
* @return 表名
|
* @return 表名
|
||||||
* @throws DbRuntimeException 没有表
|
* @throws DbException 没有表
|
||||||
*/
|
*/
|
||||||
public String getFirstTableName() throws DbRuntimeException {
|
public String getFirstTableName() throws DbException {
|
||||||
if (ArrayUtil.isEmpty(this.tableNames)) {
|
if (ArrayUtil.isEmpty(this.tableNames)) {
|
||||||
throw new DbRuntimeException("No tableName!");
|
throw new DbException("No tableName!");
|
||||||
}
|
}
|
||||||
return this.tableNames[0];
|
return this.tableNames[0];
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import org.dromara.hutool.core.lang.builder.Builder;
|
|||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import org.dromara.hutool.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import org.dromara.hutool.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.Entity;
|
import org.dromara.hutool.db.Entity;
|
||||||
import org.dromara.hutool.db.dialect.DialectName;
|
import org.dromara.hutool.db.dialect.DialectName;
|
||||||
import org.dromara.hutool.db.dialect.impl.OracleDialect;
|
import org.dromara.hutool.db.dialect.impl.OracleDialect;
|
||||||
@ -73,17 +73,17 @@ public class SqlBuilder implements Builder<String> {
|
|||||||
* 验证实体类对象的有效性
|
* 验证实体类对象的有效性
|
||||||
*
|
*
|
||||||
* @param entity 实体类对象
|
* @param entity 实体类对象
|
||||||
* @throws DbRuntimeException SQL异常包装,获取元数据信息失败
|
* @throws DbException SQL异常包装,获取元数据信息失败
|
||||||
*/
|
*/
|
||||||
public static void validateEntity(final Entity entity) throws DbRuntimeException {
|
public static void validateEntity(final Entity entity) throws DbException {
|
||||||
if (null == entity) {
|
if (null == entity) {
|
||||||
throw new DbRuntimeException("Entity is null !");
|
throw new DbException("Entity is null !");
|
||||||
}
|
}
|
||||||
if (StrUtil.isBlank(entity.getTableName())) {
|
if (StrUtil.isBlank(entity.getTableName())) {
|
||||||
throw new DbRuntimeException("Entity`s table name is null !");
|
throw new DbException("Entity`s table name is null !");
|
||||||
}
|
}
|
||||||
if (entity.isEmpty()) {
|
if (entity.isEmpty()) {
|
||||||
throw new DbRuntimeException("No filed and value in this entity !");
|
throw new DbException("No filed and value in this entity !");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ public class SqlBuilder implements Builder<String> {
|
|||||||
*/
|
*/
|
||||||
public SqlBuilder delete(String tableName) {
|
public SqlBuilder delete(String tableName) {
|
||||||
if (StrUtil.isBlank(tableName)) {
|
if (StrUtil.isBlank(tableName)) {
|
||||||
throw new DbRuntimeException("Table name is blank !");
|
throw new DbException("Table name is blank !");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != quoteWrapper) {
|
if (null != quoteWrapper) {
|
||||||
@ -339,7 +339,7 @@ public class SqlBuilder implements Builder<String> {
|
|||||||
*/
|
*/
|
||||||
public SqlBuilder from(String... tableNames) {
|
public SqlBuilder from(String... tableNames) {
|
||||||
if (ArrayUtil.isEmpty(tableNames) || ArrayUtil.hasBlank(tableNames)) {
|
if (ArrayUtil.isEmpty(tableNames) || ArrayUtil.hasBlank(tableNames)) {
|
||||||
throw new DbRuntimeException("Table name is blank in table names !");
|
throw new DbException("Table name is blank in table names !");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != quoteWrapper) {
|
if (null != quoteWrapper) {
|
||||||
@ -489,7 +489,7 @@ public class SqlBuilder implements Builder<String> {
|
|||||||
*/
|
*/
|
||||||
public SqlBuilder join(String tableName, final Join join) {
|
public SqlBuilder join(String tableName, final Join join) {
|
||||||
if (StrUtil.isBlank(tableName)) {
|
if (StrUtil.isBlank(tableName)) {
|
||||||
throw new DbRuntimeException("Table name is blank !");
|
throw new DbException("Table name is blank !");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != join) {
|
if (null != join) {
|
||||||
|
@ -15,7 +15,7 @@ package org.dromara.hutool.db.sql;
|
|||||||
import org.dromara.hutool.core.collection.iter.ArrayIter;
|
import org.dromara.hutool.core.collection.iter.ArrayIter;
|
||||||
import org.dromara.hutool.core.io.IoUtil;
|
import org.dromara.hutool.core.io.IoUtil;
|
||||||
import org.dromara.hutool.core.func.SerFunction;
|
import org.dromara.hutool.core.func.SerFunction;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.StatementUtil;
|
import org.dromara.hutool.db.StatementUtil;
|
||||||
import org.dromara.hutool.db.handler.RsHandler;
|
import org.dromara.hutool.db.handler.RsHandler;
|
||||||
|
|
||||||
@ -39,10 +39,10 @@ public class SqlExecutor {
|
|||||||
* @param sql SQL,使用name做为占位符,例如:name
|
* @param sql SQL,使用name做为占位符,例如:name
|
||||||
* @param paramMap 参数Map
|
* @param paramMap 参数Map
|
||||||
* @return 影响的行数
|
* @return 影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.0.10
|
* @since 4.0.10
|
||||||
*/
|
*/
|
||||||
public static int execute(final Connection conn, final String sql, final Map<String, Object> paramMap) throws DbRuntimeException {
|
public static int execute(final Connection conn, final String sql, final Map<String, Object> paramMap) throws DbException {
|
||||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||||
return execute(conn, namedSql.getSql(), namedSql.getParamArray());
|
return execute(conn, namedSql.getSql(), namedSql.getParamArray());
|
||||||
}
|
}
|
||||||
@ -56,15 +56,15 @@ public class SqlExecutor {
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 影响的行数
|
* @return 影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static int execute(final Connection conn, final String sql, final Object... params) throws DbRuntimeException {
|
public static int execute(final Connection conn, final String sql, final Object... params) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
ps = StatementUtil.prepareStatement(false, conn, sql, params);
|
ps = StatementUtil.prepareStatement(false, conn, sql, params);
|
||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
@ -78,15 +78,15 @@ public class SqlExecutor {
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 如果执行后第一个结果是ResultSet,则返回true,否则返回false。
|
* @return 如果执行后第一个结果是ResultSet,则返回true,否则返回false。
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static boolean call(final Connection conn, final String sql, final Object... params) throws DbRuntimeException {
|
public static boolean call(final Connection conn, final String sql, final Object... params) throws DbException {
|
||||||
CallableStatement call = null;
|
CallableStatement call = null;
|
||||||
try {
|
try {
|
||||||
call = StatementUtil.prepareCall(conn, sql, params);
|
call = StatementUtil.prepareCall(conn, sql, params);
|
||||||
return call.execute();
|
return call.execute();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(call);
|
IoUtil.closeQuietly(call);
|
||||||
}
|
}
|
||||||
@ -100,14 +100,14 @@ public class SqlExecutor {
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return ResultSet
|
* @return ResultSet
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.1.4
|
* @since 4.1.4
|
||||||
*/
|
*/
|
||||||
public static ResultSet callQuery(final Connection conn, final String sql, final Object... params) throws DbRuntimeException {
|
public static ResultSet callQuery(final Connection conn, final String sql, final Object... params) throws DbException {
|
||||||
try {
|
try {
|
||||||
return StatementUtil.prepareCall(conn, sql, params).executeQuery();
|
return StatementUtil.prepareCall(conn, sql, params).executeQuery();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,10 +120,10 @@ public class SqlExecutor {
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param paramMap 参数Map
|
* @param paramMap 参数Map
|
||||||
* @return 主键
|
* @return 主键
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.0.10
|
* @since 4.0.10
|
||||||
*/
|
*/
|
||||||
public static Long executeForGeneratedKey(final Connection conn, final String sql, final Map<String, Object> paramMap) throws DbRuntimeException {
|
public static Long executeForGeneratedKey(final Connection conn, final String sql, final Map<String, Object> paramMap) throws DbException {
|
||||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||||
return executeForGeneratedKey(conn, namedSql.getSql(), namedSql.getParamArray());
|
return executeForGeneratedKey(conn, namedSql.getSql(), namedSql.getParamArray());
|
||||||
}
|
}
|
||||||
@ -137,9 +137,9 @@ public class SqlExecutor {
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 主键
|
* @return 主键
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static Long executeForGeneratedKey(final Connection conn, final String sql, final Object... params) throws DbRuntimeException {
|
public static Long executeForGeneratedKey(final Connection conn, final String sql, final Object... params) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
@ -155,7 +155,7 @@ public class SqlExecutor {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
IoUtil.closeQuietly(rs);
|
IoUtil.closeQuietly(rs);
|
||||||
@ -171,15 +171,15 @@ public class SqlExecutor {
|
|||||||
* @param sql SQL
|
* @param sql SQL
|
||||||
* @param paramsBatch 批量的参数
|
* @param paramsBatch 批量的参数
|
||||||
* @return 每个SQL执行影响的行数
|
* @return 每个SQL执行影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static int[] executeBatch(final Connection conn, final String sql, final Iterable<Object[]> paramsBatch) throws DbRuntimeException {
|
public static int[] executeBatch(final Connection conn, final String sql, final Iterable<Object[]> paramsBatch) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
ps = StatementUtil.prepareStatementForBatch(conn, sql, paramsBatch);
|
ps = StatementUtil.prepareStatementForBatch(conn, sql, paramsBatch);
|
||||||
return ps.executeBatch();
|
return ps.executeBatch();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(ps);
|
IoUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
@ -193,10 +193,10 @@ public class SqlExecutor {
|
|||||||
* @param conn 数据库连接对象
|
* @param conn 数据库连接对象
|
||||||
* @param sqls SQL列表
|
* @param sqls SQL列表
|
||||||
* @return 每个SQL执行影响的行数
|
* @return 每个SQL执行影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.5.6
|
* @since 4.5.6
|
||||||
*/
|
*/
|
||||||
public static int[] executeBatch(final Connection conn, final String... sqls) throws DbRuntimeException {
|
public static int[] executeBatch(final Connection conn, final String... sqls) throws DbException {
|
||||||
return executeBatch(conn, new ArrayIter<>(sqls));
|
return executeBatch(conn, new ArrayIter<>(sqls));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,10 +208,10 @@ public class SqlExecutor {
|
|||||||
* @param conn 数据库连接对象
|
* @param conn 数据库连接对象
|
||||||
* @param sqls SQL列表
|
* @param sqls SQL列表
|
||||||
* @return 每个SQL执行影响的行数
|
* @return 每个SQL执行影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.5.6
|
* @since 4.5.6
|
||||||
*/
|
*/
|
||||||
public static int[] executeBatch(final Connection conn, final Iterable<String> sqls) throws DbRuntimeException {
|
public static int[] executeBatch(final Connection conn, final Iterable<String> sqls) throws DbException {
|
||||||
Statement statement = null;
|
Statement statement = null;
|
||||||
try {
|
try {
|
||||||
statement = conn.createStatement();
|
statement = conn.createStatement();
|
||||||
@ -220,7 +220,7 @@ public class SqlExecutor {
|
|||||||
}
|
}
|
||||||
return statement.executeBatch();
|
return statement.executeBatch();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(statement);
|
IoUtil.closeQuietly(statement);
|
||||||
}
|
}
|
||||||
@ -236,10 +236,10 @@ public class SqlExecutor {
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param paramMap 参数对
|
* @param paramMap 参数对
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.0.10
|
* @since 4.0.10
|
||||||
*/
|
*/
|
||||||
public static <T> T query(final Connection conn, final String sql, final RsHandler<T> rsh, final Map<String, Object> paramMap) throws DbRuntimeException {
|
public static <T> T query(final Connection conn, final String sql, final RsHandler<T> rsh, final Map<String, Object> paramMap) throws DbException {
|
||||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||||
return query(conn, namedSql.getSql(), rsh, namedSql.getParamArray());
|
return query(conn, namedSql.getSql(), rsh, namedSql.getParamArray());
|
||||||
}
|
}
|
||||||
@ -253,10 +253,10 @@ public class SqlExecutor {
|
|||||||
* @param sqlBuilder SQL构建器,包含参数
|
* @param sqlBuilder SQL构建器,包含参数
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.5.3
|
* @since 5.5.3
|
||||||
*/
|
*/
|
||||||
public static <T> T query(final Connection conn, final SqlBuilder sqlBuilder, final RsHandler<T> rsh) throws DbRuntimeException {
|
public static <T> T query(final Connection conn, final SqlBuilder sqlBuilder, final RsHandler<T> rsh) throws DbException {
|
||||||
return query(conn, sqlBuilder.build(), rsh, sqlBuilder.getParamValueArray());
|
return query(conn, sqlBuilder.build(), rsh, sqlBuilder.getParamValueArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,9 +270,9 @@ public class SqlExecutor {
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static <T> T query(final Connection conn, final String sql, final RsHandler<T> rsh, final Object... params) throws DbRuntimeException {
|
public static <T> T query(final Connection conn, final String sql, final RsHandler<T> rsh, final Object... params) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
ps = StatementUtil.prepareStatement(false, conn, sql, params);
|
ps = StatementUtil.prepareStatement(false, conn, sql, params);
|
||||||
@ -291,10 +291,10 @@ public class SqlExecutor {
|
|||||||
* @param statementFunc 自定义{@link PreparedStatement}创建函数
|
* @param statementFunc 自定义{@link PreparedStatement}创建函数
|
||||||
* @param rsh 自定义结果集处理
|
* @param rsh 自定义结果集处理
|
||||||
* @return 结果
|
* @return 结果
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 5.7.17
|
* @since 5.7.17
|
||||||
*/
|
*/
|
||||||
public static <T> T query(final Connection conn, final SerFunction<Connection, PreparedStatement> statementFunc, final RsHandler<T> rsh) throws DbRuntimeException {
|
public static <T> T query(final Connection conn, final SerFunction<Connection, PreparedStatement> statementFunc, final RsHandler<T> rsh) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
ps = statementFunc.apply(conn);
|
ps = statementFunc.apply(conn);
|
||||||
@ -316,14 +316,14 @@ public class SqlExecutor {
|
|||||||
* @param ps PreparedStatement对象
|
* @param ps PreparedStatement对象
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 影响的行数
|
* @return 影响的行数
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static int executeUpdate(final PreparedStatement ps, final Object... params) throws DbRuntimeException {
|
public static int executeUpdate(final PreparedStatement ps, final Object... params) throws DbException {
|
||||||
try {
|
try {
|
||||||
StatementUtil.fillArrayParam(ps, params);
|
StatementUtil.fillArrayParam(ps, params);
|
||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,14 +335,14 @@ public class SqlExecutor {
|
|||||||
* @param ps PreparedStatement对象
|
* @param ps PreparedStatement对象
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 如果执行后第一个结果是ResultSet,则返回true,否则返回false。
|
* @return 如果执行后第一个结果是ResultSet,则返回true,否则返回false。
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static boolean execute(final PreparedStatement ps, final Object... params) throws DbRuntimeException {
|
public static boolean execute(final PreparedStatement ps, final Object... params) throws DbException {
|
||||||
try {
|
try {
|
||||||
StatementUtil.fillArrayParam(ps, params);
|
StatementUtil.fillArrayParam(ps, params);
|
||||||
return ps.execute();
|
return ps.execute();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,14 +355,14 @@ public class SqlExecutor {
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static <T> T query(final PreparedStatement ps, final RsHandler<T> rsh, final Object... params) throws DbRuntimeException {
|
public static <T> T query(final PreparedStatement ps, final RsHandler<T> rsh, final Object... params) throws DbException {
|
||||||
try {
|
try {
|
||||||
StatementUtil.fillArrayParam(ps, params);
|
StatementUtil.fillArrayParam(ps, params);
|
||||||
return executeQuery(ps, rsh);
|
return executeQuery(ps, rsh);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,9 +374,9 @@ public class SqlExecutor {
|
|||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public static <T> T queryAndClosePs(final PreparedStatement ps, final RsHandler<T> rsh, final Object... params) throws DbRuntimeException {
|
public static <T> T queryAndClosePs(final PreparedStatement ps, final RsHandler<T> rsh, final Object... params) throws DbException {
|
||||||
try {
|
try {
|
||||||
return query(ps, rsh, params);
|
return query(ps, rsh, params);
|
||||||
} finally {
|
} finally {
|
||||||
@ -392,16 +392,16 @@ public class SqlExecutor {
|
|||||||
* @param ps {@link PreparedStatement}
|
* @param ps {@link PreparedStatement}
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbException SQL执行异常
|
||||||
* @since 4.1.13
|
* @since 4.1.13
|
||||||
*/
|
*/
|
||||||
private static <T> T executeQuery(final PreparedStatement ps, final RsHandler<T> rsh) throws DbRuntimeException {
|
private static <T> T executeQuery(final PreparedStatement ps, final RsHandler<T> rsh) throws DbException {
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
return rsh.handle(rs);
|
return rsh.handle(rs);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(rs);
|
IoUtil.closeQuietly(rs);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ package org.dromara.hutool.db.sql;
|
|||||||
import org.dromara.hutool.core.io.IoUtil;
|
import org.dromara.hutool.core.io.IoUtil;
|
||||||
import org.dromara.hutool.core.util.CharsetUtil;
|
import org.dromara.hutool.core.util.CharsetUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.Entity;
|
import org.dromara.hutool.db.Entity;
|
||||||
import org.dromara.hutool.db.sql.Condition.LikeType;
|
import org.dromara.hutool.db.sql.Condition.LikeType;
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ public class SqlUtil {
|
|||||||
reader = clob.getCharacterStream();
|
reader = clob.getCharacterStream();
|
||||||
return IoUtil.read(reader);
|
return IoUtil.read(reader);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(reader);
|
IoUtil.closeQuietly(reader);
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ public class SqlUtil {
|
|||||||
in = blob.getBinaryStream();
|
in = blob.getBinaryStream();
|
||||||
return IoUtil.read(in, charset);
|
return IoUtil.read(in, charset);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(in);
|
IoUtil.closeQuietly(in);
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ public class SqlUtil {
|
|||||||
out = blob.setBinaryStream(1);
|
out = blob.setBinaryStream(1);
|
||||||
IoUtil.copy(dataStream, out);
|
IoUtil.copy(dataStream, out);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(out);
|
IoUtil.closeQuietly(out);
|
||||||
if (closeAfterUse) {
|
if (closeAfterUse) {
|
||||||
@ -238,7 +238,7 @@ public class SqlUtil {
|
|||||||
blob = conn.createBlob();
|
blob = conn.createBlob();
|
||||||
blob.setBytes(0, data);
|
blob.setBytes(0, data);
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import org.dromara.hutool.core.lang.Assert;
|
|||||||
import org.dromara.hutool.core.lang.builder.Builder;
|
import org.dromara.hutool.core.lang.builder.Builder;
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.DbRuntimeException;
|
import org.dromara.hutool.db.DbException;
|
||||||
import org.dromara.hutool.db.Entity;
|
import org.dromara.hutool.db.Entity;
|
||||||
import org.dromara.hutool.db.sql.filter.SqlFilter;
|
import org.dromara.hutool.db.sql.filter.SqlFilter;
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ public class StatementBuilder implements Builder<StatementWrapper> {
|
|||||||
try {
|
try {
|
||||||
return _build();
|
return _build();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,9 +126,9 @@ public class StatementBuilder implements Builder<StatementWrapper> {
|
|||||||
* 创建批量操作的{@link StatementWrapper}
|
* 创建批量操作的{@link StatementWrapper}
|
||||||
*
|
*
|
||||||
* @return {@link StatementWrapper},{@code null}表示不执行
|
* @return {@link StatementWrapper},{@code null}表示不执行
|
||||||
* @throws DbRuntimeException SQL异常
|
* @throws DbException SQL异常
|
||||||
*/
|
*/
|
||||||
public StatementWrapper buildForBatch() throws DbRuntimeException {
|
public StatementWrapper buildForBatch() throws DbException {
|
||||||
final String sql = this.boundSql.getSql();
|
final String sql = this.boundSql.getSql();
|
||||||
Assert.notBlank(sql, "Sql String must be not blank!");
|
Assert.notBlank(sql, "Sql String must be not blank!");
|
||||||
final List<Object> paramsBatch = this.boundSql.getParams();
|
final List<Object> paramsBatch = this.boundSql.getParams();
|
||||||
@ -159,7 +159,7 @@ public class StatementBuilder implements Builder<StatementWrapper> {
|
|||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ public class StatementBuilder implements Builder<StatementWrapper> {
|
|||||||
.fillArrayParam(params)
|
.fillArrayParam(params)
|
||||||
.getRaw();
|
.getRaw();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
throw new DbRuntimeException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user