Search in sources :

Example 76 with XmldbURI

use of org.exist.xmldb.XmldbURI in project exist by eXist-db.

the class AbstractRecoverTest method read.

/**
 * Read a document from the database.
 *
 * @param shouldExist true if the document should exist in the database, false if the document should not exist
 * @param data The data that was previously stored
 * @param dbFilename The name of the file to read from the database
 */
protected void read(final boolean shouldExist, final InputSource data, final String dbFilename) throws EXistException, PermissionDeniedException, IOException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final XmldbURI uri = TestConstants.TEST_COLLECTION_URI.append(dbFilename);
        try (final LockedDocument doc = broker.getXMLResource(uri, LockMode.READ_LOCK)) {
            if (!shouldExist) {
                assertNull("Document should not exist in the database: " + uri, doc);
            } else {
                assertNotNull("Document does not exist in the database: " + uri, doc);
                readAndVerify(broker, doc.getDocument(), data, dbFilename);
            }
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) XmldbURI(org.exist.xmldb.XmldbURI)

Example 77 with XmldbURI

use of org.exist.xmldb.XmldbURI in project exist by eXist-db.

the class IndexIntegrationTest method removeAttribute.

@Test
public void removeAttribute() throws Exception {
    final String docName = "pathNs2.xml";
    final XmldbURI docUri = XmldbURI.create("/db/test/" + docName);
    run(docUri, "<test><t xml:id=\"id2\"/></test>", (worker, stream) -> {
        // get top reindex node
        expect(worker.getReindexRoot(anyObject(), anyObject(), anyBoolean(), anyBoolean())).andStubReturn(null);
        // REMOVE STAGE
        // set document
        worker.setDocument(eqDocument(docUri));
        expectLastCall();
        // set mode
        worker.setMode(StreamListener.ReindexMode.REMOVE_SOME_NODES);
        expectLastCall();
        // get stream listener
        worker.setDocument(eqDocument(docUri));
        expectLastCall();
        worker.setMode(StreamListener.ReindexMode.REMOVE_SOME_NODES);
        expectLastCall();
        // setup chain
        // stream
        stream.startIndexDocument(anyObject());
        expectLastCall();
        stream.attribute(anyObject(), eqAttr("xml:id", "id2"), anyObject());
        expectLastCall();
        stream.endIndexDocument(anyObject());
        expectLastCall();
        worker.flush();
        expectLastCall();
        // flush
        worker.flush();
        expectLastCall();
    }, service -> queryResource(service, docName, "update delete //t/@xml:id", 0));
}
Also used : XmldbURI(org.exist.xmldb.XmldbURI) Test(org.junit.Test)

Example 78 with XmldbURI

use of org.exist.xmldb.XmldbURI in project exist by eXist-db.

the class IndexIntegrationTest method insertElement.

@Test
public void insertElement() throws Exception {
    final String docName = "pathNs2.xml";
    final XmldbURI docUri = XmldbURI.create("/db/test/" + docName);
    run(docUri, "<test/>", (worker, stream) -> {
        // set document
        worker.setDocument(eqDocument(docUri));
        expectLastCall();
        // get top reindex node
        expect(worker.getReindexRoot(anyObject(), anyObject(), anyBoolean(), anyBoolean())).andStubReturn(null);
        // set mode
        worker.setMode(StreamListener.ReindexMode.STORE);
        expectLastCall();
        // get stream listener
        // setup chain
        // stream
        stream.startIndexDocument(anyObject());
        expectLastCall();
        stream.startElement(anyObject(), anyObject(), anyObject());
        expectLastCall();
        stream.attribute(anyObject(), anyObject(), anyObject());
        expectLastCall();
        stream.endElement(anyObject(), anyObject(), anyObject());
        expectLastCall();
        stream.endIndexDocument(anyObject());
        expectLastCall();
        // flush
        worker.flush();
        expectLastCall();
    }, service -> queryResource(service, docName, "update insert <t xml:id=\"id1\"/> into /test", 0));
}
Also used : XmldbURI(org.exist.xmldb.XmldbURI) Test(org.junit.Test)

Example 79 with XmldbURI

use of org.exist.xmldb.XmldbURI in project exist by eXist-db.

the class ExistXqueryRegistry method deregisterServices.

public void deregisterServices(final DBBroker broker, final XmldbURI xqueryLocation) {
    getRegistry(broker).deregister(xqueryLocation.getURI());
    // find and remove services from modules that depend on this one
    for (final String dependant : getDependants(xqueryLocation)) {
        try {
            // on the maps.
            if (dependant != null) {
                getRegistry(broker).deregister(new URI(dependant));
                // record the now missing dependency
                recordMissingDependency(xqueryLocation.toString(), XmldbURI.create(dependant));
            }
        } catch (final URISyntaxException e) {
            LOG.error(e.getMessage(), e);
        }
    }
/*
         * update the missingDependencies??
         * Probably not needed as this will be done in find services
         */
}
Also used : URISyntaxException(java.net.URISyntaxException) XmldbURI(org.exist.xmldb.XmldbURI) URI(java.net.URI)

