From 8e61f039e99d981759d9217476fa735308524e3d Mon Sep 17 00:00:00 2001 From: Steven Brockman Date: Fri, 13 Sep 2019 09:27:47 -0400 Subject: [PATCH] Adding in error handling changes from Brad --- .../java/com/marklogic/rowbot/QueryBot.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/marklogic/rowbot/QueryBot.java b/src/main/java/com/marklogic/rowbot/QueryBot.java index ac5a153..2e62f4d 100644 --- a/src/main/java/com/marklogic/rowbot/QueryBot.java +++ b/src/main/java/com/marklogic/rowbot/QueryBot.java @@ -76,11 +76,11 @@ public void run() { try { Properties props = new Properties(); - JSONObject propsObj = connectionObj.getJSONObject("properties"); - Iterator itr = propsObj.keys(); - while (itr.hasNext()) { - String key = itr.next(); - props.put(key, propsObj.getString(key)); + JSONObject propsObject = connectionObj.getJSONObject("properties"); + Iterator keys = propsObject.keys(); + while (keys.hasNext()) { + String key = keys.next(); + props.put(key, propsObject.getString(key)); } this.connection = DriverManager.getConnection(connectionString, props); @@ -92,6 +92,8 @@ public void run() { double queryTime = 0; long queryStart = System.nanoTime(); int rowNum = 0; + boolean success = true; + String successMsg = null; try { String query = this.queryObject.getString("query"); try ( @@ -114,6 +116,11 @@ public void run() { Runnable insertThread = new InsertBot(rowMap, queryObject, rowNum, this.rowBot); insertPool.execute(insertThread); } + } catch (Exception e) { + System.out.println("Error with Query: " + query); + e.printStackTrace(); + success = false; + successMsg = e.toString(); } //signals pool to not accept more tasks. @@ -125,10 +132,12 @@ public void run() { long queryEnd = System.nanoTime(); queryTime = (queryEnd - queryStart) / QueryBot.NANO_TIME_DIV; - this.queryComplete(true, this.queryObject.getString("queryId"), this.queryObject.getString("query"), rowNum, queryTime, null); } catch (Exception e) { - this.queryComplete(false, this.queryObject.getString("queryId"), this.queryObject.getString("query"), rowNum, queryTime, e.toString()); + e.printStackTrace(); + success = false; + successMsg = e.toString(); } finally { + this.queryComplete(success, this.queryObject.getString("queryId"), this.queryObject.getString("query"), rowNum, queryTime, successMsg); // NOTE: connections are now closed in RowBot at the END. session.close(); try {