You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/09/06 01:56:42 UTC
[2/4] git commit: Fix connection leak in SqlRun
Fix connection leak in SqlRun
Project: http://git-wip-us.apache.org/repos/asf/incubator-optiq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-optiq/commit/b139ab80
Tree: http://git-wip-us.apache.org/repos/asf/incubator-optiq/tree/b139ab80
Diff: http://git-wip-us.apache.org/repos/asf/incubator-optiq/diff/b139ab80
Branch: refs/heads/master
Commit: b139ab80b23a74ce940095ef5db029b5aa03714a
Parents: d62c064
Author: Julian Hyde <jh...@apache.org>
Authored: Fri Sep 5 13:14:54 2014 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Fri Sep 5 13:14:54 2014 -0700
----------------------------------------------------------------------
.../main/java/net/hydromatic/optiq/tools/SqlRun.java | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/b139ab80/core/src/main/java/net/hydromatic/optiq/tools/SqlRun.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/tools/SqlRun.java b/core/src/main/java/net/hydromatic/optiq/tools/SqlRun.java
index edac068..5a7b505 100644
--- a/core/src/main/java/net/hydromatic/optiq/tools/SqlRun.java
+++ b/core/src/main/java/net/hydromatic/optiq/tools/SqlRun.java
@@ -92,6 +92,14 @@ public class SqlRun {
}
}
+ private void close() throws SQLException {
+ if (connection != null) {
+ Connection c = connection;
+ connection = null;
+ c.close();
+ }
+ }
+
public void execute(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
this.printWriter = new PrintWriter(writer);
@@ -99,6 +107,7 @@ public class SqlRun {
Command command = new Parser().parse();
try {
command.execute(execute);
+ close();
} catch (Exception e) {
throw new RuntimeException(
"Error while executing command " + command, e);
@@ -108,7 +117,11 @@ public class SqlRun {
}
} finally {
printWriter.flush();
- this.connection = null;
+ try {
+ close();
+ } catch (SQLException e) {
+ // ignore
+ }
}
}