changeset 82:4231a7f5cdc3 embedded

Added better null values mapping for JDBC embedded connection compatibility. The previous potential bug on boolean columns in now fixed
author Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
date Tue, 27 Dec 2016 17:23:38 +0000 (2016-12-27)
parents a3c686217ca1
children 724a0061db63
files src/main/java/nl/cwi/monetdb/embedded/resultset/AbstractQueryResultSetColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetBooleanColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetByteColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetDoubleColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetFloatColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetIntColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetLongColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetObjectColumn.java src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetShortColumn.java src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
diffstat 10 files changed, 102 insertions(+), 205 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/AbstractQueryResultSetColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/AbstractQueryResultSetColumn.java
@@ -27,7 +27,7 @@ public abstract class AbstractQueryResul
     /**
      * The index of the column.
      */
-    protected final int resultSetIndex;
+    final int resultSetIndex;
 
     /**
      * The number of rows in this column.
@@ -44,6 +44,11 @@ public abstract class AbstractQueryResul
      */
     private int lastRetrievedIndex;
 
+    /**
+     * The null values mapping
+     */
+    final boolean[] nullValues;
+
 	protected AbstractQueryResultSetColumn(String columnType, long tablePointer, int resultSetIndex, String columnName,
                                            int columnDigits, int columnScale, int numberOfRows) {
         super(columnType, columnName, columnDigits, columnScale);
@@ -52,6 +57,7 @@ public abstract class AbstractQueryResul
         this.numberOfRows = numberOfRows;
         this.firstRetrievedIndex = numberOfRows;
         this.lastRetrievedIndex = 0;
+        this.nullValues = new boolean[numberOfRows];
  	}
 
     /**
@@ -74,30 +80,15 @@ public abstract class AbstractQueryResul
 
     protected abstract A storeNewDataAndGetResult(int startIndex, int numberOfRowsToRetrieve);
 
-    protected abstract boolean[] checkIfIndexesAreNullImplementation(A values, boolean[] res)
-            throws MonetDBEmbeddedException;
-
-    protected abstract Object[] mapValuesToObjectArrayImplementation(A values)
-            throws MonetDBEmbeddedException;
+    protected abstract Object[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve);
 
-    /**
-     * Maps columns values using the provided Java representation by the query.
-     *
-     * @param startIndex The first column index to retrieve
-     * @param endIndex The last column index to retrieve
-     * @return The column values as a Java array
-     * @throws MonetDBEmbeddedException If an error in the database occurred
-     */
-    public A fetchColumnValues(int startIndex, int endIndex) throws MonetDBEmbeddedException {
+    private int checkBoundsAndFetch(int startIndex, int endIndex) throws MonetDBEmbeddedException {
         if(endIndex < startIndex) {
-            int aux = startIndex;
-            startIndex = endIndex;
-            endIndex = aux;
-        }
-        if (startIndex < 0) {
+            throw new ArrayIndexOutOfBoundsException("The endIndex cannot be smaller than the startIndex!");
+        } else if (startIndex < 0) {
             throw new ArrayIndexOutOfBoundsException("The start index must be larger than 0!");
         } else if (endIndex > this.numberOfRows) {
-            throw new ArrayIndexOutOfBoundsException("The index must be smaller than the number of elements in the columns!");
+            throw new ArrayIndexOutOfBoundsException("The index must be smaller than the number of elements in the set!");
         } else if(startIndex == endIndex) {
             throw new ArrayIndexOutOfBoundsException("Retrieving 0 values?");
         }
@@ -119,6 +110,19 @@ public abstract class AbstractQueryResul
             }
             this.fetchMoreData(firstIndexToFetch, lastIndexToFetch);
         }
+        return numberOfRowsToRetrieve;
+    }
+
+    /**
+     * Maps columns values using the provided Java representation by the query.
+     *
+     * @param startIndex The first column index to retrieve
+     * @param endIndex The last column index to retrieve
+     * @return The column values as a Java array
+     * @throws MonetDBEmbeddedException If an error in the database occurred
+     */
+    public A fetchColumnValues(int startIndex, int endIndex) throws MonetDBEmbeddedException {
+        int numberOfRowsToRetrieve = this.checkBoundsAndFetch(startIndex, endIndex);
         return this.storeNewDataAndGetResult(startIndex, numberOfRowsToRetrieve);
     }
 
