/** * {@inheritDoc} * * @see javax.jcr.query.Query#execute() */ @SuppressWarnings( "deprecation" ) @Override public org.modeshape.jcr.api.query.QueryResult execute() throws RepositoryException { context.checkValid(); final long start = System.nanoTime(); // Create an executable query and set it on this object ... CancellableQuery newExecutable = context.createExecutableQuery(query, hints, variables); CancellableQuery executable = executingQuery.getAndSet(newExecutable); if (executable == null) { // We are the first to call 'execute()', so use our newly-created one ... executable = newExecutable; } // otherwise, some other thread called execute, so we can use it and just wait for the results ... final QueryResults result = executable.execute(); // may be cancelled // And reset the reference to null (if not already set to something else) ... executingQuery.compareAndSet(executable, null); checkForProblems(result.getProblems()); context.recordDuration(Math.abs(System.nanoTime() - start), TimeUnit.NANOSECONDS, statement, language); if (Query.XPATH.equals(language)) { return new XPathQueryResult(context, statement, result, hints.restartable, hints.rowsKeptInMemory); } else if (Query.SQL.equals(language)) { return new JcrSqlQueryResult(context, statement, result, hints.restartable, hints.rowsKeptInMemory); } return new JcrQueryResult(context, statement, result, hints.restartable, hints.rowsKeptInMemory); }
/** * {@inheritDoc} * * @see javax.jcr.query.Query#execute() */ @SuppressWarnings( "deprecation" ) @Override public org.modeshape.jcr.api.query.QueryResult execute() throws RepositoryException { context.checkValid(); final long start = System.nanoTime(); // Create an executable query and set it on this object ... CancellableQuery newExecutable = context.createExecutableQuery(query, hints, variables); CancellableQuery executable = executingQuery.getAndSet(newExecutable); if (executable == null) { // We are the first to call 'execute()', so use our newly-created one ... executable = newExecutable; } // otherwise, some other thread called execute, so we can use it and just wait for the results ... final QueryResults result = executable.execute(); // may be cancelled // And reset the reference to null (if not already set to something else) ... executingQuery.compareAndSet(executable, null); checkForProblems(result.getProblems()); context.recordDuration(Math.abs(System.nanoTime() - start), TimeUnit.NANOSECONDS, statement, language); if (Query.XPATH.equals(language)) { return new XPathQueryResult(context, statement, result, hints.restartable, hints.rowsKeptInMemory); } else if (Query.SQL.equals(language)) { return new JcrSqlQueryResult(context, statement, result, hints.restartable, hints.rowsKeptInMemory); } return new JcrQueryResult(context, statement, result, hints.restartable, hints.rowsKeptInMemory); }
@SuppressWarnings( "deprecation" ) @Override public org.modeshape.jcr.api.query.QueryResult explain() throws RepositoryException { context.checkValid(); // Set to only compute the plan and then create an executable query ... PlanHints hints = this.hints.clone(); hints.planOnly = true; CancellableQuery planOnlyExecutable = context.createExecutableQuery(query, hints, variables); // otherwise, some other thread called execute, so we can use it and just wait for the results ... final QueryResults result = planOnlyExecutable.execute(); // may be cancelled checkForProblems(result.getProblems()); if (Query.XPATH.equals(language)) { return new XPathQueryResult(context, statement, result, false, 0); } else if (Query.SQL.equals(language)) { return new JcrSqlQueryResult(context, statement, result, false, 0); } return new JcrQueryResult(context, statement, result, false, 0); }
@SuppressWarnings( "deprecation" ) @Override public org.modeshape.jcr.api.query.QueryResult explain() throws RepositoryException { context.checkValid(); // Set to only compute the plan and then create an executable query ... PlanHints hints = this.hints.clone(); hints.planOnly = true; CancellableQuery planOnlyExecutable = context.createExecutableQuery(query, hints, variables); // otherwise, some other thread called execute, so we can use it and just wait for the results ... final QueryResults result = planOnlyExecutable.execute(); // may be cancelled checkForProblems(result.getProblems()); if (Query.XPATH.equals(language)) { return new XPathQueryResult(context, statement, result, false, 0); } else if (Query.SQL.equals(language)) { return new JcrSqlQueryResult(context, statement, result, false, 0); } return new JcrQueryResult(context, statement, result, false, 0); }
@Before public void beforeEach() { context = mock(JcrQueryContext.class); query = "SELECT jcr:primaryType, foo:bar FROM nt:unstructured"; graphResult = mock(QueryResults.class); columnTypes = Arrays.asList("STRING", "LONG"); columnNames = Arrays.asList("jcr:primaryType", "foo:bar"); SelectorName tableName = new SelectorName("nt:unstructured"); columns = Arrays.asList(new Column(tableName, columnNames.get(0), columnNames.get(0)), new Column(tableName, columnNames.get(1), columnNames.get(1))); resultColumns = new ScanningQueryEngine.ResultColumns(columns, columnTypes, true, null); when(graphResult.getColumns()).thenReturn(resultColumns); when(graphResult.getRows()).thenReturn(NodeSequence.emptySequence(1)); PlanHints hints = new PlanHints(); result = new XPathQueryResult(context, query, graphResult, hints.restartable, hints.rowsKeptInMemory); }