private Status write(String table, String key, WritePolicy writePolicy, Map<String, ByteIterator> values) { Bin[] bins = new Bin[values.size()]; int index = 0; for (Map.Entry<String, ByteIterator> entry: values.entrySet()) { bins[index] = new Bin(entry.getKey(), entry.getValue().toArray()); ++index; } Key keyObj = new Key(namespace, table, key); try { client.put(writePolicy, keyObj, bins); return Status.OK; } catch (AerospikeException e) { System.err.println("Error while writing key " + key + ": " + e); return Status.ERROR; } }
@Override public void storeCommittedWindowId(String appId, int operatorId, long windowId) { try { String keyString = appId + String.valueOf(operatorId); Key key = new Key(namespace,metaSet,keyString.hashCode()); Bin bin1 = new Bin(metaTableAppIdColumn,appId); Bin bin2 = new Bin(metaTableOperatorIdColumn,operatorId); Bin bin3 = new Bin(metaTableWindowColumn,windowId); client.put(null, key, bin1,bin2,bin3); } catch (AerospikeException e) { throw new RuntimeException(e); } }
/** * Create bin with a GeoJSON value. * * @param name bin name, current limit is 14 characters * @param value bin value */ public static Bin asGeoJSON(String name, String value) { return new Bin(name, Value.getAsGeoJSON(value)); }
/** * Create bin with a null value. This is useful for bin deletions within a record. * For servers configured as "single-bin", enter a null or empty name. * * @param name bin name, current limit is 14 characters */ public static Bin asNull(String name) { return new Bin(name, Value.getAsNull()); }
/** * Create bin with a null value. This is useful for bin deletions within a record. * For servers configured as "single-bin", enter a null or empty name. * * @param name bin name, current limit is 14 characters */ public static Bin asNull(String name) { return new Bin(name, Value.getAsNull()); }
/** * Create bin with a blob value. The value will be java serialized. * This method is faster than the bin Object constructor because the blob is converted * directly instead of using multiple "instanceof" type checks with a blob default. * <p> * For servers configured as "single-bin", enter a null or empty name. * * @param name bin name, current limit is 14 characters * @param value bin value */ public static Bin asBlob(String name, Object value) { return new Bin(name, Value.getAsBlob(value)); }
private Bin createBinForInteger(String binName, String binRawValue) { try { // Server stores all integer type data in 64bit so use long. Long integer = Long.parseLong(binRawValue); return new Bin(binName, integer); } catch (Exception pi) { log.error("File: " + Utils.getFileName(this.fileName) + " Line: " + lineNumber + " Integer/Long Parse Error: " + pi); return null; } }
/** * Create bin with a GeoJSON value. * * @param name bin name, current limit is 14 characters * @param value bin value */ public static Bin asGeoJSON(String name, String value) { return new Bin(name, Value.getAsGeoJSON(value)); }
/** * Create bin with a blob value. The value will be java serialized. * This method is faster than the bin Object constructor because the blob is converted * directly instead of using multiple "instanceof" type checks with a blob default. * <p> * For servers configured as "single-bin", enter a null or empty name. * * @param name bin name, current limit is 14 characters * @param value bin value */ public static Bin asBlob(String name, Object value) { return new Bin(name, Value.getAsBlob(value)); }
private Bin createBinForFloat(String binName, String binRawValue) { try { float binfloat = Float.parseFloat(binRawValue); // Now server support float return new Bin(binName, binfloat); } catch (Exception e) { log.error("File: " + Utils.getFileName(this.fileName) + " Line: " + lineNumber + " Floating number Parse Error: " + e); return null; } }
/** * An atomic operation that adds a value to an existing bin value. Bin value must be an integer type. * * @param fieldName Name of the bin or, if mapped Class was provided, name of the mapped field * @param value Value to add to the bin value. */ public SingleKeyCommander<T> add(String fieldName, long value) { String binName = mapper != null ? mapper.getBinName(fieldName) : fieldName; operations.add(Operation.add(new Bin(binName, value))); return this; }
/** * An atomic operation that appends a value to an existing bin value. Bin value must be a string type. * * @param fieldName Name of the bin or, if mapped Class was provided, name of the mapped field * @param value Value to append to the bin value. */ public SingleKeyCommander<T> append(String fieldName, String value) { String binName = mapper != null ? mapper.getBinName(fieldName) : fieldName; operations.add(Operation.append(new Bin(binName, value))); return this; }
/** * An atomic operation that prepends a value to an existing bin value. Bin value must be a string type. * * @param fieldName Name of the bin or, if mapped Class was provided, name of the mapped field * @param value Value to prepend to the bin value. */ public SingleKeyCommander<T> prepend(String fieldName, String value) { String binName = mapper != null ? mapper.getBinName(fieldName) : fieldName; operations.add(Operation.prepend(new Bin(binName, value))); return this; }
@Override protected Key getUpdatedBins(TestEvent tuple, List<Bin> bins) throws AerospikeException { Key key = new Key(NAMESPACE,SET_NAME,String.valueOf(tuple.id)); bins.add(new Bin("ID",tuple.id)); return key; } }
/** * Write records individually. */ private void writeRecords() { WriteHandler handler = new WriteHandler(size); for (int i = 1; i <= size; i++) { Key key = sendKeys[i-1]; Bin bin = new Bin(binName, valuePrefix + 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(eventLoop, handler, params.writePolicy, key, bin); } }
/** * Asynchronously write and read a bin using alternate methods. */ @Override public void runExample(AerospikeClient client, EventLoop eventLoop) { Key key = new Key(params.namespace, params.set, "putgetkey"); Bin bin = new Bin(params.getBinName("putgetbin"), "value"); runPutGetInline(client, eventLoop, key, bin); runPutGetWithRetry(client, eventLoop, key, bin); }
/** * Set a key value as string with an expiration (No expiration set on cache2k, it is already set * @param skey String. The key name. * @param value String. The value. * @throws Exception on aerorpike or cache errors. */ public void set(String set, String skey, Object value) throws Exception { WritePolicy policy = new WritePolicy(); Key key = new Key("test", set, skey); Bin bin1 = new Bin("value", value); ae.getClient().put(null, key, bin1); }
@Override public ValueWrapper putIfAbsent(Object key, Object value) { Record record = client.operate(this.createOnly, getKey(key), Operation.put(new Bin(VALUE, value)), Operation.get(VALUE)); return toWrapper(record); }
private void writeIfGenerationNotChanged(AerospikeClient client, Parameters params) throws Exception { Key key = new Key(params.namespace, params.set, "udfkey2"); Bin bin = new Bin(params.getBinName("udfbin2"), "string value"); // Seed record. client.put(params.writePolicy, key, bin); // Get record generation. long gen = (Long)client.execute(params.writePolicy, key, "record_example", "getGeneration"); // Write record if generation has not changed. client.execute(params.writePolicy, key, "record_example", "writeIfGenerationNotChanged", Value.get(bin.name), bin.value, Value.get(gen)); console.info("Record written."); }