/** * 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(dynamoDBClient); List<T> objList = null; if (DynamoDBQuery.getType().equals(DynamoDBQuery.RANGE_QUERY)) objList = mapper.query(persistentClass, (DynamoDBQueryExpression)dynamoDBQuery.getQueryExpression()); if (DynamoDBQuery.getType().equals(DynamoDBQuery.SCAN_QUERY)) objList = mapper.scan(persistentClass, (DynamoDBScanExpression)dynamoDBQuery.getQueryExpression()); return new DynamoDBResult<K, T>(this, query, objList); }
/** * Puts an object identified by a key * @throws IOException */ @Override public void put(K key, T obj) { try{ Object rangeKey = getRangeKey(key); Object hashKey = getHashKey(key); // if the key does not have these attributes then try to get them from the object if (hashKey == null) hashKey = getHashKey(obj); if (rangeKey == null) rangeKey = getRangeKey(obj); if (hashKey != null){ DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient); if (rangeKey != null) mapper.load(persistentClass, hashKey.toString(), rangeKey.toString()); else mapper.load(persistentClass, hashKey.toString()); mapper.save(obj); } else throw new GoraException("Error while retrieving keys from object: " + obj.toString()); }catch(NullPointerException npe){ LOG.error("Error while putting an item. " + npe.toString()); npe.printStackTrace(); }catch(Exception e){ LOG.error("Error while putting an item. " + obj.toString()); e.printStackTrace(); } }
public static<T extends DynamoModel> Map<String, List<Object>> batchFind(Class<T> type, List<String> ids) { Map<Class<?>, List<KeyPair>> map = new HashMap<Class<?>, List<KeyPair>>(); List<KeyPair> keypairs = new ArrayList<KeyPair>(); for(String s:ids) { KeyPair k = new KeyPair(); k.setHashKey(s); keypairs.add(k); } map.put(type, keypairs); String tableName = getTableNameFromAnnotation(type); DynamoDBMapper mapper = new DynamoDBMapper(DynamoDB.getConnection(), contructMapperConfig(tableName)); return mapper.batchLoad(map); }
public static<T extends DynamoModel> void batchSave(List<T> models) { if(0 == models.size()) { return; } String tableName = getTableNameFromAnnotation(models.get(0).getClass()); DynamoDBMapper mapper = new DynamoDBMapper(DynamoDB.getConnection(), contructMapperConfig(tableName)); mapper.batchSave(models); }
public DynamoModel() { super(); tableName = getTableNameFromAnnotation(this.getClass()); mapper = new DynamoDBMapper(DynamoDB.getConnection(), contructMapperConfig(tableName)); }
public static<T extends DynamoModel> T find(Class<T> type, String id) { String tableName = getTableNameFromAnnotation(type); DynamoDBMapper mapper = new DynamoDBMapper(DynamoDB.getConnection(), contructMapperConfig(tableName)); return mapper.load(type, id); }
public static<T extends DynamoModel> void delete(Class<T> type, T item) { String tableName = getTableNameFromAnnotation(type); DynamoDBMapper mapper = new DynamoDBMapper(DynamoDB.getConnection(), contructMapperConfig(tableName)); mapper.delete(item); }
public static<T extends DynamoModel> void batchDelete(Class<T> type, List<? extends DynamoModel> objectsToSave) { String tableName = getTableNameFromAnnotation(type); DynamoDBMapper mapper = new DynamoDBMapper(DynamoDB.getConnection(), contructMapperConfig(tableName)); mapper.batchDelete(objectsToSave); }