com.backendless.transaction.UnitOfWorkDeleteImpl 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.Persistence;
import com.backendless.exceptions.ExceptionMessage;
import com.backendless.persistence.BackendlessSerializer;
import com.backendless.transaction.payload.DeleteBulkPayload;
import java.util.List;
import java.util.Map;
class UnitOfWorkDeleteImpl implements UnitOfWorkDelete
{
private final List operations;
private final OpResultIdGenerator opResultIdGenerator;
UnitOfWorkDeleteImpl( List operations, OpResultIdGenerator opResultIdGenerator )
{
this.operations = operations;
this.opResultIdGenerator = opResultIdGenerator;
}
@Override
public OpResult delete( E instance )
{
Map entityMap = SerializationHelper.serializeEntityToMap( instance );
String tableName = BackendlessSerializer.getSimpleName( instance.getClass() );
return delete( tableName, entityMap );
}
@Override
public OpResult delete( String tableName, Map objectMap )
{
String objectId = TransactionHelper.convertObjectMapToObjectId( objectMap );
return delete( tableName, objectId );
}
@Override
public OpResult delete( String tableName, String objectId )
{
String operationResultId = opResultIdGenerator.generateOpResultId( OperationType.DELETE, tableName );
OperationDelete operationDelete = new OperationDelete( OperationType.DELETE, tableName, operationResultId, objectId );
operations.add( operationDelete );
return TransactionHelper.makeOpResult( tableName, operationResultId, OperationType.DELETE );
}
@Override
public OpResult delete( OpResult result )
{
if( result == null )
throw new IllegalArgumentException( ExceptionMessage.NULL_OP_RESULT );
if( !OperationType.supportEntityDescriptionResultType.contains( result.getOperationType() ) )
throw new IllegalArgumentException( ExceptionMessage.REF_TYPE_NOT_SUPPORT );
String operationResultId = opResultIdGenerator.generateOpResultId( OperationType.DELETE, result.getTableName() );
OperationDelete operationDelete = new OperationDelete( OperationType.DELETE, result.getTableName(), operationResultId,
result.resolveTo( Persistence.DEFAULT_OBJECT_ID_FIELD ).makeReference() );
operations.add( operationDelete );
return TransactionHelper.makeOpResult( result.getTableName(), operationResultId, OperationType.DELETE );
}
@Override
public OpResult delete( OpResultValueReference resultIndex )
{
if( resultIndex == null )
throw new IllegalArgumentException( ExceptionMessage.NULL_OP_RESULT_VALUE_REFERENCE );
if( resultIndex.getResultIndex() == null || resultIndex.getPropName() != null )
throw new IllegalArgumentException( ExceptionMessage.OP_RESULT_INDEX_YES_PROP_NAME_NOT );
Map referenceToObjectId = TransactionHelper.convertCreateBulkOrFindResultIndexToObjectId( resultIndex );
String operationResultId = opResultIdGenerator.generateOpResultId( OperationType.DELETE, resultIndex.getOpResult().getTableName() );
OperationDelete operationDelete = new OperationDelete( OperationType.DELETE, resultIndex.getOpResult().getTableName(),
operationResultId, referenceToObjectId );
operations.add( operationDelete );
return TransactionHelper.makeOpResult( resultIndex.getOpResult().getTableName(), operationResultId, OperationType.DELETE );
}
@Override
public OpResult bulkDelete( List instances )
{
if( instances == null || instances.isEmpty() )
throw new IllegalArgumentException( ExceptionMessage.NULL_EMPTY_BULK );
if( instances.get( 0 ) instanceof Map )
throw new IllegalArgumentException( ExceptionMessage.USE_ANOTHER_METHOD_WITH_TABLE_NAME_AND_LIST_OBJECT_MAPS );
else if( instances.get( 0 ) instanceof String )
throw new IllegalArgumentException( ExceptionMessage.USE_ANOTHER_METHOD_WITH_TABLE_NAME_AND_LIST_IDS );
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy