Java Code Examples for com.datastax.driver.core.querybuilder.QueryBuilder#eq()
The following examples show how to use
com.datastax.driver.core.querybuilder.QueryBuilder#eq() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueueMessageSerializationImpl.java From usergrid with Apache License 2.0 | 6 votes |
private Statement createDeleteAllMessagesStatement( Shard shard ) { Clause queueNameClause = QueryBuilder.eq( COLUMN_QUEUE_NAME, shard.getQueueName() ); Clause regionClause = QueryBuilder.eq( COLUMN_REGION, shard.getRegion() ); Clause shardIdClause = QueryBuilder.eq( COLUMN_SHARD_ID, shard.getShardId() ); DatabaseQueueMessage.Type dbqmType = Shard.Type.DEFAULT.equals( shard.getType() ) ? DatabaseQueueMessage.Type.DEFAULT : DatabaseQueueMessage.Type.INFLIGHT; Statement deleteAll = QueryBuilder.delete().from( getTableName( dbqmType )) .where(queueNameClause) .and(regionClause) .and(shardIdClause); return deleteAll; }
Example 2
Source File: QueueMessageSerializationImpl.java From usergrid with Apache License 2.0 | 6 votes |
@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)); }
Example 3
Source File: ShardSerializationImpl.java From usergrid with Apache License 2.0 | 6 votes |
public void updateShardPointer(final Shard shard){ Assignment assignment = QueryBuilder.set(COLUMN_POINTER, shard.getPointer()); Clause queueNameClause = QueryBuilder.eq(COLUMN_QUEUE_NAME, shard.getQueueName()); Clause regionClause = QueryBuilder.eq(COLUMN_REGION, shard.getRegion()); Clause activeClause = QueryBuilder.eq(COLUMN_ACTIVE, 1); Clause shardIdClause = QueryBuilder.eq(COLUMN_SHARD_ID, shard.getShardId()); Statement update = QueryBuilder.update(getTableName(shard.getType())) .with(assignment) .where(queueNameClause) .and(regionClause) .and(activeClause) .and(shardIdClause); cassandraClient.getQueueMessageSession().execute(update); }
Example 4
Source File: CassandraSession.java From presto with Apache License 2.0 | 5 votes |
private static void addWhereClause(Select.Where where, List<CassandraColumnHandle> partitionKeyColumns, List<Object> filterPrefix) { for (int i = 0; i < filterPrefix.size(); i++) { CassandraColumnHandle column = partitionKeyColumns.get(i); Object value = column.getCassandraType().getJavaValue(filterPrefix.get(i)); Clause clause = QueryBuilder.eq(CassandraCqlUtils.validColumnName(column.getName()), value); where.and(clause); } }
Example 5
Source File: QueueMessageSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
private Statement createDeleteMessageStatement( final String queueName, final String region, final Long shardIdOrNull, final DatabaseQueueMessage.Type type, final UUID queueMessageId ) { final long shardId; if ( shardIdOrNull == null ) { Shard.Type shardType = DatabaseQueueMessage.Type.DEFAULT.equals( type ) ? Shard.Type.DEFAULT : Shard.Type.INFLIGHT; Shard shard = shardStrategy.selectShard( queueName, region, shardType, queueMessageId ); shardId = shard.getShardId(); } else { shardId = shardIdOrNull; } Clause queueNameClause = QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ); Clause regionClause = QueryBuilder.eq( COLUMN_REGION, region ); Clause shardIdClause = QueryBuilder.eq( COLUMN_SHARD_ID, shardId ); Clause queueMessageIdClause = QueryBuilder.eq( COLUMN_QUEUE_MESSAGE_ID, queueMessageId); Statement delete = QueryBuilder.delete().from(getTableName( type )) .where(queueNameClause) .and(regionClause) .and(shardIdClause) .and(queueMessageIdClause); return delete; }
Example 6
Source File: MapSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public void delete( final MapScope scope, final String key ) { Statement deleteMapEntry; Clause equalsEntryKey = QueryBuilder.eq("key", getMapEntryPartitionKey(scope, key)); deleteMapEntry = QueryBuilder.delete().from(MAP_ENTRIES_TABLE) .where(equalsEntryKey); session.execute(deleteMapEntry); // not sure which bucket the value is in, execute a delete against them all final int[] buckets = BUCKET_LOCATOR.getAllBuckets( scope.getName() ); List<ByteBuffer> mapKeys = new ArrayList<>(); for( int bucket : buckets){ mapKeys.add( getMapKeyPartitionKey(scope, bucket)); } Statement deleteMapKey; Clause inKey = QueryBuilder.in("key", mapKeys); Clause column1Equals = QueryBuilder.eq("column1", DataType.text().serialize(key, ProtocolVersion.NEWEST_SUPPORTED)); deleteMapKey = QueryBuilder.delete().from(MAP_KEYS_TABLE) .where(inKey).and(column1Equals); session.execute(deleteMapKey); }
Example 7
Source File: QueueSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public DatabaseQueue getQueue(String name) { logger.trace( "getQueue " + name ); Clause queueNameClause = QueryBuilder.eq(COLUMN_QUEUE_NAME, name); Statement query = QueryBuilder.select().all().from(TABLE_QUEUES) .where(queueNameClause); Row row = cassandraClient.getApplicationSession().execute(query).one(); if(row == null){ return null; } final String queueName = row.getString(COLUMN_QUEUE_NAME); final String regions = row.getString(COLUMN_REGIONS); final String defaultDestinations = row.getString(COLUMN_DEFAULT_DESTINATIONS); final long defaultDelayMs = row.getLong(COLUMN_DEFAULT_DELAY_MS); final int retryCount = row.getInt(COLUMN_RETRY_COUNT); final int handlingTimeoutSec = row.getInt(COLUMN_HANDLING_TIMEOUT_SEC); final String deadLetterQueue = row.getString(COLUMN_DEAD_LETTER_QUEUE); return new DatabaseQueue( queueName, regions, defaultDestinations, defaultDelayMs, retryCount, handlingTimeoutSec, deadLetterQueue); }
Example 8
Source File: ShardSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
public void deleteShard(final Shard shard){ Clause queueNameClause = QueryBuilder.eq(COLUMN_QUEUE_NAME, shard.getQueueName()); Clause regionClause = QueryBuilder.eq(COLUMN_REGION, shard.getRegion()); Clause activeClause = QueryBuilder.eq(COLUMN_ACTIVE, 1); Clause shardIdClause = QueryBuilder.eq(COLUMN_SHARD_ID, shard.getShardId()); Statement delete = QueryBuilder.delete().from(getTableName(shard.getType())) .where(queueNameClause) .and(regionClause) .and(activeClause) .and(shardIdClause); cassandraClient.getQueueMessageSession().execute(delete); }
Example 9
Source File: CassandraTable.java From hugegraph with Apache License 2.0 | 4 votes |
protected Clause relation2Cql(Relation relation) { String key = relation.serialKey().toString(); Object value = relation.serialValue(); switch (relation.relation()) { case EQ: return QueryBuilder.eq(key, value); case GT: return QueryBuilder.gt(key, value); case GTE: return QueryBuilder.gte(key, value); case LT: return QueryBuilder.lt(key, value); case LTE: return QueryBuilder.lte(key, value); case IN: return QueryBuilder.in(key, value); case CONTAINS_VALUE: return QueryBuilder.contains(key, value); case CONTAINS_KEY: return QueryBuilder.containsKey(key, value); case SCAN: String[] col = pkColumnName().stream() .map(pk -> formatKey(pk)) .toArray(String[]::new); Shard shard = (Shard) value; Object start = QueryBuilder.raw(shard.start()); Object end = QueryBuilder.raw(shard.end()); return Clauses.and( QueryBuilder.gte(QueryBuilder.token(col), start), QueryBuilder.lt(QueryBuilder.token(col), end)); /* * Currently we can't support LIKE due to error: * "cassandra no viable alternative at input 'like'..." */ // case LIKE: // return QueryBuilder.like(key, value); case NEQ: default: throw new NotSupportException("relation '%s'", relation); } }
Example 10
Source File: QueueMessageSerializationImpl.java From usergrid with Apache License 2.0 | 4 votes |
@Override public DatabaseQueueMessage loadMessage( final String queueName, final String region, final Long shardIdOrNull, final DatabaseQueueMessage.Type type, final UUID queueMessageId ) { if ( queueMessageId == null ) { return null; } logger.trace("loadMessage {}", queueMessageId); final long shardId; if ( shardIdOrNull == null ) { Shard.Type shardType = DatabaseQueueMessage.Type.DEFAULT.equals( type ) ? Shard.Type.DEFAULT : Shard.Type.INFLIGHT; Shard shard = shardStrategy.selectShard( queueName, region, shardType, queueMessageId ); shardId = shard.getShardId(); } else { shardId = shardIdOrNull; } Clause queueNameClause = QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ); Clause regionClause = QueryBuilder.eq( COLUMN_REGION, region ); Clause shardIdClause = QueryBuilder.eq( COLUMN_SHARD_ID, shardId ); Clause queueMessageIdClause = QueryBuilder.eq( COLUMN_QUEUE_MESSAGE_ID, queueMessageId); Statement select = QueryBuilder.select().from(getTableName( type )) .where(queueNameClause) .and(regionClause) .and(shardIdClause) .and(queueMessageIdClause); Row row = cassandraClient.getQueueMessageSession().execute(select).one(); if (row == null) { return null; } return new DatabaseQueueMessage( row.getUUID( COLUMN_MESSAGE_ID), type, row.getString( COLUMN_QUEUE_NAME), row.getString( COLUMN_REGION), row.getLong( COLUMN_SHARD_ID), row.getLong( COLUMN_QUEUED_AT), row.getLong( COLUMN_INFLIGHT_AT), row.getUUID( COLUMN_QUEUE_MESSAGE_ID) ); }
Example 11
Source File: MultiShardMessageIterator.java From usergrid with Apache License 2.0 | 4 votes |
private void advance(){ if (currentShard == null){ currentShard = shardIterator.next(); } Clause queueNameClause = QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName); Clause regionClause = QueryBuilder.eq( COLUMN_REGION, region); Clause shardIdClause = QueryBuilder.eq( COLUMN_SHARD_ID, currentShard.getShardId()); // if we have a pointer from the shard and this is the first seek, init from the pointer's position if ( currentShard.getPointer() != null && nextStart == null ){ nextStart = currentShard.getPointer(); } Statement query; if ( nextStart == null) { query = QueryBuilder.select().all().from(QueueMessageSerializationImpl.getTableName(messageType)) .where(queueNameClause) .and(regionClause) .and(shardIdClause) .limit(PAGE_SIZE); } else { Clause messageIdClause = QueryBuilder.gt( COLUMN_QUEUE_MESSAGE_ID, nextStart); query = QueryBuilder.select().all().from(QueueMessageSerializationImpl.getTableName(messageType)) .where(queueNameClause) .and(regionClause) .and(shardIdClause) .and(messageIdClause) .limit(PAGE_SIZE); } List<Row> rows = cassandraClient.getQueueMessageSession().execute(query).all(); logger.trace("results {} from query {}", rows.size(), query.toString()); if ( (rows == null || rows.size() == 0) && shardIterator.hasNext()) { currentShard = shardIterator.next(); advance(); } else { currentIterator = getIteratorFromRows(rows); } }
Example 12
Source File: ScopedCacheSerializationImpl.java From usergrid with Apache License 2.0 | 4 votes |
private void invalidateCQL(CacheScope scope){ Preconditions.checkNotNull(scope, "scope is required"); // determine bucketed row-key based application UUID final String rowKeyString = scope.getApplication().getUuid().toString(); final int bucket = BUCKET_LOCATOR.getCurrentBucket(rowKeyString); final Clause inKey = QueryBuilder.eq("key", getPartitionKey(scope, rowKeyString, bucket) ); final Statement statement = QueryBuilder.delete().from(SCOPED_CACHE_TABLE) .where(inKey); session.execute(statement); }
Example 13
Source File: ScopedCacheSerializationImpl.java From usergrid with Apache License 2.0 | 4 votes |
private void removeValueCQL(CacheScope scope, K key) { Preconditions.checkNotNull( scope, "scope is required"); Preconditions.checkNotNull( key, "key is required" ); // determine bucketed row-key based application UUID final String rowKeyString = scope.getApplication().getUuid().toString(); final int bucket = BUCKET_LOCATOR.getCurrentBucket(rowKeyString); // determine column name based on K key to string final String columnName = key.toString(); final Clause inKey = QueryBuilder.eq("key", getPartitionKey(scope, rowKeyString, bucket) ); final Clause inColumn = QueryBuilder.eq("column1", DataType.text().serialize(columnName, ProtocolVersion.NEWEST_SUPPORTED) ); final Statement statement = QueryBuilder.delete().from(SCOPED_CACHE_TABLE) .where(inKey) .and(inColumn); session.execute(statement); }
Example 14
Source File: CassandraTable.java From hugegraph with Apache License 2.0 | 4 votes |
public static final Clause formatEQ(HugeKeys key, Object value) { return QueryBuilder.eq(formatKey(key), value); }
Example 15
Source File: ShardSerializationImpl.java From usergrid with Apache License 2.0 | 3 votes |
public Shard loadShard(final Shard shard){ Clause queueNameClause = QueryBuilder.eq(COLUMN_QUEUE_NAME, shard.getQueueName()); Clause regionClause = QueryBuilder.eq(COLUMN_REGION, shard.getRegion()); Clause activeClause = QueryBuilder.eq(COLUMN_ACTIVE, 1); Clause shardIdClause = QueryBuilder.eq(COLUMN_SHARD_ID, shard.getShardId()); Statement select = QueryBuilder.select().from(getTableName(shard.getType())) .where(queueNameClause) .and(regionClause) .and(activeClause) .and(shardIdClause); Row row = cassandraClient.getQueueMessageSession().execute(select).one(); if (row == null){ return null; } final String queueName = row.getString(COLUMN_QUEUE_NAME); final String region = row.getString(COLUMN_REGION); final long shardId = row.getLong(COLUMN_SHARD_ID); final UUID pointer = row.getUUID(COLUMN_POINTER); return new Shard(queueName, region, shard.getType(), shardId, pointer); }
Example 16
Source File: ShardIterator.java From usergrid with Apache License 2.0 | 3 votes |
private void advance(){ Clause queueNameClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_QUEUE_NAME, queueName); Clause regionClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_REGION, region); Clause activeClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_ACTIVE, 1); Clause shardIdClause; if (nextStart == 0L && lastShardId.isPresent()) { shardIdClause = QueryBuilder.gt( ShardSerializationImpl.COLUMN_SHARD_ID, lastShardId.get() ); } else if (nextStart == 0L && !lastShardId.isPresent()) { shardIdClause = QueryBuilder.gte( ShardSerializationImpl.COLUMN_SHARD_ID, 0L ); } else { shardIdClause = QueryBuilder.gt( ShardSerializationImpl.COLUMN_SHARD_ID, nextStart ); } Statement query = QueryBuilder.select().all().from(ShardSerializationImpl.getTableName(shardType)) .where(queueNameClause) .and(regionClause) .and(activeClause) .and(shardIdClause) .limit(PAGE_SIZE); List<Row> rows = cassandraClient.getQueueMessageSession().execute(query).all(); currentIterator = getIteratorFromRows(rows); }
Example 17
Source File: QueueSerializationImpl.java From usergrid with Apache License 2.0 | 3 votes |
@Override public void deleteQueue(String name) { logger.trace( "deleteQueue " + name ); Clause queueNameClause = QueryBuilder.eq(COLUMN_QUEUE_NAME, name); Statement delete = QueryBuilder.delete().from(TABLE_QUEUES) .where(queueNameClause); cassandraClient.getApplicationSession().execute(delete); }
Example 18
Source File: QueueMessageSerializationImpl.java From usergrid with Apache License 2.0 | 3 votes |
@Override public void deleteMessageData( final UUID messageId ) { logger.trace("deleteMessageData {}", messageId); Clause messageIdClause = QueryBuilder.eq(COLUMN_MESSAGE_ID, messageId); Statement delete = QueryBuilder.delete().from(TABLE_MESSAGE_DATA).where(messageIdClause); cassandraClient.getApplicationSession().execute(delete); }
Example 19
Source File: ScopedCacheSerializationImpl.java From usergrid with Apache License 2.0 | 2 votes |
private V readValueCQL(CacheScope scope, K key, TypeReference typeRef){ Preconditions.checkNotNull(scope, "scope is required"); Preconditions.checkNotNull(key, "key is required"); final String rowKeyString = scope.getApplication().getUuid().toString(); final int bucket = BUCKET_LOCATOR.getCurrentBucket(rowKeyString); // determine column name based on K key to string final String columnName = key.toString(); final Clause inKey = QueryBuilder.eq("key", getPartitionKey(scope, rowKeyString, bucket) ); final Clause inColumn = QueryBuilder.eq("column1", DataType.text().serialize(columnName, ProtocolVersion.NEWEST_SUPPORTED) ); final Statement statement = QueryBuilder.select().all().from(SCOPED_CACHE_TABLE) .where(inKey) .and(inColumn) .setConsistencyLevel(cassandraConfig.getDataStaxReadCl()); final ResultSet resultSet = session.execute(statement); final com.datastax.driver.core.Row row = resultSet.one(); if (row == null){ if(logger.isDebugEnabled()){ logger.debug("Cache value not found for key {}", key ); } return null; } try { return MAPPER.readValue(row.getBytes("value").array(), typeRef); } catch (IOException ioe) { logger.error("Unable to read cached value", ioe); throw new RuntimeException("Unable to read cached value", ioe); } }
Example 20
Source File: UniqueValueSerializationStrategyImpl.java From usergrid with Apache License 2.0 | 2 votes |
@Override public BatchStatement deleteCQL( final ApplicationScope scope, UniqueValue value){ Preconditions.checkNotNull( value, "value is required" ); final BatchStatement batch = new BatchStatement(); final Id entityId = value.getEntityId(); final UUID entityVersion = value.getEntityVersion(); final Field<?> field = value.getField(); ValidationUtils.verifyIdentity( entityId ); ValidationUtils.verifyVersion( entityVersion ); final EntityVersion ev = new EntityVersion( entityId, entityVersion ); final UniqueFieldEntry uniqueFieldEntry = new UniqueFieldEntry( entityVersion, field ); ByteBuffer partitionKey = getPartitionKey( scope.getApplication(), value.getEntityId().getType(), value.getField().getTypeName().toString(), value.getField().getName(), value.getField().getValue()); ByteBuffer columnValue = serializeUniqueValueColumn(ev); final Clause uniqueEqKey = QueryBuilder.eq("key", partitionKey ); final Clause uniqueEqColumn = QueryBuilder.eq("column1", columnValue ); Statement uniqueDelete = QueryBuilder.delete().from(TABLE_UNIQUE_VALUES).where(uniqueEqKey).and(uniqueEqColumn); batch.add(uniqueDelete); ByteBuffer logPartitionKey = getLogPartitionKey(scope.getApplication(), entityId); ByteBuffer logColumnValue = serializeUniqueValueLogColumn(uniqueFieldEntry); final Clause uniqueLogEqKey = QueryBuilder.eq("key", logPartitionKey ); final Clause uniqueLogEqColumn = QueryBuilder.eq("column1", logColumnValue ); Statement uniqueLogDelete = QueryBuilder.delete() .from(TABLE_UNIQUE_VALUES_LOG).where(uniqueLogEqKey).and( uniqueLogEqColumn); batch.add(uniqueLogDelete); if ( logger.isTraceEnabled() ) { logger.trace( "Building batch statement for unique value entity={} version={} name={} value={} ", value.getEntityId().getUuid(), value.getEntityVersion(), value.getField().getName(), value.getField().getValue() ); } return batch; }