Skip to content

Commit b881541

Browse files
committed
优化代码,去除不必要的 synchonized
1 parent 46f86aa commit b881541

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ public static String replaceArrayChildPath(String parentPath, String valuePath)
17691769
* @param result 需要被关联的object
17701770
*/
17711771
@Override
1772-
public synchronized void putQueryResult(String path, Object result) {
1772+
public void putQueryResult(String path, Object result) {
17731773
Log.i(TAG, "\n putQueryResult valuePath = " + path + "; result = " + result + "\n <<<<<<<<<<<<<<<<<<<<<<<");
17741774
// if (queryResultMap.containsKey(valuePath)) {//只保存被关联的value
17751775
Log.d(TAG, "putQueryResult queryResultMap.containsKey(valuePath) >> queryResultMap.put(path, result);");

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,18 +2303,16 @@ public Object getWhere(String key, boolean exactMatch) {
23032303
if (key == null || where == null){
23042304
return null;
23052305
}
2306-
synchronized (where) {
2307-
if (where != null) {
2308-
int index;
2309-
for (Entry<String,Object> entry : where.entrySet()) {
2310-
String k = entry.getKey();
2311-
index = k.indexOf(key);
2312-
if (index >= 0 && StringUtil.isName(k.substring(index)) == false) {
2313-
return entry.getValue();
2314-
}
2315-
}
2306+
2307+
int index;
2308+
for (Entry<String,Object> entry : where.entrySet()) {
2309+
String k = entry.getKey();
2310+
index = k.indexOf(key);
2311+
if (index >= 0 && StringUtil.isName(k.substring(index, index + 1)) == false) {
2312+
return entry.getValue();
23162313
}
23172314
}
2315+
23182316
return null;
23192317
}
23202318
@Override

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,26 +1120,30 @@ public void close() {
11201120

11211121
@Override
11221122
public ResultSet executeQuery(@NotNull SQLConfig config) throws Exception {
1123-
PreparedStatement s = getStatement(config);
1124-
// 不准,getStatement 有时比 execute sql 更耗时 executedSQLStartTime = System.currentTimeMillis();
1125-
ResultSet rs = s.executeQuery(); //PreparedStatement 不用传 SQL
1126-
// executedSQLEndTime = System.currentTimeMillis();
1123+
PreparedStatement stt = getStatement(config);
1124+
// 不准,getStatement 有时比 execute sql 更耗时 executedSQLStartTime = System.currentTimeMillis();
1125+
ResultSet rs = stt.executeQuery(); //PreparedStatement 不用传 SQL
1126+
// executedSQLEndTime = System.currentTimeMillis();
1127+
// if (config.isExplain() && (config.isSQLServer() || config.isOracle())) {
1128+
// FIXME 返回的是 boolean 值 rs = stt.getMoreResults(Statement.CLOSE_CURRENT_RESULT);
1129+
// }
1130+
11271131
return rs;
11281132
}
11291133

11301134
@Override
11311135
public int executeUpdate(@NotNull SQLConfig config) throws Exception {
1132-
PreparedStatement s = getStatement(config);
1136+
PreparedStatement stt = getStatement(config);
11331137
// 不准,getStatement 有时比 execute sql 更耗时 executedSQLStartTime = System.currentTimeMillis();
1134-
int count = s.executeUpdate(); // PreparedStatement 不用传 SQL
1138+
int count = stt.executeUpdate(); // PreparedStatement 不用传 SQL
11351139
// executedSQLEndTime = System.currentTimeMillis();
11361140

11371141
if (count <= 0 && config.isHive()) {
11381142
count = 1;
11391143
}
11401144

11411145
if (config.getId() == null && config.getMethod() == RequestMethod.POST) { // 自增id
1142-
ResultSet rs = s.getGeneratedKeys();
1146+
ResultSet rs = stt.getGeneratedKeys();
11431147
if (rs != null && rs.next()) {
11441148
config.setId(rs.getLong(1)); //返回插入的主键id FIXME Oracle 拿不到
11451149
}

0 commit comments

Comments
 (0)