Search in sources :

Example 1 with CTX

use of com.aerospike.client.cdt.CTX in project aerospike-client-java by aerospike.

the class TestListExp method modifyWithContext.

@Test
public void modifyWithContext() {
    List<Value> listSubA = new ArrayList<Value>();
    listSubA.add(Value.get("e"));
    listSubA.add(Value.get("d"));
    listSubA.add(Value.get("c"));
    listSubA.add(Value.get("b"));
    listSubA.add(Value.get("a"));
    List<Value> listA = new ArrayList<Value>();
    listA.add(Value.get("a"));
    listA.add(Value.get("b"));
    listA.add(Value.get("c"));
    listA.add(Value.get("d"));
    listA.add(Value.get(listSubA));
    List<Value> listB = new ArrayList<Value>();
    listB.add(Value.get("x"));
    listB.add(Value.get("y"));
    listB.add(Value.get("z"));
    client.operate(null, keyA, ListOperation.appendItems(ListPolicy.Default, binA, listA), ListOperation.appendItems(ListPolicy.Default, binB, listB), Operation.put(new Bin(binC, "M")));
    CTX ctx = CTX.listIndex(4);
    Record record;
    List<?> result;
    policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append binB/binC to binA in expression.
    ListExp.appendItems(ListPolicy.Default, Exp.listBin(binB), ListExp.append(ListPolicy.Default, Exp.stringBin(binC), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
    record = client.get(policy, keyA, binA);
    assertRecordFound(keyA, record);
    result = record.getList(binA);
    assertEquals(5, result.size());
    policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append local listB and local "M" string to binA in expression.
    ListExp.appendItems(ListPolicy.Default, Exp.val(listB), ListExp.append(ListPolicy.Default, Exp.val("M"), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
    record = client.get(policy, keyA, binA);
    assertRecordFound(keyA, record);
    result = record.getList(binA);
    assertEquals(5, result.size());
}
Also used : Bin(com.aerospike.client.Bin) CTX(com.aerospike.client.cdt.CTX) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 2 with CTX

use of com.aerospike.client.cdt.CTX 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);
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) CTX(com.aerospike.client.cdt.CTX) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 3 with CTX

use of com.aerospike.client.cdt.CTX in project aerospike-client-java by aerospike.

the class OperateMap method runNestedListCreateExample.

public void runNestedListCreateExample(AerospikeClient client, Parameters params) {
    Key key = new Key(params.namespace, params.set, "mapkey3");
    String binName = params.getBinName("mapbin");
    // Delete record if it already exists.
    client.delete(params.writePolicy, key);
    List<Value> l1 = new ArrayList<Value>();
    l1.add(Value.get(7));
    l1.add(Value.get(9));
    l1.add(Value.get(5));
    Map<Value, Value> inputMap = new HashMap<Value, Value>();
    inputMap.put(Value.get("key1"), Value.get(l1));
    // Create maps.
    client.put(params.writePolicy, key, new Bin(binName, inputMap));
    // Create ordered list at map's "key2" only if list does not exist.
    // Append 2,1 to ordered list.
    CTX ctx = CTX.mapKey(Value.get("key2"));
    Record record = client.operate(params.writePolicy, key, ListOperation.create(binName, ListOrder.ORDERED, false, ctx), ListOperation.append(binName, Value.get(2), ctx), ListOperation.append(binName, Value.get(1), ctx), Operation.get(binName));
    record = client.get(params.policy, key);
    console.info("Record: " + record);
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) CTX(com.aerospike.client.cdt.CTX) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 4 with CTX

use of com.aerospike.client.cdt.CTX in project aerospike-client-java by aerospike.

the class Pack method init.

public static void init(Packer packer, CTX[] ctx) {
    if (ctx != null && ctx.length > 0) {
        packer.packArrayBegin(3);
        packer.packInt(0xff);
        packer.packArrayBegin(ctx.length * 2);
        for (CTX c : ctx) {
            packer.packInt(c.id);
            c.value.pack(packer);
        }
    }
}
Also used : CTX(com.aerospike.client.cdt.CTX)

Aggregations

CTX (com.aerospike.client.cdt.CTX)4 Bin (com.aerospike.client.Bin)3 Record (com.aerospike.client.Record)3 Value (com.aerospike.client.Value)3 Key (com.aerospike.client.Key)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)1