|
32 | 32 | */
|
33 | 33 | package org.exist.xquery.modules.sql;
|
34 | 34 |
|
35 |
| -import com.evolvedbinary.j8fu.function.Function2E; |
36 | 35 | import com.evolvedbinary.j8fu.tuple.Tuple2;
|
37 | 36 | import org.exist.EXistException;
|
38 | 37 | import org.exist.collections.Collection;
|
|
42 | 41 | import org.exist.source.StringSource;
|
43 | 42 | import org.exist.storage.BrokerPool;
|
44 | 43 | import org.exist.storage.DBBroker;
|
45 |
| -import org.exist.storage.XQueryPool; |
46 | 44 | import org.exist.storage.lock.Lock;
|
47 | 45 | import org.exist.storage.txn.Txn;
|
48 | 46 | import org.exist.test.ExistEmbeddedServer;
|
49 | 47 | import org.exist.util.LockException;
|
50 | 48 | import org.exist.xmldb.XmldbURI;
|
51 |
| -import org.exist.xquery.CompiledXQuery; |
52 | 49 | import org.exist.xquery.XPathException;
|
53 |
| -import org.exist.xquery.XQuery; |
54 | 50 | import org.exist.xquery.XQueryContext;
|
55 | 51 | import org.exist.xquery.modules.ModuleUtils;
|
56 | 52 | import org.exist.xquery.value.Sequence;
|
|
73 | 69 |
|
74 | 70 | import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple;
|
75 | 71 | import static java.nio.charset.StandardCharsets.UTF_8;
|
| 72 | +import static org.exist.xquery.modules.sql.Util.executeQuery; |
| 73 | +import static org.exist.xquery.modules.sql.Util.withCompiledQuery; |
76 | 74 | import static org.junit.Assert.assertEquals;
|
77 | 75 | import static org.junit.Assert.assertTrue;
|
78 | 76 |
|
@@ -185,44 +183,4 @@ public void getJndiConnectionFromModuleIsAutomaticallyClosed() throws EXistExcep
|
185 | 183 | transaction.commit();
|
186 | 184 | }
|
187 | 185 | }
|
188 |
| - |
189 |
| - private Sequence executeQuery(final DBBroker broker, final CompiledXQuery compiledXQuery) throws PermissionDeniedException, XPathException { |
190 |
| - final BrokerPool pool = broker.getBrokerPool(); |
191 |
| - final XQuery xqueryService = pool.getXQueryService(); |
192 |
| - return xqueryService.execute(broker, compiledXQuery, null, new Properties()); |
193 |
| - } |
194 |
| - |
195 |
| - private <T> T withCompiledQuery(final DBBroker broker, final Source source, final Function2E<CompiledXQuery, T, XPathException, PermissionDeniedException> op) throws XPathException, PermissionDeniedException, IOException { |
196 |
| - final BrokerPool pool = broker.getBrokerPool(); |
197 |
| - final XQuery xqueryService = pool.getXQueryService(); |
198 |
| - final XQueryPool xqueryPool = pool.getXQueryPool(); |
199 |
| - final CompiledXQuery compiledQuery = compileQuery(broker, xqueryService, xqueryPool, source); |
200 |
| - try { |
201 |
| - return op.apply(compiledQuery); |
202 |
| - } finally { |
203 |
| - if (compiledQuery != null) { |
204 |
| - xqueryPool.returnCompiledXQuery(source, compiledQuery); |
205 |
| - } |
206 |
| - } |
207 |
| - } |
208 |
| - |
209 |
| - private CompiledXQuery compileQuery(final DBBroker broker, final XQuery xqueryService, final XQueryPool xqueryPool, final Source query) throws PermissionDeniedException, XPathException, IOException { |
210 |
| - CompiledXQuery compiled = xqueryPool.borrowCompiledXQuery(broker, query); |
211 |
| - XQueryContext context; |
212 |
| - if (compiled == null) { |
213 |
| - context = new XQueryContext(broker.getBrokerPool()); |
214 |
| - } else { |
215 |
| - context = compiled.getContext(); |
216 |
| - context.prepareForReuse(); |
217 |
| - } |
218 |
| - |
219 |
| - if (compiled == null) { |
220 |
| - compiled = xqueryService.compile(broker, context, query); |
221 |
| - } else { |
222 |
| - compiled.getContext().updateContext(context); |
223 |
| - context.getWatchDog().reset(); |
224 |
| - } |
225 |
| - |
226 |
| - return compiled; |
227 |
| - } |
228 | 186 | }
|
0 commit comments