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;
}
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()));
}
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()));
}
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()));
}
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;
}
}
Aggregations