Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions java/driver/jni/src/main/cpp/jni_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_openDatabase(
error_guard.error);

const jsize num_params = env->GetArrayLength(parameters);
if (env->ExceptionCheck()) return nullptr;
Comment on lines 339 to +340

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will conflict with other changes so let's wait for other PRs first

if (num_params % 2 != 0) {
throw AdbcException{
.code = ADBC_STATUS_INVALID_ARGUMENT,
Expand All @@ -346,8 +347,10 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_openDatabase(
for (jsize i = 0; i < num_params; i += 2) {
// N.B. assuming String because Java side is typed as String[]
auto key = reinterpret_cast<jstring>(env->GetObjectArrayElement(parameters, i));
if (env->ExceptionCheck()) return nullptr;
auto value =
reinterpret_cast<jstring>(env->GetObjectArrayElement(parameters, i + 1));
if (env->ExceptionCheck()) return nullptr;

JniStringView key_str(env, key);
JniStringView value_str(env, value);
Expand Down Expand Up @@ -728,8 +731,10 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_statementGetOptionBytes(
return nullptr;
}
jbyteArray result = env->NewByteArray(static_cast<jsize>(length));
if (result == nullptr || env->ExceptionCheck()) return nullptr;
env->SetByteArrayRegion(result, 0, static_cast<jsize>(length),
reinterpret_cast<const jbyte*>(buf.data()));
if (env->ExceptionCheck()) return nullptr;
return result;
}

Expand Down Expand Up @@ -807,9 +812,11 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_statementSetOptionBytes(
try {
JniStringView key_str(env, key);
jsize value_length = env->GetArrayLength(value);
if (env->ExceptionCheck()) return;
std::vector<uint8_t> value_buf(static_cast<size_t>(value_length));
env->GetByteArrayRegion(value, 0, value_length,
reinterpret_cast<jbyte*>(value_buf.data()));
if (env->ExceptionCheck()) return;
CHECK_ADBC_ERROR(AdbcStatementSetOptionBytes(stmt, key_str.value, value_buf.data(),
value_buf.size(), &error_guard.error),
error_guard.error);
Expand Down Expand Up @@ -905,11 +912,13 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_connectionGetObjects(
const char** c_table_types = nullptr;
if (table_types != nullptr) {
jsize len = env->GetArrayLength(table_types);
if (env->ExceptionCheck()) return nullptr;
table_type_strings.reserve(len);
table_type_ptrs.reserve(len + 1);
for (jsize i = 0; i < len; i++) {
auto element =
reinterpret_cast<jstring>(env->GetObjectArrayElement(table_types, i));
if (env->ExceptionCheck()) return nullptr;
table_type_strings.push_back(GetJniString(env, element));
table_type_ptrs.push_back(table_type_strings.back().c_str());
}
Expand Down Expand Up @@ -948,9 +957,11 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_connectionGetInfo(
std::vector<uint32_t> info_codes_vec;
if (info_codes != nullptr) {
jsize len = env->GetArrayLength(info_codes);
if (env->ExceptionCheck()) return nullptr;
info_codes_vec.resize(len);
env->GetIntArrayRegion(info_codes, 0, len,
reinterpret_cast<jint*>(info_codes_vec.data()));
if (env->ExceptionCheck()) return nullptr;
c_info_codes = info_codes_vec.data();
info_codes_length = static_cast<size_t>(len);
}
Expand Down Expand Up @@ -1041,8 +1052,10 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_connectionGetOptionBytes(
return nullptr;
}
jbyteArray result = env->NewByteArray(static_cast<jsize>(length));
if (result == nullptr || env->ExceptionCheck()) return nullptr;
env->SetByteArrayRegion(result, 0, static_cast<jsize>(length),
reinterpret_cast<const jbyte*>(buf.data()));
if (env->ExceptionCheck()) return nullptr;
return result;
}

Expand Down Expand Up @@ -1120,9 +1133,11 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_connectionSetOptionBytes(
try {
JniStringView key_str(env, key);
jsize value_length = env->GetArrayLength(value);
if (env->ExceptionCheck()) return;
std::vector<uint8_t> value_buf(static_cast<size_t>(value_length));
env->GetByteArrayRegion(value, 0, value_length,
reinterpret_cast<jbyte*>(value_buf.data()));
if (env->ExceptionCheck()) return;
CHECK_ADBC_ERROR(AdbcConnectionSetOptionBytes(conn, key_str.value, value_buf.data(),
value_buf.size(), &error_guard.error),
error_guard.error);
Expand Down Expand Up @@ -1303,8 +1318,10 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_databaseGetOptionBytes(
return nullptr;
}
jbyteArray result = env->NewByteArray(static_cast<jsize>(length));
if (result == nullptr || env->ExceptionCheck()) return nullptr;
env->SetByteArrayRegion(result, 0, static_cast<jsize>(length),
reinterpret_cast<const jbyte*>(buf.data()));
if (env->ExceptionCheck()) return nullptr;
return result;
}

Expand Down Expand Up @@ -1382,9 +1399,11 @@ Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_databaseSetOptionBytes(
try {
JniStringView key_str(env, key);
jsize value_length = env->GetArrayLength(value);
if (env->ExceptionCheck()) return;
std::vector<uint8_t> value_buf(static_cast<size_t>(value_length));
env->GetByteArrayRegion(value, 0, value_length,
reinterpret_cast<jbyte*>(value_buf.data()));
if (env->ExceptionCheck()) return;
CHECK_ADBC_ERROR(AdbcDatabaseSetOptionBytes(db, key_str.value, value_buf.data(),
value_buf.size(), &error_guard.error),
error_guard.error);
Expand Down
Loading