Java Code Examples for com.datastax.driver.core.querybuilder.Update#Where
The following examples show how to use
com.datastax.driver.core.querybuilder.Update#Where .
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: UpdateStatementHandler.java From scalardb with Apache License 2.0 | 6 votes |
private Update prepare(Put put) { Update update = QueryBuilder.update(put.forNamespace().get(), put.forTable().get()); Update.Assignments assignments = update.with(); put.getValues().forEach((k, v) -> assignments.and(set(k, bindMarker()))); Update.Where where = update.where(); put.getPartitionKey().forEach(v -> where.and(QueryBuilder.eq(v.getName(), bindMarker()))); put.getClusteringKey() .ifPresent( k -> { k.forEach(v -> where.and(QueryBuilder.eq(v.getName(), bindMarker()))); }); setCondition(where, put); return update; }
Example 2
Source File: CassandraUtil.java From sunbird-lms-service with MIT License | 6 votes |
/** * Method to create the cassandra update query. * * @param primaryKey map representing the composite primary key. * @param nonPKRecord map contains the fields that has to update. * @param keyspaceName cassandra keyspace name. * @param tableName cassandra table name. * @return RegularStatement. */ public static RegularStatement createUpdateQuery( Map<String, Object> primaryKey, Map<String, Object> nonPKRecord, String keyspaceName, String tableName) { Update update = QueryBuilder.update(keyspaceName, tableName); Assignments assignments = update.with(); Update.Where where = update.where(); nonPKRecord .entrySet() .stream() .forEach( x -> { assignments.and(QueryBuilder.set(x.getKey(), x.getValue())); }); primaryKey .entrySet() .stream() .forEach( x -> { where.and(QueryBuilder.eq(x.getKey(), x.getValue())); }); return where; }
Example 3
Source File: ConditionSetter.java From scalardb with Apache License 2.0 | 5 votes |
/** * Adds {@code PutIf}-specific conditions to the statement * * @param condition {@code PutIf} condition */ @Override public void visit(PutIf condition) { Update.Where update = (Update.Where) statement; List<ConditionalExpression> expressions = condition.getExpressions(); Update.Conditions cond = update.onlyIf(createClauseWith(expressions.get(0))); IntStream.range(1, expressions.size()) .forEach( i -> { cond.and(createClauseWith(expressions.get(i))); }); }
Example 4
Source File: ConditionSetter.java From scalardb with Apache License 2.0 | 4 votes |
/** * Adds {@code PutIfExists}-specific conditions to the statement * * @param condition {@code PutIfExists} condition */ @Override public void visit(PutIfExists condition) { Update.Where update = (Update.Where) statement; update.ifExists(); }
Example 5
Source File: CassandraDACImpl.java From sunbird-lms-service with MIT License | 4 votes |
public Response updateMapRecord( String keySpace, String table, Map<String, Object> primaryKey, String column, String key, Object value, boolean add) { Update update = QueryBuilder.update(keySpace, table); if (add) { update.with(QueryBuilder.put(column, key, value)); } else { update.with(QueryBuilder.remove(column, key)); } if (MapUtils.isEmpty(primaryKey)) { ProjectLogger.log( Constants.EXCEPTION_MSG_FETCH + table + " : primary key is a must for update call", LoggerEnum.ERROR.name()); throw new ProjectCommonException( ResponseCode.SERVER_ERROR.getErrorCode(), ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode()); } Update.Where where = update.where(); for (Map.Entry<String, Object> filter : primaryKey.entrySet()) { Object filterValue = filter.getValue(); if (filterValue instanceof List) { where = where.and(QueryBuilder.in(filter.getKey(), ((List) filter.getValue()))); } else { where = where.and(QueryBuilder.eq(filter.getKey(), filter.getValue())); } } try { Response response = new Response(); ProjectLogger.log("Remove Map-Key Query: " + update.toString(), LoggerEnum.INFO); connectionManager.getSession(keySpace).execute(update); response.put(Constants.RESPONSE, Constants.SUCCESS); return response; } catch (Exception e) { e.printStackTrace(); ProjectLogger.log(Constants.EXCEPTION_MSG_FETCH + table + " : " + e.getMessage(), e); throw new ProjectCommonException( ResponseCode.SERVER_ERROR.getErrorCode(), ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode()); } }
Example 6
Source File: CassandraApplicableFlagDAO.java From james-project with Apache License 2.0 | 4 votes |
private Update.Where updateQuery(CassandraId cassandraId, Set<String> userFlags) { return addUserFlagsToQuery(userFlags, update(TABLE_NAME).with()) .where(eq(MAILBOX_ID, cassandraId.asUuid())); }