Search in sources :

Example 11 with TransactionException

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;
}
Also used : XPathException(org.exist.xquery.XPathException) Sequence(org.exist.xquery.value.Sequence) Txn(org.exist.storage.txn.Txn) XmldbURI(org.exist.xmldb.XmldbURI) URI(java.net.URI) DocumentImpl(org.exist.dom.persistent.DocumentImpl) ExistPkgInfo(org.exist.repo.ExistPkgInfo) ExistRepository(org.exist.repo.ExistRepository) TransactionException(org.exist.storage.txn.TransactionException) LockedDocument(org.exist.dom.persistent.LockedDocument) Package(org.expath.pkg.repo.Package) BatchUserInteraction(org.expath.pkg.repo.tui.BatchUserInteraction) ExistRepository(org.exist.repo.ExistRepository)

Example 12 with TransactionException

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);
    }
}
Also used : TransactionException(org.exist.storage.txn.TransactionException) Txn(org.exist.storage.txn.Txn)

Example 13 with TransactionException

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;
}
Also used : TransactionException(org.exist.storage.txn.TransactionException) XPathException(org.exist.xquery.XPathException) Txn(org.exist.storage.txn.Txn) IndexStatisticsWorker(org.exist.storage.statistics.IndexStatisticsWorker)

Aggregations

TransactionException (org.exist.storage.txn.TransactionException)13 Txn (org.exist.storage.txn.Txn)13 IOException (java.io.IOException)6 PermissionDeniedException (org.exist.security.PermissionDeniedException)5 XmldbURI (org.exist.xmldb.XmldbURI)5 URISyntaxException (java.net.URISyntaxException)4 BinaryDocument (org.exist.dom.persistent.BinaryDocument)4 LockedDocument (org.exist.dom.persistent.LockedDocument)4 XPathException (org.exist.xquery.XPathException)4 URI (java.net.URI)3 DocumentImpl (org.exist.dom.persistent.DocumentImpl)3 InputStream (java.io.InputStream)2 UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Collection (org.exist.collections.Collection)2 Permission (org.exist.security.Permission)2 BrokerPool (org.exist.storage.BrokerPool)2 SAXException (org.xml.sax.SAXException)2 TaggedTryUnchecked (com.evolvedbinary.j8fu.Try.TaggedTryUnchecked)1