updateStmt.where(QueryBuilder.eq(YCSB_KEY, QueryBuilder.bindMarker()));
private void decrementCounterInStorage( String queueName, DatabaseQueueMessage.Type type, long decrement ) { Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_MESSAGE_TYPE, type.toString() ) ) .with( QueryBuilder.decr( COLUMN_COUNTER_VALUE, decrement ) ); cassandraClient.getQueueMessageSession().execute( update ); }
private void incrementCounterInStorage( String queueName, DatabaseQueueMessage.Type type, long increment ) { Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_MESSAGE_TYPE, type.toString() ) ) .with( QueryBuilder.incr( COLUMN_COUNTER_VALUE, increment ) ); cassandraClient.getQueueMessageSession().execute( update ); }
void incrementCounterInStorage( String queueName, Shard.Type type, long shardId, long increment ) { Statement update = QueryBuilder.update( TABLE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString() ) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) ) .with( QueryBuilder.incr( COLUMN_COUNTER_VALUE, increment ) ); cassandraClient.getQueueMessageSession().execute( update ); }
@Override public Optional<CassandraCredentials> updateStatus(String applicationId, String credentialsId, CredentialsStatus status) { LOG.debug("Updating credentials status with applicationID[{}] " + "and credentialsID[{}] to STATUS[{}]", applicationId, credentialsId, status.toString()); Update.Assignments query = update(getColumnFamilyName()) .where(eq(CREDENTIALS_ID_PROPERTY, credentialsId)) .and(eq(CREDENTIALS_APPLICATION_ID_PROPERTY, applicationId)) .with(set(CREDENTIALS_STATUS_PROPERTY, status.toString())); execute(query); return find(applicationId, credentialsId); }
@Override public void resetCounter(String queueName, DatabaseQueueMessage.Type type) { // this sucks: "You cannot index, delete, or re-add a counter column" // https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_counter_t.html // so instead we decrement or increment the counter to zero // get value first, before resetting in memory counter long value = getCounterValue( queueName, type ); String key = buildKey( queueName, type ); InMemoryCount inMemoryCount = inMemoryCounters.get( key ); if ( inMemoryCount != null ) { inMemoryCount.reset(); } if ( value < 0 ) { Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_MESSAGE_TYPE, type.toString() ) ) .with( QueryBuilder.incr( COLUMN_COUNTER_VALUE, -1 * value ) ); // incr must be positive cassandraClient.getQueueMessageSession().execute( update ); } else { Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_MESSAGE_TYPE, type.toString() ) ) .with( QueryBuilder.decr( COLUMN_COUNTER_VALUE, value ) ); cassandraClient.getQueueMessageSession().execute( update ); } }
/** * Adds a where clause to the UPDATE statement these options are part of. * * @param clause clause to add. * @return the WHERE clause of the UPDATE statement these options are part of. */ public Where where(Clause clause) { return statement.where(clause); }
/** * Adds a where clause to the UPDATE statement these conditions are part of. * * @param clause clause to add. * @return the WHERE clause of the UPDATE statement these conditions are part of. */ public Where where(Clause clause) { return statement.where(clause); }
/** * Adds a where clause to the UPDATE statement those assignments are part of. * * @param clause the clause to add. * @return the where clause of the UPDATE statement those assignments are part of. */ public Where where(Clause clause) { return statement.where(clause); }
.where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString() ) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString() ) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) )
@Override public void insert(CassandraSessionPool.Session session, CassandraBackendEntry.Row entry) { Map<HugeKeys, Object> columns = entry.columns(); assert columns.containsKey(HugeKeys.ID); Object id = columns.get(HugeKeys.ID); Object label = columns.get(HugeKeys.LABEL); E.checkState(label != null, "The label of inserting vertex can't be null"); Map<?, ?> properties = (Map<?, ?>) columns.get(HugeKeys.PROPERTIES); E.checkState(properties != null, "The properties of inserting vertex can't be null"); Update update = QueryBuilder.update(table()); update.with(QueryBuilder.set(formatKey(HugeKeys.LABEL), label)); update.with(QueryBuilder.putAll(formatKey(HugeKeys.PROPERTIES), properties)); update.where(formatEQ(HugeKeys.ID, id)); session.add(update); } }
Update update = QueryBuilder.update(columnFamilyName); update.with(QueryBuilder.incr("value", entry.getCount())); update.where(QueryBuilder.eq("metricname", metricName)) .and(QueryBuilder.eq("groupid", entry.getGroupId())) .and(QueryBuilder.eq("metrictime", update.where(QueryBuilder.eq(entryInTag.getKey(), entryInTag.getValue()));
public void increaseCounter(CassandraSessionPool.Session session, HugeType type, long increment) { Update update = QueryBuilder.update(TABLE); update.with(QueryBuilder.incr(formatKey(HugeKeys.ID), increment)); update.where(formatEQ(HugeKeys.SCHEMA_TYPE, type.name())); session.execute(update); } }
public void insert(CassandraSessionPool.Session session, CassandraBackendEntry.Row entry) { Update update = QueryBuilder.update(this.table); update.with(QueryBuilder.add(ELEMENT_IDS, entry.id().asLong())); update.where(CassandraTable.formatEQ(HugeKeys.NAME, entry.column(HugeKeys.NAME))); session.add(update); }
/** * Append several elements to the collection column of a row */ @Override public void append(CassandraSessionPool.Session session, CassandraBackendEntry.Row entry) { List<HugeKeys> idNames = this.idColumnName(); List<HugeKeys> colNames = this.modifiableColumnName(); Map<HugeKeys, Object> columns = entry.columns(); Update update = QueryBuilder.update(table()); for (HugeKeys key : colNames) { if (!columns.containsKey(key)) { continue; } String name = formatKey(key); Object value = columns.get(key); if (value instanceof Map) { update.with(QueryBuilder.putAll(name, (Map<?, ?>) value)); } else if (value instanceof List) { update.with(QueryBuilder.appendAll(name, (List<?>) value)); } else { update.with(QueryBuilder.append(name, value)); } } for (HugeKeys idName : idNames) { assert columns.containsKey(idName); update.where(formatEQ(idName, columns.get(idName))); } session.add(update); }
/** * Remove data from label index table */ private static void removeLabelIndex(CassandraSessionPool.Session session, String table, CassandraBackendEntry.Row entry) { Update update = QueryBuilder.update(table); Object label = entry.column(HugeKeys.LABEL); if (label == null) { // Maybe delete edges by edge label(passed by id) assert entry.id().asString().indexOf(':') < 0 : entry; return; } update.with(QueryBuilder.remove(ELEMENT_IDS, IdUtil.writeString(entry.id()))); update.where(CassandraTable.formatEQ(HugeKeys.LABEL, label)); session.add(update); }
update.where(formatEQ(idName, columns.get(idName)));
/** * Append data to label index table */ private static void appendLabelIndex(CassandraSessionPool.Session session, String table, CassandraBackendEntry.Row entry) { Update update = QueryBuilder.update(table); update.with(QueryBuilder.append(ELEMENT_IDS, IdUtil.writeString(entry.id()))); update.where(CassandraTable.formatEQ(HugeKeys.LABEL, entry.column(HugeKeys.LABEL))); session.add(update); }
public void delete(CassandraSessionPool.Session session, CassandraBackendEntry.Row entry, String mainTable) { // Get name from main table by id Select select = QueryBuilder.select().from(mainTable); select.where(CassandraTable.formatEQ(HugeKeys.ID, entry.id().asLong())); ResultSet resultSet = session.execute(select); List<Row> rows = resultSet.all(); if (rows.size() == 0) { return; } String name = rows.get(0).getString(HugeKeys.NAME.string()); Update update = QueryBuilder.update(this.table); update.with(QueryBuilder.remove(ELEMENT_IDS, entry.id().asLong())); update.where(CassandraTable.formatEQ(HugeKeys.NAME, name)); session.add(update); }
@Test(groups = "unit") public void updateInjectionTest() throws Exception { String query; Statement update; query = "UPDATE foo.bar USING TIMESTAMP 42 SET a=12 WHERE k='2 OR 1=1';"; update = update("foo", "bar").using(timestamp(42)).with(set("a", 12)).where(eq("k", "2 OR 1=1")); assertEquals(update.toString(), query); query = "UPDATE foo SET b='null WHERE k=1; --comment' WHERE k=2;"; update = update("foo").where().and(eq("k", 2)).with(set("b", "null WHERE k=1; --comment")); assertEquals(update.toString(), query); query = "UPDATE foo USING TIMESTAMP 42 SET \"b WHERE k=1; --comment\"=[3,2,1]+\"b WHERE k=1; --comment\" WHERE k=2;"; update = update("foo") .where() .and(eq("k", 2)) .with(prependAll("b WHERE k=1; --comment", Arrays.asList(3, 2, 1))) .using(timestamp(42)); assertEquals(update.toString(), query); }