/** * Creates a new table mapper using this mapper to perform operations. * @param <T> The object type which this mapper operates. * @param <H> The hash key value type. * @param <R> The range key value type; use <code>?</code> if no range key. * @param clazz The object class. * @return The table mapper. */ public <T,H,R> DynamoDBTableMapper<T,H,R> newTableMapper(Class<T> clazz) { DynamoDBMapperConfig config = mergeConfig(null); return new DynamoDBTableMapper<T,H,R>(this.db, this, config, getTableModel(clazz, config)); }
private <T> AttributeTransformer.Parameters<T> toParameters( final Map<String, AttributeValue> attributeValues, final boolean partialUpdate, final Class<T> modelClass, final String tableName, final DynamoDBMapperConfig mapperConfig) { return new TransformerParameters<T>( getTableModel(modelClass, mapperConfig), attributeValues, partialUpdate, modelClass, mapperConfig, tableName); }
@Override public Map<String, List<Object>> batchLoad(Map<Class<?>, List<KeyPair>> itemsToGet, DynamoDBMapperConfig config) { config = mergeConfig(config); List<Object> keys = new ArrayList<Object>(); if ( itemsToGet != null ) { for ( Class<?> clazz : itemsToGet.keySet() ) { if ( itemsToGet.get(clazz) != null ) { final DynamoDBMapperTableModel model = getTableModel(clazz, config); for ( KeyPair keyPair : itemsToGet.get(clazz) ) { keys.add(model.createKey(keyPair.getHashKey(), keyPair.getRangeKey())); } } } } return batchLoad(keys, config); }
@Override public <T extends Object> T load(Class<T> clazz, Object hashKey, Object rangeKey, DynamoDBMapperConfig config) { config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); T keyObject = model.createKey(hashKey, rangeKey); return load(keyObject, config); }
final DynamoDBMapperTableModel model = getTableModel(clazz, config);
/** * The one true implementation of marshallIntoObject. */ private <T> T privateMarshallIntoObject( AttributeTransformer.Parameters<T> parameters) { Class<T> clazz = parameters.getModelClass(); Map<String, AttributeValue> values = untransformAttributes(parameters); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, parameters.getMapperConfig()); return model.unconvert(values); }
final DynamoDBMapperTableModel<Object> model = getTableModel(clazz, config); for ( final DynamoDBMapperFieldModel<Object,Object> field : model.fields() ) { AttributeValue currentValue = null; final DynamoDBMapperTableModel<Object> model = getTableModel(clazz, config);
String tableName = getTableName(clazz, object, finalConfig); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, finalConfig);
@Override public <T extends Object> T load(T keyObject, DynamoDBMapperConfig config) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) keyObject.getClass(); config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); String tableName = getTableName(clazz, keyObject, config); GetItemRequest rq = new GetItemRequest() .withRequestMetricCollector(config.getRequestMetricCollector()); Map<String, AttributeValue> key = model.convertKey(keyObject); rq.setKey(key); rq.setTableName(tableName); rq.setConsistentRead(config.getConsistentReads() == ConsistentReads.CONSISTENT); GetItemResult item = db.getItem(applyUserAgent(rq)); Map<String, AttributeValue> itemAttributes = item.getItem(); if ( itemAttributes == null ) { return null; } T object = privateMarshallIntoObject( toParameters(itemAttributes, clazz, tableName, config)); return object; }
final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config);
final DynamoDBMapperTableModel<Object> model = getTableModel((Class<Object>)clazz, saveConfig); for ( final DynamoDBMapperFieldModel<Object,Object> field : model.fields() ) { if ( canGenerate(model, object, getLocalSaveBehavior(), field) ) {
@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; }
protected <T> QueryRequest createQueryRequestFromExpression(Class<T> clazz, DynamoDBQueryExpression<T> xpress, DynamoDBMapperConfig config) { final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); QueryRequest req = new QueryRequest(); req.setConsistentRead(xpress.isConsistentRead()); req.setTableName(getTableName(clazz, xpress.getHashKeyValues(), config)); req.setIndexName(xpress.getIndexName()); req.setKeyConditionExpression(xpress.getKeyConditionExpression()); processKeyConditions(req, xpress, model); req.withScanIndexForward(xpress.isScanIndexForward()) .withLimit(xpress.getLimit()) .withExclusiveStartKey(xpress.getExclusiveStartKey()) .withQueryFilter(xpress.getQueryFilter()) .withConditionalOperator(xpress.getConditionalOperator()) .withSelect(xpress.getSelect()) .withProjectionExpression(xpress.getProjectionExpression()) .withFilterExpression(xpress.getFilterExpression()) .withExpressionAttributeNames(xpress.getExpressionAttributeNames()) .withExpressionAttributeValues(xpress.getExpressionAttributeValues()) .withReturnConsumedCapacity(xpress.getReturnConsumedCapacity()) .withRequestMetricCollector(config.getRequestMetricCollector()) ; return applyUserAgent(req); }
/** * {@inheritDoc} */ @Override public <T> DynamoDBMapperTableModel<T> getTableModel(Class<T> domainClass) { return dynamoDBMapper.getTableModel(domainClass, dynamoDBMapperConfig); }
/** * Creates a new table mapper using this mapper to perform operations. * @param <T> The object type which this mapper operates. * @param <H> The hash key value type. * @param <R> The range key value type; use <code>?</code> if no range key. * @param clazz The object class. * @return The table mapper. */ public <T,H,R> DynamoDBTableMapper<T,H,R> newTableMapper(Class<T> clazz) { DynamoDBMapperConfig config = mergeConfig(null); return new DynamoDBTableMapper<T,H,R>(this.db, this, config, getTableModel(clazz, config)); }
private <T> AttributeTransformer.Parameters<T> toParameters( final Map<String, AttributeValue> attributeValues, final boolean partialUpdate, final Class<T> modelClass, final String tableName, final DynamoDBMapperConfig mapperConfig) { return new TransformerParameters<T>( getTableModel(modelClass, mapperConfig), attributeValues, partialUpdate, modelClass, mapperConfig, tableName); }
@Override public Map<String, List<Object>> batchLoad(Map<Class<?>, List<KeyPair>> itemsToGet, DynamoDBMapperConfig config) { config = mergeConfig(config); List<Object> keys = new ArrayList<Object>(); if ( itemsToGet != null ) { for ( Class<?> clazz : itemsToGet.keySet() ) { if ( itemsToGet.get(clazz) != null ) { final DynamoDBMapperTableModel model = getTableModel(clazz, config); for ( KeyPair keyPair : itemsToGet.get(clazz) ) { keys.add(model.createKey(keyPair.getHashKey(), keyPair.getRangeKey())); } } } } return batchLoad(keys, config); }
@Override public <T extends Object> T load(Class<T> clazz, Object hashKey, Object rangeKey, DynamoDBMapperConfig config) { config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); T keyObject = model.createKey(hashKey, rangeKey); return load(keyObject, config); }
/** * The one true implementation of marshallIntoObject. */ private <T> T privateMarshallIntoObject( AttributeTransformer.Parameters<T> parameters) { Class<T> clazz = parameters.getModelClass(); Map<String, AttributeValue> values = untransformAttributes(parameters); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, parameters.getMapperConfig()); return model.unconvert(values); }
protected <T> QueryRequest createQueryRequestFromExpression(Class<T> clazz, DynamoDBQueryExpression<T> xpress, DynamoDBMapperConfig config) { final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); QueryRequest req = new QueryRequest(); req.setConsistentRead(xpress.isConsistentRead()); req.setTableName(getTableName(clazz, xpress.getHashKeyValues(), config)); req.setIndexName(xpress.getIndexName()); req.setKeyConditionExpression(xpress.getKeyConditionExpression()); processKeyConditions(req, xpress, model); req.withScanIndexForward(xpress.isScanIndexForward()) .withLimit(xpress.getLimit()) .withExclusiveStartKey(xpress.getExclusiveStartKey()) .withQueryFilter(xpress.getQueryFilter()) .withConditionalOperator(xpress.getConditionalOperator()) .withSelect(xpress.getSelect()) .withProjectionExpression(xpress.getProjectionExpression()) .withFilterExpression(xpress.getFilterExpression()) .withExpressionAttributeNames(xpress.getExpressionAttributeNames()) .withExpressionAttributeValues(xpress.getExpressionAttributeValues()) .withReturnConsumedCapacity(xpress.getReturnConsumedCapacity()) .withRequestMetricCollector(config.getRequestMetricCollector()) ; return applyUserAgent(req); }