MCPcopy Create free account
hub / github.com/BaseXdb/basex / run

Method run

basex-core/src/main/java/org/basex/core/jobs/QueryJob.java:188–271  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

186 }
187
188 @Override
189 public void run() {
190 try {
191 result.init();
192
193 final JobContext jc = jc();
194 final String id = jc.id();
195 final Context ctx = jc.context;
196 final JobOptions opts = job.options;
197
198 String log = opts.get(JobOptions.LOG);
199 if(log != null && log.isEmpty()) log = null;
200 if(log != null) ctx.log.write(LogType.REQUEST, log, null, "JOB:" + id, ctx);
201
202 final Performance perf = new Performance();
203 qp = new QueryProcessor(job.query, opts.get(JobOptions.BASE_URI), ctx, null);
204 try {
205 // parse, push and register query. order is important!
206 for(final Entry<String, Value> binding : job.bindings.entrySet()) {
207 final String key = binding.getKey();
208 final Value value = binding.getValue();
209 if(key.isEmpty()) qp.context(value);
210 else qp.variable(key, value);
211 }
212 qp.parse();
213 updating = qp.updating;
214 result.time = perf.nanoRuntime();
215
216 // register job
217 pushJob(qp);
218 register(ctx);
219 // reset timer
220 perf.nanoRuntime();
221 if(remove) ctx.jobs.tasks.remove(id);
222
223 // retrieve result; copy persistent database nodes
224 result.value = qp.value().materialize(d -> d == null || d.inMemory(), null, qp.qc);
225 } catch(final JobException ex) {
226 // query was interrupted: remove cached result
227 Util.debug(ex);
228 ctx.jobs.results.remove(id);
229 } catch(final QueryException ex) {
230 result.exception = ex;
231 } catch(final Throwable ex) {
232 result.exception = XQUERY_UNEXPECTED_X.get(null, ex);
233 } finally {
234 // close and invalidate query after result has been assigned. order is important!
235 if(Boolean.TRUE.equals(opts.get(JobOptions.CACHE))) {
236 ctx.jobs.scheduleResult(this);
237 state(JobState.CACHED);
238 } else {
239 state(JobState.SCHEDULED);
240 }
241
242 if(ctx.jobs.active.containsKey(id)) {
243 qp.close();
244 unregister(ctx);
245 popJob();

Callers

nothing calls this directly

Calls 15

idMethod · 0.95
nanoRuntimeMethod · 0.95
debugMethod · 0.95
jcMethod · 0.80
getKeyMethod · 0.80
pushJobMethod · 0.80
scheduleResultMethod · 0.80
stateMethod · 0.80
popJobMethod · 0.80
getMethod · 0.65
removeMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected