feat: 增加缓存机制,sql在生命周期内仅构建一次

This commit is contained in:
wangyu 2023-03-01 11:38:42 +08:00
parent 4f8384ee88
commit df4349b774

View File

@ -14,7 +14,6 @@ import group.flyfish.fluent.query.Parameterized;
import group.flyfish.fluent.query.Query; import group.flyfish.fluent.query.Query;
import group.flyfish.fluent.update.Update; import group.flyfish.fluent.update.Update;
import group.flyfish.fluent.update.UpdateImpl; import group.flyfish.fluent.update.UpdateImpl;
import group.flyfish.fluent.utils.cache.CachedWrapper;
import group.flyfish.fluent.utils.context.AliasComposite; import group.flyfish.fluent.utils.context.AliasComposite;
import group.flyfish.fluent.utils.data.ParameterUtils; import group.flyfish.fluent.utils.data.ParameterUtils;
import group.flyfish.fluent.utils.sql.ConcatSegment; import group.flyfish.fluent.utils.sql.ConcatSegment;
@ -29,6 +28,8 @@ import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static group.flyfish.fluent.utils.cache.CachedWrapper.wrap;
/** /**
* 查询工具类 * 查询工具类
* *
@ -45,7 +46,7 @@ final class SQLImpl extends ConcatSegment<SQLImpl> implements SQLOperations, Pre
private Class<?> primaryClass; private Class<?> primaryClass;
// sql实体提供者 // sql实体提供者
private final Supplier<SQLEntity> entity = CachedWrapper.wrap(this::entity); private final Supplier<SQLEntity> entity = wrap(this::entity);
/** /**
* 绑定实现类 * 绑定实现类
@ -270,7 +271,7 @@ final class SQLImpl extends ConcatSegment<SQLImpl> implements SQLOperations, Pre
* @return 转换结果 * @return 转换结果
*/ */
private SQLEntity entity() { private SQLEntity entity() {
return SQLEntity.of(CachedWrapper.wrap(this::sql), this::parsedParameters); return SQLEntity.of(wrap(this::sql), wrap(this::parsedParameters));
} }
} }