/** * Add common {@link WriteOptions} options to {@link Delete} CQL statements. * * @param delete {@link Delete} CQL statement, must not be {@literal null}. * @param writeOptions write options (e.g. consistency level) to add to the CQL statement. * @return the given {@link Delete}. * @since 2.1 */ static Delete addWriteOptions(Delete delete, WriteOptions writeOptions) { Assert.notNull(delete, "Delete must not be null"); QueryOptionsUtil.addQueryOptions(delete, writeOptions); return delete; } }
/** * Creates a Delete Query Object from an annotated POJO. The {@link Delete} uses the identity from the given * {@code objectToDelete}. * * @param tableName the table name, must not be empty and not {@literal null}. * @param objectToDelete the object to delete, must not be {@literal null}. * @param options optional {@link QueryOptions} to apply to the {@link Delete} statement. * @param entityWriter the {@link EntityWriter} to write delete where clauses. * @return The Query object to run with session.execute(); */ static Delete createDeleteQuery(String tableName, Object objectToDelete, QueryOptions options, EntityWriter<Object, Object> entityWriter) { Assert.hasText(tableName, "TableName must not be empty"); Assert.notNull(objectToDelete, "Object to delete must not be null"); Assert.notNull(entityWriter, "EntityWriter must not be null"); Delete.Selection deleteSelection = QueryBuilder.delete(); Delete delete = deleteSelection.from(tableName); if (options instanceof WriteOptions) { QueryOptionsUtil.addWriteOptions(delete, (WriteOptions) options); } else { QueryOptionsUtil.addQueryOptions(delete, options); } Where where = delete.where(); entityWriter.write(objectToDelete, where); return delete; }
.execute((ReactiveSessionCallback<WriteResult>) session -> session.prepare(this.ingestQuery) .map(s -> QueryOptionsUtil.addPreparedStatementOptions(s, this.writeOptions)) .flatMapMany(s -> Flux.fromIterable(rows)
/** * Add common {@link WriteOptions} options to {@link Insert} CQL statements. * * @param insert {@link Insert} CQL statement, must not be {@literal null}. * @param writeOptions write options (e.g. consistency level) to add to the CQL statement. * @return the given {@link Insert}. * @see #addWriteOptions(Insert, WriteOptions) * @since 2.1 */ static Insert addWriteOptions(Insert insert, WriteOptions writeOptions) { Assert.notNull(insert, "Insert must not be null"); if (writeOptions instanceof InsertOptions) { InsertOptions insertOptions = (InsertOptions) writeOptions; if (insertOptions.isIfNotExists()) { insert = insert.ifNotExists(); } } QueryOptionsUtil.addWriteOptions(insert, writeOptions); return insert; }
.execute((ReactiveSessionCallback<WriteResult>) session -> session.prepare(this.ingestQuery) .map(s -> QueryOptionsUtil.addPreparedStatementOptions(s, this.writeOptions)) .flatMapMany(s -> Flux.fromIterable(rows)
/** * Add common {@link WriteOptions} options to {@link Update} CQL statements. * * @param update {@link Update} CQL statement, must not be {@literal null}. * @param writeOptions write options (e.g. consistency level) to add to the CQL statement. * @return the given {@link Update}. * @see QueryOptionsUtil#addWriteOptions(Update, WriteOptions) * @since 2.1 */ static Update addWriteOptions(Update update, WriteOptions writeOptions) { Assert.notNull(update, "Update must not be null"); QueryOptionsUtil.addWriteOptions(update, writeOptions); if (writeOptions instanceof UpdateOptions) { UpdateOptions updateOptions = (UpdateOptions) writeOptions; if (updateOptions.isIfExists()) { update.where().ifExists(); } } return update; }
public void setStatementProcessor(MessageProcessor<Statement> statementProcessor) { Assert.notNull(statementProcessor, "'statementProcessor' must not be null."); this.sessionMessageCallback = (session, requestMessage) -> session.execute( QueryOptionsUtil.addQueryOptions(statementProcessor.processMessage(requestMessage), this.writeOptions)); this.mode = Type.STATEMENT; }
public void setStatementProcessor(MessageProcessor<Statement> statementProcessor) { Assert.notNull(statementProcessor, "'statementProcessor' must not be null."); this.sessionMessageCallback = (session, requestMessage) -> session.execute( QueryOptionsUtil.addQueryOptions(statementProcessor.processMessage(requestMessage), this.writeOptions)); this.mode = Type.STATEMENT; }
/** * Create a new {@link CachedPreparedStatementCreator} given {@link PreparedStatementCache} and {@code cql} to * prepare. This method applies {@link QueryOptions} to the {@link com.datastax.driver.core.Statement} before * preparing it. Subsequent calls require the a CQL statement that {@link String#equals(Object) are equal} to the * previously used CQL string for a cache hit. Otherwise, the statement is likely to be re-prepared. * * @param cache must not be {@literal null}. * @param cql must not be {@literal null} or empty. * @param queryOptions must not be {@literal null}. * @return the {@link CachedPreparedStatementCreator} for {@code cql}. */ public static CachedPreparedStatementCreator of(PreparedStatementCache cache, String cql, QueryOptions queryOptions) { Assert.notNull(cache, "Cache must not be null"); Assert.hasText(cql, "CQL statement is required"); Assert.notNull(queryOptions, "QueryOptions must not be null"); return new CachedPreparedStatementCreator(cache, QueryOptionsUtil.addQueryOptions(new SimpleStatement(cql), queryOptions)); }
/** * Add common {@link WriteOptions} options to {@link Delete} CQL statements. * * @param delete {@link Delete} CQL statement, must not be {@literal null}. * @param writeOptions write options (e.g. consistency level) to add to the CQL statement. * @return the given {@link Delete}. * @since 2.1 */ public static Delete addWriteOptions(Delete delete, WriteOptions writeOptions) { Assert.notNull(delete, "Update must not be null"); addQueryOptions(delete, writeOptions); if (writeOptions.getTimestamp() != null) { delete.using(QueryBuilder.timestamp(writeOptions.getTimestamp())); } return delete; }
.map(it -> QueryOptionsUtil.addQueryOptions(boundQuery, it)) .orElse(boundQuery); } else if (this.queryMethod.hasConsistencyLevel()) {
private Select createSelect(Query query, CassandraPersistentEntity<?> entity, Filter filter, List<Selector> selectors, CqlIdentifier tableName) { Sort sort = Optional.of(query.getSort()).map(querySort -> getQueryMapper().getMappedSort(querySort, entity)) .orElse(Sort.unsorted()); Select select = createSelectAndOrder(selectors, tableName, filter, sort); query.getQueryOptions().ifPresent(queryOptions -> QueryOptionsUtil.addQueryOptions(select, queryOptions)); if (query.getLimit() > 0) { select.limit(Ints.checkedCast(query.getLimit())); } if (query.isAllowFiltering()) { select.allowFiltering(); } query.getPagingState().ifPresent(select::setPagingState); return select; }
/** * Create an {@literal UPDATE} statement by mapping {@link Query} to {@link Update}. * * @param query must not be {@literal null}. * @param updateObj must not be {@literal null}. * @param entity must not be {@literal null}. * @param tableName must not be {@literal null}. * @return the rendered {@link RegularStatement}. * @since 2.1 */ RegularStatement update(Query query, Update updateObj, CassandraPersistentEntity<?> entity, CqlIdentifier tableName) { Assert.notNull(query, "Query must not be null"); Assert.notNull(updateObj, "Update must not be null"); Assert.notNull(entity, "Entity must not be null"); Assert.notNull(tableName, "Table name must not be null"); Filter filter = getQueryMapper().getMappedObject(query, entity); Update mappedUpdate = getUpdateMapper().getMappedObject(updateObj, entity); com.datastax.driver.core.querybuilder.Update update = update(tableName, mappedUpdate, filter); query.getQueryOptions().ifPresent(queryOptions -> { if (queryOptions instanceof WriteOptions) { QueryUtils.addWriteOptions(update, (WriteOptions) queryOptions); } else { QueryOptionsUtil.addQueryOptions(update, queryOptions); } }); query.getPagingState().ifPresent(update::setPagingState); return update; }
/** * Create a {@literal DELETE} statement by mapping {@link Query} to {@link Delete}. * * @param query must not be {@literal null}. * @param entity must not be {@literal null}. * @param tableName must not be {@literal null}. * @return the rendered {@link RegularStatement}. * @see 2.1 */ public RegularStatement delete(Query query, CassandraPersistentEntity<?> entity, CqlIdentifier tableName) { Assert.notNull(query, "Query must not be null"); Assert.notNull(entity, "Entity must not be null"); Assert.notNull(tableName, "Table name must not be null"); Filter filter = getQueryMapper().getMappedObject(query, entity); List<String> columnNames = getQueryMapper().getMappedColumnNames(query.getColumns(), entity); Delete delete = delete(columnNames, tableName, filter); query.getQueryOptions().ifPresent(queryOptions -> { if (queryOptions instanceof WriteOptions) { QueryUtils.addWriteOptions(delete, (WriteOptions) queryOptions); } else { QueryOptionsUtil.addQueryOptions(delete, queryOptions); } }); query.getPagingState().ifPresent(delete::setPagingState); return delete; }
/** * Add common {@link WriteOptions} options to {@link Insert} CQL statements. * * @param insert {@link Insert} CQL statement, must not be {@literal null}. * @param writeOptions write options (e.g. consistency level) to add to the CQL statement. * @return the given {@link Insert}. */ public static Insert addWriteOptions(Insert insert, WriteOptions writeOptions) { Assert.notNull(insert, "Insert must not be null"); addQueryOptions(insert, writeOptions); if (!writeOptions.getTtl().isNegative()) { insert.using(QueryBuilder.ttl(Math.toIntExact(writeOptions.getTtl().getSeconds()))); } if (writeOptions.getTimestamp() != null) { insert.using(QueryBuilder.timestamp(writeOptions.getTimestamp())); } return insert; }
/** * Add common {@link WriteOptions} options to {@link Update} CQL statements. * * @param update {@link Update} CQL statement, must not be {@literal null}. * @param writeOptions write options (e.g. consistency level) to add to the CQL statement. * @return the given {@link Update}. */ public static Update addWriteOptions(Update update, WriteOptions writeOptions) { Assert.notNull(update, "Update must not be null"); addQueryOptions(update, writeOptions); if (!writeOptions.getTtl().isNegative()) { update.using(QueryBuilder.ttl(Math.toIntExact(writeOptions.getTtl().getSeconds()))); } if (writeOptions.getTimestamp() != null) { update.using(QueryBuilder.timestamp(writeOptions.getTimestamp())); } return update; } }