Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Stitch and Realm SDKs - 1: scaffolding #6804

Merged
merged 13 commits into from
May 1, 2020
Merged
1 change: 1 addition & 0 deletions realm/realm-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ dependencies {
implementation('io.reactivex.rxjava2:rxandroid:2.1.1') {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
}
implementation "com.google.android.gms:play-services-tasks:17.0.2" // added to support mongo client's asynchronous nature without breaking Stitch's API
edualonso marked this conversation as resolved.
Show resolved Hide resolved

// TODO: investigate why we can't use the latest multidex version
// check baseDebugAndroidTestRuntimeClasspath and objectServerDebugAndroidTestRuntimeClasspath
Expand Down
9 changes: 8 additions & 1 deletion realm/realm-library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ if (build_SYNC)
io.realm.internal.objectstore.OsAsyncOpenTask
io.realm.internal.objectstore.OsJavaNetworkTransport
io.realm.internal.objectstore.OsSyncUser
io.realm.internal.objectstore.OsRemoteMongoClient
edualonso marked this conversation as resolved.
Show resolved Hide resolved
io.realm.internal.objectstore.OsRemoteMongoDatabase
io.realm.internal.objectstore.OsRemoteMongoCollection
)
endif()
create_javah(TARGET jni_headers
Expand Down Expand Up @@ -204,6 +207,9 @@ if (NOT build_SYNC)
${CMAKE_CURRENT_SOURCE_DIR}/io_realm_internal_objectstore_OsAsyncOpenTask.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io_realm_internal_objectstore_OsAppCredentials.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io_realm_internal_objectstore_OsSyncUser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io_realm_internal_objectstore_OsRemoteMongoClient.cpp
edualonso marked this conversation as resolved.
Show resolved Hide resolved
${CMAKE_CURRENT_SOURCE_DIR}/io_realm_internal_objectstore_OsRemoteMongoDatabase.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io_realm_internal_objectstore_OsRemoteMongoCollection.cpp
)
endif()

Expand All @@ -222,7 +228,8 @@ if (build_SYNC)
"object-store/src/results.cpp"
"object-store/src/impl/results_notifier.cpp"
"object-store/src/sync/*.cpp"
"object-store/src/sync/impl/*.cpp")
"object-store/src/sync/impl/*.cpp"
"object-store/src/util/bson/*.cpp")
endif()

add_library(realm-jni SHARED ${jni_SRC} ${objectstore_SRC} ${objectstore_sync_SRC})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2020 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "io_realm_internal_objectstore_OsRemoteMongoClient.h"

#include "java_class_global_def.hpp"
#include "java_network_transport.hpp"
#include "util.hpp"
#include "jni_util/java_method.hpp"
#include "jni_util/jni_utils.hpp"

#include <realm/util/optional.hpp>
#include <sync/app.hpp>
#include <sync/sync_user.hpp>
#include <sync/remote_mongo_client.hpp>
#include <sync/remote_mongo_database.hpp>

using namespace realm;
using namespace realm::app;
using namespace realm::jni_util;
using namespace realm::_impl;

static void finalize_client(jlong ptr) {
delete reinterpret_cast<RemoteMongoClient*>(ptr);
}

JNIEXPORT jlong JNICALL
Java_io_realm_internal_objectstore_OsRemoteMongoClient_nativeCreate(JNIEnv *env,
jclass,
jlong j_app_ptr,
jstring j_service_name) {
try {
App *app = reinterpret_cast<App *>(j_app_ptr);
edualonso marked this conversation as resolved.
Show resolved Hide resolved
JStringAccessor name(env, j_service_name);
RemoteMongoClient client = app->remote_mongo_client(name);
edualonso marked this conversation as resolved.
Show resolved Hide resolved
return reinterpret_cast<jlong>(new RemoteMongoClient(std::move(client)));
}
CATCH_STD()
return reinterpret_cast<jlong>(nullptr);
}

