use of org.springframework.data.cassandra.repository.Query.Idempotency in project spring-data-cassandra by spring-projects.
the class QueryStatementCreator method select.
/**
* Create a {@link Statement} from a {@link StringBasedQuery} and apply query options.
*
* @param stringBasedQuery must not be {@literal null}.
* @param parameterAccessor must not be {@literal null}.
* @return the {@link Statement}.
*/
SimpleStatement select(StringBasedQuery stringBasedQuery, CassandraParameterAccessor parameterAccessor, SpELExpressionEvaluator evaluator) {
try {
SimpleStatement boundQuery = stringBasedQuery.bindQuery(parameterAccessor, evaluator);
Optional<QueryOptions> queryOptions = Optional.ofNullable(parameterAccessor.getQueryOptions());
SimpleStatement queryToUse = boundQuery;
if (queryOptions.isPresent()) {
queryToUse = Optional.ofNullable(parameterAccessor.getQueryOptions()).map(it -> QueryOptionsUtil.addQueryOptions(boundQuery, it)).orElse(boundQuery);
} else if (this.queryMethod.hasConsistencyLevel()) {
queryToUse = queryToUse.setConsistencyLevel(this.queryMethod.getRequiredAnnotatedConsistencyLevel());
}
Idempotency idempotency = this.queryMethod.getIdempotency();
if (idempotency != Idempotency.UNDEFINED) {
queryToUse = queryToUse.setIdempotent(idempotency == Idempotency.IDEMPOTENT);
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Created query [%s].", QueryExtractorDelegate.getCql(queryToUse)));
}
return queryToUse;
} catch (RuntimeException cause) {
throw QueryCreationException.create(this.queryMethod, cause);
}
}
Aggregations