Search in sources :

Example 16 with RealmConfiguration

use of io.realm.RealmConfiguration in project realm-java by realm.

the class MyApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Realm.init(this);
    RealmConfiguration config = new RealmConfiguration.Builder().build();
    Realm.deleteRealm(config);
    Realm.setDefaultConfiguration(config);
    createTestData();
}
Also used : RealmConfiguration(io.realm.RealmConfiguration)

Example 17 with RealmConfiguration

use of io.realm.RealmConfiguration in project realm-java by realm.

the class OsListTests method setUp.

@Before
public void setUp() {
    OsObjectSchemaInfo objectSchemaInfo = new OsObjectSchemaInfo.Builder("TestModel", false, 14, 0).addPersistedValueListProperty("", "longList", RealmFieldType.INTEGER_LIST, !Property.REQUIRED).addPersistedValueListProperty("", "doubleList", RealmFieldType.DOUBLE_LIST, !Property.REQUIRED).addPersistedValueListProperty("", "floatList", RealmFieldType.FLOAT_LIST, !Property.REQUIRED).addPersistedValueListProperty("", "booleanList", RealmFieldType.BOOLEAN_LIST, !Property.REQUIRED).addPersistedValueListProperty("", "binaryList", RealmFieldType.BINARY_LIST, !Property.REQUIRED).addPersistedValueListProperty("", "dateList", RealmFieldType.DATE_LIST, !Property.REQUIRED).addPersistedValueListProperty("", "stringList", RealmFieldType.STRING_LIST, !Property.REQUIRED).addPersistedValueListProperty("", "requiredLongList", RealmFieldType.INTEGER_LIST, Property.REQUIRED).addPersistedValueListProperty("", "requiredDoubleList", RealmFieldType.DOUBLE_LIST, Property.REQUIRED).addPersistedValueListProperty("", "requiredFloatList", RealmFieldType.FLOAT_LIST, Property.REQUIRED).addPersistedValueListProperty("", "requiredBooleanList", RealmFieldType.BOOLEAN_LIST, Property.REQUIRED).addPersistedValueListProperty("", "requiredBinaryList", RealmFieldType.BINARY_LIST, Property.REQUIRED).addPersistedValueListProperty("", "requiredDateList", RealmFieldType.DATE_LIST, Property.REQUIRED).addPersistedValueListProperty("", "requiredStringList", RealmFieldType.STRING_LIST, Property.REQUIRED).build();
    List<OsObjectSchemaInfo> objectSchemaInfoList = new ArrayList<OsObjectSchemaInfo>();
    objectSchemaInfoList.add(objectSchemaInfo);
    OsSchemaInfo schemaInfo = new OsSchemaInfo(objectSchemaInfoList);
    RealmConfiguration config = configFactory.createConfiguration();
    OsRealmConfig.Builder configBuilder = new OsRealmConfig.Builder(config).autoUpdateNotification(true).schemaInfo(schemaInfo);
    sharedRealm = OsSharedRealm.getInstance(configBuilder, OsSharedRealm.VersionID.LIVE);
    sharedRealm.beginTransaction();
    Table table = sharedRealm.getTable(Table.getTableNameForClass("TestModel"));
    row = table.getUncheckedRow(OsObject.createRow(table));
    sharedRealm.commitTransaction();
    schemaInfo = sharedRealm.getSchemaInfo();
    testObjectSchemaInfo = schemaInfo.getObjectSchemaInfo("TestModel");
    sharedRealm.beginTransaction();
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 18 with RealmConfiguration

use of io.realm.RealmConfiguration in project realm-java by realm.

the class OsResultsTests method addRowAsync.

private void addRowAsync(final OsSharedRealm sharedRealm) {
    final CountDownLatch latch = new CountDownLatch(1);
    final RealmConfiguration configuration = sharedRealm.getConfiguration();
    new Thread(new Runnable() {

        @Override
        public void run() {
            OsSharedRealm sharedRealm = getSharedRealm(configuration);
            addRow(sharedRealm);
            sharedRealm.close();
            latch.countDown();
        }
    }).start();
    TestHelper.awaitOrFail(latch);
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) RunInLooperThread(io.realm.rule.RunInLooperThread) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread)

