Changeset: 4a5fded5bea7 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4a5fded5bea7
Modified Files:
        java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
        java/src/nl/cwi/monetdb/jdbc/MonetStatement.java
Branch: Oct2010
Log Message:

Send Xclose command for prepared handles, bug #2720


diffs (81 lines):

diff -r 1711adfe9ad4 -r 4a5fded5bea7 
java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
--- a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java  Wed Dec 15 
11:35:48 2010 +0100
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java  Wed Dec 15 
11:49:59 2010 +0100
@@ -62,6 +62,8 @@
 
        private final String[] values;
        private final StringBuffer buf;
+       
+       private final MonetConnection connection;
 
        /* only parse the date patterns once, use multiple times */
        /** Format of a timestamp with RFC822 time zone */
@@ -117,6 +119,8 @@
                values = new String[size];
                buf = new StringBuffer(6 + 12 * size);
 
+               this.connection = connection;
+
                // fill the arrays
                ResultSet rs = super.getResultSet();
                for (int i = 0; rs.next(); i++) {
@@ -159,6 +163,8 @@
                buf = null;
                id = -1;
                size = -1;
+
+               this.connection = connection;
        }
 
        //== methods interface PreparedStatement
@@ -1322,6 +1328,38 @@
                throw new SQLException("Operation currently not supported!");
        }
 
+       /**
+        * Releases this PreparedStatement object's database and JDBC
+        * resources immediately instead of waiting for this to happen when
+        * it is automatically closed.  It is generally good practice to
+        * release resources as soon as you are finished with them to avoid
+        * tying up database resources.
+        * <br /><br />
+        * Calling the method close on a PreparedStatement object that is
+        * already closed has no effect.
+        * <br /><br />
+        * <b>Note:</b> A PreparedStatement object is automatically closed
+        * when it is garbage collected. When a Statement object is closed,
+        * its current ResultSet object, if one exists, is also closed. 
+        */
+       public void close() {
+               try {
+                       if (!closed && id != -1)
+                               connection.sendControlCommand("close " + id);
+               } catch (SQLException e) {
+                       // probably server closed connection
+               }
+               super.close();
+       }
+
+       /**
+        * Call close to release the server-sided handle for this
+        * PreparedStatement.
+        */
+       protected void finalize() {
+               close();
+       }
+
        //== end methods interface PreparedStatement
 
        /**
diff -r 1711adfe9ad4 -r 4a5fded5bea7 
java/src/nl/cwi/monetdb/jdbc/MonetStatement.java
--- a/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java  Wed Dec 15 11:35:48 
2010 +0100
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java  Wed Dec 15 11:49:59 
2010 +0100
@@ -59,7 +59,7 @@
        /** The warnings this Statement object generated */
        private SQLWarning warnings;
        /** Whether this Statement object is closed or not */
-       private boolean closed;
+       protected boolean closed;
        /** The size of the blocks of results to ask for at the server */
        private int fetchSize = 0;
        /** The maximum number of rows to return in a ResultSet */
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to