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.");
}
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);
}
}
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();
}
}
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();
}
}
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);
}
}
Aggregations