DATACOUCH-196 - Fix ViewIndexed generated map and improve usability
The generated view's default map function now emits meta.id so that CRUD findAll(ids) works. The default value for the view name is now "all". The ViewIndexed isn't documented as applicable to METHODs (deferred feature).
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package org.springframework.data.couchbase.repository.index;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
import org.springframework.data.couchbase.core.query.ViewIndexed;
|
||||
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
|
||||
@ViewIndexed(designDoc = "foo")
|
||||
public interface IndexedFooRepository extends CouchbaseRepository<IndexedFooRepository.Foo, String> {
|
||||
|
||||
@Document
|
||||
final class Foo {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String value1;
|
||||
|
||||
private int value2;
|
||||
|
||||
public Foo(String id, String value1, int value2) {
|
||||
this.id = id;
|
||||
this.value1 = value1;
|
||||
this.value2 = value2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class IndexedRepositoryTestListener extends DependencyInjectionTestExecut
|
||||
public void beforeTestClass(final TestContext testContext) throws Exception {
|
||||
Bucket client = (Bucket) testContext.getApplicationContext().getBean("couchbaseBucket");
|
||||
client.bucketManager().removeDesignDocument(IndexedRepositoryTests.VIEW_DOC);
|
||||
client.bucketManager().removeDesignDocument("foo");
|
||||
client.query(N1qlQuery.simple(Index.dropPrimaryIndex(client.name())));
|
||||
client.query(N1qlQuery.simple(Index.dropIndex(client.name(), IndexedRepositoryTests.SECONDARY)));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.data.couchbase.repository.index;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.couchbase.client.java.query.N1qlQuery;
|
||||
import com.couchbase.client.java.query.N1qlQueryResult;
|
||||
import com.couchbase.client.java.view.DesignDocument;
|
||||
@@ -144,4 +146,40 @@ public class IndexedRepositoryTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindListOfIdsThroughDefaulViewIndexed() {
|
||||
IndexedFooRepository.Foo foo1 = new IndexedFooRepository.Foo("foo1", "foo", 1);
|
||||
IndexedFooRepository.Foo foo2 = new IndexedFooRepository.Foo("foo2", "bar", 2);
|
||||
|
||||
IndexedFooRepository repository = factory.getRepository(IndexedFooRepository.class);
|
||||
|
||||
DesignDocument designDoc = template.getCouchbaseBucket()
|
||||
.bucketManager()
|
||||
.getDesignDocument("foo");
|
||||
|
||||
assertNotNull(designDoc);
|
||||
boolean foundView = false;
|
||||
for (View view : designDoc.views()) {
|
||||
if (view.name().equals("all")) {
|
||||
foundView = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue("Expected to find view \"all\" on design document \"foo\"", foundView);
|
||||
|
||||
repository.save(foo1);
|
||||
repository.save(foo2);
|
||||
|
||||
int count = 0;
|
||||
for (Object o : repository.findAll(Arrays.asList("foo1", "foo2"))) {
|
||||
count++;
|
||||
}
|
||||
assertEquals(2L, count);
|
||||
count = 0;
|
||||
for (Object o : repository.findAll(Arrays.asList("foo1", "foo3"))) {
|
||||
count++;
|
||||
}
|
||||
assertEquals(1L, count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user