@Override public String generateAccessToken(String externalId, String tenantId) { LOG.debug("Generating access token for endpoint user with external id {} and tenant id {}", externalId, tenantId); String accessToken = UUID.randomUUID().toString(); Update.Where query = update(getColumnFamilyName()) .with(set(CassandraModelConstants.EP_USER_ACCESS_TOKEN_PROPERTY, accessToken)) .where(eq(EP_USER_EXTERNAL_ID_PROPERTY, externalId)) .and(eq(EP_USER_TENANT_ID_PROPERTY, tenantId)); execute(query); LOG.trace("Generated access token {} for endpoint user by query {}", accessToken, query); return accessToken; }
.with(set("schema_id", String.valueOf(schemaId + idShift))) .where(eq("topic_id", ids[0])) .and(eq("nf_type", ids[1])) .and(eq("nf_version", Integer.valueOf(ids[2]))) .and(eq("seq_num", Integer.valueOf(ids[3]))) ); .with(set("schema_id", String.valueOf(schemaId + idShift))) .where(eq("ep_key_hash", epKeyHash)) .and(eq("last_mod_time", lastModTime)) );
/** * Generate a SELECT ... FROM ... WHERE ... <strong>clust = ?</strong> */ @SuppressWarnings("static-access") public final EntityWithNoKeyspaceUDT_Update.E Eq(NoKeyspaceUDT clust) { where.and(QueryBuilder.eq("clust", QueryBuilder.bindMarker("clust"))); boundValues.add(clust); encodedValues.add(meta.clust.encodeFromJava(clust, Optional.of(cassandraOptions))); return new EntityWithNoKeyspaceUDT_Update.E(where, cassandraOptions); }
update = update("foo").where().and(eq("k", 2)).with(set("b", null)); assertEquals(update.toString(), query); .and(remove("c", "a")) .where(eq("k", 2)) .and(eq("l", "foo")) .and(lt("m", 4)) .and(gte("n", 1)); assertEquals(update.toString(), query); update("foo") .where() .and(eq("k", 2)) .and(eq("l", "foo")) .with(prependAll("b", Arrays.asList(3, 2, 1))) .using(timestamp(42)); update("foo") .where() .and(eq("k", 2)) .and(eq("l", "foo")) .using(timestamp(42)) .with(prependAll("b", Arrays.asList(3, 2, 1))); .using(timestamp(42)) .where(eq("k", 2)) .and(eq("l", "foo")) .with(prependAll("b", Arrays.asList(3, 2, 1))); assertEquals(update.toString(), query);
@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); }
/** * Adds a WHERE clause to this statement. * * <p>This is a shorter/more readable version for {@code where().and(clause)}. * * @param clause the clause to add. * @return the where clause of this query to which more clause can be added. */ public Where where(Clause clause) { return where.and(clause); }
if (whereClauses.length > 1) { for (int i = 1; i < whereClauses.length; i++) { query = query.and(whereClauses[i]);
.and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString() ) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) ) .with( QueryBuilder.incr( COLUMN_COUNTER_VALUE, -1 * value ) ); // incr must be positive cassandraClient.getQueueMessageSession().execute( update ); .and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString() ) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) ) .with( QueryBuilder.decr( COLUMN_COUNTER_VALUE, value ) ); cassandraClient.getQueueMessageSession().execute( update );
@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 ); } }
@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); }
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 ); }
public void updateShardPointer(final Shard shard){ Assignment assignment = QueryBuilder.set(COLUMN_POINTER, shard.getPointer()); Clause queueNameClause = QueryBuilder.eq(COLUMN_QUEUE_NAME, shard.getQueueName()); Clause regionClause = QueryBuilder.eq(COLUMN_REGION, shard.getRegion()); Clause activeClause = QueryBuilder.eq(COLUMN_ACTIVE, 1); Clause shardIdClause = QueryBuilder.eq(COLUMN_SHARD_ID, shard.getShardId()); Statement update = QueryBuilder.update(getTableName(shard.getType())) .with(assignment) .where(queueNameClause) .and(regionClause) .and(activeClause) .and(shardIdClause); 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 ); }
/** * @return cql query statement to update the total_partitions for a workflow in the "workflows" table */ public String getUpdateTotalPartitionsStatement() { return QueryBuilder.update(keyspace, TABLE_WORKFLOWS) .with(set(TOTAL_PARTITIONS_KEY, bindMarker())) .and(set(TOTAL_TASKS_KEY, bindMarker())) .where(eq(WORKFLOW_ID_KEY, bindMarker())) .and(eq(SHARD_ID_KEY, 1)) .getQueryString(); }
/** * @return cql query statement to update the total_tasks in a shard for a workflow in the "workflows" table */ public String getUpdateTotalTasksStatement() { return QueryBuilder.update(keyspace, TABLE_WORKFLOWS) .with(set(TOTAL_TASKS_KEY, bindMarker())) .where(eq(WORKFLOW_ID_KEY, bindMarker())) .and(eq(SHARD_ID_KEY, bindMarker())) .getQueryString(); }
/** * @return cql query statement to update a workflow in the "workflows" table */ public String getUpdateWorkflowStatement() { return QueryBuilder.update(keyspace, TABLE_WORKFLOWS) .with(set(PAYLOAD_KEY, bindMarker())) .where(eq(WORKFLOW_ID_KEY, bindMarker())) .and(eq(SHARD_ID_KEY, 1)) .and(eq(ENTITY_KEY, ENTITY_TYPE_WORKFLOW)) .and(eq(TASK_ID_KEY, "")) .getQueryString(); }