phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject [1/2] git commit: PHOENIX-89 Statements are not closed using PhoenixConnection.executeStatements()
Date Mon, 03 Mar 2014 21:05:44 GMT
Repository: incubator-phoenix
Updated Branches:
  refs/heads/master 1190a54b2 -> 77c2a040d


PHOENIX-89 Statements are not closed using PhoenixConnection.executeStatements()


Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/08cd6587
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/08cd6587
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/08cd6587

Branch: refs/heads/master
Commit: 08cd6587b1af4ad0b32cd5c39d08687f58fafaa1
Parents: 70a6ea3
Author: maryannxue <maryannxue@apache.org>
Authored: Mon Mar 3 16:03:57 2014 -0500
Committer: maryannxue <maryannxue@apache.org>
Committed: Mon Mar 3 16:03:57 2014 -0500

----------------------------------------------------------------------
 .../apache/phoenix/jdbc/PhoenixConnection.java  | 108 ++++++++++---------
 1 file changed, 57 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/08cd6587/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index 705489e..01481ac 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -196,72 +196,78 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
         PhoenixStatementParser parser = new PhoenixStatementParser(reader);
         try {
             while (true) {
-                PhoenixPreparedStatement stmt = new PhoenixPreparedStatement(this, parser);
-                this.statements.add(stmt);
-                ParameterMetaData paramMetaData = stmt.getParameterMetaData();
-                for (int i = 0; i < paramMetaData.getParameterCount(); i++) {
-                    stmt.setObject(i+1, binds.get(bindsOffset+i));
-                }
-                long start = System.currentTimeMillis();
-                boolean isQuery = stmt.execute();
-                if (isQuery) {
-                    ResultSet rs = stmt.getResultSet();
-                    if (!rs.next()) {
-                        if (out != null) {
-                            out.println("no rows selected");
-                        }
-                    } else {
-                        int columnCount = 0;
-                        if (out != null) {
-                            ResultSetMetaData md = rs.getMetaData();
-                            columnCount = md.getColumnCount();
-                            for (int i = 1; i <= columnCount; i++) {
-                                int displayWidth = md.getColumnDisplaySize(i);
-                                String label = md.getColumnLabel(i);
-                                if (md.isSigned(i)) {
-                                    out.print(displayWidth < label.length() ? label.substring(0,displayWidth)
: Strings.padStart(label, displayWidth, ' '));
-                                    out.print(' ');
-                                } else {
-                                    out.print(displayWidth < label.length() ? label.substring(0,displayWidth)
: Strings.padEnd(md.getColumnLabel(i), displayWidth, ' '));
-                                    out.print(' ');
-                                }
-                            }
-                            out.println();
-                            for (int i = 1; i <= columnCount; i++) {
-                                int displayWidth = md.getColumnDisplaySize(i);
-                                out.print(Strings.padStart("", displayWidth,'-'));
-                                out.print(' ');
+                PhoenixPreparedStatement stmt = null;
+                try {
+                    stmt = new PhoenixPreparedStatement(this, parser);
+                    ParameterMetaData paramMetaData = stmt.getParameterMetaData();
+                    for (int i = 0; i < paramMetaData.getParameterCount(); i++) {
+                        stmt.setObject(i+1, binds.get(bindsOffset+i));
+                    }
+                    long start = System.currentTimeMillis();
+                    boolean isQuery = stmt.execute();
+                    if (isQuery) {
+                        ResultSet rs = stmt.getResultSet();
+                        if (!rs.next()) {
+                            if (out != null) {
+                                out.println("no rows selected");
                             }
-                            out.println();
-                        }
-                        do {
+                        } else {
+                            int columnCount = 0;
                             if (out != null) {
                                 ResultSetMetaData md = rs.getMetaData();
+                                columnCount = md.getColumnCount();
                                 for (int i = 1; i <= columnCount; i++) {
                                     int displayWidth = md.getColumnDisplaySize(i);
-                                    String value = rs.getString(i);
-                                    String valueString = value == null ? QueryConstants.NULL_DISPLAY_TEXT
: value;
+                                    String label = md.getColumnLabel(i);
                                     if (md.isSigned(i)) {
-                                        out.print(Strings.padStart(valueString, displayWidth,
' '));
+                                        out.print(displayWidth < label.length() ? label.substring(0,displayWidth)
: Strings.padStart(label, displayWidth, ' '));
+                                        out.print(' ');
                                     } else {
-                                        out.print(Strings.padEnd(valueString, displayWidth,
' '));
+                                        out.print(displayWidth < label.length() ? label.substring(0,displayWidth)
: Strings.padEnd(md.getColumnLabel(i), displayWidth, ' '));
+                                        out.print(' ');
                                     }
+                                }
+                                out.println();
+                                for (int i = 1; i <= columnCount; i++) {
+                                    int displayWidth = md.getColumnDisplaySize(i);
+                                    out.print(Strings.padStart("", displayWidth,'-'));
                                     out.print(' ');
                                 }
                                 out.println();
                             }
-                        } while (rs.next());
+                            do {
+                                if (out != null) {
+                                    ResultSetMetaData md = rs.getMetaData();
+                                    for (int i = 1; i <= columnCount; i++) {
+                                        int displayWidth = md.getColumnDisplaySize(i);
+                                        String value = rs.getString(i);
+                                        String valueString = value == null ? QueryConstants.NULL_DISPLAY_TEXT
: value;
+                                        if (md.isSigned(i)) {
+                                            out.print(Strings.padStart(valueString, displayWidth,
' '));
+                                        } else {
+                                            out.print(Strings.padEnd(valueString, displayWidth,
' '));
+                                        }
+                                        out.print(' ');
+                                    }
+                                    out.println();
+                                }
+                            } while (rs.next());
+                        }
+                    } else if (out != null){
+                        int updateCount = stmt.getUpdateCount();
+                        if (updateCount >= 0) {
+                            out.println((updateCount == 0 ? "no" : updateCount) + (updateCount
== 1 ? " row " : " rows ") + stmt.getUpdateOperation().toString());
+                        }
                     }
-                } else if (out != null){
-                    int updateCount = stmt.getUpdateCount();
-                    if (updateCount >= 0) {
-                        out.println((updateCount == 0 ? "no" : updateCount) + (updateCount
== 1 ? " row " : " rows ") + stmt.getUpdateOperation().toString());
+                    bindsOffset += paramMetaData.getParameterCount();
+                    double elapsedDuration = ((System.currentTimeMillis() - start) / 1000.0);
+                    out.println("Time: " + elapsedDuration + " sec(s)\n");
+                    nStatements++;
+                } finally {
+                    if (stmt != null) {
+                        stmt.close();
                     }
                 }
-                bindsOffset += paramMetaData.getParameterCount();
-                double elapsedDuration = ((System.currentTimeMillis() - start) / 1000.0);
-                out.println("Time: " + elapsedDuration + " sec(s)\n");
-                nStatements++;
             }
         } catch (EOFException e) {
         }


Mime
View raw message