Changeset: 41e9202e4bde for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=41e9202e4bde
Modified Files:
        java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
        java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
Branch: Jun2016
Log Message:

Migrating code of class MonetVirtualResultSet from MonetDatabaseMetaData.java 
to MonetResultSet.java.
For the Jun2016 release I have removed all usages of MonetVirtualResultSet from 
MonetDatabaseMetaData.java
so it does not make sense to keep in this file.
MonetVirtualResultSet is a subclass of MonetResultSet, so it is more logical to 
include it in that file.
Also added info on issues with this internal (not part of JDBC) class.


diffs (192 lines):

diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java 
b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
--- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
+++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
@@ -4074,88 +4074,3 @@ public class MonetDatabaseMetaData exten
 
        //== end methods interface DatabaseMetaData
 }
-
-/**
- * This class is not intended for normal use. Therefore it is restricted to
- * classes from the very same package only. Because it is mainly used
- * only in the MonetDatabaseMetaData class it is placed here.
- */
-class MonetVirtualResultSet extends MonetResultSet {
-       private String results[][];
-       private boolean closed;
-
-       MonetVirtualResultSet(
-               String[] columns,
-               String[] types,
-               String[][] results
-       ) throws IllegalArgumentException {
-               super(columns, types, results.length);
-
-               this.results = results;
-               closed = false;
-       }
-
-       /**
-        * This method is overridden in order to let it use the results array
-        * instead of the cache in the Statement object that created it.
-        *
-        * @param row the number of the row to which the cursor should move. A
-        *        positive number indicates the row number counting from the
-        *        beginning of the result set; a negative number indicates the 
row
-        *        number counting from the end of the result set
-        * @return true if the cursor is on the result set; false otherwise
-        * @throws SQLException if a database error occurs
-        */
-       @Override
-       public boolean absolute(int row) throws SQLException {
-               if (closed)
-                       throw new SQLException("ResultSet is closed!", "M1M20");
-
-               // first calculate what the JDBC row is
-               if (row < 0) {
-                       // calculate the negatives...
-                       row = tupleCount + row + 1;
-               }
-               // now place the row not farther than just before or after the 
result
-               if (row < 0) row = 0;   // before first
-               else if (row > tupleCount + 1) row = tupleCount + 1;    // 
after last
-
-               // store it
-               curRow = row;
-
-               // see if we have the row
-               if (row < 1 || row > tupleCount) return false;
-
-               for (int i = 0; i < results[row - 1].length; i++) {
-                       tlp.values[i] = results[row - 1][i];
-               }
-
-               return true;
-       }
-
-       /**
-        * Mainly here to prevent errors when the close method is called. There
-        * is no real need for this object to close it. We simply remove our
-        * resultset data.
-        */
-       @Override
-       public void close() {
-               if (!closed) {
-                       closed = true;
-                       results = null;
-                       // types and columns are MonetResultSets private parts
-               }
-       }
-
-       /**
-        * Retrieves the fetch size for this ResultSet object, which will be
-        * zero, since it's a virtual set.
-        *
-        * @return the current fetch size for this ResultSet object
-        * @throws SQLException if a database access error occurs
-        */
-       @Override
-       public int getFetchSize() throws SQLException {
-               return 0;
-       }
-}
diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java 
b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -3435,3 +3435,96 @@ public class MonetResultSet extends Mone
                return new SQLFeatureNotSupportedException("Method " + name + " 
not implemented", "0A000");
        }
 }
+
+/**
+ * This internal subclass is not intended for normal use. Therefore it is 
restricted to
+ * classes from the very same package only.
+ *
+ * Known issues with this class: some methods of the ResultSetMetaData object 
(obtained via getMetaData())
+ * require that its statement argument (accessed via getStatement()) has a 
valid Statement object set.
+ * Instances of this subclass do not have a valid Statement (see special 
constructor), so
+ * those metadata methods do not return the correct values.
+ * Special checks are programmed to prevent NullPointerExceptions, see above.
+ *
+ * As of Jun2016 this class is only used by MonetStatement.getGeneratedKeys()
+ * TODO: try to eliminate the need for this class completely.
+ */
+class MonetVirtualResultSet extends MonetResultSet {
+       private String results[][];
+       private boolean closed;
+
+       MonetVirtualResultSet(
+               String[] columns,
+               String[] types,
+               String[][] results
+       ) throws IllegalArgumentException {
+               super(columns, types, results.length);
+
+               this.results = results;
+               closed = false;
+       }
+
+       /**
+        * This method is overridden in order to let it use the results array
+        * instead of the cache in the Statement object that created it.
+        *
+        * @param row the number of the row to which the cursor should move. A
+        *        positive number indicates the row number counting from the
+        *        beginning of the result set; a negative number indicates the 
row
+        *        number counting from the end of the result set
+        * @return true if the cursor is on the result set; false otherwise
+        * @throws SQLException if a database error occurs
+        */
+       @Override
+       public boolean absolute(int row) throws SQLException {
+               if (closed)
+                       throw new SQLException("ResultSet is closed!", "M1M20");
+
+               // first calculate what the JDBC row is
+               if (row < 0) {
+                       // calculate the negatives...
+                       row = tupleCount + row + 1;
+               }
+               // now place the row not farther than just before or after the 
result
+               if (row < 0) row = 0;   // before first
+               else if (row > tupleCount + 1) row = tupleCount + 1;    // 
after last
+
+               // store it
+               curRow = row;
+
+               // see if we have the row
+               if (row < 1 || row > tupleCount) return false;
+
+               for (int i = 0; i < results[row - 1].length; i++) {
+                       tlp.values[i] = results[row - 1][i];
+               }
+
+               return true;
+       }
+
+       /**
+        * Mainly here to prevent errors when the close method is called. There
+        * is no real need for this object to close it. We simply remove our
+        * resultset data.
+        */
+       @Override
+       public void close() {
+               if (!closed) {
+                       closed = true;
+                       results = null;
+                       // types and columns are MonetResultSets private parts
+               }
+       }
+
+       /**
+        * Retrieves the fetch size for this ResultSet object, which will be
+        * zero, since it's a virtual set.
+        *
+        * @return the current fetch size for this ResultSet object
+        * @throws SQLException if a database access error occurs
+        */
+       @Override
+       public int getFetchSize() throws SQLException {
+               return 0;
+       }
+}
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to