use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class LocalCollectionManagementService method createCollection.
@Override
public Collection createCollection(final XmldbURI name, final Date created) throws XMLDBException {
final XmldbURI collName = resolve(name);
withDb((broker, transaction) -> {
try {
final org.exist.collections.Collection coll = broker.getOrCreateCollection(transaction, collName, Optional.ofNullable(created).map(c -> new Tuple2<>(null, c.getTime())));
try (final ManagedCollectionLock collectionLock = broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(collName)) {
broker.saveCollection(transaction, coll);
}
return null;
} catch (final LockException | TriggerException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
}
});
return new LocalCollection(user, brokerPool, collection, collName);
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class LocalCollectionManagementService method moveResource.
@Override
public void moveResource(final XmldbURI src, final XmldbURI dest, final XmldbURI name) throws XMLDBException {
final XmldbURI srcPath = resolve(src);
final XmldbURI destPath = dest == null ? srcPath.removeLastSegment() : resolve(dest);
final XmldbURI newName;
if (name == null) {
newName = srcPath.lastSegment();
} else {
newName = name;
}
withDb((broker, transaction) -> modify(broker, transaction, srcPath.removeLastSegment()).apply((sourceCol, b1, t1) -> {
try (final LockedDocument lockedSource = sourceCol.getDocumentWithLock(b1, srcPath.lastSegment(), Lock.LockMode.WRITE_LOCK)) {
final DocumentImpl source = lockedSource == null ? null : lockedSource.getDocument();
if (source == null) {
// NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
sourceCol.close();
throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE, "Resource " + srcPath + " not found");
}
return modify(b1, t1, destPath).apply((destinationCol, b2, t2) -> {
try (final ManagedDocumentLock lockedDestination = b2.getBrokerPool().getLockManager().acquireDocumentWriteLock(destinationCol.getURI().append(newName))) {
b2.moveResource(t2, source, destinationCol, newName);
// NOTE: early release of Collection locks inline with Asymmetrical Locking scheme
destinationCol.close();
sourceCol.close();
}
return null;
});
}
}));
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class LocalCollection method storeXMLResource.
private void storeXMLResource(final LocalXMLResource res) throws XMLDBException {
final XmldbURI resURI;
try {
resURI = XmldbURI.xmldbUriFor(res.getId());
} catch (final URISyntaxException e) {
throw new XMLDBException(ErrorCodes.INVALID_URI, e);
}
modify().apply((collection, broker, transaction) -> {
String uri = null;
if (res.file != null) {
uri = res.file.toUri().toASCIIString();
}
try (final ManagedDocumentLock documentLock = broker.getBrokerPool().getLockManager().acquireDocumentWriteLock(collection.getURI().append(resURI))) {
final String strMimeType = res.getMimeType(broker, transaction);
final MimeType mimeType = strMimeType != null ? MimeTable.getInstance().getContentType(strMimeType) : null;
if (res.root != null) {
collection.storeDocument(transaction, broker, resURI, res.root, mimeType, res.datecreated, res.datemodified, null, null, null);
} else {
final InputSource source;
if (uri != null) {
source = new InputSource(uri);
} else if (res.inputSource != null) {
source = res.inputSource;
} else {
source = new StringInputSource(res.content);
}
final XMLReader reader;
if (useHtmlReader(broker, transaction, res)) {
reader = getHtmlReader();
} else {
reader = null;
}
broker.storeDocument(transaction, resURI, source, mimeType, res.datecreated, res.datemodified, null, null, reader, collection);
}
// NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
collection.close();
return null;
} catch (final EXistException | SAXException e) {
// NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
collection.close();
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
}
});
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class LocalCollection method createResource.
@Override
public Resource createResource(String id, final String type) throws XMLDBException {
if (id == null) {
id = createId();
}
final XmldbURI idURI;
try {
idURI = XmldbURI.xmldbUriFor(id);
} catch (final URISyntaxException e) {
throw new XMLDBException(ErrorCodes.INVALID_URI, e);
}
final Resource r;
switch(type) {
case XMLResource.RESOURCE_TYPE:
r = new LocalXMLResource(user, brokerPool, this, idURI);
break;
case BinaryResource.RESOURCE_TYPE:
r = new LocalBinaryResource(user, brokerPool, this, idURI);
break;
default:
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "Unknown resource type: " + type);
}
((AbstractEXistResource) r).isNewResource = true;
return r;
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class LocalCollection method getChildCollection.
@Override
public org.xmldb.api.base.Collection getChildCollection(final String name) throws XMLDBException {
final XmldbURI childURI;
try {
childURI = XmldbURI.xmldbUriFor(name);
} catch (final URISyntaxException e) {
throw new XMLDBException(ErrorCodes.INVALID_URI, e);
}
final XmldbURI nameUri = this.<XmldbURI>read().apply((collection, broker, transaction) -> {
XmldbURI childName = null;
if (collection.hasChildCollection(broker, childURI)) {
childName = getPathURI().append(childURI);
}
return childName;
});
if (nameUri != null) {
return new LocalCollection(user, brokerPool, this, nameUri);
} else {
return null;
}
}
Aggregations