JNIEXPORT jlong JNICALL
Java_io_realm_internal_objectstore_OsRemoteMongoClient_nativeCreateDatabase(JNIEnv *env,
jclass,
jlong j_client_ptr,
jstring j_database_name) {
try {
RemoteMongoClient *client = reinterpret_cast<RemoteMongoClient *>(j_client_ptr);
JStringAccessor name(env, j_database_name);
RemoteMongoDatabase database = client->db(name);
return reinterpret_cast<jlong>(new RemoteMongoDatabase(std::move(database)));
}
CATCH_STD()
return reinterpret_cast<jlong>(nullptr);
}

JNIEXPORT jlong JNICALL
Java_io_realm_internal_objectstore_OsRemoteMongoClient_nativeGetFinalizerMethodPtr(JNIEnv *, jclass) {
edualonso marked this conversation as resolved.
Show resolved Hide resolved
return reinterpret_cast<jlong>(&finalize_client);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2020 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "io_realm_internal_objectstore_OsRemoteMongoCollection.h"

#include "java_class_global_def.hpp"
#include "java_network_transport.hpp"
#include "util.hpp"
#include "jni_util/java_method.hpp"
#include "jni_util/jni_utils.hpp"
#include "object-store/src/util/bson/bson.hpp"

#include <realm/util/optional.hpp>
#include <sync/app.hpp>
#include <sync/sync_user.hpp>
#include <sync/remote_mongo_database.hpp>
#include <sync/remote_mongo_collection.hpp>

using namespace realm;
using namespace realm::app;
using namespace realm::jni_util;
using namespace realm::_impl;

static std::function<jobject(JNIEnv*, uint64_t)> collection_mapper = [](JNIEnv* env, uint64_t result) {
return JavaClassGlobalDef::new_long(env, result);
};

static void finalize_collection(jlong ptr) {
delete reinterpret_cast<RemoteMongoCollection*>(ptr);
}

JNIEXPORT void JNICALL
Java_io_realm_internal_objectstore_OsRemoteMongoCollection_nativeCount(JNIEnv *env,
jclass,
jlong j_collection_ptr,
jstring j_filter,
jlong j_limit,
jobject j_callback) {
try {
RemoteMongoCollection* collection = reinterpret_cast<RemoteMongoCollection*>(j_collection_ptr);
JStringAccessor name(env, j_filter);
edualonso marked this conversation as resolved.
Show resolved Hide resolved
uint64_t limit = std::uint64_t(j_limit);
collection->count(name, limit, JavaNetworkTransport::create_result_callback(env, j_callback, collection_mapper));
}
CATCH_STD()
}

JNIEXPORT jlong JNICALL
Java_io_realm_internal_objectstore_OsRemoteMongoCollection_nativeGetFinalizerMethodPtr(JNIEnv *, jclass) {
return reinterpret_cast<jlong>(&finalize_collection);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2020 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "io_realm_internal_objectstore_OsRemoteMongoDatabase.h"

#include "java_class_global_def.hpp"
#include "java_network_transport.hpp"
#include "util.hpp"
#include "jni_util/java_method.hpp"
#include "jni_util/jni_utils.hpp"

#include <realm/util/optional.hpp>
#include <sync/app.hpp>
#include <sync/sync_user.hpp>
#include <sync/remote_mongo_database.hpp>
#include <sync/remote_mongo_collection.hpp>

using namespace realm;
using namespace realm::app;
using namespace realm::jni_util;
using namespace realm::_impl;

static void finalize_database(jlong ptr) {
delete reinterpret_cast<RemoteMongoDatabase*>(ptr);
}

JNIEXPORT jlong JNICALL
Java_io_realm_internal_objectstore_OsRemoteMongoDatabase_nativeGetCollection(JNIEnv* env,
jclass,
jlong j_database_ptr,
jstring j_collection_name) {
try {
RemoteMongoDatabase* database = reinterpret_cast<RemoteMongoDatabase*>(j_database_ptr);
JStringAccessor name(env, j_collection_name);
RemoteMongoCollection collection = database->collection(name);
return reinterpret_cast<jlong>(new RemoteMongoCollection(std::move(collection)));
}
CATCH_STD()
return reinterpret_cast<jlong>(nullptr);
}

JNIEXPORT jlong JNICALL
Java_io_realm_internal_objectstore_OsRemoteMongoDatabase_nativeGetFinalizerMethodPtr(JNIEnv*, jclass) {
edualonso marked this conversation as resolved.
Show resolved Hide resolved
return reinterpret_cast<jlong>(&finalize_database);
}
4 changes: 2 additions & 2 deletions realm/realm-library/src/main/cpp/java_network_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct JavaNetworkTransport : public app::GenericNetworkTransport {
return [callback, success_mapper](T result, Optional<app::AppError> error) {
JNIEnv* env = JniUtils::get_env(true);

static JavaClass java_callback_class(env, "io/realm/RealmApp$OsJNIResultCallback");
static JavaClass java_callback_class(env, "io/realm/internal/jni/OsJNIResultCallback");
static JavaMethod java_notify_onerror(env, java_callback_class, "onError", "(Ljava/lang/String;ILjava/lang/String;)V");
static JavaMethod java_notify_onsuccess(env, java_callback_class, "onSuccess", "(Ljava/lang/Object;)V");

Expand All @@ -138,7 +138,7 @@ struct JavaNetworkTransport : public app::GenericNetworkTransport {
return [callback](Optional<app::AppError> error) {
JNIEnv* env = JniUtils::get_env(true);

static JavaClass java_callback_class(env, "io/realm/RealmApp$OsJNIVoidResultCallback");
static JavaClass java_callback_class(env, "io/realm/internal/jni/OsJNIVoidResultCallback");
static JavaMethod java_notify_onerror(env, java_callback_class, "onError", "(Ljava/lang/String;ILjava/lang/String;)V");
static JavaMethod java_notify_onsuccess(env, java_callback_class, "onSuccess", "(Ljava/lang/Object;)V");

Expand Down
2 changes: 1 addition & 1 deletion realm/realm-library/src/main/cpp/object-store
Submodule object-store updated 66 files
+19,882 −10,010 external/json/json.hpp
+22 −2 src/CMakeLists.txt
+6 −4 src/impl/realm_coordinator.cpp
+143 −164 src/sync/app.cpp
+47 −37 src/sync/app.hpp
+67 −0 src/sync/app_service_client.cpp
+35 −8 src/sync/app_service_client.hpp
+68 −0 src/sync/app_utils.hpp
+2 −2 src/sync/auth_request_client.hpp
+17 −0 src/sync/remote_mongo_client.cpp
+4 −4 src/sync/remote_mongo_client.hpp
+461 −0 src/sync/remote_mongo_collection.cpp
+49 −32 src/sync/remote_mongo_collection.hpp
+16 −0 src/sync/remote_mongo_database.cpp
+6 −6 src/sync/remote_mongo_database.hpp
+0 −47 src/sync/remote_mongo_read_operation.hpp
+0 −3 src/sync/sync_config.hpp
+3 −5 src/sync/sync_session.cpp
+0 −4 src/sync/sync_session.hpp
+6 −6 src/sync/sync_user.cpp
+5 −4 src/sync/sync_user.hpp
+1,170 −0 src/util/bson/bson.cpp
+353 −0 src/util/bson/bson.hpp
+28 −0 src/util/bson/datetime.cpp
+45 −0 src/util/bson/datetime.hpp
+253 −0 src/util/bson/indexed_map.hpp
+46 −0 src/util/bson/max_key.hpp
+46 −0 src/util/bson/min_key.hpp
+80 −0 src/util/bson/regular_expression.cpp
+89 −0 src/util/bson/regular_expression.hpp
+1 −0 tests/CMakeLists.txt
+552 −0 tests/bson.cpp
+5 −0 tests/mongodb/apps/default-app/auth_providers/anon-user.json
+5 −0 tests/mongodb/apps/default-app/auth_providers/api-key.json
+8 −0 tests/mongodb/apps/default-app/auth_providers/custom-function.json
+14 −0 tests/mongodb/apps/default-app/auth_providers/local-userpass.json
+5 −0 tests/mongodb/apps/default-app/functions/authFunc/config.json
+17 −0 tests/mongodb/apps/default-app/functions/authFunc/source.js
+5 −0 tests/mongodb/apps/default-app/functions/confirmFunc/config.json
+49 −0 tests/mongodb/apps/default-app/functions/confirmFunc/source.js
+5 −0 tests/mongodb/apps/default-app/functions/resetFunc/config.json
+51 −0 tests/mongodb/apps/default-app/functions/resetFunc/source.js
+3 −0 tests/mongodb/apps/default-app/secrets.json
+21 −0 tests/mongodb/apps/default-app/services/BackingDB/config.json
+30 −0 tests/mongodb/apps/default-app/services/BackingDB/rules/test_data.Dog.json
+41 −0 tests/mongodb/apps/default-app/services/BackingDB/rules/test_data.Person.json
+13 −0 tests/mongodb/apps/default-app/stitch.json
+1 −1 tests/mongodb/auth_providers/anon-user.json
+1 −1 tests/mongodb/auth_providers/api-key.json
+2 −1 tests/mongodb/auth_providers/custom-function.json
+1 −1 tests/mongodb/auth_providers/local-userpass.json
+1 −1 tests/mongodb/functions/authFunc/config.json
+0 −0 tests/mongodb/functions/authFunc/source.js
+1 −1 tests/mongodb/functions/confirmFunc/config.json
+2 −0 tests/mongodb/functions/confirmFunc/source.js
+1 −1 tests/mongodb/functions/resetFunc/config.json
+9 −8 tests/mongodb/functions/resetFunc/source.js
+3 −0 tests/mongodb/secrets.json
+10 −0 tests/mongodb/services/BackingDB/config.json
+35 −0 tests/mongodb/services/BackingDB/rules/test_data.Dog.json
+47 −0 tests/mongodb/services/BackingDB/rules/test_data.Person.json
+1 −1 tests/mongodb/stitch.json
+396 −2 tests/sync/app.cpp
+0 −2 tests/sync/session/wait_for_completion.cpp
+15 −10 tests/util/test_file.cpp
+3 −2 tests/util/test_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import javax.annotation.Nullable;

import io.realm.internal.Util;
import io.realm.internal.jni.OsJNIResultCallback;
import io.realm.internal.jni.OsJNIVoidResultCallback;
import io.realm.internal.objectstore.OsJavaNetworkTransport;

import static io.realm.RealmApp.NETWORK_POOL_EXECUTOR;
Expand Down Expand Up @@ -74,7 +76,7 @@ public RealmUserApiKey createApiKey(String name) throws ObjectServerError {
Util.checkEmpty(name, "name");
AtomicReference<RealmUserApiKey> success = new AtomicReference<>(null);
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
RealmApp.OsJNIResultCallback<RealmUserApiKey> callback = new RealmApp.OsJNIResultCallback<RealmUserApiKey>(success, error) {
OsJNIResultCallback<RealmUserApiKey> callback = new OsJNIResultCallback<RealmUserApiKey>(success, error) {
@Override
protected RealmUserApiKey mapSuccess(Object result) {
return createKeyFromNative((Object[]) result);
Expand Down Expand Up @@ -116,7 +118,7 @@ public RealmUserApiKey fetchApiKey(ObjectId id) throws ObjectServerError {
Util.checkNull(id, "id");
AtomicReference<RealmUserApiKey> success = new AtomicReference<>(null);
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_FETCH_SINGLE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new RealmApp.OsJNIResultCallback<RealmUserApiKey>(success, error) {
nativeCallFunction(TYPE_FETCH_SINGLE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new OsJNIResultCallback<RealmUserApiKey>(success, error) {
@Override
protected RealmUserApiKey mapSuccess(Object result) {
return createKeyFromNative((Object[]) result);
Expand Down Expand Up @@ -151,7 +153,7 @@ public RealmUserApiKey run() throws ObjectServerError {
public List<RealmUserApiKey> fetchAllApiKeys() throws ObjectServerError {
AtomicReference<List<RealmUserApiKey>> success = new AtomicReference<>(null);
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_FETCH_ALL, user.getApp().nativePtr, user.osUser.getNativePtr(), null, new RealmApp.OsJNIResultCallback<List<RealmUserApiKey>>(success, error) {
nativeCallFunction(TYPE_FETCH_ALL, user.getApp().nativePtr, user.osUser.getNativePtr(), null, new OsJNIResultCallback<List<RealmUserApiKey>>(success, error) {
@Override
protected List<RealmUserApiKey> mapSuccess(Object result) {
Object[] keyData = (Object[]) result;
Expand Down Expand Up @@ -192,7 +194,7 @@ public List<RealmUserApiKey> run() throws ObjectServerError {
public void deleteApiKey(ObjectId id) throws ObjectServerError {
Util.checkNull(id, "id");
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_DELETE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new RealmApp.OsJNIVoidResultCallback(error));
nativeCallFunction(TYPE_DELETE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new OsJNIVoidResultCallback(error));
RealmApp.handleResult(null, error);
}

Expand Down Expand Up @@ -224,7 +226,7 @@ public Void run() throws ObjectServerError {
public void disableApiKey(ObjectId id) throws ObjectServerError {
Util.checkNull(id, "id");
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_DISABLE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new RealmApp.OsJNIVoidResultCallback(error));
nativeCallFunction(TYPE_DISABLE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new OsJNIVoidResultCallback(error));
RealmApp.handleResult(null, error);
}

Expand Down Expand Up @@ -256,7 +258,7 @@ public Void run() throws ObjectServerError {
public void enableApiKey(ObjectId id) throws ObjectServerError {
Util.checkNull(id, "id");
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_ENABLE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new RealmApp.OsJNIVoidResultCallback(error));
nativeCallFunction(TYPE_ENABLE, user.getApp().nativePtr, user.osUser.getNativePtr(), id.toHexString(), new OsJNIVoidResultCallback(error));
RealmApp.handleResult(null, error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.atomic.AtomicReference;

import io.realm.internal.Util;
import io.realm.internal.jni.OsJNIVoidResultCallback;
import io.realm.internal.objectstore.OsJavaNetworkTransport;

import static io.realm.RealmApp.NETWORK_POOL_EXECUTOR;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void registerUser(String email, String password) throws ObjectServerError
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_REGISTER_USER,
app.nativePtr,
new RealmApp.OsJNIVoidResultCallback(error),
new OsJNIVoidResultCallback(error),
email, password);
RealmApp.handleResult(null, error);
}
Expand Down Expand Up @@ -103,7 +104,7 @@ public void confirmUser(String token, String tokenId) throws ObjectServerError {
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_CONFIRM_USER,
app.nativePtr,
new RealmApp.OsJNIVoidResultCallback(error),
new OsJNIVoidResultCallback(error),
token, tokenId);
RealmApp.handleResult(null, error);
}
Expand Down Expand Up @@ -139,7 +140,7 @@ public void resendConfirmationEmail(String email) throws ObjectServerError {
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_RESEND_CONFIRMATION_EMAIL,
app.nativePtr,
new RealmApp.OsJNIVoidResultCallback(error),
new OsJNIVoidResultCallback(error),
email);
RealmApp.handleResult(null, error);
}
Expand Down Expand Up @@ -174,7 +175,7 @@ public void sendResetPasswordEmail(String email) throws ObjectServerError {
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_SEND_RESET_PASSWORD_EMAIL,
app.nativePtr,
new RealmApp.OsJNIVoidResultCallback(error),
new OsJNIVoidResultCallback(error),
email);
RealmApp.handleResult(null, error);
}
Expand Down Expand Up @@ -218,7 +219,7 @@ public void callResetPasswordFunction(String email, String newPassword, Object..
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_CALL_RESET_PASSWORD_FUNCTION,
app.nativePtr,
new RealmApp.OsJNIVoidResultCallback(error),
new OsJNIVoidResultCallback(error),
email, newPassword, array.toString());
RealmApp.handleResult(null, error);
}
Expand Down Expand Up @@ -262,7 +263,7 @@ public void resetPassword(String token, String tokenId, String newPassword) thro
AtomicReference<ObjectServerError> error = new AtomicReference<>(null);
nativeCallFunction(TYPE_RESET_PASSWORD,
app.nativePtr,
new RealmApp.OsJNIVoidResultCallback(error),
new OsJNIVoidResultCallback(error),
token, tokenId, newPassword);
RealmApp.handleResult(null, error);
}
Expand Down
Loading