DataType secondParamType = getPrimitiveDataTypeFromString(secondParamTypeName); DataType mapType = DataType.map(firstParamType, secondParamType); statement.setMap(paramIndex, (Map) codecRegistry.codecFor(mapType).parse(paramValue)); return;
public void addRowKey(String metricName, DataPointsRowKey rowKey, int rowKeyTtl) { m_newRowKeys.add(rowKey); ByteBuffer bb = ByteBuffer.allocate(8); bb.putLong(0, rowKey.getTimestamp()); Statement bs = m_clusterConnection.psRowKeyTimeInsert.bind() .setString(0, metricName) .setTimestamp(1, new Date(rowKey.getTimestamp())) //.setBytesUnsafe(1, bb) //Setting timestamp in a more optimal way .setInt(2, rowKeyTtl) .setIdempotent(true); bs.setConsistencyLevel(m_consistencyLevel); rowKeyBatch.add(bs); bs = m_clusterConnection.psRowKeyInsert.bind() .setString(0, metricName) .setTimestamp(1, new Date(rowKey.getTimestamp())) //.setBytesUnsafe(1, bb) //Setting timestamp in a more optimal way .setString(2, rowKey.getDataType()) .setMap(3, rowKey.getTags()) .setInt(4, rowKeyTtl) .setIdempotent(true); bs.setConsistencyLevel(m_consistencyLevel); rowKeyBatch.add(bs); }
statement.setTimestamp(1, new Date(rowKey.getTimestamp())); statement.setString(2, rowKey.getDataType()); statement.setMap(3, rowKey.getTags()); statement.setConsistencyLevel(cluster.getReadConsistencyLevel()); cluster.execute(statement);
BoundStatement bs = stmt.bind(); Map<Integer, String> map1 =... bs.setMap(0, map1); // 0 is the zere-based index of your bindmarker
@Override public <K, V> QueryBinder<ENTITY> setMap(int i, Map<K, V> v) { for (BoundStatement statement : statements.values()) { statement.setMap(i, v); } return this; }
@Test(groups = "short") public void should_use_collection_codecs_with_prepared_statements_2() { session() .execute( session() .prepare(insertQuery) .bind() .setInt(0, n_int) .setList(1, l_int) .setList(2, l_bigint, Long.class) // variant with element type explicitly set .setSet(3, s_float) .setSet( 4, s_double, TypeToken.of(Double.class)) // variant with element type explicitly set .setMap(5, m_varint) .setMap( 6, m_decimal, Integer.class, BigDecimal.class) // variant with element type explicitly set ); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, n_int)); Row row = rows.one(); assertRow(row); }
session() .execute( ins.bind().setList(0, null).setSet(1, null).setMap(2, null).setTupleValue(3, null));
setValue(byName, "v", mapping.outerType, mapping.value); byName.setList("l", list, mapping.javaType); byName.setMap("m", map, mapping.javaType, mapping.javaType); if (is21) { byName.setTupleValue("t", tupleValue); setValue(byIndex, 1, mapping.outerType, mapping.value); byIndex.setList(2, list, mapping.javaType); byIndex.setMap(3, map, mapping.javaType, mapping.javaType); if (is21) { byIndex.setTupleValue(4, tupleValue);
@Override public <K, V> QueryBinder<ENTITY> setMap(String name, Map<K, V> v) { for (BoundStatement statement : statements.values()) { if (statement.preparedStatement().getVariables().contains(name)) { statement.setMap(name, v); } } return this; }
/** * Sets the value for (all occurrences of) variable {@code name} to the * provided map. * <p> * Please note that {@code null} values are not supported inside collection by CQL. * * @param <K> the type of the keys for the map to set. * @param <V> the type of the values for the map to set. * @param name the name of the variable to set; if multiple variables * {@code name} are prepared, all of them are set. * @param v the value to set. * @return this BoundStatement. * * @throws IllegalArgumentException if {@code name} is not a prepared * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. * @throws InvalidTypeException if (any occurrence of) {@code name} is * not a map type or if the elements (keys or values) of {@code v} are not of * the type of the elements of column {@code name}. * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections * by CQL. */ public <K, V> BoundStatement setMap(String name, Map<K, V> v) { int[] indexes = metadata().getAllIdx(name); for (int i = 0; i < indexes.length; i++) setMap(indexes[i], v); return this; }
@Override public UserSettings remove(HawkularUser user, String key) { UserSettings settings = getByUser(user); if (null == settings) { return null; } settings.remove(key); update(settings, stmtUpdateInstance.get().setMap("properties", settings.getProperties())); logger.removedSetting(user.getId(), key); return settings; }
@Override public UserSettings store(HawkularUser user, String key, String value) { UserSettings settings = getOrCreateByUser(user); settings.put(key, value); update(settings, stmtUpdateInstance.get().setMap("properties", settings.getProperties())); logger.storedSetting(user.getId(), key, value); return settings; }
public void setString(int parameterIndex, String value) throws SQLException { checkNotClosed(); checkIndex(parameterIndex); try{ this.statement.setString(parameterIndex-1, value); }catch(CodecNotFoundException e){ // Big ugly hack in order to parse string representations of collections // Yes, I'm ashamed... if(e.getMessage().contains("set<")){ String itemType = e.getMessage().substring(e.getMessage().indexOf("<")+1, e.getMessage().indexOf(">")); this.statement.setSet(parameterIndex-1, Utils.parseSet(itemType, value)); }else if(e.getMessage().contains("list<")){ String itemType = e.getMessage().substring(e.getMessage().indexOf("<")+1, e.getMessage().indexOf(">")); this.statement.setList(parameterIndex-1, Utils.parseList(itemType, value)); }else if(e.getMessage().contains("map<")){ String[] kvTypes = e.getMessage().substring(e.getMessage().indexOf("<")+1, e.getMessage().indexOf(">")).replace(" ", "").split(","); this.statement.setMap(parameterIndex-1, Utils.parseMap(kvTypes[0],kvTypes[1], value)); } } }
private String updateSimple(String key) { Map<String, UDTValue> billing_addresses = new HashMap<>(); HashSet<String> phones = new HashSet<>(); for (int i = 0; i < this.dataGenerator.getRandomInteger()%6+1; i++) { phones.add(RandomStringUtils.randomAlphanumeric(10)); } UDTValue address = cassAddressType.newValue(); address.setString("street", RandomStringUtils.randomAlphanumeric(30)); address.setString("city", RandomStringUtils.randomAlphanumeric(20)); address.setInt("zip_code", this.dataGenerator.getRandomInteger()); address.setSet("phones", phones); billing_addresses.put(RandomStringUtils.randomAlphanumeric(8),address); HashSet<UDTValue> emails = new HashSet<>(); for (int i = 0; i < this.dataGenerator.getRandomInteger()%5+1; i++) { UDTValue email = cassEmailType.newValue(); email.setString("fp",RandomStringUtils.randomAlphanumeric(15)); email.setString("domain",RandomStringUtils.randomAlphanumeric(10)); emails.add(email); } BoundStatement bStmt = updatePstmt1.bind(); bStmt.setMap("billing_addresses", billing_addresses); bStmt.setSet("emails", emails); bStmt.setString("id", key); bStmt.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel())); ResultSet rs = session.execute(bStmt); if (rs !=null) return ResultOK; return ResutlFailed; }
private String updateSimple(String key) { Map<String, UDTValue> billing_addresses = new HashMap<>(); HashSet<String> phones = new HashSet<>(); for (int i = 0; i < this.dataGenerator.getRandomInteger()%6+1; i++) { phones.add(RandomStringUtils.randomAlphanumeric(10)); } UDTValue address = cassAddressType.newValue(); address.setString("street", RandomStringUtils.randomAlphanumeric(30)); address.setString("city", RandomStringUtils.randomAlphanumeric(20)); address.setInt("zip_code", this.dataGenerator.getRandomInteger()); address.setSet("phones", phones); billing_addresses.put(RandomStringUtils.randomAlphanumeric(8),address); HashSet<UDTValue> emails = new HashSet<>(); for (int i = 0; i < this.dataGenerator.getRandomInteger()%5+1; i++) { UDTValue email = cassEmailType.newValue(); email.setString("fp",RandomStringUtils.randomAlphanumeric(15)); email.setString("domain",RandomStringUtils.randomAlphanumeric(10)); emails.add(email); } BoundStatement bStmt = updatePstmt1.bind(); bStmt.setMap("billing_addresses", billing_addresses); bStmt.setSet("emails", emails); bStmt.setString("id", key); bStmt.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel())); ResultSet rs = session.execute(bStmt); if (rs !=null) return ResultOK; return ResutlFailed; }
bs.setMap(1, dataPoint.getTags()); i++;
bs.setMap(1, dataPoint.getTags()); i++;
@Test(groups = "short") public void should_use_collection_codecs_with_prepared_statements_2() { session() .execute( session() .prepare(insertQuery) .bind() .setInt(0, n_int) .setList(1, l_int) .setList(2, l_bigint, Long.class) // variant with element type explicitly set .setSet(3, s_float) .setSet( 4, s_double, TypeToken.of(Double.class)) // variant with element type explicitly set .setMap(5, m_varint) .setMap( 6, m_decimal, Integer.class, BigDecimal.class) // variant with element type explicitly set ); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, n_int)); Row row = rows.one(); assertRow(row); }
session() .execute( ins.bind().setList(0, null).setSet(1, null).setMap(2, null).setTupleValue(3, null));
if (null != input.r_ep()) bound.set("r_ep", input.r_ep(), EndpointUDT.class); if (!input.annotations().isEmpty()) bound.setList("annotations", input.annotations()); if (!input.tags().isEmpty()) bound.setMap("tags", input.tags()); if (input.shared()) bound.setBool("shared", true); if (input.debug()) bound.setBool("debug", true);