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