use of org.exist.storage.txn.TransactionException in project exist by eXist-db.
the class InstallFunction method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Sequence removed = BooleanValue.FALSE;
boolean force = true;
UserInteractionStrategy interact = new BatchUserInteraction();
String pkgOrPath = args[0].getStringValue();
Optional<ExistRepository> repo = getContext().getRepository();
try {
if (repo.isPresent()) {
Repository parent_repo = repo.get().getParentRepo();
Package pkg;
if (isCalledAs("install")) {
// download .xar from a URI
URI uri = _getURI(pkgOrPath);
pkg = parent_repo.installPackage(uri, force, interact);
repo.get().reportAction(ExistRepository.Action.INSTALL, pkg.getName());
} else {
// .xar is stored as a binary resource
try (final LockedDocument lockedDoc = getBinaryDoc(pkgOrPath);
final Txn transaction = context.getBroker().continueOrBeginTransaction()) {
final DocumentImpl doc = lockedDoc.getDocument();
LOG.debug("Installing file: {}", doc.getURI());
pkg = parent_repo.installPackage(new BinaryDocumentXarSource(context.getBroker().getBrokerPool(), transaction, (BinaryDocument) doc), force, interact);
repo.get().reportAction(ExistRepository.Action.INSTALL, pkg.getName());
transaction.commit();
}
}
ExistPkgInfo info = (ExistPkgInfo) pkg.getInfo("exist");
if (info != null && !info.getJars().isEmpty())
ClasspathHelper.updateClasspath(context.getBroker().getBrokerPool(), pkg);
// TODO: expath libs do not provide a way to see if there were any XQuery modules installed at all
context.getBroker().getBrokerPool().getXQueryPool().clear();
removed = BooleanValue.TRUE;
} else {
throw new XPathException("expath repository not available");
}
} catch (PackageException | TransactionException ex) {
logger.error(ex.getMessage(), ex);
return removed;
// /TODO: _repo.removePackage seems to throw PackageException
// throw new XPathException("Problem installing package " + pkg + " in expath repository, check that eXist-db has access permissions to expath repository file directory ", ex);
} catch (XPathException xpe) {
logger.error(xpe.getMessage());
return removed;
}
return removed;
}
use of org.exist.storage.txn.TransactionException in project exist by eXist-db.
the class NativeBroker method readBinaryResource.
@Override
public void readBinaryResource(final BinaryDocument blob, final OutputStream os) throws IOException {
try (final Txn transaction = continueOrBeginTransaction()) {
readBinaryResource(transaction, blob, os);
transaction.commit();
} catch (final TransactionException e) {
throw new IOException(e.getMessage(), e);
}
}
use of org.exist.storage.txn.TransactionException in project exist by eXist-db.
the class UpdateStatistics method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
final IndexStatisticsWorker index = (IndexStatisticsWorker) context.getBroker().getIndexController().getWorkerByIndexId(IndexStatistics.ID);
if (index != null) {
try (final Txn transaction = context.getBroker().continueOrBeginTransaction()) {
index.updateIndex(context.getBroker(), transaction);
transaction.commit();
} catch (final TransactionException e) {
throw new XPathException(this, e.getMessage(), e);
}
} else {
logger.error("The module may not be enabled!");
}
return Sequence.EMPTY_SEQUENCE;
}
Aggregations