Package convex.core
Class Result
- All Implemented Interfaces:
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
values
Fields inherited from class convex.core.data.ARecord
DEFAULT_VALUE, format
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionstatic Result
Create a Resultstatic Result
Create a Resultstatic Result
Create a Resultint
encode
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.static Result
fromContext
(CVMLong id, Context<?> ctx) Constructs a Result from a ContextReturns the Error Code from this Result.getID()
Returns the message ID for this result.getInfo()
Returns the info for this Result.byte
getTag()
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.boolean
isError()
Tests is the Result represents an Errorstatic Result
read
(ByteBuffer bb) Reads a Result from a ByteBuffer encoding.void
validate()
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 Result
withValues
(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, updateAll, updateRefs, validateCell
Methods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, encodeRaw, entrySet, estimatedEncodingSize, forEach, get, getEntry, getEntryByHash, getFormat, getKeyRefEntry, getKeys, getType, getValuesArray, isCanonical, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMap
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, filterValues, get, get, getElementRef, print, put, putAll, remove, slice
Methods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACountable
slice
Methods 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, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:ARecord
Gets a vector of values for this record, in format-determined order -
withValues
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 classARecordGeneric
- Parameters:
newValues
- New values to use- Returns:
- Updated Record
-
validate
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:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validate
in interfaceIValidated
- Overrides:
validate
in classACell
- 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 interfaceIWriteable
- Specified by:
encode
in 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
-
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
-
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: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 classARecordGeneric
- Returns:
- Record tag byte
-