DATACOUCH-199 - Make automatic index creation opt-in
In addition to annotating the repository with xxxIndexed annotations, user must now opt-in to the feature by redefining the indexManager bean in the configuration. This is so production use of this feature is actively discouraged.
This commit is contained in:
@@ -14,6 +14,7 @@ import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.core.WriteResultChecking;
|
||||
import org.springframework.data.couchbase.core.query.Consistency;
|
||||
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
|
||||
@Configuration
|
||||
public class IntegrationTestApplicationConfig extends AbstractCouchbaseConfiguration {
|
||||
@@ -66,6 +67,12 @@ public class IntegrationTestApplicationConfig extends AbstractCouchbaseConfigura
|
||||
return template;
|
||||
}
|
||||
|
||||
//this is for dev so it is ok to auto-create indexes
|
||||
@Override
|
||||
public IndexManager indexManager() {
|
||||
return new IndexManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Consistency getDefaultConsistency() {
|
||||
return Consistency.READ_YOUR_OWN_WRITES;
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.data.couchbase.repository.UserRepository;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
import org.springframework.data.couchbase.repository.extending.base.impl.MyRepository;
|
||||
import org.springframework.data.couchbase.repository.extending.base.impl.MyRepositoryImpl;
|
||||
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -104,6 +105,12 @@ public class RepositoryBaseTest {
|
||||
public CouchbaseOperations couchbaseOperations() {
|
||||
return mockOpsA;
|
||||
}
|
||||
|
||||
//this is for dev so it is ok to auto-create indexes
|
||||
@Override
|
||||
public IndexManager indexManager() {
|
||||
return new IndexManager();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.core.query.Consistency;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -68,6 +69,12 @@ public class RepositoryCustomMethodTest {
|
||||
return "";
|
||||
}
|
||||
|
||||
//this is for dev so it is ok to auto-create indexes
|
||||
@Override
|
||||
public IndexManager indexManager() {
|
||||
return new IndexManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Consistency getDefaultConsistency() {
|
||||
return Consistency.STRONGLY_CONSISTENT;
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.core.WriteResultChecking;
|
||||
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
|
||||
@Configuration
|
||||
public class FeatureDetectionTestApplicationConfig extends AbstractCouchbaseConfiguration {
|
||||
@@ -71,6 +72,12 @@ public class FeatureDetectionTestApplicationConfig extends AbstractCouchbaseConf
|
||||
return new DefaultClusterInfo(JsonObject.empty());
|
||||
}
|
||||
|
||||
//this is for dev so it is ok to auto-create indexes
|
||||
@Override
|
||||
public IndexManager indexManager() {
|
||||
return new IndexManager();
|
||||
}
|
||||
|
||||
//change the name of the field that will hold type information
|
||||
@Override
|
||||
public String typeKey() {
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
import org.springframework.data.couchbase.repository.User;
|
||||
|
||||
@N1qlSecondaryIndexed(indexName = IndexedRepositoryTests.IGNORED_SECONDARY)
|
||||
@ViewIndexed(designDoc = IndexedRepositoryTests.VIEW_DOC, viewName = IndexedRepositoryTests.IGNORED_VIEW_NAME)
|
||||
public interface AnotherIndexedUserRepository extends CouchbaseRepository<User, String> {
|
||||
|
||||
@ViewIndexed(designDoc = IndexedRepositoryTests.VIEW_DOC, viewName = IndexedRepositoryTests.IGNORED_VIEW_NAME)
|
||||
public List<User> findByAge(int age);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class IndexedRepositoryTests {
|
||||
private RepositoryFactorySupport factory;
|
||||
|
||||
private RepositoryFactorySupport ignoringIndexFactory;
|
||||
private IndexManager ignoringIndexManager = new IndexManager(true, true, true);
|
||||
private IndexManager ignoringIndexManager = new IndexManager(false, false, false);
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping;
|
||||
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -105,6 +106,12 @@ public class RepositoryTemplateWiringTests {
|
||||
return mockOpsC;
|
||||
}
|
||||
|
||||
//this is for dev so it is ok to auto-create indexes
|
||||
@Override
|
||||
public IndexManager indexManager() {
|
||||
return new IndexManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureRepositoryOperationsMapping(RepositoryOperationsMapping base) {
|
||||
base.setDefault(templateC())
|
||||
|
||||
Reference in New Issue
Block a user