Package convex.core
Class Result
- All Implemented Interfaces:
IAssociative<Keyword,,ACell> IValidated,IWriteable,Map<Keyword,ACell>
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:
- Message ID
- Result value
- Error Code
- Additional info
-
Nested Class Summary
-
Field Summary
Fields inherited from class convex.core.data.ARecordGeneric
format, valuesFields inherited from class convex.core.data.ARecord
DEFAULT_VALUEFields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionstatic ResultCreate a Resultstatic ResultCreate a Resultstatic ResultCreate a Resultintencode(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.static ResultfromContext(CVMLong id, Context<?> ctx) Constructs a Result from a Contextstatic ResultfromContext(Context<?> ctx) Constructs a Result from a Contextstatic ResultReturns the Error Code from this Result.Gets the RecordFormat instance that describes this Record's layoutgetID()Returns the message ID for this result.getInfo()Returns the info for this Result.bytegetTag()Gets the tag byte for this record type.getTrace()Returns the stack trace for this result.<T extends ACell>
TgetValue()Returns the value for this result.booleanisError()Tests is the Result represents an Errorstatic Resultstatic Resultread(ByteBuffer bb) Reads a Result from a ByteBuffer encoding.voidvalidate()Validates the complete structure of this object.values()Gets a vector of values for this Record, in format-determined orderUpdates result with a given message ID.protected ResultwithValues(AVector<ACell> newValues) Updates the record with a new set of values.Methods inherited from class convex.core.data.ARecordGeneric
entryAt, equals, equals, get, getRef, getRefCount, updateRefs, validateCellMethods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, encodeRaw, entrySet, estimatedEncodingSize, forEach, get, getEntry, getEntryByHash, getKeyRefEntry, getKeys, getType, getValuesArray, isCanonical, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMapMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, getElementRef, merge, print, put, putAll, remove, slice, sliceMethods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isCompletelyEncoded, isEmbedded, mark, mark, toString, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Method Details
-
create
Create a Result- Parameters:
id- ID of Result messagevalue- Result ValueerrorCode- Error Code (may be null for success)info- Additional info- Returns:
- Result instance
-
create
Create a Result- Parameters:
id- ID of Result messagevalue- Result ValueerrorCode- Error Code (may be null for success)- Returns:
- Result instance
-
create
Create a Result- Parameters:
id- ID of Result messagevalue- Result Value- Returns:
- Result instance
-
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
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
Returns the stack trace for this result. May be null- Returns:
- Trace vector from this result
-
getInfo
Returns the info for this Result. May be null- Returns:
- Info map from this result
-
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
Description copied from class:ARecordGets a vector of values for this Record, in format-determined order -
withValues
Description copied from class:ARecordGenericUpdates the record with a new set of values. Returns this if and only if values vector is identical.- Specified by:
withValuesin classARecordGeneric- Parameters:
newValues- New values to use- Returns:
- Updated Record
-
validate
Description copied from interface:IValidatedValidates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validatein interfaceIValidated- Overrides:
validatein classACell- Throws:
InvalidDataException- If the data Value is invalid in any way
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACellWrites 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:
encodein interfaceIWriteable- Specified by:
encodein classACell- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
read
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
- Throws:
BadFormatException
-
isError
public boolean isError()Tests is the Result represents an Error- Returns:
- True if error, false otherwise
-
fromContext
Constructs a Result from a Context- Parameters:
id- Id for Resultctx- Context- Returns:
- New Result instance
-
fromContext
Constructs a Result from a Context- Parameters:
ctx- Context- Returns:
- New Result instance
-
withID
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:ARecordGets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding.- Specified by:
getTagin classARecordGeneric- Returns:
- Record tag byte
-
getFormat
Description copied from class:ARecordGets the RecordFormat instance that describes this Record's layout -
fromException
-