Remove support for @Query ORDER BY ASC / DESC
Some NoSQL-type products cannot perform an ORDER BY x DESC in
a query. Remove support for it in gwtorm so that applications
don't try to take advantage of a feature that isn't fully portable.
Change-Id: I8fe011dbaa389ddbcfdb4a8ddee0102569213f7a
diff --git a/src/main/antlr/com/google/gwtorm/schema/Query.g b/src/main/antlr/com/google/gwtorm/schema/Query.g
index ce13198..b5e7a49 100644
--- a/src/main/antlr/com/google/gwtorm/schema/Query.g
+++ b/src/main/antlr/com/google/gwtorm/schema/Query.g
@@ -32,8 +32,6 @@
ID;
PLACEHOLDER;
COMMA;
- ASC;
- DESC;
LIMIT;
CONSTANT_INTEGER;
CONSTANT_STRING;
@@ -150,17 +148,7 @@
;
orderBy
- : ORDER^ BY! fieldSort (COMMA! fieldSort)*
- ;
-
-fieldSort
- : field sortDirection^
- | field -> ^(ASC field)
- ;
-
-sortDirection
- : ASC
- | DESC
+ : ORDER^ BY! field (COMMA! field)*
;
limit
@@ -214,8 +202,6 @@
ORDER: 'ORDER' ;
BY: 'BY' ;
AND: 'AND' ;
-ASC: 'ASC' ;
-DESC: 'DESC' ;
LIMIT: 'LIMIT' ;
TRUE: 'true' ;
FALSE: 'false' ;
diff --git a/src/main/java/com/google/gwtorm/client/Query.java b/src/main/java/com/google/gwtorm/client/Query.java
index 6e7bc9a..d22324f 100644
--- a/src/main/java/com/google/gwtorm/client/Query.java
+++ b/src/main/java/com/google/gwtorm/client/Query.java
@@ -35,7 +35,7 @@
*
* <pre>
* [WHERE <condition> [AND <condition> ...]]
- * [ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
+ * [ORDER BY <property> [, <property> ...]]
* [LIMIT { <count> | ? }]
*
* <condition> := <property> { < | <= | > | >= | = | != } <value>
diff --git a/src/main/java/com/google/gwtorm/schema/QueryModel.java b/src/main/java/com/google/gwtorm/schema/QueryModel.java
index c24bc2b..d737f16 100644
--- a/src/main/java/com/google/gwtorm/schema/QueryModel.java
+++ b/src/main/java/com/google/gwtorm/schema/QueryModel.java
@@ -220,8 +220,7 @@
case QueryParser.ORDER:
fmt.buf.append(" ORDER BY ");
for (int i = 0; i < node.getChildCount(); i++) {
- final Tree sortOrder = node.getChild(i);
- final Tree id = sortOrder.getChild(0);
+ final Tree id = node.getChild(i);
if (i > 0) {
fmt.buf.append(',');
}
@@ -232,9 +231,6 @@
fmt.buf.append(fmt.tableAlias);
fmt.buf.append('.');
fmt.buf.append(cItr.next().getColumnName());
- if (sortOrder.getType() == QueryParser.DESC) {
- fmt.buf.append(" DESC");
- }
if (cItr.hasNext()) {
fmt.buf.append(',');
}
@@ -243,9 +239,6 @@
fmt.buf.append(fmt.tableAlias);
fmt.buf.append('.');
fmt.buf.append(col.getColumnName());
- if (sortOrder.getType() == QueryParser.DESC) {
- fmt.buf.append(" DESC");
- }
}
}
break;
diff --git a/src/test/java/com/google/gwtorm/data/PersonAccess.java b/src/test/java/com/google/gwtorm/data/PersonAccess.java
index 7df107e..594d588 100644
--- a/src/test/java/com/google/gwtorm/data/PersonAccess.java
+++ b/src/test/java/com/google/gwtorm/data/PersonAccess.java
@@ -30,10 +30,6 @@
@Query("WHERE age > ? ORDER BY age")
ResultSet<TestPerson> olderThan(int age) throws OrmException;
- @Query("WHERE name != ? AND age > ? ORDER BY name DESC")
- ResultSet<TestPerson> notPerson(TestPerson.Key key, int age)
- throws OrmException;
-
@Query("WHERE name = 'bob' LIMIT ?")
ResultSet<TestPerson> firstNBob(int n) throws OrmException;
diff --git a/src/test/java/com/google/gwtorm/schema/QueryParserTest.java b/src/test/java/com/google/gwtorm/schema/QueryParserTest.java
index c050ede..01e12b6 100644
--- a/src/test/java/com/google/gwtorm/schema/QueryParserTest.java
+++ b/src/test/java/com/google/gwtorm/schema/QueryParserTest.java
@@ -120,33 +120,27 @@
assertEquals(1, t.getChildCount());
final Tree a = t.getChild(0);
- assertEquals(QueryParser.ASC, a.getType());
- assertEquals(1, a.getChildCount());
- assertEquals(QueryParser.ID, a.getChild(0).getType());
- assertTrue(a.getChild(0) instanceof QueryParser.Column);
- assertEquals("a", a.getChild(0).getText());
+ assertEquals(QueryParser.ID, a.getType());
+ assertTrue(a instanceof QueryParser.Column);
+ assertEquals("a", a.getText());
}
public void testOrderByAB() throws QueryParseException {
- final Tree t = parse("ORDER BY a DESC, b ASC");
+ final Tree t = parse("ORDER BY a, b");
assertNotNull(t);
assertEquals(QueryParser.ORDER, t.getType());
assertEquals(2, t.getChildCount());
{
final Tree a = t.getChild(0);
- assertEquals(QueryParser.DESC, a.getType());
- assertEquals(1, a.getChildCount());
- assertEquals(QueryParser.ID, a.getChild(0).getType());
- assertTrue(a.getChild(0) instanceof QueryParser.Column);
- assertEquals("a", a.getChild(0).getText());
+ assertEquals(QueryParser.ID, a.getType());
+ assertTrue(a instanceof QueryParser.Column);
+ assertEquals("a", a.getText());
}
{
final Tree b = t.getChild(1);
- assertEquals(QueryParser.ASC, b.getType());
- assertEquals(1, b.getChildCount());
- assertEquals(QueryParser.ID, b.getChild(0).getType());
- assertTrue(b.getChild(0) instanceof QueryParser.Column);
- assertEquals("b", b.getChild(0).getText());
+ assertEquals(QueryParser.ID, b.getType());
+ assertTrue(b instanceof QueryParser.Column);
+ assertEquals("b", b.getText());
}
}
@@ -166,10 +160,7 @@
assertEquals(QueryParser.ORDER, o.getType());
assertEquals(1, o.getChildCount());
- final Tree a = o.getChild(0);
- assertEquals(QueryParser.ASC, a.getType());
- assertEquals(1, a.getChildCount());
- final Tree aId = a.getChild(0);
+ final Tree aId = o.getChild(0);
assertEquals(QueryParser.ID, aId.getType());
assertTrue(aId instanceof QueryParser.Column);
assertEquals("a", aId.getText());
diff --git a/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java b/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java
index 2099303..c3f5c08 100644
--- a/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java
+++ b/src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java
@@ -279,21 +279,6 @@
assertEquals(all.get(2).name(), r.get(1).name());
}
- public void testFetchNotPerson() throws Exception {
- final PhoneBookDb schema = openAndCreate();
- final ArrayList<TestPerson> all = new ArrayList<TestPerson>();
- all.add(new TestPerson(new TestPerson.Key("Bob"), 18));
- all.add(new TestPerson(new TestPerson.Key("Mary"), 22));
- all.add(new TestPerson(new TestPerson.Key("Zak"), 33));
- schema.people().insert(all);
-
- final List<TestPerson> r =
- schema.people().notPerson(new TestPerson.Key("Mary"), 10).toList();
- assertEquals(2, r.size());
- assertEquals(all.get(2).name(), r.get(0).name());
- assertEquals(all.get(0).name(), r.get(1).name());
- }
-
public void testBooleanType() throws Exception {
final PhoneBookDb schema = openAndCreate();
final TestPerson bob = new TestPerson(new TestPerson.Key("Bob"), 18);