/** * Constructor, specifying bin name and string value. * 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 Bin(String name, String value) { this.name = name; this.value = Value.get(value); }
private Operation(Type type) { this.type = type; this.binName = null; this.value = Value.getAsNull(); } }
protected static Operation createOperation(int command, Operation.Type type, String binName, Value v1, Value v2, int v3) { Packer packer = new Packer(); packer.packRawShort(command); packer.packArrayBegin(3); v1.pack(packer); v2.pack(packer); packer.packInt(v3); return new Operation(type, binName, Value.get(packer.toByteArray())); }
case IN: // Conver IN to a collection of or as Aerospike has not support for IN query Value val = getValue1(); int valType = val.getType(); if(valType != ParticleType.LIST) throw new IllegalArgumentException("FilterOperation.IN expects List argument with type: " + ParticleType.LIST + ", but got: " + valType); List<?> inList = (List<?>) val.getObject(); for(Object value : inList) rs.addAll(new Qualifier(this.getField(), FilterOperation.EQ, Value.get(value)).toPredExp()); rs.add(PredExp.or(inList.size())); break; case EQ: val = getValue1(); valType = val.getType(); switch (valType) { case ParticleType.INTEGER: rs.add(getFieldExpr(valType)); rs.add(PredExp.integerValue(val.toLong())); rs.add(PredExp.integerEqual()); break; case NOTEQ: rs.addAll(Arrays.asList(valToPredExp(getValue1()))); rs.add(getValue1().getType()==ParticleType.INTEGER?PredExp.integerUnequal():PredExp.stringUnequal()); break; case GT:
public void checkKeyType(Key key) { try { userKeyFieldMapper.converter.fromProperty(key.userKey.getObject()); } catch (ClassCastException e) { throw new SpikeifyError("Mismatched key type: provided " + key.userKey.getObject().getClass().getName() + " key can not be mapped to " + userKeyFieldMapper.field.getType() + " (" + userKeyFieldMapper.field.getDeclaringClass().getName() + "." + userKeyFieldMapper.field.getName() + ")"); } }
protected static Operation createRangeOperation(int command, Operation.Type type, String binName, Value begin, Value end, int returnType) { Packer packer = new Packer(); packer.packRawShort(command); if (begin == null) { begin = Value.getAsNull(); } if (end == null) { packer.packArrayBegin(2); packer.packInt(returnType); begin.pack(packer); } else { packer.packArrayBegin(3); packer.packInt(returnType); begin.pack(packer); end.pack(packer); } return new Operation(type, binName, Value.get(packer.toByteArray())); } }
private static Value genValue(RandomShift random, DBObjectSpec spec, long keySeed) { switch (spec.type) { case 'I': if (keySeed == -1) { return Value.get(random.nextInt()); } else { return Value.get(keySeed); } case 'B': byte[] ba = new byte[spec.size]; random.nextBytes(ba); return Value.get(ba); case 'S': StringBuilder sb = new StringBuilder(spec.size); for (int i = 0; i < spec.size; i++) { // Append ascii value between ordinal 33 and 127. sb.append((char)(random.nextInt(94) + 33)); } return Value.get(sb.toString()); case 'D': return Value.get(System.currentTimeMillis()); default: return Value.getAsNull(); } } }
private Filter collectionContains(IndexCollectionType collectionType) { Value val = getValue1(); int valType = val.getType(); switch (valType) { case ParticleType.INTEGER: return Filter.contains(getField(), collectionType, val.toLong()); case ParticleType.STRING: return Filter.contains(getField(), collectionType, val.toString()); } return null; }
public Long convert(Bin source) { return source.value.toLong(); } }
@Override protected Object getGeoJSON(String value) { return Value.getAsGeoJSON(value); } }
protected String luaValueString(Value value) { String res = null; if(null == value) return res; int type = value.getType(); switch (type) { // case ParticleType.LIST: // res = value.toString(); // break; // case ParticleType.MAP: // res = value.toString(); // break; // case ParticleType.DOUBLE: // res = value.toString(); // break; case ParticleType.STRING: res = String.format("'%s'", value.toString()); break; case ParticleType.GEOJSON: res = String.format("'%s'", value.toString()); break; default: res = value.toString(); break; } return res; }
/** * 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())); }
public boolean validate(Record record) { if (bins == null) { if (record == null) { return true; } System.out.println("Mismatch: Expected null. Received not null."); return false; } if (record == null || record.bins == null) { System.out.println("Mismatch: Expected not null. Received null."); return false; } Map<String,Object> map = record.bins; int max = bins.length; for (int i = 0; i < max; i++) { Object expected = bins[i].value.getObject(); Object received = map.get(Integer.toString(i)); if (! expected.equals(received)) { System.out.println("Mismatch: Expected '" + expected + "' Received '" + received + "'"); return false; } } return true; } }
protected static Operation createRangeOperation(int command, Operation.Type type, String binName, Value begin, Value end, int returnType) { Packer packer = new Packer(); packer.packRawShort(command); if (begin == null) { begin = Value.getAsNull(); } if (end == null) { packer.packArrayBegin(2); packer.packInt(returnType); begin.pack(packer); } else { packer.packArrayBegin(3); packer.packInt(returnType); begin.pack(packer); end.pack(packer); } return new Operation(type, binName, Value.get(packer.toByteArray())); } }
l1.add(Value.get(new GregorianCalendar(2018, 1, 1).getTime())); l1.add(Value.get(1)); l2.add(Value.get(new GregorianCalendar(2018, 1, 2).getTime())); l2.add(Value.get(2)); l3.add(Value.get(new GregorianCalendar(2018, 2, 1).getTime())); l3.add(Value.get(3)); l4.add(Value.get(new GregorianCalendar(2018, 2, 2).getTime())); l4.add(Value.get(4)); l5.add(Value.get(new GregorianCalendar(2018, 2, 5).getTime())); l5.add(Value.get(5)); inputMap.put(Value.get("Charlie"), Value.get(l1)); inputMap.put(Value.get("Jim"), Value.get(l2)); inputMap.put(Value.get("John"), Value.get(l3)); inputMap.put(Value.get("Harry"), Value.get(l4)); inputMap.put(Value.get("Bill"), Value.get(l5)); end.add(Value.get(new GregorianCalendar(2018, 2, 2).getTime())); end.add(Value.getAsNull()); MapOperation.removeByValueRange(binName, null, Value.get(end), MapReturnType.COUNT) );
private PredExp[] valToPredExp(Value val) throws PredExpException { int valType = val.getType(); switch (valType) { case ParticleType.INTEGER: return new PredExp[]{ getFieldExpr(valType), PredExp.integerValue(val.toLong())}; case ParticleType.STRING: return new PredExp[]{ getFieldExpr(valType), PredExp.stringValue(val.toString())}; case ParticleType.GEOJSON: return new PredExp[]{ getFieldExpr(valType), PredExp.geoJSONValue(val.toString())}; default: throw new PredExpException("PredExp Unsupported Particle Type: " + val.getType()); } }
private K prepareKey(Key key){ switch (keyType) { case KEY: return (K) key; case LONG: return (K) (Long) key.userKey.toLong(); case STRING: return (K) key.userKey.toString(); default: throw new IllegalStateException("Error: unsupported key type. Must be one of: Key, Long or String"); // should not happen } } }