use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class Operate method runExample.
/**
* Demonstrate multiple operations on a single record in one call.
*/
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
// Write initial record.
Key key = new Key(params.namespace, params.set, "opkey");
Bin bin1 = new Bin("optintbin", 7);
Bin bin2 = new Bin("optstringbin", "string value");
console.info("Put: namespace=%s set=%s key=%s bin1=%s value1=%s bin2=%s value2=%s", key.namespace, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);
client.put(params.writePolicy, key, bin1, bin2);
// Add integer, write new string and read record.
Bin bin3 = new Bin(bin1.name, 4);
Bin bin4 = new Bin(bin2.name, "new string");
console.info("Add: " + bin3.value);
console.info("Write: " + bin4.value);
console.info("Read:");
Record record = client.operate(params.writePolicy, key, Operation.add(bin3), Operation.put(bin4), Operation.get());
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
validateBin(key, record, bin3.name, 11, record.getInt(bin3.name));
validateBin(key, record, bin4.name, bin4.value.toString(), record.getValue(bin4.name));
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class UserDefinedFunction method appendListUsingUdf.
private void appendListUsingUdf(AerospikeClient client, Parameters params) throws Exception {
Key key = new Key(params.namespace, params.set, "udfkey5");
String binName = params.getBinName("udfbin5");
String value = "appended value";
client.execute(params.writePolicy, key, "record_example", "appendListBin", Value.get(binName), Value.get(value));
Record record = client.get(params.policy, key, binName);
if (record != null) {
Object received = record.getValue(binName);
if (received != null && received instanceof List<?>) {
List<?> list = (List<?>) received;
if (list.size() == 5) {
Object obj = list.get(4);
if (obj.equals(value)) {
console.info("UDF data matched: namespace=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, binName, received);
return;
}
}
}
console.error("UDF data mismatch");
console.error("Expected: " + value);
console.error("Received: " + received);
} else {
console.error("Failed to find record: " + key.userKey);
}
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class UserDefinedFunction method writeUsingUdf.
private void writeUsingUdf(AerospikeClient client, Parameters params) throws Exception {
Key key = new Key(params.namespace, params.set, "udfkey1");
Bin bin = new Bin(params.getBinName("udfbin1"), "string value");
client.execute(params.writePolicy, key, "record_example", "writeBin", Value.get(bin.name), bin.value);
Record record = client.get(params.policy, key, bin.name);
String expected = bin.value.toString();
String received = record.getString(bin.name);
if (received != null && received.equals(expected)) {
console.info("Data matched: namespace=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, bin.name, received);
} else {
console.error("Data mismatch: Expected %s. Received %s.", expected, received);
}
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestAsyncBatch method asyncBatchGetHeaders.
@Test
public void asyncBatchGetHeaders() throws Exception {
client.getHeader(eventLoop, new RecordArrayListener() {
public void onSuccess(Key[] keys, Record[] records) {
if (assertEquals(Size, records.length)) {
for (int i = 0; i < records.length; i++) {
Record record = records[i];
if (!assertRecordFound(keys[i], record)) {
break;
}
if (!assertGreaterThanZero(record.generation)) {
break;
}
if (!assertGreaterThanZero(record.expiration)) {
break;
}
}
}
notifyComplete();
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, sendKeys);
waitTillComplete();
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestAsyncBatch method asyncBatchListOperate.
@Test
public void asyncBatchListOperate() throws Exception {
client.get(eventLoop, new RecordArrayListener() {
public void onSuccess(Key[] keys, Record[] records) {
if (assertEquals(Size, records.length)) {
for (int i = 0; i < records.length; i++) {
Record record = records[i];
List<?> results = record.getList(ListBin);
long size = (Long) results.get(0);
long val = (Long) results.get(1);
assertEquals(i + 1, size);
assertEquals(i * (i + 1), val);
}
}
notifyComplete();
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, sendKeys, ListOperation.size(ListBin), ListOperation.getByIndex(ListBin, -1, ListReturnType.VALUE));
waitTillComplete();
}
Aggregations