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:
mikereiche
2020-09-22 16:39:26 -07:00
parent 82edad5759
commit e72cdba6ee
8 changed files with 66 additions and 248 deletions

View File

@@ -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);
}

View File

@@ -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) {

View File

@@ -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);