Skip to content

Commit a25bbc5

Browse files
committed
新增 IS_RETURN_STACK_TRACE 配置是否返回 trace:stack 字段,优化代码
1 parent 38dfb93 commit a25bbc5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractParser.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public abstract class AbstractParser<T, M extends Map<String, Object>, L extends
6262
*/
6363
public static boolean IS_PRINT_REQUEST_ENDTIME_LOG = false;
6464

65+
/**
66+
* 可以通过切换该变量来控制返回 trace:stack 字段,如果是 gson 则不设置为 false,避免序列化报错。
67+
* 与 {@link Log#DEBUG} 任何一个为 true 返回 trace:stack 字段。
68+
*/
69+
public static boolean IS_RETURN_STACK_TRACE = true;
70+
6571

6672
/**
6773
* 分页页码是否从 1 开始,默认为从 0 开始
@@ -622,7 +628,10 @@ public M parseResponse(M request) {
622628
// }
623629
Throwable t = error instanceof CommonException && error.getCause() != null ? error.getCause() : error;
624630
res.put("trace:throw", t.getClass().getName());
625-
res.put("trace:stack", t.getStackTrace());
631+
632+
if (IS_RETURN_STACK_TRACE) {
633+
res.put("trace:stack", t.getStackTrace());
634+
}
626635
}
627636
}
628637

APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,14 +1213,15 @@ public PreparedStatement getStatement(@NotNull SQLConfig<T, M, L> config, String
12131213
sql = config.gainSQL(config.isPrepared());
12141214
}
12151215

1216+
Connection conn = getConnection(config);
12161217
PreparedStatement statement; //创建Statement对象
12171218
if (config.getMethod() == RequestMethod.POST && config.getId() == null) { //自增id
12181219
if (config.isOracle()) {
12191220
// 解决 oracle 使用自增主键 插入获取不到id问题
12201221
String[] generatedColumns = {config.getIdKey()};
1221-
statement = getConnection(config).prepareStatement(sql, generatedColumns);
1222+
statement = conn.prepareStatement(sql, generatedColumns);
12221223
} else {
1223-
statement = getConnection(config).prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
1224+
statement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
12241225
}
12251226
}
12261227
else if (RequestMethod.isGetMethod(config.getMethod(), true)) {
@@ -1234,13 +1235,13 @@ else if (RequestMethod.isGetMethod(config.getMethod(), true)) {
12341235
if (config.isMySQL() || config.isTiDB() || config.isMariaDB() || config.isOracle() || config.isSQLServer() || config.isDb2()
12351236
|| config.isPostgreSQL() || config.isCockroachDB() || config.isOpenGauss() || config.isTimescaleDB() || config.isQuestDB()
12361237
) {
1237-
statement = getConnection(config).prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
1238+
statement = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
12381239
} else {
1239-
statement = getConnection(config).prepareStatement(sql);
1240+
statement = conn.prepareStatement(sql);
12401241
}
12411242
}
12421243
else {
1243-
statement = getConnection(config).prepareStatement(sql);
1244+
statement = conn.prepareStatement(sql);
12441245
}
12451246

12461247
List<Object> valueList = config.isPrepared() ? config.getPreparedValueList() : null;

0 commit comments

Comments
 (0)