@@ -185,22 +189,10 @@ public abstract class AbstractQueryResul
      * @return If the index is null or not
      */
     public boolean[] checkIfIndexesAreNull(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        if(endIndex < startIndex) {
-            int aux = startIndex;
-            startIndex = endIndex;
-            endIndex = aux;
-        }
-        if (startIndex < 0) {
-            throw new ArrayIndexOutOfBoundsException("The start index must be larger than 0!");
-        } else if (endIndex > this.numberOfRows) {
-            throw new ArrayIndexOutOfBoundsException("The index must be smaller than the number of elements in the columns!");
-        } else if(startIndex == endIndex) {
-            throw new ArrayIndexOutOfBoundsException("Checking 0 values?");
-        }
-        int numberOfRowsToRetrieve = endIndex - startIndex;
-        A values = this.fetchColumnValues(startIndex, endIndex);
+        int numberOfRowsToRetrieve = this.checkBoundsAndFetch(startIndex, endIndex);
         boolean[] res = new boolean[numberOfRowsToRetrieve];
-        return this.checkIfIndexesAreNullImplementation(values, res);
+        System.arraycopy(this.nullValues, startIndex, res, 0, numberOfRowsToRetrieve);
+        return res;
     }
 
     /**
@@ -211,19 +203,7 @@ public abstract class AbstractQueryResul
      * @return The mapped Java array
      */
     public Object[] mapValuesToObjectArray(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        if(endIndex < startIndex) {
-            int aux = startIndex;
-            startIndex = endIndex;
-            endIndex = aux;
-        }
-        if (startIndex < 0) {
-            throw new ArrayIndexOutOfBoundsException("The start index must be larger than 0!");
-        } else if (endIndex > this.numberOfRows) {
-            throw new ArrayIndexOutOfBoundsException("The index must be smaller than the number of elements in the columns!");
-        } else if(startIndex == endIndex) {
-            throw new ArrayIndexOutOfBoundsException("Retrieving 0 values?");
-        }
-        A values = this.fetchColumnValues(startIndex, endIndex);
-        return this.mapValuesToObjectArrayImplementation(values);
+        int numberOfRowsToRetrieve = this.checkBoundsAndFetch(startIndex, endIndex);
+        return this.mapValuesToObjectArrayImplementation(startIndex, numberOfRowsToRetrieve);
     }
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetBooleanColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetBooleanColumn.java
@@ -49,8 +49,7 @@ public final class QueryResultSetBoolean
 
     @Override
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        boolean[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -61,21 +60,11 @@ public final class QueryResultSetBoolean
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(boolean[] values, boolean[] res)
-            throws MonetDBEmbeddedException {
-        boolean nil = GetBooleanNullConstant();
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil);
-        }
-        return res;
-    }
-
-    @Override
-    protected Boolean[] mapValuesToObjectArrayImplementation(boolean[] values) throws MonetDBEmbeddedException {
-        boolean nil = GetBooleanNullConstant();
-        Boolean[] res = new Boolean[values.length];
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil) ? null : values[i];
+    protected Boolean[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        Boolean[] res = new Boolean[numberOfRowsToRetrieve];
+        int endIndex = startIndex + numberOfRowsToRetrieve;
+        for(int i = startIndex, j = 0 ; i < endIndex ; i++, j++) {
+            res[j] = (this.nullValues[i]) ? null : this.values[i];
         }
         return res;
     }
@@ -83,6 +72,6 @@ public final class QueryResultSetBoolean
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native boolean[] fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex)
-            throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex,
+                                            boolean[] values, boolean[] nullValues) throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetByteColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetByteColumn.java
@@ -48,8 +48,7 @@ public final class QueryResultSetByteCol
 
     @Override
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        byte[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -60,21 +59,11 @@ public final class QueryResultSetByteCol
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(byte[] values, boolean[] res)
-            throws MonetDBEmbeddedException {
-        byte nil = GetByteNullConstant();
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil);
-        }
-        return res;
-    }
-
-    @Override
-    protected Byte[] mapValuesToObjectArrayImplementation(byte[] values) throws MonetDBEmbeddedException {
-        byte nil = GetByteNullConstant();
-        Byte[] res = new Byte[values.length];
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil) ? null : values[i];
+    protected Byte[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        Byte[] res = new Byte[numberOfRowsToRetrieve];
+        int endIndex = startIndex + numberOfRowsToRetrieve;
+        for(int i = startIndex, j = 0 ; i < endIndex ; i++, j++) {
+            res[j] = (this.nullValues[i]) ? null : this.values[i];
         }
         return res;
     }
@@ -82,6 +71,6 @@ public final class QueryResultSetByteCol
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native byte[] fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex)
-            throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex,
+                                            byte[] values, boolean[] nullValues) throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetDoubleColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetDoubleColumn.java
@@ -48,8 +48,7 @@ public final class QueryResultSetDoubleC
 
     @Override
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        double[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -60,21 +59,11 @@ public final class QueryResultSetDoubleC
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(double[] values, boolean[] res)
-            throws MonetDBEmbeddedException {
-        double nil = GetDoubleNullConstant();
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil);
-        }
-        return res;
-    }
-
-    @Override
-    protected Double[] mapValuesToObjectArrayImplementation(double[] values) throws MonetDBEmbeddedException {
-        double nil = GetDoubleNullConstant();
-        Double[] res = new Double[values.length];
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil) ? null : values[i];
+    protected Double[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        Double[] res = new Double[numberOfRowsToRetrieve];
+        int endIndex = startIndex + numberOfRowsToRetrieve;
+        for(int i = startIndex, j = 0 ; i < endIndex ; i++, j++) {
+            res[j] = (this.nullValues[i]) ? null : this.values[i];
         }
         return res;
     }
