use of org.exist.collections.Collection in project exist by eXist-db.
the class CopyCollectionTest method copyCol.
private void copyCol(final Subject execAsUser, final DBBroker.PreserveType preserve, final XmldbURI srcColName, final XmldbURI destColName) throws EXistException, PermissionDeniedException, LockException, IOException, TriggerException {
final XmldbURI src = TEST_COLLECTION_URI.append(srcColName);
final XmldbURI dest = TEST_COLLECTION_URI.append(destColName);
final BrokerPool pool = existWebServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(execAsUser));
final Txn transaction = pool.getTransactionManager().beginTransaction();
final Collection srcCol = broker.openCollection(src, LockMode.READ_LOCK);
final Collection destCol = broker.openCollection(dest.removeLastSegment(), LockMode.WRITE_LOCK)) {
broker.copyCollection(transaction, srcCol, destCol, dest.lastSegment(), preserve);
transaction.commit();
}
// basic shallow check that copy of the collection is the same as the original
try (final DBBroker broker = pool.get(Optional.of(execAsUser));
final Collection original = broker.openCollection(src, LockMode.READ_LOCK);
final Collection copy = broker.openCollection(dest, LockMode.READ_LOCK)) {
assertEquals(original.getDocumentCount(broker), copy.getDocumentCount(broker));
assertEquals(original.getChildCollectionCount(broker), copy.getChildCollectionCount(broker));
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class MoveCollectionRecoveryTest method store.
private void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
final Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
assertNotNull(test);
broker.saveCollection(transaction, test);
final String sample;
try (final InputStream is = SAMPLES.getBiblioSample()) {
assertNotNull(is);
sample = InputStreamUtil.readString(is, UTF_8);
}
broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource(sample), MimeType.XML_TYPE, test);
final Collection dest = broker.getOrCreateCollection(transaction, TestConstants.DESTINATION_COLLECTION_URI);
assertNotNull(dest);
broker.saveCollection(transaction, dest);
broker.moveCollection(transaction, test, dest, XmldbURI.create("test3"));
transact.commit(transaction);
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class MoveCollectionRecoveryTest method moveToSelfSubCollection.
@Test(expected = PermissionDeniedException.class)
public void moveToSelfSubCollection() throws EXistException, IOException, PermissionDeniedException, TriggerException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection src = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(src);
broker.saveCollection(transaction, src);
final Collection dst = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
assertNotNull(dst);
broker.saveCollection(transaction, dst);
broker.moveCollection(transaction, src, dst, src.getURI().lastSegment());
fail("expect PermissionDeniedException: Cannot move collection '/db/test' to it child collection '/db/test/test2'");
transact.commit(transaction);
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class MoveOverwriteCollectionTest method moveAndOverwriteCollection.
/**
* This test ensures that when moving an Collection over the top of an existing Collection,
* the overwritten resource is completely removed from the database;
* i.e. its nodes are no longer present in the structural index
*/
@Test
public void moveAndOverwriteCollection() throws Exception {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Tuple3<Collection, Collection, Collection> collections = store(broker);
try {
final DefaultDocumentSet docs = new DefaultDocumentSet();
docs.add(collections._1.getDocument(broker, doc1Name));
docs.add(collections._2.getDocument(broker, doc2Name));
docs.add(collections._3.getDocument(broker, doc3Name));
moveToRoot(broker, collections._3);
final Collection col = broker.getCollection(TEST_COLLECTION_URI);
docs.add(col.getDocument(broker, doc3Name));
checkIndex(broker, docs);
} finally {
collections._3.close();
collections._2.close();
collections._1.close();
}
}
}
use of org.exist.collections.Collection in project exist by eXist-db.
the class MarshallerTest method startDB.
@BeforeClass
public static void startDB() throws EXistException, DatabaseConfigurationException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection root = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
broker.saveCollection(transaction, root);
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(TEST_DOC), MimeType.XML_TYPE, root);
transact.commit(transaction);
}
}
Aggregations