Changeset: c224dedd2719 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c224dedd2719 Added Files: tools/embedded/java-package/org_monetdb_embedded_result_EmbeddedQueryResult.c Removed Files: tools/embedded/java-package/other.c tools/embedded/java-package/src/main/java/org/monetdb/embedded/result/QueryResult.java tools/embedded/java-package/src/main/java/org/monetdb/embedded/result/Result.java Modified Files: tools/embedded/java-package/org_monetdb_embedded_MonetDBEmbedded.c tools/embedded/java-package/src/main/java/org/monetdb/embedded/result/column/IntegerColumn.java Branch: embedded-java Log Message:
Add single column retrival (WIP) Clean up old code diffs (truncated from 448 to 300 lines): diff --git a/tools/embedded/java-package/org_monetdb_embedded_MonetDBEmbedded.c b/tools/embedded/java-package/org_monetdb_embedded_MonetDBEmbedded.c --- a/tools/embedded/java-package/org_monetdb_embedded_MonetDBEmbedded.c +++ b/tools/embedded/java-package/org_monetdb_embedded_MonetDBEmbedded.c @@ -24,14 +24,9 @@ JNIEXPORT jint JNICALL Java_org_monetdb_ return monetdb_startup(dir, silent_char); } -/* - * Class: org_monetdb_embedded_MonetDBEmbedded - * Method: query - * Signature: (Ljava/lang/String;)Lorg/monetdb/embedded/result/EmbeddedQueryResult; - */ JNIEXPORT jobject JNICALL Java_org_monetdb_embedded_MonetDBEmbedded_query (JNIEnv *env, jobject object, jstring query) { - res_table* output = NULL; + res_table *output = NULL; const char *query_string = (*env)->GetStringUTFChars(env, query, 0); jobject *result; @@ -115,16 +110,11 @@ JNIEXPORT jobject JNICALL Java_org_monet return result; } -/* - * Class: org_monetdb_embedded_MonetDBLite - * Method: append - * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/reflect/Array;)Ljava/lang/String; - */ JNIEXPORT jstring JNICALL Java_org_monetdb_embedded_MonetDBLite_append (JNIEnv *env, jobject object, jstring schema_name, jstring table_name, jobject data) { const char *schema_name = (*env)->GetStringUTFChars(env, schema, 0); const char *table_name = (*env)->GetStringUTFChars(env, table, 0); + (void)data; - (*env)->ReleaseStringUTFChars(env, string, str); - return (*env)->NewStringUTF(env, strupr(cap)); + return (*env)->NewStringUTF(env, ""); } diff --git a/tools/embedded/java-package/org_monetdb_embedded_result_EmbeddedQueryResult.c b/tools/embedded/java-package/org_monetdb_embedded_result_EmbeddedQueryResult.c new file mode 100644 --- /dev/null +++ b/tools/embedded/java-package/org_monetdb_embedded_result_EmbeddedQueryResult.c @@ -0,0 +1,66 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2008-2015 MonetDB B.V. + */ + +#include "org_monetdb_embedded_result_EmbeddedQueryResult.h" +#include "embedded.h" + +JNIEXPORT jobject JNICALL Java_org_monetdb_embedded_result_EmbeddedQueryResult_getColumnWrapper +(JNIEnv *env, jobject object, jlong resultTablePointer, jint columnIndex) { + // The result table + res_table* result = (res_table *)resultTablePointer; + // Get the column we need + res_col col = output->cols[columnIndex]; + BAT* b = BATdescriptor(col.b); + int size = BATcount(b); + // The values and nulls arrays + jintArray values = (*env)->NewIntArray(env, size); + jbooleanArray nulls = (*env)->NewBooleanArray(env, size); + + jobect *column; + jclass columnClass = (*env)->FindClass(env, "org/monetdb/embedded/result/column/IntegerColumn"); + // from Java IntegerColumn(int[] values, int columnSize, boolean[] nullIndex) + jmethodID columnConstructor = (*env)->GetMethodID(env, columnClass, "<init>", "([II[Z)V"); + + int i = 0; + int val_tmp[size]; + jboolean nul_tmp[size]; + if (b->T->nonil && !b->T->nil) { + for (i = 0; i < size; i++) { + val_tmp[i] = (int) ((int*) Tloc(b, BUNfirst(b)))[i]; + } + } + else { + for (i = 0; i < size; i++) { + int v = ((int*) Tloc(b, BUNfirst(b)))[i]; + if (v == int##_nil) { + val_tmp[i] = 0; + nul_tmp = JNI_TRUE; + + } else { + val_tmp[i] = (int)v; + nul_tmp = JNI_FALSE; + } + } + } + // Move from the tmp C arrays to a Java arrays + (*env)->SetIntArrayRegion(env, values, 0, size, val_tmp); + (*env)->SetBooleanArrayRegion(env, nulls, 0, size, nul_tmp); + + // Create the column object + // from Java IntegerColumn(int[] values, int columnSize, boolean[] nullIndex) + result = (*env)->NewObject(env, columnClass, columnConstructor, values, size, nulls); + + return column; +} + +JNIEXPORT void JNICALL Java_org_monetdb_embedded_result_EmbeddedQueryResult_cleanupResult +(JNIEnv *env, jobject object, jlong resultTablePointer) { + res_table* result = (res_table *)resultTablePointer; + + monetdb_cleanup_result(result); +} diff --git a/tools/embedded/java-package/other.c b/tools/embedded/java-package/other.c deleted file mode 100644 --- a/tools/embedded/java-package/other.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Copyright 2008-2015 MonetDB B.V. - */ - -#include "org_monetdb_embedded_MonetDBEmbedded.h" -#include "embedded.h" -#include "gdk.h" - -/* - * Class: org_monetdb_embedded_MonetDBEmbedded - * Method: query - * Signature: (Ljava/lang/String;)Lorg/monetdb/embedded/result/EmbeddedQueryResult; - */ -JNIEXPORT jobject JNICALL Java_org_monetdb_embedded_MonetDBEmbedded_query -(JNIEnv *, jobject, jstring) { - const char *query_string = (*env)->GetStringUTFChars(env, query, 0); - res_table* output = NULL; - jobjectArray *result; - jclass resultClass = (*env)->FindClass(env, "org/monetdb/embedded/Result"); - - // In case we cant find the result object class - if (resultClass == NULL) { - return NULL; - } - - char* err = monetdb_query(query_string, (void**)&output); - // Release the query string - (*env)->ReleaseStringUTFChars(env, query, query_string); - - if (err != NULL) { - jclass exClass = (*env)->FindClass(env, "java/sql/SQLException"); - - // Clean up the result data - monetdb_cleanup_result(output); - if (exClass == NULL) { - // Cloud not find the exception class, just return empty object - return NULL; - } - return (*env)->ThrowNew(env, exClass, err); - } - - // Create the result object - result = (*env)->NewObjectArray(env, output->nr_cols, resultClass, NULL); - if (output && output->nr_cols > 0) { - int i; - for (i = 0; i < output->nr_cols; i++) { - res_col col = output->cols[i]; - BAT* b = BATdescriptor(col.b); - char *type_string; - int size = BATcount(b); - int j = 0; - jobject *array; - jclass arrayClass = (*env)->FindClass(env, "java/lang/reflect/Array"); - - // Set the Java array, depending on its type - varvalue = bat_to_sexp(b); - if (varvalue == NULL) { - switch (ATOMstorage(getColumnType(b->T->type))) { - case TYPE_int: - type_string = "integer"; - jintArray array = (*env)->NewIntArray(env, size); - for (j = 0; j < size; i++) { - b-> - } - // move from the temp structure to the java structure - (*env)->SetIntArrayRegion(env, result, 0, size, fill); - break; - case TYPE_lng: - break; - default: - } - // Set the meta fields in the result object - jstring name = (jstring)(*env)->NewStringUTF(env, col.name); - jstring type = (jstring)(*env)->NewStringUTF(env, type_string); - - // Construct a single result object - jmethodID resultConstructor = (*env)->GetMethodID(env, resultClass, "<init>", "([L;LJAVA/LANG/STRING;LJAVA/LANG/STRING)V"); - jobject resultObject = (*env)->NewObject(env, resultClass, resultConstructor, array, name, type); - - // Add the result object to the result array - (*env)->SetObjectArrayElement(env, result, i, resultObject); - } - return result; - } - return result; - } -} - -JNIEXPORT jobject JNICALL Java_org_monetdb_embedded_MonetDBEmbedded_query -(JNIEnv *, jobject, jstring) { - jintArray array = (*env)->NewIntArray(env, size); - - BAT* b = BATdescriptor(col.b); - int size = BATcount(b); - - int i = 0; - int tmp[size]; - if (b->T->nonil && !b->T->nil) { - for (i = 0; i < size; i++) { - tmp[i] = (int) ((int*) Tloc(b, BUNfirst(b)))[i]; - } - } - // else { - // for (i = 0; i < size; i++) { - // int v = ((int*) Tloc(b, BUNfirst(b)))[i]; - // if (v == int##_nil) { - // tmp[i] = naval; - // } else { - // tmp[i] = (int)v; - // } - // } - // } - - // Move from the tmp C array to a Java array - (*env)->SetIntArrayRegion(env, array, 0, size, tmp); - return array; -} - -/* - * Class: org_monetdb_embedded_MonetDBLite - * Method: append - * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/reflect/Array;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_monetdb_embedded_MonetDBLite_append -(JNIEnv *env, jobject object, jstring schema_name, jstring table_name, jobject data) { - const char *schema_name = (*env)->GetStringUTFChars(env, schema, 0); - const char *table_name = (*env)->GetStringUTFChars(env, table, 0); - - (*env)->ReleaseStringUTFChars(env, string, str); - return (*env)->NewStringUTF(env, strupr(cap)); -} diff --git a/tools/embedded/java-package/src/main/java/org/monetdb/embedded/result/QueryResult.java b/tools/embedded/java-package/src/main/java/org/monetdb/embedded/result/QueryResult.java deleted file mode 100644 --- a/tools/embedded/java-package/src/main/java/org/monetdb/embedded/result/QueryResult.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Copyright 2008-2015 MonetDB B.V. - */ - -package org.monetdb.embedded.result; - -import java.io.Closeable; -import java.io.IOException; -import java.lang.reflect.Array; -import java.sql.Blob; -import java.sql.SQLException; -import java.sql.Timestamp; - -public class QueryResult implements Closeable { - private Array[] columns; - private String[] columnNames; - private String[] columnTypes; - - /** - * Returns the number of columns in a result set. - * - * @return Number of columns - */ - public int numberOfColumns() { - return columns.length; - } - - /** - * Get a column from the result set by index. - * - * @param id Column index (starting from 0) - * @return The columns as an array, {@code null} if index not in bounds - * @throws SQLException - */ - public Array getColumn(int index) throws SQLException, IndexOutOfBoundsException { - if (index < 0 || index >= columns.length) { - return null; - } - return getColumn(columns[index], columnTypes[index]); - } - - /** _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list