DATACOUCH-616 - Fix parsing of String Query containing conditionals in quotes
For a query as below that has conditional portions, the parsing for
parameters was being done before the conditional portions were being
resolved, which left the parameters between quotes where they wre
not being recognized as query parameters.
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} " +
" #{#projectIds != null ? 'AND iata IN $1' : ''} ")
Long count(@Param("projectIds") List<String> projectIds)
This commit is contained in:
@@ -18,14 +18,13 @@ package org.springframework.data.couchbase.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.couchbase.client.java.query.QueryScanConsistency;
|
||||
import org.springframework.data.couchbase.repository.Query;
|
||||
import org.springframework.data.couchbase.repository.ScanConsistency;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.couchbase.client.java.query.QueryScanConsistency;
|
||||
|
||||
/**
|
||||
* template class for Reactive Couchbase operations
|
||||
*
|
||||
@@ -65,4 +64,11 @@ public interface AirportRepository extends PagingAndSortingRepository<Airport, S
|
||||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
|
||||
long count();
|
||||
|
||||
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} " +
|
||||
" #{#projectIds != null ? 'AND iata IN $1' : ''} " +
|
||||
" #{#planIds != null ? 'AND icao IN $2' : ''} " +
|
||||
" #{#active != null ? 'AND false = $3' : ''} ")
|
||||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
|
||||
Long countFancyExpression(@Param("projectIds") List<String> projectIds, @Param("planIds") List<String> planIds, @Param("active") Boolean active);
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.data.couchbase.core.mapping.Document;
|
||||
* @author Michael Reiche
|
||||
*/
|
||||
|
||||
@Document(expiry = 5)
|
||||
@Document(expiry = 1)
|
||||
public class UserAnnotated extends User {
|
||||
|
||||
public UserAnnotated(String id, String firstname, String lastname) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.couchbase.repository;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -131,6 +132,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
airportRepository.save(airport);
|
||||
}
|
||||
|
||||
Long count = airportRepository.countFancyExpression( Arrays.asList("JFK"), Arrays.asList("jfk"), false);
|
||||
assertEquals( 1, count);
|
||||
|
||||
long airportCount = airportRepository.count();
|
||||
assertEquals(7, airportCount);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user