use of com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper in project tutorials by eugenp.
the class ProductInfoRepositoryIntegrationTest method setup.
@Before
public void setup() {
try {
repository = new ProductInfoRepository();
repository.setMapper(dynamoDBMapper);
CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class);
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
amazonDynamoDB.createTable(tableRequest);
} catch (ResourceInUseException e) {
// Do nothing, table already created
}
// TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
}
use of com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper in project qpp-conversion-tool by CMSgov.
the class DynamoDbConfigTest method dbMapperNoAudit.
@Test
public void dbMapperNoAudit() {
when(environment.getProperty(eq(Constants.NO_AUDIT_ENV_VARIABLE))).thenReturn("true");
when(environment.getProperty(eq(Constants.DYNAMO_TABLE_NAME_ENV_VARIABLE))).thenReturn(null);
when(environment.getProperty(eq(Constants.KMS_KEY_ENV_VARIABLE))).thenReturn(null);
DynamoDBMapper dynamoDBMapper = underTest.dynamoDbMapper(amazonDynamoDB);
assertThat(dynamoDBMapper).isNull();
}
use of com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper in project gora by apache.
the class DynamoDBNativeStore method execute.
/**
* Executes a query after building a DynamoDB specific query based on the
* received one
*/
@Override
public Result<K, T> execute(Query<K, T> query) throws GoraException {
try {
DynamoDBQuery<K, T> dynamoDBQuery = buildDynamoDBQuery(query);
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBStoreHandler.getDynamoDbClient());
List<T> objList = null;
if (DynamoDBQuery.getType().equals(DynamoDBQuery.RANGE_QUERY))
objList = mapper.scan(persistentClass, (DynamoDBScanExpression) dynamoDBQuery.getQueryExpression());
if (DynamoDBQuery.getType().equals(DynamoDBQuery.SCAN_QUERY))
objList = mapper.scan(persistentClass, (DynamoDBScanExpression) dynamoDBQuery.getQueryExpression());
return new DynamoDBResult<K, T>(this, query, objList);
} catch (Exception e) {
throw new GoraException(e);
}
}
use of com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper in project gora by apache.
the class DynamoDBNativeStore method delete.
/**
* Deletes the object using key
*
* @param key the key of the object
* @return true for a successful process
*/
@Override
public boolean delete(K key) throws GoraException {
try {
T object = null;
Object rangeKey = null, hashKey = null;
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBStoreHandler.getDynamoDbClient());
for (Method met : key.getClass().getDeclaredMethods()) {
if (met.getName().equals(GET_RANGE_KEY_METHOD)) {
Object[] params = null;
rangeKey = met.invoke(key, params);
break;
}
}
for (Method met : key.getClass().getDeclaredMethods()) {
if (met.getName().equals(GET_HASH_KEY_METHOD)) {
Object[] params = null;
hashKey = met.invoke(key, params);
break;
}
}
if (hashKey == null)
object = (T) mapper.load(persistentClass, key);
if (rangeKey == null)
object = (T) mapper.load(persistentClass, hashKey);
else
object = (T) mapper.load(persistentClass, hashKey, rangeKey);
if (object == null)
return false;
// setting key for dynamodbMapper
mapper.delete(object);
return true;
} catch (Exception e) {
throw new GoraException(e);
}
}
Aggregations