use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class Geo method getPoints.
public void getPoints(final String geofenceName, final BackendlessGeoQuery query, final AsyncCallback<List<GeoPoint>> responder) {
try {
checkGeoQuery(query);
CollectionAdaptingPolicy<GeoPoint> adaptingPolicy = new CollectionAdaptingPolicy<>();
Invoker.invokeAsync(GEO_MANAGER_SERVER_ALIAS, "getPoints", new Object[] { geofenceName, query }, new AsyncCallback<List<GeoPoint>>() {
@Override
public void handleResponse(List<GeoPoint> response) {
if (responder != null)
responder.handleResponse(response);
}
@Override
public void handleFault(BackendlessFault fault) {
responder.handleFault(fault);
}
}, new AdaptingResponder<>(GeoPoint.class, adaptingPolicy));
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class Persistence method find.
public <E> void find(Class<E> entity, DataQueryBuilder queryBuilder, AsyncCallback<List<E>> responder) {
if (entity == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_ENTITY);
if (queryBuilder == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
BackendlessDataQuery dataQuery = queryBuilder.build();
try {
Object[] args = new Object[] { BackendlessSerializer.getSimpleName(entity), dataQuery };
Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "find", args, responder, ResponderHelper.getCollectionAdaptingResponder(entity));
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class Persistence method findById.
protected <E> void findById(E entity, List<String> relations, Integer relationsDepth, AsyncCallback<E> responder) {
try {
if (entity == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_ENTITY);
IChainedResponder chainedResponder = new AdaptingResponder<E>((Class<E>) entity.getClass(), new PoJoAdaptingPolicy<E>());
Object entityArg = ReflectionUtil.hasField(entity.getClass(), Persistence.DEFAULT_OBJECT_ID_FIELD) ? entity : FootprintsManager.getInstance().getObjectId(entity);
Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", new Object[] { BackendlessSerializer.getSimpleName(entity.getClass()), entityArg, relations, relationsDepth }, responder, chainedResponder);
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class Persistence method save.
public <E> void save(final E entity, final AsyncCallback<E> responder) {
try {
if (entity == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_ENTITY);
checkDeclaredType(entity.getClass());
final Map<String, Object> serializedEntity = BackendlessSerializer.serializeToMap(entity);
MapEntityUtil.removeNullsAndRelations(serializedEntity);
MessageWriter.setObjectSubstitutor(new IObjectSubstitutor() {
@Override
public Object substitute(Object o) {
if (o == entity)
return serializedEntity;
else
return o;
}
});
AsyncCallback<E> callbackOverrider;
if (serializedEntity.get(Persistence.DEFAULT_OBJECT_ID_FIELD) == null) {
callbackOverrider = new AsyncCallback<E>() {
@Override
public void handleResponse(E newEntity) {
MessageWriter.setObjectSubstitutor(null);
FootprintsManager.getInstance().Inner.duplicateFootprintForObject(serializedEntity, newEntity, entity);
Footprint footprint = FootprintsManager.getInstance().getEntityFootprint(newEntity);
if (footprint != null)
footprint.initObjectId(entity);
if (responder != null)
responder.handleResponse(newEntity);
}
@Override
public void handleFault(BackendlessFault fault) {
MessageWriter.setObjectSubstitutor(null);
if (responder != null)
responder.handleFault(fault);
}
};
} else {
callbackOverrider = new AsyncCallback<E>() {
@Override
public void handleResponse(E newEntity) {
FootprintsManager.getInstance().Inner.updateFootprintForObject(serializedEntity, newEntity, entity);
Footprint footprint = FootprintsManager.getInstance().getEntityFootprint(newEntity);
if (footprint != null)
footprint.initObjectId(entity);
if (responder != null)
responder.handleResponse(newEntity);
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
};
}
String method = "create";
if (serializedEntity.containsKey(Persistence.DEFAULT_OBJECT_ID_FIELD) && serializedEntity.get(Persistence.DEFAULT_OBJECT_ID_FIELD) != null)
method = "save";
Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, method, new Object[] { BackendlessSerializer.getSimpleName(entity.getClass()), entity }, callbackOverrider, ResponderHelper.getPOJOAdaptingResponder(entity.getClass()));
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class Persistence method getObjectCount.
<E> void getObjectCount(final Class<E> entity, AsyncCallback<Integer> responder) {
try {
Object[] args = new Object[] { BackendlessSerializer.getSimpleName(entity) };
Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args, responder);
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
Aggregations