use of org.exist.source.StringSource in project exist by eXist-db.
the class QueryPoolTest method differentQueries.
@Test
public void differentQueries() throws XMLDBException {
EXistXQueryService service = (EXistXQueryService) testCollection.getService("XQueryService", "1.0");
for (int i = 0; i < 1000; i++) {
String query = "update insert <node id='id" + Integer.toHexString(i) + "'>" + "Some longer text <b>content</b> in this node. Some longer text <b>content</b> in this node. " + "Some longer text <b>content</b> in this node. Some longer text <b>content</b> in this node." + "</node> " + "into //test[@id = 't1']";
service.execute(new StringSource(query));
}
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class InternalModuleTest method moduleVariables.
@Test
public void moduleVariables() throws XMLDBException {
final Source querySource = new StringSource(getModuleVariableQuery("org.exist.xquery.InternalModuleTest$TestModuleWithVariables"));
final EXistXQueryService queryService = (EXistXQueryService) existServer.getRoot().getService("XQueryService", "1.0");
moduleVariablesQuery(queryService, querySource, COUNTER.get());
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class LowLevelTextTest method borrowCompiledXQueryNewStringSource.
/**
* test with a new StringSource object having same content
*/
@Test
public void borrowCompiledXQueryNewStringSource() throws PermissionDeniedException {
xqueryPool.returnCompiledXQuery(stringSource, preCompiledXQuery);
StringSource localStringSource = new StringSource(TEST_XQUERY_SOURCE);
callAndTestBorrowCompiledXQuery(localStringSource);
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class RESTServer method search.
/**
* TODO: pass request and response objects to XQuery.
*
* @param broker the database broker
* @param transaction the database transaction
* @param query the XQuery
* @param path the path of the request
* @param namespaces any XQuery namespace bindings
* @param variables any XQuery variable bindings
* @param howmany the number of items in the results to return
* @param start the start position in the results to return
* @param typed whether the result nodes should be typed
* @param outputProperties the serialization properties
* @param wrap true to wrap the result of the XQuery in an exist:result
* @param cache whether to cache the results
* @param request the request
* @param response the response
*
* @throws BadRequestException if a bad request is made
* @throws PermissionDeniedException if the request has insufficient permissions
* @throws XPathException if the XQuery raises an error
*/
protected void search(final DBBroker broker, final Txn transaction, final String query, final String path, final List<Namespace> namespaces, final ElementImpl variables, final int howmany, final int start, final boolean typed, final Properties outputProperties, final boolean wrap, final boolean cache, final HttpServletRequest request, final HttpServletResponse response) throws BadRequestException, PermissionDeniedException, XPathException {
if (xquerySubmission == EXistServlet.FeatureEnabled.FALSE) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
} else if (xquerySubmission == EXistServlet.FeatureEnabled.AUTHENTICATED_USERS_ONLY) {
final Subject currentSubject = broker.getCurrentSubject();
if (!currentSubject.isAuthenticated() || currentSubject.getId() == RealmImpl.GUEST_GROUP_ID) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
}
final String sessionIdParam = outputProperties.getProperty(Serializer.PROPERTY_SESSION_ID);
if (sessionIdParam != null) {
try {
final int sessionId = Integer.parseInt(sessionIdParam);
if (sessionId > -1) {
final Sequence cached = sessionManager.get(query, sessionId);
if (cached != null) {
LOG.debug("Returning cached query result");
writeResults(response, broker, transaction, cached, howmany, start, typed, outputProperties, wrap, 0, 0);
} else {
LOG.debug("Cached query result not found. Probably timed out. Repeating query.");
}
}
} catch (final NumberFormatException e) {
throw new BadRequestException("Invalid session id passed in query request: " + sessionIdParam);
}
}
final XmldbURI pathUri = XmldbURI.createInternal(path);
final Source source = new StringSource(query);
final XQueryPool pool = broker.getBrokerPool().getXQueryPool();
CompiledXQuery compiled = null;
try {
final XQuery xquery = broker.getBrokerPool().getXQueryService();
compiled = pool.borrowCompiledXQuery(broker, source);
XQueryContext context;
if (compiled == null) {
context = new XQueryContext(broker.getBrokerPool());
} else {
context = compiled.getContext();
context.prepareForReuse();
}
context.setStaticallyKnownDocuments(new XmldbURI[] { pathUri });
context.setBaseURI(new AnyURIValue(pathUri.toString()));
declareNamespaces(context, namespaces);
declareVariables(context, variables, request, response);
final long compilationTime;
if (compiled == null) {
final long compilationStart = System.currentTimeMillis();
compiled = xquery.compile(context, source);
compilationTime = System.currentTimeMillis() - compilationStart;
} else {
compiled.getContext().updateContext(context);
context.getWatchDog().reset();
compilationTime = 0;
}
try {
final long executeStart = System.currentTimeMillis();
final Sequence resultSequence = xquery.execute(broker, compiled, null, outputProperties);
final long executionTime = System.currentTimeMillis() - executeStart;
if (LOG.isDebugEnabled()) {
LOG.debug("Found {} in {}ms.", resultSequence.getItemCount(), executionTime);
}
if (cache) {
final int sessionId = sessionManager.add(query, resultSequence);
outputProperties.setProperty(Serializer.PROPERTY_SESSION_ID, Integer.toString(sessionId));
if (!response.isCommitted()) {
response.setIntHeader("X-Session-Id", sessionId);
}
}
writeResults(response, broker, transaction, resultSequence, howmany, start, typed, outputProperties, wrap, compilationTime, executionTime);
} finally {
context.runCleanupTasks();
}
} catch (final IOException e) {
throw new BadRequestException(e.getMessage(), e);
} finally {
if (compiled != null) {
pool.returnCompiledXQuery(source, compiled);
}
}
}
Aggregations