Search in sources :

Example 51 with BackendlessFault

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));
    }
}
Also used : CollectionAdaptingPolicy(com.backendless.core.responder.policy.CollectionAdaptingPolicy) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 52 with BackendlessFault

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));
    }
}
Also used : BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 53 with BackendlessFault

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));
    }
}
Also used : AdaptingResponder(com.backendless.core.responder.AdaptingResponder) IChainedResponder(weborb.client.IChainedResponder) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 54 with BackendlessFault

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));
    }
}
Also used : IObjectSubstitutor(weborb.writer.IObjectSubstitutor) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 55 with BackendlessFault

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));
    }
}
Also used : BackendlessFault(com.backendless.exceptions.BackendlessFault)

Aggregations

BackendlessFault (com.backendless.exceptions.BackendlessFault)65 AnonymousObject (weborb.reader.AnonymousObject)15 NamedObject (weborb.reader.NamedObject)15 AsyncCallback (com.backendless.async.callback.AsyncCallback)11 Intent (android.content.Intent)10 View (android.view.View)10 TextView (android.widget.TextView)6 BackendlessCollection (com.backendless.BackendlessCollection)6 List (java.util.List)6 Typeface (android.graphics.Typeface)5 BackendlessDataQuery (com.backendless.persistence.BackendlessDataQuery)5 EditText (android.widget.EditText)4 CollectionAdaptingPolicy (com.backendless.core.responder.policy.CollectionAdaptingPolicy)4 BackendlessFile (com.backendless.files.BackendlessFile)4 ArrayList (java.util.ArrayList)4 Button (android.widget.Button)3 GeoPoint (com.backendless.geo.GeoPoint)3 ProgressDialog (android.app.ProgressDialog)2 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2