use of io.realm.RealmConfiguration in project realm-java by realm.
the class RealmObservableFactory method from.
@Override
public <E> Flowable<RealmResults<E>> from(final Realm realm, final RealmResults<E> results) {
if (realm.isFrozen()) {
return Flowable.just(results);
}
final RealmConfiguration realmConfig = realm.getConfiguration();
Scheduler scheduler = getScheduler();
return Flowable.create(new FlowableOnSubscribe<RealmResults<E>>() {
@Override
public void subscribe(final FlowableEmitter<RealmResults<E>> emitter) {
// If the Realm has been closed, just create an empty Observable because we assume it is going to be disposed shortly.
if (!results.isValid())
return;
// Gets instance to make sure that the Realm is open for as long as the
// Observable is subscribed to it.
final Realm observableRealm = Realm.getInstance(realmConfig);
resultsRefs.get().acquireReference(results);
final RealmChangeListener<RealmResults<E>> listener = new RealmChangeListener<RealmResults<E>>() {
@Override
public void onChange(RealmResults<E> results) {
if (!emitter.isCancelled()) {
emitter.onNext(returnFrozenObjects ? results.freeze() : results);
}
}
};
results.addChangeListener(listener);
// Cleanup when stream is disposed
emitter.setDisposable(Disposables.fromRunnable(new Runnable() {
@Override
public void run() {
if (!observableRealm.isClosed()) {
results.removeChangeListener(listener);
observableRealm.close();
}
resultsRefs.get().releaseReference(results);
}
}));
// Emit current value immediately
emitter.onNext(returnFrozenObjects ? results.freeze() : results);
}
}, BACK_PRESSURE_STRATEGY).subscribeOn(scheduler).unsubscribeOn(scheduler);
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class GridViewExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_realm_example);
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
// Clear the realm from last time
Realm.deleteRealm(realmConfiguration);
// Create a new empty instance of Realm
realm = Realm.getInstance(realmConfiguration);
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class RealmAllocBenchmarks 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();
realm.createObject(AllTypes.class).getColumnRealmList().add(realm.createObject(Dog.class));
realm.commitTransaction();
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class RealmObjectReadBenchmarks method before.
@BeforeExperiment
public void before() {
Realm.init(InstrumentationRegistry.getTargetContext());
RealmConfiguration config = new RealmConfiguration.Builder().build();
Realm.deleteRealm(config);
realm = Realm.getInstance(config);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
readObject = realm.createObject(AllTypes.class);
readObject.setColumnString("Foo");
readObject.setColumnLong(42);
readObject.setColumnDouble(1.234D);
}
});
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class TestRealmConfigurationFactory method createConfiguration.
public RealmConfiguration createConfiguration(String subDir, String name, Object module, byte[] key) {
RealmConfiguration.Builder builder = createConfigurationBuilder();
File folder = getRoot();
if (subDir != null) {
folder = new File(folder, subDir);
assertTrue(folder.mkdirs());
}
builder.directory(folder);
if (name != null) {
builder.name(name);
}
if (module != null) {
builder.modules(module);
}
if (key != null) {
builder.encryptionKey(key);
}
RealmConfiguration configuration = builder.build();
configurations.add(configuration);
return configuration;
}
Aggregations