jni: Step #1 of simplified Syncbase API transition
MultiPart: 2/7
Change-Id: Ia35edfdc91a88ae054d18dfa5b8e96554c530d99
diff --git a/impl/google/services/jni.go b/impl/google/services/jni.go
index c49304f..4ef77a1 100644
--- a/impl/google/services/jni.go
+++ b/impl/google/services/jni.go
@@ -9,7 +9,8 @@
import (
jgroups "v.io/x/jni/impl/google/services/groups"
jmounttable "v.io/x/jni/impl/google/services/mounttable"
- jsyncbase "v.io/x/jni/impl/google/services/syncbase"
+ // See TODO below.
+ //jsyncbase "v.io/x/jni/impl/google/services/syncbase"
jutil "v.io/x/jni/util"
)
@@ -26,8 +27,12 @@
if err := jmounttable.Init(env); err != nil {
return err
}
- if err := jsyncbase.Init(env); err != nil {
- return err
- }
+ // TODO(sadovsky): Temporarily disable Syncbase Java code (as of 2016-03-28),
+ // while we update the code to the simplified API.
+ /*
+ if err := jsyncbase.Init(env); err != nil {
+ return err
+ }
+ */
return nil
}
diff --git a/v23/jni.go b/v23/jni.go
index 40d431f..f658aa6 100644
--- a/v23/jni.go
+++ b/v23/jni.go
@@ -14,7 +14,8 @@
jsecurity "v.io/x/jni/v23/security"
jaccess "v.io/x/jni/v23/security/access"
jgroups "v.io/x/jni/v23/services/groups"
- jnosql "v.io/x/jni/v23/syncbase/nosql"
+ // See TODO below.
+ //jsyncbase "v.io/x/jni/v23/syncbase"
)
// #include "jni.h"
@@ -42,8 +43,12 @@
if err := jgroups.Init(env); err != nil {
return err
}
- if err := jnosql.Init(env); err != nil {
- return err
- }
+ // TODO(sadovsky): Temporarily disable Syncbase Java code (as of 2016-03-28),
+ // while we update the code to the simplified API.
+ /*
+ if err := jsyncbase.Init(env); err != nil {
+ return err
+ }
+ */
return nil
}
diff --git a/v23/syncbase/nosql/jni.go b/v23/syncbase/jni.go
similarity index 68%
rename from v23/syncbase/nosql/jni.go
rename to v23/syncbase/jni.go
index 8710a7d..01d04f8 100644
--- a/v23/syncbase/nosql/jni.go
+++ b/v23/syncbase/jni.go
@@ -4,13 +4,13 @@
// +build java android
-package nosql
+package syncbase
import (
"unsafe"
- wire "v.io/v23/services/syncbase/nosql"
- "v.io/v23/syncbase/nosql"
+ wire "v.io/v23/services/syncbase"
+ "v.io/v23/syncbase"
jutil "v.io/x/jni/util"
jcontext "v.io/x/jni/v23/context"
@@ -20,15 +20,15 @@
import "C"
var (
- // Global reference for io.v.v23.syncbase.nosql.DatabaseImpl class.
+ // Global reference for io.v.v23.syncbase.DatabaseImpl class.
jDatabaseImplClass jutil.Class
- // Global reference for io.v.v23.syncbase.nosql.Conflict class.
+ // Global reference for io.v.v23.syncbase.Conflict class.
jConflictClass jutil.Class
- // Global reference for io.v.v23.syncbase.nosql.Resolution class.
+ // Global reference for io.v.v23.syncbase.Resolution class.
jResolutionClass jutil.Class
- // Global reference for io.v.v23.services.syncbase.nosql.BatchOptions class.
+ // Global reference for io.v.v23.services.syncbase.BatchOptions class.
jBatchOptionsClass jutil.Class
- // Global reference for io.v.v23.services.syncbase.nosql.SchemaMetadata class.
+ // Global reference for io.v.v23.services.syncbase.SchemaMetadata class.
jSchemaMetadataClass jutil.Class
)
@@ -37,31 +37,31 @@
// from the main Java thread (e.g., On_Load()).
func Init(env jutil.Env) error {
var err error
- jDatabaseImplClass, err = jutil.JFindClass(env, "io/v/v23/syncbase/nosql/DatabaseImpl")
+ jDatabaseImplClass, err = jutil.JFindClass(env, "io/v/v23/syncbase/DatabaseImpl")
if err != nil {
return err
}
- jConflictClass, err = jutil.JFindClass(env, "io/v/v23/syncbase/nosql/Conflict")
+ jConflictClass, err = jutil.JFindClass(env, "io/v/v23/syncbase/Conflict")
if err != nil {
return err
}
- jResolutionClass, err = jutil.JFindClass(env, "io/v/v23/syncbase/nosql/Resolution")
+ jResolutionClass, err = jutil.JFindClass(env, "io/v/v23/syncbase/Resolution")
if err != nil {
return err
}
- jBatchOptionsClass, err = jutil.JFindClass(env, "io/v/v23/services/syncbase/nosql/BatchOptions")
+ jBatchOptionsClass, err = jutil.JFindClass(env, "io/v/v23/services/syncbase/BatchOptions")
if err != nil {
return err
}
- jSchemaMetadataClass, err = jutil.JFindClass(env, "io/v/v23/services/syncbase/nosql/SchemaMetadata")
+ jSchemaMetadataClass, err = jutil.JFindClass(env, "io/v/v23/services/syncbase/SchemaMetadata")
if err != nil {
return err
}
return nil
}
-//export Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeCreate
-func Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeCreate(jenv *C.JNIEnv, jDatabaseImplClass C.jclass, jParentFullName C.jstring, jRelativeName C.jstring, jSchemaObj C.jobject) C.jobject {
+//export Java_io_v_v23_syncbase_DatabaseImpl_nativeCreate
+func Java_io_v_v23_syncbase_DatabaseImpl_nativeCreate(jenv *C.JNIEnv, jDatabaseImplClass C.jclass, jParentFullName C.jstring, jRelativeName C.jstring, jSchemaObj C.jobject) C.jobject {
env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
parentFullName := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jParentFullName))))
relativeName := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jRelativeName))))
@@ -71,7 +71,7 @@
jutil.JThrowV(env, err)
return nil
}
- db := nosql.NewDatabase(parentFullName, relativeName, schema)
+ db := syncbase.NewDatabase(parentFullName, relativeName, schema)
jdb := newJNIDatabase(env, db, parentFullName, schema, jSchema)
jDatabase, err := javaDatabase(env, jdb)
if err != nil {
@@ -81,8 +81,8 @@
return C.jobject(unsafe.Pointer(jDatabase))
}
-//export Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeBeginBatch
-func Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeBeginBatch(jenv *C.JNIEnv, jDatabaseImpl C.jobject, goRef C.jlong, jContext C.jobject, jBatchOptsObj C.jobject, jCallbackObj C.jobject) {
+//export Java_io_v_v23_syncbase_DatabaseImpl_nativeBeginBatch
+func Java_io_v_v23_syncbase_DatabaseImpl_nativeBeginBatch(jenv *C.JNIEnv, jDatabaseImpl C.jobject, goRef C.jlong, jContext C.jobject, jBatchOptsObj C.jobject, jCallbackObj C.jobject) {
env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj)))
jBatchOpts := jutil.Object(uintptr(unsafe.Pointer(jBatchOptsObj)))
@@ -114,8 +114,8 @@
})
}
-//export Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeEnforceSchema
-func Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeEnforceSchema(jenv *C.JNIEnv, jDatabaseImpl C.jobject, goRef C.jlong, jContext C.jobject, jCallbackObj C.jobject) {
+//export Java_io_v_v23_syncbase_DatabaseImpl_nativeEnforceSchema
+func Java_io_v_v23_syncbase_DatabaseImpl_nativeEnforceSchema(jenv *C.JNIEnv, jDatabaseImpl C.jobject, goRef C.jlong, jContext C.jobject, jCallbackObj C.jobject) {
env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj)))
jdb := (*jniDatabase)(jutil.GoRefValue(jutil.Ref(goRef)))
@@ -129,7 +129,7 @@
})
}
-//export Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeFinalize
-func Java_io_v_v23_syncbase_nosql_DatabaseImpl_nativeFinalize(jenv *C.JNIEnv, jDatabaseImpl C.jobject, goRef C.jlong) {
+//export Java_io_v_v23_syncbase_DatabaseImpl_nativeFinalize
+func Java_io_v_v23_syncbase_DatabaseImpl_nativeFinalize(jenv *C.JNIEnv, jDatabaseImpl C.jobject, goRef C.jlong) {
jutil.GoDecRef(jutil.Ref(goRef))
}
diff --git a/v23/syncbase/nosql/resolver.go b/v23/syncbase/resolver.go
similarity index 80%
rename from v23/syncbase/nosql/resolver.go
rename to v23/syncbase/resolver.go
index a0d2114..509341a 100644
--- a/v23/syncbase/nosql/resolver.go
+++ b/v23/syncbase/resolver.go
@@ -4,20 +4,21 @@
// +build java android
-package nosql
+package syncbase
import (
"runtime"
"v.io/v23/context"
- "v.io/v23/syncbase/nosql"
+ "v.io/v23/syncbase"
jutil "v.io/x/jni/util"
jcontext "v.io/x/jni/v23/context"
)
-// GoResolver converts a provided Java ConflictResolver into a Go ConflictResolver.
-func GoResolver(env jutil.Env, jResolver jutil.Object) nosql.ConflictResolver {
+// GoResolver converts a provided Java ConflictResolver into a Go
+// ConflictResolver.
+func GoResolver(env jutil.Env, jResolver jutil.Object) syncbase.ConflictResolver {
if jResolver.IsNull() {
return nil
}
@@ -40,7 +41,7 @@
jResolver jutil.Object
}
-func (r *jniResolver) OnConflict(ctx *context.T, conflict *nosql.Conflict) nosql.Resolution {
+func (r *jniResolver) OnConflict(ctx *context.T, conflict *syncbase.Conflict) syncbase.Resolution {
env, freeFunc := jutil.GetEnv()
defer freeFunc()
jContext, err := jcontext.JavaContext(env, ctx, nil)
@@ -52,13 +53,13 @@
panic("Couldn't create Java Conflict object: " + err.Error())
}
contextSign := jutil.ClassSign("io.v.v23.context.VContext")
- conflictSign := jutil.ClassSign("io.v.v23.syncbase.nosql.Conflict")
- resolutionSign := jutil.ClassSign("io.v.v23.syncbase.nosql.Resolution")
+ conflictSign := jutil.ClassSign("io.v.v23.syncbase.Conflict")
+ resolutionSign := jutil.ClassSign("io.v.v23.syncbase.Resolution")
jResolution, err := jutil.CallObjectMethod(env, r.jResolver, "onConflict", []jutil.Sign{contextSign, conflictSign}, resolutionSign, jContext, jConflict)
if err != nil {
panic("Error invoking Java ConflictResolver: " + err.Error())
}
- var resolution nosql.Resolution
+ var resolution syncbase.Resolution
if err := jutil.GoVomCopy(env, jResolution, jResolutionClass, &resolution); err != nil {
panic("Couldn't create Go Resolution: " + err.Error())
}
diff --git a/v23/syncbase/nosql/util.go b/v23/syncbase/util.go
similarity index 70%
rename from v23/syncbase/nosql/util.go
rename to v23/syncbase/util.go
index 74db874..d8ff179 100644
--- a/v23/syncbase/nosql/util.go
+++ b/v23/syncbase/util.go
@@ -4,25 +4,25 @@
// +build java android
-package nosql
+package syncbase
import (
"runtime"
- wire "v.io/v23/services/syncbase/nosql"
- "v.io/v23/syncbase/nosql"
+ wire "v.io/v23/services/syncbase"
+ "v.io/v23/syncbase"
jutil "v.io/x/jni/util"
)
type jniDatabase struct {
- nosql.Database
+ syncbase.Database
parentFullName string
- schema *nosql.Schema
+ schema *syncbase.Schema
jSchema jutil.Object
}
-func newJNIDatabase(env jutil.Env, db nosql.Database, parentFullName string, schema *nosql.Schema, jSchema jutil.Object) *jniDatabase {
+func newJNIDatabase(env jutil.Env, db syncbase.Database, parentFullName string, schema *syncbase.Schema, jSchema jutil.Object) *jniDatabase {
// Reference Java schema; it will be de-referenced when the Go database
// created below is garbage-collected (through the finalizer callback we
// setup just below).
@@ -42,7 +42,7 @@
}
func javaDatabase(env jutil.Env, jdb *jniDatabase) (jutil.Object, error) {
- schemaSign := jutil.ClassSign("io.v.v23.syncbase.nosql.Schema")
+ schemaSign := jutil.ClassSign("io.v.v23.syncbase.Schema")
ref := jutil.GoNewRef(jdb) // Un-refed when jDatabase is finalized
jDatabase, err := jutil.NewObject(env, jDatabaseImplClass, []jutil.Sign{jutil.LongSign, jutil.StringSign, jutil.StringSign, jutil.StringSign, schemaSign}, int64(ref), jdb.parentFullName, jdb.FullName(), jdb.Name(), jdb.jSchema)
if err != nil {
@@ -52,17 +52,18 @@
return jDatabase, nil
}
-func javaBatchDatabase(env jutil.Env, batchDB nosql.BatchDatabase, parentFullName string, jSchema jutil.Object) (jutil.Object, error) {
- schemaSign := jutil.ClassSign("io.v.v23.syncbase.nosql.Schema")
+func javaBatchDatabase(env jutil.Env, batchDB syncbase.BatchDatabase, parentFullName string, jSchema jutil.Object) (jutil.Object, error) {
+ schemaSign := jutil.ClassSign("io.v.v23.syncbase.Schema")
return jutil.NewObject(env, jDatabaseImplClass, []jutil.Sign{jutil.LongSign, jutil.StringSign, jutil.StringSign, jutil.StringSign, schemaSign}, 0, parentFullName, batchDB.FullName(), batchDB.Name(), jSchema)
}
-// GoSchema converts the provided Java Schema object into a Go nosql.Schema type.
-func GoSchema(env jutil.Env, jSchema jutil.Object) (*nosql.Schema, error) {
+// GoSchema converts the provided Java Schema object into a Go syncbase.Schema
+// type.
+func GoSchema(env jutil.Env, jSchema jutil.Object) (*syncbase.Schema, error) {
if jSchema.IsNull() {
return nil, nil
}
- metadataSign := jutil.ClassSign("io.v.v23.services.syncbase.nosql.SchemaMetadata")
+ metadataSign := jutil.ClassSign("io.v.v23.services.syncbase.SchemaMetadata")
jMetadata, err := jutil.CallObjectMethod(env, jSchema, "getMetadata", nil, metadataSign)
if err != nil {
return nil, err
@@ -71,13 +72,13 @@
if err := jutil.GoVomCopy(env, jMetadata, jSchemaMetadataClass, &metadata); err != nil {
return nil, err
}
- resolverSign := jutil.ClassSign("io.v.v23.syncbase.nosql.ConflictResolver")
+ resolverSign := jutil.ClassSign("io.v.v23.syncbase.ConflictResolver")
jResolver, err := jutil.CallObjectMethod(env, jSchema, "getResolver", nil, resolverSign)
if err != nil {
return nil, err
}
resolver := GoResolver(env, jResolver)
- return &nosql.Schema{
+ return &syncbase.Schema{
Metadata: metadata,
Resolver: resolver,
}, nil