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) {
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) {
LOG.error("Error while deleting value with key " + key.toString());
LOG.error(e.getMessage());
return false;
}
}
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) {
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);
}
Aggregations