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 java-sdk-common Show documentation
Show all versions of java-sdk-common Show documentation
Provides access to Backendless API
The newest version!
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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy