@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; }
update("notification") .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]))) update("ep_nfs") .with(set("schema_id", String.valueOf(schemaId + idShift))) .where(eq("ep_key_hash", epKeyHash)) .and(eq("last_mod_time", lastModTime)) );
@Override public CassandraEndpointProfile updateServerProfile(byte[] keyHash, int version, String serverProfile) { LOG.debug("Updating server profile for endpoint profile with key hash [{}] " + "with schema version [{}]", Utils.encodeHexString(keyHash), version); ByteBuffer key = ByteBuffer.wrap(keyHash); Statement update = QueryBuilder.update(EP_COLUMN_FAMILY_NAME) .with(set(EP_SERVER_PROFILE_PROPERTY, serverProfile)) .and(set(EP_SERVER_PROFILE_VERSION_PROPERTY, version)) .where(eq(EP_EP_KEY_HASH_PROPERTY, key)); execute(update, ConsistencyLevel.ALL); return findById(key); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_not_allow_bind_marker_for_discard() { update("foo").with(discard("l", bindMarker())).where(eq("k", 1)); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_not_allow_bind_marker_for_append() { update("foo").with(append("l", bindMarker())).where(eq("k", 1)); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_now_allow_bind_marker_for_prepend() { update("foo").with(prepend("l", bindMarker())).where(eq("k", 1)); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_not_allow_bind_marker_for_add() { // This generates the query "UPDATE foo SET s = s + {?} WHERE k = 1", which is invalid in // Cassandra update("foo").with(add("s", bindMarker())).where(eq("k", 1)); }
@Test(groups = "unit", expectedExceptions = CodecNotFoundException.class) public void rejectUnknownValueTest() throws Exception { RegularStatement s = update("foo").with(set("a", new byte[13])).where(eq("k", 2)).setForceNoValues(true); s.getQueryString(); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_not_allow_bind_marker_for_remove() { update("foo").with(remove("s", bindMarker())).where(eq("k", 1)); }
@Test(groups = "unit") public void statementForwardingTest() throws Exception { Update upd = update("foo"); upd.setConsistencyLevel(ConsistencyLevel.QUORUM); upd.enableTracing(); Statement query = upd.using(timestamp(42)).with(set("a", 12)).and(incr("c", 3)).where(eq("k", 2)); assertEquals(query.getConsistencyLevel(), ConsistencyLevel.QUORUM); assertTrue(query.isTracing()); }
private ImmutableList<BuiltStatement> idempotentBuiltStatements() { return ImmutableList.<BuiltStatement>of( update("foo").with(set("v", 1)).where(eq("k", 1)), // set simple value update("foo").with(add("s", 1)).where(eq("k", 1)), // add to set update("foo").with(put("m", "a", 1)).where(eq("k", 1)), // put in map // select statements should be idempotent even with function calls select().countAll().from("foo").where(eq("k", 1)), select().ttl("v").from("foo").where(eq("k", 1)), select().writeTime("v").from("foo").where(eq("k", 1)), select().fcall("token", "k").from("foo").where(eq("k", 1))); }
@SuppressWarnings("deprecation") @Test(groups = "short") public void should_handle_collections_of_tuples() { String query; BuiltStatement statement; query = "UPDATE foo SET l=[(1,2)] WHERE k=1;"; TupleType tupleType = cluster().getMetadata().newTupleType(cint(), cint()); List<TupleValue> list = ImmutableList.of(tupleType.newValue(1, 2)); statement = update("foo").with(set("l", list)).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); } }
update(tableName) .with(set("body", bodyEncoded)) .where(eq("user_id", userId)) .and(eq("app_token", appToken)) .and(eq("schema_version", schemaVersion))
Update.Where query = assigns.where(whereClauses[0]); if (whereClauses.length > 1) { for (int i = 1; i < whereClauses.length; i++) {
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); }
/** * @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(); }
/** * @return cql query statement to add a new task_id to workflow_id mapping to the "task_lookup" table */ public String getUpdateTaskLookupStatement() { return QueryBuilder.update(keyspace, TABLE_TASK_LOOKUP) .with(set(WORKFLOW_ID_KEY, bindMarker())) .where(eq(TASK_ID_KEY, bindMarker())) .getQueryString(); }
/** * @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(); }