Search in sources :

Example 81 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class ConstructedNodesRecoveryTest method testTempChildCollectionExists.

private void testTempChildCollectionExists(DBBroker broker, TransactionManager transact, String childCollectionName) throws PermissionDeniedException, IOException, TriggerException, TransactionException {
    // create a transaction
    try (final Txn transaction = transact.beginTransaction()) {
        // get the temp child collection
        Collection tempChildCollection = broker.getOrCreateCollection(transaction, XmldbURI.TEMP_COLLECTION_URI.append(childCollectionName));
        assertNotNull(tempChildCollection);
        broker.saveCollection(transaction, tempChildCollection);
        transact.commit(transaction);
    }
}
Also used : Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn)

Example 82 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class ForwardReferenceTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool brokerPool = EXIST_EMBEDDED_SERVER.getBrokerPool();
    try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
        final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
        try (final Collection testCollection = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI)) {
            CONFIG_MODULE_URI = storeQuery(broker, transaction, CONFIG_MODULE, testCollection, CONFIG_MODULE_NAME);
            assertEquals(TEST_COLLECTION_URI.append(CONFIG_MODULE_NAME), CONFIG_MODULE_URI);
            PAGES_MODULE_URI = storeQuery(broker, transaction, PAGES_MODULE, testCollection, PAGES_MODULE_NAME);
            assertEquals(TEST_COLLECTION_URI.append(PAGES_MODULE_NAME), PAGES_MODULE_URI);
            TEST_PAGES_MODULE_URI = storeQuery(broker, transaction, TEST_PAGES_MODULE, testCollection, TEST_PAGES_MODULE_NAME);
            assertEquals(TEST_COLLECTION_URI.append(TEST_PAGES_MODULE_NAME), TEST_PAGES_MODULE_URI);
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) BeforeClass(org.junit.BeforeClass)

Example 83 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class ContentFunctionsTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, TriggerException, 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 collection = broker.getOrCreateCollection(transaction, XmldbURI.create("/db/content-functions-test"))) {
            try (final InputStream is = ContentFunctionsTest.class.getResourceAsStream("minimal.pdf")) {
                assertNotNull(is);
                collection.addBinaryResource(transaction, broker, XmldbURI.create("minimal.pdf"), is, "application/pdf", -1);
            }
            try (final InputStream is = ContentFunctionsTest.class.getResourceAsStream("test.xlsx")) {
                assertNotNull(is);
                collection.addBinaryResource(transaction, broker, XmldbURI.create("test.xlsx"), is, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", -1);
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) InputStream(java.io.InputStream) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 84 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class ValueSequenceTest method sortInDocumentOrder.

@Test
public void sortInDocumentOrder() throws EXistException, PermissionDeniedException, AuthenticationException {
    final ValueSequence seq = new ValueSequence(true);
    seq.keepUnOrdered(true);
    // in-memory doc
    final MemTreeBuilder memtree = new MemTreeBuilder();
    memtree.startDocument();
    memtree.startElement(new QName("m1", XMLConstants.NULL_NS_URI), null);
    memtree.startElement(new QName("m2", XMLConstants.NULL_NS_URI), null);
    memtree.characters("test data");
    memtree.endElement();
    memtree.endElement();
    memtree.endDocument();
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Subject admin = pool.getSecurityManager().authenticate("admin", "");
    try (final DBBroker broker = pool.get(Optional.of(admin))) {
        // persistent doc
        final Collection sysCollection = broker.getCollection(SecurityManager.SECURITY_COLLECTION_URI);
        final DocumentImpl doc = sysCollection.getDocument(broker, XmldbURI.create("config.xml"));
        final NodeProxy docProxy = new NodeProxy(doc);
        final NodeProxy nodeProxy = new NodeProxy(doc, ((NodeImpl) doc.getFirstChild()).getNodeId());
        seq.add(memtree.getDocument());
        seq.add(docProxy);
        seq.add((org.exist.dom.memtree.NodeImpl) memtree.getDocument().getFirstChild());
        seq.add(nodeProxy);
        // call sort
        seq.sortInDocumentOrder();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) QName(org.exist.dom.QName) Collection(org.exist.collections.Collection) DocumentImpl(org.exist.dom.persistent.DocumentImpl) NodeProxy(org.exist.dom.persistent.NodeProxy) BrokerPool(org.exist.storage.BrokerPool)

Example 85 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class Sync method handleCollection.

private List<XmldbURI> handleCollection(final XmldbURI collectionPath, final String rootTargetAbsPath, final Path targetDirectory, final Date startDate, final boolean prune, final List<String> excludes, final MemTreeBuilder output) throws PermissionDeniedException, LockException {
    try (final Collection collection = context.getBroker().openCollection(collectionPath, LockMode.READ_LOCK)) {
        if (collection == null) {
            reportError(output, "Collection not found: " + collectionPath);
            return Collections.emptyList();
        }
        if (prune) {
            pruneCollectionEntries(collection, rootTargetAbsPath, targetDirectory, excludes, output);
        }
        for (final Iterator<DocumentImpl> i = collection.iterator(context.getBroker()); i.hasNext(); ) {
            final DocumentImpl doc = i.next();
            final Path targetFile = targetDirectory.resolve(doc.getFileURI().toASCIIString());
            saveFile(targetFile, doc, startDate, output);
        }
        final List<XmldbURI> subCollections = new ArrayList<>(collection.getChildCollectionCount(context.getBroker()));
        for (final Iterator<XmldbURI> i = collection.collectionIterator(context.getBroker()); i.hasNext(); ) {
            subCollections.add(i.next());
        }
        return subCollections;
    }
}
Also used : Path(java.nio.file.Path) Collection(org.exist.collections.Collection) DocumentImpl(org.exist.dom.persistent.DocumentImpl) XmldbURI(org.exist.xmldb.XmldbURI)

Aggregations

Collection (org.exist.collections.Collection)297 Txn (org.exist.storage.txn.Txn)160 XmldbURI (org.exist.xmldb.XmldbURI)99 DBBroker (org.exist.storage.DBBroker)89 TransactionManager (org.exist.storage.txn.TransactionManager)86 BrokerPool (org.exist.storage.BrokerPool)69 StringInputSource (org.exist.util.StringInputSource)57 Test (org.junit.Test)57 EXistException (org.exist.EXistException)43 PermissionDeniedException (org.exist.security.PermissionDeniedException)43 DocumentImpl (org.exist.dom.persistent.DocumentImpl)42 IOException (java.io.IOException)33 LockedDocument (org.exist.dom.persistent.LockedDocument)31 SAXException (org.xml.sax.SAXException)26 InputStream (java.io.InputStream)19 Path (java.nio.file.Path)19 Permission (org.exist.security.Permission)19 LockException (org.exist.util.LockException)16 TriggerException (org.exist.collections.triggers.TriggerException)15 BinaryDocument (org.exist.dom.persistent.BinaryDocument)15