All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.backendless.persistence.MapDrivenDataStore Maven / Gradle / Ivy

The newest version!
/*
 * ********************************************************************************************************************
 *  

* BACKENDLESS.COM CONFIDENTIAL *

* ******************************************************************************************************************** *

* Copyright 2012 BACKENDLESS.COM. All Rights Reserved. *

* NOTICE: All information contained herein is, and remains the property of Backendless.com and its suppliers, * if any. The intellectual and technical concepts contained herein are proprietary to Backendless.com and its * suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret * or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden * unless prior written permission is obtained from Backendless.com. *

* ******************************************************************************************************************** */ package com.backendless.persistence; import com.backendless.IDataStore; import com.backendless.Invoker; import com.backendless.Persistence; import com.backendless.async.callback.AsyncCallback; import com.backendless.commons.persistence.GroupResult; import com.backendless.core.responder.AdaptingResponder; import com.backendless.exceptions.BackendlessException; import com.backendless.exceptions.BackendlessFault; import com.backendless.exceptions.ExceptionMessage; import com.backendless.rt.data.EventHandler; import com.backendless.utils.ResponderHelper; import weborb.client.Fault; import weborb.client.IRawResponder; import weborb.client.IResponder; import weborb.exceptions.AdaptingException; import weborb.reader.AnonymousObject; import weborb.reader.NamedObject; import weborb.types.IAdaptingType; import weborb.v3types.ErrMessage; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; public class MapDrivenDataStore implements IDataStore { private final String tableName; private final Persistence persistence; private final EventHandler eventHandler; public MapDrivenDataStore( String tableName, Persistence persistence, EventHandler eventHandler ) { this.tableName = tableName; this.persistence = persistence; this.eventHandler = eventHandler; } @Override public List create( List objects ) throws BackendlessException { return create( objects, null, false ); } @Override public void create( List objects, AsyncCallback> responder ) { create( objects, responder, true ); } private List create( List objects, AsyncCallback> responder, boolean async ) throws BackendlessException { if( objects == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_BULK ); if( objects.isEmpty() ) return new ArrayList<>(); Object[] args = new Object[] { tableName, objects }; if( async ) Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "createBulk", args, responder, ResponderHelper.getCollectionAdaptingResponder( String.class ) ); else return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "createBulk", args, ResponderHelper.getCollectionAdaptingResponder( String.class ) ); return null; } @Override public Map save( Map entity ) throws BackendlessException { return save( entity, false ); } @Override public Map save( Map entity, boolean isUpsert ) throws BackendlessException { if( entity == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ENTITY ); Object[] args = new Object[] { tableName, entity }; String methodName; if( isUpsert ) { methodName = "upsert"; } else { methodName = "save"; } return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, methodName, args, new MapDrivenResponder() ); } @Override public void save( Map entity, final AsyncCallback responder ) { save( entity, false, responder ); } @Override public void save( Map entity, boolean isUpsert, AsyncCallback responder ) { try { if( entity == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ENTITY ); Object[] args = new Object[] { tableName, entity }; String methodName; if( isUpsert ) { methodName = "upsert"; } else { methodName = "save"; } Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, methodName, args, responder, new MapDrivenResponder() ); } catch( Throwable e ) { if( responder != null ) responder.handleFault( new BackendlessFault( e ) ); } } @Override public Map deepSave( Map entity ) throws BackendlessException { if( entity == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ENTITY ); Object[] args = new Object[] { tableName, entity }; Map newEntity = Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deepSave", args, new MapDrivenResponder() ); return newEntity; } @Override public void deepSave( Map entity, final AsyncCallback responder ) { try { if( entity == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ENTITY ); Object[] args = new Object[] { tableName, entity }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deepSave", args, responder, new MapDrivenResponder() ); } catch( Throwable e ) { if( responder != null ) responder.handleFault( new BackendlessFault( e ) ); } } @Override public Long remove( Map entity ) throws BackendlessException { if( entity == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ENTITY ); Object[] args = new Object[] { tableName, entity }; Object result = Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "remove", args ); return ((Number) result).longValue(); } @Override public void remove( Map entity, final AsyncCallback responder ) { try { if( entity == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ENTITY ); AsyncCallback removalCallback = new AsyncCallback() { @Override public void handleResponse( Object response ) { responder.handleResponse( ((Number) response).longValue() ); } @Override public void handleFault( BackendlessFault fault ) { if( responder != null ) responder.handleFault( fault ); } }; Object[] args = new Object[] { tableName, entity }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "remove", args, removalCallback ); } catch( Throwable e ) { if( responder != null ) responder.handleFault( new BackendlessFault( e ) ); } } @Override public int remove( final String whereClause ) throws BackendlessException { Object[] args = new Object[] { tableName, whereClause }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "removeBulk", args ); } @Override public void remove( final String whereClause, AsyncCallback responder ) throws BackendlessException { Object[] args = new Object[] { tableName, whereClause }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "removeBulk", args, responder ); } @Override public int update( final String whereClause, Map changes ) throws BackendlessException { Object[] args = new Object[] { tableName, whereClause, changes }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "updateBulk", args ); } @Override public void update( final String whereClause, Map changes, AsyncCallback responder ) throws BackendlessException { Object[] args = new Object[] { tableName, whereClause, changes }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "updateBulk", args, responder ); } @Override public Map findFirst() throws BackendlessException { Object[] args = new Object[] { tableName }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "first", args, new MapDrivenResponder() ); } @Override public Map findFirst( Integer relationsDepth ) throws BackendlessException { return findFirst( Collections.emptyList(), relationsDepth, null ); } @Override public Map findFirst( List relations ) throws BackendlessException { return findFirst( relations, null, null ); } @Override public Map findFirst( List relations, Integer relationsDepth, Integer relationsPageSize ) throws BackendlessException { Object[] args = new Object[] { tableName, relations, relationsDepth, relationsPageSize }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "first", args, new MapDrivenResponder() ); } @Override public void findFirst( AsyncCallback callback ) { try { Object[] args = new Object[] { tableName }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "first", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public void findFirst( Integer relationsDepth, AsyncCallback callback ) { findFirst( Collections.emptyList(), relationsDepth, null, callback ); } @Override public void findFirst( List relations, AsyncCallback callback ) { findFirst( relations, null, null, callback ); } @Override public void findFirst( List relations, Integer relationsDepth, Integer relationsPageSize, AsyncCallback callback ) { try { Object[] args = new Object[] { tableName, relations, relationsDepth, relationsPageSize }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "first", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public Map findLast() throws BackendlessException { Object[] args = new Object[] { tableName }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "last", args, new MapDrivenResponder() ); } @Override public Map findLast( Integer relationsDepth ) throws BackendlessException { return findLast( Collections.emptyList(), relationsDepth, null ); } @Override public Map findLast( List relations ) throws BackendlessException { return findLast( relations, null, null ); } @Override public Map findLast( List relations, Integer relationsDepth, Integer relationsPageSize ) throws BackendlessException { Object[] args = new Object[] { tableName, relations, relationsDepth, relationsPageSize }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "last", args, new MapDrivenResponder() ); } @Override public void findLast( AsyncCallback callback ) { try { Object[] args = new Object[] { tableName }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "last", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public void findLast( Integer relationsDepth, AsyncCallback callback ) { findLast( Collections.emptyList(), relationsDepth, null, callback ); } @Override public void findLast( List relations, AsyncCallback callback ) { findLast( relations, null, null, callback ); } @Override public void findLast( List relations, Integer relationsDepth, Integer relationPageSize, AsyncCallback callback ) { try { Object[] args = new Object[] { tableName, relations, relationsDepth }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "last", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public List find() throws BackendlessException { return find( DataQueryBuilder.create() ); } @Override public List find( DataQueryBuilder dataQuery ) throws BackendlessException { Object[] args = new Object[] { tableName, dataQuery.build() }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "find", args, ResponderHelper.getCollectionAdaptingResponder( HashMap.class ) ); } @Override public void find( AsyncCallback> callback ) { find( DataQueryBuilder.create(), callback ); } @Override public void find( final DataQueryBuilder dataQuery, final AsyncCallback> callback ) { try { Object[] args = new Object[] { tableName, dataQuery.build() }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "find", args, callback, ResponderHelper.getCollectionAdaptingResponder( HashMap.class ) ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public GroupResult group( GroupDataQueryBuilder dataQuery ) { Object[] args = new Object[] { tableName, dataQuery.build() }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "group", args, ResponderHelper.getGroupResultAdaptingResponder( HashMap.class ) ); } @Override public void group( final GroupDataQueryBuilder dataQuery, final AsyncCallback> callback ) { try { Object[] args = new Object[] { tableName, dataQuery.build() }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "group", args, callback, ResponderHelper.getGroupResultAdaptingResponder( HashMap.class ) ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public Map findById( String id ) throws BackendlessException { return findById( id, Collections.emptyList() ); } @Override public Map findById( String id, List relations ) throws BackendlessException { if( id == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ID ); Object[] args = new Object[] { tableName, id, relations }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, new MapDrivenResponder() ); } @Override public Map findById( String id, Integer relationsDepth ) throws BackendlessException { return findById( id, Collections.emptyList(), relationsDepth ); } @Override public Map findById( String id, List relations, Integer relationsDepth ) throws BackendlessException { if( id == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ID ); Object[] args = new Object[] { tableName, id, relations, relationsDepth }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, new MapDrivenResponder() ); } @Override public Map findById( Map entity ) throws BackendlessException { return findById( entity, Collections.emptyList(), (Integer) null ); } @Override public Map findById( Map entity, List relations ) throws BackendlessException { return findById( entity, relations, (Integer) null ); } @Override public Map findById( Map entity, Integer relationsDepth ) throws BackendlessException { return findById( entity, Collections.emptyList(), relationsDepth ); } @Override public Map findById( Map entity, List relations, Integer relationsDepth ) throws BackendlessException { Object[] args = new Object[] { tableName, entity, relations, relationsDepth }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, new MapDrivenResponder() ); } @Override public void findById( String id, AsyncCallback callback ) { findById( id, Collections.emptyList(), callback ); } @Override public void findById( String id, List relations, AsyncCallback callback ) { findById( id, relations, null, callback ); } @Override public void findById( String id, Integer relationsDepth, AsyncCallback callback ) { findById( id, Collections.emptyList(), relationsDepth, callback ); } @Override public void findById( String id, List relations, Integer relationsDepth, AsyncCallback callback ) { try { if( id == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ID ); Object[] args = new Object[] { tableName, id, relations, relationsDepth }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public void findById( Map entity, AsyncCallback callback ) { findById( entity, Collections.emptyList(), callback ); } @Override public void findById( Map entity, List relations, AsyncCallback callback ) { findById( entity, relations, null, callback ); } @Override public void findById( Map entity, Integer relationsDepth, AsyncCallback callback ) { findById( entity, Collections.emptyList(), relationsDepth, callback ); } @Override public void findById( Map entity, List relations, Integer relationsDepth, AsyncCallback callback ) { try { if( entity == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_ENTITY ); Object[] args = new Object[] { tableName, entity, relations, relationsDepth }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public Map findById( String id, DataQueryBuilder queryBuilder ) throws BackendlessException { Object[] args = new Object[] { tableName, id, queryBuilder.build() }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, new MapDrivenResponder() ); } @Override public Map findById( Map entity, DataQueryBuilder queryBuilder ) throws BackendlessException { Object[] args = new Object[] { tableName, entity, queryBuilder.build() }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, new MapDrivenResponder() ); } @Override public void findById( String id, DataQueryBuilder queryBuilder, AsyncCallback callback ) { try { Object[] args = new Object[] { tableName, id, queryBuilder.build() }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public void findById( Map entity, DataQueryBuilder queryBuilder, AsyncCallback callback ) { try { Object[] args = new Object[] { tableName, entity, queryBuilder.build() }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "findById", args, callback, new MapDrivenResponder() ); } catch( Throwable e ) { if( callback != null ) callback.handleFault( new BackendlessFault( e ) ); } } @Override public List loadRelations( String objectId, LoadRelationsQueryBuilder queryBuilder ) { return persistence.loadRelations( tableName, objectId, queryBuilder, queryBuilder.getRelationType() ); } @Override public void loadRelations( String objectId, LoadRelationsQueryBuilder queryBuilder, AsyncCallback> callback ) { persistence.loadRelations( tableName, objectId, queryBuilder, queryBuilder.getRelationType(), callback ); } @Override public int getObjectCount() { Object[] args = new Object[] { tableName }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args ); } @Override public int getObjectCount( DataQueryBuilder dataQueryBuilder ) { if( dataQueryBuilder == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_FIELD( "dataQueryBuilder" ) ); BackendlessDataQuery dataQuery = dataQueryBuilder.build(); Object[] args = new Object[] { tableName, dataQuery }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args ); } @Override public int getObjectCountInGroup( GroupDataQueryBuilder dataQueryBuilder ) { if( dataQueryBuilder == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_FIELD( "dataQueryBuilder" ) ); BackendlessDataQuery dataQuery = dataQueryBuilder.build(); Object[] args = new Object[] { tableName, dataQuery }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "countInGroup", args ); } @Override public void getObjectCount( AsyncCallback responder ) { try { Object[] args = new Object[] { tableName }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args, responder ); } catch( Throwable e ) { if( responder != null ) responder.handleFault( new BackendlessFault( e ) ); } } @Override public void getObjectCount( DataQueryBuilder dataQueryBuilder, AsyncCallback responder ) { try { if( dataQueryBuilder == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_FIELD( "dataQueryBuilder" ) ); BackendlessDataQuery dataQuery = dataQueryBuilder.build(); Object[] args = new Object[] { tableName, dataQuery }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args, responder ); } catch( Throwable e ) { if( responder != null ) responder.handleFault( new BackendlessFault( e ) ); } } @Override public void getObjectCountInGroup( GroupDataQueryBuilder dataQueryBuilder, AsyncCallback responder ) { try { if( dataQueryBuilder == null ) throw new IllegalArgumentException( ExceptionMessage.NULL_FIELD( "dataQueryBuilder" ) ); BackendlessDataQuery dataQuery = dataQueryBuilder.build(); Object[] args = new Object[] { tableName, dataQuery }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "countInGroup", args, responder ); } catch( Throwable e ) { if( responder != null ) responder.handleFault( new BackendlessFault( e ) ); } } @Override public int addRelation( Map parent, String relationColumnName, Collection children ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); Collection childrenObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = child instanceof Map ? (String) ((Map) child).get( Persistence.DEFAULT_OBJECT_ID_FIELD ) : Persistence.getEntityId( child ); childrenObjectIds.add( childObjectId ); } return addRelation( parentObjectId, relationColumnName, childrenObjectIds ); } @Override public void addRelation( Map parent, String relationColumnName, Collection children, AsyncCallback callback ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); Collection childrenObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = child instanceof Map ? (String) ((Map) child).get( Persistence.DEFAULT_OBJECT_ID_FIELD ) : Persistence.getEntityId( child ); childrenObjectIds.add( childObjectId ); } addRelation( parentObjectId, relationColumnName, childrenObjectIds, callback ); } @Override public int addRelation( Map parent, String relationColumnName, String whereClause ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); return addRelation( parentObjectId, relationColumnName, whereClause ); } @Override public void addRelation( Map parent, String relationColumnName, String whereClause, AsyncCallback callback ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); addRelation( parentObjectId, relationColumnName, whereClause, callback ); } @Override public int setRelation( Map parent, String relationColumnName, Collection children ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); Collection childrenObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = child instanceof Map ? (String) ((Map) child).get( Persistence.DEFAULT_OBJECT_ID_FIELD ) : Persistence.getEntityId( child ); childrenObjectIds.add( childObjectId ); } return setRelation( parentObjectId, relationColumnName, childrenObjectIds ); } @Override public void setRelation( Map parent, String relationColumnName, Collection children, AsyncCallback callback ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); Collection childrenObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = child instanceof Map ? (String) ((Map) child).get( Persistence.DEFAULT_OBJECT_ID_FIELD ) : Persistence.getEntityId( child ); childrenObjectIds.add( childObjectId ); } setRelation( parentObjectId, relationColumnName, childrenObjectIds, callback ); } @Override public int setRelation( Map parent, String relationColumnName, String whereClause ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); return setRelation( parentObjectId, relationColumnName, whereClause ); } @Override public void setRelation( Map parent, String relationColumnName, String whereClause, AsyncCallback callback ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); setRelation( parentObjectId, relationColumnName, whereClause, callback ); } @Override public int deleteRelation( Map parent, String relationColumnName, Collection children ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); Collection childrenObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = child instanceof Map ? (String) ((Map) child).get( Persistence.DEFAULT_OBJECT_ID_FIELD ) : Persistence.getEntityId( child ); childrenObjectIds.add( childObjectId ); } return deleteRelation( parentObjectId, relationColumnName, childrenObjectIds ); } @Override public void deleteRelation( Map parent, String relationColumnName, Collection children, AsyncCallback callback ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); Collection childrenObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = child instanceof Map ? (String) ((Map) child).get( Persistence.DEFAULT_OBJECT_ID_FIELD ) : Persistence.getEntityId( child ); childrenObjectIds.add( childObjectId ); } deleteRelation( parentObjectId, relationColumnName, childrenObjectIds, callback ); } @Override public int deleteRelation( Map parent, String relationColumnName, String whereClause ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); return deleteRelation( parentObjectId, relationColumnName, whereClause ); } @Override public void deleteRelation( Map parent, String relationColumnName, String whereClause, AsyncCallback callback ) { String parentObjectId = (String) parent.get( Persistence.DEFAULT_OBJECT_ID_FIELD ); deleteRelation( parentObjectId, relationColumnName, whereClause, callback ); } @Override public int addRelation( String parentObjectId, String relationColumnName, Collection childrenObjectIds ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, childrenObjectIds }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args ); } @Override public void addRelation( String parentObjectId, String relationColumnName, Collection childrenObjectIds, AsyncCallback callback ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, childrenObjectIds }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args, callback ); } @Override public int addRelation( String parentObjectId, String relationColumnName, String whereClause ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, whereClause }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args ); } @Override public void addRelation( String parentObjectId, String relationColumnName, String whereClause, AsyncCallback callback ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, whereClause }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args, callback ); } @Override public int setRelation( String parentObjectId, String relationColumnName, Collection childrenObjectIds ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, childrenObjectIds }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "setRelation", args ); } @Override public void setRelation( String parentObjectId, String relationColumnName, Collection childrenObjectIds, AsyncCallback callback ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, childrenObjectIds }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "setRelation", args, callback ); } @Override public int setRelation( String parentObjectId, String relationColumnName, String whereClause ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, whereClause }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "setRelation", args ); } @Override public void setRelation( String parentObjectId, String relationColumnName, String whereClause, AsyncCallback callback ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, whereClause }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "setRelation", args, callback ); } @Override public int deleteRelation( String parentObjectId, String relationColumnName, Collection childrenObjectIds ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, childrenObjectIds }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args ); } @Override public void deleteRelation( String parentObjectId, String relationColumnName, Collection childrenObjectIds, AsyncCallback callback ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, childrenObjectIds }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args, callback ); } @Override public int deleteRelation( String parentObjectId, String relationColumnName, String whereClause ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, whereClause }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args ); } @Override public void deleteRelation( String parentObjectId, String relationColumnName, String whereClause, AsyncCallback callback ) { Object[] args = new Object[] { tableName, relationColumnName, parentObjectId, whereClause }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args, callback ); } @Override public EventHandler rt() { return eventHandler; } private static class MapDrivenResponder implements IRawResponder { private IResponder nextResponder; @Override public void setNextResponder( IResponder iResponder ) { this.nextResponder = iResponder; } @Override public void responseHandler( Object adaptingType ) { IAdaptingType type = (IAdaptingType) adaptingType; IAdaptingType bodyHolder = ((NamedObject) type).getTypedObject(); if( ((IAdaptingType) adaptingType).getDefaultType().equals( ErrMessage.class ) ) { if( nextResponder != null ) { nextResponder.errorHandler( AdaptingResponder.adaptFault( (AnonymousObject) bodyHolder ) ); } } else { IAdaptingType entity = (IAdaptingType) ((AnonymousObject) bodyHolder).getProperties().get( "body" ); try { Object adaptedEntity = entity.adapt( HashMap.class ); if( nextResponder != null ) nextResponder.responseHandler( adaptedEntity ); } catch( AdaptingException e ) { errorHandler( new BackendlessFault( e ) ); } } } @Override public void errorHandler( Fault fault ) { nextResponder.errorHandler( fault ); } } }