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

com.backendless.DataStoreFactory Maven / Gradle / Ivy

There is a newer version: 7.0-alpha
Show newest version
/*
 * ********************************************************************************************************************
 *  

* BACKENDLESS.COM CONFIDENTIAL *

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

* Copyright 2(Integer)null12 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; import com.backendless.async.callback.AsyncCallback; import com.backendless.exceptions.BackendlessException; import com.backendless.persistence.BackendlessSerializer; import com.backendless.persistence.DataQueryBuilder; import com.backendless.persistence.LoadRelationsQueryBuilder; import java.util.ArrayList; import java.util.Collection; import java.util.List; class DataStoreFactory { private static final List emptyRelations = new ArrayList(); protected static IDataStore createDataStore( final Class entityClass ) { return new IDataStore() { @Override public E save( final E entity ) throws BackendlessException { return Backendless.Persistence.save( entity ); } @Override public void save( final E entity, final AsyncCallback responder ) { Backendless.Persistence.save( entity, responder ); } @Override public Long remove( final E entity ) throws BackendlessException { return Backendless.Persistence.remove( entity ); } @Override public void remove( final E entity, final AsyncCallback responder ) { Backendless.Persistence.remove( entity, responder ); } @Override public E findFirst() throws BackendlessException { return Backendless.Persistence.first( entityClass ); } @Override public E findFirst( Integer relationsDepth ) throws BackendlessException { return findFirst( emptyRelations, relationsDepth ); } @Override public E findFirst( List relations ) throws BackendlessException { return findFirst( relations, (Integer)null ); } private E findFirst( List relations, Integer relationsDepth ) throws BackendlessException { return Backendless.Persistence.first( entityClass, relations, relationsDepth ); } @Override public int getObjectCount() { return Backendless.Persistence.getObjectCount( entityClass ); } @Override public int getObjectCount( DataQueryBuilder dataQueryBuilder ) { return Backendless.Persistence.getObjectCount( entityClass, dataQueryBuilder ); } public void findFirst( final AsyncCallback responder ) { Backendless.Persistence.first( entityClass, responder ); } @Override public void findFirst( Integer relationsDepth, final AsyncCallback responder ) { findFirst( emptyRelations, relationsDepth, responder ); } @Override public void findFirst( List relations, AsyncCallback responder ) { findFirst( relations, (Integer)null, responder ); } private void findFirst( List relations, Integer relationsDepth, final AsyncCallback responder ) { Backendless.Persistence.first( entityClass, relations, relationsDepth, responder ); } @Override public E findLast() throws BackendlessException { return Backendless.Persistence.last( entityClass ); } @Override public E findLast( Integer relationsDepth ) throws BackendlessException { return findLast( emptyRelations, relationsDepth ); } @Override public E findLast( List relations ) throws BackendlessException { return findLast( relations, (Integer)null ); } private E findLast( List relations, Integer relationsDepth ) throws BackendlessException { return Backendless.Persistence.last( entityClass, relations, relationsDepth ); } @Override public void findLast( final AsyncCallback responder ) { Backendless.Persistence.last( entityClass, responder ); } @Override public void findLast( Integer relationsDepth, final AsyncCallback responder ) { findLast( emptyRelations, relationsDepth, responder ); } @Override public void findLast( List relations, AsyncCallback responder ) { findLast( relations, (Integer)null, responder ); } private void findLast( List relations, Integer relationsDepth, final AsyncCallback responder ) { Backendless.Persistence.last( entityClass, relations, relationsDepth, responder ); } @Override public List find() throws BackendlessException { return Backendless.Persistence.find( entityClass, DataQueryBuilder.create() ); } @Override public List find( DataQueryBuilder dataQueryBuilder ) throws BackendlessException { return Backendless.Persistence.find( entityClass, dataQueryBuilder ); } @Override public void find( AsyncCallback> responder ) { Backendless.Persistence.find( entityClass, DataQueryBuilder.create(), responder ); } @Override public void find( DataQueryBuilder dataQueryBuilder, AsyncCallback> responder ) { Backendless.Persistence.find( entityClass, dataQueryBuilder, responder ); } @Override public E findById( String objectId ) throws BackendlessException { return findById( objectId, emptyRelations ); } @Override public E findById( String objectId, List relations ) throws BackendlessException { return Backendless.Persistence.findById( entityClass, objectId, relations ); } @Override public E findById( String objectId, Integer relationsDepth ) throws BackendlessException { return Backendless.Persistence.findById( entityClass, objectId, emptyRelations, relationsDepth ); } @Override public E findById( String objectId, List relations, Integer relationsDepth ) throws BackendlessException { return Backendless.Persistence.findById( entityClass, objectId, relations, relationsDepth ); } @Override public E findById( E entity ) { return findById( entity, emptyRelations ); } @Override public E findById( E entity, List relations ) { return findById( entity, relations, (Integer)null ); } @Override public E findById( E entity, Integer relationsDepth ) { return findById( entity, emptyRelations, relationsDepth ); } @Override public E findById( E entity, List relations, Integer relationsDepth ) { return Backendless.Data.findById( entity, relations, relationsDepth ); } @Override public void findById( String objectId, AsyncCallback responder ) { findById( objectId, emptyRelations, responder ); } @Override public void findById( String objectId, List relations, AsyncCallback responder ) { Backendless.Persistence.findById( entityClass, objectId, relations, responder ); } @Override public void findById( String objectId, Integer relationsDepth, AsyncCallback responder ) { findById( objectId, emptyRelations, relationsDepth, responder ); } @Override public void findById( String objectId, List relations, Integer relationsDepth, AsyncCallback responder ) { Backendless.Persistence.findById( entityClass, objectId, relations, relationsDepth, responder ); } @Override public void findById( E entity, AsyncCallback responder ) { findById( entity, emptyRelations, responder ); } @Override public void findById( E entity, List relations, AsyncCallback responder ) { findById( entity, relations, (Integer)null, responder ); } @Override public void findById( E entity, Integer relationsDepth, AsyncCallback responder ) { findById( entity, emptyRelations, relationsDepth, responder ); } @Override public void findById( E entity, List relations, Integer relationsDepth, AsyncCallback responder ) { Backendless.Data.findById( entity, relations, relationsDepth, responder ); } @Override public E findById( String id, DataQueryBuilder queryBuilder ) throws BackendlessException { return Backendless.Persistence.findById( entityClass, id, queryBuilder ); } @Override public E findById( E entity, DataQueryBuilder queryBuilder ) throws BackendlessException { return Backendless.Persistence.findById( entity, queryBuilder ); } @Override public void findById( String id, DataQueryBuilder queryBuilder, AsyncCallback responder ) { Backendless.Persistence.findById( entityClass, id, queryBuilder, responder ); } @Override public void findById( E entity, DataQueryBuilder queryBuilder, AsyncCallback responder ) { Backendless.Persistence.findById( entity, queryBuilder, responder ); } @Override public List loadRelations( String objectId, LoadRelationsQueryBuilder queryBuilder ) { String typeName = BackendlessSerializer.getSimpleName( entityClass ); return Backendless.Persistence.loadRelations( typeName, objectId, queryBuilder, queryBuilder.getRelationType() ); } @Override public void loadRelations( String objectId, LoadRelationsQueryBuilder queryBuilder, AsyncCallback> responder ) { String typeName = BackendlessSerializer.getSimpleName( entityClass ); Backendless.Persistence.loadRelations( typeName, objectId, queryBuilder, queryBuilder.getRelationType(), responder ); } @Override public void getObjectCount( AsyncCallback responder ) { Backendless.Persistence.getObjectCount( entityClass, responder ); } @Override public void getObjectCount( DataQueryBuilder dataQueryBuilder, AsyncCallback responder ) { Backendless.Persistence.getObjectCount( entityClass, dataQueryBuilder, responder ); } @Override public int addRelation( E parent, String relationColumnName, Collection children ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Collection childObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = Persistence.getEntityId( child ); childObjectIds.add( childObjectId ); } Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, childObjectIds }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args ); } @Override public void addRelation( E parent, String relationColumnName, Collection children, AsyncCallback callback ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Collection childObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = Persistence.getEntityId( child ); childObjectIds.add( childObjectId ); } Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, childObjectIds }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args, callback ); } @Override public int addRelation( E parent, String relationColumnName, String whereClause ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, whereClause }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args ); } @Override public void addRelation( E parent, String relationColumnName, String whereClause, AsyncCallback callback ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, whereClause }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args, callback ); } @Override public int setRelation( E parent, String relationColumnName, Collection children ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Collection childObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = Persistence.getEntityId( child ); childObjectIds.add( childObjectId ); } Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, childObjectIds }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "setRelation", args ); } @Override public void setRelation( E parent, String relationColumnName, Collection children, AsyncCallback callback ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Collection childObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = Persistence.getEntityId( child ); childObjectIds.add( childObjectId ); } Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, childObjectIds }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "setRelation", args, callback ); } @Override public int setRelation( E parent, String relationColumnName, String whereClause ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, whereClause }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "setRelation", args ); } @Override public void setRelation( E parent, String relationColumnName, String whereClause, AsyncCallback callback ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, whereClause }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "addRelation", args, callback ); } @Override public int deleteRelation( E parent, String relationColumnName, Collection children ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Collection childObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = Persistence.getEntityId( child ); childObjectIds.add( childObjectId ); } Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, childObjectIds }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args ); } @Override public void deleteRelation( E parent, String relationColumnName, Collection children, AsyncCallback callback ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Collection childObjectIds = new ArrayList<>(); for( R child : children ) { String childObjectId = Persistence.getEntityId( child ); childObjectIds.add( childObjectId ); } Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, childObjectIds }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args, callback ); } @Override public int deleteRelation( E parent, String relationColumnName, String whereClause ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, whereClause }; return Invoker.invokeSync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args ); } @Override public void deleteRelation( E parent, String relationColumnName, String whereClause, AsyncCallback callback ) { String parentTableName = BackendlessSerializer.getSimpleName( parent.getClass() ); String parentObjectId = Persistence.getEntityId( parent ); Object[] args = new Object[] { parentTableName, relationColumnName, parentObjectId, whereClause }; Invoker.invokeAsync( Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "deleteRelation", args, callback ); } }; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy