From 7759a1a0a1a137b2d7f57546705523342a34eb8c Mon Sep 17 00:00:00 2001 From: simmyan <8966188@qq.com> Date: Sat, 30 Sep 2023 13:33:42 +0800 Subject: [PATCH] refaPara --- .../main/java/io/xream/sqli/api/Routable.java | 2 +- .../main/java/io/xream/sqli/builder/QB.java | 14 ++--- .../io/xream/sqli/builder/SourceScript.java | 2 +- .../sqli/builder/internal/DefaultQ2Sql.java | 52 ++++++++--------- ...axException.java => QSyntaxException.java} | 6 +- .../io/xream/sqli/filter/BaseTypeFilter.java | 4 +- .../java/io/xream/sqli/parser/Parser.java | 2 +- ...Support.java => XSingleSourceSupport.java} | 12 ++-- .../java/io/xream/sqli/test/SqlGenerator.java | 12 ++-- .../java/io/xream/sqli/util/ParserUtil.java | 2 +- sqli-core/README.md | 2 +- .../java/io/xream/sqli/api/RepositoryX.java | 2 +- .../xream/sqli/api/TemporaryRepository.java | 2 +- .../internal/DefaultL2CacheResolver.java | 12 ++-- .../java/io/xream/sqli/converter/X2Bean.java | 2 +- .../{ResultMapFinder.java => XFinder.java} | 8 +-- .../java/io/xream/sqli/spi/JdbcHelper.java | 4 +- .../repository/core/CacheableRepository.java | 30 +++++----- .../io/xream/sqli/repository/dao/Dao.java | 8 +-- .../io/xream/sqli/repository/dao/DaoImpl.java | 56 +++++++++---------- .../xream/sqli/repository/dao/SqlBuilder.java | 8 +-- .../sqli/repository/dao/TemporaryDao.java | 2 +- .../sqli/repository/dao/TemporaryDaoImpl.java | 4 +- .../internal/DefaultRepositoryX.java | 48 ++++++++-------- .../internal/DefaultTemporaryRepository.java | 6 +- .../repository/internal/SafeRefreshBiz.java | 6 +- .../io/xream/sqli/starter/SqliStarter.java | 2 +- 27 files changed, 154 insertions(+), 156 deletions(-) rename sqli-builder/src/main/java/io/xream/sqli/exception/{CriteriaSyntaxException.java => QSyntaxException.java} (83%) rename sqli-builder/src/main/java/io/xream/sqli/support/{ResultMapSingleSourceSupport.java => XSingleSourceSupport.java} (74%) rename sqli-core/src/main/java/io/xream/sqli/core/{ResultMapFinder.java => XFinder.java} (85%) diff --git a/sqli-builder/src/main/java/io/xream/sqli/api/Routable.java b/sqli-builder/src/main/java/io/xream/sqli/api/Routable.java index 5faaf42f..69bf2001 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/api/Routable.java +++ b/sqli-builder/src/main/java/io/xream/sqli/api/Routable.java @@ -21,7 +21,7 @@ /** * to find target unit, * not for db sharding, - * not suggest having Criteria,qr as the request object, the interface + * not suggest having Q,qr as the request object, the interface * of Routeable maybe meaningless, of cource, your request object clzz can implements * Routeable * diff --git a/sqli-builder/src/main/java/io/xream/sqli/builder/QB.java b/sqli-builder/src/main/java/io/xream/sqli/builder/QB.java index a2511563..d4272dff 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/builder/QB.java +++ b/sqli-builder/src/main/java/io/xream/sqli/builder/QB.java @@ -131,8 +131,8 @@ public static QB of(Class clz) { } public static X x() { - Q.X resultMapCriteria = new Q.X(); - return new X(resultMapCriteria); + Q.X xq = new Q.X(); + return new X(xq); } public Class getClz() { @@ -173,8 +173,8 @@ public SourceBuilder source(Class clzz) { public SourceBuilder sub(Sub sub) { X subBuilder = QB.x(); sub.buildBy(subBuilder); - Q.X resultMapCriteria = subBuilder.build(); - sourceScriptTemp.setSubQ(resultMapCriteria); + Q.X xq = subBuilder.build(); + sourceScriptTemp.setSubQ(xq); subBuilder.clear(); return this; } @@ -345,11 +345,11 @@ public X sourceScript(String sourceScript, Object...vs) { public X distinct(String... objs) { if (objs == null) throw new IllegalArgumentException("distinct non resultKey"); - Q.X resultMapped = get(); - Distinct distinct = resultMapped.getDistinct(); + Q.X xq = get(); + Distinct distinct = xq.getDistinct(); if (Objects.isNull(distinct)) { distinct = new Distinct(); - resultMapped.setDistinct(distinct); + xq.setDistinct(distinct); } for (String obj : objs) { distinct.add(obj); diff --git a/sqli-builder/src/main/java/io/xream/sqli/builder/SourceScript.java b/sqli-builder/src/main/java/io/xream/sqli/builder/SourceScript.java index aff092f6..0074b503 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/builder/SourceScript.java +++ b/sqli-builder/src/main/java/io/xream/sqli/builder/SourceScript.java @@ -182,7 +182,7 @@ public String sql(Mappable mappable) { public String toString() { return "SourceScript{" + "source='" + source + '\'' + - ", subCriteria=" + subQ + + ", subQ=" + subQ + ", joinType=" + joinType + ", joinStr='" + joinStr + '\'' + ", on=" + on + diff --git a/sqli-builder/src/main/java/io/xream/sqli/builder/internal/DefaultQ2Sql.java b/sqli-builder/src/main/java/io/xream/sqli/builder/internal/DefaultQ2Sql.java index b07f3da2..34a1105c 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/builder/internal/DefaultQ2Sql.java +++ b/sqli-builder/src/main/java/io/xream/sqli/builder/internal/DefaultQ2Sql.java @@ -19,7 +19,7 @@ package io.xream.sqli.builder.internal; import io.xream.sqli.builder.*; -import io.xream.sqli.exception.CriteriaSyntaxException; +import io.xream.sqli.exception.QSyntaxException; import io.xream.sqli.exception.ParsingException; import io.xream.sqli.exception.SqlBuildException; import io.xream.sqli.filter.BaseTypeFilter; @@ -27,7 +27,7 @@ import io.xream.sqli.parser.BeanElement; import io.xream.sqli.parser.Parsed; import io.xream.sqli.parser.Parser; -import io.xream.sqli.support.ResultMapSingleSourceSupport; +import io.xream.sqli.support.XSingleSourceSupport; import io.xream.sqli.support.TimeSupport; import io.xream.sqli.util.EnumUtil; import io.xream.sqli.util.SqliJsonUtil; @@ -39,7 +39,7 @@ /** * @author Sim */ -public final class DefaultQ2Sql implements Q2Sql, ResultKeyGenerator, SourceScriptOptimizable, ResultMapSingleSourceSupport { +public final class DefaultQ2Sql implements Q2Sql, ResultKeyGenerator, SourceScriptOptimizable, XSingleSourceSupport { private static Q2Sql instance; @@ -358,25 +358,25 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta boolean flag = false; - Q.X resultMapped = (Q.X) q; + Q.X xq = (Q.X) q; StringBuilder columnBuilder = new StringBuilder(); - Map mapperPropertyMap = resultMapped.getMapperPropertyMap(); + Map mapperPropertyMap = xq.getMapperPropertyMap(); - if (Objects.nonNull(resultMapped.getDistinct())) { + if (Objects.nonNull(xq.getDistinct())) { columnBuilder.append(SqlScript.DISTINCT); - List list = resultMapped.getDistinct().getList(); + List list = xq.getDistinct().getList(); int size = list.size(); int i = 0; StringBuilder distinctColumn = new StringBuilder(); distinctColumn.append(columnBuilder); for (String resultKey : list) { addConditonBeforeOptimization(resultKey, sqlSth.conditionSet); - String mapper = mapping(resultKey, resultMapped); + String mapper = mapping(resultKey, xq); mapperPropertyMap.put(mapper, resultKey);//REDUCE ALIAN NAME distinctColumn.append(SqlScript.SPACE).append(mapper); - mapper = generate(mapper, resultMapped); + mapper = generate(mapper, xq); columnBuilder.append(SqlScript.SPACE).append(mapper); i++; if (i < size) { @@ -388,7 +388,7 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta flag = true; } - List reduceList = resultMapped.getReduceList(); + List reduceList = xq.getReduceList(); if (!reduceList.isEmpty()) { @@ -399,7 +399,7 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta addConditonBeforeOptimization(reduce.getProperty(), sqlSth.conditionSet); String alianProperty = reduce.getProperty() + SqlScript.UNDER_LINE + reduce.getType().toString().toLowerCase();//property_count String alianName = alianProperty.replace(SqlScript.DOT, SqlScript.DOLLOR); - resultMapped.getResultKeyAliaMap().put(alianName, alianProperty); + xq.getResultKeyAliaMap().put(alianName, alianProperty); String value = mapping(reduce.getProperty(), q); @@ -428,13 +428,13 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta Having h = reduce.getHaving(); if (h != null) { h.setAliaOrFunction(alianName); - resultMapped.getHavingList().add(h); + xq.getHavingList().add(h); } flag = true; } } - List resultList = resultMapped.getResultKeyList(); + List resultList = xq.getResultKeyList(); if (!resultList.isEmpty()) { if (flag) { columnBuilder.append(SqlScript.COMMA); @@ -445,7 +445,7 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta addConditonBeforeOptimization(resultKey, sqlSth.conditionSet); String mapper = mapping(resultKey, q); mapperPropertyMap.put(mapper, resultKey); - mapper = generate(mapper, resultMapped); + mapper = generate(mapper, xq); columnBuilder.append(SqlScript.SPACE).append(mapper); if (i < size - 1) { columnBuilder.append(SqlScript.COMMA); @@ -455,7 +455,7 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta } - List resultListAssignedAliaList = resultMapped.getResultKeyAssignedAliaList(); + List resultListAssignedAliaList = xq.getResultKeyAssignedAliaList(); if (!resultListAssignedAliaList.isEmpty()) { if (flag) { columnBuilder.append(SqlScript.COMMA); @@ -468,7 +468,7 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta String mapper = mapping(key, q); mapperPropertyMap.put(mapper, key); String alian = kv.getV().toString(); - resultMapped.getResultKeyAliaMap().put(alian, mapper); + xq.getResultKeyAliaMap().put(alian, mapper); columnBuilder.append(SqlScript.SPACE).append(mapper).append(SqlScript.AS).append(alian); if (i < size - 1) { columnBuilder.append(SqlScript.COMMA); @@ -478,13 +478,13 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta } - List functionList = resultMapped.getResultFunctionList(); + List functionList = xq.getResultFunctionList(); if (!functionList.isEmpty()) {// if (flag) { columnBuilder.append(SqlScript.COMMA); } - Map resultKeyAliaMap = resultMapped.getResultKeyAliaMap(); + Map resultKeyAliaMap = xq.getResultKeyAliaMap(); int size = functionList.size(); for (int i = 0; i < size; i++) { @@ -516,7 +516,7 @@ private String resultKey(SqlSth sqlSth, Q q, SqlBuildingAttached sqlBuildingAtta String script = columnBuilder.toString(); if (SqliStringUtil.isNullOrEmpty(script)) { - throw new CriteriaSyntaxException("Suggest API: find(Criteria criteria), no any resultKey for ResultMapCriteria"); + throw new QSyntaxException("Suggest API: find(Q Q), q any resultKey for Q.X"); } return script; @@ -596,14 +596,14 @@ private void having(SqlSth sqlSth, Q q) { if (!(q instanceof Q.X)) return; - Q.X resultMapped = (Q.X) q; - List havingList = resultMapped.getHavingList(); + Q.X xq = (Q.X) q; + List havingList = xq.getHavingList(); if (havingList.isEmpty()) return; if (!q.isTotalRowsIgnored()) { - throw new CriteriaSyntaxException("Reduce with having not support totalRows query, try to builder.paged().ignoreTotalRows()"); + throw new QSyntaxException("Reduce with having not support totalRows query, try to builder.paged().ignoreTotalRows()"); } boolean flag = true; @@ -701,7 +701,7 @@ private void sourceScript(SqlSth sb, Q q) { if (rmc.getSourceScripts().isEmpty()) {// builderSource null String str = q.sourceScript(); - Objects.requireNonNull(str, "Not set sourceScript of ResultMappedBuilder"); + Objects.requireNonNull(str, "Not set sourceScript of QB.X"); final String strd = normalizeSql(str); StringBuilder sbs = new StringBuilder(); mapping((reg) -> strd.split(reg), rmc, sbs); @@ -772,13 +772,13 @@ private void filter0(Q q) { List bbList = q.getBbList(); if (q instanceof Q.X) { - Q.X resultMapCriteria = (Q.X) q;//FIXME 判断是虚表 - filter(bbList, resultMapCriteria); + Q.X xq = (Q.X) q;//FIXME 判断是虚表 + filter(bbList, xq); for (SourceScript sourceScript : ((Q.X) q).getSourceScripts()) { List bbs = sourceScript.getBbList(); if (bbs == null || bbs.isEmpty()) continue; - filter(bbs, resultMapCriteria); + filter(bbs, xq); } } else { filter(bbList, q); diff --git a/sqli-builder/src/main/java/io/xream/sqli/exception/CriteriaSyntaxException.java b/sqli-builder/src/main/java/io/xream/sqli/exception/QSyntaxException.java similarity index 83% rename from sqli-builder/src/main/java/io/xream/sqli/exception/CriteriaSyntaxException.java rename to sqli-builder/src/main/java/io/xream/sqli/exception/QSyntaxException.java index bf8eb058..20f3cfe9 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/exception/CriteriaSyntaxException.java +++ b/sqli-builder/src/main/java/io/xream/sqli/exception/QSyntaxException.java @@ -21,11 +21,9 @@ /** * @author Sim */ -public class CriteriaSyntaxException extends RuntimeException{ +public class QSyntaxException extends RuntimeException{ - private static final long serialVersionUID = 5749142995547236081L; - - public CriteriaSyntaxException(String message){ + public QSyntaxException(String message){ super(message); } diff --git a/sqli-builder/src/main/java/io/xream/sqli/filter/BaseTypeFilter.java b/sqli-builder/src/main/java/io/xream/sqli/filter/BaseTypeFilter.java index 929aa514..6c2d37ad 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/filter/BaseTypeFilter.java +++ b/sqli-builder/src/main/java/io/xream/sqli/filter/BaseTypeFilter.java @@ -32,12 +32,12 @@ public final class BaseTypeFilter { public static boolean baseTypeSupported = false; - public static boolean isBaseType(String key, Object v, Mappable criteria) { + public static boolean isBaseType(String key, Object v, Mappable m) { if (! baseTypeSupported) return false; String[] arr = key.split("\\."); String alia = arr[0]; - String clzName = criteria.getAliaMap().get(alia); + String clzName = m.getAliaMap().get(alia); if (clzName == null) clzName = alia; Parsed parsed = Parser.get(clzName); diff --git a/sqli-builder/src/main/java/io/xream/sqli/parser/Parser.java b/sqli-builder/src/main/java/io/xream/sqli/parser/Parser.java index 9736a24c..50bfdfc3 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/parser/Parser.java +++ b/sqli-builder/src/main/java/io/xream/sqli/parser/Parser.java @@ -183,7 +183,7 @@ private static void sortOnParsing(Parsed parsed, List elementList) public static void parse(Class clz) { if (clz == Q.class || clz == Q.X.class || clz == Void.class) - throw new IllegalArgumentException("parser unsupport Criteria, CriteriaJoinable, ...."); + throw new IllegalArgumentException("parser unsupport Q, Q.X, ...."); Parsed parsed = new Parsed(clz); List elementList = ParserUtil.parseElementList(clz); diff --git a/sqli-builder/src/main/java/io/xream/sqli/support/ResultMapSingleSourceSupport.java b/sqli-builder/src/main/java/io/xream/sqli/support/XSingleSourceSupport.java similarity index 74% rename from sqli-builder/src/main/java/io/xream/sqli/support/ResultMapSingleSourceSupport.java rename to sqli-builder/src/main/java/io/xream/sqli/support/XSingleSourceSupport.java index ba26efbb..bdd9b676 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/support/ResultMapSingleSourceSupport.java +++ b/sqli-builder/src/main/java/io/xream/sqli/support/XSingleSourceSupport.java @@ -26,16 +26,16 @@ /** * @author Sim */ -public interface ResultMapSingleSourceSupport { +public interface XSingleSourceSupport { - default void supportSingleSource(Q.X resultMapCriteria) { - if (resultMapCriteria.getSourceScripts().size() == 1 && resultMapCriteria.getParsed() == null) { - SourceScript sourceScript = resultMapCriteria.getSourceScripts().get(0); + default void supportSingleSource(Q.X xq) { + if (xq.getSourceScripts().size() == 1 && xq.getParsed() == null) { + SourceScript sourceScript = xq.getSourceScripts().get(0); String source = sourceScript.getSource(); if (source != null) { Parsed parsed = Parser.get(source); - resultMapCriteria.setParsed(parsed); - resultMapCriteria.setClzz(parsed.getClzz()); + xq.setParsed(parsed); + xq.setClzz(parsed.getClzz()); } } } diff --git a/sqli-builder/src/main/java/io/xream/sqli/test/SqlGenerator.java b/sqli-builder/src/main/java/io/xream/sqli/test/SqlGenerator.java index efb66f8a..e645403b 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/test/SqlGenerator.java +++ b/sqli-builder/src/main/java/io/xream/sqli/test/SqlGenerator.java @@ -36,7 +36,7 @@ public class SqlGenerator { private static SqlGenerator instance; private static Q2Sql condToSql; - private static List resultMapCriteriaList = new ArrayList<>(); + private static List xKvList = new ArrayList<>(); private SqlGenerator(){} @@ -54,9 +54,9 @@ public SqlGenerator source(Class clzz) { return instance; } - public SqlGenerator build(String traceKey, Q.X resultMapCriteria){ - KV kv = new KV(traceKey,resultMapCriteria); - resultMapCriteriaList.add(kv); + public SqlGenerator build(String traceKey, Q.X xq){ + KV kv = new KV(traceKey,xq); + xKvList.add(kv); return instance; } @@ -64,7 +64,7 @@ public void generate(String fileName){ StringBuilder sb = new StringBuilder(); - for (KV kv : resultMapCriteriaList) { + for (KV kv : xKvList) { SqlBuilt sqlBuilt = new SqlBuilt(); @@ -105,7 +105,7 @@ private static void write(String fileName, StringBuilder sb) { }catch (Exception e){ e.printStackTrace(); }finally { - resultMapCriteriaList.clear(); + xKvList.clear(); } } } diff --git a/sqli-builder/src/main/java/io/xream/sqli/util/ParserUtil.java b/sqli-builder/src/main/java/io/xream/sqli/util/ParserUtil.java index 6e5601ed..f98a0368 100644 --- a/sqli-builder/src/main/java/io/xream/sqli/util/ParserUtil.java +++ b/sqli-builder/src/main/java/io/xream/sqli/util/ParserUtil.java @@ -374,7 +374,7 @@ public static String filterSQLKeyword(String mapper) { public static String getClzName(String alia, Map aliaMap) { if (aliaMap == null) - throw new ParsingException("CriteriaBuilder.builder(Class) not support the key contains '.'"); + throw new ParsingException("QB.of(Class) not support the key contains '.'"); String a = aliaMap.get(alia); if (SqliStringUtil.isNotNull(a)) return a; diff --git a/sqli-core/README.md b/sqli-core/README.md index f6be1358..d58252fd 100644 --- a/sqli-core/README.md +++ b/sqli-core/README.md @@ -17,7 +17,7 @@ ### API BaseRepository - ResultMapRepository + RepositoryX TemporaryRepository CacheFilter diff --git a/sqli-core/src/main/java/io/xream/sqli/api/RepositoryX.java b/sqli-core/src/main/java/io/xream/sqli/api/RepositoryX.java index a5e071bc..add3e215 100644 --- a/sqli-core/src/main/java/io/xream/sqli/api/RepositoryX.java +++ b/sqli-core/src/main/java/io/xream/sqli/api/RepositoryX.java @@ -26,7 +26,7 @@ import java.util.Map; /** - * ResultMap API + * X API * @author Sim */ public interface RepositoryX { diff --git a/sqli-core/src/main/java/io/xream/sqli/api/TemporaryRepository.java b/sqli-core/src/main/java/io/xream/sqli/api/TemporaryRepository.java index 53ba56be..48448648 100644 --- a/sqli-core/src/main/java/io/xream/sqli/api/TemporaryRepository.java +++ b/sqli-core/src/main/java/io/xream/sqli/api/TemporaryRepository.java @@ -26,7 +26,7 @@ /** * How to update with TemporaryRepository? * suggest: - * .findToHandle(ResultMapCriteria, map -> { + * .findToHandle(Q.X, map -> { * * refresh( * qr.build().... diff --git a/sqli-core/src/main/java/io/xream/sqli/cache/internal/DefaultL2CacheResolver.java b/sqli-core/src/main/java/io/xream/sqli/cache/internal/DefaultL2CacheResolver.java index 785e7172..17754411 100644 --- a/sqli-core/src/main/java/io/xream/sqli/cache/internal/DefaultL2CacheResolver.java +++ b/sqli-core/src/main/java/io/xream/sqli/cache/internal/DefaultL2CacheResolver.java @@ -463,11 +463,11 @@ public List listUnderProtection(Class clz, Object conditionObj, QueryF @Override public List listUnderProtection(Q q, QueryForCache queryForCache, QueryFromDb> QueryFromDb) { - final String criteriaKey = buildCacheKey(q); + final String qKey = buildCacheKey(q); final Class clz = q.getClzz(); List keyList = null; try { - keyList = getResultKeyList(clz, criteriaKey); + keyList = getResultKeyList(clz, qKey); }catch (NotQueryUnderProtectionException upe) { } @@ -489,7 +489,7 @@ public List listUnderProtection(Q q, QueryForCache queryForCache, QueryFr keyList.add(key); } - setResultKeyList(clz, criteriaKey, keyList); + setResultKeyList(clz, qKey, keyList); close(); return list; } @@ -568,8 +568,8 @@ public T getOneUnderProtection(Class clz, Object conditionObj, QueryFromD public Page findUnderProtection(Q q, QueryForCache queryForCache, QueryFromDb> findQueryFromDb, QueryFromDb> listQueryFromDb){ Class clz = q.getClzz(); Parsed parsed = Parser.get(clz); - final String criteriaKey = buildCacheKey(q); - Page p = getResultKeyListPaginated(clz, criteriaKey);// FIXME + final String qKey = buildCacheKey(q); + Page p = getResultKeyListPaginated(clz, qKey);// FIXME if (p == null) { @@ -620,7 +620,7 @@ public Page findUnderProtection(Q q, QueryForCache queryForCache, QueryFr p.setKeyList(keyList); p.reSetList(null); - setResultKeyListPaginated(clz, criteriaKey, p); + setResultKeyListPaginated(clz, qKey, p); p.setKeyList(null); p.reSetList(list); diff --git a/sqli-core/src/main/java/io/xream/sqli/converter/X2Bean.java b/sqli-core/src/main/java/io/xream/sqli/converter/X2Bean.java index 064e84ec..15954879 100644 --- a/sqli-core/src/main/java/io/xream/sqli/converter/X2Bean.java +++ b/sqli-core/src/main/java/io/xream/sqli/converter/X2Bean.java @@ -33,7 +33,7 @@ public class X2Bean { private X2Bean(){} /** - * not support resultMap by builder.resultWithDottedKey(); + * not support q by builder.resultWithDottedKey(); */ public static T copy(Class clz, Map map) { diff --git a/sqli-core/src/main/java/io/xream/sqli/core/ResultMapFinder.java b/sqli-core/src/main/java/io/xream/sqli/core/XFinder.java similarity index 85% rename from sqli-core/src/main/java/io/xream/sqli/core/ResultMapFinder.java rename to sqli-core/src/main/java/io/xream/sqli/core/XFinder.java index 5bab676f..059b3f53 100644 --- a/sqli-core/src/main/java/io/xream/sqli/core/ResultMapFinder.java +++ b/sqli-core/src/main/java/io/xream/sqli/core/XFinder.java @@ -31,13 +31,13 @@ /** * @author Sim */ -public interface ResultMapFinder { +public interface XFinder { - List> queryForResultMapList(String sql, Collection list, XHelpful xHelpful, Class orClzz, Dialect dialect); + List> queryForXList(String sql, Collection list, XHelpful xHelpful, Class orClzz, Dialect dialect); void queryForMapToHandle(String sql, Collection valueList, Dialect dialect, XHelpful xHelpful, Parsed orParsed, RowHandler handler); - default List> toResultMapList(boolean isResultWithDottedKey, DataMapQuery dataMapQuery) { + default List> toXList(boolean isResultWithDottedKey, DataMapQuery dataMapQuery) { List> objectPropertyMapList = dataMapQuery.query(DataMapQuery.FIXED_ROW_MAPPER); if (isResultWithDottedKey) @@ -49,7 +49,7 @@ default List> toResultMapList(boolean isResultWithDottedKey, return objectPropertyMapList; } - default Map toResultMap(XHelpful xHelpful, Dialect dialect, Map dataMap) { + default Map toXq(XHelpful xHelpful, Dialect dialect, Map dataMap) { Map map = DataMapQuery.FIXED_ROW_MAPPER.mapRow(dataMap,null, xHelpful,dialect); if (xHelpful.isResultWithDottedKey()) return map; diff --git a/sqli-core/src/main/java/io/xream/sqli/spi/JdbcHelper.java b/sqli-core/src/main/java/io/xream/sqli/spi/JdbcHelper.java index e9efde97..f33ea1e4 100644 --- a/sqli-core/src/main/java/io/xream/sqli/spi/JdbcHelper.java +++ b/sqli-core/src/main/java/io/xream/sqli/spi/JdbcHelper.java @@ -19,7 +19,7 @@ package io.xream.sqli.spi; import io.xream.sqli.core.BaseFinder; -import io.xream.sqli.core.ResultMapFinder; +import io.xream.sqli.core.XFinder; import io.xream.sqli.dialect.Dialect; import java.util.Collection; @@ -28,7 +28,7 @@ /** * @author Sim */ -public interface JdbcHelper extends BaseFinder, ResultMapFinder { +public interface JdbcHelper extends BaseFinder, XFinder { boolean createBatch(Class clzz, String sql, BatchObjectValues batchObjectValues, int batchSize, Dialect dialect); diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/core/CacheableRepository.java b/sqli-repo/src/main/java/io/xream/sqli/repository/core/CacheableRepository.java index 10afc435..cbbd09c1 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/core/CacheableRepository.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/core/CacheableRepository.java @@ -322,31 +322,31 @@ public T getOne(T condition) { } @Override - public Page> find(Q.X criteria) { - if (criteria.isAbort()) { + public Page> find(Q.X xq) { + if (xq.isAbort()) { Page page = new Page<>(); - page.setClzz(criteria.getClzz()); - page.setRows(criteria.getRows()); - page.setPage(criteria.getPage()); + page.setClzz(xq.getClzz()); + page.setRows(xq.getRows()); + page.setPage(xq.getPage()); return page; } - return dao.find(criteria); + return dao.find(xq); } @Override - public List> list(Q.X criteria) { + public List> list(Q.X xq) { - if (criteria.isAbort()) + if (xq.isAbort()) return new ArrayList<>(); - return dao.list(criteria); + return dao.list(xq); } @Override - public List listPlainValue(Class clzz, Q.X criteria){ - if (criteria.isAbort()) + public List listPlainValue(Class clzz, Q.X xq){ + if (xq.isAbort()) return new ArrayList<>(); - return dao.listPlainValue(clzz,criteria); + return dao.listPlainValue(clzz,xq); } @@ -363,10 +363,10 @@ public void findToHandle(Q q, RowHandler handler) { } @Override - public void findToHandle(Q.X criteria, RowHandler> handler) { - if (criteria.isAbort()) + public void findToHandle(Q.X xq, RowHandler> handler) { + if (xq.isAbort()) return; - this.dao.findToHandle(criteria,handler); + this.dao.findToHandle(xq,handler); } @Override diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/Dao.java b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/Dao.java index 55c2937a..b3656dbb 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/Dao.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/Dao.java @@ -56,11 +56,11 @@ List> list(String sql, List in(In in); - Page> find(Q.X resultMapped); + Page> find(Q.X xq); - List> list(Q.X resultMapped); + List> list(Q.X xq); - List listPlainValue(Class clzz, Q.X resultMapped); + List listPlainValue(Class clzz, Q.X xq); Page find(Q q); @@ -73,7 +73,7 @@ List> list(String sql, boolean refresh(T t); void findToHandle(Q q, RowHandler handler); - void findToHandle(Q.X resultMapCriteria, RowHandler> handler); + void findToHandle(Q.X xq, RowHandler> handler); boolean exists(Q q); } \ No newline at end of file diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java index 0b41a5e6..8333b38d 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java @@ -49,7 +49,7 @@ public final class DaoImpl implements Dao, SqlTemplate { private Logger logger = LoggerFactory.getLogger(Dao.class); private static Dao instance; - private Q2Sql condToSql; + private Q2Sql q2Sql; private Dialect dialect; private JdbcHelper jdbcHelper; @@ -72,8 +72,8 @@ public Dialect getDialect(){ return this.dialect; } - public void setCriteriaToSql(Q2Sql condToSql) { - this.condToSql = condToSql; + public void set2Sql(Q2Sql condToSql) { + this.q2Sql = condToSql; } public void setJdbcHelper(JdbcHelper jdbcHelper) { @@ -173,7 +173,7 @@ public boolean createOrReplace(Object obj) { @Override public List> list(String sql, List conditionList) { - return this.jdbcHelper.queryForResultMapList(sql, conditionList,null, null,this.dialect); + return this.jdbcHelper.queryForXList(sql, conditionList,null, null,this.dialect); } @@ -215,7 +215,7 @@ public List list(Q q) { Class clz = q.getClzz(); List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList, q, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, q, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); SqliLoggerProxy.debug(clz, sql); @@ -229,7 +229,7 @@ public Page find(Q q) { Class clz = q.getClzz(); List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList, q, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, q, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); SqliLoggerProxy.debug(clz, sql); @@ -276,7 +276,7 @@ public boolean refreshByCondition(Qr qr) { Class clz = qr.getClz(); Parsed parsed = Parser.get(clz); - String sql = sqlBuilder.buildRefreshByCondition(parsed, qr, this.condToSql,this.dialect); + String sql = sqlBuilder.buildRefreshByCondition(parsed, qr, this.q2Sql,this.dialect); List valueList = qr.getValueList(); SqliLoggerProxy.debug(clz, valueList); @@ -325,43 +325,43 @@ public List in(In in) { } @Override - public Page> find(Q.X resultMapped) { + public Page> find(Q.X xq) { List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList,resultMapped, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, xq, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); - Class clz = resultMapped.getClzz(); + Class clz = xq.getClzz(); - SqliLoggerProxy.debug(resultMapped.getRepositoryClzz(), sql); + SqliLoggerProxy.debug(xq.getRepositoryClzz(), sql); - List> list = this.jdbcHelper.queryForResultMapList(sql, valueList,resultMapped, clz, this.dialect); - ResultSortUtil.sort(list,resultMapped); - Page> pagination = PageBuilderHelper.build(resultMapped, list, () -> getCount(resultMapped.getRepositoryClzz(), sqlBuilt.getCountSql(), valueList)); + List> list = this.jdbcHelper.queryForXList(sql, valueList, xq, clz, this.dialect); + ResultSortUtil.sort(list, xq); + Page> pagination = PageBuilderHelper.build(xq, list, () -> getCount(xq.getRepositoryClzz(), sqlBuilt.getCountSql(), valueList)); return pagination; } @Override - public List> list(Q.X resultMapped) { + public List> list(Q.X xq) { List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList,resultMapped, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, xq, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); - SqliLoggerProxy.debug(resultMapped.getRepositoryClzz(), sql); + SqliLoggerProxy.debug(xq.getRepositoryClzz(), sql); - List> list = this.jdbcHelper.queryForResultMapList(sql, valueList,resultMapped, resultMapped.getClzz(), this.dialect); - ResultSortUtil.sort(list,resultMapped); + List> list = this.jdbcHelper.queryForXList(sql, valueList, xq, xq.getClzz(), this.dialect); + ResultSortUtil.sort(list, xq); return list; } @Override - public List listPlainValue(Class clzz, Q.X resultMapped){ + public List listPlainValue(Class clzz, Q.X xq){ List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList,resultMapped, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, xq, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); - SqliLoggerProxy.debug(resultMapped.getRepositoryClzz(), sql); + SqliLoggerProxy.debug(xq.getRepositoryClzz(), sql); List list = this.jdbcHelper.queryForPlainValueList(clzz,sql,valueList,this.dialect); return list; @@ -394,22 +394,22 @@ public T getOne(T conditionObj) { } @Override - public void findToHandle(Q.X resultMapped, RowHandler> handler) { + public void findToHandle(Q.X xq, RowHandler> handler) { List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList,resultMapped, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, xq, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); - SqliLoggerProxy.debug(resultMapped.getRepositoryClzz(), sql); + SqliLoggerProxy.debug(xq.getRepositoryClzz(), sql); - this.jdbcHelper.queryForMapToHandle(sql, valueList, dialect, resultMapped, null, handler); + this.jdbcHelper.queryForMapToHandle(sql, valueList, dialect, xq, null, handler); } @Override public void findToHandle(Q q, RowHandler handler) { List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList, q, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, q, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); Class clz = q.getClzz(); @@ -423,7 +423,7 @@ public boolean exists(Q q) { Class clz = q.getClzz(); List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList, q, condToSql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList, q, q2Sql, dialect); String sql = sqlBuilt.getSql().toString(); sql = sql.replace("*","1"); sql += " LIMIT 1"; diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/SqlBuilder.java b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/SqlBuilder.java index 459557e1..c1a2aeb1 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/SqlBuilder.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/SqlBuilder.java @@ -77,8 +77,8 @@ protected String buildQueryByObject(Parsed parsed, String sql, Map valueList, Q q, Q2Sql criteriaParser, Dialect dialect) { + protected SqlBuilt buildQueryByQ(List valueList, Q q, Q2Sql qParser, Dialect dialect) { final SqlBuilt sqlBuilt = new SqlBuilt(); final List subList = new ArrayList<>(); - criteriaParser.toSql(false, q, sqlBuilt, new SqlBuildingAttached() { + qParser.toSql(false, q, sqlBuilt, new SqlBuildingAttached() { @Override public List getValueList() { return valueList; diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDao.java b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDao.java index a6afa709..a505a410 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDao.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDao.java @@ -24,6 +24,6 @@ * @author Sim */ public interface TemporaryDao { - boolean findToCreate(Class clzz, Q.X resultMapCriteria); + boolean findToCreate(Class clzz, Q.X xq); boolean execute(String sql); } diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDaoImpl.java b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDaoImpl.java index 89f3fce1..283abddf 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDaoImpl.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDaoImpl.java @@ -74,10 +74,10 @@ public void setJdbcHelper(JdbcHelper jdbcHelper) { @Override - public boolean findToCreate(Class clzz, Q.X resultMapCriteria) { + public boolean findToCreate(Class clzz, Q.X xq) { List valueList = new ArrayList<>(); - SqlBuilt sqlBuilt = sqlBuilder.buildQueryByCriteria(valueList,resultMapCriteria, q2Sql, dialect); + SqlBuilt sqlBuilt = sqlBuilder.buildQueryByQ(valueList,xq, q2Sql, dialect); StringBuilder fromSqlSb = sqlBuilt.getSql(); Parsed parsed = Parser.get(clzz); diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultRepositoryX.java b/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultRepositoryX.java index 0b7b8f1a..e7024149 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultRepositoryX.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultRepositoryX.java @@ -26,7 +26,7 @@ import io.xream.sqli.builder.Qr; import io.xream.sqli.builder.RemoveRefreshCreate; import io.xream.sqli.core.*; -import io.xream.sqli.exception.CriteriaSyntaxException; +import io.xream.sqli.exception.QSyntaxException; import io.xream.sqli.exception.PersistenceException; import io.xream.sqli.page.Page; import io.xream.sqli.parser.Parser; @@ -38,7 +38,7 @@ import java.util.Map; /** - * Implement of BaseRepository, ResultMapRepository + * Implement of BaseRepository, RepositoryX * * @param * @author Sim @@ -263,7 +263,7 @@ public List in(String property, List inList) { @Override public Page find(Q q) { - assertCriteriaClzz(q); + assertQClzz(q); this.setDefaultClzz(q); Page page = repository.find(q); page.setClzz(this.clzz); @@ -273,7 +273,7 @@ public Page find(Q q) { @Override public List list(Q q) { - assertCriteriaClzz(q); + assertQClzz(q); this.setDefaultClzz(q); return repository.list(q); @@ -281,58 +281,58 @@ public List list(Q q) { @Override public void findToHandle(Q q, RowHandler handler) { - assertCriteriaClzz(q); + assertQClzz(q); this.setDefaultClzz(q); this.repository.findToHandle(q,handler); } @Override public boolean exists(Q q) { - assertCriteriaClzz(q); + assertQClzz(q); this.setDefaultClzz(q); return this.repository.exists(q); } @Override - public Page> findX(Q.X resultMapCriteria) { - this.setDefaultClzz(resultMapCriteria); - return repository.find(resultMapCriteria); + public Page> findX(Q.X xq) { + this.setDefaultClzz(xq); + return repository.find(xq); } @Override - public List> listX(Q.X resultMapCriteria) { - this.setDefaultClzz(resultMapCriteria); - return repository.list(resultMapCriteria); + public List> listX(Q.X xq) { + this.setDefaultClzz(xq); + return repository.list(xq); } @Override - public List listPlainValue(Class clzz, Q.X resultMapCriteria){ - this.setDefaultClzz(resultMapCriteria); - return repository.listPlainValue(clzz,resultMapCriteria); + public List listPlainValue(Class clzz, Q.X xq){ + this.setDefaultClzz(xq); + return repository.listPlainValue(clzz,xq); } @Override - public void findToHandleX(Q.X resultMapCriteria, RowHandler> handler) { - this.setDefaultClzz(resultMapCriteria); - this.repository.findToHandle(resultMapCriteria,handler); + public void findToHandleX(Q.X xq, RowHandler> handler) { + this.setDefaultClzz(xq); + this.repository.findToHandle(xq,handler); } - private void setDefaultClzz(Q.X resultMapCriteria) { + private void setDefaultClzz(Q.X xq) { if (this.clzz != Void.class) { - resultMapCriteria.setParsed(Parser.get(this.clzz)); + xq.setParsed(Parser.get(this.clzz)); } - resultMapCriteria.setClzz(this.clzz); - resultMapCriteria.setRepositoryClzz(this.repositoryClzz); + xq.setClzz(this.clzz); + xq.setRepositoryClzz(this.repositoryClzz); } private void setDefaultClzz(Q q) { q.setClzz(this.clzz); q.setParsed(Parser.get(this.clzz)); } - private void assertCriteriaClzz(Q q) { + private void assertQClzz(Q q) { if (this.clzz != q.getClzz()) - throw new CriteriaSyntaxException("T: " + this.clzz +", Criteria.clzz:" + q.getClzz()); + throw new QSyntaxException("T: " + this.clzz +", Q.clzz:" + q.getClzz()); } //can not delete this method: protected void setRepositoryClzz(Class clzz) protected void setRepositoryClzz(Class clzz){ diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultTemporaryRepository.java b/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultTemporaryRepository.java index 26b132c9..b3f27cb8 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultTemporaryRepository.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultTemporaryRepository.java @@ -103,15 +103,15 @@ public boolean createBatch(List objList) { } @Override - public boolean findToCreate(Class clzz, Q.X resultMapCriteria) { + public boolean findToCreate(Class clzz, Q.X xq) { - return doProxy("findToCreate(Class, ResultMapCriteria)", () -> { + return doProxy("findToCreate(Class, Q.X)", () -> { Parsed parsed = io.xream.sqli.parser.Parser.get(clzz.getSimpleName()); if (parsed == null) { io.xream.sqli.parser.Parser.parse(clzz); } - return temporaryDao.findToCreate(clzz, resultMapCriteria); + return temporaryDao.findToCreate(clzz, xq); }); } diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/internal/SafeRefreshBiz.java b/sqli-repo/src/main/java/io/xream/sqli/repository/internal/SafeRefreshBiz.java index a94d00dd..2736c36e 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/internal/SafeRefreshBiz.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/internal/SafeRefreshBiz.java @@ -21,7 +21,7 @@ import io.xream.sqli.builder.Bb; import io.xream.sqli.builder.Op; import io.xream.sqli.builder.Qr; -import io.xream.sqli.exception.CriteriaSyntaxException; +import io.xream.sqli.exception.QSyntaxException; import io.xream.sqli.parser.Parsed; import io.xream.sqli.parser.Parser; @@ -39,7 +39,7 @@ default void tryToRefreshSafe(Class clzz, Qr qr) { Parsed parsed = Parser.get(clzz); Field keyField = parsed.getKeyField(); if (Objects.isNull(keyField)) - throw new CriteriaSyntaxException("No PrimaryKey, UnSafe Refresh, try to invoke DefaultRepository.refreshUnSafe(qr rq)"); + throw new QSyntaxException("No PrimaryKey, UnSafe Refresh, try to invoke DefaultRepository.refreshUnSafe(qr rq)"); boolean unSafe = true;//Safe @@ -69,6 +69,6 @@ default void tryToRefreshSafe(Class clzz, Qr qr) { } if (unSafe) - throw new CriteriaSyntaxException("UnSafe Refresh, try to invoke DefaultRepository.refreshUnSafe(qr rq)"); + throw new QSyntaxException("UnSafe Refresh, try to invoke DefaultRepository.refreshUnSafe(qr rq)"); } } diff --git a/sqli-repo/src/main/java/io/xream/sqli/starter/SqliStarter.java b/sqli-repo/src/main/java/io/xream/sqli/starter/SqliStarter.java index d56749a8..2353076e 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/starter/SqliStarter.java +++ b/sqli-repo/src/main/java/io/xream/sqli/starter/SqliStarter.java @@ -72,7 +72,7 @@ public Repository repository(Q2Sql condToSql, JdbcHelper jdbcHelper, CacheableRepository repository = CacheableRepository.newInstance(); repository.setDao(dao); - ((DaoImpl)dao).setCriteriaToSql(condToSql); + ((DaoImpl)dao).set2Sql(condToSql); ((DaoImpl)dao).setJdbcHelper(jdbcHelper); ((DaoImpl)dao).setDialect(dialect);