use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class ListMap method testListStrings.
/**
* Write/Read ArrayList<String> directly instead of relying on java serializer.
*/
private void testListStrings(AerospikeClient client, Parameters params) throws Exception {
console.info("Read/Write ArrayList<String>");
Key key = new Key(params.namespace, params.set, "listkey1");
client.delete(params.writePolicy, key);
ArrayList<String> list = new ArrayList<String>();
list.add("string1");
list.add("string2");
list.add("string3");
Bin bin = new Bin(params.getBinName("listbin1"), list);
client.put(params.writePolicy, key, bin);
Record record = client.get(params.policy, key, bin.name);
List<?> receivedList = (List<?>) record.getValue(bin.name);
validateSize(3, receivedList.size());
validate("string1", receivedList.get(0));
validate("string2", receivedList.get(1));
validate("string3", receivedList.get(2));
console.info("Read/Write ArrayList<String> successful.");
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class ListMap method testMapComplex.
/**
* Write/Read HashMap<Object,Object> directly instead of relying on java serializer.
*/
private void testMapComplex(AerospikeClient client, Parameters params) throws Exception {
console.info("Read/Write HashMap<Object,Object>");
Key key = new Key(params.namespace, params.set, "mapkey2");
client.delete(params.writePolicy, key);
byte[] blob = new byte[] { 3, 52, 125 };
List<Integer> list = new ArrayList<Integer>();
list.add(100034);
list.add(12384955);
list.add(3);
list.add(512);
HashMap<Object, Object> map = new HashMap<Object, Object>();
map.put("key1", "string1");
map.put("key2", 2);
map.put("key3", blob);
// map.put("key4", Value.getAsList(list)) works too
map.put("key4", list);
map.put("key5", true);
map.put("key6", false);
Bin bin = new Bin(params.getBinName("mapbin2"), map);
client.put(params.writePolicy, key, bin);
Record record = client.get(params.policy, key, bin.name);
Map<?, ?> receivedMap = (Map<?, ?>) record.getValue(bin.name);
validateSize(6, receivedMap.size());
validate("string1", receivedMap.get("key1"));
// Server convert numbers to long, so must expect long.
validate(2L, receivedMap.get("key2"));
validate(blob, (byte[]) receivedMap.get("key3"));
List<?> receivedInner = (List<?>) receivedMap.get("key4");
validateSize(4, receivedInner.size());
validate(100034L, receivedInner.get(0));
validate(12384955L, receivedInner.get(1));
validate(3L, receivedInner.get(2));
validate(512L, receivedInner.get(3));
validate(true, receivedMap.get("key5"));
validate(false, receivedMap.get("key6"));
console.info("Read/Write HashMap<Object,Object> successful");
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class ListMap method testListComplex.
/**
* Write/Read ArrayList<Object> directly instead of relying on java serializer.
*/
private void testListComplex(AerospikeClient client, Parameters params) throws Exception {
console.info("Read/Write ArrayList<Object>");
Key key = new Key(params.namespace, params.set, "listkey2");
client.delete(params.writePolicy, key);
byte[] blob = new byte[] { 3, 52, 125 };
ArrayList<Object> list = new ArrayList<Object>();
list.add("string1");
list.add(2);
list.add(blob);
Bin bin = new Bin(params.getBinName("listbin2"), list);
client.put(params.writePolicy, key, bin);
Record record = client.get(params.policy, key, bin.name);
List<?> receivedList = (List<?>) record.getValue(bin.name);
validateSize(3, receivedList.size());
validate("string1", receivedList.get(0));
// Server convert numbers to long, so must expect long.
validate(2L, receivedList.get(1));
validate(blob, (byte[]) receivedList.get(2));
console.info("Read/Write ArrayList<Object> successful.");
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class OperateBit method runSimpleExample.
/**
* Simple example of bit functionality.
*/
public void runSimpleExample(AerospikeClient client, Parameters params) throws Exception {
Key key = new Key(params.namespace, params.set, "bitkey");
String binName = params.getBinName("bitbin");
// Delete record if it already exists.
client.delete(params.writePolicy, key);
byte[] bytes = new byte[] { 0b00000001, 0b00000010, 0b00000011, 0b00000100, 0b00000101 };
client.put(params.writePolicy, key, new Bin(binName, bytes));
// Set last 3 bits of bitmap to true.
Record record = client.operate(params.writePolicy, key, BitOperation.set(BitPolicy.Default, binName, -3, 3, new byte[] { (byte) 0b11100000 }), Operation.get(binName));
List<?> list = record.getList(binName);
byte[] val = (byte[]) list.get(1);
for (byte b : val) {
console.info(Byte.toString(b));
}
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class OperateMap method runNestedMapCreateExample.
public void runNestedMapCreateExample(AerospikeClient client, Parameters params) {
Key key = new Key(params.namespace, params.set, "mapkey2");
String binName = params.getBinName("mapbin");
// Delete record if it already exists.
client.delete(params.writePolicy, key);
Map<Value, Value> m1 = new HashMap<Value, Value>();
m1.put(Value.get("key21"), Value.get(7));
m1.put(Value.get("key22"), Value.get(6));
Map<Value, Value> m2 = new HashMap<Value, Value>();
m2.put(Value.get("a"), Value.get(3));
m2.put(Value.get("c"), Value.get(5));
Map<Value, Value> inputMap = new HashMap<Value, Value>();
inputMap.put(Value.get("key1"), Value.get(m1));
inputMap.put(Value.get("key2"), Value.get(m2));
// Create maps.
client.put(params.writePolicy, key, new Bin(binName, inputMap));
// Create key ordered map at "key2" only if map does not exist.
// Set map value to 4 for map key "key21" inside of map key "key2".
CTX ctx = CTX.mapKey(Value.get("key2"));
Record record = client.operate(params.writePolicy, key, MapOperation.create(binName, MapOrder.KEY_VALUE_ORDERED, ctx), MapOperation.put(MapPolicy.Default, binName, Value.get("b"), Value.get(4), ctx), Operation.get(binName));
record = client.get(params.policy, key);
console.info("Record: " + record);
}
Aggregations