Search in sources :

Example 41 with Operation

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

the class Command method setOperate.

public final boolean setOperate(WritePolicy policy, Key key, Operation[] operations) throws AerospikeException {
    begin();
    int fieldCount = estimateKeySize(policy, key);
    int readAttr = 0;
    int writeAttr = 0;
    boolean hasWrite = false;
    boolean readBin = false;
    boolean readHeader = false;
    boolean respondAllOps = policy.respondAllOps;
    for (Operation operation : operations) {
        switch(operation.type) {
            case MAP_READ:
                // Map operations require respondAllOps to be true.
                respondAllOps = true;
            // Fall through to read.
            case CDT_READ:
            case READ:
                readAttr |= Command.INFO1_READ;
                // Read all bins if no bin is specified.
                if (operation.binName == null) {
                    readAttr |= Command.INFO1_GET_ALL;
                }
                readBin = true;
                break;
            case READ_HEADER:
                readAttr |= Command.INFO1_READ;
                readHeader = true;
                break;
            case MAP_MODIFY:
                // Map operations require respondAllOps to be true.
                respondAllOps = true;
            // Fall through to write.
            default:
                writeAttr = Command.INFO2_WRITE;
                hasWrite = true;
                break;
        }
        estimateOperationSize(operation);
    }
    sizeBuffer();
    if (readHeader && !readBin) {
        readAttr |= Command.INFO1_NOBINDATA;
    }
    if (respondAllOps) {
        writeAttr |= Command.INFO2_RESPOND_ALL_OPS;
    }
    writeHeader(policy, readAttr, writeAttr, fieldCount, operations.length);
    writeKey(policy, key);
    for (Operation operation : operations) {
        writeOperation(operation);
    }
    end();
    return hasWrite;
}
Also used : Operation(com.aerospike.client.Operation)

Example 42 with Operation

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

the class ListOperation method append.

/**
 * Create default list append operation.
 * Server appends value to end of list bin.
 * Server returns list size.
 */
public static Operation append(String binName, Value value) {
    Packer packer = new Packer();
    packer.packRawShort(APPEND);
    packer.packArrayBegin(1);
    value.pack(packer);
    return new Operation(Operation.Type.CDT_MODIFY, binName, Value.get(packer.toByteArray()));
}
Also used : Operation(com.aerospike.client.Operation) Packer(com.aerospike.client.util.Packer)

Example 43 with Operation

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

the class ListOperation method insertItems.

/**
 * Create list insert items operation with policy.
 * Server inserts each input list item starting at specified index of list bin.
 * Server returns list size.
 */
public static Operation insertItems(ListPolicy policy, String binName, int index, List<Value> list) {
    Packer packer = new Packer();
    packer.packRawShort(INSERT_ITEMS);
    packer.packArrayBegin(3);
    packer.packInt(index);
    packer.packValueList(list);
    packer.packInt(policy.flags);
    return new Operation(Operation.Type.CDT_MODIFY, binName, Value.get(packer.toByteArray()));
}
Also used : Operation(com.aerospike.client.Operation) Packer(com.aerospike.client.util.Packer)

Example 44 with Operation

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

the class ListOperation method append.

/**
 * Create list append operation with policy.
 * Server appends value to list bin.
 * Server returns list size.
 */
public static Operation append(ListPolicy policy, String binName, Value value) {
    Packer packer = new Packer();
    packer.packRawShort(APPEND);
    packer.packArrayBegin(3);
    value.pack(packer);
    packer.packInt(policy.attributes);
    packer.packInt(policy.flags);
    return new Operation(Operation.Type.CDT_MODIFY, binName, Value.get(packer.toByteArray()));
}
Also used : Operation(com.aerospike.client.Operation) Packer(com.aerospike.client.util.Packer)

Example 45 with Operation

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

the class Command method estimateOperate.

public final void estimateOperate(Operation[] operations, OperateArgs args) {
    boolean readBin = false;
    boolean readHeader = false;
    boolean respondAllOps = false;
    for (Operation operation : operations) {
        switch(operation.type) {
            case MAP_READ:
                // Map operations require respondAllOps to be true.
                respondAllOps = true;
            // Fall through to read.
            case CDT_READ:
            case READ:
                args.readAttr |= Command.INFO1_READ;
                // Read all bins if no bin is specified.
                if (operation.binName == null) {
                    args.readAttr |= Command.INFO1_GET_ALL;
                }
                readBin = true;
                break;
            case READ_HEADER:
                args.readAttr |= Command.INFO1_READ;
                readHeader = true;
                break;
            case MAP_MODIFY:
                // Map operations require respondAllOps to be true.
                respondAllOps = true;
            // Fall through to write.
            default:
                args.writeAttr = Command.INFO2_WRITE;
                args.hasWrite = true;
                break;
        }
        estimateOperationSize(operation);
    }
    args.size = dataOffset;
    if (readHeader && !readBin) {
        args.readAttr |= Command.INFO1_NOBINDATA;
    }
    if (respondAllOps) {
        args.writeAttr |= Command.INFO2_RESPOND_ALL_OPS;
    }
}
Also used : Operation(com.aerospike.client.Operation)

Aggregations

Operation (com.aerospike.client.Operation)51 Packer (com.aerospike.client.util.Packer)36 Record (com.aerospike.client.Record)6 ArrayList (java.util.ArrayList)6 Key (com.aerospike.client.Key)5 BatchRead (com.aerospike.client.BatchRead)4 CommandExp (com.aerospike.client.exp.CommandExp)4 ListOperation (com.aerospike.client.cdt.ListOperation)3 ExpOperation (com.aerospike.client.exp.ExpOperation)3 Expression (com.aerospike.client.exp.Expression)3 HLLOperation (com.aerospike.client.operation.HLLOperation)3 HLLPolicy (com.aerospike.client.operation.HLLPolicy)3 List (java.util.List)2 Test (org.junit.Test)2 AerospikeException (com.aerospike.client.AerospikeException)1 Bin (com.aerospike.client.Bin)1 Value (com.aerospike.client.Value)1 HLLValue (com.aerospike.client.Value.HLLValue)1 StringValue (com.aerospike.client.Value.StringValue)1 BatchListListener (com.aerospike.client.listener.BatchListListener)1