use of org.exist.storage.lock.ManagedCollectionLock in project exist by eXist-db.
the class PersistentDomTest method createCollection.
private static void createCollection(final DBBroker broker, final Txn transaction, final XmldbURI collectionUri, final Tuple2<XmldbURI, String>... docs) throws PermissionDeniedException, IOException, SAXException, LockException, EXistException {
try (final ManagedCollectionLock collectionLock = broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(collectionUri)) {
final Collection collection = broker.getOrCreateCollection(transaction, collectionUri);
broker.saveCollection(transaction, collection);
for (final Tuple2<XmldbURI, String> doc : docs) {
broker.storeDocument(transaction, doc._1, new StringInputSource(doc._2), MimeType.XML_TYPE, collection);
}
}
}
use of org.exist.storage.lock.ManagedCollectionLock in project exist by eXist-db.
the class EmbeddedBinariesTest method storeBinaryFile.
@Override
protected void storeBinaryFile(final XmldbURI filePath, final byte[] content) throws Exception {
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
try (final ManagedCollectionLock collectionLock = brokerPool.getLockManager().acquireCollectionWriteLock(filePath.removeLastSegment())) {
final Collection collection = broker.getOrCreateCollection(transaction, filePath.removeLastSegment());
broker.storeDocument(transaction, filePath.lastSegment(), new StringInputSource(content), MimeType.BINARY_TYPE, collection);
broker.saveCollection(transaction, collection);
}
transaction.commit();
}
}
use of org.exist.storage.lock.ManagedCollectionLock in project exist by eXist-db.
the class EmbeddedXMLStreamReaderTest method createCollection.
private static void createCollection(final DBBroker broker, final Txn transaction, final XmldbURI collectionUri, final Tuple2<XmldbURI, String>... docs) throws PermissionDeniedException, IOException, SAXException, LockException, EXistException {
try (final ManagedCollectionLock collectionLock = broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(collectionUri)) {
final Collection collection = broker.getOrCreateCollection(transaction, collectionUri);
broker.saveCollection(transaction, collection);
for (final Tuple2<XmldbURI, String> doc : docs) {
broker.storeDocument(transaction, doc._1, new StringInputSource(doc._2), MimeType.XML_TYPE, collection);
}
}
}
use of org.exist.storage.lock.ManagedCollectionLock in project exist by eXist-db.
the class TransformTest method createCollection.
@SafeVarargs
private static void createCollection(final DBBroker broker, final Txn transaction, final XmldbURI collectionUri, final Tuple2<XmldbURI, String>... docs) throws PermissionDeniedException, IOException, SAXException, LockException, EXistException {
try (final ManagedCollectionLock collectionLock = broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(collectionUri)) {
final Collection collection = broker.getOrCreateCollection(transaction, collectionUri);
broker.saveCollection(transaction, collection);
for (final Tuple2<XmldbURI, String> doc : docs) {
broker.storeDocument(transaction, doc._1, new StringInputSource(doc._2), MimeType.XML_TYPE, collection);
}
}
}
use of org.exist.storage.lock.ManagedCollectionLock in project exist by eXist-db.
the class PackageTriggerTest method setup.
@BeforeClass
public static void setup() throws PermissionDeniedException, SAXException, EXistException, IOException, LockException, XPathException {
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
// Create a collection to test the trigger in
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
final Collection collection = broker.getOrCreateCollection(transaction, triggerTestCollection);
broker.saveCollection(transaction, collection);
transaction.commit();
}
// Store XAR in database
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
try (final ManagedCollectionLock collectionLock = brokerPool.getLockManager().acquireCollectionWriteLock(xarUri.removeLastSegment())) {
final Collection collection = broker.getOrCreateCollection(transaction, xarUri.removeLastSegment());
broker.storeDocument(transaction, xarUri.lastSegment(), new InputStreamSupplierInputSource(() -> PackageTriggerTest.class.getResourceAsStream("/" + xarFile)), MimeType.EXPATH_PKG_TYPE, collection);
broker.saveCollection(transaction, collection);
}
transaction.commit();
}
// Install and deploy XAR
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = brokerPool.getXQueryService();
final Sequence result = xquery.execute(broker, "repo:install-and-deploy-from-db('/db/" + xarFile + "')", null);
Assert.assertEquals(1, result.getItemCount());
}
// Store collection.xconf in newly created collection under /db/system/config
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = brokerPool.getXQueryService();
final Sequence result = xquery.execute(broker, "xmldb:create-collection('/db/system/config/db','trigger-test'), " + "xmldb:store('/db/system/config/db/trigger-test', '" + DEFAULT_COLLECTION_CONFIG_FILE + "', " + "<collection xmlns=\"http://exist-db.org/collection-config/1.0\"><triggers><trigger class=\"org.exist.repo.ExampleTrigger\"/></triggers></collection>)", null);
Assert.assertEquals(2, result.getItemCount());
}
}
Aggregations