use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class Util method compileQuery.
static CompiledXQuery compileQuery(final DBBroker broker, final XQuery xqueryService, final XQueryPool xqueryPool, final Source query) throws PermissionDeniedException, XPathException, IOException {
CompiledXQuery compiled = xqueryPool.borrowCompiledXQuery(broker, query);
XQueryContext context;
if (compiled == null) {
context = new XQueryContext(broker.getBrokerPool());
} else {
context = compiled.getContext();
context.prepareForReuse();
}
if (compiled == null) {
compiled = xqueryService.compile(context, query);
} else {
compiled.getContext().updateContext(context);
context.getWatchDog().reset();
}
return compiled;
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class JNDIModule method retrieveJNDIContext.
/**
* Retrieves a previously stored Connection from the Context of an XQuery
*
* @param context The Context of the XQuery containing the JNDI Context
* @param ctxID The ID of the JNDI Context to retrieve from the Context of the XQuery
*
* @return the JNDI context
*/
public static final Context retrieveJNDIContext(XQueryContext context, long ctxID) {
Context jndiContext = null;
// get the existing connections map from the context
HashMap contexts = (HashMap) context.getAttribute(JNDIModule.JNDICONTEXTS_VARIABLE);
if (contexts != null) {
jndiContext = (Context) contexts.get(ctxID);
}
return (jndiContext);
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class JNDIModule method closeJNDIContext.
/**
* Closes a specified JNDI Context for the specified XQueryContext
*
* @param context The context to close JNDI Contexts for
* @param ctxID The ID of the JNDI Context to retrieve from the Context of the XQuery
* @param contexts The contexts hashmap
*/
private static final void closeJNDIContext(XQueryContext context, long ctxID, HashMap contexts) {
Context ctx = null;
if (contexts != null) {
ctx = (Context) contexts.get(ctxID);
if (ctx != null) {
try {
// close the connection
ctx.close();
// remove it from the connections map
contexts.remove(ctxID);
} catch (NamingException ne) {
LOG.error("Unable to close JNDI Context", ne);
}
}
}
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class LocalXPathQueryService method execute.
private ResourceSet execute(final LocalXmldbFunction<Source> sourceOp) throws XMLDBException {
return withDb((broker, transaction) -> {
final long start = System.currentTimeMillis();
final Source source = sourceOp.apply(broker, transaction);
final XmldbURI[] docs = new XmldbURI[] { XmldbURI.create(collection.getName(broker, transaction)) };
final XQuery xquery = brokerPool.getXQueryService();
final XQueryPool pool = brokerPool.getXQueryPool();
XQueryContext context;
CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, source);
if (compiled == null) {
context = new XQueryContext(broker.getBrokerPool());
} else {
context = compiled.getContext();
context.prepareForReuse();
}
context.setStaticallyKnownDocuments(docs);
if (variableDecls.containsKey(Debuggee.PREFIX + ":session")) {
context.declareVariable(Debuggee.SESSION, variableDecls.get(Debuggee.PREFIX + ":session"));
variableDecls.remove(Debuggee.PREFIX + ":session");
}
setupContext(source, context);
if (compiled == null) {
compiled = xquery.compile(context, source);
}
try {
final Sequence result = xquery.execute(broker, compiled, null, properties);
if (LOG.isDebugEnabled()) {
LOG.debug("query took {} ms.", System.currentTimeMillis() - start);
}
final Properties resourceSetProperties = new Properties(properties);
resourceSetProperties.setProperty(EXistOutputKeys.XDM_SERIALIZATION, "yes");
return result != null ? new LocalResourceSet(user, brokerPool, collection, resourceSetProperties, result, null) : null;
} finally {
compiled.getContext().runCleanupTasks();
pool.returnCompiledXQuery(source, compiled);
}
});
}
use of org.exist.xquery.XQueryContext in project exist by eXist-db.
the class LocalXPathQueryService method compileAndCheck.
private Either<XPathException, CompiledExpression> compileAndCheck(final DBBroker broker, final Txn transaction, final String query) throws XMLDBException {
final long start = System.currentTimeMillis();
final XQuery xquery = broker.getBrokerPool().getXQueryService();
final XQueryContext context = new XQueryContext(broker.getBrokerPool());
try {
setupContext(null, context);
final CompiledExpression expr = xquery.compile(context, query);
if (LOG.isDebugEnabled()) {
LOG.debug("compilation took {}", System.currentTimeMillis() - start);
}
return Either.Right(expr);
} catch (final PermissionDeniedException e) {
throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, e.getMessage(), e);
} catch (final IllegalArgumentException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
} catch (final XPathException e) {
return Either.Left(e);
}
}
Aggregations