Refine search
/** * @return cql query statement to retrieve a workflow (without its tasks) from the "workflows" table */ public String getSelectWorkflowStatement() { return QueryBuilder.select(PAYLOAD_KEY) .from(keyspace, TABLE_WORKFLOWS) .where(eq(WORKFLOW_ID_KEY, bindMarker())) .and(eq(SHARD_ID_KEY, 1)) .and(eq(ENTITY_KEY, ENTITY_TYPE_WORKFLOW)) .getQueryString(); }
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"); 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 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; }
/** * @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<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)); }
@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 a task from the "workflows" table */ public String getSelectTaskStatement() { return QueryBuilder.select(PAYLOAD_KEY) .from(keyspace, TABLE_WORKFLOWS) .where(eq(WORKFLOW_ID_KEY, bindMarker())) .and(eq(SHARD_ID_KEY, bindMarker())) .and(eq(ENTITY_KEY, ENTITY_TYPE_TASK)) .and(eq(TASK_ID_KEY, bindMarker())) .getQueryString(); }
@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 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<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; }
/** * @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 CassandraEndpointUserConfiguration findByUserIdAndAppTokenAndSchemaVersion( String userId, String appToken, Integer schemaVersion ) { LOG.debug("Searching for user specific configuration by user id {}, " + "application token {} and schema version {}", userId, appToken, schemaVersion); Select.Where select = select().from(getColumnFamilyName()) .where(eq(EP_USER_CONF_USER_ID_PROPERTY, userId)) .and(eq(EP_USER_CONF_APP_TOKEN_PROPERTY, appToken)) .and(eq(EP_USER_CONF_VERSION_PROPERTY, schemaVersion)); CassandraEndpointUserConfiguration userConfiguration = findOneByStatement(select); if (LOG.isTraceEnabled()) { LOG.debug("[{},{},{}] Search result: {}.", userId, appToken, schemaVersion, userConfiguration); } else { LOG.debug("[{},{},{}] Search result: {}.", userId, appToken, schemaVersion, userConfiguration != null); } return userConfiguration; }
@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(); } }
@Override public CassandraEndpointNotification findById(String id) { LOG.debug("Try to find endpoint notifications by id {}", id); CassandraEndpointNotification key = new CassandraEndpointNotification(id); Select.Where where = select().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, key.getEndpointKeyHash())) .and(eq(ET_NF_LAST_MOD_TIME_PROPERTY, key.getLastModifyTime())); LOG.debug("[{}] Execute query {}:", id, where); CassandraEndpointNotification endpointNotification = findOneByStatement(where); LOG.trace("Found endpoint notification {} by id {}:", endpointNotification, id); return endpointNotification; }
@Override public List<SizeEstimate> getSizeEstimates(String keyspaceName, String tableName) { checkSizeEstimatesTableExist(); Statement statement = select("range_start", "range_end", "mean_partition_size", "partitions_count") .from(SYSTEM, SIZE_ESTIMATES) .where(eq("keyspace_name", keyspaceName)) .and(eq("table_name", tableName)); ResultSet result = executeWithSession(session -> session.execute(statement)); ImmutableList.Builder<SizeEstimate> estimates = ImmutableList.builder(); for (Row row : result.all()) { SizeEstimate estimate = new SizeEstimate( row.getString("range_start"), row.getString("range_end"), row.getLong("mean_partition_size"), row.getLong("partitions_count")); estimates.add(estimate); } return estimates.build(); }
@Override public List<CassandraEndpointNotification> findNotificationsByKeyHash(byte[] keyHash) { LOG.debug("Try to find endpoint notifications by endpoint key hash {}", Utils.encodeHexString(keyHash)); List<CassandraEndpointNotification> cassandraEndpointNotifications = Collections.emptyList(); if (keyHash != null) { Select.Where where = select().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, getByteBuffer(keyHash))); LOG.debug("Execute query {}:", where); cassandraEndpointNotifications = findListByStatement(where); } return cassandraEndpointNotifications; }
/** * @return cql query statement to retrieve a workflow with its tasks from the "workflows" table */ public String getSelectWorkflowWithTasksStatement() { return QueryBuilder.select() .all() .from(keyspace, TABLE_WORKFLOWS) .where(eq(WORKFLOW_ID_KEY, bindMarker())) .and(eq(SHARD_ID_KEY, bindMarker())) .getQueryString(); }