use of io.realm.mongodb.AppException in project realm-java by realm.
the class RealmResultTaskImpl method getAsync.
@Override
public void getAsync(App.Callback<T> callback) {
Util.checkNull(callback, "callback");
Util.checkLooperThread("RealmResultTaskImpl can only run on looper threads.");
RealmNotifier handler = new AndroidRealmNotifier(null, new AndroidCapabilities());
pendingTask = service.submit(new Runnable() {
@Override
public void run() {
try {
postSuccess(handler, executor.run(), callback);
} catch (AppException e) {
postError(handler, e, callback);
} catch (Throwable e) {
postError(handler, new AppException(ErrorCode.UNKNOWN, "Unexpected error", e), callback);
}
}
});
}
use of io.realm.mongodb.AppException in project realm-java by realm.
the class JniBsonProtocol method decode.
public static <T> T decode(String string, Decoder<T> decoder) {
try {
StringReader stringReader = new StringReader(string);
JsonReader jsonReader = new JsonReader(stringReader);
jsonReader.readStartDocument();
jsonReader.readName(VALUE);
T value = decoder.decode(jsonReader, DecoderContext.builder().build());
jsonReader.readEndDocument();
return value;
} catch (CodecConfigurationException e) {
// might be missing
throw new AppException(ErrorCode.BSON_CODEC_NOT_FOUND, "Could not resolve decoder for end type" + string, e);
} catch (Exception e) {
throw new AppException(ErrorCode.BSON_DECODING, "Error decoding value " + string, e);
}
}
use of io.realm.mongodb.AppException in project realm-java by realm.
the class JniBsonProtocol method encode.
public static <T> String encode(T value, Encoder<T> encoder) {
try {
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(stringWriter, writerSettings);
jsonWriter.writeStartDocument();
jsonWriter.writeName(VALUE);
encoder.encode(jsonWriter, value, EncoderContext.builder().build());
jsonWriter.writeEndDocument();
return stringWriter.toString();
} catch (CodecConfigurationException e) {
// might be missing
throw new AppException(ErrorCode.BSON_CODEC_NOT_FOUND, "Could not resolve encoder for end type", e);
} catch (Exception e) {
throw new AppException(ErrorCode.BSON_ENCODING, "Error encoding value", e);
}
}
use of io.realm.mongodb.AppException in project realm-java by realm.
the class SyncSession method notifySessionError.
// This callback will happen on the thread running the Sync Client.
void notifySessionError(String nativeErrorCategory, int nativeErrorCode, String errorMessage, String clientResetPathInfo) {
if (errorHandler == null) {
return;
}
ErrorCode errCode = ErrorCode.fromNativeError(nativeErrorCategory, nativeErrorCode);
if (errCode == ErrorCode.CLIENT_RESET) {
// errorMessage contains the path to the backed up file
if (clientResetPathInfo == null) {
throw new IllegalStateException("Missing Client Reset info.");
}
RealmConfiguration backupRealmConfiguration = configuration.forErrorRecovery(clientResetPathInfo);
if (clientResetHandler instanceof ManuallyRecoverUnsyncedChangesStrategy) {
((ManuallyRecoverUnsyncedChangesStrategy) clientResetHandler).onClientReset(this, new ClientResetRequiredError(appNativePointer, errCode, errorMessage, configuration, backupRealmConfiguration));
} else if (clientResetHandler instanceof DiscardUnsyncedChangesStrategy) {
((DiscardUnsyncedChangesStrategy) clientResetHandler).onError(this, new ClientResetRequiredError(appNativePointer, errCode, errorMessage, configuration, backupRealmConfiguration));
}
} else {
AppException wrappedError;
if (errCode == ErrorCode.UNKNOWN) {
wrappedError = new AppException(nativeErrorCategory, nativeErrorCode, errorMessage);
} else {
wrappedError = new AppException(errCode, errorMessage);
}
errorHandler.onError(this, wrappedError);
}
}
use of io.realm.mongodb.AppException in project realm-java by realm.
the class UpdateDescription method fromBsonDocument.
/**
* Converts an update description BSON document from a MongoDB Change Event into an
* UpdateDescription object.
*
* @param document the
* @return the converted UpdateDescription
*/
public static UpdateDescription fromBsonDocument(final BsonDocument document) {
try {
checkContainsKey(Fields.UPDATED_FIELDS_FIELD, document, "document");
checkContainsKey(Fields.REMOVED_FIELDS_FIELD, document, "document");
} catch (IllegalArgumentException exception) {
throw new AppException(ErrorCode.EVENT_DESERIALIZING, exception);
}
final BsonArray removedFieldsArr = document.getArray(Fields.REMOVED_FIELDS_FIELD);
final Set<String> removedFields = new HashSet<>(removedFieldsArr.size());
for (final BsonValue field : removedFieldsArr) {
removedFields.add(field.asString().getValue());
}
return new UpdateDescription(document.getDocument(Fields.UPDATED_FIELDS_FIELD), removedFields);
}
Aggregations