Example 19 with RealmConfiguration

use of io.realm.RealmConfiguration in project realm-java by realm.

the class PrimaryKeyTests method removingPrimaryKeyRemovesConstraint_typeSetters.

/**
 * This test surfaces a bunch of problems, most of them seem to be around caching of the schema
 * during a transaction
 *
 * 1) Removing the primary key do not invalidate the cache in RealmSchema and those cached
 *    are ImmutableRealmObjectSchema so do not change when the primary key is removed.
 *
 * 2) Addding `schema.refresh()` to RealmObjectSchema.removePrimaryKey()` causes
 *    RealmPrimaryKeyConstraintException anyway. Unclear why.
 */
@Test
public void removingPrimaryKeyRemovesConstraint_typeSetters() {
    RealmConfiguration config = configFactory.createConfigurationBuilder().name("removeConstraints").build();
    DynamicRealm realm = DynamicRealm.getInstance(config);
    RealmSchema realmSchema = realm.getSchema();
    realm.beginTransaction();
    RealmObjectSchema tableSchema = realmSchema.create("Employee").addField("name", String.class, FieldAttribute.PRIMARY_KEY);
    realm.createObject("Employee", "Foo");
    DynamicRealmObject obj = realm.createObject("Employee", "Foo2");
    try {
        // Tries to create 2nd entry with name Foo.
        obj.setString("name", "Foo");
    } catch (IllegalArgumentException e) {
        tableSchema.removePrimaryKey();
        obj.setString("name", "Foo");
    } finally {
        realm.close();
    }
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) DynamicRealmObject(io.realm.DynamicRealmObject) RealmSchema(io.realm.RealmSchema) DynamicRealm(io.realm.DynamicRealm) RealmObjectSchema(io.realm.RealmObjectSchema) Test(org.junit.Test)

Example 20 with RealmConfiguration

use of io.realm.RealmConfiguration in project realm-java by realm.

the class OsObjectStoreTests method callWithLock.

@Test
public void callWithLock() {
    RealmConfiguration config = configFactory.createConfiguration();
    // Return false if there are opened OsSharedRealm instance
    OsSharedRealm sharedRealm = OsSharedRealm.getInstance(config, OsSharedRealm.VersionID.LIVE);
    assertFalse(OsObjectStore.callWithLock(config, new Runnable() {

        @Override
        public void run() {
            fail();
        }
    }));
    sharedRealm.close();
    final AtomicBoolean callbackCalled = new AtomicBoolean(false);
    assertTrue(OsObjectStore.callWithLock(config, new Runnable() {

        @Override
        public void run() {
            callbackCalled.set(true);
        }
    }));
    assertTrue(callbackCalled.get());
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Aggregations

RealmConfiguration (io.realm.RealmConfiguration)64 Realm (io.realm.Realm)20 DynamicRealm (io.realm.DynamicRealm)17 Scheduler (io.reactivex.Scheduler)14 RealmChangeListener (io.realm.RealmChangeListener)8 BeforeExperiment (dk.ilios.spanner.BeforeExperiment)6 Before (org.junit.Before)5 DynamicRealmObject (io.realm.DynamicRealmObject)4 RealmList (io.realm.RealmList)4 RealmResults (io.realm.RealmResults)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Context (android.content.Context)3 OrderedCollectionChangeSet (io.realm.OrderedCollectionChangeSet)3 OrderedRealmCollectionChangeListener (io.realm.OrderedRealmCollectionChangeListener)3 RealmObjectSchema (io.realm.RealmObjectSchema)3 AllTypes (io.realm.entities.AllTypes)3 IntentFilter (android.content.IntentFilter)2 LinearLayout (android.widget.LinearLayout)2 RealmSchema (io.realm.RealmSchema)2