|
|
|
@ -38,23 +38,29 @@ public class Main {
|
|
|
|
|
|
|
|
|
|
private static ExecutionMode executionMode = ExecutionMode.PLUGIN_BACKEND;
|
|
|
|
|
|
|
|
|
|
private static Connection getConnection(String dbIp, long port, String sid, String username, String password) {
|
|
|
|
|
private static Connection getConnection(String dbIp, long port, String sid, String username, String password) throws SQLException {
|
|
|
|
|
log.debug("Establishing conneciton...");
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
|
|
|
|
|
String jdbcConnection = String.format("jdbc:oracle:thin:@%s:%d:%s", dbIp, port, sid);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
conn = DriverManager.getConnection(jdbcConnection, username, password);
|
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new RuntimeException("Couldn't connect to database", e);
|
|
|
|
|
}
|
|
|
|
|
conn = DriverManager.getConnection(jdbcConnection, username, password);
|
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
|
|
|
|
|
|
log.debug("Established conneciton!");
|
|
|
|
|
return conn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void closeConnection(Connection conn) {
|
|
|
|
|
if (conn != null) {
|
|
|
|
|
try {
|
|
|
|
|
conn.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
log.error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static QueryResult executeExampleQueryWithException(Connection conn) throws SQLException, JsonProcessingException {
|
|
|
|
|
String sql = "SELECT id, version, workspac FROM s_settings";
|
|
|
|
|
return SqlExecutor.executeQuery(conn, sql, 10L);
|
|
|
|
@ -127,7 +133,51 @@ public class Main {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
private static void serveForever(String host, long port, String sid, String username, String password) {
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
conn = getConnection(host, port, sid, username, password);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
System.err.println("Could not connect to Database: " + e.getMessage());
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
log.info("Waiting for input...");
|
|
|
|
|
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.forName("UTF-8")));
|
|
|
|
|
String line;
|
|
|
|
|
StringBuffer commandBuffer = new StringBuffer();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
|
if (!"--- END ---".equals(line)) {
|
|
|
|
|
commandBuffer.append(line).append("\n");
|
|
|
|
|
} else {
|
|
|
|
|
String query = commandBuffer.toString().trim();
|
|
|
|
|
String result;
|
|
|
|
|
if (query.toLowerCase().startsWith("select")) {
|
|
|
|
|
result = formatJsonObject(SqlExecutor.executeQuery(conn, query, null));
|
|
|
|
|
} else if (query.toLowerCase().startsWith("update") || query.toLowerCase().startsWith("insert")) {
|
|
|
|
|
result = formatJsonObject(SqlExecutor.executeUpdate(conn, query));
|
|
|
|
|
} else {
|
|
|
|
|
result = formatJsonObject(SqlExecutor.execute(conn, query));
|
|
|
|
|
}
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
commandBuffer.setLength(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
closeConnection(conn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
String frogRunnerMode = System.getenv("FROG_RUNNER_MODE");
|
|
|
|
|
if (frogRunnerMode != null) {
|
|
|
|
|
if (frogRunnerMode.equals("TERMINAL")) {
|
|
|
|
@ -152,31 +202,8 @@ public class Main {
|
|
|
|
|
String username = args[3];
|
|
|
|
|
String password = args[4];
|
|
|
|
|
|
|
|
|
|
@Cleanup
|
|
|
|
|
Connection conn = getConnection(host, port, sid, username, password);
|
|
|
|
|
log.info("Waiting for input...");
|
|
|
|
|
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.forName("UTF-8")));
|
|
|
|
|
String line;
|
|
|
|
|
StringBuffer commandBuffer = new StringBuffer();
|
|
|
|
|
|
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
|
if (!"--- END ---".equals(line)) {
|
|
|
|
|
commandBuffer.append(line).append("\n");
|
|
|
|
|
} else {
|
|
|
|
|
String query = commandBuffer.toString().trim();
|
|
|
|
|
String result;
|
|
|
|
|
if (query.toLowerCase().startsWith("select")) {
|
|
|
|
|
result = formatJsonObject(SqlExecutor.executeQuery(conn, query, null));
|
|
|
|
|
} else if (query.toLowerCase().startsWith("update") || query.toLowerCase().startsWith("insert")) {
|
|
|
|
|
result = formatJsonObject(SqlExecutor.executeUpdate(conn, query));
|
|
|
|
|
} else {
|
|
|
|
|
result = formatJsonObject(SqlExecutor.execute(conn, query));
|
|
|
|
|
}
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
commandBuffer.setLength(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
serveForever(host, port, sid, username, password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|