aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server
diff options
context:
space:
mode:
Diffstat (limited to 'mdbc-server')
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java30
1 files changed, 24 insertions, 6 deletions
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java b/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java
index 9455494..8e09065 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java
@@ -78,7 +78,14 @@ public class QueryProcessor {
}
public static Map<String, List<String>> parseSqlQuery(String query) throws SqlParseException {
+ logger.info(EELFLoggerDelegate.applicationLogger, "Parsing query: "+query);
Map<String, List<String>> tableOpsMap = new HashMap<>();
+ //for Create no need to check locks.
+ if(query.toUpperCase().startsWith("CREATE")) {
+ logger.error(EELFLoggerDelegate.errorLogger, "CREATE TABLE DDL not currently supported currently.");
+ return tableOpsMap;
+ }
+
/*SqlParser parser = SqlParser.create(query);
SqlNode sqlNode = parser.parseQuery();*/
SqlNode sqlNode = getSqlParser(query).parseStmt();
@@ -124,16 +131,22 @@ public class QueryProcessor {
SqlNode where = sqlSelect.getWhere();
for (String table : tablesArr) {
- String[] split = table.split("`");
- String tableName = split[1];
+
+ String tableName = null;
+ if(table.contains("`")) {
+ String[] split = table.split("`");
+ tableName = split[1];
+ } else
+ tableName = table;
+
List<String> Ops = tableOpsMap.get(tableName);
if (Ops == null) Ops = new ArrayList<>();
if (where == null) {
Ops.add(Operation.TABLE.getOperation());
- tableOpsMap.put(split[1], Ops);
+ tableOpsMap.put(tableName, Ops);
} else {
Ops.add(Operation.SELECT.getOperation());
- tableOpsMap.put(split[1], Ops);
+ tableOpsMap.put(tableName, Ops);
}
}
}
@@ -141,6 +154,7 @@ public class QueryProcessor {
return tableOpsMap;
}
+ @Deprecated
public static Map<String, List<String>> extractTableFromQuery(String sqlQuery) {
List<String> tables = null;
Map<String, List<String>> tableOpsMap = new HashMap<>();
@@ -214,8 +228,12 @@ public class QueryProcessor {
}
public static void main(String[] args) throws SqlParseException {
- String sqlQuery = "SELECT name, age FROM table1 t1, table2 t2 WHERE t1.id = t2.id";
- // Map<String, List<String>> tableOpsMap = extractTableFromQuery(sqlQuery);
+
+ String sqlQuery = "CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20))";
+ System.out.println(parseSqlQuery(sqlQuery));
+
+ sqlQuery = "SELECT name, age FROM table1 t1, table2 t2 WHERE t1.id = t2.id";
+ //Map<String, List<String>> tableOpsMap = extractTableFromQuery(sqlQuery);
System.out.println(parseSqlQuery(sqlQuery));
sqlQuery = "SELECT name, age FROM table1, table2 t2 WHERE id = t2.id";