本文整理了Java中com.datastax.driver.core.querybuilder.Select.where()
方法的一些代码示例,展示了Select.where()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Select.where()
方法的具体详情如下:
包路径:com.datastax.driver.core.querybuilder.Select
类名称:Select
方法名:where
[英]Returns a Where statement for this query without adding clause.
[中]返回此查询的Where语句,但不添加子句。
代码示例来源:origin: kaaproject/kaa
@Override
public List<CassandraEndpointUserConfiguration> findByUserId(String userId) {
LOG.debug("Searching for user specific configurations by user id {}", userId);
Select.Where select = select().from(getColumnFamilyName())
.where(eq(EP_USER_CONF_USER_ID_PROPERTY, userId));
List<CassandraEndpointUserConfiguration> configurationList = findListByStatement(select);
if (LOG.isTraceEnabled()) {
LOG.trace("[{}] Search result: {}.",
userId, Arrays.toString(configurationList.toArray()));
} else {
LOG.debug("[{}] Search result: {}.",
userId, configurationList.size());
}
return configurationList;
}
代码示例来源:origin: apache/usergrid
private <T> T getValuesCQL(
final MapScope scope, final Collection<String> keys, final ResultsBuilderCQL<T> builder ) {
final List<ByteBuffer> serializedKeys = new ArrayList<>();
keys.forEach(key -> serializedKeys.add(getMapEntryPartitionKey(scope,key)));
Clause in = QueryBuilder.in("key", serializedKeys );
Statement statement = QueryBuilder.select().all().from(MAP_ENTRIES_TABLE)
.where(in);
ResultSet resultSet = session.execute(statement);
return builder.buildResultsCQL( resultSet );
}
代码示例来源:origin: kaaproject/kaa
@Override
public Optional<CassandraEndpointRegistration> findByCredentialsId(String credentialsId) {
LOG.debug("Searching for endpoint registration by credentials ID [{}]", credentialsId);
Clause clause = QueryBuilder.eq(
CassandraModelConstants.EP_REGISTRATION_CREDENTIALS_ID_PROPERTY, credentialsId);
Statement statement = QueryBuilder.select().from(this.getColumnFamilyName())
.where(clause);
return Optional.ofNullable(this.findOneByStatement(statement));
}
代码示例来源:origin: kaaproject/kaa
@Override
public List<CassandraEndpointProfile> findByEndpointUserId(String endpointUserId) {
LOG.debug("Try to find endpoint profiles by endpoint user id [{}]", endpointUserId);
List<CassandraEndpointProfile> profileList = Collections.emptyList();
CassandraEndpointUser endpointUser = endpointUserDao.findById(endpointUserId);
if (endpointUser != null) {
List<String> ids = endpointUser.getEndpointIds();
if (ids != null && !ids.isEmpty()) {
Statement select = select().from(getColumnFamilyName())
.where(in(EP_EP_KEY_HASH_PROPERTY, convertStringIds(ids)));
LOG.trace("Execute statements {}", select);
profileList = findListByStatement(select);
}
}
if (LOG.isTraceEnabled()) {
LOG.trace("Found endpoint profiles {}", Arrays.toString(profileList.toArray()));
}
return profileList;
}
代码示例来源:origin: kaaproject/kaa
@Override
public CassandraEndpointUser findByExternalIdAndTenantId(String externalId, String tenantId) {
LOG.debug("Try to find endpoint user by external id {} and tenant id {}",
externalId, tenantId);
Where where = select().from(getColumnFamilyName())
.where(eq(EP_USER_EXTERNAL_ID_PROPERTY, externalId))
.and(eq(EP_USER_TENANT_ID_PROPERTY, tenantId));
LOG.trace("Try to find endpoint user by cql select {}", where);
CassandraEndpointUser endpointUser = findOneByStatement(where);
LOG.trace("Found {} endpoint user", endpointUser);
return endpointUser;
}
代码示例来源:origin: apache/usergrid
@Override
public Iterator<UniqueValue> getAllUniqueFields( final ApplicationScope collectionScope, final Id entityId ) {
Preconditions.checkNotNull( collectionScope, "collectionScope is required" );
Preconditions.checkNotNull( entityId, "entity id is required" );
Clause inKey = QueryBuilder.in("key", getLogPartitionKey(collectionScope.getApplication(), entityId));
Statement statement = QueryBuilder.select().all().from(TABLE_UNIQUE_VALUES_LOG)
.where(inKey);
return new AllUniqueFieldsIterator(session, statement, entityId);
}
代码示例来源:origin: kaaproject/kaa
@Override
public boolean checkSdkToken(String sdkToken) {
LOG.debug("Checking for endpoint profiles with SDK token {}", sdkToken);
Statement query = select().from(EP_BY_SDK_TOKEN_COLUMN_FAMILY_NAME)
.where(eq(EP_BY_SDK_TOKEN_SDK_TOKEN_PROPERTY, sdkToken));
return execute(query).one() != null;
}
代码示例来源:origin: apache/usergrid
private ByteBuffer getValueCQL( MapScope scope, String key, final ConsistencyLevel consistencyLevel ) {
Clause in = QueryBuilder.in("key", getMapEntryPartitionKey(scope, key) );
Statement statement = QueryBuilder.select().all().from(MAP_ENTRIES_TABLE)
.where(in)
.setConsistencyLevel(consistencyLevel);
ResultSet resultSet = session.execute(statement);
com.datastax.driver.core.Row row = resultSet.one();
return row != null ? row.getBytes("value") : null;
}
代码示例来源:origin: Netflix/conductor
/**
* @return cql query statement to retrieve the workflow_id for a particular task_id from the "task_lookup" table
*/
public String getSelectTaskFromLookupTableStatement() {
return QueryBuilder.select(WORKFLOW_ID_KEY)
.from(keyspace, TABLE_TASK_LOOKUP)
.where(eq(TASK_ID_KEY, bindMarker()))
.getQueryString();
}
代码示例来源:origin: apache/usergrid
@Override
public MapKeyResults getAllKeys(final MapScope scope, final String cursor, final int limit ){
final int[] buckets = BUCKET_LOCATOR.getAllBuckets( scope.getName() );
final List<ByteBuffer> partitionKeys = new ArrayList<>(NUM_BUCKETS.length);
for (int bucket : buckets) {
partitionKeys.add(getMapKeyPartitionKey(scope, bucket));
}
Clause in = QueryBuilder.in("key", partitionKeys);
Statement statement;
if( isBlank(cursor) ){
statement = QueryBuilder.select().all().from(MAP_KEYS_TABLE)
.where(in)
.setFetchSize(limit);
}else{
statement = QueryBuilder.select().all().from(MAP_KEYS_TABLE)
.where(in)
.setFetchSize(limit)
.setPagingState(PagingState.fromString(cursor));
}
ResultSet resultSet = session.execute(statement);
PagingState pagingState = resultSet.getExecutionInfo().getPagingState();
final List<String> keys = new ArrayList<>();
Iterator<Row> resultIterator = resultSet.iterator();
int size = 0;
while( resultIterator.hasNext() && size < limit){
size++;
keys.add((String)DataType.text().deserialize(resultIterator.next().getBytes("column1"), ProtocolVersion.NEWEST_SUPPORTED));
}
return new MapKeyResults(pagingState != null ? pagingState.toString() : null, keys);
}
代码示例来源:origin: apache/usergrid
@Override
public List<UUID> getTokensForPrincipal(ByteBuffer principalKeyBuffer){
Preconditions.checkNotNull(principalKeyBuffer, "principal key bytebuffer cannot be null");
Clause inPrincipal = QueryBuilder.eq("key", principalKeyBuffer);
Statement statement = QueryBuilder
.select()
.column("column1")
.from(PRINCIPAL_TOKENS_TABLE)
.where(inPrincipal);
final List<Row> rows = session.execute(statement).all();
final List<UUID> tokenUUIDs = new ArrayList<>(rows.size());
rows.forEach(row -> tokenUUIDs.add(row.getUUID("column1")));
logger.trace("getTokensForPrincipal, token UUIDs: {}", tokenUUIDs);
return tokenUUIDs;
}
代码示例来源:origin: apache/usergrid
field.getTypeName().toString(), field.getName(), field.getValue()) );
final Statement statement = QueryBuilder.select().all().from(TABLE_UNIQUE_VALUES)
.where(inKey)
.setConsistencyLevel(consistencyLevel);
代码示例来源:origin: kaaproject/kaa
@Override
public Optional<CassandraCredentials> find(String applicationId, String credentialsId) {
LOG.debug("Searching credential by applicationID[{}] and credentialsID[{}]",
applicationId, credentialsId);
Select.Where query = select().from(getColumnFamilyName())
.where(eq(CREDENTIALS_APPLICATION_ID_PROPERTY, applicationId))
.and(eq(CREDENTIALS_ID_PROPERTY, credentialsId));
return Optional.ofNullable(this.findOneByStatement(query));
}
代码示例来源:origin: kaaproject/kaa
private T insertLocked(T entity) {
Insert insert = insertInto(getColumnFamilyName()).ifNotExists();
CassandraEntityMapper<T> entityMapper = CassandraEntityMapper.getEntityMapperForClass(
getColumnFamilyClass(), cassandraClient);
for (String name : entityMapper.getKeyColumnNames()) {
insert.value(name, entityMapper.getColumnValueForName(name, entity, cassandraClient));
}
for (String name : entityMapper.getNonKeyColumnNames()) {
insert.value(name, entityMapper.getColumnValueForName(name, entity, cassandraClient));
}
insert.setConsistencyLevel(getWriteConsistencyLevel());
ResultSet res = execute(insert);
if (!res.wasApplied()) {
LOG.error("[{}] Can't insert entity. Entity already exists!", getColumnFamilyClass());
throw new KaaOptimisticLockingFailureException("Can't insert entity. Entity already exists!");
} else {
Clause[] whereClauses = buildKeyClauses(entityMapper, entity);
Select.Where where = select().from(getColumnFamilyName()).where(whereClauses[0]);
if (whereClauses.length > 1) {
for (int i = 1; i < whereClauses.length; i++) {
where = where.and(whereClauses[i]);
}
}
return findOneByStatement(where);
}
}
代码示例来源:origin: kaaproject/kaa
@Override
public CassandraEndpointSpecificConfiguration findByEndpointKeyHashAndConfigurationVersion(byte[] endpointKeyHash, int configurationVersion) {
LOG.debug("Try to find endpoint specific configuration by endpointKeyHash {} and configurationVersion {}", endpointKeyHash, configurationVersion);
Select.Where where = select().from(getColumnFamilyName())
.where(eq(EPS_CONFIGURATION_KEY_HASH_PROPERTY, getByteBuffer(endpointKeyHash)))
.and(eq(EP_CONFIGURATION_VERSION_PROPERTY, configurationVersion));
LOG.trace("Try to find endpoint specific configuration by cql select {}", where);
CassandraEndpointSpecificConfiguration configuration = findOneByStatement(where);
LOG.trace("Found {} endpoint specific configuration", configuration);
return configuration;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
public void should_fail_if_in_clause_has_too_many_values() {
List<Object> values = Collections.<Object>nCopies(65536, "a");
select().all().from("foo").where(in("bar", values.toArray()));
}
代码示例来源:origin: Netflix/conductor
/**
* @return cql query statement to retrieve the total_tasks and total_partitions for a workflow from the "workflows" table
*/
public String getSelectTotalStatement() {
return QueryBuilder.select(TOTAL_TASKS_KEY, TOTAL_PARTITIONS_KEY)
.from(keyspace, TABLE_WORKFLOWS)
.where(eq(WORKFLOW_ID_KEY, bindMarker()))
.and(eq(SHARD_ID_KEY, 1))
.getQueryString();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(
groups = "unit",
expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = "Missing values for IN clause")
public void should_fail_if_in_clause_has_null_values() {
select().all().from("foo").where(in("bar", (List<?>) null));
}
代码示例来源:origin: kaaproject/kaa
@Override
public Optional<CassandraEndpointRegistration> findByEndpointId(String endpointId) {
LOG.debug("Searching for endpoint registration by endpoint ID [{}]", endpointId);
Optional<String> credentialsId = this.byEndpointId.getCredentialsIdByEndpointId(
endpointId);
if (credentialsId.isPresent()) {
LOG.debug("[{}] Endpoint credentials ID by endpoint ID: {}",
endpointId, credentialsId.get());
Clause clause = QueryBuilder.eq(
CassandraModelConstants.EP_REGISTRATION_CREDENTIALS_ID_PROPERTY,
credentialsId.get());
Statement statement = QueryBuilder.select().from(this.getColumnFamilyName())
.where(clause);
return Optional.ofNullable(this.findOneByStatement(statement));
} else {
LOG.debug("[{}] No credentials ID found by endpoint ID: {}", endpointId);
return Optional.empty();
}
}
代码示例来源:origin: hugegraph/hugegraph
public long getCounter(CassandraSessionPool.Session session,
HugeType type) {
Clause where = formatEQ(HugeKeys.SCHEMA_TYPE, type.name());
Select select = QueryBuilder.select(formatKey(HugeKeys.ID))
.from(TABLE);
select.where(where);
Row row = session.execute(select).one();
if (row == null) {
return 0L;
} else {
return row.getLong(formatKey(HugeKeys.ID));
}
}
内容来源于网络,如有侵权,请联系作者删除!