use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class RangeIndexWorker method getAnalyzer.
/**
* Return the analyzer to be used for the given field or qname. Either field
* or qname should be specified.
*/
private Analyzer getAnalyzer(QName qname, String fieldName, DocumentSet docs) {
for (Iterator<Collection> i = docs.getCollectionIterator(); i.hasNext(); ) {
Collection collection = i.next();
IndexSpec idxConf = collection.getIndexConfiguration(broker);
if (idxConf != null) {
RangeIndexConfig config = (RangeIndexConfig) idxConf.getCustomIndexSpec(RangeIndex.ID);
if (config != null) {
Analyzer analyzer = config.getAnalyzer(qname, fieldName);
if (analyzer != null)
return analyzer;
}
}
}
return null;
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class AbstractGMLJDBCIndexWorker method removeCollection.
@Override
public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
boolean isCollectionGMLAware = false;
IndexSpec idxConf = collection.getIndexConfiguration(broker);
if (idxConf != null) {
Map collectionConfig = (Map) idxConf.getCustomIndexSpec(AbstractGMLJDBCIndex.ID);
isCollectionGMLAware = (collectionConfig != null);
}
if (!isCollectionGMLAware)
return;
Connection conn = null;
try {
conn = acquireConnection();
if (LOG.isDebugEnabled())
LOG.debug("Dropping GML index for collection {}", collection.getURI());
int nodeCount = removeCollection(collection, conn);
if (LOG.isDebugEnabled())
LOG.debug("Dropped {} nodes from GML index", nodeCount);
} catch (SQLException e) {
LOG.error(e);
} finally {
try {
if (conn != null)
releaseConnection(conn);
} catch (SQLException e) {
LOG.error(e);
}
}
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class CollectionConfiguration method read.
/**
* @param broker the database broker
* @param doc collection configuration document
* @param checkOnly true to only check
* @param srcCollectionURI The collection from which the document is being read. This
* is not necessarily the same as this.collection.getURI() because the
* source document may have come from a parent collection.
* @param docName The name of the document being read
*
* @throws CollectionConfigurationException if an error occurs whilst reading the collection configuration
*/
protected void read(final DBBroker broker, final Document doc, final boolean checkOnly, final XmldbURI srcCollectionURI, final XmldbURI docName) throws CollectionConfigurationException {
if (!checkOnly) {
this.docName = docName;
this.srcCollectionURI = srcCollectionURI;
}
final Element root = doc.getDocumentElement();
if (root == null) {
throwOrLog("Configuration document can not be parsed", checkOnly);
return;
}
if (!ROOT_ELEMENT.equals(root.getLocalName())) {
throwOrLog("Expected element '" + ROOT_ELEMENT + "' in configuration document. Got element '" + root.getLocalName() + "'", checkOnly);
return;
}
if (root.getNamespaceURI() == null || !NAMESPACE.equals(root.getNamespaceURI())) {
throwOrLog("Expected namespace '" + NAMESPACE + "' for element '" + PARAMETER_ELEMENT + "' in configuration document. Got '" + root.getNamespaceURI() + "'", checkOnly);
return;
}
final NodeList childNodes = root.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (NAMESPACE.equals(node.getNamespaceURI())) {
if (TRIGGERS_ELEMENT.equals(node.getLocalName())) {
final NodeList triggers = node.getChildNodes();
for (int j = 0; j < triggers.getLength(); j++) {
node = triggers.item(j);
if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals(TRIGGER_ELEMENT)) {
configureTrigger(broker.getBrokerPool().getClassLoader(), (Element) node, srcCollectionURI, checkOnly);
}
}
} else if (INDEX_ELEMENT.equals(node.getLocalName())) {
final Element elem = (Element) node;
try {
if (indexSpec == null) {
indexSpec = new IndexSpec(broker, elem);
} else {
indexSpec.read(broker, elem);
}
} catch (final DatabaseConfigurationException e) {
if (checkOnly) {
throw new CollectionConfigurationException(e.getMessage(), e);
} else {
LOG.warn(e.getMessage(), e);
}
}
} else if (VALIDATION_ELEMENT.equals(node.getLocalName())) {
final Element elem = (Element) node;
final String mode = elem.getAttribute(VALIDATION_MODE_ATTR);
if (mode == null) {
LOG.debug("Unable to determine validation mode in {}", srcCollectionURI);
validationMode = XMLReaderObjectFactory.VALIDATION_SETTING.UNKNOWN;
} else {
LOG.debug("{} : Validation mode={}", srcCollectionURI, mode);
validationMode = XMLReaderObjectFactory.VALIDATION_SETTING.fromOption(mode);
}
} else {
throwOrLog("Ignored node '" + node.getLocalName() + "' in configuration document", checkOnly);
// TODO : throw an exception like above ? -pb
}
} else if (node.getNodeType() == Node.ELEMENT_NODE) {
throwOrLog("Ignored node '" + node.getLocalName() + "' in namespace '" + node.getNamespaceURI() + "' in configuration document", checkOnly);
}
}
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class IndexKeys method getDefinedIndexes.
/**
* Check index configurations for all collection in the given DocumentSet and return
* a list of QNames, which have indexes defined on them.
*
* @param broker
* @param docs
*/
private QName[] getDefinedIndexes(DBBroker broker, DocumentSet docs) {
final Set<QName> indexes = new HashSet<>();
for (final Iterator<org.exist.collections.Collection> i = docs.getCollectionIterator(); i.hasNext(); ) {
final org.exist.collections.Collection collection = i.next();
final IndexSpec idxConf = collection.getIndexConfiguration(broker);
if (idxConf != null) {
final List<QName> qnames = idxConf.getIndexedQNames();
for (QName qname : qnames) {
final QName qName = (QName) qname;
indexes.add(qName);
}
}
}
final QName[] qnames = new QName[indexes.size()];
return indexes.toArray(qnames);
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class Configuration method configureIndexer.
private void configureIndexer(final Optional<Path> dbHome, Document doc, Element indexer) throws DatabaseConfigurationException, MalformedURLException {
final String caseSensitive = getConfigAttributeValue(indexer, NativeValueIndex.INDEX_CASE_SENSITIVE_ATTRIBUTE);
if (caseSensitive != null) {
config.put(NativeValueIndex.PROPERTY_INDEX_CASE_SENSITIVE, parseBoolean(caseSensitive, false));
LOG.debug(NativeValueIndex.PROPERTY_INDEX_CASE_SENSITIVE + ": {}", config.get(NativeValueIndex.PROPERTY_INDEX_CASE_SENSITIVE));
}
int depth = 3;
final String indexDepth = getConfigAttributeValue(indexer, NativeBroker.INDEX_DEPTH_ATTRIBUTE);
if (indexDepth != null) {
try {
depth = Integer.parseInt(indexDepth);
if (depth < 3) {
LOG.warn("parameter index-depth should be >= 3 or you will experience a severe " + "performance loss for node updates (XUpdate or XQuery update extensions)");
depth = 3;
}
config.put(NativeBroker.PROPERTY_INDEX_DEPTH, depth);
LOG.debug(NativeBroker.PROPERTY_INDEX_DEPTH + ": {}", config.get(NativeBroker.PROPERTY_INDEX_DEPTH));
} catch (final NumberFormatException e) {
LOG.warn(e);
}
}
final String suppressWS = getConfigAttributeValue(indexer, Indexer.SUPPRESS_WHITESPACE_ATTRIBUTE);
if (suppressWS != null) {
config.put(Indexer.PROPERTY_SUPPRESS_WHITESPACE, suppressWS);
LOG.debug(Indexer.PROPERTY_SUPPRESS_WHITESPACE + ": {}", config.get(Indexer.PROPERTY_SUPPRESS_WHITESPACE));
}
final String suppressWSmixed = getConfigAttributeValue(indexer, Indexer.PRESERVE_WS_MIXED_CONTENT_ATTRIBUTE);
if (suppressWSmixed != null) {
config.put(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT, parseBoolean(suppressWSmixed, false));
LOG.debug(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT + ": {}", config.get(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT));
}
// index settings
final NodeList cl = doc.getElementsByTagName(Indexer.CONFIGURATION_INDEX_ELEMENT_NAME);
if (cl.getLength() > 0) {
final Element elem = (Element) cl.item(0);
final IndexSpec spec = new IndexSpec(null, elem);
config.put(Indexer.PROPERTY_INDEXER_CONFIG, spec);
// LOG.debug(Indexer.PROPERTY_INDEXER_CONFIG + ": " + config.get(Indexer.PROPERTY_INDEXER_CONFIG));
}
// index modules
NodeList modules = indexer.getElementsByTagName(IndexManager.CONFIGURATION_ELEMENT_NAME);
if (modules.getLength() > 0) {
modules = ((Element) modules.item(0)).getElementsByTagName(IndexManager.CONFIGURATION_MODULE_ELEMENT_NAME);
final IndexModuleConfig[] modConfig = new IndexModuleConfig[modules.getLength()];
for (int i = 0; i < modules.getLength(); i++) {
final Element elem = (Element) modules.item(i);
final String className = elem.getAttribute(IndexManager.INDEXER_MODULES_CLASS_ATTRIBUTE);
final String id = elem.getAttribute(IndexManager.INDEXER_MODULES_ID_ATTRIBUTE);
if ((className == null) || (className.isEmpty())) {
throw (new DatabaseConfigurationException("Required attribute class is missing for module"));
}
if ((id == null) || (id.isEmpty())) {
throw (new DatabaseConfigurationException("Required attribute id is missing for module"));
}
modConfig[i] = new IndexModuleConfig(id, className, elem);
}
config.put(IndexManager.PROPERTY_INDEXER_MODULES, modConfig);
}
}
Aggregations