use of io.realm.exceptions.RealmException in project realm-rxjava-example by kboyarshinov.
the class OnSubscribeRealm method call.
@Override
public void call(final Subscriber<? super T> subscriber) {
synchronized (lock) {
boolean canceled = this.canceled.get();
if (!canceled && !subscribers.isEmpty()) {
subscriber.add(newUnsubscribeAction(subscriber));
subscribers.add(subscriber);
return;
} else if (canceled) {
return;
}
}
subscriber.add(newUnsubscribeAction(subscriber));
subscribers.add(subscriber);
RealmConfiguration.Builder builder = new RealmConfiguration.Builder(context);
if (fileName != null) {
builder.name(fileName);
}
Realm realm = Realm.getInstance(builder.build());
boolean withError = false;
T object = null;
try {
if (!this.canceled.get()) {
realm.beginTransaction();
object = get(realm);
if (object != null && !this.canceled.get()) {
realm.commitTransaction();
} else {
realm.cancelTransaction();
}
}
} catch (RuntimeException e) {
realm.cancelTransaction();
sendOnError(new RealmException("Error during transaction.", e));
withError = true;
} catch (Error e) {
realm.cancelTransaction();
sendOnError(e);
withError = true;
}
if (object != null && !this.canceled.get() && !withError) {
sendOnNext(object);
}
try {
realm.close();
} catch (RealmException ex) {
sendOnError(ex);
withError = true;
}
if (!withError) {
sendOnCompleted();
}
this.canceled.set(false);
}
use of io.realm.exceptions.RealmException in project realm-java by realm.
the class RealmJsonTests method createObjectFromJson_streamNullJson.
@Test
public void createObjectFromJson_streamNullJson() throws IOException {
assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
InputStream in = TestHelper.loadJsonFromAssets(context, "all_types_invalid.json");
realm.beginTransaction();
try {
realm.createObjectFromJson(AnnotationTypes.class, in);
fail();
} catch (RealmException ignored) {
} finally {
realm.commitTransaction();
in.close();
}
}
use of io.realm.exceptions.RealmException in project realm-java by realm.
the class RealmJsonTests method createOrUpdateObjectFromJson_streamInvalidJson.
@Test
public void createOrUpdateObjectFromJson_streamInvalidJson() throws IOException {
assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
AllTypesPrimaryKey obj = new AllTypesPrimaryKey();
obj.setColumnLong(1);
realm.beginTransaction();
realm.copyToRealm(obj);
realm.commitTransaction();
InputStream in = TestHelper.loadJsonFromAssets(context, "all_types_invalid.json");
realm.beginTransaction();
try {
realm.createOrUpdateObjectFromJson(AllTypesPrimaryKey.class, in);
fail();
} catch (RealmException ignored) {
} finally {
realm.commitTransaction();
in.close();
}
}
use of io.realm.exceptions.RealmException in project realm-java by realm.
the class SyncObjectServerFacade method init.
@Override
public void init(Context context) {
//noinspection TryWithIdenticalCatches
try {
// FIXME: Reflection can be avoided by moving some functions of SyncManager and ObjectServer out of public
Class<?> syncManager = Class.forName("io.realm.ObjectServer");
Method method = syncManager.getDeclaredMethod("init", Context.class);
method.setAccessible(true);
method.invoke(null, context);
} catch (NoSuchMethodException e) {
throw new RealmException("Could not initialize the Realm Object Server", e);
} catch (InvocationTargetException e) {
throw new RealmException("Could not initialize the Realm Object Server", e);
} catch (IllegalAccessException e) {
throw new RealmException("Could not initialize the Realm Object Server", e);
} catch (ClassNotFoundException e) {
throw new RealmException("Could not initialize the Realm Object Server", e);
}
if (applicationContext == null) {
applicationContext = context;
applicationContext.registerReceiver(new NetworkStateReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
}
use of io.realm.exceptions.RealmException in project realm-java by realm.
the class SyncObjectServerFacade method invokeRemoveSession.
//FIXME remove this reflection call once we redesign the SyncManager to separate interface
// from implementation to avoid issue like exposing internal method like SyncManager#removeSession
// or SyncSession#close. This happens because SyncObjectServerFacade is internal, whereas
// SyncManager#removeSession or SyncSession#close are package private & should not be public.
private void invokeRemoveSession(SyncConfiguration syncConfig) {
try {
if (removeSessionMethod == null) {
synchronized (SyncObjectServerFacade.class) {
if (removeSessionMethod == null) {
Method removeSession = SyncManager.class.getDeclaredMethod("removeSession", SyncConfiguration.class);
removeSession.setAccessible(true);
removeSessionMethod = removeSession;
}
}
}
removeSessionMethod.invoke(null, syncConfig);
} catch (NoSuchMethodException e) {
throw new RealmException("Could not lookup method to remove session: " + syncConfig.toString(), e);
} catch (InvocationTargetException e) {
throw new RealmException("Could not invoke method to remove session: " + syncConfig.toString(), e);
} catch (IllegalAccessException e) {
throw new RealmException("Could not remove session: " + syncConfig.toString(), e);
}
}
Aggregations