Package convex.core

Class Result

All Implemented Interfaces:
IAssociative<Keyword,ACell>, IValidated, IWriteable, Map<Keyword,ACell>

public final class Result extends ARecordGeneric
Class representing the result of a Query or Transaction. A Result is typically used to communicate the outcome of a Query or a Transaction from a Peer to a Client. Contains:
  1. Message ID
  2. Result value
  3. Error Code
  4. Additional info
  • Method Details

    • create

      public static Result create(CVMLong id, ACell value, ACell errorCode, AMap<Keyword,ACell> info)
      Create a Result
      Parameters:
      id - ID of Result message
      value - Result Value
      errorCode - Error Code (may be null for success)
      info - Additional info
      Returns:
      Result instance
    • create

      public static Result create(CVMLong id, ACell value, ACell errorCode)
      Create a Result
      Parameters:
      id - ID of Result message
      value - Result Value
      errorCode - Error Code (may be null for success)
      Returns:
      Result instance
    • create

      public static Result create(CVMLong id, ACell value)
      Create a Result
      Parameters:
      id - ID of Result message
      value - Result Value
      Returns:
      Result instance
    • getID

      public ACell getID()
      Returns the message ID for this result. Message ID is an arbitrary ID assigned by a client requesting a transaction.
      Returns:
      ID from this result
    • getValue

      public <T extends ACell> T getValue()
      Returns the value for this result. The value is the result of transaction execution (may be an error message if the transaction failed)
      Type Parameters:
      T - Type of Value
      Returns:
      ID from this result
    • getTrace

      public AVector<AString> getTrace()
      Returns the stack trace for this result. May be null
      Returns:
      Trace vector from this result
    • getInfo

      public AMap<Keyword,ACell> getInfo()
      Returns the info for this Result. May be null
      Returns:
      Info map from this result
    • getErrorCode

      public ACell getErrorCode()
      Returns the Error Code from this Result. Normally this should be a Keyword. Will be null if no error occurred.
      Returns:
      ID from this result
    • values

      public AVector<ACell> values()
      Description copied from class: ARecord
      Gets a vector of values for this Record, in format-determined order
      Specified by:
      values in interface Map<Keyword,ACell>
      Overrides:
      values in class ARecordGeneric
      Returns:
      Vector of Values
    • withValues

      protected Result withValues(AVector<ACell> newValues)
      Description copied from class: ARecordGeneric
      Updates the record with a new set of values. Returns this if and only if values vector is identical.
      Specified by:
      withValues in class ARecordGeneric
      Parameters:
      newValues - New values to use
      Returns:
      Updated Record
    • validate

      public void validate() throws InvalidDataException
      Description copied from interface: IValidated
      Validates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:
      1. Call super.validate() - which will indirectly call validateCell()
      2. Call validate() on any contained cells in this class
      Specified by:
      validate in interface IValidated
      Overrides:
      validate in class ACell
      Throws:
      InvalidDataException - If the data Value is invalid in any way
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • read

      public static Result read(ByteBuffer bb) throws BadFormatException
      Reads a Result from a ByteBuffer encoding. Assumes tag byte already read.
      Parameters:
      bb - ByteBuffer to read from
      Returns:
      The Result read
      Throws:
      BadFormatException - If a Result could not be read
    • read

      public static Result read(Blob b, int pos) throws BadFormatException
      Throws:
      BadFormatException
    • isError

      public boolean isError()
      Tests is the Result represents an Error
      Returns:
      True if error, false otherwise
    • fromContext

      public static Result fromContext(CVMLong id, Context<?> ctx)
      Constructs a Result from a Context
      Parameters:
      id - Id for Result
      ctx - Context
      Returns:
      New Result instance
    • fromContext

      public static Result fromContext(Context<?> ctx)
      Constructs a Result from a Context
      Parameters:
      ctx - Context
      Returns:
      New Result instance
    • withID

      public Result withID(ACell id)
      Updates result with a given message ID. Used to tag Results for return to Clients
      Parameters:
      id - New Result message ID
      Returns:
      Updated Result
    • getTag

      public byte getTag()
      Description copied from class: ARecord
      Gets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding.
      Specified by:
      getTag in class ARecordGeneric
      Returns:
      Record tag byte
    • getFormat

      public RecordFormat getFormat()
      Description copied from class: ARecord
      Gets the RecordFormat instance that describes this Record's layout
      Specified by:
      getFormat in class ARecord
      Returns:
      RecordFormat instance
    • fromException

      public static Result fromException(Throwable e)