From 8cf170c0bfb71052a09baad4e43029954352442a Mon Sep 17 00:00:00 2001 From: TommyLemon <1184482681@qq.com> Date: Wed, 7 Apr 2021 01:28:36 +0800 Subject: [PATCH] =?UTF-8?q?AbstractSQLExecutor=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9C=AA=E6=88=90=E5=8A=9F=E4=B9=9F?= =?UTF-8?q?=E6=9C=AA=E6=8A=9B=E5=BC=82=E5=B8=B8=E7=9A=84=20code=20?= =?UTF-8?q?=E5=92=8C=20msg=EF=BC=9BAbstractParser=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=8A=E5=93=8D=E5=BA=94=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0=EF=BC=9BAbstractSQLConfig=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20key$=20=E7=9A=84=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/apijson/orm/AbstractParser.java | 29 +++++++++---------- .../java/apijson/orm/AbstractSQLConfig.java | 7 +++-- .../java/apijson/orm/AbstractSQLExecutor.java | 5 ++-- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java b/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java index be8ef09e3..7f3a2f3c2 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java @@ -48,6 +48,11 @@ public abstract class AbstractParser implements Parser, ParserCreator, VerifierCreator, SQLCreator { protected static final String TAG = "AbstractParser"; + /** + * 打印大数据量日志的标识。线上环境比较敏感,可以通过切换该变量来控制异常栈抛出、错误日志打印。保守起见,该值默认为false。 + * 与 {@link Log#DEBUG} 任何一个为 true 都会打印关键的接口请求及响应信息。 + */ + public static boolean IS_PRINT_BIG_LOG = false; /** * method = null @@ -301,9 +306,6 @@ public JSONObject parseResponse(String request) { private int queryDepth; - // 打印异常日志的标识。线上环境比较敏感,可以通过切换该变量来控制异常栈抛出、错误日志打印。保守起见,该值默认为false。 - public static boolean isPrintErrorLog = false; - /**解析请求json并获取对应结果 * @param request * @return requestObject @@ -386,12 +388,11 @@ public JSONObject parseResponse(JSONObject request) { long endTime = System.currentTimeMillis(); long duration = endTime - startTime; - if (isPrintErrorLog) { //用 | 替代 /,避免 APIJSON ORM,APIAuto 等解析路径错误 + if (Log.DEBUG) { requestObject.put("sql:generate|cache|execute|maxExecute", getSQLExecutor().getGeneratedSQLCount() + "|" + getSQLExecutor().getCachedSQLCount() + "|" + getSQLExecutor().getExecutedSQLCount() + "|" + getMaxSQLCount()); requestObject.put("depth:count|max", queryDepth + "|" + getMaxQueryDepth()); requestObject.put("time:start|duration|end", startTime + "|" + duration + "|" + endTime); if (error != null) { - Log.d(TAG, String.format("onObjectParse error, error is %s", error.getMessage())); requestObject.put("throw", error.getClass().getName()); requestObject.put("trace", error.getStackTrace()); } @@ -399,17 +400,15 @@ public JSONObject parseResponse(JSONObject request) { onClose(); - //会不会导致原来的session = null? session = null; - - if (isPrintErrorLog) { - Log.d(TAG, "\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n " - + requestMethod + "/parseResponse request = \n" + requestString + "\n\n"); - - Log.d(TAG, "parseResponse return response = \n" + JSON.toJSONString(requestObject) - + "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \n\n\n"); + System.err.println("\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n " + + TAG + ".DEBUG: " + requestMethod + "/parseResponse request = \n" + requestString + "\n\n"); + + if (Log.DEBUG || IS_PRINT_BIG_LOG || error != null) { // 日志仅存服务器,所以不太敏感,而且这些日志虽然量大但非常重要,对排查 bug 很关键 + System.err.println(TAG + ".DEBUG: " + requestMethod + "/parseResponse return response = \n" + JSON.toJSONString(requestObject) + "\n\n"); } - Log.d(TAG, "parseResponse endTime = " + endTime + "; duration = " + duration - + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n\n"); + + System.err.println(TAG + ".DEBUG: " + requestMethod + "/parseResponse endTime = " + endTime + "; duration = " + duration + + "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \n\n\n"); return res; } diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index 6f61b9c19..968128011 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -2018,9 +2018,12 @@ public String getSearchString(String key, Object[] values, int type) throws Ille if (v instanceof String == false) { throw new IllegalArgumentException(key + "$:value 中 value 的类型只能为 String 或 String[]!"); } - if (((String) v).contains("%%")) { - throw new IllegalArgumentException(key + "$:value 中 value 值 " + v + " 中包含 %% !不允许有连续的 % !"); + if (((String) v).isEmpty()) { // 允许查空格 StringUtil.isEmpty((String) v, true) + throw new IllegalArgumentException(key + "$:value 中 value 值 " + v + "是空字符串,没有意义,不允许这样传!"); } + // if (((String) v).contains("%%")) { // 需要通过 %\%% 来模糊搜索 % + // throw new IllegalArgumentException(key + "$:value 中 value 值 " + v + " 中包含 %% !不允许有连续的 % !"); + // } condition += (i <= 0 ? "" : (Logic.isAnd(type) ? AND : OR)) + getLikeString(key, v); } diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java index 8966d0132..68bd8fe7e 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java @@ -27,7 +27,6 @@ import java.util.Map.Entry; import java.util.Set; -import apijson.orm.exception.NotExistException; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -211,11 +210,11 @@ public JSONObject execute(@NotNull SQLConfig config, boolean unknowType) throws int updateCount = executeUpdate(config); if (updateCount <= 0) { - throw new NotExistException("没权限访问或对象不存在!"); + throw new IllegalAccessException("没权限访问或对象不存在!"); // NotExistException 会被 catch 转为成功状态 } // updateCount>0时收集结果。例如更新操作成功时,返回count(affected rows)、id字段 - result = new JSONObject(true); + result = AbstractParser.newSuccessResult(); // TODO 对 APIAuto 及其它现有的前端/客户端影响比较大,暂时还是返回 code 和 msg,5.0 再移除 new JSONObject(true); //id,id{}至少一个会有,一定会返回,不用抛异常来阻止关联写操作时前面错误导致后面无条件执行! result.put(JSONResponse.KEY_COUNT, updateCount);//返回修改的记录数