Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2014-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://aws.amazon.com/apache2.0
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and
* limitations under the License.
*/
package com.amazonaws.services.dynamodbv2.datamodeling;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.BinaryAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.BinarySetAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.BooleanAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.ListAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.MapAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.NumberAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.NumberSetAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.StringAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.ArgumentMarshaller.StringSetAttributeMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperFieldModel.DynamoDBAttributeType;
import com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties.Bean;
import com.amazonaws.services.dynamodbv2.datamodeling.StandardModelFactories.Rule;
import com.amazonaws.services.dynamodbv2.datamodeling.StandardModelFactories.RuleFactory;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.BooleanSetToNumberSetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.BooleanToBooleanMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.BooleanToNumberMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.ByteArraySetToBinarySetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.ByteArrayToBinaryMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.ByteBufferSetToBinarySetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.ByteBufferToBinaryMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.CalendarSetToStringSetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.CalendarToStringMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.CollectionToListMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.CustomMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.DateSetToStringSetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.DateToStringMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.MapToMapMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.NumberSetToNumberSetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.NumberToNumberMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.ObjectSetToStringSetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.ObjectToMapMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.ObjectToStringMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.S3LinkToStringMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.StringSetToStringSetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.StringToStringMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.marshallers.UUIDSetToStringSetMarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.BigDecimalSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.BigDecimalUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.BigIntegerSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.BigIntegerUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.BooleanSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.BooleanUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ByteArraySetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ByteArrayUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ByteBufferSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ByteBufferUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ByteSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ByteUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.CalendarSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.CalendarUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.CustomUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.DateSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.DateUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.DoubleSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.DoubleUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.FloatSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.FloatUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.IntegerSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.IntegerUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ListUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.LongSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.LongUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.MapUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.NullableUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ObjectSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ObjectUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.S3LinkUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ShortSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.ShortUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.StringSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.StringUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.UUIDSetUnmarshaller;
import com.amazonaws.services.dynamodbv2.datamodeling.unmarshallers.UUIDUnmarshaller;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
* Pre-defined strategies for mapping between Java types and DynamoDB types.
*/
public final class ConversionSchemas {
private static final Log LOGGER =
LogFactory.getLog(ConversionSchemas.class);
/**
* The V1 schema mapping, which retains strict backwards compatibility with
* the original DynamoDB data model. In particular, it marshals Java
* Booleans as DynamoDB Numbers rather than the newer Boolean type, and does
* not support marshaling Lists or Maps. It can unmarshal
* values written in newer formats to ease migration.
*
* Use me if you have other code still using an old version of the SDK that
* does not understand the new List and Map types and want to ensure that
* you don't accidentally start writing values using these types.
*/
public static final ConversionSchema V1 = v1Builder("V1ConversionSchema").build();
/**
* A V2 conversion schema which retains backwards compatibility with the
* V1 conversion schema for existing DynamoDB types, but adds the ability
* to marshall recursive structures using the new List and Map types. This
* is currently the default conversion schema.
*/
public static final ConversionSchema V2_COMPATIBLE = v2CompatibleBuilder(
"V2CompatibleConversionSchema").build();
/**
* The native V2 conversion schema. This schema breaks compatibility with
* older versions of the mapper that only support the V1 schema by
* storing booleans as native DynamoDB Booleans rather than as a 1 or 0
* in a DynamoDB Number. Switching to the V2 schema will prevent older
* versions of the mapper from reading items you write that contain
* booleans.
*/
public static final ConversionSchema V2 = v2Builder("V2ConversionSchema").build();
static final ConversionSchema DEFAULT = V2_COMPATIBLE;
/**
* A ConversionSchema builder that defaults to building {@link #V1}.
*/
public static Builder v1Builder(String name) {
return new Builder(name, V1MarshallerSet.marshallers(), V1MarshallerSet.setMarshallers(),
StandardUnmarshallerSet.unmarshallers(),
StandardUnmarshallerSet.setUnmarshallers());
}
/**
* A ConversionSchema builder that defaults to building {@link #V2_COMPATIBLE}.
*/
public static Builder v2CompatibleBuilder(String name) {
return new Builder(name, V2CompatibleMarshallerSet.marshallers(),
V2CompatibleMarshallerSet.setMarshallers(),
StandardUnmarshallerSet.unmarshallers(),
StandardUnmarshallerSet.setUnmarshallers());
}
/**
* A ConversionSchema builder that defaults to building {@link #V2}.
*/
public static Builder v2Builder(String name) {
return new Builder(name, V2MarshallerSet.marshallers(), V2MarshallerSet.setMarshallers(),
StandardUnmarshallerSet.unmarshallers(),
StandardUnmarshallerSet.setUnmarshallers());
}
public static class Builder {
private final String name;
private final List> marshallers;
private final List> setMarshallers;
private final List> unmarshallers;
private final List> setUnmarshallers;
Builder(String name, List> marshallers,
List> setMarshallers,
List> unmarshallers,
List> setUnmarshallers) {
this.name = name;
this.marshallers = marshallers;
this.setMarshallers = setMarshallers;
this.unmarshallers = unmarshallers;
this.setUnmarshallers = setUnmarshallers;
}
/**
* Adds marshaling of a type to the schema. Types are in LIFO order, so the last type added
* will be the first matched.
*/
public Builder addFirstType(Class> clazz, ArgumentMarshaller marshaller,
ArgumentUnmarshaller unmarshaller) {
this.marshallers.add(0, Pair.of(clazz, marshaller));
this.unmarshallers.add(0, Pair.of(clazz, unmarshaller));
return this;
}
/**
* Adds marshaling of a Set of a type to the schema. Types are in LIFO order, so the last
* type added will be the first matched.
*/
public Builder addFirstSetType(Class> clazz, ArgumentMarshaller marshaller,
ArgumentUnmarshaller unmarshaller) {
this.setMarshallers.add(0, Pair.of(clazz, marshaller));
this.setUnmarshallers.add(0, Pair.of(clazz, unmarshaller));
return this;
}
public ConversionSchema build() {
return new StandardConversionSchema(name, new AbstractMarshallerSet(marshallers,
setMarshallers),
new StandardUnmarshallerSet(unmarshallers,
setUnmarshallers));
}
}
static class StandardConversionSchema implements ConversionSchema {
private final String name;
private final MarshallerSet marshallers;
private final UnmarshallerSet unmarshallers;
public StandardConversionSchema(
String name,
MarshallerSet marshallers,
UnmarshallerSet unmarshallers) {
this.name = name;
this.marshallers = new CachingMarshallerSet(
new AnnotationAwareMarshallerSet(marshallers));
this.unmarshallers = new CachingUnmarshallerSet(
new AnnotationAwareUnmarshallerSet(unmarshallers));
}
@Override
public ItemConverter getConverter(Dependencies dependencies) {
S3ClientCache s3cc = dependencies.get(S3ClientCache.class);
return new StandardItemConverter(
marshallers,
unmarshallers,
s3cc);
}
@Override
public String toString() {
return name;
}
}
static class StandardItemConverter implements ItemConverter {
private final MarshallerSet marshallerSet;
private final UnmarshallerSet unmarshallerSet;
private final S3ClientCache s3cc;
public StandardItemConverter(
MarshallerSet marshallerSet,
UnmarshallerSet unmarshallerSet,
S3ClientCache s3cc) {
this.marshallerSet = marshallerSet;
this.unmarshallerSet = unmarshallerSet;
this.s3cc = s3cc;
}
@Override
public DynamoDBMapperFieldModel getFieldModel(Method getter) {
final ArgumentMarshaller marshaller = getMarshaller(getter);
final DynamoDBAttributeType attributeType;
if (marshaller instanceof StringAttributeMarshaller) {
attributeType = DynamoDBAttributeType.S;
} else if (marshaller instanceof NumberAttributeMarshaller) {
attributeType = DynamoDBAttributeType.N;
} else if (marshaller instanceof BinaryAttributeMarshaller) {
attributeType = DynamoDBAttributeType.B;
} else if (marshaller instanceof StringSetAttributeMarshaller) {
attributeType = DynamoDBAttributeType.SS;
} else if (marshaller instanceof NumberSetAttributeMarshaller) {
attributeType = DynamoDBAttributeType.NS;
} else if (marshaller instanceof BinarySetAttributeMarshaller) {
attributeType = DynamoDBAttributeType.BS;
} else if (marshaller instanceof BooleanAttributeMarshaller) {
attributeType = DynamoDBAttributeType.BOOL;
} else if (marshaller instanceof ListAttributeMarshaller) {
attributeType = DynamoDBAttributeType.L;
} else if (marshaller instanceof MapAttributeMarshaller) {
attributeType = DynamoDBAttributeType.M;
} else {
throw new DynamoDBMappingException(
"Unrecognized marshaller type for " + getter + ": "
+ marshaller);
}
// Note, generating the attribute name using this method is not
// actually correct for @DynamoDBFlattened attributes, however,
// its the best that can be done given only the method. The
// proper way to get this information is using the model factory.
final StandardAnnotationMaps.FieldMap annotations = StandardAnnotationMaps.of(getter, null);
final DynamoDBMapperFieldModel.Builder builder = new DynamoDBMapperFieldModel.Builder(void.class, annotations);
builder.with(attributeType);
return builder.build();
}
@Override
public AttributeValue convert(Method getter, Object object) {
if (object == null) {
return null;
}
ArgumentMarshaller marshaller = getMarshaller(getter);
return marshaller.marshall(object);
}
@Override
public Map convert(Object object) {
if (object == null) {
return null;
}
Class