Changeset: daa1a4c70879 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=daa1a4c70879
Modified Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
Branch: default
Log Message:

For MonetresultSet class: added method checkNotClosed() and invocation for all 
methods which should test it.
This makes the behavior more robust and compliant with JDBC spec in case the 
ResultSet object was closed.
Also changed 3 variables from public access into protected.

For rsmdw class: added method checkColumnIndexValidity() and invocation for all 
relevant ResultSetMetaData methods.
Previously when a method was called with column nr 0 it would not throw an 
exception. Now it does.
Added made the internal array variables final.


diffs (truncated from 1155 to 300 lines):

diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -70,14 +70,9 @@ public class MonetResultSet
        extends MonetWrapper
        implements ResultSet, AutoCloseable
 {
-       // the following have default access modifier for the 
MonetVirtualResultSet subclass
-       /** The current line of the buffer split in columns */
-       final TupleLineParser tlp;
-       /** The current position of the cursor for this ResultSet object */
-       int curRow = 0;
-
-       // a blank final is immutable once assigned in the constructor
-       /** A Header to retrieve lines from */
+       /** The parental Statement object */
+       private final Statement statement;
+       /** A Header to retrieve lines from. Note: it will be null in case of a 
MonetVirtualResultSet ! */
        private final MonetConnection.ResultSetResponse header;
        /** The names of the columns in this ResultSet */
        private final String[] columns;
@@ -85,11 +80,15 @@ public class MonetResultSet
        private final String[] types;
        /** The JDBC SQL types of the columns in this ResultSet. The content 
will be derived from the MonetDB types[] */
        private final int[] JdbcSQLTypes;
+
+       // the following have protected access modifier for the 
MonetVirtualResultSet subclass
+       // they are accessed from MonetVirtualResultSet.absolute()
+       /** The current line of the buffer split in columns */
+       protected final TupleLineParser tlp;
+       /** The current position of the cursor for this ResultSet object */
+       protected int curRow = 0;
        /** The number of rows in this ResultSet */
-       final int tupleCount;
-
-       /** The parental Statement object */
-       private final Statement statement;
+       protected final int tupleCount;
 
        /** The type of this ResultSet (forward or scrollable) */
        private int type = TYPE_FORWARD_ONLY;
@@ -246,13 +245,11 @@ public class MonetResultSet
         */
        @Override
        public boolean absolute(int row) throws SQLException {
+               checkNotClosed();
                if (row != curRow + 1 && type == TYPE_FORWARD_ONLY)
                        throw new SQLException("(Absolute) positioning not 
allowed on forward " +
                                " only result sets!", "M1M05");
 
-               if (header.isClosed())
-                       throw new SQLException("ResultSet is closed!", "M1M20");
-
                // first calculate what the JDBC row is
                if (row < 0) {
                        // calculate the negatives...
@@ -264,13 +261,13 @@ public class MonetResultSet
                else if (row > tupleCount + 1)
                        row = tupleCount + 1;   // after last
 
-               String tmpLine = header.getLine(row - 1);
-
                // store it
                curRow = row;
 
+               String tmpLine = (header != null) ? header.getLine(row - 1) : 
null;
                if (tmpLine == null)
                        return false;
+
                try {
                        tlp.parse(tmpLine);
                } catch (MCLParseException e) {
@@ -337,10 +334,12 @@ public class MonetResultSet
         *
         * @param columnLabel the name of the column
         * @return the column index of the given column name
-        * @throws SQLException if the ResultSet object does not contain 
columnLabel
+        * @throws SQLException if the ResultSet object does not contain a 
column labeled columnLabel,
+        *      a database access error occurs or this method is called on a 
closed result set
         */
        @Override
        public int findColumn(String columnLabel) throws SQLException {
+               checkNotClosed();
                if (columnLabel != null) {
                        final int array_size = columns.length;
                        for (int i = 0; i < array_size; i++) {
@@ -416,11 +415,11 @@ public class MonetResultSet
         * value as a stream of uninterpreted bytes; if the value is SQL
         * NULL, the value returned is null
         * @throws SQLException if the columnIndex is not valid; if a
-        * database access error occurs or this method is called on a closed
-        * result set
+        * database access error occurs or this method is called on a closed 
result set
         */
        @Override
        public InputStream getBinaryStream(int columnIndex) throws SQLException 
{
+               checkNotClosed();
                try {
                        switch (JdbcSQLTypes[columnIndex - 1]) {
                                case Types.BLOB:
@@ -461,8 +460,7 @@ public class MonetResultSet
         * value as a stream of uninterpreted bytes; if the value is SQL
         * NULL, the result is null
         * @throws SQLException if the columnLabel is not valid; if a
-        * database access error occurs or this method is called on a closed
-        * result set
+        * database access error occurs or this method is called on a closed 
result set
         */
        @Override
        public InputStream getBinaryStream(String columnLabel) throws 
SQLException {
@@ -477,10 +475,11 @@ public class MonetResultSet
         * @return a java.io.Reader object that contains the column value;
         *         if the value is SQL NULL, the value returned is null in
         *         the Java programming language.
-        * @throws SQLException if a database access error occurs
+        * @throws SQLException if a database access error occurs or this 
method is called on a closed result set
         */
        @Override
        public Reader getCharacterStream(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -555,10 +554,11 @@ public class MonetResultSet
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return a Blob object representing the SQL BLOB value in the
         *         specified column
-        * @throws SQLException if a database access error occurs
+        * @throws SQLException if a database access error occurs or this 
method is called on a closed result set
         */
        @Override
        public Blob getBlob(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -596,10 +596,11 @@ public class MonetResultSet
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return a Clob object representing the SQL CLOB value in the
         *         specified column
-        * @throws SQLException if a database access error occurs
+        * @throws SQLException if a database access error occurs or this 
method is called on a closed result set
         */
        @Override
        public Clob getClob(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -671,10 +672,11 @@ public class MonetResultSet
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return the column value (full precision); if the value is SQL NULL,
         *         the value returned is null in the Java programming language.
-        * @throws SQLException if a database access error occurs
+        * @throws SQLException if a database access error occurs or this 
method is called on a closed result set
         */
        @Override
        public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -698,13 +700,14 @@ public class MonetResultSet
         * @param scale the number of digits to the right of the decimal point
         * @return the column value (full precision); if the value is SQL NULL,
         *         the value returned is null in the Java programming language.
-        * @throws SQLException if a database access error occurs
+        * @throws SQLException if a database access error occurs or this 
method is called on a closed result set
         */
        @Override
        @Deprecated
        public BigDecimal getBigDecimal(int columnIndex, int scale)
                throws SQLException
        {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -763,10 +766,12 @@ public class MonetResultSet
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return the column value; if the value is SQL NULL, the value 
returned
         *         is false
-        * @throws SQLException if there is no such column
+        * @throws SQLException if the columnIndex is not valid; if a database 
access error occurs
+        *      or this method is called on a closed result set
         */
        @Override
        public boolean getBoolean(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -845,10 +850,11 @@ public class MonetResultSet
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return the column value; if the value is SQL NULL, the value 
returned
         *         is 0
-        * @throws SQLException if a database access error occurs
+        * @throws SQLException if a database access error occurs or this 
method is called on a closed result set
         */
        @Override
        public byte getByte(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -886,10 +892,11 @@ public class MonetResultSet
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return the column value; if the value is SQL NULL, the value 
returned
         *         is null
-        * @throws SQLException if a database access error occurs
+        * @throws SQLException if a database access error occurs or this 
method is called on a closed result set
         */
        @Override
        public byte[] getBytes(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -990,12 +997,12 @@ public class MonetResultSet
         * ResultSet object as a double in the Java programming language.
         *
         * @param columnIndex the first column is 1, the second is 2, ...
-        * @return the column value; if the value is SQL NULL, the value 
returned
-        *         is 0
-        * @throws SQLException if there is no such column
+        * @return the column value; if the value is SQL NULL, the value 
returned is 0
+        * @throws SQLException if there is no such column or this method is 
called on a closed result set
         */
        @Override
        public double getDouble(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -1016,8 +1023,7 @@ public class MonetResultSet
         * ResultSet object as a double in the Java programming language.
         *
         * @param columnLabel the SQL name of the column
-        * @return the column value; if the value is SQL NULL, the value 
returned
-        *         is 0
+        * @return the column value; if the value is SQL NULL, the value 
returned is 0
         * @throws SQLException if the ResultSet object does not contain 
columnLabel
         */
        @Override
@@ -1039,7 +1045,6 @@ public class MonetResultSet
 
        /**
         * Retrieves the fetch direction for this ResultSet object.
-        * <b>currently not implemented</b>
         *
         * @return the current fetch direction for this ResultSet object
         */
@@ -1053,7 +1058,6 @@ public class MonetResultSet
         * object will be processed. The initial value is determined by the
         * Statement object that produced this ResultSet object.
         * The fetch direction may be changed at any time.
-        * <b>currently not implemented</b>
         *
         * @param direction - an int specifying the suggested fetch direction;
         * one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or 
ResultSet.FETCH_UNKNOWN
@@ -1110,12 +1114,12 @@ public class MonetResultSet
         * ResultSet object as a float in the Java programming language.
         *
         * @param columnIndex the first column is 1, the second is 2, ...
-        * @return the column value; if the value is SQL NULL, the value 
returned
-        *         is 0
-        * @throws SQLException if there is no such column
+        * @return the column value; if the value is SQL NULL, the value 
returned is 0
+        * @throws SQLException if there is no such column or this method is 
called on a closed result set
         */
        @Override
        public float getFloat(int columnIndex) throws SQLException {
+               checkNotClosed();
                try {
                        String val = tlp.values[columnIndex - 1];
                        if (val == null) {
@@ -1150,10 +1154,11 @@ public class MonetResultSet
         *
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return the column value; if the value is SQL NULL, the value 
returned is 0
-        * @throws SQLException if there is no such column
+        * @throws SQLException if there is no such column or this method is 
called on a closed result set
         */
        @Override
        public int getInt(int columnIndex) throws SQLException {
+               checkNotClosed();
                String val = "";
                try {
                        val = tlp.values[columnIndex - 1];
@@ -1201,10 +1206,11 @@ public class MonetResultSet
         *
         * @param columnIndex the first column is 1, the second is 2, ...
         * @return the column value; if the value is SQL NULL, the value 
returned is 0
-        * @throws SQLException if there is no such column
+        * @throws SQLException if there is no such column or this method is 
called on a closed result set
         */
        @Override
        public long getLong(int columnIndex) throws SQLException {
+               checkNotClosed();
                String val = "";
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to