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; }
@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 List<CassandraNotification> findNotificationsByTopicId(String topicId) { LOG.debug("Try to find notifications by topic id {}", topicId); Where query = select().from(getColumnFamilyName()).where(eq(NF_TOPIC_ID_PROPERTY, topicId)) .and(QueryBuilder.in( NF_NOTIFICATION_TYPE_PROPERTY, getStringTypes(NotificationTypeDto.values()))); LOG.trace("Execute query {}", query); List<CassandraNotification> notifications = findListByStatement(query); if (LOG.isTraceEnabled()) { LOG.trace("Found notifications {}", Arrays.toString(notifications.toArray())); } return notifications; }
@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 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 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; }
/** * @deprecated This method needs additional testing and thus isn't recommended to use as of October, 2015. */ public ByteBuffer[] getEpIdsBySdkToken(String sdkToken) { LOG.debug("Trying to find a list of enpoint key hash values by SDK token {}", sdkToken); Statement query = QueryBuilder .select() .from(this.getColumnFamilyName()) .where(QueryBuilder.eq(EP_BY_SDK_TOKEN_SDK_TOKEN_PROPERTY, sdkToken)); List<CassandraEpBySdkToken> queryResult = this.findListByStatement(query); ByteBuffer[] result = new ByteBuffer[queryResult.size()]; int pos = 0; for (CassandraEpBySdkToken endpointProfile : queryResult) { result[pos++] = endpointProfile.getEndpointKeyHash(); } LOG.debug("Endpoint profile hash values found: {}", Arrays.toString(result)); return result; } }
@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; }
@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; }
private Long retrieveCounterFromStorage( String queueName, DatabaseQueueMessage.Type type ) { Statement query = QueryBuilder.select().from( TABLE_MESSAGE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_MESSAGE_TYPE, type.toString()) ); ResultSet resultSet = cassandraClient.getQueueMessageSession().execute( query ); List<Row> all = resultSet.all(); if ( all.size() > 1 ) { throw new QakkaRuntimeException( "Multiple rows for counter " + queueName + " type " + type ); } if ( all.isEmpty() ) { return null; } return all.get(0).getLong( COLUMN_COUNTER_VALUE ); }
@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 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; }
/** * Get endpoints ids from specific application. * @param appId is application's id * @return endpoints ids */ public ByteBuffer[] getEpIdsListByAppId(String appId) { LOG.debug("Try to find endpoint key hash list by application id {}", appId); List<CassandraEpByAppId> filter = findListByStatement(select() .from(getColumnFamilyName()) .where(eq(EP_BY_APP_ID_APPLICATION_ID_PROPERTY, appId))); ByteBuffer[] result = new ByteBuffer[filter.size()]; int pos = 0; for (CassandraEpByAppId ep : filter) { result[pos++] = ep.getEndpointKeyHash(); } return result; }
/** * Found credential's id by endpoint id. * @param endpointId is endpoint id * @return string id or empty <code>Optional</code> if not found */ public Optional<String> getCredentialsIdByEndpointId(String endpointId) { Clause clause = QueryBuilder.eq( CassandraModelConstants.EP_REGISTRATION_BY_ENDPOINT_ID_ENDPOINT_ID_PROPERTY, endpointId); Statement statement = QueryBuilder.select().from(this.getColumnFamilyName()).where(clause); CassandraEpRegistrationByEndpointId result = this.findOneByStatement(statement); if (result != null) { return Optional.of(result.getCredentialsId()); } else { return Optional.empty(); } } }
@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 DatabaseQueueMessageBody loadMessageData(final UUID messageId ){ logger.trace("loadMessageData {}", messageId); Clause messageIdClause = QueryBuilder.eq( COLUMN_MESSAGE_ID, messageId ); Statement select = QueryBuilder.select().from( TABLE_MESSAGE_DATA).where(messageIdClause); Row row = cassandraClient.getApplicationSession().execute(select).one(); if ( row == null ) { return null; } return new DatabaseQueueMessageBody( row.getBytes( COLUMN_MESSAGE_DATA), row.getString( COLUMN_CONTENT_TYPE)); }
Long retrieveCounterFromStorage( String queueName, Shard.Type type, long shardId ) { Statement query = QueryBuilder.select().from( TABLE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString()) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) ); ResultSet resultSet = cassandraClient.getQueueMessageSession().execute( query ); List<Row> all = resultSet.all(); if ( all.size() > 1 ) { throw new QakkaRuntimeException( "Multiple rows for counter " + queueName + " type " + type + " shardId " + shardId ); } if ( all.isEmpty() ) { return null; } return all.get(0).getLong( COLUMN_COUNTER_VALUE ); }
@Override public List<CassandraNotification> findNotificationsByTopicIdAndVersionAndStartSecNum( String topicId, int seqNum, int sysNfVersion, int userNfVersion) { LOG.debug("Try to find notifications by topic id {} start sequence number {} " + "system schema version {} user schema version {}", topicId, seqNum, sysNfVersion, userNfVersion); List<CassandraNotification> resultList = new ArrayList<>(); Where systemQuery = select().from(getColumnFamilyName()) .where(eq(NF_TOPIC_ID_PROPERTY, topicId)) .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, NotificationTypeDto.SYSTEM.name())) .and(eq(NF_VERSION_PROPERTY, sysNfVersion)) .and(QueryBuilder.gt(NF_SEQ_NUM_PROPERTY, seqNum)); Where userQuery = select().from(getColumnFamilyName()) .where(eq(NF_TOPIC_ID_PROPERTY, topicId)) .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, NotificationTypeDto.USER.name())) .and(eq(NF_VERSION_PROPERTY, userNfVersion)) .and(QueryBuilder.gt(NF_SEQ_NUM_PROPERTY, seqNum)); List<CassandraNotification> systemList = findListByStatement(systemQuery); List<CassandraNotification> userList = findListByStatement(userQuery); resultList.addAll(systemList); resultList.addAll(userList); if (LOG.isTraceEnabled()) { LOG.trace("Found notifications {} by topic id {}, seqNum {}, sysVer {}, userVer {} ", Arrays.toString( resultList.toArray()), topicId, seqNum, sysNfVersion, userNfVersion); } return resultList; }
Statement queryStatement; if ("0".equals(pageLink.getOffset())) { queryStatement = select().from(getColumnFamilyName()) .where(eq(EP_BY_APP_ID_APPLICATION_ID_PROPERTY, appId)) .limit(Integer.valueOf(limit) + 1); appId, limit); } else { queryStatement = select().from(getColumnFamilyName()) .where(eq(EP_BY_APP_ID_APPLICATION_ID_PROPERTY, appId)) .and(gte(EP_BY_APP_ID_ENDPOINT_KEY_HASH_PROPERTY, endpointKey))