Search in sources :

Example 1 with Idempotency

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);
    }
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Idempotency(org.springframework.data.cassandra.repository.Query.Idempotency) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions)

Aggregations

SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 QueryOptions (org.springframework.data.cassandra.core.cql.QueryOptions)1 Idempotency (org.springframework.data.cassandra.repository.Query.Idempotency)1