Search in sources :

Example 61 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class SystemExportImportTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection test = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        final CollectionConfigurationManager mgr = pool.getConfigurationManager();
        mgr.addConfiguration(transaction, broker, test, COLLECTION_CONFIG);
        broker.storeDocument(transaction, doc01uri.lastSegment(), new StringInputSource(XML1), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc02uri.lastSegment(), new StringInputSource(XML2), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc03uri.lastSegment(), new StringInputSource(XML3), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc11uri.lastSegment(), new StringInputSource(BINARY.getBytes(UTF_8)), MimeType.BINARY_TYPE, test);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 62 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class CollectionOrderTest method assertOrderOfSubCollections.

private void assertOrderOfSubCollections(final BrokerPool pool, final List<String> subCollectionNames) throws EXistException, PermissionDeniedException, LockException {
    // iterate the collections ensuring they are in the same order as we created them
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        try (final Collection testCollection = broker.openCollection(TEST_COLLECTION, Lock.LockMode.READ_LOCK)) {
            final Iterator<XmldbURI> subCollections = testCollection.collectionIterator(broker);
            int idx = 0;
            while (subCollections.hasNext()) {
                final XmldbURI subCollection = subCollections.next();
                final String subCollectionName = subCollectionNames.get(idx++);
                assertEquals("sub-Collection names are not equal at index: " + idx, subCollectionName, subCollection.lastSegment().toString());
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Txn(org.exist.storage.txn.Txn) XmldbURI(org.exist.xmldb.XmldbURI)

Example 63 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class CollectionOrderTest method createTestCollection.

@Before
public void createTestCollection() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        broker.getOrCreateCollection(transaction, TEST_COLLECTION);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) Before(org.junit.Before)

Example 64 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class CollectionOrderTest method createDocuments.

private void createDocuments(final BrokerPool pool, final List<String> documentNames) throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    // create the documents
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        try (final Collection testCollection = broker.openCollection(TEST_COLLECTION, Lock.LockMode.WRITE_LOCK)) {
            for (final String documentName : documentNames) {
                final String xml = "<document id='" + UUID.randomUUID().toString() + "'><name>" + documentName + "</name></document>";
                broker.storeDocument(transaction, XmldbURI.create(documentName), new StringInputSource(xml), MimeType.XML_TYPE, testCollection);
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Txn(org.exist.storage.txn.Txn)

Example 65 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class CollectionStoreTest method store.

@Test
public void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        try (final Collection col = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI)) {
            broker.storeDocument(transaction, TEST_XML_DOC_URI, new StringInputSource(TEST_XML_DOC), MimeType.XML_TYPE, col);
            broker.saveCollection(transaction, col);
        }
        try (final Collection col = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.READ_LOCK)) {
            try (final LockedDocument lockedDoc = col.getDocumentWithLock(broker, TEST_XML_DOC_URI, LockMode.READ_LOCK)) {
                // NOTE: early release of collection lock inline with async locking
                col.close();
                if (lockedDoc != null) {
                    final Source expected = Input.fromString(TEST_XML_DOC).build();
                    final Source actual = Input.fromDocument(lockedDoc.getDocument()).build();
                    final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
                    assertFalse(diff.toString(), diff.hasDifferences());
                }
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Diff(org.xmlunit.diff.Diff) LockedDocument(org.exist.dom.persistent.LockedDocument) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) StringInputSource(org.exist.util.StringInputSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

DBBroker (org.exist.storage.DBBroker)468 BrokerPool (org.exist.storage.BrokerPool)304 Txn (org.exist.storage.txn.Txn)219 Sequence (org.exist.xquery.value.Sequence)185 Test (org.junit.Test)170 XQuery (org.exist.xquery.XQuery)108 Collection (org.exist.collections.Collection)93 TransactionManager (org.exist.storage.txn.TransactionManager)70 EXistException (org.exist.EXistException)66 StringInputSource (org.exist.util.StringInputSource)66 PermissionDeniedException (org.exist.security.PermissionDeniedException)44 Source (org.exist.source.Source)42 StringSource (org.exist.source.StringSource)41 XmldbURI (org.exist.xmldb.XmldbURI)41 CompiledXQuery (org.exist.xquery.CompiledXQuery)39 IOException (java.io.IOException)38 QName (org.exist.dom.QName)37 LockedDocument (org.exist.dom.persistent.LockedDocument)36 Database (org.exist.Database)35 XPathException (org.exist.xquery.XPathException)30