Search in sources :

Example 71 with Key

use of com.aerospike.client.Key in project aerospike-client-java by aerospike.

the class QueryGeoCollection method writeMapRecords.

private void writeMapRecords(AerospikeClient client, Parameters params, String keyPrefix, String binName, String binName2, String valuePrefix, int size) throws Exception {
    for (int i = 0; i < size; i++) {
        Key key = new Key(params.namespace, params.set, keyPrefix + i);
        HashMap<String, Value> map = new HashMap<String, Value>();
        for (int jj = 0; jj < 10; ++jj) {
            double plat = 0.0 + (0.01 * i);
            double plng = 0.0 + (0.10 * jj);
            String geoString = generatePoint(plat, plng);
            map.put(valuePrefix + "pointkey_" + i + "_" + jj, Value.getAsGeoJSON(geoString));
            double rlat = 0.0 + (0.01 * i);
            double rlng = 0.0 - (0.10 * jj);
            geoString = generatePolygon(rlat, rlng);
            map.put(valuePrefix + "regionkey_" + i + "_" + jj, Value.getAsGeoJSON(geoString));
        }
        Bin bin = new Bin(binName, map);
        Bin bin2 = new Bin(binName2, "other_bin_value_" + i);
        client.put(params.writePolicy, key, bin, bin2);
    }
    console.info("Write " + size + " records.");
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) Value(com.aerospike.client.Value) Key(com.aerospike.client.Key)

Example 72 with Key

use of com.aerospike.client.Key in project aerospike-client-java by aerospike.

the class QueryGeoCollection method deleteRecords.

private void deleteRecords(AerospikeClient client, Parameters params, String keyPrefix, int size) throws Exception {
    for (int i = 0; i < size; i++) {
        Key key = new Key(params.namespace, params.set, keyPrefix + i);
        client.delete(params.writePolicy, key);
    }
}
Also used : Key(com.aerospike.client.Key)

Example 73 with Key

use of com.aerospike.client.Key in project aerospike-client-java by aerospike.

the class QueryInteger method runQuery.

private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
    int begin = 14;
    int end = 18;
    console.info("Query for: ns=%s set=%s index=%s bin=%s >= %s <= %s", params.namespace, params.set, indexName, binName, begin, end);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.range(binName, begin, end));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Key key = rs.getKey();
            Record record = rs.getRecord();
            int result = record.getInt(binName);
            console.info("Record found: ns=%s set=%s bin=%s digest=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
            count++;
        }
        if (count != 5) {
            console.error("Query count mismatch. Expected 5. Received " + count);
        }
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Example 74 with Key

use of com.aerospike.client.Key in project aerospike-client-java by aerospike.

the class QueryRegion method runRadiusQuery.

private void runRadiusQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
    double lon = -122.0;
    double lat = 37.5;
    double radius = 50000.0;
    console.info("QueryRadius for: ns=%s set=%s index=%s bin=%s within long=%f lat=%f radius=%f", params.namespace, params.set, indexName, binName, lon, lat, radius);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.geoWithinRadius(binName, lon, lat, radius));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Key key = rs.getKey();
            Record record = rs.getRecord();
            String result = record.getGeoJSON(binName);
            console.info("Record found: ns=%s set=%s bin=%s digest=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
            count++;
        }
        if (count != 4) {
            console.error("Query count mismatch. Expected 4. Received " + count);
        }
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Example 75 with Key

use of com.aerospike.client.Key in project aerospike-client-java by aerospike.

the class QueryRegion method writeRecords.

private void writeRecords(AerospikeClient client, Parameters params, String keyPrefix, String binName, int size) throws Exception {
    console.info("Write " + size + " records.");
    for (int i = 0; i < size; i++) {
        double lng = -122 + (0.1 * i);
        double lat = 37.5 + (0.1 * i);
        StringBuilder ptsb = new StringBuilder();
        ptsb.append("{ \"type\": \"Point\", \"coordinates\": [");
        ptsb.append(String.valueOf(lng));
        ptsb.append(", ");
        ptsb.append(String.valueOf(lat));
        ptsb.append("] }");
        Key key = new Key(params.namespace, params.set, keyPrefix + i);
        Bin bin = Bin.asGeoJSON(binName, ptsb.toString());
        client.put(params.writePolicy, key, bin);
    }
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Aggregations

Key (com.aerospike.client.Key)204 Record (com.aerospike.client.Record)106 Bin (com.aerospike.client.Bin)104 Test (org.junit.Test)79 AerospikeException (com.aerospike.client.AerospikeException)50 ArrayList (java.util.ArrayList)50 Value (com.aerospike.client.Value)37 HashMap (java.util.HashMap)32 List (java.util.List)31 WritePolicy (com.aerospike.client.policy.WritePolicy)21 Map (java.util.Map)15 Statement (com.aerospike.client.query.Statement)10 BeforeClass (org.junit.BeforeClass)10 Policy (com.aerospike.client.policy.Policy)9 RecordSet (com.aerospike.client.query.RecordSet)9 IndexTask (com.aerospike.client.task.IndexTask)8 IOException (java.io.IOException)6 Collections.singletonList (java.util.Collections.singletonList)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 BatchRead (com.aerospike.client.BatchRead)5