Search in sources :

Example 1 with MutableDocumentSet

use of org.exist.dom.persistent.MutableDocumentSet in project exist by eXist-db.

the class TestTrigger method addRecord.

private void addRecord(DBBroker broker, Txn transaction, String xupdate) throws TriggerException {
    MutableDocumentSet docs = new DefaultDocumentSet();
    docs.add(doc);
    final boolean triggersEnabled = broker.isTriggersEnabled();
    try {
        // IMPORTANT: temporarily disable triggers on the collection.
        // We would end up in infinite recursion if we don't do that
        broker.setTriggersEnabled(false);
        // create the XUpdate processor
        XUpdateProcessor processor = new XUpdateProcessor(broker, docs);
        // process the XUpdate
        Modification[] modifications = processor.parse(new InputSource(new StringReader(xupdate)));
        for (int i = 0; i < modifications.length; i++) {
            modifications[i].process(transaction);
        }
        broker.flush();
    } catch (Exception e) {
        throw new TriggerException(e.getMessage(), e);
    } finally {
        // IMPORTANT: reenable trigger processing for the collection.
        broker.setTriggersEnabled(triggersEnabled);
    }
}
Also used : XUpdateProcessor(org.exist.xupdate.XUpdateProcessor) MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) Modification(org.exist.xupdate.Modification) InputSource(org.xml.sax.InputSource) StringInputSource(org.exist.util.StringInputSource) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) StringReader(java.io.StringReader)

Example 2 with MutableDocumentSet

use of org.exist.dom.persistent.MutableDocumentSet in project exist by eXist-db.

the class SerializeAttrMatchesTest method configureAndStore.

private DocumentSet configureAndStore(final String configuration, final String data, final String docName) throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException {
    final MutableDocumentSet docs = new DefaultDocumentSet();
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        if (configuration != null) {
            final CollectionConfigurationManager mgr = pool.getConfigurationManager();
            mgr.addConfiguration(transaction, broker, test, configuration);
        }
        broker.storeDocument(transaction, XmldbURI.create(docName), new StringInputSource(data), MimeType.XML_TYPE, test);
        docs.add(test.getDocument(broker, XmldbURI.create(docName)));
        transact.commit(transaction);
    }
    return docs;
}
Also used : MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) TransactionManager(org.exist.storage.txn.TransactionManager) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 3 with MutableDocumentSet

use of org.exist.dom.persistent.MutableDocumentSet in project exist by eXist-db.

the class LuceneIndexTest method configureAndStore.

private DocumentSet configureAndStore(final String configuration, final String data, final String docName) throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException {
    final MutableDocumentSet docs = new DefaultDocumentSet();
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        if (configuration != null) {
            final CollectionConfigurationManager mgr = pool.getConfigurationManager();
            mgr.addConfiguration(transaction, broker, root, configuration);
        }
        broker.storeDocument(transaction, XmldbURI.create(docName), new StringInputSource(data), MimeType.XML_TYPE, root);
        docs.add(root.getDocument(broker, XmldbURI.create(docName)));
        transact.commit(transaction);
    }
    return docs;
}
Also used : MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) DBBroker(org.exist.storage.DBBroker) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) TransactionManager(org.exist.storage.txn.TransactionManager) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 4 with MutableDocumentSet

use of org.exist.dom.persistent.MutableDocumentSet in project exist by eXist-db.

the class LuceneIndexTest method configureAndStore.

private DocumentSet configureAndStore(String configuration, final String[] sampleNames) throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException {
    final MutableDocumentSet docs = new DefaultDocumentSet();
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        if (configuration != null) {
            final CollectionConfigurationManager mgr = pool.getConfigurationManager();
            mgr.addConfiguration(transaction, broker, root, configuration);
        }
        for (final String sampleName : sampleNames) {
            broker.storeDocument(transaction, XmldbURI.create(sampleName), new InputStreamSupplierInputSource(() -> SAMPLES.getShakespeareSample(sampleName)), MimeType.XML_TYPE, root);
            docs.add(root.getDocument(broker, XmldbURI.create(sampleName)));
        }
        transact.commit(transaction);
    }
    return docs;
}
Also used : MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) DBBroker(org.exist.storage.DBBroker) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) TransactionManager(org.exist.storage.txn.TransactionManager) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 5 with MutableDocumentSet

use of org.exist.dom.persistent.MutableDocumentSet in project exist by eXist-db.

the class FunDoctype method eval.

/* (non-Javadoc)
	 * @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
	 */
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().start(this);
        context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
        if (contextSequence != null) {
            context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
        }
        if (contextItem != null) {
            context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
        }
    }
    final MutableDocumentSet docs = new DefaultDocumentSet();
    for (int i = 0; i < getArgumentCount(); i++) {
        final Sequence seq = getArgument(i).eval(contextSequence, contextItem);
        for (final SequenceIterator j = seq.iterate(); j.hasNext(); ) {
            final String next = j.nextItem().getStringValue();
            try {
                context.getBroker().getXMLResourcesByDoctype(next, docs);
            } catch (final PermissionDeniedException | LockException e) {
                LOG.error(e.getMessage(), e);
                throw new XPathException(this, e);
            }
        }
    }
    final NodeSet result = new ExtArrayNodeSet(1);
    for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext(); ) {
        result.add(new NodeProxy(i.next(), NodeId.DOCUMENT_NODE));
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : ExtArrayNodeSet(org.exist.dom.persistent.ExtArrayNodeSet) NodeSet(org.exist.dom.persistent.NodeSet) MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) DocumentImpl(org.exist.dom.persistent.DocumentImpl) NodeProxy(org.exist.dom.persistent.NodeProxy) ExtArrayNodeSet(org.exist.dom.persistent.ExtArrayNodeSet) LockException(org.exist.util.LockException) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Aggregations

DefaultDocumentSet (org.exist.dom.persistent.DefaultDocumentSet)10 MutableDocumentSet (org.exist.dom.persistent.MutableDocumentSet)10 TransactionManager (org.exist.storage.txn.TransactionManager)5 DocumentImpl (org.exist.dom.persistent.DocumentImpl)4 Txn (org.exist.storage.txn.Txn)4 StringReader (java.io.StringReader)3 CollectionConfigurationManager (org.exist.collections.CollectionConfigurationManager)3 BrokerPool (org.exist.storage.BrokerPool)3 DBBroker (org.exist.storage.DBBroker)3 LockException (org.exist.util.LockException)3 StringInputSource (org.exist.util.StringInputSource)3 Modification (org.exist.xupdate.Modification)3 XUpdateProcessor (org.exist.xupdate.XUpdateProcessor)3 InputSource (org.xml.sax.InputSource)3 ExtArrayNodeSet (org.exist.dom.persistent.ExtArrayNodeSet)2 PermissionDeniedException (org.exist.security.PermissionDeniedException)2 Reader (java.io.Reader)1 URISyntaxException (java.net.URISyntaxException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 EXistException (org.exist.EXistException)1