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

com.backendless.transaction.OpResult Maven / Gradle / Ivy

There is a newer version: 7.0-alpha
Show newest version
package com.backendless.transaction;

import com.backendless.exceptions.ExceptionMessage;

import java.util.HashMap;
import java.util.Map;

public class OpResult
{
  private final String tableName;
  private final OperationType operationType;
  private String opResultId;

  OpResult( String tableName, OperationType operationType, String opResultId )
  {
    this.tableName = tableName;
    this.operationType = operationType;
    this.opResultId = opResultId;
  }

  public OperationType getOperationType()
  {
    return operationType;
  }

  public String getTableName()
  {
    return tableName;
  }

  public String getOpResultId()
  {
    return opResultId;
  }

  public OpResultValueReference resolveTo( int resultIndex, String propName )
  {
    return new OpResultValueReference( this, resultIndex, propName );
  }

  public OpResultValueReference resolveTo( int resultIndex )
  {
    return new OpResultValueReference( this, resultIndex );
  }

  public OpResultValueReference resolveTo( String propName )
  {
    return new OpResultValueReference( this, propName );
  }

  Map makeReference()
  {
    Map referenceMap = new HashMap<>();
    referenceMap.put( UnitOfWork.REFERENCE_MARKER, true );
    referenceMap.put( UnitOfWork.OP_RESULT_ID, opResultId );
    return referenceMap;
  }

  public void setOpResultId( UnitOfWork unitOfWork, String newOpResultId )
  {
    if( unitOfWork.getOpResultIdStrings().contains( newOpResultId ) )
      throw new IllegalArgumentException( ExceptionMessage.OP_RESULT_ID_ALREADY_PRESENT );

    for( Operation operation : unitOfWork.getOperations() )
      if( operation.getOpResultId().equals( opResultId ) )
      {
        operation.setOpResultId( newOpResultId );
        break;
      }

    opResultId = newOpResultId;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy