/** * Gets the hash key field model for the specified type. * @param <H> The hash key type. * @return The hash key field model. * @throws DynamoDBMappingException If the hash key is not present. */ public DynamoDBMapperFieldModel<T,H> hashKey() { return this.model.hashKey(); }
@Override public String getHashKeyName() { return model.hashKey().name(); }
/** * Constructs a new table mapper for the given class. * @param model The field model factory. * @param mapper The DynamoDB mapper. * @param db The service object to use for all service calls. */ protected DynamoDBTableMapper(AmazonDynamoDB db, DynamoDBMapper mapper, final DynamoDBMapperConfig config, final DynamoDBMapperTableModel<T> model) { this.rk = model.rangeKeyIfExists(); this.hk = model.hashKey(); this.model = model; this.config = config; this.mapper = mapper; this.db = db; }
public DynamoDBMapperTableModel<T> build() { final DynamoDBMapperTableModel<T> result = new DynamoDBMapperTableModel<T>(this); if (properties.tableName() != null) { result.hashKey(); //<- make sure the hash key is present } return result; } }
/** * Creates a new key map from the specified object. * @param <H> The hash key type. * @param <R> The range key type. * @param object The object instance. * @return The key map. */ public <H,R> Map<String,AttributeValue> convertKey(final T key) { final DynamoDBMapperFieldModel<T,H> hk = this.<H>hashKey(); final DynamoDBMapperFieldModel<T,R> rk = this.<R>rangeKeyIfExists(); return this.<H,R>convertKey(hk.get(key), (rk == null ? (R)null : rk.get(key))); }
/** * Creates a new key map from the specified hash and range key. * @param <H> The hash key type. * @param <R> The range key type. * @param hashKey The hash key. * @param rangeKey The range key (optional if not present on table). * @return The key map. */ public <H,R> Map<String,AttributeValue> convertKey(final H hashKey, final R rangeKey) { final Map<String,AttributeValue> key = new LinkedHashMap<String,AttributeValue>(4); final DynamoDBMapperFieldModel<T,H> hk = this.<H>hashKey(); final AttributeValue hkValue = hashKey == null ? null : hk.convert(hashKey); if (hkValue != null) { key.put(hk.name(), hkValue); } else { throw new DynamoDBMappingException( targetType.getSimpleName() + "[" + hk.name() + "]; no HASH key value present" ); } final DynamoDBMapperFieldModel<T,R> rk = this.<R>rangeKeyIfExists(); final AttributeValue rkValue = rangeKey == null ? null : rk.convert(rangeKey); if (rkValue != null) { key.put(rk.name(), rkValue); } else if (rk != null) { throw new DynamoDBMappingException( targetType.getSimpleName() + "[" + rk.name() + "]; no RANGE key value present" ); } return key; }
/** * Creates a new object instance with the keys populated. * @param <H> The hash key type. * @param <R> The range key type. * @param hashKey The hash key. * @param rangeKey The range key (optional if not present on table). * @return The new instance. */ public <H,R> T createKey(final H hashKey, final R rangeKey) { final T key = StandardBeanProperties.DeclaringReflect.<T>newInstance(targetType); if (hashKey != null) { final DynamoDBMapperFieldModel<T,H> hk = hashKey(); hk.set(key, hashKey); } if (rangeKey != null) { final DynamoDBMapperFieldModel<T,R> rk = rangeKey(); rk.set(key, rangeKey); } return key; }
&& (!rangeKeyConditions.isEmpty()); final String userProvidedIndexName = queryRequest.getIndexName(); final String primaryHashKeyName = model.hashKey().name();
@Override public <T> CreateTableRequest generateCreateTableRequest(Class<T> clazz, DynamoDBMapperConfig config) { config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); final CreateTableRequest request = new CreateTableRequest(); request.setTableName(getTableName(clazz, config)); request.withKeySchema(new KeySchemaElement(model.hashKey().name(), HASH)); if (model.rangeKeyIfExists() != null) { request.withKeySchema(new KeySchemaElement(model.rangeKey().name(), RANGE)); } request.setGlobalSecondaryIndexes(model.globalSecondaryIndexes()); request.setLocalSecondaryIndexes(model.localSecondaryIndexes()); for (final DynamoDBMapperFieldModel<T,Object> field : model.fields()) { if (field.keyType() != null || field.indexed()) { request.withAttributeDefinitions(new AttributeDefinition() .withAttributeType(ScalarAttributeType.valueOf(field.attributeType().name())) .withAttributeName(field.name()) ); } } return request; }
/** * Gets the hash key field model for the specified type. * @param <H> The hash key type. * @return The hash key field model. * @throws DynamoDBMappingException If the hash key is not present. */ public DynamoDBMapperFieldModel<T,H> hashKey() { return this.model.hashKey(); }
@Override public String getHashKeyName() { return model.hashKey().name(); }
/** * Constructs a new table mapper for the given class. * @param model The field model factory. * @param mapper The DynamoDB mapper. * @param db The service object to use for all service calls. */ protected DynamoDBTableMapper(AmazonDynamoDB db, DynamoDBMapper mapper, final DynamoDBMapperConfig config, final DynamoDBMapperTableModel<T> model) { this.rk = model.rangeKeyIfExists(); this.hk = model.hashKey(); this.model = model; this.config = config; this.mapper = mapper; this.db = db; }
public DynamoDBMapperTableModel<T> build() { final DynamoDBMapperTableModel<T> result = new DynamoDBMapperTableModel<T>(this); if (properties.tableName() != null) { result.hashKey(); //<- make sure the hash key is present } return result; } }
/** * Creates a new key map from the specified object. * @param <H> The hash key type. * @param <R> The range key type. * @param object The object instance. * @return The key map. */ public <H,R> Map<String,AttributeValue> convertKey(final T key) { final DynamoDBMapperFieldModel<T,H> hk = this.<H>hashKey(); final DynamoDBMapperFieldModel<T,R> rk = this.<R>rangeKeyIfExists(); return this.<H,R>convertKey(hk.get(key), (rk == null ? (R)null : rk.get(key))); }
/** * Creates a new key map from the specified hash and range key. * @param <H> The hash key type. * @param <R> The range key type. * @param hashKey The hash key. * @param rangeKey The range key (optional if not present on table). * @return The key map. */ public <H,R> Map<String,AttributeValue> convertKey(final H hashKey, final R rangeKey) { final Map<String,AttributeValue> key = new LinkedHashMap<String,AttributeValue>(4); final DynamoDBMapperFieldModel<T,H> hk = this.<H>hashKey(); final AttributeValue hkValue = hashKey == null ? null : hk.convert(hashKey); if (hkValue != null) { key.put(hk.name(), hkValue); } else { throw new DynamoDBMappingException( targetType.getSimpleName() + "[" + hk.name() + "]; no HASH key value present" ); } final DynamoDBMapperFieldModel<T,R> rk = this.<R>rangeKeyIfExists(); final AttributeValue rkValue = rangeKey == null ? null : rk.convert(rangeKey); if (rkValue != null) { key.put(rk.name(), rkValue); } else if (rk != null) { throw new DynamoDBMappingException( targetType.getSimpleName() + "[" + rk.name() + "]; no RANGE key value present" ); } return key; }
/** * Creates a new object instance with the keys populated. * @param <H> The hash key type. * @param <R> The range key type. * @param hashKey The hash key. * @param rangeKey The range key (optional if not present on table). * @return The new instance. */ public <H,R> T createKey(final H hashKey, final R rangeKey) { final T key = StandardBeanProperties.DeclaringReflect.<T>newInstance(targetType); if (hashKey != null) { final DynamoDBMapperFieldModel<T,H> hk = hashKey(); hk.set(key, hashKey); } if (rangeKey != null) { final DynamoDBMapperFieldModel<T,R> rk = rangeKey(); rk.set(key, rangeKey); } return key; }
&& (!rangeKeyConditions.isEmpty()); final String userProvidedIndexName = queryRequest.getIndexName(); final String primaryHashKeyName = model.hashKey().name();
@Override public <T> CreateTableRequest generateCreateTableRequest(Class<T> clazz, DynamoDBMapperConfig config) { config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); final CreateTableRequest request = new CreateTableRequest(); request.setTableName(getTableName(clazz, config)); request.withKeySchema(new KeySchemaElement(model.hashKey().name(), HASH)); if (model.rangeKeyIfExists() != null) { request.withKeySchema(new KeySchemaElement(model.rangeKey().name(), RANGE)); } request.setGlobalSecondaryIndexes(model.globalSecondaryIndexes()); request.setLocalSecondaryIndexes(model.localSecondaryIndexes()); for (final DynamoDBMapperFieldModel<T,Object> field : model.fields()) { if (field.keyType() != null || field.indexed()) { request.withAttributeDefinitions(new AttributeDefinition() .withAttributeType(ScalarAttributeType.valueOf(field.attributeType().name())) .withAttributeName(field.name()) ); } } return request; }