Index: modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrQueryResult.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrQueryResult.java (revision 2343) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrQueryResult.java (working copy) @@ -50,7 +50,6 @@ import org.modeshape.graph.query.model.Column; import org.modeshape.graph.query.validate.Schemata; import org.modeshape.graph.query.validate.Schemata.Table; import org.modeshape.jcr.JcrI18n; -import org.modeshape.jcr.query.JcrSqlQueryResult.JcrSqlQueryResultRowIterator; /** * The results of a query. This is not thread-safe because it relies upon JcrSession, which is not thread-safe. Also, although the @@ -548,13 +547,13 @@ public class JcrQueryResult implements QueryResult, org.modeshape.jcr.api.query. if (JCR_NAME_COLUMN_NAME.equals(columnName)) { Location location = (Location)tuple[iterator.locationIndex]; Path path = location.getPath(); - if (path.isRoot()) return ((JcrSqlQueryResultRowIterator)iterator).jcrName(); + if (path.isRoot()) return iterator.jcrName(); return iterator.jcrName(path.getLastSegment().getName()); } if (MODE_LOCALNAME_COLUMN_NAME.equals(columnName)) { Location location = (Location)tuple[iterator.locationIndex]; Path path = location.getPath(); - if (path.isRoot()) return ((JcrSqlQueryResultRowIterator)iterator).jcrString(""); + if (path.isRoot()) return iterator.jcrString(""); return iterator.jcrString(path.getLastSegment().getName().getLocalName()); } if (MODE_DEPTH_COLUMN_NAME.equals(columnName)) { @@ -675,13 +674,13 @@ public class JcrQueryResult implements QueryResult, org.modeshape.jcr.api.query. if (JCR_NAME_COLUMN_NAME.equals(columnName)) { Location location = (Location)tuple[locationIndex]; Path path = location.getPath(); - if (path.isRoot()) return ((JcrSqlQueryResultRowIterator)iterator).jcrName(); + if (path.isRoot()) return iterator.jcrName(); return iterator.jcrName(path.getLastSegment().getName()); } if (MODE_LOCALNAME_COLUMN_NAME.equals(columnName)) { Location location = (Location)tuple[locationIndex]; Path path = location.getPath(); - if (path.isRoot()) return ((JcrSqlQueryResultRowIterator)iterator).jcrString(""); + if (path.isRoot()) return iterator.jcrString(""); return iterator.jcrString(path.getLastSegment().getName().getLocalName()); } if (MODE_DEPTH_COLUMN_NAME.equals(columnName)) { Index: modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrSqlQueryResult.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrSqlQueryResult.java (revision 2343) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrSqlQueryResult.java (working copy) @@ -24,17 +24,10 @@ package org.modeshape.jcr.query; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import javax.jcr.ItemNotFoundException; -import javax.jcr.Node; import javax.jcr.PropertyType; -import javax.jcr.RepositoryException; -import javax.jcr.Value; -import javax.jcr.query.Row; import javax.jcr.query.RowIterator; -import org.modeshape.graph.Location; import org.modeshape.graph.query.QueryResults; import org.modeshape.graph.query.validate.Schemata; @@ -100,49 +93,6 @@ public class JcrSqlQueryResult extends JcrQueryResult { public RowIterator getRows() { final int numRows = results.getRowCount(); final List tuples = results.getTuples(); - return new JcrSqlQueryResultRowIterator(context, queryStatement, results, tuples.iterator(), numRows); - } - - protected static class JcrSqlQueryResultRowIterator extends SingleSelectorQueryResultRowIterator { - - protected JcrSqlQueryResultRowIterator( JcrQueryContext context, - String query, - QueryResults results, - Iterator tuples, - long numRows ) { - super(context, query, results, tuples, numRows); - } - - @Override - protected Row createRow( Node node, - Object[] tuple ) { - return new JcrSqlQueryResultRow(this, node, tuple); - } - } - - protected static class JcrSqlQueryResultRow extends SingleSelectorQueryResultRow { - protected JcrSqlQueryResultRow( SingleSelectorQueryResultRowIterator iterator, - Node node, - Object[] tuple ) { - super(iterator, node, tuple); - } - - /** - * {@inheritDoc} - * - * @see javax.jcr.query.Row#getValue(java.lang.String) - */ - @Override - public Value getValue( String columnName ) throws ItemNotFoundException, RepositoryException { - if (JCR_PATH_COLUMN_NAME.equals(columnName)) { - Location location = (Location)tuple[iterator.locationIndex]; - return iterator.jcrPath(location.getPath()); - } - if (JCR_SCORE_COLUMN_NAME.equals(columnName)) { - Float score = (Float)tuple[iterator.scoreIndex]; - return iterator.jcrDouble(score); - } - return super.getValue(columnName); - } + return new SingleSelectorQueryResultRowIterator(context, queryStatement, results, tuples.iterator(), numRows); } } Index: modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java =================================================================== --- modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java (revision 2343) +++ modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java (working copy) @@ -561,7 +561,7 @@ public class JcrQueryManagerTest { @FixFor( "MODE-934" ) @Test - public void shouldParseQueryWithUnqualifiedPathInSelect() throws RepositoryException { + public void shouldParseQueryWithUnqualifiedPathInSelectOfJcrSql2Query() throws RepositoryException { Query query = session.getWorkspace().getQueryManager().createQuery("select [jcr:primaryType], [jcr:path] FROM [nt:base]", Query.JCR_SQL2); assertThat(query, is(notNullValue())); @@ -579,7 +579,7 @@ public class JcrQueryManagerTest { @FixFor( "MODE-934" ) @Test - public void shouldParseQueryWithUnqualifiedPathInSelectAndCriteria() throws RepositoryException { + public void shouldParseQueryWithUnqualifiedPathInSelectAndCriteriaOfJcrSql2Query() throws RepositoryException { Query query = session.getWorkspace() .getQueryManager() .createQuery("select [jcr:primaryType], [jcr:path] FROM [nt:base] WHERE [jcr:path] LIKE '/Cars/%'", @@ -599,7 +599,8 @@ public class JcrQueryManagerTest { @FixFor( "MODE-934" ) @Test - public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedNameInCriteria() throws RepositoryException { + public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedNameInCriteriaOfJcrSql2Query() + throws RepositoryException { Query query = session.getWorkspace() .getQueryManager() .createQuery("select [jcr:primaryType], [jcr:path] FROM [nt:base] WHERE [jcr:name] LIKE '%3%'", @@ -619,7 +620,8 @@ public class JcrQueryManagerTest { @FixFor( "MODE-934" ) @Test - public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedLocalNameInCriteria() throws RepositoryException { + public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedLocalNameInCriteriaOfJcrSql2Query() + throws RepositoryException { Query query = session.getWorkspace() .getQueryManager() .createQuery("select [jcr:primaryType], [jcr:path] FROM [nt:base] WHERE [mode:localName] LIKE '%3%'", @@ -639,7 +641,7 @@ public class JcrQueryManagerTest { @FixFor( "MODE-934" ) @Test - public void shouldParseQueryWithJcrPathInJoinCriteria() throws RepositoryException { + public void shouldParseQueryWithJcrPathInJoinCriteriaOfJcrSql2Query() throws RepositoryException { Query query = session.getWorkspace() .getQueryManager() .createQuery("select base.[jcr:primaryType], base.[jcr:path], car.[car:year] " @@ -660,7 +662,7 @@ public class JcrQueryManagerTest { @FixFor( "MODE-934" ) @Test - public void shouldNotIncludePseudoColumnsInSelectStar() throws RepositoryException { + public void shouldNotIncludePseudoColumnsInSelectStarOfJcrSql2Query() throws RepositoryException { Query query = session.getWorkspace().getQueryManager().createQuery("select * FROM [nt:base]", Query.JCR_SQL2); assertThat(query, is(notNullValue())); // print = true; @@ -808,6 +810,128 @@ public class JcrQueryManagerTest { } } + @SuppressWarnings( "deprecation" ) + @FixFor( "MODE-934" ) + @Test + public void shouldParseQueryWithUnqualifiedPathInSelectOfJcrSqlQuery() throws RepositoryException { + Query query = session.getWorkspace().getQueryManager().createQuery("select jcr:primaryType, jcr:path FROM nt:base", + Query.SQL); + assertThat(query, is(notNullValue())); + // print = true; + QueryResult result = query.execute(); + assertThat(result, is(notNullValue())); + assertResults(query, result, 24); + assertResultsHaveColumns(result, new String[] {"jcr:primaryType", "jcr:path", "jcr:score"}); + RowIterator iter = result.getRows(); + while (iter.hasNext()) { + Row row = iter.nextRow(); + assertThat(row, is(notNullValue())); + } + } + + @SuppressWarnings( "deprecation" ) + @FixFor( "MODE-934" ) + @Test + public void shouldParseQueryWithUnqualifiedPathInSelectAndCriteriaOfJcrSqlQuery() throws RepositoryException { + Query query = session.getWorkspace() + .getQueryManager() + .createQuery("select jcr:primaryType, jcr:path FROM nt:base WHERE jcr:path LIKE '/Cars/%'", + Query.SQL); + assertThat(query, is(notNullValue())); + // print = true; + QueryResult result = query.execute(); + assertThat(result, is(notNullValue())); + assertResults(query, result, 17); + assertResultsHaveColumns(result, new String[] {"jcr:primaryType", "jcr:path", "jcr:score"}); + RowIterator iter = result.getRows(); + while (iter.hasNext()) { + Row row = iter.nextRow(); + assertThat(row, is(notNullValue())); + } + } + + @SuppressWarnings( "deprecation" ) + @FixFor( "MODE-934" ) + @Test + public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedNameInCriteriaOfJcrSqlQuery() throws RepositoryException { + Query query = session.getWorkspace() + .getQueryManager() + .createQuery("select jcr:primaryType, jcr:path FROM nt:base WHERE jcr:name LIKE '%3%'", Query.SQL); + assertThat(query, is(notNullValue())); + // print = true; + QueryResult result = query.execute(); + assertThat(result, is(notNullValue())); + assertResults(query, result, 4); + assertResultsHaveColumns(result, new String[] {"jcr:primaryType", "jcr:path", "jcr:score"}); + RowIterator iter = result.getRows(); + while (iter.hasNext()) { + Row row = iter.nextRow(); + assertThat(row, is(notNullValue())); + } + } + + @SuppressWarnings( "deprecation" ) + @FixFor( "MODE-934" ) + @Test + public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedLocalNameInCriteriaOfJcrSqlQuery() + throws RepositoryException { + Query query = session.getWorkspace() + .getQueryManager() + .createQuery("select jcr:primaryType, jcr:path FROM nt:base WHERE mode:localName LIKE '%3%'", + Query.SQL); + assertThat(query, is(notNullValue())); + // print = true; + QueryResult result = query.execute(); + assertThat(result, is(notNullValue())); + assertResults(query, result, 4); + assertResultsHaveColumns(result, new String[] {"jcr:primaryType", "jcr:path", "jcr:score"}); + RowIterator iter = result.getRows(); + while (iter.hasNext()) { + Row row = iter.nextRow(); + assertThat(row, is(notNullValue())); + } + } + + @SuppressWarnings( "deprecation" ) + @FixFor( "MODE-934" ) + @Test + public void shouldParseQueryWithJcrPathInJoinCriteriaOfJcrSqlQuery() throws RepositoryException { + Query query = session.getWorkspace() + .getQueryManager() + .createQuery("select nt:base.jcr:primaryType, nt:base.jcr:path, car:Car.car:year " + + "FROM nt:base, car:Car WHERE car:Car.jcr:path = nt:base.jcr:path", + Query.SQL); + assertThat(query, is(notNullValue())); + // print = true; + QueryResult result = query.execute(); + assertThat(result, is(notNullValue())); + assertResults(query, result, 13); + assertResultsHaveColumns(result, new String[] {"jcr:primaryType", "jcr:path", "car:year", "jcr:path", "jcr:score"}); + RowIterator iter = result.getRows(); + while (iter.hasNext()) { + Row row = iter.nextRow(); + assertThat(row, is(notNullValue())); + } + } + + @SuppressWarnings( "deprecation" ) + @FixFor( "MODE-934" ) + @Test + public void shouldNotIncludePseudoColumnsInSelectStarOfJcrSqlQuery() throws RepositoryException { + Query query = session.getWorkspace().getQueryManager().createQuery("select * FROM nt:base", Query.SQL); + assertThat(query, is(notNullValue())); + // print = true; + QueryResult result = query.execute(); + assertThat(result, is(notNullValue())); + assertResults(query, result, 24); + assertResultsHaveColumns(result, new String[] {"jcr:primaryType", "jcr:path", "jcr:score"}); + RowIterator iter = result.getRows(); + while (iter.hasNext()) { + Row row = iter.nextRow(); + assertThat(row, is(notNullValue())); + } + } + // ---------------------------------------------------------------------------------------------------------------- // XPath Queries // ----------------------------------------------------------------------------------------------------------------