use of io.realm.RealmConfiguration in project realm-java by realm.
the class JNIColumnInfoTest method setUp.
@Before
public void setUp() {
Realm.init(InstrumentationRegistry.getInstrumentation().getContext());
RealmConfiguration config = configFactory.createConfiguration();
sharedRealm = OsSharedRealm.getInstance(config, OsSharedRealm.VersionID.LIVE);
table = TestHelper.createTable(sharedRealm, "temp", new TestHelper.AdditionalTableSetup() {
@Override
public void execute(Table table) {
table.addColumn(RealmFieldType.STRING, "firstName");
table.addColumn(RealmFieldType.STRING, "lastName");
}
});
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class RealmObservableFactory method changesetsFrom.
@Override
public Observable<ObjectChange<DynamicRealmObject>> changesetsFrom(DynamicRealm realm, final DynamicRealmObject object) {
if (realm.isFrozen()) {
return Observable.just(new ObjectChange<DynamicRealmObject>(object, null));
}
final RealmConfiguration realmConfig = realm.getConfiguration();
Scheduler scheduler = getScheduler();
return Observable.create(new ObservableOnSubscribe<ObjectChange<DynamicRealmObject>>() {
@Override
public void subscribe(final ObservableEmitter<ObjectChange<DynamicRealmObject>> emitter) {
// If the Realm has been closed, just create an empty Observable because we assume it is going to be disposed shortly.
if (!RealmObject.isValid(object))
return;
// Gets instance to make sure that the Realm is open for as long as the
// Observable is subscribed to it.
final DynamicRealm observableRealm = DynamicRealm.getInstance(realmConfig);
objectRefs.get().acquireReference(object);
final RealmObjectChangeListener<DynamicRealmObject> listener = new RealmObjectChangeListener<DynamicRealmObject>() {
@Override
public void onChange(DynamicRealmObject obj, ObjectChangeSet changeSet) {
if (!emitter.isDisposed()) {
emitter.onNext(new ObjectChange<>(returnFrozenObjects ? RealmObject.freeze(obj) : obj, changeSet));
}
}
};
object.addChangeListener(listener);
// Cleanup when stream is disposed
emitter.setDisposable(Disposables.fromRunnable(new Runnable() {
@Override
public void run() {
if (!observableRealm.isClosed()) {
RealmObject.removeChangeListener(object, listener);
observableRealm.close();
}
objectRefs.get().releaseReference(object);
}
}));
// Emit current value immediately
emitter.onNext(new ObjectChange<>(returnFrozenObjects ? RealmObject.freeze(object) : object, null));
}
}).subscribeOn(scheduler).unsubscribeOn(scheduler);
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class RealmObservableFactory method from.
@Override
public <E> Flowable<RealmResults<E>> from(DynamicRealm 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 DynamicRealm observableRealm = DynamicRealm.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 RealmObservableFactory method from.
@Override
public Flowable<Realm> from(Realm realm) {
if (realm.isFrozen()) {
return Flowable.just(realm);
}
final RealmConfiguration realmConfig = realm.getConfiguration();
Scheduler scheduler = getScheduler();
return Flowable.create(new FlowableOnSubscribe<Realm>() {
@Override
public void subscribe(final FlowableEmitter<Realm> emitter) throws Exception {
// Instance is cached by Realm, so no need to keep strong reference
final Realm observableRealm = Realm.getInstance(realmConfig);
final RealmChangeListener<Realm> listener = new RealmChangeListener<Realm>() {
@Override
public void onChange(Realm realm) {
if (!emitter.isCancelled()) {
emitter.onNext(returnFrozenObjects ? realm.freeze() : realm);
}
}
};
observableRealm.addChangeListener(listener);
// Cleanup when stream is disposed
emitter.setDisposable(Disposables.fromRunnable(new Runnable() {
@Override
public void run() {
if (!observableRealm.isClosed()) {
observableRealm.removeChangeListener(listener);
observableRealm.close();
}
}
}));
// Emit current value immediately
emitter.onNext(returnFrozenObjects ? observableRealm.freeze() : observableRealm);
}
}, BACK_PRESSURE_STRATEGY).subscribeOn(scheduler).unsubscribeOn(scheduler);
}
use of io.realm.RealmConfiguration in project realm-java by realm.
the class RealmObservableFactory method changesetsFrom.
@Override
public <E> Observable<CollectionChange<RealmResults<E>>> changesetsFrom(DynamicRealm realm, final RealmResults<E> results) {
if (realm.isFrozen()) {
return Observable.just(new CollectionChange<RealmResults<E>>(results, null));
}
final RealmConfiguration realmConfig = realm.getConfiguration();
Scheduler scheduler = getScheduler();
return Observable.create(new ObservableOnSubscribe<CollectionChange<RealmResults<E>>>() {
@Override
public void subscribe(final ObservableEmitter<CollectionChange<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 DynamicRealm observableRealm = DynamicRealm.getInstance(realmConfig);
resultsRefs.get().acquireReference(results);
final OrderedRealmCollectionChangeListener<RealmResults<E>> listener = new OrderedRealmCollectionChangeListener<RealmResults<E>>() {
@Override
public void onChange(RealmResults<E> results, OrderedCollectionChangeSet changeSet) {
if (!emitter.isDisposed()) {
emitter.onNext(new CollectionChange<>(returnFrozenObjects ? results.freeze() : results, changeSet));
}
}
};
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(new CollectionChange<>(returnFrozenObjects ? results.freeze() : results, null));
}
}).subscribeOn(scheduler).unsubscribeOn(scheduler);
}
Aggregations