@FixFor( "MODE-1671" ) @Test public void shouldReturnResolvableNodeIdentifierFromQuery() throws RepositoryException { String sql = "SELECT [mode:id] AS reallylongvaluethatwillprintcompletely FROM [nt:unstructured]"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); final Map<String, Node> nodesById = new HashMap<>(); validateQuery().rowCount(24).noWarnings().hasColumns("reallylongvaluethatwillprintcompletely").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { String id = row.getValue("mode:id").getString(); Node nodeFromQuery = row.getNode(); Node resolvedNode = session().getNodeByIdentifier(id); assertSame(nodeFromQuery, resolvedNode); nodesById.put(id, nodeFromQuery); } }).validate(query, result); for (Map.Entry<String, Node> entry : nodesById.entrySet()) { final String id = entry.getKey(); final Node expectedNode = entry.getValue(); sql = "SELECT [mode:id] AS reallylongvaluethatwillprintcompletely FROM [nt:unstructured] WHERE [mode:id] = '" + id + "'"; query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); result = query.execute(); validateQuery().rowCount(1).noWarnings().hasColumns("reallylongvaluethatwillprintcompletely") .onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { String id = row.getValue("mode:id").getString(); Node nodeFromQuery = row.getNode(); String nodeId = nodeFromQuery.getIdentifier(); assertSame(nodeFromQuery, expectedNode); assertSame(nodeId, id); } }).validate(query, result); sql = "SELECT [mode:id] FROM [nt:unstructured] WHERE [mode:id] = $id"; query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); query.bindValue("id", session().getValueFactory().createValue(id)); result = query.execute(); validateQuery().rowCount(1).noWarnings().hasColumns("mode:id").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { String id = row.getValue("mode:id").getString(); Node nodeFromQuery = row.getNode(); assertSame(nodeFromQuery, expectedNode); assertSame(nodeFromQuery.getIdentifier(), id); } }).validate(query, result); } }
@Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } JcrQueryManager( JcrSession session ); }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } JcrQueryManager( JcrSession session ); @Override org.modeshape.jcr.api.query.qom.QueryObjectModelFactory getQOMFactory(); @Override org.modeshape.jcr.api.query.Query createQuery( String statement,
                                                          String language ); @Override org.modeshape.jcr.api.query.Query createQuery( String statement, 
                                                          String language,
                                                          Locale locale ); org.modeshape.jcr.api.query.Query createQuery( String expression,
                                                          String language,
                                                          Path storedAtPath, 
                                                          Locale locale ); Query createQuery( QueryCommand command ); @Override org.modeshape.jcr.api.query.Query getQuery( Node node ); @Override String[] getSupportedQueryLanguages(); }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } JcrQueryManager( JcrSession session ); @Override org.modeshape.jcr.api.query.qom.QueryObjectModelFactory getQOMFactory(); @Override org.modeshape.jcr.api.query.Query createQuery( String statement,
                                                          String language ); @Override org.modeshape.jcr.api.query.Query createQuery( String statement, 
                                                          String language,
                                                          Locale locale ); org.modeshape.jcr.api.query.Query createQuery( String expression,
                                                          String language,
                                                          Path storedAtPath, 
                                                          Locale locale ); Query createQuery( QueryCommand command ); @Override org.modeshape.jcr.api.query.Query getQuery( Node node ); @Override String[] getSupportedQueryLanguages();  }