Search in sources :

Example 1 with AerospikeQueryResult

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);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) AerospikeResultRecord(org.apache.gora.aerospike.query.AerospikeResultRecord) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) AerospikeResultRecord(org.apache.gora.aerospike.query.AerospikeResultRecord) RecordSet(com.aerospike.client.query.RecordSet) AerospikeQueryResult(org.apache.gora.aerospike.query.AerospikeQueryResult) Key(com.aerospike.client.Key) AerospikeException(com.aerospike.client.AerospikeException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)1 Key (com.aerospike.client.Key)1 Record (com.aerospike.client.Record)1 RecordSet (com.aerospike.client.query.RecordSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AerospikeQueryResult (org.apache.gora.aerospike.query.AerospikeQueryResult)1 AerospikeResultRecord (org.apache.gora.aerospike.query.AerospikeResultRecord)1 GoraException (org.apache.gora.util.GoraException)1