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);
}
}
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);
}
}
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;
}
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);
}
}
}
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);
}
}
}
Aggregations