/** * Get bin value as list. */ public List<?> getList(String name) { return (List<?>)getValue(name); }
public void onRecord(Key key, Record record) throws AerospikeException { int result = record.getInt(binName); console.info("Record found: ns=%s set=%s bin=%s digest=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result); count.incrementAndGet(); }
/** * Convert key and record to string. */ @Override public String toString() { StringBuilder sb = new StringBuilder(1024); if (key != null) { sb.append(key.toString()); } sb.append(':'); if (record != null) { sb.append(record.toString()); } return sb.toString(); } }
@SuppressWarnings("unchecked") @Override public KeyRecord next() { KeyRecord keyRecord = null; if (this.recordSetIterator != null) { keyRecord = this.recordSetIterator.next(); } else if (this.resultSetIterator != null) { Map<String, Object> map = (Map<String, Object>) this.resultSetIterator.next(); Map<String, Object> meta = (Map<String, Object>) map.get(META_DATA); map.remove(META_DATA); Map<String, Object> binMap = new HashMap<String, Object>(map); if (log.isDebugEnabled()) { for (Map.Entry<String, Object> entry : map.entrySet()) { log.debug(entry.getKey() + " = " + entry.getValue()); } } Long generation = (Long) meta.get(GENERATION); Long ttl = (Long) meta.get(EXPIRY); Record record = new Record(binMap, generation.intValue(), ttl.intValue()); Key key = new Key(namespace, (byte[]) meta.get(DIGEST), (String) meta.get(SET_NAME), null); keyRecord = new KeyRecord(key, record); } else if (singleRecord != null) { keyRecord = singleRecord; singleRecord = null; } return keyRecord; }
/** * Demonstrate multiple operations on a single record in one call. */ @Override public void runExample(AerospikeClient client, Parameters params) throws Exception { // Write initial record. Key key = new Key(params.namespace, params.set, "opkey"); Bin bin1 = new Bin("optintbin", 7); Bin bin2 = new Bin("optstringbin", "string value"); console.info("Put: namespace=%s set=%s key=%s bin1=%s value1=%s bin2=%s value2=%s", key.namespace, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value); client.put(params.writePolicy, key, bin1, bin2); // Add integer, write new string and read record. Bin bin3 = new Bin(bin1.name, 4); Bin bin4 = new Bin(bin2.name, "new string"); console.info("Add: " + bin3.value); console.info("Write: " + bin4.value); console.info("Read:"); Record record = client.operate(params.writePolicy, key, Operation.add(bin3), Operation.put(bin4), Operation.get()); if (record == null) { throw new Exception(String.format( "Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey)); } validateBin(key, record, bin3.name, 11, record.getInt(bin3.name)); validateBin(key, record, bin4.name, bin4.value.toString(), record.getValue(bin4.name)); }
/** * Get bin value as float. */ public float getFloat(String name) { return (float)getDouble(name); }
Key key = rs.getKey(); Record record = rs.getRecord(); String result = record.getGeoJSON(binName);
@Override public Record get(Policy policy, Key key) throws AerospikeException { policy = (policy == null) ? readPolicyDefault : policy; String nsName = key.namespace == null ? defaultNamespace : key.namespace; String setName = key.setName == null ? defaultNamespace : key.setName; Map<String, Map<Key, Rec>> namespace = getNamespace(nsName); Map<Key, Rec> set = getSet(setName, namespace); Rec existingRec = set.get(key); if (existingRec == null) { return null; } return new Record(existingRec.getBins(), existingRec.generation, existingRec.expires); }
/** * Get bin value as float. */ public float getFloat(String name) { return (float)getDouble(name); }
Key key = rs.getKey(); Record record = rs.getRecord(); String result = record.getGeoJSON(binName);
/** * Get bin value as map. */ public Map<?,?> getMap(String name) { return (Map<?,?>)getValue(name); }
protected final Record parseRecord() { Map<String,Object> bins = null; for (int i = 0 ; i < opCount; i++) { int opSize = Buffer.bytesToInt(dataBuffer, dataOffset); byte particleType = dataBuffer[dataOffset+5]; byte nameSize = dataBuffer[dataOffset+7]; String name = Buffer.utf8ToString(dataBuffer, dataOffset+8, nameSize); dataOffset += 4 + 4 + nameSize; int particleBytesSize = (int) (opSize - (4 + nameSize)); Object value = Buffer.bytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize); dataOffset += particleBytesSize; if (bins == null) { bins = new HashMap<String,Object>(); } bins.put(name, value); } return new Record(bins, generation, expiration); }
/** * Convert key and record to string. */ @Override public String toString() { StringBuilder sb = new StringBuilder(1024); if (key != null) { sb.append(key.toString()); } sb.append(':'); if (record != null) { sb.append(record.toString()); } return sb.toString(); } }
/** * Get bin value as String. */ public String getString(String name) { return (String)getValue(name); }
protected final Record parseRecord() { Map<String,Object> bins = null; for (int i = 0 ; i < opCount; i++) { int opSize = Buffer.bytesToInt(dataBuffer, dataOffset); byte particleType = dataBuffer[dataOffset+5]; byte nameSize = dataBuffer[dataOffset+7]; String name = Buffer.utf8ToString(dataBuffer, dataOffset+8, nameSize); dataOffset += 4 + 4 + nameSize; int particleBytesSize = (int) (opSize - (4 + nameSize)); Object value = Buffer.bytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize); dataOffset += particleBytesSize; if (bins == null) { bins = new HashMap<String,Object>(); } bins.put(name, value); } return new Record(bins, generation, expiration); }
@Override public TestEvent getTuple(Record record) { return new TestEvent(record.getInt("ID")); }
while (rs.next()) { Record record = rs.getRecord(); console.info("Record: " + record.toString());
/** * Get bin value as map. */ public Map<?,?> getMap(String name) { return (Map<?,?>)getValue(name); }
/** * Parses the given byte buffer and populate the result object. * Returns the number of bytes that were parsed from the given buffer. */ protected final Record parseRecord() throws AerospikeException, IOException { Map<String,Object> bins = null; for (int i = 0 ; i < opCount; i++) { readBytes(8); int opSize = Buffer.bytesToInt(dataBuffer, 0); byte particleType = dataBuffer[5]; byte nameSize = dataBuffer[7]; readBytes(nameSize); String name = Buffer.utf8ToString(dataBuffer, 0, nameSize); int particleBytesSize = opSize - (4 + nameSize); readBytes(particleBytesSize); Object value = Buffer.bytesToParticle(particleType, dataBuffer, 0, particleBytesSize); if (bins == null) { bins = new HashMap<String,Object>(); } bins.put(name, value); } return new Record(bins, generation, expiration); }