Created
June 5, 2015 18:48
-
-
Save stillalex/7b845a61d83ef86c3a34 to your computer and use it in GitHub Desktop.
RepositoryInitializer for disabling a given index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.google.common.collect.Sets.newHashSet; | |
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME; | |
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; | |
import java.util.Set; | |
import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer; | |
import org.apache.jackrabbit.oak.spi.state.NodeBuilder; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class CustomIndexInitializer implements RepositoryInitializer { | |
private final Logger log = LoggerFactory.getLogger(getClass()); | |
public void initialize(NodeBuilder builder) { | |
log.info("Custom initializer invoked"); | |
if (builder.hasChildNode(INDEX_DEFINITIONS_NAME)) { | |
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); | |
Set<String> disabled = newHashSet("index-node-name"); | |
for (String i : disabled) { | |
log.info("disabling {}", i); | |
disableIndex(index, i); | |
} | |
} | |
} | |
private static void disableIndex(NodeBuilder index, String indexName) { | |
if (index.hasChildNode(indexName)) { | |
index.child(indexName).setProperty(TYPE_PROPERTY_NAME, "disabled"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment