use of org.apache.gora.aerospike.query.AerospikeQueryResult in project gora by apache.
the class AerospikeStore method execute.
/**
* {@inheritDoc}
*
* @param query the query to execute.
* @return the query result
*/
@Override
public Result<K, T> execute(Query<K, T> query) throws GoraException {
List<AerospikeResultRecord> resultRecords = new ArrayList<>();
String namespace = aerospikeParameters.getAerospikeMapping().getNamespace();
String set = aerospikeParameters.getAerospikeMapping().getSet();
try {
// Query execution without any keys
if (query.getStartKey() == null && query.getEndKey() == null) {
try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
while (recordSet.next()) {
AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(recordSet.getKey(), recordSet.getRecord());
resultRecords.add(aerospikeRecord);
}
}
} else // Query execution for single key
if (query.getKey() != null) {
Key key = getAerospikeKey(query.getKey());
Record record = aerospikeClient.get(null, key);
if (record != null) {
resultRecords.add(new AerospikeResultRecord(key, record));
}
}
// }
return new AerospikeQueryResult<>(this, query, resultRecords, getFieldsToQuery(null));
} catch (Exception e) {
throw new GoraException(e);
}
}
Aggregations