Throw an explicit exception if count query does not return a count. (#1195)
Also just use the first projected property instead of one explicitly named "count". Closes #925,#960.
This commit is contained in:
@@ -114,6 +114,12 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
|
||||
Long countFancyExpression(@Param("projectIds") List<String> projectIds, @Param("planIds") List<String> planIds,
|
||||
@Param("active") Boolean active);
|
||||
|
||||
@Query("SELECT 1 FROM `#{#n1ql.bucket}` WHERE 0 = 1" )
|
||||
Long countBad();
|
||||
|
||||
@Query("SELECT count(*) FROM `#{#n1ql.bucket}`" )
|
||||
Long countGood();
|
||||
|
||||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
|
||||
Page<Airport> findAllByIataNot(String iata, Pageable pageable);
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.data.auditing.DateTimeProvider;
|
||||
import org.springframework.data.couchbase.CouchbaseClientFactory;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.core.CouchbaseQueryExecutionException;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.core.RemoveResult;
|
||||
import org.springframework.data.couchbase.core.query.N1QLExpression;
|
||||
@@ -474,6 +475,16 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void badCount(){
|
||||
assertThrows(CouchbaseQueryExecutionException.class, () -> airportRepository.countBad());
|
||||
}
|
||||
|
||||
@Test
|
||||
void goodCount(){
|
||||
airportRepository.countGood();
|
||||
}
|
||||
|
||||
@Test
|
||||
void threadSafeParametersTest() throws Exception {
|
||||
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
|
||||
|
||||
Reference in New Issue
Block a user