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

@@ -249,15 +249,18 @@ public abstract class AbstractCouchbaseConfiguration {
/**
* Register an {@link IndexManager} bean that will be used to process {@link ViewIndexed},
* {@link N1qlPrimaryIndexed} and {@link N1qlSecondaryIndexed} annotations on repositories
* to automatically create indexes.
* to automatically create indexes. By default, since such automatic creations are discouraged in
* production envrironment, the configuration will assume the worst and will ignore these annotations.
* <p/>
* If this configuration is used in a context where such automatic creations are not desired (eg.
* you want automatic index creation in Dev but not in Prod, and this configuration is the Prod one),
* override the bean and use the {@link IndexManager#IndexManager(boolean, boolean, boolean)} constructor.
* If you are sure this configuration used in a context where such automatic creations are desired (eg.
* you want automatic index creation in Dev, just not in Prod, and this configuration is the Dev one),
* override the bean and use the {@link IndexManager#IndexManager()} constructor (or
* {@link IndexManager#IndexManager(boolean, boolean, boolean)} constructor with appropriate flags set to true to
* activate).
*/
@Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER)
public IndexManager indexManager() {
return new IndexManager();
return new IndexManager(false, false, false); //this ignores view, N1QL primary and secondary annotations
}
/**

View File

@@ -65,13 +65,14 @@ public class CouchbaseIndexManagerParser extends AbstractSingleBeanDefinitionPar
*/
@Override
protected void doParse(final Element element, final BeanDefinitionBuilder bean) {
boolean ignoreViews = Boolean.parseBoolean(element.getAttribute("ignoreViews"));
boolean ignorePrimary = Boolean.parseBoolean(element.getAttribute("ignorePrimary"));
boolean ignoreSecondary = Boolean.parseBoolean(element.getAttribute("ignoreSecondary"));
//the following values default to false, so you must opt-in by providing them
boolean processViews = Boolean.parseBoolean(element.getAttribute("processViews"));
boolean processPrimary = Boolean.parseBoolean(element.getAttribute("processPrimary"));
boolean processSecondary = Boolean.parseBoolean(element.getAttribute("processSecondary"));
bean.addConstructorArgValue(ignoreViews);
bean.addConstructorArgValue(ignorePrimary);
bean.addConstructorArgValue(ignoreSecondary);
bean.addConstructorArgValue(processViews);
bean.addConstructorArgValue(processPrimary);
bean.addConstructorArgValue(processSecondary);
}
}

View File

@@ -70,24 +70,24 @@ public class IndexManager {
/**
* Construct an IndexManager that can be used as a Bean in a {@link Profile @Profile} annotated configuration
* in order to ignore all or part of automatic index creations in some contexts (like activating it in Dev but
* in order to activate only all or part of automatic index creations in some contexts (like activating it in Dev but
* not in Prod).
*
* @param ignoreViews true to ignore {@link ViewIndexed} annotations.
* @param ignoreN1qlPrimary true to ignore {@link N1qlPrimaryIndexed} annotations.
* @param ignoreN1qlSecondary true to ignore {@link N1qlSecondaryIndexed} annotations.
* @param processViews true to process, false to ignore {@link ViewIndexed} annotations.
* @param processN1qlPrimary true to process, false to ignore {@link N1qlPrimaryIndexed} annotations.
* @param processN1qlSecondary true to process, false to ignore {@link N1qlSecondaryIndexed} annotations.
*/
public IndexManager(boolean ignoreViews, boolean ignoreN1qlPrimary, boolean ignoreN1qlSecondary) {
this.ignoreViews = ignoreViews;
this.ignoreN1qlPrimary = ignoreN1qlPrimary;
this.ignoreN1qlSecondary = ignoreN1qlSecondary;
public IndexManager(boolean processViews, boolean processN1qlPrimary, boolean processN1qlSecondary) {
this.ignoreViews = !processViews;
this.ignoreN1qlPrimary = !processN1qlPrimary;
this.ignoreN1qlSecondary = !processN1qlSecondary;
}
/**
* Construct a default IndexManager that process all three types of automatic index creations.
*/
public IndexManager() {
this(false, false, false);
this(true, true, true);
}
/**