mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
重构Jdk自带的Lambda体系,支持序列化+包裹受检异常
改动如下: 1. AnnotationUtil 115行 简化 predicate::test 为 predicate 2. 调整 Func1 为 SerFunction 3. 调整 Func0 为 SerSupplier 4. 移除 GenericBuilder 对于多参数构造双冒号简写支持,直接采用lambda方式,例如GenericBuilder.of(Box::new, 2048L, "Hello Partner!", 222, 333, 444)改为GenericBuilder.of(() -> new Box(2048L, "Hello Partner!", 222, 333, 444)) 5. 移除 CheckedUtil,现有重构后的Lambda 支持包裹异常 6. 移除 Func,该函数式接口属于泛型可变参数,不推荐使用 7. 移除 Supplier1,1参数Supplier应该使用SerFunction替代 8. 移除 Supplier2,2参数Supplier应该使用SerBiFunction替代 9. 移除 Supplier3,3参数Supplier应该使用SerFunction3替代(因第4条更改思路,该SerFunction3并未添加) 10. 移除 Supplier4,4参数Supplier应该使用SerFunction4替代(因第4条更改思路,该SerFunction4并未添加) 11. 移除 Supplier5,5参数Supplier应该使用SerFunction5替代(因第4条更改思路,该SerFunction5并未添加) 12. 移除 VoidFunc,该函数式接口属于泛型可变参数,不推荐使用 13. 调整 VoidFunc0 为 SerRunnable 14. 调整 VoidFunc1 为 SerConsumer 15. 调整 EntryStream 泛型命名、完善javadoc 16. EnumUtil 273行 简化 field::callWithRuntimeException 为 field
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.func.Func1;
|
||||
import cn.hutool.core.lang.func.SerFunction;
|
||||
import cn.hutool.db.dialect.Dialect;
|
||||
import cn.hutool.db.handler.BeanListHandler;
|
||||
import cn.hutool.db.handler.EntityHandler;
|
||||
@@ -191,7 +191,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
||||
* @throws DbRuntimeException SQL执行异常
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public <T> T query(final Func1<Connection, PreparedStatement> statementFunc, final RsHandler<T> rsh) throws DbRuntimeException {
|
||||
public <T> T query(final SerFunction<Connection, PreparedStatement> statementFunc, final RsHandler<T> rsh) throws DbRuntimeException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.lang.func.Func0;
|
||||
import cn.hutool.core.lang.func.SerSupplier;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -144,7 +144,7 @@ public class ActiveEntity extends Entity {
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public ActiveEntity setFields(final Func0<?>... fields) {
|
||||
public ActiveEntity setFields(final SerSupplier<?>... fields) {
|
||||
return (ActiveEntity) super.setFields(fields);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.lang.func.VoidFunc1;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.db.dialect.Dialect;
|
||||
import cn.hutool.db.dialect.DialectFactory;
|
||||
import cn.hutool.db.ds.DSFactory;
|
||||
@@ -114,7 +114,7 @@ public class Db extends AbstractDb<Db> {
|
||||
* @return this
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
public Db tx(final VoidFunc1<Db> func) throws SQLException {
|
||||
public Db tx(final SerConsumer<Db> func) throws SQLException {
|
||||
return tx(null, func);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class Db extends AbstractDb<Db> {
|
||||
* @return this
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
public Db tx(final TransactionLevel transactionLevel, final VoidFunc1<Db> func) throws SQLException {
|
||||
public Db tx(final TransactionLevel transactionLevel, final SerConsumer<Db> func) throws SQLException {
|
||||
final Connection conn = getConnection();
|
||||
|
||||
// 检查是否支持事务
|
||||
|
@@ -2,7 +2,7 @@ package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.lang.func.Func0;
|
||||
import cn.hutool.core.lang.func.SerSupplier;
|
||||
import cn.hutool.core.map.Dict;
|
||||
import cn.hutool.core.reflect.MethodUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
@@ -180,7 +180,7 @@ public class Entity extends Dict {
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Entity setFields(final Func0<?>... fields) {
|
||||
public Entity setFields(final SerSupplier<?>... fields) {
|
||||
return (Entity) super.setFields(fields);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.lang.func.VoidFunc1;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.db.dialect.Dialect;
|
||||
import cn.hutool.db.dialect.DialectFactory;
|
||||
@@ -249,16 +249,16 @@ public class Session extends AbstractDb<Session> implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 在事务中执行操作,通过实现{@link VoidFunc1}接口的call方法执行多条SQL语句从而完成事务
|
||||
* 在事务中执行操作,通过实现{@link SerConsumer}接口的call方法执行多条SQL语句从而完成事务
|
||||
*
|
||||
* @param func 函数抽象,在函数中执行多个SQL操作,多个操作会被合并为同一事务
|
||||
* @throws DbRuntimeException SQL异常
|
||||
* @since 3.2.3
|
||||
*/
|
||||
public void tx(final VoidFunc1<Session> func) throws DbRuntimeException {
|
||||
public void tx(final SerConsumer<Session> func) throws DbRuntimeException {
|
||||
try {
|
||||
beginTransaction();
|
||||
func.call(this);
|
||||
func.accept(this);
|
||||
commit();
|
||||
} catch (final Throwable e) {
|
||||
quietRollback();
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.collection.iter.ArrayIter;
|
||||
import cn.hutool.core.lang.func.Func1;
|
||||
import cn.hutool.core.lang.func.SerFunction;
|
||||
import cn.hutool.db.DbRuntimeException;
|
||||
import cn.hutool.db.DbUtil;
|
||||
import cn.hutool.db.StatementUtil;
|
||||
@@ -289,10 +289,10 @@ public class SqlExecutor {
|
||||
* @throws DbRuntimeException SQL执行异常
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public static <T> T query(final Connection conn, final Func1<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 DbRuntimeException {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
ps = statementFunc.callWithRuntimeException(conn);
|
||||
ps = statementFunc.apply(conn);
|
||||
return executeQuery(ps, rsh);
|
||||
} finally {
|
||||
DbUtil.close(ps);
|
||||
|
Reference in New Issue
Block a user