@SuppressWarnings( "synthetic-access" ) @Override public String explain( String query, String language ) { return ((org.modeshape.jcr.api.query.QueryResult)queryResult).getPlan(); }
private void checkCancelled( QueryContext context ) throws QueryCancelledException { if (context.isCancelled()) { throw new QueryCancelledException(); } }
public static String explainPlain(Session session, String queryExpression) throws RepositoryException { Query query = session.getWorkspace().getQueryManager().createQuery(queryExpression, "JCR-SQL2"); org.modeshape.jcr.api.query.Query msQuery = (org.modeshape.jcr.api.query.Query)query; // Get the query plan without executing it ... org.modeshape.jcr.api.query.QueryResult result = msQuery.explain(); String plan = result.getPlan(); return plan; }
bindExtraVariables(uriInfo, session.getValueFactory(), query); org.modeshape.jcr.api.query.QueryResult result = query.explain(); String plan = result.getPlan(); return new RestQueryPlanResult(plan, statement, language, query.getAbstractQueryModelRepresentation());
private JcrType getJcrType( int column ) { JcrType typeInfo = null; if (results instanceof org.modeshape.jcr.api.query.QueryResult) { final String typeName = ((org.modeshape.jcr.api.query.QueryResult)results).getColumnTypes()[column - 1]; typeInfo = JcrType.typeInfo(typeName); } /** * If no type is matched, then default to STRING */ return (typeInfo != null ? typeInfo : JcrType.typeInfo(DefaultDataTypes.STRING)); }
@FixFor( "MODE-1833" ) @Test public void shouldBeAbleToQueryAllColumnsOnSimpleType() throws RepositoryException { QueryManager queryManager = session.getWorkspace().getQueryManager(); QueryObjectModelFactory factory = queryManager.getQOMFactory(); Query query = factory.createQuery(factory.selector("modetest:simpleType", "type1"), null, null, new Column[] {factory.column("type1", null, null)}); QueryResult result = query.execute(); validateQuery().rowCount(0).validate(query, result); }
@FixFor( "MODE-1901" ) @Test public void shouldExplainQueryWithoutExecutingQuery() throws RepositoryException { String sql = "SELECT * FROM [nt:file]"; org.modeshape.jcr.api.query.Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); org.modeshape.jcr.api.query.QueryResult result = query.explain(); validateQuery().rowCount(0).warnings(0).onlyQueryPlan().validate(query, result); }
@Test public void shouldUseSingleColumnStringIndexForQueryWithNoCriteriaOtherThanPrimaryTypeViaFromClause() throws Exception { registerValueIndex("unstructuredNodes", "nt:unstructured", null, "*", "jcr:primaryType", PropertyType.NAME); // print = true; // Add a node that uses this type ... Node root = session().getRootNode(); Node book1 = root.addNode("myFirstBook"); book1.addMixin("mix:title"); book1.setProperty("jcr:title", "The Title"); Node book2 = root.addNode("mySecondBook"); book2.addMixin("mix:title"); book2.setProperty("jcr:title", "A Different Title"); // Create a node that is not a 'mix:title' and therefore won't be included in the SELECT clauses ... Node other = root.addNode("somethingElse"); other.setProperty("propA", "a value for property A"); other.setProperty("jcr:title", "The Title"); session.save(); // Compute a query plan that should use this index ... Query query = jcrSql2Query("SELECT * FROM [nt:unstructured]"); validateQuery().rowCount(3L).useIndex("unstructuredNodes").validate(query, query.execute()); }
protected void query( String sql, String language, long numberOfResults, Predicate predicate ) throws Exception { Query query = ((Session)session).getWorkspace().getQueryManager().createQuery(sql, language); QueryResult result = query.execute(); assertResults(query, result, numberOfResults, predicate); }
protected void validateWarnings( QueryResult result ) { if (warningCount >= 0) { Collection<String> warnings = ((org.modeshape.jcr.api.query.QueryResult)result).getWarnings(); if (print) { System.out.println("Warnings on query"); for (String warning : warnings) { System.out.println(" " + warning); } System.out.println(); } assertThat(warnings.size(), is(warningCount)); } }
public List<T> findWithExplainPlan(String queryExpression) { try { org.modeshape.jcr.api.query.Query query = (org.modeshape.jcr.api.query.Query) getSession().getWorkspace().getQueryManager().createQuery(queryExpression, "JCR-SQL2"); org.modeshape.jcr.api.query.QueryResult result = query.explain(); String plan = result.getPlan(); log.info(plan); return find(queryExpression); } catch (RepositoryException e) { throw new MetadataRepositoryException("Failure while finding entity ", e); } }
protected void print( Query query, QueryResult result ) { System.out.println(); System.out.println(query); System.out.println(" plan -> " + ((org.modeshape.jcr.api.query.QueryResult)result).getPlan()); System.out.println(result); }
private JcrType getJcrType( int column ) { JcrType typeInfo = null; if (results instanceof org.modeshape.jcr.api.query.QueryResult) { final String typeName = ((org.modeshape.jcr.api.query.QueryResult)results).getColumnTypes()[column - 1]; typeInfo = JcrType.typeInfo(typeName); } /** * If no type is matched, then default to STRING */ return (typeInfo != null ? typeInfo : JcrType.typeInfo(DefaultDataTypes.STRING)); }
private void checkCancelled( QueryContext context ) throws QueryCancelledException { if (context.isCancelled()) { throw new QueryCancelledException(); } }
@Test public void shouldUseSingleColumnStringIndexForQueryWithNoCriteriaOtherThanMixinViaFromClause() throws Exception { registerValueIndex("titleNodes", "mix:title", null, "*", "jcr:mixinTypes", PropertyType.NAME); // print = true; // Add a node that uses this type ... Node root = session().getRootNode(); Node book1 = root.addNode("myFirstBook"); book1.addMixin("mix:title"); book1.setProperty("jcr:title", "The Title"); Node book2 = root.addNode("mySecondBook"); book2.addMixin("mix:title"); book2.setProperty("jcr:title", "A Different Title"); // Create a node that is not a 'mix:title' and therefore won't be included in the SELECT clauses ... Node other = root.addNode("somethingElse"); other.setProperty("propA", "a value for property A"); other.setProperty("jcr:title", "The Title"); session.save(); // Compute a query plan that should use this index ... Query query = jcrSql2Query("SELECT * FROM [mix:title]"); validateQuery().rowCount(2L).useIndex("titleNodes").validate(query, query.execute()); }
@SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToExecuteXPathQueryToFindAllUnstructuredNodesOrderedByPropertyValue() throws RepositoryException { QueryManager manager = session.getWorkspace().getQueryManager(); Query query = manager.createQuery("//element(*,nt:unstructured) order by @jcr:primaryType", Query.XPATH); QueryResult result = query.execute(); validateQuery().rowCount(24).hasColumns("jcr:primaryType", "jcr:path", "jcr:score").validate(query, result); query = manager.createQuery("//element(*,car:Car) order by @car:year", Query.XPATH); result = query.execute(); validateQuery().rowCount(13).hasColumns("car:year", "jcr:path", "jcr:score").validate(query, result); }
@Override public String explain( String query, String language ) throws RepositoryException { logger.trace("Explaining query: {0}", query); // Create the query ... final org.modeshape.jcr.api.query.Query jcrQuery = (org.modeshape.jcr.api.query.Query)getLocalSession().getSession().getWorkspace().getQueryManager().createQuery(query, language); return jcrQuery.explain().getPlan(); }
private void setColumns( QueryResult result, RestQueryResult restQueryResult, String[] columnNames ) { if (result instanceof org.modeshape.jcr.api.query.QueryResult) { org.modeshape.jcr.api.query.QueryResult modeShapeQueryResult = (org.modeshape.jcr.api.query.QueryResult)result; String[] columnTypes = modeShapeQueryResult.getColumnTypes(); for (int i = 0; i < columnNames.length; i++) { restQueryResult.addColumn(columnNames[i], columnTypes[i]); } } else { for (String columnName : columnNames) { restQueryResult.addColumn(columnName, UNKNOWN_TYPE); } } }
@Test public void shouldFindBuiltInNodeTypes() throws Exception { String queryString = "select [jcr:path] from [nt:base] where ischildnode('/jcr:system/jcr:nodeTypes')"; QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(queryString, Query.JCR_SQL2); QueryResult result = query.execute(); long numNodetypes = session.getWorkspace().getNodeTypeManager().getAllNodeTypes().getSize(); validateQuery().rowCount(numNodetypes).validate(query, result); }
@Override public String explain( String query, String language ) throws RepositoryException { logger.trace("Explaining query: {0}", query); // Create the query ... final org.modeshape.jcr.api.query.Query jcrQuery = (org.modeshape.jcr.api.query.Query)getLocalSession().getSession().getWorkspace().getQueryManager().createQuery(query, language); return jcrQuery.explain().getPlan(); }