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