@Test public void testGetValue() throws Exception { withSession(session -> { Select.Selection selection = select().column("id"); columns.stream().map(col -> "test_" + col.getLeft().getName()).forEach(selection::column); Select.Where select = selection.from("test_table").where(eq("id", 123)); ResultSet result = session.execute(select); List<Object> objects = CqlUtils.toList(result.one()); for (int i = 0; i < columns.size(); ++i) { ImmutablePair<DataType, Object> column = columns.get(i); assertEquals("Column test_" + column.getLeft().getName() + " did not match.", column.getRight(), objects.get(i + 1)); } }); }
public static Object getValue(GettableByIndexData gettable, int columnIndex, DataType dataType) { if(gettable.isNull(columnIndex)) { return null; } switch (dataType.getName()) { case ASCII: case VARCHAR: case TEXT: return gettable.getString(columnIndex); case BIGINT: return gettable.getLong(columnIndex); case BOOLEAN: return gettable.getBool(columnIndex); case DECIMAL: return gettable.getDecimal(columnIndex); case DOUBLE: return gettable.getDouble(columnIndex); case FLOAT: return gettable.getFloat(columnIndex); case INT: return gettable.getInt(columnIndex); case TIMESTAMP: return gettable.getDate(columnIndex); case UUID: case TIMEUUID: return gettable.getUUID(columnIndex); case LIST: return gettable.getList(columnIndex, typeArgument(dataType, 0)); case SET: return gettable.getSet(columnIndex, typeArgument(dataType, 0)); case MAP: return gettable.getMap(columnIndex, typeArgument(dataType, 0), typeArgument(dataType, 1)); case BLOB: return gettable.getBytes(columnIndex); case INET: return gettable.getInet(columnIndex); case VARINT: return gettable.getVarint(columnIndex); case TUPLE: return gettable.getTupleValue(columnIndex); default: throw new HecateException(String.format("Unsupported data type %s.", dataType.getName())); } }
CqlUtils { public static Object getValue(GettableByIndexData gettable, int columnIndex, DataType dataType) { if(gettable.isNull(columnIndex)) { return null; } switch (dataType.getName()) { case ASCII: case VARCHAR: case TEXT: return gettable.getString(columnIndex); case BIGINT: return gettable.getLong(columnIndex); case BOOLEAN: return gettable.getBool(columnIndex); case DECIMAL: return gettable.getDecimal(columnIndex); case DOUBLE: return gettable.getDouble(columnIndex); case FLOAT: return gettable.getFloat(columnIndex); case INT: return gettable.getInt(columnIndex); case TIMESTAMP: return gettable.getDate(columnIndex); case UUID: case TIMEUUID: return gettable.getUUID(columnIndex); case LIST: return gettable.getList(columnIndex, typeArgument(dataType, 0)); case SET: return gettable.getSet(columnIndex, typeArgument(dataType, 0)); case MAP: return gettable.getMap(columnIndex, typeArgument(dataType, 0), typeArgument(dataType, 1)); case BLOB: return gettable.getBytes(columnIndex); case INET: return gettable.getInet(columnIndex); case VARINT: return gettable.getVarint(columnIndex); case TUPLE: return gettable.getTupleValue(columnIndex); default: throw new HecateException(String.format("Unsupported data type %s.", dataType.getName())); } } }
CqlUtils { public static Object getValue(GettableByIndexData gettable, int columnIndex, DataType dataType) { if(gettable.isNull(columnIndex)) { return null; } switch (dataType.getName()) { case ASCII: case VARCHAR: case TEXT: return gettable.getString(columnIndex); case BIGINT: return gettable.getLong(columnIndex); case BOOLEAN: return gettable.getBool(columnIndex); case DECIMAL: return gettable.getDecimal(columnIndex); case DOUBLE: return gettable.getDouble(columnIndex); case FLOAT: return gettable.getFloat(columnIndex); case INT: return gettable.getInt(columnIndex); case TIMESTAMP: return gettable.getDate(columnIndex); case UUID: case TIMEUUID: return gettable.getUUID(columnIndex); case LIST: return gettable.getList(columnIndex, typeArgument(dataType, 0)); case SET: return gettable.getSet(columnIndex, typeArgument(dataType, 0)); case MAP: return gettable.getMap(columnIndex, typeArgument(dataType, 0), typeArgument(dataType, 1)); case BLOB: return gettable.getBytes(columnIndex); case INET: return gettable.getInet(columnIndex); case VARINT: return gettable.getVarint(columnIndex); case TUPLE: return gettable.getTupleValue(columnIndex); default: throw new HecateException(String.format("Unsupported data type %s.", dataType.getName())); } } private  CqlUtils(); }
CqlUtils { public static Object getValue(GettableByIndexData gettable, int columnIndex, DataType dataType) { if(gettable.isNull(columnIndex)) { return null; } switch (dataType.getName()) { case ASCII: case VARCHAR: case TEXT: return gettable.getString(columnIndex); case BIGINT: return gettable.getLong(columnIndex); case BOOLEAN: return gettable.getBool(columnIndex); case DECIMAL: return gettable.getDecimal(columnIndex); case DOUBLE: return gettable.getDouble(columnIndex); case FLOAT: return gettable.getFloat(columnIndex); case INT: return gettable.getInt(columnIndex); case TIMESTAMP: return gettable.getDate(columnIndex); case UUID: case TIMEUUID: return gettable.getUUID(columnIndex); case LIST: return gettable.getList(columnIndex, typeArgument(dataType, 0)); case SET: return gettable.getSet(columnIndex, typeArgument(dataType, 0)); case MAP: return gettable.getMap(columnIndex, typeArgument(dataType, 0), typeArgument(dataType, 1)); case BLOB: return gettable.getBytes(columnIndex); case INET: return gettable.getInet(columnIndex); case VARINT: return gettable.getVarint(columnIndex); case TUPLE: return gettable.getTupleValue(columnIndex); default: throw new HecateException(String.format("Unsupported data type %s.", dataType.getName())); } } private  CqlUtils(); static BoundStatement bind(PreparedStatement statement, Object[] params); static Object getValue(GettableByIndexData gettable, int columnIndex, DataType dataType); static List<Object> toList(TupleValue tuple); static List<Object> toList(Row row); }
CqlUtils { public static Object getValue(GettableByIndexData gettable, int columnIndex, DataType dataType) { if(gettable.isNull(columnIndex)) { return null; } switch (dataType.getName()) { case ASCII: case VARCHAR: case TEXT: return gettable.getString(columnIndex); case BIGINT: return gettable.getLong(columnIndex); case BOOLEAN: return gettable.getBool(columnIndex); case DECIMAL: return gettable.getDecimal(columnIndex); case DOUBLE: return gettable.getDouble(columnIndex); case FLOAT: return gettable.getFloat(columnIndex); case INT: return gettable.getInt(columnIndex); case TIMESTAMP: return gettable.getDate(columnIndex); case UUID: case TIMEUUID: return gettable.getUUID(columnIndex); case LIST: return gettable.getList(columnIndex, typeArgument(dataType, 0)); case SET: return gettable.getSet(columnIndex, typeArgument(dataType, 0)); case MAP: return gettable.getMap(columnIndex, typeArgument(dataType, 0), typeArgument(dataType, 1)); case BLOB: return gettable.getBytes(columnIndex); case INET: return gettable.getInet(columnIndex); case VARINT: return gettable.getVarint(columnIndex); case TUPLE: return gettable.getTupleValue(columnIndex); default: throw new HecateException(String.format("Unsupported data type %s.", dataType.getName())); } } private  CqlUtils(); static BoundStatement bind(PreparedStatement statement, Object[] params); static Object getValue(GettableByIndexData gettable, int columnIndex, DataType dataType); static List<Object> toList(TupleValue tuple); static List<Object> toList(Row row); static final Logger CQL_LOGGER; }