()
| 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(); |
nothing calls this directly
no test coverage detected