@Override public <T> Flux<T> execute(ReactiveSessionCallback<T> action) throws DataAccessException { Assert.notNull(action, "Callback object must not be null"); return createFlux(action).onErrorMap(translateException("ReactiveSessionCallback", getCql(action))); }
@Override public <T> Flux<T> execute(ReactivePreparedStatementCreator psc, ReactivePreparedStatementCallback<T> action) throws DataAccessException { Assert.notNull(psc, "ReactivePreparedStatementCreator must not be null"); Assert.notNull(action, "ReactivePreparedStatementCallback object must not be null"); return createFlux(session -> { logger.debug("Preparing statement [{}] using {}", getCql(psc), psc); return psc.createPreparedStatement(session).doOnNext(this::applyStatementSettings) .flatMapMany(ps -> action.doInPreparedStatement(session, ps)); }).onErrorMap(translateException("ReactivePreparedStatementCallback", getCql(psc))); }
/** * Query using a prepared statement, reading the {@link ReactiveResultSet} with a {@link ReactiveResultSetExtractor}. * * @param psc object that can create a {@link PreparedStatement} given a {@link ReactiveSession} * @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is * {@literal null}, the CQL will be assumed to contain no bind parameters. * @param rse object that will extract results * @return an arbitrary result object, as returned by the {@link ReactiveResultSetExtractor} * @throws DataAccessException if there is any problem */ public <T> Flux<T> query(ReactivePreparedStatementCreator psc, @Nullable PreparedStatementBinder preparedStatementBinder, ReactiveResultSetExtractor<T> rse) throws DataAccessException { Assert.notNull(psc, "ReactivePreparedStatementCreator must not be null"); Assert.notNull(rse, "ReactiveResultSetExtractor object must not be null"); return execute(psc, (session, ps) -> Mono.just(ps).flatMapMany(pps -> { if (logger.isDebugEnabled()) { logger.debug("Executing Prepared CQL Statement [{}]", ps.getQueryString()); } BoundStatement boundStatement = (preparedStatementBinder != null ? preparedStatementBinder.bindValues(ps) : ps.bind()); applyStatementSettings(boundStatement); return session.execute(boundStatement); }).flatMap(rse::extractData)).onErrorMap(translateException("Query", getCql(psc))); }