Add support Java bindings

This add support for Java bindings in the bindings/java directory.
This commit is contained in:
김선우
2025-01-01 21:53:50 +09:00
committed by Pekka Enberg
parent 1c2e074c93
commit 370e1ca5c2
22 changed files with 1253 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
use crate::errors::CustomError;
use jni::objects::{JObject, JValue};
use jni::JNIEnv;
pub(crate) fn row_to_obj_array<'local>(
env: &mut JNIEnv<'local>,
row: &limbo_core::Row,
) -> Result<JObject<'local>, CustomError> {
let obj_array =
env.new_object_array(row.values.len() as i32, "java/lang/Object", JObject::null())?;
for (i, value) in row.values.iter().enumerate() {
let obj = match value {
limbo_core::Value::Null => JObject::null(),
limbo_core::Value::Integer(i) => {
env.new_object("java/lang/Long", "(J)V", &[JValue::Long(*i)])?
}
limbo_core::Value::Float(f) => {
env.new_object("java/lang/Double", "(D)V", &[JValue::Double(*f)])?
}
limbo_core::Value::Text(s) => env.new_string(s)?.into(),
limbo_core::Value::Blob(b) => env.byte_array_from_slice(b)?.into(),
};
if let Err(e) = env.set_object_array_element(&obj_array, i as i32, obj) {
eprintln!("Error on parsing row: {:?}", e);
}
}
Ok(obj_array.into())
}