@Override public CompletableFuture<ImmutableSet<? extends Batchable<?>>> onWrite(WriteQueryData queryData) { // this interceptor does not support where condition based queries if (!queryData.getWhereConditions().isEmpty()) { throw new InvalidQueryException("where condition based queries are not supported"); } if (queryData.hasKey(ACCOUNT_ID) && queryData.hasValueToMutate(KEY) && queryData.hasSetValuesToAddOrSet(EMAIL_IDX)) { List<Write> writes = Lists.newArrayList(); for (TupleValue tupleValue : queryData.getSetValuesToAddOrSet(EMAIL_IDX)) { writes.add(keyByEmailDao.writeWithKey(KeyByEmailColumns.EMAIL, tupleValue.getString(0), KeyByEmailColumns.CREATED, tupleValue.getLong(1)) .value(KeyByEmailColumns.KEY, queryData.getValueToMutate(KEY)) .value(KeyByEmailColumns.ACCOUNT_ID, queryData.getKey(ACCOUNT_ID)) .withConsistency(ConsistencyLevel.QUORUM)); } return CompletableFuture.completedFuture(ImmutableSet.copyOf(writes)); } else { return CompletableFuture.completedFuture(ImmutableSet.of()); } }
/** * Bind Tuple to BoundStatement. * * @param bs * @param inList * @throws Exception */ public void bindTuple(Session session, BoundStatement bs, List<Object> inList) throws Exception { if (!isCollection()) { throw new Exception( "attempting to bind non-collection as collection"); } LOG.trace("bindTuple: entered with {}", inList.toString()); LOG.trace("bindTuple: first object's type {}", inList.get(0).getClass() .getCanonicalName()); TupleType tupleType = Utils.getTupleType(session.getCluster() .getMetadata(), inList); TupleValue tv = tupleType.newValue(inList.toArray(new Object[inList .size()])); for (Integer pos : getPositions()) bs.setTupleValue(pos, tv); }
@Override public void set(SettableByIndexData target, TupleValue value) throws Exception { if (value == null) { target.setToNull(index); } else { target.setTupleValue(index, value); } }
@Override public TupleValue convert(I in) throws Exception { if (in == null) return null; TupleValue tv = tupleType.newValue(); mapper.mapTo(in, tv, null); return tv; }
private ImmutableSet<Deletion> getDeletions(Record record) { List<Deletion> deletions = Lists.newArrayList(); for (TupleValue tupleValue : record.getValue(KeyByAccountColumns.EMAIL_IDX)) { deletions.add(keyByEmailDao.deleteWithKey(KeyByEmailColumns.EMAIL, tupleValue.getString(0), KeyByEmailColumns.CREATED, tupleValue.getLong(1)) .withConsistency(ConsistencyLevel.QUORUM)); } return ImmutableSet.copyOf(deletions); }
public Class<TupleValue> getType() { return TupleValue.class; }
public TupleValue compose(Object obj) { return (TupleValue)obj; }
public Object decompose(TupleValue value) { return (Object) value; }
@Override public int getScale(TupleValue obj) { // TODO Auto-generated method stub return -1; }
@Override public int getPrecision(TupleValue obj) { // TODO Auto-generated method stub return -1; }
@Override public String toString(TupleValue obj) { // TODO Auto-generated method stub return obj.toString(); }
public TupleValue getTupleValue(int i) { return null; }
public TupleValue getTupleValue(String name) { return null; }
@Override public TupleValue getTupleValue(int i) { return row.getTupleValue(i); }
@Override public TupleValue getTupleValue(String name) { return row.getTupleValue(name); }
public static Class<?> asJavaClass(DataType.Name name) { if (name == null) return null; switch (name) { case ASCII: return String.class; case BIGINT: return Long.class; case BLOB: return ByteBuffer.class; case BOOLEAN: return Boolean.class; case COUNTER: return Long.class; case DECIMAL: return BigDecimal.class; case DOUBLE: return Double.class; case FLOAT: return Float.class; case INET: return InetAddress.class; case INT: return Integer.class; case LIST: return List.class; case MAP: return Map.class; case SET: return Set.class; case TEXT: return String.class; case TIMESTAMP: return Date.class; case TIMEUUID: return UUID.class; case UUID: return UUID.class; case VARCHAR: return String.class; case VARINT: return BigInteger.class; case UDT: return UDTValue.class; case TUPLE: return TupleValue.class; case CUSTOM: return ByteBuffer.class; } if (isDate(name)) return localDateClass; if (isTime(name)) return Long.class; if (isSmallInt(name)) return Short.class; if (isTinyInt(name)) return Byte.class; return null; }
@Override public TupleValue get(GettableByIndexData target) throws Exception { return target.getTupleValue(index); }
public ConverterToTupleValueMapper(Mapper<I, TupleValue> mapper, TupleType tupleType) { this.mapper = mapper; this.tupleType = tupleType; }
public TupleValue getT() { return t; }
public void setT(TupleValue t) { this.t = t; }
@Override public TupleValue getTupleValue(String name) { return record.getTupleValue(name); }
@Override public TupleValue getTupleValue(int i) { throw new UnsupportedOperationException(); }
@Override public TupleValue getTupleValue(String name) { throw new UnsupportedOperationException(); }
public static Object getObjectFromRow(Row row, String colName, DataType.Name type) { switch (type) { case BLOB: return row.getBytes(colName); case DECIMAL: return row.getDecimal(colName); case VARINT: return row.getVarint(colName); case BOOLEAN: return row.getBool(colName); case INET: return row.getInet(colName); case INT: return row.getInt(colName); case SMALLINT: return row.getShort(colName); case TINYINT: return row.getByte(colName); case BIGINT: case COUNTER: case TIME: return row.getLong(colName); case FLOAT: return row.getFloat(colName); case DOUBLE: return row.getDouble(colName); case DATE: return row.getDate(colName); case TIMESTAMP: return row.getTimestamp(colName); case TIMEUUID: case UUID: return row.getUUID(colName); case SET: return row.getSet(colName, String.class); case LIST: return row.getList(colName, String.class); case MAP: return row.getMap(colName, String.class, String.class); case TUPLE: // A tuple would have to be returned as a List of Objects List<Object> tupleObjs = new ArrayList<Object>(); TupleValue tv = row.getTupleValue(colName); // get a bead on the number of values in the tuple int numValues = tv.getType().getComponentTypes().size(); // copy corresponding objects to list for (int i = 0; i < numValues; i++) { tupleObjs.add(tv.getObject(i)); } return tupleObjs; default: return row.getString(colName); } }
/** * Return the {@code i}th value as a tuple value. * * This method uses the {@link CodecRegistry} to find a codec to convert the * underlying CQL type to a {@code TupleValue} (if the CQL type is a tuple, * the registry will generate a codec automatically). * * @param i * the index ({@code 0 <= i < size()}) to retrieve. * @return the value of the {@code i}th element as a tuple value. If the * value is NULL, then {@code null} will be returned. * @throws IndexOutOfBoundsException * if {@code i} is not a valid index for this object. * @throws CodecNotFoundException * if there is no registered codec to convert the element's CQL * type to a {@code TupleValue}. */ public TupleValue getTupleValue(int i);
/** * @param name the name to retrieve. * @return the value of {@code name} as a tuple value. If the value is NULL, null will be returned. */ TupleValue getTupleValue(String name);
/** * defines a new name with TupleValue-typed value * * @param name the name * @return a new instance */ public static ColumnName<TupleValue> defineTupleValue(String name) { return define(name, TupleValue.class); }