Search in sources :

Example 61 with LockedDocument

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

the class SourceFactoryTest method getSourceFromXmldb_noContext.

@Test
public void getSourceFromXmldb_noContext() throws IOException, PermissionDeniedException {
    final String contextPath = null;
    final String location = "xmldb:exist:///db/library.xqm";
    final DBBroker mockBroker = createMock(DBBroker.class);
    final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
    final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
    expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
    expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
    expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
    expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(location)).times(2);
    expect(mockBinDoc.getLastModified()).andReturn(123456789l);
    /*expect*/
    mockLockedDoc.close();
    replay(mockBroker, mockLockedDoc, mockBinDoc);
    final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
    assertTrue(libSource instanceof DBSource);
    assertEquals(XmldbURI.create(location), ((DBSource) libSource).getDocumentPath());
    verify(mockBroker, mockLockedDoc, mockBinDoc);
}
Also used : BinaryDocument(org.exist.dom.persistent.BinaryDocument) DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) Test(org.junit.Test)

Example 62 with LockedDocument

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

the class AbstractUpdateTest method read.

private void read(final BrokerPool pool) throws EXistException, PermissionDeniedException, SAXException, XPathException {
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Serializer serializer = broker.borrowSerializer();
        try (final LockedDocument lockedDoc = broker.getXMLResource(TEST_COLLECTION_URI.append("test2/test.xml"), LockMode.READ_LOCK)) {
            assertNotNull("Document '" + TEST_COLLECTION_URI.append("test2/test.xml") + "' should not be null", lockedDoc);
            final String data = serializer.serialize(lockedDoc.getDocument());
        } finally {
            broker.returnSerializer(serializer);
        }
        final XQuery xquery = pool.getXQueryService();
        final Sequence seq = xquery.execute(broker, "/products/product[last()]", null);
        for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
            Item next = i.nextItem();
        }
    }
}
Also used : Item(org.exist.xquery.value.Item) SequenceIterator(org.exist.xquery.value.SequenceIterator) XQuery(org.exist.xquery.XQuery) LockedDocument(org.exist.dom.persistent.LockedDocument) Sequence(org.exist.xquery.value.Sequence) Serializer(org.exist.storage.serializers.Serializer)

Example 63 with LockedDocument

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

the class SourceFactoryTest method getSourceFromXmldbEmbedded_noContext.

@Test
public void getSourceFromXmldbEmbedded_noContext() throws IOException, PermissionDeniedException {
    final String contextPath = null;
    final String location = "xmldb:exist://embedded-eXist-server/db/library.xqm";
    final DBBroker mockBroker = createMock(DBBroker.class);
    final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
    final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
    expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
    expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
    expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
    expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(location)).times(2);
    expect(mockBinDoc.getLastModified()).andReturn(123456789l);
    /*expect*/
    mockLockedDoc.close();
    replay(mockBroker, mockLockedDoc, mockBinDoc);
    final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
    assertTrue(libSource instanceof DBSource);
    assertEquals(XmldbURI.create(location), ((DBSource) libSource).getDocumentPath());
    verify(mockBroker, mockLockedDoc, mockBinDoc);
}
Also used : BinaryDocument(org.exist.dom.persistent.BinaryDocument) DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) Test(org.junit.Test)

Example 64 with LockedDocument

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

the class SourceFactoryTest method getSourceFromDb.

@Test
public void getSourceFromDb() throws IOException, PermissionDeniedException {
    final String contextPath = "/db";
    final String location = "library.xqm";
    final DBBroker mockBroker = createMock(DBBroker.class);
    final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
    final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
    expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
    expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
    expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
    expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(contextPath).append(location)).times(2);
    expect(mockBinDoc.getLastModified()).andReturn(123456789l);
    /*expect*/
    mockLockedDoc.close();
    replay(mockBroker, mockLockedDoc, mockBinDoc);
    final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
    assertTrue(libSource instanceof DBSource);
    assertEquals(XmldbURI.create(contextPath).append(location), ((DBSource) libSource).getDocumentPath());
    verify(mockBroker, mockLockedDoc, mockBinDoc);
}
Also used : BinaryDocument(org.exist.dom.persistent.BinaryDocument) DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) Test(org.junit.Test)

Example 65 with LockedDocument

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

the class SourceFactoryTest method getSourceFromXmldbEmbedded.

@Test
public void getSourceFromXmldbEmbedded() throws IOException, PermissionDeniedException {
    final String contextPath = "xmldb:exist://embedded-eXist-server/db";
    final String location = "library.xqm";
    final DBBroker mockBroker = createMock(DBBroker.class);
    final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
    final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
    expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
    expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
    expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
    expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(contextPath).append(location)).times(2);
    expect(mockBinDoc.getLastModified()).andReturn(123456789l);
    /*expect*/
    mockLockedDoc.close();
    replay(mockBroker, mockLockedDoc, mockBinDoc);
    final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
    assertTrue(libSource instanceof DBSource);
    assertEquals(XmldbURI.create(contextPath).append(location), ((DBSource) libSource).getDocumentPath());
    verify(mockBroker, mockLockedDoc, mockBinDoc);
}
Also used : BinaryDocument(org.exist.dom.persistent.BinaryDocument) DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) Test(org.junit.Test)

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