@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)); }
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 ); }
@Override public List<String> getListOfQueues() { logger.trace( "getListOfQueues " ); Statement select = QueryBuilder.select().all().from( TABLE_QUEUES ); ResultSet rs = cassandraClient.getApplicationSession().execute( select ); return rs.all().stream() .map( row -> row.getString( COLUMN_QUEUE_NAME )) .collect( Collectors.toList() ); }
ResultSet results = session.execute(select().from("notification")); for (Row row : results) { String id = row.getString("nf_id"); 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]))) .and(eq("seq_num", Integer.valueOf(ids[3]))) ); results = session.execute(select().from("ep_nfs")); for (Row row : results) { String id = row.getString("nf_id");
@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; }
@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; }
@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; }
@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); }
/** * @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(); }
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; }
/** * Get all entities from cassandra database. * @return <code>List</code> of entities */ public List<T> find() { LOG.debug("Get all entities from column family {}", getColumnFamilyName()); return findListByStatement( QueryBuilder.select() .all().from(getColumnFamilyName()) .setConsistencyLevel(getReadConsistencyLevel())); }
@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); }
@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)); }