Changeset: 1c3cdf0667d7 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/1c3cdf0667d7
Modified Files:
        src/main/java/org/monetdb/jdbc/MonetConnection.java
        src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
        src/main/java/org/monetdb/jdbc/MonetResultSet.java
        src/main/java/org/monetdb/jdbc/MonetStatement.java
Branch: default
Log Message:

Do more cleanup in the close() methods such as calling clearWarnings(), 
clearParameters(), clearBatch() and dereferencing cached objects.
Remove deprecated finalize() method from MonetPreparedStatement. finalize() is 
deprecated from Java 9 onwards.


diffs (154 lines):

diff --git a/src/main/java/org/monetdb/jdbc/MonetConnection.java 
b/src/main/java/org/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -432,7 +432,14 @@ public class MonetConnection
         */
        @Override
        public void close() {
+               if (closed)
+                       return;
+
+               clearWarnings();
+               dbmd = null;
                synchronized (server) {
+                       // Note: An entry in a WeakHashMap will automatically be
+                       // removed when its key is no longer in ordinary use.
                        for (Statement st : statements.keySet()) {
                                try {
                                        st.close();
@@ -2587,7 +2594,8 @@ public class MonetConnection
                 */
                @Override
                public void close() {
-                       if (closed) return;
+                       if (closed)
+                               return;
 
                        // send command to server indicating we're done with 
this
                        // result only if we had an ID in the header and this 
result
@@ -2605,7 +2613,12 @@ public class MonetConnection
                                if (r != null)
                                        r.close();
                        }
-
+                       name = null;
+                       type = null;
+                       columnLengths = null;
+                       tableNames = null;
+                       schemaNames = null;
+                       resultBlocks = null;
                        closed = true;
                }
 
diff --git a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java 
b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
--- a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
@@ -2692,28 +2692,24 @@ public class MonetPreparedStatement
         */
        @Override
        public void close() {
-               try {
-                       if (!closed && id != -1)
+               if (!closed && id != -1) {
+                       try {
                                connection.sendControlCommand("release " + id);
-               } catch (SQLException e) {
-                       // probably server closed connection
+                       } catch (SQLException e) {
+                               // probably server closed connection
+                       }
                }
+               clearParameters();
+               mTimestampZ = null;
+               mTimestamp = null;
+               mTimeZ = null;
+               mTime = null;
+               mDate = null;
+               execStmt = null;
                super.close();
        }
 
        /**
-        * Call close to release the server-sided handle for this
-        * PreparedStatement.
-        *
-        * @deprecated (since="9")
-        */
-       @Override
-       @Deprecated
-       protected void finalize() {
-               close();
-       }
-
-       /**
         * Return the prepared SQL statement including parameter types and 
parameter values that were set.
         *
         * @return a String representing this Object
diff --git a/src/main/java/org/monetdb/jdbc/MonetResultSet.java 
b/src/main/java/org/monetdb/jdbc/MonetResultSet.java
--- a/src/main/java/org/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/org/monetdb/jdbc/MonetResultSet.java
@@ -320,6 +320,7 @@ public class MonetResultSet
         */
        @Override
        public void close() {
+               clearWarnings();
                if (header != null && !header.isClosed()) {
                        header.close();
                }
diff --git a/src/main/java/org/monetdb/jdbc/MonetStatement.java 
b/src/main/java/org/monetdb/jdbc/MonetStatement.java
--- a/src/main/java/org/monetdb/jdbc/MonetStatement.java
+++ b/src/main/java/org/monetdb/jdbc/MonetStatement.java
@@ -252,11 +252,15 @@ public class MonetStatement
         */
        @Override
        public void close() {
+               clearBatch();
+               clearWarnings();
                // close previous ResultSet, if not closed already
                if (lastResponseList != null) {
                        lastResponseList.close();
                        lastResponseList = null;
                }
+               header = null;
+               batchLock = null;
                closed = true;
        }
 
@@ -904,8 +908,7 @@ public class MonetStatement
         * general should not be necessary given SQL standards compliance.
         * In this sense, this driver will ignore any call to this function.
         *
-        * @param enable true to enable escape processing; false to disable
-        *        it
+        * @param enable true to enable escape processing; false to disable it
         * @throws SQLException if a database access error occurs
         */
        @Override
@@ -952,7 +955,7 @@ public class MonetStatement
         */
        @Override
        public void setFetchSize(final int rows) throws SQLException {
-               if (rows >= 0 && !(getMaxRows() != 0 && rows > getMaxRows())) {
+               if (rows >= 0 && !(maxRows != 0 && rows > getMaxRows())) {
                        fetchSize = rows;
                } else {
                        throw new SQLException("Illegal fetch size value: " + 
rows, "M1M05");
@@ -1509,7 +1512,7 @@ public class MonetStatement
  * TODO: try to eliminate the need for this class completely.
  */
 final class MonetVirtualResultSet extends MonetResultSet {
-       private final String results[][];
+       private String results[][];
        private boolean closed;
 
        MonetVirtualResultSet(
@@ -1571,7 +1574,8 @@ final class MonetVirtualResultSet extend
         */
        @Override
        public void close() {
+               results = null;
                closed = true;
-               // types and columns are MonetResultSets private parts
+               super.close();
        }
 }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to