@@ -82,6 +71,6 @@ public final class QueryResultSetDoubleC
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native double[] fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex)
-            throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex,
+                                            double[] values, boolean[] nullValues) throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetFloatColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetFloatColumn.java
@@ -48,8 +48,7 @@ public final class QueryResultSetFloatCo
 
     @Override
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        float[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -60,21 +59,11 @@ public final class QueryResultSetFloatCo
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(float[] values, boolean[] res)
-            throws MonetDBEmbeddedException {
-        float nil = GetFloatNullConstant();
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil);
-        }
-        return res;
-    }
-
-    @Override
-    protected Float[] mapValuesToObjectArrayImplementation(float[] values) throws MonetDBEmbeddedException {
-        float nil = GetFloatNullConstant();
-        Float[] res = new Float[values.length];
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil) ? null : values[i];
+    protected Float[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        Float[] res = new Float[numberOfRowsToRetrieve];
+        int endIndex = startIndex + numberOfRowsToRetrieve;
+        for(int i = startIndex, j = 0 ; i < endIndex ; i++, j++) {
+            res[j] = (this.nullValues[i]) ? null : this.values[i];
         }
         return res;
     }
@@ -82,6 +71,6 @@ public final class QueryResultSetFloatCo
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native float[] fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex)
-            throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex,
+                                            float[] values, boolean[] nullValues) throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetIntColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetIntColumn.java
@@ -48,8 +48,7 @@ public final class QueryResultSetIntColu
 
     @Override
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        int[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -60,21 +59,11 @@ public final class QueryResultSetIntColu
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(int[] values, boolean[] res)
-            throws MonetDBEmbeddedException {
-        int nil = GetIntNullConstant();
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil);
-        }
-        return res;
-    }
-
-    @Override
-    protected Integer[] mapValuesToObjectArrayImplementation(int[] values) throws MonetDBEmbeddedException {
-        int nil = GetIntNullConstant();
-        Integer[] res = new Integer[values.length];
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil) ? null : values[i];
+    protected Integer[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        Integer[] res = new Integer[numberOfRowsToRetrieve];
+        int endIndex = startIndex + numberOfRowsToRetrieve;
+        for(int i = startIndex, j = 0 ; i < endIndex ; i++, j++) {
+            res[j] = (this.nullValues[i]) ? null : this.values[i];
         }
         return res;
     }
@@ -82,6 +71,6 @@ public final class QueryResultSetIntColu
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native int[] fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex)
-            throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex,
+                                            int[] values, boolean[] nullValues) throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetLongColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetLongColumn.java
@@ -48,8 +48,7 @@ public final class QueryResultSetLongCol
 
     @Override
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        long[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -60,21 +59,11 @@ public final class QueryResultSetLongCol
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(long[] values, boolean[] res)
-            throws MonetDBEmbeddedException {
-        long nil = GetLongNullConstant();
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil);
-        }
-        return res;
-    }
-
-    @Override
-    protected Long[] mapValuesToObjectArrayImplementation(long[] values) throws MonetDBEmbeddedException {
-        long nil = GetLongNullConstant();
-        Long[] res = new Long[values.length];
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil) ? null : values[i];
+    protected Long[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        Long[] res = new Long[numberOfRowsToRetrieve];
+        int endIndex = startIndex + numberOfRowsToRetrieve;
+        for(int i = startIndex, j = 0 ; i < endIndex ; i++, j++) {
+            res[j] = (this.nullValues[i]) ? null : this.values[i];
         }
         return res;
     }
