Search in sources :

Example 6 with RealmConfiguration

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

the class RealmResultsBenchmarks method before.

@BeforeExperiment
public void before() {
    Realm.init(InstrumentationRegistry.getTargetContext());
    RealmConfiguration config = new RealmConfiguration.Builder().build();
    Realm.deleteRealm(config);
    realm = Realm.getInstance(config);
    realm.beginTransaction();
    for (int i = 0; i < DATA_SIZE; i++) {
        AllTypes obj = realm.createObject(AllTypes.class);
        obj.setColumnLong(i);
        obj.setColumnBoolean(i % 2 == 0);
        obj.setColumnString("Foo " + i);
        obj.setColumnDouble(i + 1.234D);
    }
    realm.commitTransaction();
    results = realm.where(AllTypes.class).findAll();
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) AllTypes(io.realm.entities.AllTypes) BeforeExperiment(dk.ilios.spanner.BeforeExperiment)

Example 7 with RealmConfiguration

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

the class NewsReaderApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    context = this;
    initializeTimber();
    RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {

        @Override
        public void handleError(Throwable e) {
            super.handleError(e);
            Timber.e(e.toString());
        }
    });
    // Configure default configuration for Realm
    Realm.init(this);
    RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
    Realm.setDefaultConfiguration(realmConfig);
}
Also used : RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) RealmConfiguration(io.realm.RealmConfiguration)

Example 8 with RealmConfiguration

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

the class EncryptionExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Generate a key
    // IMPORTANT! This is a silly way to generate a key. It is also never stored.
    // For proper key handling please consult:
    // * https://developer.android.com/training/articles/keystore.html
    // * http://nelenkov.blogspot.dk/2012/05/storing-application-secrets-in-androids.html
    byte[] key = new byte[64];
    new SecureRandom().nextBytes(key);
    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().encryptionKey(key).build();
    // Start with a clean slate every time
    Realm.deleteRealm(realmConfiguration);
    // Open the Realm with encryption enabled
    realm = Realm.getInstance(realmConfiguration);
    // Everything continues to work as normal except for that the file is encrypted on disk
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            Person person = realm.createObject(Person.class);
            person.setName("Happy Person");
            person.setAge(14);
        }
    });
    Person person = realm.where(Person.class).findFirst();
    Log.i(TAG, String.format("Person name: %s", person.getName()));
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) SecureRandom(java.security.SecureRandom) Realm(io.realm.Realm)

Example 9 with RealmConfiguration

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

the class JNILinkTest method setUp.

@Before
public void setUp() {
    RealmConfiguration config = configFactory.createConfiguration();
    sharedRealm = SharedRealm.getInstance(config);
    sharedRealm.beginTransaction();
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) Before(org.junit.Before)

Example 10 with RealmConfiguration

use of io.realm.RealmConfiguration in project ocreader by schaal.

the class Queries method init.

public static void init(Context context) {
    Realm.init(context);
    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().schemaVersion(SCHEMA_VERSION).migration(migration).initialData(initialData).compactOnLaunch().build();
    Realm.setDefaultConfiguration(realmConfiguration);
    Realm realm = null;
    try {
        realm = Realm.getDefaultInstance();
        if (realm.isEmpty())
            realm.executeTransaction(initialData);
    } catch (Exception ex) {
        Log.e(TAG, "Failed to open realm db", ex);
        closeRealm(realm);
        Realm.deleteRealm(realmConfiguration);
    } finally {
        closeRealm(realm);
    }
}
Also used : RealmConfiguration(io.realm.RealmConfiguration) Realm(io.realm.Realm) RealmException(io.realm.exceptions.RealmException)

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