summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Schumacher <jeffschu@google.com>2010-05-28 16:26:50 -0700
committerShawn O. Pearce <sop@google.com>2010-05-28 17:10:33 -0700
commitcf066607cacb6f1e182812e422b9115735a46e1d (patch)
treee6634b6e808a5c5028ca80b8c9320242b8a2a577
parent4c894aab66d9a98d8105edec826e706eb333eb11 (diff)
downloadgwtorm-cf066607cacb6f1e182812e422b9115735a46e1d.tar.gz
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
-rw-r--r--src/main/antlr/com/google/gwtorm/schema/Query.g16
-rw-r--r--src/main/java/com/google/gwtorm/client/Query.java2
-rw-r--r--src/main/java/com/google/gwtorm/schema/QueryModel.java9
-rw-r--r--src/test/java/com/google/gwtorm/data/PersonAccess.java4
-rw-r--r--src/test/java/com/google/gwtorm/schema/QueryParserTest.java31
-rw-r--r--src/test/java/com/google/gwtorm/server/PhoneBookDbTestCase.java15
6 files changed, 14 insertions, 63 deletions
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 @@ tokens {
ID;
PLACEHOLDER;
COMMA;
- ASC;
- DESC;
LIMIT;
CONSTANT_INTEGER;
CONSTANT_STRING;
@@ -150,17 +148,7 @@ where
;
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 @@ WHERE: 'WHERE' ;
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 @@ import java.lang.annotation.Target;
*
* <pre>
* [WHERE &lt;condition&gt; [AND &lt;condition&gt; ...]]
- * [ORDER BY &lt;property&gt; [ASC | DESC] [, &lt;property&gt; [ASC | DESC] ...]]
+ * [ORDER BY &lt;property&gt; [, &lt;property&gt; ...]]
* [LIMIT { &lt;count&gt; | ? }]
*
* &lt;condition&gt; := &lt;property&gt; { &lt; | &lt;= | &gt; | &gt;= | = | != } &lt;value&gt;
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 @@ public class QueryModel {
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 @@ public class QueryModel {
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 @@ public class QueryModel {
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 @@ public interface PersonAccess extends Access<TestPerson, TestPerson.Key> {
@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 @@ public class QueryParserTest extends TestCase {
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 @@ public class QueryParserTest extends TestCase {
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 @@ public class PhoneBookDbTestCase extends TestCase {
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);