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();
}
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();
}
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);
}
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();
}
}
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());
}
Aggregations