@@ -82,6 +71,6 @@ public final class QueryResultSetLongCol
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native long[] fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex)
-            throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex,
+                                            long[] values, boolean[] nullValues) throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetObjectColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetObjectColumn.java
@@ -52,9 +52,8 @@ public final class QueryResultSetObjectC
     @Override
     @SuppressWarnings("unchecked")
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        T[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex,
-                (Class<T>) this.mapping.getJavaClass(), this.mapping.ordinal(), startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, (Class<T>) this.mapping.getJavaClass(),
+                this.mapping.ordinal(), startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -66,16 +65,11 @@ public final class QueryResultSetObjectC
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(T[] values, boolean[] res) throws MonetDBEmbeddedException {
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == null);
-        }
-        return res;
-    }
-
-    @Override
-    protected T[] mapValuesToObjectArrayImplementation(T[] values) throws MonetDBEmbeddedException {
-        return values;
+    @SuppressWarnings("unchecked")
+    protected T[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        T[] result = (T[]) Array.newInstance(this.mapping.getJavaClass(), numberOfRowsToRetrieve);
+        System.arraycopy(this.values, startIndex, result, 0, numberOfRowsToRetrieve);
+        return result;
     }
 
     @Override
@@ -90,6 +84,7 @@ public final class QueryResultSetObjectC
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native T[] fetchValuesInternal(long tablePointer, int resultSetIndex, Class<T> jClass, int javaIndex,
-                                           int startIndex, int endIndex) throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, Class<T> jClass, int javaIndex,
+                                           int startIndex, int endIndex, T[] values, boolean[] nullValues)
+            throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetShortColumn.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetShortColumn.java
@@ -48,8 +48,7 @@ public final class QueryResultSetShortCo
 
     @Override
     protected void fetchMoreData(int startIndex, int endIndex) throws MonetDBEmbeddedException {
-        short[] values = this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex);
-        System.arraycopy(values, 0, this.values, startIndex, values.length);
+        this.fetchValuesInternal(this.tablePointer, this.resultSetIndex, startIndex, endIndex, this.values, this.nullValues);
     }
 
     @Override
@@ -60,21 +59,11 @@ public final class QueryResultSetShortCo
     }
 
     @Override
-    protected boolean[] checkIfIndexesAreNullImplementation(short[] values, boolean[] res)
-            throws MonetDBEmbeddedException {
-        short nil = GetShortNullConstant();
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil);
-        }
-        return res;
-    }
-
-    @Override
-    protected Short[] mapValuesToObjectArrayImplementation(short[] values) throws MonetDBEmbeddedException {
-        short nil = GetShortNullConstant();
-        Short[] res = new Short[values.length];
-        for(int i = 0 ; i < values.length ; i++) {
-            res[i] = (values[i] == nil) ? null : values[i];
+    protected Short[] mapValuesToObjectArrayImplementation(int startIndex, int numberOfRowsToRetrieve) {
+        Short[] res = new Short[numberOfRowsToRetrieve];
+        int endIndex = startIndex + numberOfRowsToRetrieve;
+        for(int i = startIndex, j = 0 ; i < endIndex ; i++, j++) {
+            res[j] = (this.nullValues[i]) ? null : this.values[i];
         }
         return res;
     }
@@ -82,6 +71,6 @@ public final class QueryResultSetShortCo
     /**
      * Internal implementation to fetch values from the column.
      */
-    private native short[] fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex)
-            throws MonetDBEmbeddedException;
+    private native void fetchValuesInternal(long tablePointer, int resultSetIndex, int startIndex, int endIndex,
+                                            short[] values, boolean[] nullValues) throws MonetDBEmbeddedException;
 }
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
@@ -53,13 +53,12 @@ public class JDBCEmbeddedConnection exte
 
     public TableResultHeaders fillTableHeaders(String[] columnNames, int[] columnLengths, String[] types,
                                                String[] tableNames) {
-        this.getNextTableHeaderInternal(this.connectionPointer, this.lastResultSetPointer, columnNames, columnLengths,
-                types, tableNames);
+        this.getNextTableHeaderInternal(this.lastResultSetPointer, columnNames, columnLengths, types, tableNames);
         return TableResultHeaders.ALL;
     }
 
     public int parseTupleLines(int[] typesMap, Object[] values, boolean[][] nulls) {
-        return this.parseTupleLinesInternal(this.connectionPointer, this.lastResultSetPointer, typesMap, values, nulls);
+        return this.parseTupleLinesInternal(this.lastResultSetPointer, typesMap, values, nulls);
     }
 
     public String getLastError() {
@@ -86,11 +85,11 @@ public class JDBCEmbeddedConnection exte
         this.sendCloseCommandInternal(this.connectionPointer, commandId);
     }
 
-    private native void getNextTableHeaderInternal(long connectionPointer, long resultSetPointer, String[] columnNames,
-                                                   int[] columnLengths, String[] types, String[] tableNames);
+    private native void getNextTableHeaderInternal(long resultSetPointer, String[] columnNames, int[] columnLengths,
+                                                   String[] types, String[] tableNames);
 
-    private native int parseTupleLinesInternal(long connectionPointer, long resultSetPointer, int[] typesMap,
-                                               Object[] values, boolean[][] nulls);
+    private native int parseTupleLinesInternal(long resultSetPointer, int[] typesMap, Object[] values,
+                                               boolean[][] nulls);
 
     private native void sendQueryInternal(long connectionPointer, String query, boolean execute);