Search in sources :

Example 76 with LockedDocument

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

the class StoreResourceTest method checkAttributes.

private void checkAttributes(final XmldbURI docName, final String expectedOwner, final String expectedGroup, final int expectedMode, final Matcher<Long> expectedCreated, final Matcher<Long> expectedLastModified) throws EXistException, PermissionDeniedException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final LockedDocument lockedDoc = broker.getXMLResource(TEST_COLLECTION_URI.append(docName), Lock.LockMode.READ_LOCK)) {
        final DocumentImpl doc = lockedDoc.getDocument();
        final Permission permission = doc.getPermissions();
        assertEquals("Owner value was not expected", expectedOwner, permission.getOwner().getName());
        assertEquals("Group value was not expected", expectedGroup, permission.getGroup().getName());
        assertEquals("Mode value was not expected", expectedMode, permission.getMode());
        assertThat("Created value is not correct", doc.getCreated(), expectedCreated);
        assertThat("LastModified value is not correct", doc.getLastModified(), expectedLastModified);
    }
}
Also used : LockedDocument(org.exist.dom.persistent.LockedDocument) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 77 with LockedDocument

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

the class UpdateRecoverTest method read.

private void read(final BrokerPool pool) throws IllegalAccessException, DatabaseConfigurationException, InstantiationException, ClassNotFoundException, XMLDBException, EXistException, PermissionDeniedException, SAXException {
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_XML_URI), LockMode.READ_LOCK)) {
            assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test.xml' 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 78 with LockedDocument

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

the class AbstractJournalTest 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 file The file that was previously stored
 * @param dbFilename The name of the file to read from the database
 */
private void read(final boolean shouldExist, final Path file, 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 lockedDoc = broker.getXMLResource(uri, Lock.LockMode.READ_LOCK)) {
            if (!shouldExist) {
                assertNull("Document should not exist in the database: " + uri, lockedDoc);
            } else {
                assertNotNull("Document does not exist in the database: " + uri, lockedDoc);
                readAndVerify(broker, lockedDoc.getDocument(), file, dbFilename);
            }
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) BrokerPool(org.exist.storage.BrokerPool) XmldbURI(org.exist.xmldb.XmldbURI)

Example 79 with LockedDocument

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

the class MoveResourceRecoveryTest method readAborted.

private void readAborted() throws EXistException, PermissionDeniedException, SAXException, IOException, LockException {
    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.TEST_COLLECTION_URI2.append("new_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);
        }
        final TransactionManager transact = pool.getTransactionManager();
        try (final Txn transaction = transact.beginTransaction();
            final Collection root = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.WRITE_LOCK)) {
            assertNotNull(root);
            transaction.acquireCollectionLock(() -> broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(root.getURI()));
            broker.removeCollection(transaction, root);
            transact.commit(transaction);
        }
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) LockedDocument(org.exist.dom.persistent.LockedDocument) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) Serializer(org.exist.storage.serializers.Serializer)

Example 80 with LockedDocument

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

the class MoveResourceRecoveryTest method read.

private void read() throws EXistException, PermissionDeniedException, SAXException, IOException, LockException {
    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/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);
        }
        final TransactionManager transact = pool.getTransactionManager();
        try (final Txn transaction = transact.beginTransaction();
            final Collection root = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.WRITE_LOCK)) {
            assertNotNull(root);
            transaction.acquireCollectionLock(() -> broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(root.getURI()));
            broker.removeCollection(transaction, root);
            transact.commit(transaction);
        }
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) LockedDocument(org.exist.dom.persistent.LockedDocument) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) 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