/** * Adds the provided option. * * @param using an {@code INSERT} option. * @return this {@code Options} object. */ public Options and(Using using) { usings.add(using); checkForBindMarkers(using); return this; }
.value("key", getMapEntryPartitionKey(scope, key)) .value("column1", DataType.cboolean().serialize(true, ProtocolVersion.NEWEST_SUPPORTED)) .value("value", DataType.text().serialize(value, ProtocolVersion.NEWEST_SUPPORTED))); batchStatement.add(QueryBuilder.insertInto(MAP_KEYS_TABLE) .using(timeToLive) .value("key", getMapKeyPartitionKey(scope, bucket)) .value("column1", DataType.text().serialize(key, ProtocolVersion.NEWEST_SUPPORTED)) .value("value", DataType.cboolean().serialize(true, ProtocolVersion.NEWEST_SUPPORTED)));
.and(ttl(24)); assertEquals(insert.toString(), query); assertThat(insert.getKeyspace()).isEqualTo("baz"); // keyspace set since provided. }) .using(ttl(24)) .and(timestamp(42)); assertEquals(insert.toString(), query); }) .using(ttl(bindMarker())) .and(timestamp(bindMarker())); assertEquals(insert.toString(), query); insertInto("foo", "bar") .using(timestamp(42)) .values( new String[] {"a", "b"}, new Object[] { insertInto("foo") .using(timestamp(42)) .value("c", 123) .values( new String[] {"a", "b"},
.value(VALUE_COLUMN_NAME, bindMarker(VALUE_BINDING)) .using(timestamp(bindMarker(TIMESTAMP_BINDING))) .and(ttl(bindMarker(TTL_BINDING))));
}) .using(ttl(24)) .and(timestamp(42)); assertEquals(insert.toString(), query);
private static String insertQuery(TableMetadata tableMetadata, String... options) { Insert insert = QueryBuilder.insertInto(tableMetadata); if (options != null) { Insert.Options using = insert.using(); for (String option : options) { if ("TTL".equals(option)) { using.and(QueryBuilder.ttl(QueryBuilder.bindMarker())); } else { using.and(QueryBuilder.timestamp(QueryBuilder.bindMarker())); } } } List<ColumnMetadata> columns = tableMetadata.getColumns(); for(ColumnMetadata column : columns) { insert.value(column.getName(), QueryBuilder.bindMarker()); } return insert.toString(); }
private void insertSubscription(OwnedSubscription subscription) { Map<String, Object> json = new HashMap<String, Object>() {{ put("filter", subscription.getTableFilter().toString()); put("expiresAt", subscription.getExpiresAt().getTime()); put("eventTtl", subscription.getEventTtl().getSeconds()); put("ownerId", subscription.getOwnerId()); }}; _keyspace.getCqlSession().execute( insertInto(CF_NAME) .value(rowkeyColumn(), ROW_KEY) .value(subscriptionNameColumn(), subscription.getName()) .value(subscriptionColumn(), JsonHelper.asJson(json)) .using(ttl(Math.toIntExact(subscription.getEventTtl().getSeconds()))) .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM)); }
private void insertSubscription(OwnedSubscription subscription) { Map<String, Object> json = new HashMap<String, Object>() {{ put("filter", subscription.getTableFilter().toString()); put("expiresAt", subscription.getExpiresAt().getTime()); put("eventTtl", subscription.getEventTtl().getSeconds()); put("ownerId", subscription.getOwnerId()); }}; _keyspace.getCqlSession().execute( insertInto(CF_NAME) .value(rowkeyColumn(), ROW_KEY) .value(subscriptionNameColumn(), subscription.getName()) .value(subscriptionColumn(), JsonHelper.asJson(json)) .using(ttl(Math.toIntExact(subscription.getEventTtl().getSeconds()))) .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM)); }
@Override public void commit(List<History> historyList, Object rowKey) { if (historyList != null && !historyList.isEmpty()) { for (History history : historyList) { _batchStatement.add(QueryBuilder.insertInto(_tableDDL.getTableMetadata()) .value(_tableDDL.getRowKeyColumnName(), rowKey) .value(_tableDDL.getChangeIdColumnName(), history.getChangeId()) .value(_tableDDL.getValueColumnName(), _changeEncoder.encodeHistory(history)) .using(ttl(Ttls.toSeconds(_historyStore.getHistoryTtl(), 1, null))) .setConsistencyLevel(_consistencyLevel)); } } }
@Override public void commit(List<History> historyList, Object rowKey) { if (historyList != null && !historyList.isEmpty()) { for (History history : historyList) { _batchStatement.add(QueryBuilder.insertInto(_tableDDL.getTableMetadata()) .value(_tableDDL.getRowKeyColumnName(), rowKey) .value(_tableDDL.getChangeIdColumnName(), history.getChangeId()) .value(_tableDDL.getValueColumnName(), _changeEncoder.encodeHistory(history)) .using(ttl(Ttls.toSeconds(_historyStore.getHistoryTtl(), 1, null))) .setConsistencyLevel(_consistencyLevel)); } } }
@Override public void storeData(String sessionId, int pageId, byte[] data) { Insert insert = QueryBuilder .insertInto(settings.getKeyspaceName(), settings.getTableName()) .using(QueryBuilder.ttl((int) settings.getRecordTtl().minutes())) .values(new String[]{COLUMN_SESSION_ID, COLUMN_PAGE_ID, COLUMN_DATA}, new Object[]{sessionId, pageId, ByteBuffer.wrap(data)}); session.execute(insert); LOGGER.debug("Inserted data for session '{}' and page id '{}'", sessionId, pageId); }
/** * Adds a new options for this INSERT statement. * * @param using the option to add. * @return the options of this INSERT statement. */ public Options using(Using using) { return usings.and(using); }
/** * Adds the provided option. * * @param using an INSERT option. * @return this {@code Options} object. */ public Options and(Using using) { usings.add(using); checkForBindMarkers(using); return this; }
Insert(String keyspace, String table, List<Object> routingKeyValues, List<ColumnMetadata> partitionKey) { super(keyspace, partitionKey, routingKeyValues); this.table = table; this.usings = new Options(this); }
/** * Adds a new options for this INSERT statement. * * @param using the option to add. * @return the options of this INSERT statement. */ public Options using(Using using) { return usings.and(using); }
Insert(String keyspace, String table, List<Object> routingKeyValues, List<ColumnMetadata> partitionKey) { super(keyspace, partitionKey, routingKeyValues); this.table = table; this.usings = new Options(this); }
Insert(String keyspace, String table, List<Object> routingKeyValues, List<ColumnMetadata> partitionKey) { super(keyspace, partitionKey, routingKeyValues); this.table = table; this.usings = new Options(this); }
/** * Adds the provided option. * * @param using an INSERT option. * @return this {@code Options} object. */ public Options and(Using using) { usings.add(using); checkForBindMarkers(using); return this; }
@Override void modifyQueryString(BuiltStatement query) { ((Insert) query).using().and( QueryBuilder.ttl(QueryBuilder.bindMarker())); }
Insert(String keyspace, String table) { super(keyspace); this.table = table; this.usings = new Options(this); }