use of com.aerospike.client.Bin in project gora by apache.
the class AerospikeStore method put.
/**
* Method to insert the persistent objects with the given key to the aerospike database server.
* In writing the records, the policy defined in the mapping file is used to decide on the
* behaviour of transaction handling.
*
* @param key key of the object
* @param persistent object to be persisted
*/
@Override
public void put(K key, T persistent) throws GoraException {
try {
Key recordKey = getAerospikeKey(key);
List<Field> fields = persistent.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
if (!persistent.isDirty(i)) {
continue;
}
Object persistentValue = persistent.get(i);
String mappingBinName = aerospikeParameters.getAerospikeMapping().getBinMapping().get(fields.get(i).name());
if (mappingBinName == null) {
LOG.error("Aerospike mapping for field {}#{} not found. Wrong gora-aerospike-mapping.xml?", persistent.getClass().getName(), fields.get(i).name());
throw new RuntimeException("Aerospike mapping for field [" + persistent.getClass().getName() + "#" + fields.get(i).name() + "] not found. Wrong gora-aerospike-mapping.xml?");
}
Bin bin;
if (persistentValue != null) {
bin = new Bin(mappingBinName, getSerializableValue(persistentValue, fields.get(i).schema()));
} else {
bin = Bin.asNull(mappingBinName);
}
aerospikeClient.put(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey, bin);
}
} catch (Exception e) {
throw new GoraException(e);
}
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class RWTask method doWrite.
/**
* Write the key at the given index
*/
protected void doWrite(RandomShift random, long keyIdx, boolean multiBin, WritePolicy writePolicy) {
Key key = new Key(args.namespace, args.setName, keyStart + keyIdx);
// Use predictable value for 0th bin same as key value
Bin[] bins = args.getBins(random, multiBin, keyStart + keyIdx);
try {
put(writePolicy, key, bins);
} catch (AerospikeException ae) {
writeFailure(ae);
runNextCommand();
} catch (Exception e) {
writeFailure(e);
runNextCommand();
}
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class Arguments method getBins.
public Bin[] getBins(RandomShift random, boolean multiBin, long keySeed) {
if (fixedBins != null) {
return (multiBin) ? fixedBins : fixedBin;
}
int binCount = (multiBin) ? nBins : 1;
Bin[] bins = new Bin[binCount];
int specLength = objectSpec.length;
for (int i = 0; i < binCount; i++) {
String name = Integer.toString(i);
// Use passed in value for 0th bin. Random for others.
Value value = genValue(random, objectSpec[i % specLength], i == 0 ? keySeed : -1);
bins[i] = new Bin(name, value);
}
return bins;
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class InsertTaskSync method runCommand.
private void runCommand(long keyCurrent, RandomShift random) {
Key key = new Key(args.namespace, args.setName, keyCurrent);
// Use predictable value for 0th bin same as key value
Bin[] bins = args.getBins(random, true, keyCurrent);
put(key, bins);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestOperateMap method operateMapMixed.
@Test
public void operateMapMixed() {
// Test normal operations with map operations.
Key key = new Key(args.namespace, args.set, "opmkey2");
client.delete(null, key);
Map<Value, Value> itemMap = new HashMap<Value, Value>();
itemMap.put(Value.get(12), Value.get("myval"));
itemMap.put(Value.get(-8734), Value.get("str2"));
itemMap.put(Value.get(1), Value.get("my default"));
itemMap.put(Value.get(7), Value.get(1));
Record record = client.operate(null, key, MapOperation.putItems(new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteFlags.DEFAULT), binName, itemMap), Operation.put(new Bin("otherbin", "hello")));
assertRecordFound(key, record);
long size = record.getLong(binName);
assertEquals(4, size);
record = client.operate(null, key, MapOperation.getByKey(binName, Value.get(12), MapReturnType.INDEX), Operation.append(new Bin("otherbin", Value.get("goodbye"))), Operation.get("otherbin"));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
long index = record.getLong(binName);
assertEquals(3, index);
List<?> results = record.getList("otherbin");
String val = (String) results.get(1);
assertEquals("hellogoodbye", val);
}
Aggregations