Search in sources :

Example 1 with CollectionExistsException

use of org.exist.webdav.exceptions.CollectionExistsException in project exist by eXist-db.

the class ExistCollection method createCollection.

public XmldbURI createCollection(String name) throws PermissionDeniedException, CollectionExistsException, EXistException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Create  '{}' in '{}'", name, xmldbUri);
    }
    XmldbURI newCollection = xmldbUri.append(name);
    final TransactionManager txnManager = brokerPool.getTransactionManager();
    try (final DBBroker broker = brokerPool.get(Optional.ofNullable(subject));
        final Txn txn = txnManager.beginTransaction();
        final Collection collection = broker.openCollection(newCollection, LockMode.WRITE_LOCK)) {
        if (collection != null) {
            final String msg = "Collection already exists";
            LOG.debug(msg);
            // XXX: double "abort" is bad thing!!!
            txnManager.abort(txn);
            throw new CollectionExistsException(msg);
        }
        // Create collection
        try (final Collection created = broker.getOrCreateCollection(txn, newCollection)) {
            broker.saveCollection(txn, created);
            broker.flush();
            // Commit change
            txnManager.commit(txn);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Collection created sucessfully");
            }
        }
    } catch (EXistException | PermissionDeniedException e) {
        LOG.error(e);
        throw e;
    } catch (Throwable e) {
        LOG.error(e);
        throw new EXistException(e);
    } finally {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Finished creation");
        }
    }
    return newCollection;
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) PermissionDeniedException(org.exist.security.PermissionDeniedException) Txn(org.exist.storage.txn.Txn) EXistException(org.exist.EXistException) XmldbURI(org.exist.xmldb.XmldbURI) CollectionExistsException(org.exist.webdav.exceptions.CollectionExistsException)

Example 2 with CollectionExistsException

use of org.exist.webdav.exceptions.CollectionExistsException in project exist by eXist-db.

the class MiltonCollection method createCollection.

/* ==========================
     * MakeCollectionableResource
     * ========================== */
@Override
public CollectionResource createCollection(String name) throws NotAuthorizedException, ConflictException {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Create collection '{}' in '{}'.", name, resourceXmldbUri);
    }
    CollectionResource collection = null;
    try {
        XmldbURI collectionURI = existCollection.createCollection(name);
        collection = new MiltonCollection(host, collectionURI, brokerPool, subject);
    } catch (PermissionDeniedException ex) {
        LOG.debug(ex.getMessage());
        throw new NotAuthorizedException(this);
    } catch (CollectionExistsException | EXistException ex) {
        LOG.debug(ex.getMessage());
        throw new ConflictException(this, "Create Collection '" + getXmldbUri().append(name) + "' failed: " + ex.getMessage());
    }
    return collection;
}
Also used : PermissionDeniedException(org.exist.security.PermissionDeniedException) EXistException(org.exist.EXistException) XmldbURI(org.exist.xmldb.XmldbURI) CollectionExistsException(org.exist.webdav.exceptions.CollectionExistsException)

Aggregations

EXistException (org.exist.EXistException)2 PermissionDeniedException (org.exist.security.PermissionDeniedException)2 CollectionExistsException (org.exist.webdav.exceptions.CollectionExistsException)2 XmldbURI (org.exist.xmldb.XmldbURI)2 Collection (org.exist.collections.Collection)1 DBBroker (org.exist.storage.DBBroker)1 TransactionManager (org.exist.storage.txn.TransactionManager)1 Txn (org.exist.storage.txn.Txn)1