com.datastax.driver.core.querybuilder.Assignment Java Examples
The following examples show how to use
com.datastax.driver.core.querybuilder.Assignment.
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: 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 #2
Source File: CassandraMailboxCounterDAO.java From james-project with Apache License 2.0 | 4 votes |
private PreparedStatement updateMailboxStatement(Session session, Assignment operation) { return session.prepare( update(TABLE_NAME) .with(operation) .where(eq(MAILBOX_ID, bindMarker(MAILBOX_ID)))); }
Example #3
Source File: PutCassandraRecord.java From nifi with Apache License 2.0 | 4 votes |
protected Statement generateUpdate(String cassandraTable, RecordSchema schema, String updateKeys, String updateMethod, Map<String, Object> recordContentMap) { Update updateQuery; // Split up the update key names separated by a comma, should not be empty final Set<String> updateKeyNames; updateKeyNames = Arrays.stream(updateKeys.split(",")) .map(String::trim) .filter(StringUtils::isNotEmpty) .collect(Collectors.toSet()); if (updateKeyNames.isEmpty()) { throw new IllegalArgumentException("No Update Keys were specified"); } // Verify if all update keys are present in the record for (String updateKey : updateKeyNames) { if (!schema.getFieldNames().contains(updateKey)) { throw new IllegalArgumentException("Update key '" + updateKey + "' is not present in the record schema"); } } // Prepare keyspace/table names if (cassandraTable.contains(".")) { String[] keyspaceAndTable = cassandraTable.split("\\."); updateQuery = QueryBuilder.update(keyspaceAndTable[0], keyspaceAndTable[1]); } else { updateQuery = QueryBuilder.update(cassandraTable); } // Loop through the field names, setting those that are not in the update key set, and using those // in the update key set as conditions. for (String fieldName : schema.getFieldNames()) { Object fieldValue = recordContentMap.get(fieldName); if (updateKeyNames.contains(fieldName)) { updateQuery.where(QueryBuilder.eq(fieldName, fieldValue)); } else { Assignment assignment; if (SET_TYPE.getValue().equalsIgnoreCase(updateMethod)) { assignment = QueryBuilder.set(fieldName, fieldValue); } else if (INCR_TYPE.getValue().equalsIgnoreCase(updateMethod)) { assignment = QueryBuilder.incr(fieldName, convertFieldObjectToLong(fieldName, fieldValue)); } else if (DECR_TYPE.getValue().equalsIgnoreCase(updateMethod)) { assignment = QueryBuilder.decr(fieldName, convertFieldObjectToLong(fieldName, fieldValue)); } else { throw new IllegalArgumentException("Update Method '" + updateMethod + "' is not valid."); } updateQuery.with(assignment); } } return updateQuery; }