Search in sources :

Example 81 with Bin

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

the class QueryRegionFilter method writeRecords.

private void writeRecords(AerospikeClient client, Parameters params, String keyPrefix, String binName1, String binName2, 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 bin1 = Bin.asGeoJSON(binName1, ptsb.toString());
        Bin bin2;
        if (i % 7 == 0) {
            bin2 = new Bin(binName2, "hospital");
        } else if (i % 2 == 0) {
            bin2 = new Bin(binName2, "school");
        } else {
            bin2 = new Bin(binName2, "store");
        }
        client.put(params.writePolicy, key, bin1, bin2);
    }
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Example 82 with Bin

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

the class QuerySum method writeRecords.

private void writeRecords(AerospikeClient client, Parameters params, String keyPrefix, String binName, int size) throws Exception {
    for (int i = 1; i <= size; i++) {
        Key key = new Key(params.namespace, params.set, keyPrefix + i);
        Bin bin = new Bin(binName, i);
        console.info("Put: ns=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, bin.name, bin.value);
        client.put(params.writePolicy, key, bin);
    }
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Example 83 with Bin

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

the class Command method setWrite.

public final void setWrite(WritePolicy policy, Operation.Type operation, Key key, Bin[] bins) {
    begin();
    int fieldCount = estimateKeySize(policy, key);
    CommandExp exp = getCommandExp(policy);
    if (exp != null) {
        dataOffset += exp.size();
        fieldCount++;
    }
    for (Bin bin : bins) {
        estimateOperationSize(bin);
    }
    sizeBuffer();
    writeHeaderWrite(policy, Command.INFO2_WRITE, fieldCount, bins.length);
    writeKey(policy, key);
    if (exp != null) {
        dataOffset = exp.write(this);
    }
    for (Bin bin : bins) {
        writeOperation(bin, operation);
    }
    end();
    compress(policy);
}
Also used : Bin(com.aerospike.client.Bin) CommandExp(com.aerospike.client.exp.CommandExp)

Example 84 with Bin

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

the class QueryPredExp method writeRecords.

private void writeRecords(AerospikeClient client, Parameters params, String binName, int size) throws Exception {
    console.info("Write " + size + " records.");
    for (int i = 1; i <= size; i++) {
        Key key = new Key(params.namespace, params.set, i);
        Bin bin1 = new Bin(binName, i);
        Bin bin2 = new Bin("bin2", i * 10);
        Bin bin3;
        if (i % 4 == 0) {
            bin3 = new Bin("bin3", "prefix-" + i + "-suffix");
        } else if (i % 2 == 0) {
            bin3 = new Bin("bin3", "prefix-" + i + "-SUFFIX");
        } else {
            bin3 = new Bin("bin3", "pre-" + i + "-suf");
        }
        client.put(params.writePolicy, key, bin1, bin2, bin3);
    }
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Example 85 with Bin

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

the class TestQueryPredExp method prepare.

@BeforeClass
public static void prepare() {
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask task = client.createIndex(policy, args.namespace, setName, indexName, binName, IndexType.NUMERIC);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, setName, keyPrefix + i);
        List<Integer> list = null;
        Map<String, String> map = null;
        if (i == 1) {
            list = new ArrayList<Integer>(5);
            list.add(1);
            list.add(2);
            list.add(4);
            list.add(9);
            list.add(20);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 2) {
            list = new ArrayList<Integer>(3);
            list.add(5);
            list.add(9);
            list.add(100);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 3) {
            map = new HashMap<String, String>();
            map.put("A", "AAA");
            map.put("B", "BBB");
            map.put("C", "BBB");
        // list will be null, which means listbin will not exist in this record.
        } else {
            list = new ArrayList<Integer>(0);
            map = new HashMap<String, String>(0);
        }
        client.put(null, key, new Bin(binName, i), new Bin("bin2", i), new Bin("listbin", list), new Bin("mapbin", map));
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) ArrayList(java.util.ArrayList) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Aggregations

Bin (com.aerospike.client.Bin)151 Key (com.aerospike.client.Key)129 Record (com.aerospike.client.Record)70 Test (org.junit.Test)54 AerospikeException (com.aerospike.client.AerospikeException)34 ArrayList (java.util.ArrayList)31 WritePolicy (com.aerospike.client.policy.WritePolicy)27 HashMap (java.util.HashMap)22 Value (com.aerospike.client.Value)20 List (java.util.List)15 BeforeClass (org.junit.BeforeClass)14 Map (java.util.Map)13 Policy (com.aerospike.client.policy.Policy)12 IndexTask (com.aerospike.client.task.IndexTask)11 WriteListener (com.aerospike.client.listener.WriteListener)5 RegisterTask (com.aerospike.client.task.RegisterTask)5 AbstractMap (java.util.AbstractMap)4 TreeMap (java.util.TreeMap)4 CTX (com.aerospike.client.cdt.CTX)3 BitPolicy (com.aerospike.client.operation.BitPolicy)3