DATACOUCH-64 - Enable dynamic queries on repositories.
This changeset adds dynamic queries that can be annotated with @View and also provide a custom Query param to change properties at runtime if needed.
This commit is contained in:
@@ -23,6 +23,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactory;
|
||||
@@ -98,4 +99,16 @@ public class SimpleCouchbaseRepositoryTests {
|
||||
assertEquals(100, repository.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindCustom() {
|
||||
Iterable<User> users = repository.customViewQuery(new Query().setLimit(2).setStale(Stale.FALSE));
|
||||
int size = 0;
|
||||
for (User u : users) {
|
||||
size++;
|
||||
assertNotNull(u.getKey());
|
||||
assertNotNull(u.getUsername());
|
||||
}
|
||||
assertEquals(2, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,15 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import com.couchbase.client.protocol.views.Query;
|
||||
import org.springframework.data.couchbase.core.view.View;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
public interface UserRepository extends CouchbaseRepository<User, String> {
|
||||
|
||||
@View(designDocument = "user", viewName = "all")
|
||||
Iterable<User> customViewQuery(Query query);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user