Search in sources :

Example 56 with LockedDocument

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

the class InstallFunction method getBinaryDoc.

private LockedDocument getBinaryDoc(final String path) throws XPathException {
    try {
        final XmldbURI uri = XmldbURI.createInternal(path);
        final LockedDocument lockedDoc = context.getBroker().getXMLResource(uri, LockMode.READ_LOCK);
        if (lockedDoc == null) {
            throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not .xar resource", new StringValue(path));
        } else if (lockedDoc.getDocument().getResourceType() != DocumentImpl.BINARY_FILE) {
            lockedDoc.close();
            throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not a valid .xar, it's not a binary resource", new StringValue(path));
        }
        return lockedDoc;
    } catch (PermissionDeniedException e) {
        throw new XPathException(this, EXPathErrorCode.EXPDY003, e.getMessage(), new StringValue(path), e);
    }
}
Also used : XPathException(org.exist.xquery.XPathException) LockedDocument(org.exist.dom.persistent.LockedDocument) PermissionDeniedException(org.exist.security.PermissionDeniedException) StringValue(org.exist.xquery.value.StringValue) XmldbURI(org.exist.xmldb.XmldbURI)

Example 57 with LockedDocument

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

the class MoveCollectionRecoveryTest method read.

private void read() throws EXistException, PermissionDeniedException, SAXException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(TestConstants.DESTINATION_COLLECTION_URI.append("test3").append(TestConstants.TEST_XML_URI), LockMode.READ_LOCK)) {
            assertNotNull("Document should not be null", lockedDoc);
            String data = serializer.serialize(lockedDoc.getDocument());
            assertNotNull(data);
        } finally {
            broker.returnSerializer(serializer);
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) Serializer(org.exist.storage.serializers.Serializer)

Example 58 with LockedDocument

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

the class CopyCollectionRecoveryTest method read.

private void read() throws EXistException, PermissionDeniedException, SAXException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("destination/test3/test.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document should not be null", lockedDoc);
            serializer.serialize(lockedDoc.getDocument());
        } finally {
            broker.returnSerializer(serializer);
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) Serializer(org.exist.storage.serializers.Serializer)

Example 59 with LockedDocument

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

the class CopyResourceRecoveryTest method read.

private void read(final String testCollectionName) throws EXistException, PermissionDeniedException, SAXException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append("new_test.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document should not be null", lockedDoc);
            final String data = serializer.serialize(lockedDoc.getDocument());
            assertNotNull(data);
        } finally {
            broker.returnSerializer(serializer);
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) Serializer(org.exist.storage.serializers.Serializer)

Example 60 with LockedDocument

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

the class CopyResourceRecoveryTest method readAborted.

private void readAborted(final String testCollectionName, final String subCollection) throws EXistException, PermissionDeniedException, SAXException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append(subCollection).append("test2.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document should not be null", lockedDoc);
            final String data = serializer.serialize(lockedDoc.getDocument());
            assertNotNull(data);
        } finally {
            broker.returnSerializer(serializer);
        }
        try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append("new_test2.xml"), LockMode.READ_LOCK)) {
            assertNull("Document should not exist as copy was not committed", lockedDoc);
        }
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) Serializer(org.exist.storage.serializers.Serializer)

Aggregations

LockedDocument (org.exist.dom.persistent.LockedDocument)91 DocumentImpl (org.exist.dom.persistent.DocumentImpl)40 XmldbURI (org.exist.xmldb.XmldbURI)39 DBBroker (org.exist.storage.DBBroker)36 PermissionDeniedException (org.exist.security.PermissionDeniedException)30 Collection (org.exist.collections.Collection)28 Txn (org.exist.storage.txn.Txn)27 BrokerPool (org.exist.storage.BrokerPool)21 EXistException (org.exist.EXistException)20 Test (org.junit.Test)20 IOException (java.io.IOException)18 BinaryDocument (org.exist.dom.persistent.BinaryDocument)18 Serializer (org.exist.storage.serializers.Serializer)15 XPathException (org.exist.xquery.XPathException)14 URISyntaxException (java.net.URISyntaxException)13 InputStream (java.io.InputStream)11 LockException (org.exist.util.LockException)11 Tuple2 (com.evolvedbinary.j8fu.tuple.Tuple2)9 Lock (org.exist.storage.lock.Lock)9 TransactionManager (org.exist.storage.txn.TransactionManager)9