Skip to content

Commit

Permalink
解决耗时判断错误;优化对 executeQuery 还是 executeUpdate 的判断,兼容 nGQL, openCypher 等图…
Browse files Browse the repository at this point in the history
…数据库语言
  • Loading branch information
TommyLemon committed Sep 7, 2022
1 parent 505f1c7 commit 00d1452
Showing 1 changed file with 18 additions and 8 deletions.
Expand Up @@ -1364,31 +1364,38 @@ public String execute(@RequestBody String request, HttpSession session) {
config.setPrepared(true);
config.setPreparedValueList(valueList);

String sqlPrefix = EXECUTE_STRICTLY ? sql.substring(0, 7).toUpperCase() : "";
boolean isWrite = sqlPrefix.startsWith("INSERT ") || sqlPrefix.startsWith("UPDATE ") || sqlPrefix.startsWith("DELETE ");

long executeStartTime = System.currentTimeMillis();

Statement statement = executor.getStatement(config, sql);
if (statement instanceof PreparedStatement) {
if (EXECUTE_STRICTLY) {
if (sql.startsWith("SELECT ")) {
((PreparedStatement) statement).executeQuery();
} else {
if (isWrite) {
((PreparedStatement) statement).executeUpdate();
} else {
((PreparedStatement) statement).executeQuery();
}
}
else {
((PreparedStatement) statement).execute();
}
} else {
if (EXECUTE_STRICTLY) {
if (sql.startsWith("SELECT ")) {
statement.executeQuery(sql);
} else {
if (isWrite) {
statement.executeUpdate(sql);
} else {
statement.executeQuery(sql);
}
}
else {
statement.execute(sql);
}
}

long executeDuration = System.currentTimeMillis() - executeStartTime;

ResultSet rs = statement.getResultSet();
ResultSetMetaData rsmd = rs.getMetaData();
int length = rsmd.getColumnCount();
Expand Down Expand Up @@ -1424,14 +1431,17 @@ public String execute(@RequestBody String request, HttpSession session) {
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;

long sqlDuration = cursorDuration + rsDuration;
long sqlDuration = executeDuration + cursorDuration + rsDuration;
long parseDuration = duration - sqlDuration;

result.put("time:start|duration|end|parse|sql", startTime + "|" + duration + "|" + endTime + "|" + parseDuration + "|" + sqlDuration);

return result.toJSONString();
} catch (Exception e) {
return DemoParser.newErrorResult(e).toJSONString();
JSONObject result = DemoParser.newErrorResult(e);
result.put("throw", e.getClass().getName());
result.put("trace:stack", e.getStackTrace());
return result.toJSONString();
}

}
Expand Down

0 comments on commit 00d1452

Please sign in to comment.