Changeset: 4231a7f5cdc3 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=4231a7f5cdc3
Modified 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
Branch: embedded
Log Message:
Added better null values mapping for JDBC embedded connection compatibility.
The previous potential bug on boolean columns in now fixed
diffs (truncated from 561 to 300 lines):
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/resultset/AbstractQueryResultSetColumn.java
b/src/main/java/nl/cwi/monetdb/embedded/resultset/AbstractQueryResultSetColumn.java
---
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(int
startIndex, int numberOfRowsToRetrieve);
- protected abstract Object[] mapValuesToObjectArrayImplementation(A values)
- throws MonetDBEmbeddedException;
-
- /**
- * 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);
}
}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetBooleanColumn.java
b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetBooleanColumn.java
---
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;
}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetByteColumn.java
b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetByteColumn.java
---
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;
}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetDoubleColumn.java
b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetDoubleColumn.java
---
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;
}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetFloatColumn.java
b/src/main/java/nl/cwi/monetdb/embedded/resultset/QueryResultSetFloatColumn.java
---
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
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list