/** * Gets the range key field model for the specified type. * @param <R> The range key type. * @return The range key field model. * @throws DynamoDBMappingException If the range key is not present. */ public DynamoDBMapperFieldModel<T,R> rangeKey() { return this.model.rangeKey(); }
@Override public String getRangeKeyName() { return model.rangeKeyIfExists() == null ? null : model.rangeKey().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; }
/** * 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; }
@Override public String getRangeKeyName() { return model.rangeKeyIfExists() == null ? null : model.rangeKey().name(); } }
/** * Gets the range key field model for the specified type. * @param <R> The range key type. * @return The range key field model. * @throws DynamoDBMappingException If the range key is not present. */ public DynamoDBMapperFieldModel<T,R> rangeKey() { return this.model.rangeKey(); }
@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; }
/** * 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; }