Example 80 with XmldbURI

use of org.exist.xmldb.XmldbURI in project exist by eXist-db.

the class MetadataFunctions method extractMetadataFromLocalResource.

private Sequence extractMetadataFromLocalResource(final XmldbURI docUri) throws XPathException {
    try (final LockedDocument lockedDoc = context.getBroker().getXMLResource(docUri, LockMode.READ_LOCK)) {
        if (lockedDoc != null && lockedDoc.getDocument() instanceof BinaryDocument) {
            final BinaryDocument binDoc = (BinaryDocument) lockedDoc.getDocument();
            final BrokerPool pool = context.getBroker().getBrokerPool();
            final BlobStore blobStore = pool.getBlobStore();
            try (final Txn transaction = pool.getTransactionManager().beginTransaction()) {
                final Sequence result = blobStore.with(transaction, binDoc.getBlobId(), blobFile -> TaggedTryUnchecked(XPathException.class, () -> exifToolExtract(blobFile))).get();
                transaction.commit();
                return result;
            }
        } else {
            throw new XPathException(this, "The binary document at " + docUri.toString() + " cannot be found.");
        }
    } catch (PermissionDeniedException | IOException | TransactionException e) {
        throw new XPathException(this, "Could not access binary document: " + e.getMessage(), e);
    }
}
Also used : BinaryDocument(org.exist.dom.persistent.BinaryDocument) LockMode(org.exist.storage.lock.Lock.LockMode) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) SequenceType(org.exist.xquery.value.SequenceType) FunctionParameterSequenceType(org.exist.xquery.value.FunctionParameterSequenceType) QName(org.exist.dom.QName) URISyntaxException(java.net.URISyntaxException) FunctionSignature(org.exist.xquery.FunctionSignature) PermissionDeniedException(org.exist.security.PermissionDeniedException) Cardinality(org.exist.xquery.Cardinality) BlobStore(org.exist.storage.blob.BlobStore) BasicFunction(org.exist.xquery.BasicFunction) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream) Source(org.exist.source.Source) FunctionReturnSequenceType(org.exist.xquery.value.FunctionReturnSequenceType) XmldbURI(org.exist.xmldb.XmldbURI) URI(java.net.URI) Path(java.nio.file.Path) XQueryContext(org.exist.xquery.XQueryContext) OutputStream(java.io.OutputStream) InputSource(org.xml.sax.InputSource) LockedDocument(org.exist.dom.persistent.LockedDocument) Type(org.exist.xquery.value.Type) IOException(java.io.IOException) TransactionException(org.exist.storage.txn.TransactionException) Logger(org.apache.logging.log4j.Logger) TaggedTryUnchecked(com.evolvedbinary.j8fu.Try.TaggedTryUnchecked) ModuleUtils(org.exist.xquery.modules.ModuleUtils) SAXException(org.xml.sax.SAXException) SourceFactory(org.exist.source.SourceFactory) Sequence(org.exist.xquery.value.Sequence) LogManager(org.apache.logging.log4j.LogManager) BinaryDocument(org.exist.dom.persistent.BinaryDocument) XPathException(org.exist.xquery.XPathException) InputStream(java.io.InputStream) TransactionException(org.exist.storage.txn.TransactionException) XPathException(org.exist.xquery.XPathException) LockedDocument(org.exist.dom.persistent.LockedDocument) PermissionDeniedException(org.exist.security.PermissionDeniedException) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) IOException(java.io.IOException) BrokerPool(org.exist.storage.BrokerPool) BlobStore(org.exist.storage.blob.BlobStore)

Aggregations

XmldbURI (org.exist.xmldb.XmldbURI)260 Collection (org.exist.collections.Collection)100 PermissionDeniedException (org.exist.security.PermissionDeniedException)69 Test (org.junit.Test)56 Txn (org.exist.storage.txn.Txn)55 EXistException (org.exist.EXistException)42 URISyntaxException (java.net.URISyntaxException)39 LockedDocument (org.exist.dom.persistent.LockedDocument)39 IOException (java.io.IOException)38 DBBroker (org.exist.storage.DBBroker)38 DocumentImpl (org.exist.dom.persistent.DocumentImpl)34 SAXException (org.xml.sax.SAXException)33 Permission (org.exist.security.Permission)30 LockException (org.exist.util.LockException)27 Path (java.nio.file.Path)22 XPathException (org.exist.xquery.XPathException)22 BrokerPool (org.exist.storage.BrokerPool)21 TransactionManager (org.exist.storage.txn.TransactionManager)20 Subject (org.exist.security.Subject)19 StringInputSource (org.exist.util.StringInputSource)17