Index: modeshape-graph/src/main/java/org/modeshape/graph/query/parse/SqlQueryParser.java =================================================================== --- modeshape-graph/src/main/java/org/modeshape/graph/query/parse/SqlQueryParser.java (revision 1901) +++ modeshape-graph/src/main/java/org/modeshape/graph/query/parse/SqlQueryParser.java (working copy) @@ -930,7 +930,7 @@ public class SqlQueryParser implements QueryParser { if (tokens.canConsume("CAST", "(")) { // Get the value that is to be cast ... Position pos = tokens.nextPosition(); - String value = parseLiteralValue(tokens, typeSystem); + Object value = parseLiteralValue(tokens, typeSystem); // Figure out the type we're supposed to cast to ... tokens.consume("AS"); String typeName = tokens.consume(); @@ -958,7 +958,7 @@ public class SqlQueryParser implements QueryParser { return literal(typeSystem, parseLiteralValue(tokens, typeSystem)); } - protected String parseLiteralValue( TokenStream tokens, + protected Object parseLiteralValue( TokenStream tokens, TypeSystem typeSystem ) { if (tokens.matches(SqlTokenizer.QUOTED_STRING)) { return removeBracketsAndQuotes(tokens.consume()); Index: modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrSqlQueryParser.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrSqlQueryParser.java (revision 1901) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/query/JcrSqlQueryParser.java (working copy) @@ -670,7 +670,7 @@ public class JcrSqlQueryParser extends SqlQueryParser { * org.modeshape.graph.query.model.TypeSystem) */ @Override - protected String parseLiteralValue( TokenStream tokens, + protected Object parseLiteralValue( TokenStream tokens, TypeSystem typeSystem ) { if (tokens.canConsume("TIMESTAMP")) { Position pos = tokens.previousPosition(); @@ -680,7 +680,8 @@ public class JcrSqlQueryParser extends SqlQueryParser { try { // Convert to a date and then back to a string to get canonical form ... Object dateTime = dateTimeFactory.create(value); - return dateTimeFactory.asString(dateTime); + return dateTime; + // return dateTimeFactory.asString(dateTime); } catch (ValueFormatException e) { String msg = GraphI18n.expectingLiteralAndUnableToParseAsDate.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); Index: modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java =================================================================== --- modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java (revision 1901) +++ modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java (working copy) @@ -54,11 +54,11 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.modeshape.common.FixFor; import org.modeshape.graph.connector.inmemory.InMemoryRepositorySource; import org.modeshape.graph.property.Name; import org.modeshape.graph.property.Path.Segment; import org.modeshape.jcr.JcrRepository.Option; -import org.modeshape.jcr.JcrRepository.QueryLanguage; import org.modeshape.jcr.nodetype.InvalidNodeTypeDefinitionException; import org.modeshape.jcr.query.JcrQueryResult; @@ -87,7 +87,8 @@ public class JcrQueryManagerTest { protected static String[] carColumnNames() { return new String[] {"car:mpgCity", "car:lengthInInches", "car:maker", "car:userRating", "car:engine", "car:mpgHighway", - "car:valueRating", "jcr:primaryType", "car:wheelbaseInInches", "car:year", "car:model", "car:msrp"}; + "car:valueRating", "jcr:primaryType", "car:wheelbaseInInches", "car:year", "car:model", "car:msrp", "jcr:created", + "jcr:createdBy"}; } private static JcrConfiguration configuration; @@ -206,7 +207,7 @@ public class JcrQueryManagerTest { long numberOfResults ) throws RepositoryException { assertThat(query, is(notNullValue())); assertThat(result, is(notNullValue())); - if (print) { + if (print || result.getNodes().getSize() != numberOfResults || result.getRows().getSize() != numberOfResults) { System.out.println(); System.out.println(query); System.out.println(" plan -> " + ((JcrQueryResult)result).getPlan()); @@ -386,12 +387,13 @@ public class JcrQueryManagerTest { // JCR-SQL Queries // ---------------------------------------------------------------------------------------------------------------- + @SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToCreateAndExecuteSqlQueryWithOrderByClause() throws RepositoryException { Query query = session.getWorkspace() .getQueryManager() .createQuery("SELECT car:model FROM car:Car WHERE car:model IS NOT NULL ORDER BY car:model ASC", - QueryLanguage.JCR_SQL); + Query.SQL); assertThat(query, is(notNullValue())); QueryResult result = query.execute(); assertThat(result, is(notNullValue())); @@ -404,12 +406,13 @@ public class JcrQueryManagerTest { * * @throws RepositoryException */ + @SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToCreateAndExecuteSqlQueryWithChildAxisCriteria() throws RepositoryException { Query query = session.getWorkspace() .getQueryManager() .createQuery("SELECT * FROM nt:base WHERE jcr:path LIKE '/Cars/%' AND NOT jcr:path LIKE '/Cars/%/%'", - QueryLanguage.JCR_SQL); + Query.SQL); assertThat(query, is(notNullValue())); QueryResult result = query.execute(); assertThat(result, is(notNullValue())); @@ -422,12 +425,13 @@ public class JcrQueryManagerTest { * * @throws RepositoryException */ + @SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToCreateAndExecuteSqlQueryWithContainsCriteria() throws RepositoryException { Query query = session.getWorkspace() .getQueryManager() .createQuery("SELECT * FROM nt:base WHERE jcr:path LIKE '/Cars/%' AND NOT jcr:path LIKE '/Cars/%/%'", - QueryLanguage.JCR_SQL); + Query.SQL); assertThat(query, is(notNullValue())); QueryResult result = query.execute(); assertThat(result, is(notNullValue())); @@ -435,6 +439,28 @@ public class JcrQueryManagerTest { assertResultsHaveColumns(result, "jcr:path", "jcr:score", "jcr:primaryType"); } + @Test + @FixFor( "MODE-791" ) + @SuppressWarnings( "deprecation" ) + public void shouldReturnNodesWithPropertyConstrainedByTimestamp() throws Exception { + Query query = session.getWorkspace() + .getQueryManager() + .createQuery("SELECT car:model, car:maker FROM car:Car " + "WHERE jcr:path LIKE '/Cars/%' " + + "AND (car:msrp LIKE '$3%' OR car:msrp LIKE '$2') " + + "AND (car:year LIKE '2008' OR car:year LIKE '2009') " + "AND car:valueRating > '1' " + + "AND jcr:created > TIMESTAMP '1974-07-10T00:00:00.000-05:00' " + + "AND jcr:created < TIMESTAMP '3074-07-10T00:00:00.000-05:00'", + Query.SQL); + assertThat(query, is(notNullValue())); + QueryResult result = query.execute(); + assertThat(result, is(notNullValue())); + assertResults(query, result, 5); + + for (NodeIterator iter = result.getNodes(); iter.hasNext();) { + assertThat(iter.nextNode().hasProperty("car:model"), is(true)); + } + } + // ---------------------------------------------------------------------------------------------------------------- // XPath Queries // ---------------------------------------------------------------------------------------------------------------- @@ -606,6 +632,8 @@ public class JcrQueryManagerTest { "jcr:primaryType", "jcr:path", "jcr:score", + "jcr:created", + "jcr:createdBy", "car:mpgCity", "car:userRating", "car:mpgHighway", Index: modeshape-jcr/src/test/resources/cars.cnd =================================================================== --- modeshape-jcr/src/test/resources/cars.cnd (revision 1901) +++ modeshape-jcr/src/test/resources/cars.cnd (working copy) @@ -34,7 +34,7 @@ // N O D E T Y P E S //------------------------------------------------------------------------------ -[car:Car] > nt:unstructured +[car:Car] > nt:unstructured, mix:created - car:maker (string) - car:model (string) - car:year (string) < '(19|20)\d{2}' // any 4 digit number starting with '19' or '20'