add transaction log of parse sql and get from cache
@@ -20,7 +20,8 @@ import java.util.regex.Pattern;
public class DefaultTableParser implements TableParser {
private static ILogger logger = DalElementFactory.DEFAULT.getILogger();
private static final String TABLEPARSE_ERROR = "TABLEPARSE::ERROR";
- private static final String TABLE_PARSER_CACHE_ADD = "tableParser::CacheAdd";
+ private static final String TABLEPARSE_TOTAL_COST = "TABLEPARSE::totalCost:";
+ private static final String TABLEPARSE_ACTUAL_COST = "TABLEPARSE::actualCost:";
private static final String CACHE_DEFAULT_SIZE = "1000";
private static final float LOAD_FACTOR = 0.8f;
private static final int KEY_OF_CACHE_MAX_BYTES = 2000;
@@ -54,6 +55,7 @@ public class DefaultTableParser implements TableParser {
@Override
public Set<String> getTablesFromSqls(String... sqls) {
+ long startTime = System.currentTimeMillis();
Set<String> tableSet = new HashSet<>();
if (sqls == null || sqls.length == 0)
return tableSet;
@@ -75,6 +77,7 @@ public class DefaultTableParser implements TableParser {
tableSet.addAll(extractTablesFromSql(sqlString));
}
}
+ logger.logTransaction(DalLogTypes.DAL, TABLEPARSE_TOTAL_COST, "size:" + sqlToTables.size(), startTime);
return tableSet;
}
@@ -119,14 +122,14 @@ public class DefaultTableParser implements TableParser {
protected List<String> getTablesFromCache(String sql) throws JSQLParserException {
String setKeySql = ignoreMsgId(sql);
if (getTableListErrorSQLs.contains(setKeySql)) {
- return finder.getTableList(CCJSqlParserUtil.parse(setKeySql));
+ return parseSql(setKeySql);
}
List<String> tables = null;
String cacheKeySql = ignoreWhereAndValues(setKeySql);
if (KEY_OF_CACHE_MAX_BYTES < cacheKeySql.getBytes().length) {
addSQLToErrorSet(setKeySql);
- return finder.getTableList(CCJSqlParserUtil.parse(setKeySql));
+ return parseSql(setKeySql);
}
synchronized (sqlToTables) {
@@ -134,13 +137,12 @@ public class DefaultTableParser implements TableParser {
}
if (tables == null) {
try {
- tables = finder.getTableList(CCJSqlParserUtil.parse(cacheKeySql));
+ tables = parseSql(cacheKeySql);
} catch (Throwable t) {
addSQLToErrorSet(setKeySql);
- return finder.getTableList(CCJSqlParserUtil.parse(setKeySql));
+ return parseSql(setKeySql);
}
synchronized (sqlToTables) {
- logger.logTransaction(DalLogTypes.DAL, TABLE_PARSER_CACHE_ADD, "size: " + sqlToTables.size(), System.currentTimeMillis());
sqlToTables.put(cacheKeySql, tables);
}
}
@@ -148,6 +150,13 @@ public class DefaultTableParser implements TableParser {
return tables == null ? new ArrayList<>() : tables;
}
+ protected List<String> parseSql(String sql) throws JSQLParserException {
+ long startTime = System.currentTimeMillis();
+ List<String> tables = finder.getTableList(CCJSqlParserUtil.parse(sql));
+ logger.logTransaction(DalLogTypes.DAL, TABLEPARSE_ACTUAL_COST, "size: " + sqlToTables.size(), startTime);
+ return tables;
+ }
+
protected void addSQLToErrorSet(String setKeySql) {
synchronized (getTableListErrorSQLs) {
getTableListErrorSQLs.add(setKeySql);
