Class Item
java.lang.Object
com.amazonaws.services.dynamodbv2.document.Item
An item in DynamoDB. An item is a collection of attributes. Each attribute
has a name and a value. An attribute value can be one of the followings:
- String
- Set<String>
- Number (including any subtypes and primitive types)
- Set<Number>
- byte[]
- Set<byte[]>
- ByteBuffer
- Set<ByteBuffer>
- Boolean or boolean
- null
- Map<String,T>, where T can be any type on this list but must not induce any circular reference
- List<T>, where T can be any type on this list but must not induce any circular reference
Item
to be successfully persisted in DynamoDB, at a
minimum the respective attributes for the primary key must be specified.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasMap()
Returns all attributes of the current item as a map.Returns all attributes of the current item.base64Decode
(String... binaryAttrNames) Utility method to decode the designated binary attributes from base-64 encoding; converting binary lists into binary sets.convertListsToSets
(String... listAttrNames) Utility method to converts the designated attributes fromList
intoSet
, throwingIllegalArgumentException
should there be duplicate elements.boolean
static Item
Convenient factory method - instantiates anItem
from the given JSON string.static Item
Convenient factory method - instantiates anItem
from the given map.Returns the value of the specified attribute in the current item as an object; or null if the attribute either doesn't exist or the attribute value is null.getBigInteger
(String attrName) Returns the value of the specified attribute in the current item as anBigInteger
; or null if the attribute doesn't exist.byte[]
Returns the value of the specified attribute in the current item as a byte array; or null if the attribute either doesn't exist or the attribute value is null.Set<byte[]>
getBinarySet
(String attrName) Returns the value of the specified attribute in the current item as a set of byte arrays; or null if the attribute either doesn't exist or the attribute value is null.Returns the value of the specified attribute in the current item as a non-null Boolean.boolean
getBoolean
(String attrName) Returns the value of the specified attribute in the current item as a primitive boolean.getByteBuffer
(String attrName) Returns the value of the specified attribute in the current item as aByteBuffer
; or null if the attribute either doesn't exist or the attribute value is null.getByteBufferSet
(String attrName) Returns the value of the specified attribute in the current item as a set ofByteBuffer
; or null if the attribute either doesn't exist or the attribute value is null.double
Returns the value of the specified attribute in the current item as adouble
.float
Returns the value of the specified attribute in the current item as afloat
.int
Returns the value of the specified attribute in the current item as anint
.Returns the value of the specified attribute in the current item as a JSON string; or null if the attribute either doesn't exist or the attribute value is null.getJSONPretty
(String attrName) Returns the value of the specified attribute in the current item as a JSON string with pretty indentation; or null if the attribute either doesn't exist or the attribute value is null.<T> List<T>
Returns the value of the specified attribute in the current item as a set ofT
's.; or null if the attribute either doesn't exist or the attribute value is null.long
Returns the value of the specified attribute in the current item as anlong
.Returns the value of the specified attribute in the current item as a map of string-to-T
's; or null if the attribute either doesn't exist or the attribute value is null.getMapOfNumbers
(String attrName, Class<T> valueType) Convenient method to return the specified attribute in the current item as a (copy of) map of string-to-T
's where T must be a subclass ofNumber
; or null if the attribute doesn't exist.Returns the value of the specified attribute in the current item as aBigDecimal
; or null if the attribute either doesn't exist or the attribute value is null.getNumberSet
(String attrName) Returns the value of the specified attribute in the current item as a set of BigDecimal's; or null if the attribute either doesn't exist or the attribute value is null.Convenient method to return the value of the specified attribute in the current item as a map of string-to-Object
's; or null if the attribute either doesn't exist or the attribute value is null.short
Returns the value of the specified attribute in the current item as ashort
.Returns the value of the specified attribute in the current item as a string; or null if the attribute either doesn't exist or the attribute value is null.getStringSet
(String attrName) Returns the value of the specified attribute in the current item as a set of strings; or null if the attribute either doesn't exist or the attribute value is null.Class<?>
Returns the type of the specified attribute in the current item; or null if the attribute either doesn't exist or the attribute value is null.boolean
hasAttribute
(String attrName) Returns true if this item has the specified attribute; false otherwise.int
hashCode()
boolean
Returns true if the specified attribute exists with a null value; false otherwise.boolean
Returns true if this item contains the specified attribute; false otherwise.int
Returns the number of attributes of this item.removeAttribute
(String attrName) Removes the specified attribute from the current item.toJSON()
Returns this item as a JSON string.Returns this item as a pretty JSON string.toString()
Sets the value of the specified attribute to the given value.withBigDecimalSet
(String attrName, BigDecimal... vals) Sets the value of the specified attribute in the current item to the given value.withBigDecimalSet
(String attrName, Set<BigDecimal> val) Sets the value of the specified attribute in the current item to the given value.withBigInteger
(String attrName, BigInteger val) Sets the value of the specified attribute in the current item to the given value.withBinary
(String attrName, byte[] val) Sets the value of the specified attribute in the current item to the given value.withBinary
(String attrName, ByteBuffer val) Sets the value of the specified attribute in the current item to the given value.withBinarySet
(String attrName, byte[]... vals) Sets the value of the specified attribute in the current item to the given value.withBinarySet
(String attrName, ByteBuffer... vals) Sets the value of the specified attribute in the current item to the given value.withBinarySet
(String attrName, Set<byte[]> val) Sets the value of the specified attribute in the current item to the given value.withBoolean
(String attrName, boolean val) Sets the value of the specified attribute in the current item to the boolean value.withByteBufferSet
(String attrName, Set<ByteBuffer> val) Sets the value of the specified attribute in the current item to the given value.withDouble
(String attrName, double val) Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given JSON document in the form of a string.withKeyComponent
(String keyAttrName, Object keyAttrValue) Convenient methods - sets an attribute of this item for the specified key attribute name and value.withKeyComponents
(KeyAttribute... components) Convenient methods - sets the attributes of this item from the specified key components.Sets the value of the specified attribute in the current item to the given values as a list.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute to null.withNumber
(String attrName, Number val) Sets the value of the specified attribute in the current item to the given value.withNumber
(String attrName, BigDecimal val) Sets the value of the specified attribute in the current item to the given value.withNumberSet
(String attrName, Number... vals) Sets the value of the specified attribute in the current item to the given value.withNumberSet
(String attrName, Set<Number> vals) Sets the value of the specified attribute in the current item to the given value.withPrimaryKey
(PrimaryKey primaryKey) Convenient methods - sets the attributes of this item from the given key attributes.withPrimaryKey
(String hashKeyName, Object hashKeyValue) Convenient method to set the attributes of this item from the given hash-only primary key name and value.withPrimaryKey
(String hashKeyName, Object hashKeyValue, String rangeKeyName, Object rangeKeyValue) Convenient method to set the attributes of this item from the given hash and range primary key.Sets the value of the specified attribute in the current item to the given value.withString
(String attrName, String val) Sets the value of the specified attribute in the current item to the given string value.withStringSet
(String attrName, String... val) Sets the value of the specified attribute in the current item to the given value.withStringSet
(String attrName, Set<String> val) Sets the value of the specified attribute in the current item to the given value.
-
Constructor Details
-
Item
public Item()
-
-
Method Details
-
isNull
Returns true if the specified attribute exists with a null value; false otherwise. -
isPresent
Returns true if this item contains the specified attribute; false otherwise. -
getString
Returns the value of the specified attribute in the current item as a string; or null if the attribute either doesn't exist or the attribute value is null. -
withString
Sets the value of the specified attribute in the current item to the given string value. -
getNumber
Returns the value of the specified attribute in the current item as aBigDecimal
; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
NumberFormatException
- if the attribute value is not a valid representation of aBigDecimal
.- See Also:
-
getBigInteger
Returns the value of the specified attribute in the current item as anBigInteger
; or null if the attribute doesn't exist.- Throws:
NumberFormatException
- if the attribute value is null or not a valid representation of aBigDecimal
.- See Also:
-
getShort
Returns the value of the specified attribute in the current item as ashort
.- Throws:
NumberFormatException
- if the attribute value is null or not a valid representation of aBigDecimal
.- See Also:
-
getInt
Returns the value of the specified attribute in the current item as anint
.- Throws:
NumberFormatException
- if the attribute value is null or not a valid representation of aBigDecimal
.- See Also:
-
getLong
Returns the value of the specified attribute in the current item as anlong
.- Throws:
NumberFormatException
- if the attribute value is null or not a valid representation of aBigDecimal
.- See Also:
-
getFloat
Returns the value of the specified attribute in the current item as afloat
.- Throws:
NumberFormatException
- if the attribute value is null or not a valid representation of aBigDecimal
.- See Also:
-
getDouble
Returns the value of the specified attribute in the current item as adouble
.- Throws:
NumberFormatException
- if the attribute value is null or not a valid representation of aBigDecimal
.- See Also:
-
withNumber
Sets the value of the specified attribute in the current item to the given value. -
withNumber
Sets the value of the specified attribute in the current item to the given value. -
withInt
Sets the value of the specified attribute in the current item to the given value. -
withBigInteger
Sets the value of the specified attribute in the current item to the given value. -
withShort
Sets the value of the specified attribute in the current item to the given value. -
withFloat
Sets the value of the specified attribute in the current item to the given value. -
withDouble
Sets the value of the specified attribute in the current item to the given value. -
withLong
Sets the value of the specified attribute in the current item to the given value. -
getBinary
Returns the value of the specified attribute in the current item as a byte array; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
UnsupportedOperationException
- If the attribute value involves a byte buffer which is not backed by an accessible arrayIncompatibleTypeException
- if the attribute value cannot be converted into a byte array- See Also:
-
getByteBuffer
Returns the value of the specified attribute in the current item as aByteBuffer
; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
IncompatibleTypeException
- if the attribute value cannot be converted into a byte array- See Also:
-
withBinary
Sets the value of the specified attribute in the current item to the given value. -
withBinary
Sets the value of the specified attribute in the current item to the given value. -
getStringSet
Returns the value of the specified attribute in the current item as a set of strings; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
IncompatibleTypeException
- if the attribute value cannot be converted into a set of strings because of duplicate elements- See Also:
-
withStringSet
Sets the value of the specified attribute in the current item to the given value. -
withStringSet
Sets the value of the specified attribute in the current item to the given value. -
getNumberSet
Returns the value of the specified attribute in the current item as a set of BigDecimal's; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
NumberFormatException
- if the attribute involves a value that is not a valid representation of aBigDecimal
.IncompatibleTypeException
- if the attribute value cannot be converted into a set ofBigDecimal
's because of duplicate elements- See Also:
-
withBigDecimalSet
Sets the value of the specified attribute in the current item to the given value. -
withBigDecimalSet
Sets the value of the specified attribute in the current item to the given value. -
withNumberSet
Sets the value of the specified attribute in the current item to the given value. -
withNumberSet
Sets the value of the specified attribute in the current item to the given value. -
getBinarySet
Returns the value of the specified attribute in the current item as a set of byte arrays; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
IncompatibleTypeException
- if the attribute value cannot be converted into a set of byte arrays- See Also:
-
getByteBufferSet
Returns the value of the specified attribute in the current item as a set ofByteBuffer
; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
IncompatibleTypeException
- if the attribute value cannot be converted into a set ofByteBuffer
- See Also:
-
withBinarySet
Sets the value of the specified attribute in the current item to the given value. -
withByteBufferSet
Sets the value of the specified attribute in the current item to the given value. -
withBinarySet
Sets the value of the specified attribute in the current item to the given value. -
withBinarySet
Sets the value of the specified attribute in the current item to the given value. -
getList
Returns the value of the specified attribute in the current item as a set ofT
's.; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
ClassCastException
- if the attribute involves a value that cannot be casted toT
- See Also:
-
withList
Sets the value of the specified attribute in the current item to the given value. -
withList
Sets the value of the specified attribute in the current item to the given values as a list. -
getMap
Returns the value of the specified attribute in the current item as a map of string-to-T
's; or null if the attribute either doesn't exist or the attribute value is null. Note that any numeric type of a map is always canonicalized intoBigDecimal
, and therefore ifT
referred to aNumber
type, it would need to beBigDecimal
to avoid a class cast exception.- Throws:
ClassCastException
- if the attribute is not a map of string toT
- See Also:
-
getMapOfNumbers
Convenient method to return the specified attribute in the current item as a (copy of) map of string-to-T
's where T must be a subclass ofNumber
; or null if the attribute doesn't exist.- Parameters:
attrName
- the attribute namevalueType
- the specific number type of the value to be returned. Currently, onlyShort
Integer
Long
Float
Double
Number
BigDecimal
BigInteger
- Throws:
UnsupportedOperationException
- if the value type is not supportedClassCastException
- if the attribute is not a map of string to numbers
-
getRawMap
Convenient method to return the value of the specified attribute in the current item as a map of string-to-Object
's; or null if the attribute either doesn't exist or the attribute value is null. Note that any numeric type of the map will be returned asBigDecimal
.- Throws:
ClassCastException
- if the attribute is not a map- See Also:
-
withMap
Sets the value of the specified attribute in the current item to the given value. -
withJSON
Sets the value of the specified attribute in the current item to the given JSON document in the form of a string. -
getJSON
Returns the value of the specified attribute in the current item as a JSON string; or null if the attribute either doesn't exist or the attribute value is null. -
getJSONPretty
Returns the value of the specified attribute in the current item as a JSON string with pretty indentation; or null if the attribute either doesn't exist or the attribute value is null. -
getBOOL
Returns the value of the specified attribute in the current item as a non-null Boolean.- Throws:
IncompatibleTypeException
- if either the attribute doesn't exist or if the attribute value cannot be converted into a non-null Boolean value- See Also:
-
getBoolean
Returns the value of the specified attribute in the current item as a primitive boolean.- Throws:
IncompatibleTypeException
- if either the attribute doesn't exist or if the attribute value cannot be converted into a boolean value
-
withBoolean
Sets the value of the specified attribute in the current item to the boolean value. -
withNull
Sets the value of the specified attribute to null. -
with
Sets the value of the specified attribute to the given value. An attribute value can be a- Number
- String
- binary (ie byte array or byte buffer)
- boolean
- null
- list (of any of the types on this list)
- map (with string key to value of any of the types on this list)
- set (of any of the types on this list)
-
withPrimaryKey
Convenient methods - sets the attributes of this item from the given key attributes. -
withPrimaryKey
Convenient method to set the attributes of this item from the given hash-only primary key name and value. -
withPrimaryKey
public Item withPrimaryKey(String hashKeyName, Object hashKeyValue, String rangeKeyName, Object rangeKeyValue) Convenient method to set the attributes of this item from the given hash and range primary key. -
withKeyComponents
Convenient methods - sets the attributes of this item from the specified key components. -
withKeyComponent
Convenient methods - sets an attribute of this item for the specified key attribute name and value. -
get
Returns the value of the specified attribute in the current item as an object; or null if the attribute either doesn't exist or the attribute value is null.An attribute value can be a
- Number
- String
- binary (ie byte array or byte buffer)
- boolean
- null
- list (of any of the types on this list)
- map (with string key to value of any of the types on this list)
- set (of any of the types on this list)
-
getTypeOf
Returns the type of the specified attribute in the current item; or null if the attribute either doesn't exist or the attribute value is null. -
removeAttribute
Removes the specified attribute from the current item. -
attributes
Returns all attributes of the current item. -
hasAttribute
Returns true if this item has the specified attribute; false otherwise. -
asMap
Returns all attributes of the current item as a map. -
numberOfAttributes
public int numberOfAttributes()Returns the number of attributes of this item. -
fromMap
Convenient factory method - instantiates anItem
from the given map.- Parameters:
attributes
- simple Java types; not the DyanmoDB types
-
fromJSON
Convenient factory method - instantiates anItem
from the given JSON string.- Returns:
- an
Item
initialized from the given JSON document; or null if the input is null.
-
toJSON
Returns this item as a JSON string. Note all binary data will become base-64 encoded in the resultant string. -
base64Decode
Utility method to decode the designated binary attributes from base-64 encoding; converting binary lists into binary sets.- Parameters:
binaryAttrNames
- names of binary attributes or binary set attributes currently base-64 encoded (typically when converted from a JSON string.)- See Also:
-
convertListsToSets
Utility method to converts the designated attributes fromList
intoSet
, throwingIllegalArgumentException
should there be duplicate elements.- Parameters:
listAttrNames
- names of attributes to be converted.- See Also:
-
toJSONPretty
Returns this item as a pretty JSON string. Note all binary data will become base-64 encoded in the resultant string. -
toString
-
hashCode
public int hashCode() -
equals
-