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:
Simon Baslé
2016-02-05 17:57:26 +01:00
parent 6d747e97f5
commit 0095313342
13 changed files with 95 additions and 29 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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())