};
/*
+ * Class: org_ejdb_driver_EJDB
+ * Method: syncDB
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDB_syncDB
+ (JNIEnv *env, jobject obj) {
+ jclass clazz = (*env)->GetObjectClass(env, obj);
+ jfieldID dbpID = (*env)->GetFieldID(env, clazz, "dbPointer", "J");
+ jlong dbp = (*env)->GetLongField(env, obj, dbpID);
+
+ // todo: check null?
+ EJDB* db = (EJDB*)dbp;
+
+ return ejdbsyncdb(db);
+};
+
+/*
* Class: org_ejdb_driver_EJDBCollection
- * Method: ensureCollectionDB
+ * Method: ensureDB
* Signature: (Ljava/lang/Object;)Z
*/
-JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_ensureCollectionDB
+JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_ensureDB
(JNIEnv *env, jobject obj, jobject opts) {
jclass clazz = (*env)->GetObjectClass(env, obj);
jfieldID dbpID = (*env)->GetFieldID(env, clazz, "dbPointer", "J");
/*
* Class: org_ejdb_driver_EJDBCollection
- * Method: dropCollectionDB
+ * Method: dropDB
* Signature: (Z)Z
*/
-JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_dropCollectionDB
+JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_dropDB
(JNIEnv *env, jobject obj, jboolean prune) {
jclass clazz = (*env)->GetObjectClass(env, obj);
jfieldID dbpID = (*env)->GetFieldID(env, clazz, "dbPointer", "J");
/*
* Class: org_ejdb_driver_EJDBCollection
+ * Method: syncDB
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_syncDB
+ (JNIEnv *env, jobject obj) {
+ jclass clazz = (*env)->GetObjectClass(env, obj);
+ jfieldID dbpID = (*env)->GetFieldID(env, clazz, "dbPointer", "J");
+ jlong dbp = (*env)->GetLongField(env, obj, dbpID);
+
+ // todo: check null?
+ EJDB* db = (EJDB*)dbp;
+
+ jfieldID colnameID = (*env)->GetFieldID(env, clazz, "cname", "Ljava/lang/String;");
+ jstring colname = (*env)->GetObjectField(env, obj, colnameID);
+
+ const char *cname;
+ cname = (*env)->GetStringUTFChars(env, colname, NULL);
+
+ EJCOLL * coll = ejdbgetcoll(db, cname);
+ bool status = ejdbsyncoll(coll);
+
+ (*env)->ReleaseStringUTFChars(env, colname, cname);
+
+ return status ? JNI_TRUE : JNI_FALSE;
+};
+
+/*
+ * Class: org_ejdb_driver_EJDBCollection
* Method: loadDB
* Signature: ([B)Ljava/lang/Object;
*/
EJCOLL * coll = ejdbgetcoll(db, cname);
bson *bson = bson_create_from_buffer(bdata, blength);
- bool ss = ejdbsavebson(coll, bson, &oid);
+ bool status = ejdbsavebson(coll, bson, &oid);
bson_del(bson);
(*env)->ReleaseStringUTFChars(env, colname, cname);
(*env)->ReleaseByteArrayElements(env, objdata, bdata, 0);
- if (!ss) {
- // todo: error
+ if (!status) {
+ // todo: error?
return NULL;
}
// todo: check
EJCOLL * coll = ejdbgetcoll(db, cname);
- bool rs = ejdbrmbson(coll, oid);
+ bool status = ejdbrmbson(coll, oid);
(*env)->ReleaseStringUTFChars(env, colname, cname);
(*env)->ReleaseByteArrayElements(env, oidArray, (jbyte*)oid, 0);
- return rs ? JNI_TRUE : JNI_FALSE;
+ return status ? JNI_TRUE : JNI_FALSE;
}
#endif
/*
* Class: org_ejdb_driver_EJDBCollection
- * Method: ensureCollectionDB
+ * Method: ensureDB
* Signature: (Ljava/lang/Object;)Z
*/
-JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_ensureCollectionDB
+JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_ensureDB
(JNIEnv *, jobject, jobject);
/*
* Class: org_ejdb_driver_EJDBCollection
- * Method: dropCollectionDB
+ * Method: dropDB
* Signature: (Z)Z
*/
-JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_dropCollectionDB
+JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_dropDB
(JNIEnv *, jobject, jboolean);
/*
* Class: org_ejdb_driver_EJDBCollection
+ * Method: syncDB
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_ejdb_driver_EJDBCollection_syncDB
+ (JNIEnv *, jobject);
+
+/*
+ * Class: org_ejdb_driver_EJDBCollection
* Method: loadDB
* Signature: ([B)Ljava/lang/Object;
*/
}
// todo: bson object for options
- protected native boolean ensureCollectionDB(Object opts);
- protected native boolean dropCollectionDB(boolean prune);
+ protected native boolean ensureDB(Object opts);
+ protected native boolean dropDB(boolean prune);
+ protected native boolean syncDB();
protected native Object loadDB(byte[] oid);
protected native Object saveDB(byte[] objdata);
}
public boolean ensureExists(Object opts) {
- return this.ensureCollectionDB(opts);
+ return this.ensureDB(opts);
}
public boolean drop() {
}
public boolean drop(boolean prune) {
- return this.dropCollectionDB(prune);
+ return this.dropDB(prune);
}
+ public boolean sync() {
+ return this.syncDB();
+ }
public BSONObject load(ObjectId oid) {
return (BSONObject) this.loadDB(oid.toByteArray());