# HG changeset patch # User Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> # Date 1478195993 -3600 # Node ID 00d88ee561230896ba99d44cff4ecb01cb95c7fd # Parent 38292b17cc8c5da044d36dedb43c41540e3d4088 JNI linking finally working! :D diff --git a/src/main/java/nl/cwi/monetdb/embedded/QueryResultSetColumn.java b/src/main/java/nl/cwi/monetdb/embedded/QueryResultSetColumn.java --- a/src/main/java/nl/cwi/monetdb/embedded/QueryResultSetColumn.java +++ b/src/main/java/nl/cwi/monetdb/embedded/QueryResultSetColumn.java @@ -67,7 +67,6 @@ public class QueryResultSetColumn<T> ext startIndex = endIndex; endIndex = aux; } - int numberOfRowsToRetrieve = endIndex - startIndex; if (startIndex < 0) { throw new ArrayIndexOutOfBoundsException("The start index must be larger than 0!"); } else if (endIndex > this.numberOfRows) { @@ -75,28 +74,29 @@ public class QueryResultSetColumn<T> ext } else if(startIndex == endIndex) { throw new ArrayIndexOutOfBoundsException("Retrieving 0 values?"); } + + boolean hasToConvert = false; + int numberOfRowsToRetrieve = endIndex - startIndex; + int firstIndexToFetch = Math.min(startIndex, this.firstRetrievedIndex); + int lastIndexToFetch = Math.max(endIndex, this.lastRetrievedIndex); if(startIndex < this.firstRetrievedIndex) { + this.firstRetrievedIndex = startIndex; + hasToConvert = true; + } + if(endIndex > this.lastRetrievedIndex) { + this.lastRetrievedIndex = endIndex; + hasToConvert = true; + } + if(hasToConvert) { if(this.resultSetPointer == 0) { throw new MonetDBEmbeddedException("Connection closed!"); } - if(startIndex < this.firstRetrievedIndex) { - T[] new_start_batch = this.fetchValuesInternal(this.resultSetPointer, this.resultSetIndex, - (Class<T>) this.mapping.getJavaClass(), this.mapping.ordinal(), startIndex, this.firstRetrievedIndex); - System.arraycopy(new_start_batch, 0, this.values, startIndex, new_start_batch.length); - this.firstRetrievedIndex = startIndex; - } + T[] newvalues = this.fetchValuesInternal(this.resultSetPointer, this.resultSetIndex, + (Class<T>) this.mapping.getJavaClass(), this.mapping.getJavaClass().getSimpleName(), + this.mapping.ordinal(), firstIndexToFetch, lastIndexToFetch); + System.arraycopy(newvalues, 0, this.values, firstIndexToFetch, newvalues.length); } - if(endIndex > this.lastRetrievedIndex) { - if(this.resultSetPointer == 0) { - throw new MonetDBEmbeddedException("Connection closed!"); - } - if(endIndex > this.lastRetrievedIndex) { - T[] new_end_batch = this.fetchValuesInternal(this.resultSetPointer, this.resultSetIndex, - (Class<T>) this.mapping.getJavaClass(), this.mapping.ordinal(), this.lastRetrievedIndex, endIndex); - System.arraycopy(new_end_batch, 0, this.values, this.lastRetrievedIndex, new_end_batch.length); - this.lastRetrievedIndex = endIndex; - } - } + T[] result = (T[]) Array.newInstance(javaClass, numberOfRowsToRetrieve); System.arraycopy(this.values, startIndex, result, 0, numberOfRowsToRetrieve); return result; @@ -235,7 +235,7 @@ public class QueryResultSetColumn<T> ext return Arrays.asList(this.values).listIterator(); } - private native T[] fetchValuesInternal(long resultPointer, int resultSetIndex, Class<T> jclass, int enumEntry, - int first, int last) throws MonetDBEmbeddedException; + private native T[] fetchValuesInternal(long resultPointer, int resultSetIndex, Class<T> jclass, String className, + int enumEntry, int first, int last) throws MonetDBEmbeddedException; }