Search in sources :

Example 56 with Collection

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

the class RecoveryTest2 method store.

@Test
public void store() throws DatabaseConfigurationException, EXistException, PermissionDeniedException, IOException, SAXException, BTreeException, LockException {
    BrokerPool.FORCE_CORRUPTION = true;
    final BrokerPool pool = startDb();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.saveCollection(transaction, root);
        Collection test2 = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
        assertNotNull(test2);
        broker.saveCollection(transaction, test2);
        DOMFile domDb = ((NativeBroker) broker).getDOMFile();
        assertNotNull(domDb);
        try (final Writer writer = new StringWriter()) {
            domDb.dump(writer);
        }
        // store some documents. Will be replaced below
        final Path dir = Paths.get(xmlDir);
        final List<Path> docs = FileUtils.list(dir);
        for (final Path f : docs) {
            broker.storeDocument(transaction, XmldbURI.create(FileUtils.fileName(f)), new InputSource(f.toUri().toASCIIString()), MimeType.XML_TYPE, test2);
        }
        transact.commit(transaction);
    }
}
Also used : Path(java.nio.file.Path) InputSource(org.xml.sax.InputSource) StringWriter(java.io.StringWriter) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) DOMFile(org.exist.storage.dom.DOMFile) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 57 with Collection

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

the class ReindexRecoveryTest method restart.

/**
 * Just recover.
 */
private void restart() throws EXistException, PermissionDeniedException, IOException, DatabaseConfigurationException {
    BrokerPool.FORCE_CORRUPTION = false;
    final BrokerPool pool = startDb();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Collection root = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.READ_LOCK)) {
        assertNull("Removed collection does still exist", root);
    }
}
Also used : Collection(org.exist.collections.Collection)

Example 58 with Collection

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

the class RemoveCollectionTest method storeDocs.

private Collection storeDocs(final DBBroker broker, final TransactionManager transact) throws PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, LockException, EXistException {
    Collection test;
    try (final Txn transaction = transact.beginTransaction()) {
        test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        transact.commit(transaction);
    }
    try (final Txn transaction = transact.beginTransaction()) {
        final TestDataGenerator generator = new TestDataGenerator("xdb", COUNT);
        final Path[] files = generator.generate(broker, test, generateXQ);
        for (final Path file : files) {
            final InputSource is = new InputSource(file.toUri().toASCIIString());
            broker.storeDocument(transaction, XmldbURI.create(file.getFileName().toString()), is, MimeType.XML_TYPE, test);
        }
        generator.releaseAll();
        transact.commit(transaction);
    }
    return test;
}
Also used : Path(java.nio.file.Path) InputSource(org.xml.sax.InputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) TestDataGenerator(org.exist.TestDataGenerator)

Example 59 with Collection

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

the class RemoveCollectionTest method removeResources.

public void removeResources(final BrokerPool pool) throws PermissionDeniedException, IOException, SAXException, EXistException, LockException, CollectionConfigurationException, DatabaseConfigurationException {
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Collection test = storeDocs(broker, transact);
        try (final Txn transaction = transact.beginTransaction()) {
            for (final Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext(); ) {
                final DocumentImpl doc = i.next();
                broker.removeXMLResource(transaction, doc);
            }
            broker.saveCollection(transaction, test);
            transact.commit(transaction);
        }
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 60 with Collection

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

the class ShutdownTest method storeAndShutdown.

public void storeAndShutdown() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException, XPathException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        Collection test;
        try (final Txn transaction = transact.beginTransaction()) {
            test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
            assertNotNull(test);
            broker.saveCollection(transaction, test);
            // store some documents.
            for (final String sampleName : SAMPLES.getShakespeareXmlSampleNames()) {
                broker.storeDocument(transaction, XmldbURI.create(sampleName), new InputStreamSupplierInputSource(() -> SAMPLES.getShakespeareSample(sampleName)), MimeType.XML_TYPE, test);
            }
            final XQuery xquery = pool.getXQueryService();
            assertNotNull(xquery);
            final Sequence result = xquery.execute(broker, "//SPEECH[contains(LINE, 'love')]", null);
            assertNotNull(result);
            assertEquals(187, result.getItemCount());
            transact.commit(transaction);
        }
        try (final Txn transaction = transact.beginTransaction()) {
            broker.removeCollection(transaction, test);
            transact.commit(transaction);
        }
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) XQuery(org.exist.xquery.XQuery) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence)

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