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