|
|
@ -27,8 +27,6 @@ import lombok.extern.log4j.Log4j;
|
|
|
|
|
|
|
|
|
|
|
|
@Log4j
|
|
|
|
@Log4j
|
|
|
|
public class Main {
|
|
|
|
public class Main {
|
|
|
|
private static final long MAX_ROWNUMS = 10L;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
@Getter
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public static enum ExecutionMode {
|
|
|
|
public static enum ExecutionMode {
|
|
|
@ -59,12 +57,12 @@ public class Main {
|
|
|
|
|
|
|
|
|
|
|
|
private static QueryResult executeExampleQueryWithException(Connection conn) throws SQLException, JsonProcessingException {
|
|
|
|
private static QueryResult executeExampleQueryWithException(Connection conn) throws SQLException, JsonProcessingException {
|
|
|
|
String sql = "SELECT id, version, workspac FROM s_settings";
|
|
|
|
String sql = "SELECT id, version, workspac FROM s_settings";
|
|
|
|
return SqlExecutor.executeQuery(conn, sql);
|
|
|
|
return SqlExecutor.executeQuery(conn, sql, 10L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static QueryResult executeExampleQueryWithoutParameter(Connection conn) throws SQLException, JsonProcessingException {
|
|
|
|
private static QueryResult executeExampleQueryWithoutParameter(Connection conn) throws SQLException, JsonProcessingException {
|
|
|
|
String sql = "SELECT id, version, workspace FROM s_settings";
|
|
|
|
String sql = "SELECT id, version, workspace FROM s_settings";
|
|
|
|
return SqlExecutor.executeQuery(conn, sql);
|
|
|
|
return SqlExecutor.executeQuery(conn, sql, 10L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static QueryResult executeExampleQueryWithParameter(Connection conn) throws SQLException, JsonProcessingException {
|
|
|
|
private static QueryResult executeExampleQueryWithParameter(Connection conn) throws SQLException, JsonProcessingException {
|
|
|
@ -109,7 +107,7 @@ public class Main {
|
|
|
|
@Cleanup
|
|
|
|
@Cleanup
|
|
|
|
Connection conn = getConnection("172.19.13.66", 1521L, "aax2qc", "aax2qc", "aax2qc");
|
|
|
|
Connection conn = getConnection("172.19.13.66", 1521L, "aax2qc", "aax2qc", "aax2qc");
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(formatJsonObject(SqlExecutor.executeJsonQuery(conn, "{ \"sql\": \"select customer_id from d_customers\"}")));
|
|
|
|
System.out.println(formatJsonObject(SqlExecutor.executeJsonQuery(conn, 10L, "{ \"sql\": \"select customer_id from d_customers\"}")));
|
|
|
|
System.out.println(formatJsonObject(compileExampleSpec(conn)));
|
|
|
|
System.out.println(formatJsonObject(compileExampleSpec(conn)));
|
|
|
|
System.out.println(formatJsonObject(compileExampleSpecWithErrors(conn)));
|
|
|
|
System.out.println(formatJsonObject(compileExampleSpecWithErrors(conn)));
|
|
|
|
System.out.println(formatJsonObject(executeExampleQueryWithException(conn)));
|
|
|
|
System.out.println(formatJsonObject(executeExampleQueryWithException(conn)));
|
|
|
@ -137,7 +135,6 @@ public class Main {
|
|
|
|
String sid = args[2];
|
|
|
|
String sid = args[2];
|
|
|
|
String username = args[3];
|
|
|
|
String username = args[3];
|
|
|
|
String password = args[4];
|
|
|
|
String password = args[4];
|
|
|
|
long maxRownums = (args.length >= 6) ? Long.parseLong(args[5]) : MAX_ROWNUMS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Cleanup
|
|
|
|
@Cleanup
|
|
|
|
Connection conn = getConnection(host, port, sid, username, password);
|
|
|
|
Connection conn = getConnection(host, port, sid, username, password);
|
|
|
@ -154,9 +151,7 @@ public class Main {
|
|
|
|
String query = commandBuffer.toString().trim();
|
|
|
|
String query = commandBuffer.toString().trim();
|
|
|
|
String result;
|
|
|
|
String result;
|
|
|
|
if (query.toLowerCase().startsWith("select")) {
|
|
|
|
if (query.toLowerCase().startsWith("select")) {
|
|
|
|
String selectQuery = String.format("SELECT * FROM (%s) WHERE rownum <= %d", query.replaceAll(";$", "").trim(), maxRownums);
|
|
|
|
result = formatJsonObject(SqlExecutor.executeQuery(conn, query, null));
|
|
|
|
|
|
|
|
|
|
|
|
result = formatJsonObject(SqlExecutor.executeQuery(conn, selectQuery));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
result = formatJsonObject(SqlExecutor.execute(conn, query));
|
|
|
|
result = formatJsonObject(SqlExecutor.execute(conn, query));
|
|
|
|
}
|
|
|
|
}
|
|
|
|