From c26053868c1785cfd9ff75acdddca8630fe816a8 Mon Sep 17 00:00:00 2001 From: Subhashni Balakrishnan Date: Tue, 10 Jan 2017 17:26:37 -0800 Subject: [PATCH] DATACOUCH-265 - Verify entity filter is not added, if n1ql.filter is not in query Original pull request: #128. --- .../repository/N1qlCouchbaseRepositoryTests.java | 8 ++++++++ .../data/couchbase/repository/PartyRepository.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/integration/java/org/springframework/data/couchbase/repository/N1qlCouchbaseRepositoryTests.java b/src/integration/java/org/springframework/data/couchbase/repository/N1qlCouchbaseRepositoryTests.java index 2d04bdfa..e8d9e04f 100644 --- a/src/integration/java/org/springframework/data/couchbase/repository/N1qlCouchbaseRepositoryTests.java +++ b/src/integration/java/org/springframework/data/couchbase/repository/N1qlCouchbaseRepositoryTests.java @@ -33,6 +33,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; +import org.springframework.data.mapping.model.MappingInstantiationException; import org.springframework.data.repository.core.support.RepositoryFactorySupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; @@ -177,4 +178,11 @@ public class N1qlCouchbaseRepositoryTests { previousAttendees = party.getAttendees(); } } + + //Fails on deserialization as a different entity item is also present + @Test(expected = MappingInstantiationException.class) + public void shouldFailWithMissingFilterStringBasedQuery() { + Sort sort = new Sort(Sort.Direction.DESC, "attendees"); + List parties = partyRepository.findParties(sort); + } } diff --git a/src/integration/java/org/springframework/data/couchbase/repository/PartyRepository.java b/src/integration/java/org/springframework/data/couchbase/repository/PartyRepository.java index e4954ad7..dcec677b 100644 --- a/src/integration/java/org/springframework/data/couchbase/repository/PartyRepository.java +++ b/src/integration/java/org/springframework/data/couchbase/repository/PartyRepository.java @@ -9,6 +9,7 @@ import org.springframework.data.couchbase.core.query.View; import org.springframework.data.couchbase.core.query.ViewIndexed; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.Param; /** @@ -47,6 +48,9 @@ public interface PartyRepository extends CouchbaseRepository { @Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND `attendees` >= $1") Page findPartiesWithAttendee(int count, Pageable pageable); + @Query("#{#n1ql.selectEntity}") + List findParties(Sort sort); + @Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND `desc` LIKE '%' || $included || '%' AND attendees >= $min" + " AND `desc` NOT LIKE '%' || $excluded || '%'") List findAllWithNamedParams(@Param("excluded") String ex, @Param("included") String inc, @Param("min") long minimumAttendees);