Esempio n. 1
0
SyncFileActionMetadataResults SyncMetadataManager::all_pending_actions() const
{
    SharedRealm realm = Realm::get_shared_realm(get_configuration());
    TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_fileActionMetadata);
    Results results(realm, table->where());
    return SyncFileActionMetadataResults(std::move(results), std::move(realm), m_file_action_schema);
}
Esempio n. 2
0
SyncUserMetadataResults SyncMetadataManager::get_users(bool marked) const
{
    // Open the Realm.
    SharedRealm realm = Realm::get_shared_realm(get_configuration());

    TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_userMetadata);
    Query query = table->where().equal(m_user_schema.idx_marked_for_removal, marked);

    Results results(realm, std::move(query));
    return SyncUserMetadataResults(std::move(results), std::move(realm), m_user_schema);
}
Esempio n. 3
0
void RealmCache::cache_realm(SharedRealm &realm, std::thread::id thread_id)
{
    std::lock_guard<std::mutex> lock(m_mutex);

    auto path_iter = m_cache.find(realm->config().path);
    if (path_iter == m_cache.end()) {
        m_cache.emplace(realm->config().path, std::map<std::thread::id, WeakRealm>{{thread_id, realm}});
    }
    else {
        path_iter->second.emplace(thread_id, realm);
    }
}
Esempio n. 4
0
SyncMetadataManager::SyncMetadataManager(std::string path,
                                         bool should_encrypt,
                                         util::Optional<std::vector<char>> encryption_key)
{
    constexpr uint64_t SCHEMA_VERSION = 1;
    std::lock_guard<std::mutex> lock(m_metadata_lock);

    Realm::Config config;
    config.path = std::move(path);
    config.schema = make_schema();
    config.schema_version = SCHEMA_VERSION;
    config.schema_mode = SchemaMode::Automatic;
#if REALM_PLATFORM_APPLE
    if (should_encrypt && !encryption_key) {
        encryption_key = keychain::metadata_realm_encryption_key();
    }
#endif
    if (should_encrypt) {
        if (!encryption_key) {
            throw std::invalid_argument("Metadata Realm encryption was specified, but no encryption key was provided.");
        }
        config.encryption_key = std::move(*encryption_key);
    }

    // Open the Realm.
    SharedRealm realm = Realm::get_shared_realm(config);

    // Get data about the (hardcoded) schemas.
    DescriptorRef descriptor = ObjectStore::table_for_object_type(realm->read_group(),
                                                                  c_sync_userMetadata)->get_descriptor();
    m_user_schema = {
        descriptor->get_column_index(c_sync_identity),
        descriptor->get_column_index(c_sync_marked_for_removal),
        descriptor->get_column_index(c_sync_user_token),
        descriptor->get_column_index(c_sync_auth_server_url),
        descriptor->get_column_index(c_sync_user_is_admin),
    };

    descriptor = ObjectStore::table_for_object_type(realm->read_group(), c_sync_fileActionMetadata)->get_descriptor();
    m_file_action_schema = {
        descriptor->get_column_index(c_sync_original_name),
        descriptor->get_column_index(c_sync_new_name),
        descriptor->get_column_index(c_sync_action),
        descriptor->get_column_index(c_sync_url),
        descriptor->get_column_index(c_sync_identity)
    };

    m_metadata_config = std::move(config);
}
Esempio n. 5
0
template<> size_t RJSAccessor::to_object_index(JSContextRef ctx, SharedRealm realm, JSValueRef &val, const std::string &type, bool try_update) {
    JSObjectRef object = RJSValidatedValueToObject(ctx, val);
    if (JSValueIsObjectOfClass(ctx, val, RJSObjectClass())) {
        return RJSGetInternal<Object *>(object)->row().get_index();
    }

    auto object_schema = realm->config().schema->find(type);
    if (RJSIsValueArray(ctx, object)) {
        object = RJSDictForPropertyArray(ctx, *object_schema, object);
    }

    Object child = Object::create<JSValueRef>(ctx, realm, *object_schema, (JSValueRef)object, try_update);
    return child.row().get_index();
}
Esempio n. 6
0
    static size_t to_object_index(ContextType ctx, SharedRealm realm, ValueType &value, const std::string &type, bool try_update) {
        ObjectType object = Value::validated_to_object(ctx, value);
        if (Object::template is_instance<RealmObjectClass<T>>(ctx, object)) {
            return get_internal<T, RealmObjectClass<T>>(object)->row().get_index();
        }

        auto object_schema = realm->config().schema->find(type);
        if (Value::is_array(ctx, object)) {
            object = Schema<T>::dict_for_property_array(ctx, *object_schema, object);
        }

        auto child = realm::Object::create<ValueType>(ctx, realm, *object_schema, static_cast<ValueType>(object), try_update);
        return child.row().get_index();
    }
static List get_list(const Object& object, size_t column_ndx) {
    return List(object.realm(), object.row().get_linklist(column_ndx));
}

static Property nullable(Property p) {
    p.is_nullable = true;
    return p;
}

TEST_CASE("thread safe reference") {
    InMemoryTestFile config;
    config.cache = false;
    config.automatic_change_notifications = false;

    SharedRealm r = Realm::get_shared_realm(config);

    static const ObjectSchema foo_object({"foo_object", {
        {"ignore_me", PropertyType::Int}, // Used in tests cases that don't care about the value.
    }});
    static const ObjectSchema string_object({"string_object", {
        nullable({"value", PropertyType::String}),
    }});
    static const ObjectSchema int_object({"int_object", {
        {"value", PropertyType::Int},
    }});
    static const ObjectSchema int_array_object({"int_array_object", {
        {"value", PropertyType::Array, "int_object"}
    }});
    r->update_schema({foo_object, string_object, int_object, int_array_object});