本文整理了Java中com.datastax.driver.core.querybuilder.QueryBuilder.set
方法的一些代码示例,展示了QueryBuilder.set
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryBuilder.set
方法的具体详情如下:
包路径:com.datastax.driver.core.querybuilder.QueryBuilder
类名称:QueryBuilder
方法名:set
[英]Advanced "set" assignment of a value to a column or a com.datastax.driver.core.UserType field.
This method is seldom preferable to #set(String,Object); it is only useful:
set(path("udt", "field"), value)
set(raw("some custom string"), value)
If the runtime type of name is String, this method is equivalent to #set(String,Object).
[中]向列或com高级“设置”赋值。税收。驾驶员果心用户类型字段。
这种方法很少优于#set(字符串、对象);它只是有用的:
*将值分配给UDT的各个字段时(请参见#路径(字符串…):
set(path("udt", "field"), value)
*如果希望传递一个“raw”字符串,该字符串将按原样追加到查询中(请参见#raw(string))。在撰写本文时,这种方法没有实际用途,但如果在Cassandra中添加了新功能,而您使用的是尚未意识到这些功能的较旧驱动程序版本,它将作为一种变通方法:
set(raw("some custom string"), value)
如果名称的运行时类型为String,则此方法相当于#set(String,Object)。
代码示例来源:origin: kaaproject/kaa
@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;
}
代码示例来源:origin: kaaproject/kaa
@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);
}
代码示例来源:origin: Netflix/conductor
/**
* @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();
}
代码示例来源:origin: brianfrankcooper/YCSB
updateStmt.with(QueryBuilder.set(field, QueryBuilder.bindMarker()));
代码示例来源:origin: Netflix/conductor
/**
* @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();
}
代码示例来源:origin: kaaproject/kaa
@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);
}
代码示例来源:origin: apache/usergrid
QueryBuilder.set("value", DataType.serializeValue(accessedTime, ProtocolVersion.NEWEST_SUPPORTED));
final Assignment setInactiveTime =
QueryBuilder.set("value", DataType.serializeValue(inactiveTime, ProtocolVersion.NEWEST_SUPPORTED));
代码示例来源:origin: kaaproject/kaa
.with(set("schema_id", String.valueOf(schemaId + idShift)))
.where(eq("topic_id", ids[0]))
.and(eq("nf_type", ids[1]))
.with(set("schema_id", String.valueOf(schemaId + idShift)))
.where(eq("ep_key_hash", epKeyHash))
.and(eq("last_mod_time", lastModTime))
代码示例来源:origin: Netflix/conductor
/**
* @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();
}
代码示例来源:origin: Netflix/conductor
/**
* @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();
}
代码示例来源:origin: apache/usergrid
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);
}
代码示例来源:origin: kaaproject/kaa
.with(set("body", bodyEncoded))
.where(eq("user_id", userId))
.and(eq("app_token", appToken))
代码示例来源:origin: kaaproject/kaa
Assignments assigns = update(getColumnFamilyName())
.onlyIf(eq(OPT_LOCK, version))
.with(set(OPT_LOCK, version + 1));
CassandraEntityMapper<T> entityMapper = CassandraEntityMapper.getEntityMapperForClass(
getColumnFamilyClass(), cassandraClient);
for (String name : entityMapper.getNonKeyColumnNames()) {
if (!name.equals(OPT_LOCK)) {
Assignment assignment = set(
name, entityMapper.getColumnValueForName(name, entity, cassandraClient));
assigns = assigns.and(assignment);
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* @test_category queries:builder
* @jira_ticket JAVA-1286
* @jira_ticket CASSANDRA-7423
*/
@Test(groups = "unit")
public void should_handle_setting_udt_fields() throws Exception {
assertThat(
update("tbl")
.with(set(path("a", quote("B")), "foo"))
.and(set(raw("c.\"D\""), "bar"))
.where(eq("k", 0))
.getQueryString())
.isEqualTo("UPDATE tbl SET a.\"B\"=?,c.\"D\"=? WHERE k=0;");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@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);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@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();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@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());
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "unit")
public void should_handle_from_json() throws Exception {
assertThat(
update("users")
.with(set("age", fromJson("42")))
.where(eq("id", fromJson("\"user123\"")))
.toString())
.isEqualTo("UPDATE users SET age=fromJson('42') WHERE id=fromJson('\"user123\"');");
assertThat(
insertInto("users")
.value("id", fromJson("\"user123\""))
.value("age", fromJson("42"))
.toString())
.isEqualTo("INSERT INTO users (id,age) VALUES (fromJson('\"user123\"'),fromJson('42'));");
assertThat(insertInto("users").value("id", fromJson(bindMarker())).toString())
.isEqualTo("INSERT INTO users (id) VALUES (fromJson(?));");
assertThat(insertInto("users").value("id", fromJson(bindMarker("id"))).toString())
.isEqualTo("INSERT INTO users (id) VALUES (fromJson(:id));");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(
groups = "unit",
expectedExceptions = {IllegalArgumentException.class})
public void batchMixedCounterTest() throws Exception {
batch()
.add(update("foo").with(incr("a", 1)))
.add(update("foo").with(set("b", 2)))
.add(update("foo").with(incr("c", 3)))
.using(timestamp(42));
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
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)));
}
内容来源于网络,如有侵权,请联系作者删除!