use of org.exist.xquery.XQuery in project exist by eXist-db.
the class LowLevelTextTest method setUp.
@Before
public void setUp() throws DatabaseConfigurationException, EXistException, XPathException, PermissionDeniedException, IOException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
xqueryPool = pool.getXQueryPool();
stringSource = new StringSource(TEST_XQUERY_SOURCE);
final XQuery xquery = pool.getXQueryService();
final XQueryContext context = new XQueryContext(broker.getBrokerPool());
preCompiledXQuery = xquery.compile(context, stringSource);
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class DebuggeeJointImpl method evalution.
@Override
public String evalution(String script) throws Exception {
Database db = compiledXQuery.getContext().getDatabase();
// TODO: account required
try (final DBBroker broker = db.getBroker()) {
XQueryContext context = compiledXQuery.getContext().copyContext();
context.setDebuggeeJoint(null);
context.undeclareGlobalVariable(Debuggee.SESSION);
context.undeclareGlobalVariable(Debuggee.IDEKEY);
XQuery service = broker.getBrokerPool().getXQueryService();
CompiledXQuery compiled = service.compile(broker, context, script);
Sequence resultSequence = service.execute(broker, compiled, null);
SAXSerializer sax = null;
Serializer serializer = broker.getSerializer();
serializer.reset();
try {
sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
Properties outputProps = new Properties();
StringWriter writer = new StringWriter();
sax.setOutput(writer, outputProps);
serializer.setSAXHandlers(sax, sax);
for (SequenceIterator i = resultSequence.iterate(); i.hasNext(); ) {
Item next = i.nextItem();
if (Type.subTypeOf(next.getType(), Type.NODE))
serializer.toSAX((NodeValue) next);
else
writer.write(next.getStringValue());
}
return writer.toString();
} finally {
if (sax != null) {
SerializerPool.getInstance().returnObject(sax);
}
}
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class ScriptRunner method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try {
final Database db = BrokerPool.getInstance();
db.addStatusObserver(this);
try (final DBBroker broker = db.getBroker()) {
XQuery xquery = broker.getBrokerPool().getXQueryService();
xquery.execute(broker, expression, null);
// XQueryContext context = expression.getContext();
//
// expression.reset();
//
// context.setBroker(broker);
// context.getWatchDog().reset();
//
// //do any preparation before execution
// context.prepare();
//
// context.getProfiler().traceQueryStart();
// broker.getBrokerPool().getProcessMonitor().queryStarted(context.getWatchDog());
// try {
// Sequence result = expression.eval(null);
//
// if(outputProperties != null)
// context.checkOptions(outputProperties); //must be done before context.reset!
//
// //return result;
// } finally {
// context.getProfiler().traceQueryEnd(context);
// expression.reset();
// context.reset();
// broker.getBrokerPool().getProcessMonitor().queryCompleted(context.getWatchDog());
// }
}
} catch (Exception e) {
e.printStackTrace();
exception = e;
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class EmbeddedBinariesTest method executeXQuery.
@Override
protected QueryResultAccessor<Sequence, IOException> executeXQuery(final String query) throws Exception {
final Source source = new StringSource(query);
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
final XQueryPool pool = brokerPool.getXQueryPool();
final XQuery xquery = brokerPool.getXQueryService();
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()))) {
final CompiledXQuery existingCompiled = pool.borrowCompiledXQuery(broker, source);
final XQueryContext context;
final CompiledXQuery compiled;
if (existingCompiled == null) {
context = new XQueryContext(brokerPool);
compiled = xquery.compile(context, source);
} else {
context = existingCompiled.getContext();
context.prepareForReuse();
compiled = existingCompiled;
}
final Sequence results = xquery.execute(broker, compiled, null);
return consumer2E -> {
try {
// context.runCleanupTasks(); //TODO(AR) shows the ordering issue with binary values (see comment below)
consumer2E.accept(results);
} finally {
// TODO(AR) performing #runCleanupTasks causes the stream to be closed, so if we do so before we are finished with the results, serialization fails.
context.runCleanupTasks();
pool.returnCompiledXQuery(source, compiled);
}
};
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class GMLIndexTest method highLevelSearch.
@Test
public void highLevelSearch() throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = server.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
String query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:equals(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
Sequence seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:disjoint(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:intersects(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:touches(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
// assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:crosses(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
// assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:within(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:contains(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:overlaps(//gml:*, //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
// assertTrue(seq.getItemCount() > 0);
// Tests with empty sequences
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:equals(//gml:*, ())";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertTrue(seq.getItemCount() > 0);
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:overlaps((), //gml:Point[gml:coordinates[. = '278697.450,187740.900']])";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertEquals(0, seq.getItemCount());
// In-memory test
query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " + "at 'java:org.exist.xquery.modules.spatial.SpatialModule'; " + "declare namespace gml = 'http://www.opengis.net/gml'; " + "spatial:equals(//gml:*, " + IN_MEMORY_GML + ")";
seq = xquery.execute(broker, query, null);
assertNotNull(seq);
assertTrue(seq.getItemCount() > 0);
}
}
Aggregations