diff options
author | James Moger <james.moger@gitblit.com> | 2016-04-04 19:32:44 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2016-04-04 19:32:44 -0400 |
commit | 2523ad5454716a9e08f0d3220a92760aa50773e2 (patch) | |
tree | 71a5404dfdaadcef114fa27ebc47b7023b371f3f /src | |
parent | 27979f07905dbf95b478a48babc99643d71bfdec (diff) | |
download | iciql-2523ad5454716a9e08f0d3220a92760aa50773e2.tar.gz iciql-2523ad5454716a9e08f0d3220a92760aa50773e2.zip |
Fixes #21: Order by descending on primitives
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/iciql/Query.java | 32 | ||||
-rw-r--r-- | src/test/java/com/iciql/test/ModelsTest.java | 2 | ||||
-rw-r--r-- | src/test/java/com/iciql/test/PrimitivesTest.java | 5 |
3 files changed, 35 insertions, 4 deletions
diff --git a/src/main/java/com/iciql/Query.java b/src/main/java/com/iciql/Query.java index f8fd4ca..7a8a1ff 100644 --- a/src/main/java/com/iciql/Query.java +++ b/src/main/java/com/iciql/Query.java @@ -736,6 +736,38 @@ public class Query<T> { return this; } + public Query<T> orderByDesc(byte field) { + return orderByDescPrimitive(field); + } + + public Query<T> orderByDesc(short field) { + return orderByDescPrimitive(field); + } + + public Query<T> orderByDesc(int field) { + return orderByDescPrimitive(field); + } + + public Query<T> orderByDesc(long field) { + return orderByDescPrimitive(field); + } + + public Query<T> orderByDesc(float field) { + return orderByDescPrimitive(field); + } + + public Query<T> orderByDesc(double field) { + return orderByDescPrimitive(field); + } + + Query<T> orderByDescPrimitive(Object field) { + Object alias = getPrimitiveAliasByValue(field); + if (alias == null) { + return orderByDesc(field); + } + return orderByDesc(alias); + } + public Query<T> orderByDesc(Object expr) { OrderExpression<T> e = new OrderExpression<T>(this, expr, true, false, false); addOrderBy(e); diff --git a/src/test/java/com/iciql/test/ModelsTest.java b/src/test/java/com/iciql/test/ModelsTest.java index a5474df..4230f4e 100644 --- a/src/test/java/com/iciql/test/ModelsTest.java +++ b/src/test/java/com/iciql/test/ModelsTest.java @@ -173,6 +173,6 @@ public class ModelsTest { .orderByDesc(SupportedTypes.SAMPLE.id) .selectDistinct(SupportedTypes.SAMPLE.id); assertEquals(10, ids.size()); - assertEquals("[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]", ids.toString()); + assertEquals("[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]", ids.toString()); } } diff --git a/src/test/java/com/iciql/test/PrimitivesTest.java b/src/test/java/com/iciql/test/PrimitivesTest.java index 938fd32..6250649 100644 --- a/src/test/java/com/iciql/test/PrimitivesTest.java +++ b/src/test/java/com/iciql/test/PrimitivesTest.java @@ -106,14 +106,13 @@ public class PrimitivesTest { // insert random models in reverse order
List<PrimitivesModel> models = PrimitivesModel.getList();
- PrimitivesModel model = models.get(0);
Collections.reverse(models);
// insert them in reverse order
db.insertAll(models);
PrimitivesModel p = new PrimitivesModel();
- List<Long> list = db.from(p)/*.orderByDesc(p.myLong)*/.select(p.myLong);
+ List<Long> list = db.from(p).orderByDesc(p.myLong).select(p.myLong);
assertEquals(models.size(), list.size());
- assertEquals("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", list.toString());
+ assertEquals("[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]", list.toString());
}
}
|