Search in sources :

Example 1 with StringOnly

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());
    }
}
Also used : StringOnly(io.realm.entities.StringOnly) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) Test(org.junit.Test)

Example 2 with StringOnly

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();
}
Also used : StringOnly(io.realm.entities.StringOnly) Test(org.junit.Test)

Example 3 with StringOnly

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();
}
Also used : StringOnly(io.realm.entities.StringOnly) CountDownLatch(java.util.concurrent.CountDownLatch) RunInLooperThread(io.realm.rule.RunInLooperThread) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread)

Example 4 with StringOnly

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());
}
Also used : StringOnly(io.realm.entities.StringOnly) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Example 5 with StringOnly

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();
}
Also used : StringOnly(io.realm.entities.StringOnly) Table(io.realm.internal.Table) Test(org.junit.Test)

Aggregations

StringOnly (io.realm.entities.StringOnly)7 Test (org.junit.Test)5 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)2 UiThreadTest (android.support.test.annotation.UiThreadTest)1 PrimaryKeyRequiredAsString (io.realm.entities.PrimaryKeyRequiredAsString)1 Table (io.realm.internal.Table)1 RunInLooperThread (io.realm.rule.RunInLooperThread)1 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1