Class DurationAttributeConverter
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.DurationAttributeConverter
-
- All Implemented Interfaces:
AttributeConverter<Duration>
@SdkInternalApi @ThreadSafe @Immutable public final class DurationAttributeConverter extends Object implements AttributeConverter<Duration>
A converter betweenDurationandAttributeValue.This stores and reads values in DynamoDB as a number, so that they can be sorted numerically as part of a sort key.
Durations are stored in the format "[-]X[.YYYYYYYYY]", where X is the number of seconds in the duration, and Y is the number of nanoseconds in the duration, left padded with zeroes to a length of 9. The Y and decimal point may be excluded for durations that are of whole seconds. The duration may be preceded by a - to indicate a negative duration.
Examples:
Duration.ofDays(1)is stored asItemAttributeValueMapper.fromNumber("86400")Duration.ofSeconds(9)is stored asItemAttributeValueMapper.fromNumber("9")Duration.ofSeconds(-9)is stored asItemAttributeValueMapper.fromNumber("-9")Duration.ofNanos(1_234_567_890)is stored asItemAttributeValueMapper.fromNumber("1.234567890")Duration.ofMillis(1)is stored asItemAttributeValueMapper.fromNumber("0.001000000")Duration.ofNanos(1)is stored asItemAttributeValueMapper.fromNumber("0.000000001")Duration.ofNanos(-1)is stored asItemAttributeValueMapper.fromNumber("-0.000000001")
This can be created via
create().
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AttributeValueTypeattributeValueType()TheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.static DurationAttributeConvertercreate()AttributeValuetransformFrom(Duration input)Convert the provided Java object into anAttributeValue.DurationtransformTo(AttributeValue input)Convert the providedAttributeValueinto a Java object.EnhancedType<Duration>type()The type supported by this converter.
-
-
-
Method Detail
-
create
public static DurationAttributeConverter create()
-
type
public EnhancedType<Duration> type()
Description copied from interface:AttributeConverterThe type supported by this converter.- Specified by:
typein interfaceAttributeConverter<Duration>
-
attributeValueType
public AttributeValueType attributeValueType()
Description copied from interface:AttributeConverterTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.- Specified by:
attributeValueTypein interfaceAttributeConverter<Duration>
-
transformFrom
public AttributeValue transformFrom(Duration input)
Description copied from interface:AttributeConverterConvert the provided Java object into anAttributeValue. This will raise aRuntimeExceptionif the conversion fails, or the input is null.Example:
InstantAsStringAttributeConverter converter = InstantAsStringAttributeConverter.create(); assertEquals(converter.transformFrom(Instant.EPOCH), EnhancedAttributeValue.fromString("1970-01-01T00:00:00Z").toAttributeValue());- Specified by:
transformFromin interfaceAttributeConverter<Duration>
-
transformTo
public Duration transformTo(AttributeValue input)
Description copied from interface:AttributeConverterConvert the providedAttributeValueinto a Java object. This will raise aRuntimeExceptionif the conversion fails, or the input is null.Example:
InstantAsStringAttributeConverter converter = InstantAsStringAttributeConverter.create(); assertEquals(converter.transformTo(EnhancedAttributeValue.fromString("1970-01-01T00:00:00Z").toAttributeValue()), Instant.EPOCH);- Specified by:
transformToin interfaceAttributeConverter<Duration>
-
-