-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d08886
commit f2f1cbd
Showing
16 changed files
with
334 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.surrealdb; | ||
|
||
public class Id implements AutoCloseable { | ||
|
||
private long id; | ||
|
||
Id(long id) { | ||
this.id = id; | ||
} | ||
|
||
private static native boolean deleteInstance(long id); | ||
|
||
private static native boolean isLong(long id); | ||
|
||
private static native long getLong(long id); | ||
|
||
private static native boolean isString(long id); | ||
|
||
private static native String getString(long id); | ||
|
||
private static native boolean isArray(long id); | ||
|
||
private static native Array getArray(long id); | ||
|
||
private static native boolean isObject(long id); | ||
|
||
private static native Object getObject(long id); | ||
|
||
@Override | ||
public void close() { | ||
deleteInstance(id); | ||
id = 0; | ||
} | ||
|
||
@Override | ||
protected void finalize() throws Throwable { | ||
try { | ||
close(); | ||
} finally { | ||
super.finalize(); | ||
} | ||
} | ||
|
||
public boolean isLong() { | ||
return isLong(id); | ||
} | ||
|
||
public long getLong() { | ||
return getLong(id); | ||
} | ||
|
||
public boolean isString() { | ||
return isString(id); | ||
} | ||
|
||
public String getString() { | ||
return getString(id); | ||
} | ||
|
||
public boolean isArray() { | ||
return isArray(id); | ||
} | ||
|
||
public Array getArray() { | ||
return getArray(id); | ||
} | ||
|
||
public boolean isObject() { | ||
return isObject(id); | ||
} | ||
|
||
public Object getObject() { | ||
return getObject(id); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
use std::ptr::null_mut; | ||
use std::sync::Arc; | ||
|
||
use jni::JNIEnv; | ||
use jni::objects::JClass; | ||
use jni::sys::{jboolean, jlong, jstring}; | ||
use surrealdb::sql::{Id, Value}; | ||
|
||
use crate::{create_instance, get_value_instance, new_string}; | ||
use crate::error::SurrealError; | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_isLong<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jboolean { | ||
let value = get_value_instance!(&mut env, id, ||false as jboolean); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::Number(_) = &o.id { | ||
true as jboolean | ||
} else { | ||
false as jboolean | ||
} | ||
} else { | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || false as jboolean) | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_getLong<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jlong { | ||
let value = get_value_instance!(&mut env, id, ||0); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::Number(i) = &o.id { | ||
return *i as jlong; | ||
} | ||
} | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || 0) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_isString<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jboolean { | ||
let value = get_value_instance!(&mut env, id, ||false as jboolean); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::String(_) = &o.id { | ||
true as jboolean | ||
} else { | ||
false as jboolean | ||
} | ||
} else { | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || false as jboolean) | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_getString<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jstring { | ||
let value = get_value_instance!(&mut env, id, ||null_mut()); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::String(s) = &o.id { | ||
new_string!(&mut env, s, ||null_mut()) | ||
} | ||
} | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || null_mut()) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_isObject<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jboolean { | ||
let value = get_value_instance!(&mut env, id, ||false as jboolean); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::Object(_) = &o.id { | ||
true as jboolean | ||
} else { | ||
false as jboolean | ||
} | ||
} else { | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || false as jboolean) | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_getObject<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jlong { | ||
let value = get_value_instance!(&mut env, id, ||0); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::Object(o) = &o.id { | ||
//TODO no clone? | ||
return create_instance(Arc::new(Value::Object(o.clone()))); | ||
} | ||
} | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || 0) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_isArray<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jboolean { | ||
let value = get_value_instance!(&mut env, id, ||false as jboolean); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::Array(_) = &o.id { | ||
true as jboolean | ||
} else { | ||
false as jboolean | ||
} | ||
} else { | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || false as jboolean) | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "system" fn Java_com_surrealdb_Id_getArray<'local>( | ||
mut env: JNIEnv<'local>, | ||
_class: JClass<'local>, | ||
id: jlong, | ||
) -> jlong { | ||
let value = get_value_instance!(&mut env, id, ||0); | ||
if let Value::Thing(o) = value.as_ref() { | ||
if let Id::Array(a) = &o.id { | ||
//TODO no clone? | ||
return create_instance(Arc::new(Value::Array(a.clone()))); | ||
} | ||
} | ||
SurrealError::NullPointerException("Thing").exception(&mut env, || 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.