Refine search
@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; }
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 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)); }
@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); }
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; }
/** * @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(); }
@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 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; }
@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)); }
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); } }
@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; }
/** * @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(); }
@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(); } }
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)); } }