Skip to content

Commit b248b42

Browse files
committed
新增支持达梦数据库;优化调试信息及日志打印,解决异常栈不够精准
1 parent a3dffa8 commit b248b42

File tree

9 files changed

+357
-177
lines changed

9 files changed

+357
-177
lines changed

APIJSONORM/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.Tencent</groupId>
77
<artifactId>APIJSON</artifactId>
8-
<version>5.2.0</version>
8+
<version>5.3.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONORM</name>

APIJSONORM/src/main/java/apijson/Log.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,30 @@ public class Log {
1414

1515
public static boolean DEBUG = true;
1616

17-
public static final String VERSION = "5.2.0";
18-
public static final String KEY_SYSTEM_INFO_DIVIDER = "---|-----APIJSON SYSTEM INFO-----|---";
17+
public static final String VERSION = "5.3.0";
18+
public static final String KEY_SYSTEM_INFO_DIVIDER = "\n---|-----APIJSON SYSTEM INFO-----|---\n";
1919

20-
//默认的时间格式
21-
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
20+
public static final String OS_NAME;
21+
public static final String OS_VERSION;
22+
public static final String OS_ARCH;
23+
public static final String JAVA_VERSION;
24+
static {
25+
OS_NAME = System.getProperty("os.name");
26+
OS_VERSION = System.getProperty("os.version");
27+
OS_ARCH = System.getProperty("os.arch");
28+
JAVA_VERSION = System.getProperty("java.version");
29+
}
30+
31+
32+
//默认的时间格式
33+
public static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
2234

2335
/**
2436
* modify date format
2537
* @param dateFormatString
2638
*/
2739
public static void setDateFormat(String dateFormatString) {
28-
dateFormat = new SimpleDateFormat(dateFormatString);
40+
DATE_FORMAT = new SimpleDateFormat(dateFormatString);
2941
}
3042

3143
/**
@@ -36,10 +48,10 @@ public static void setDateFormat(String dateFormatString) {
3648
*/
3749
public static void logInfo(String TAG, String msg, String level){
3850
if(level.equals("DEBUG") || level .equals("ERROR") ||level.equals("WARN")){
39-
System.err.println(dateFormat.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg);
51+
System.err.println(DATE_FORMAT.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg);
4052
}
4153
else if(level.equals("VERBOSE") || level .equals("INFO") ){
42-
System.out.println(dateFormat.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg);
54+
System.out.println(DATE_FORMAT.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg);
4355
}
4456
}
4557

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

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import apijson.StringUtil;
1313
import apijson.orm.AbstractFunctionParser.FunctionBean;
1414
import apijson.orm.exception.ConflictException;
15+
import apijson.orm.exception.CommonException;
1516
import apijson.orm.exception.NotExistException;
1617
import com.alibaba.fastjson.JSON;
1718
import com.alibaba.fastjson.JSONArray;
1819
import com.alibaba.fastjson.JSONObject;
1920

2021
import javax.activation.UnsupportedDataTypeException;
2122
import java.rmi.ServerException;
23+
import java.sql.SQLException;
2224
import java.util.ArrayList;
2325
import java.util.Arrays;
2426
import java.util.LinkedHashMap;
@@ -282,46 +284,7 @@ else if (method == PUT && value instanceof JSONArray && (whereList == null || wh
282284
}
283285
} catch (Exception e) {
284286
if (tri == false) {
285-
if (Log.DEBUG && sqlConfig != null && e.getMessage().contains(Log.KEY_SYSTEM_INFO_DIVIDER) == false) {
286-
try {
287-
String db = sqlConfig.getDatabase();
288-
if (db == null) {
289-
if (sqlConfig.isMySQL()) {
290-
db = SQLConfig.DATABASE_MYSQL;
291-
}
292-
else if (sqlConfig.isPostgreSQL()) {
293-
db = SQLConfig.DATABASE_POSTGRESQL;
294-
}
295-
else if (sqlConfig.isSQLServer()) {
296-
db = SQLConfig.DATABASE_SQLSERVER;
297-
}
298-
else if (sqlConfig.isOracle()) {
299-
db = SQLConfig.DATABASE_ORACLE;
300-
}
301-
else if (sqlConfig.isDb2()) {
302-
db = SQLConfig.DATABASE_DB2;
303-
}
304-
else if (sqlConfig.isClickHouse()) {
305-
db = SQLConfig.DATABASE_CLICKHOUSE;
306-
}
307-
else {
308-
db = AbstractSQLConfig.DEFAULT_DATABASE;
309-
}
310-
}
311-
312-
Class<? extends Exception> clazz = e.getClass();
313-
e = clazz.getConstructor(String.class).newInstance(
314-
e.getMessage()
315-
+ " " + Log.KEY_SYSTEM_INFO_DIVIDER + " \n **环境信息** "
316-
+ " \n 系统: " + System.getProperty("os.name") + " " + System.getProperty("os.version")
317-
+ " \n 数据库: " + db + " " + sqlConfig.getDBVersion()
318-
+ " \n JDK: " + System.getProperty("java.version") + " " + System.getProperty("os.arch")
319-
+ " \n APIJSON: " + Log.VERSION
320-
);
321-
} catch (Throwable e2) {}
322-
}
323-
324-
throw e; // 不忽略错误,抛异常
287+
throw CommonException.wrap(e, sqlConfig); // 不忽略错误,抛异常
325288
}
326289
invalidate(); // 忽略错误,还原request
327290
}
@@ -515,9 +478,9 @@ else if (isTable && key.startsWith("@") && JSONRequest.TABLE_KEY_LIST.contains(k
515478

516479

517480
/**
481+
* @param index
518482
* @param key
519483
* @param value
520-
* @param isFirst
521484
* @return
522485
* @throws Exception
523486
*/
@@ -746,9 +709,6 @@ public AbstractObjectParser setSQLConfig(int count, int page, int position) thro
746709

747710
protected SQLConfig sqlConfig = null;//array item复用
748711
/**SQL查询,for array item
749-
* @param count
750-
* @param page
751-
* @param position
752712
* @return this
753713
* @throws Exception
754714
*/

0 commit comments

Comments
 (0)