use of io.realm.entities.StringOnly in project realm-java by realm.
the class RealmQueryTests method georgian.
@Test
public void georgian() {
String[] words = { "მონაცემთა ბაზა", "მიწისქვეშა გადასასვლელი", "რუსთაველის გამზირი", "მთავარი ქუჩა", "სადგურის მოედანი", "ველოცირაპტორების ჯოგი" };
String[] sorted = { "ველოცირაპტორების ჯოგი", "მთავარი ქუჩა", "მიწისქვეშა გადასასვლელი", "მონაცემთა ბაზა", "რუსთაველის გამზირი", "სადგურის მოედანი" };
realm.beginTransaction();
realm.delete(StringOnly.class);
for (String word : words) {
StringOnly stringOnly = realm.createObject(StringOnly.class);
stringOnly.setChars(word);
}
realm.commitTransaction();
RealmResults<StringOnly> stringOnlies1 = realm.where(StringOnly.class).contains("chars", "მთავარი").findAll();
assertEquals(1, stringOnlies1.size());
RealmResults<StringOnly> stringOnlies2 = realm.where(StringOnly.class).findAll();
stringOnlies2 = stringOnlies2.sort("chars");
for (int i = 0; i < stringOnlies2.size(); i++) {
assertEquals(sorted[i], stringOnlies2.get(i).getChars());
}
}
use of io.realm.entities.StringOnly in project realm-java by realm.
the class SchemaTests method createObject.
@Test
public void createObject() {
Realm realm = Realm.getInstance(config);
realm.beginTransaction();
assertTrue(realm.getSchema().contains("StringOnly"));
StringOnly stringOnly = realm.createObject(StringOnly.class);
stringOnly.setChars("TEST");
realm.commitTransaction();
assertEquals(1, realm.where(StringOnly.class).count());
realm.close();
}
use of io.realm.entities.StringOnly in project realm-java by realm.
the class RealmQueryTests method largeRealmMultipleThreads.
// @Test Disabled because of time consuming.
public void largeRealmMultipleThreads() throws InterruptedException {
final int nObjects = 500000;
final int nThreads = 3;
final CountDownLatch latch = new CountDownLatch(nThreads);
realm.beginTransaction();
realm.delete(StringOnly.class);
for (int i = 0; i < nObjects; i++) {
StringOnly stringOnly = realm.createObject(StringOnly.class);
stringOnly.setChars(String.format("string %d", i));
}
realm.commitTransaction();
for (int i = 0; i < nThreads; i++) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
RealmConfiguration realmConfig = configFactory.createConfiguration();
Realm realm = Realm.getInstance(realmConfig);
RealmResults<StringOnly> realmResults = realm.where(StringOnly.class).findAll();
int n = 0;
for (StringOnly ignored : realmResults) {
n = n + 1;
}
assertEquals(nObjects, n);
realm.close();
latch.countDown();
}
});
thread.start();
}
latch.await();
}
use of io.realm.entities.StringOnly in project realm-java by realm.
the class RealmResultsTests method deleteAndDeleteAll.
@Test
public void deleteAndDeleteAll() {
realm.beginTransaction();
for (int i = 0; i < 10; i++) {
StringOnly stringOnly = realm.createObject(StringOnly.class);
stringOnly.setChars("String " + i);
}
realm.commitTransaction();
RealmResults<StringOnly> stringOnlies = realm.where(StringOnly.class).findAll();
realm.beginTransaction();
// Removes one object.
stringOnlies.get(0).deleteFromRealm();
realm.commitTransaction();
realm.beginTransaction();
// Removes the rest.
stringOnlies.deleteAllFromRealm();
realm.commitTransaction();
assertEquals(0, realm.where(StringOnly.class).findAll().size());
}
use of io.realm.entities.StringOnly in project realm-java by realm.
the class RealmMigrationTests method migratePreNull.
// Pre-null Realms will leave columns not-nullable after the underlying storage engine has
// migrated the file format. An explicit migration step to convert to nullable, and the
// old class (without @Required) can be used,
@Test
public void migratePreNull() throws IOException {
configFactory.copyRealmFromAssets(context, "default-before-migration.realm", Realm.DEFAULT_REALM_NAME);
RealmMigration migration = new RealmMigration() {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
Table table = realm.schema.getTable(StringOnly.class);
table.convertColumnToNullable(table.getColumnIndex("chars"));
}
};
RealmConfiguration realmConfig = configFactory.createConfigurationBuilder().schemaVersion(1).schema(StringOnly.class).migration(migration).build();
Realm realm = Realm.getInstance(realmConfig);
realm.beginTransaction();
StringOnly stringOnly = realm.createObject(StringOnly.class);
stringOnly.setChars(null);
realm.commitTransaction();
realm.close();
}
Aggregations