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