com.backendless.transaction.UnitOfWorkExecutorImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of backendless Show documentation
Show all versions of backendless Show documentation
Android SDK used by developers to provide Backendless API in apps.
package com.backendless.transaction;
import com.backendless.Invoker;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.core.responder.AdaptingResponder;
import com.backendless.exceptions.ExceptionMessage;
import com.backendless.utils.ResponderHelper;
import weborb.types.Types;
import java.util.Map;
class UnitOfWorkExecutorImpl implements UnitOfWorkExecutor
{
private final static String TRANSACTION_MANAGER_SERVER_ALIAS = "com.backendless.transaction.TransactionService";
private final UnitOfWork unitOfWork;
private final Map clazzes;
UnitOfWorkExecutorImpl( UnitOfWork unitOfWork, Map clazzes )
{
this.unitOfWork = unitOfWork;
this.clazzes = clazzes;
}
@Override
public UnitOfWorkResult execute()
{
return execute( null, false );
}
@Override
public void execute( AsyncCallback responder )
{
execute( responder, true );
}
private UnitOfWorkResult execute( AsyncCallback responder, boolean async )
{
if( unitOfWork.getOperations() == null || unitOfWork.getOperations().isEmpty() )
throw new IllegalArgumentException( ExceptionMessage.LIST_OPERATIONS_NULL_EMPTY );
Object[] args = new Object[]{ unitOfWork };
for( Map.Entry entry : clazzes.entrySet() )
{
if( Types.getMappedClientClass( entry.getKey() ) == null )
{
Types.addClientClassMapping( entry.getKey(), entry.getValue() );
}
}
AdaptingResponder unitOfWorkAdaptingResponder = ResponderHelper.getPOJOAdaptingResponder( UnitOfWorkResult.class );
if( async )
Invoker.invokeAsync( TRANSACTION_MANAGER_SERVER_ALIAS, "execute", args, responder, unitOfWorkAdaptingResponder );
else
return Invoker.invokeSync( TRANSACTION_MANAGER_SERVER_ALIAS, "execute", args, unitOfWorkAdaptingResponder );
return null;
}
}