From: James Moger Date: Mon, 4 Apr 2016 23:32:44 +0000 (-0400) Subject: Fixes #21: Order by descending on primitives X-Git-Tag: release-2.0.0~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2523ad5454716a9e08f0d3220a92760aa50773e2;p=iciql.git Fixes #21: Order by descending on primitives --- diff --git a/releases.moxie b/releases.moxie index 6a448cb..3630f1d 100644 --- a/releases.moxie +++ b/releases.moxie @@ -10,6 +10,7 @@ r30: { text: ~ security: ~ fixes: + - Fixed order by descending on primitives (issue-21) - Fixed setting null column values (issue-22) - Fixed Postgres 9.5 Upsert syntax (issue-23) changes: ~ 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 { return this; } + public Query orderByDesc(byte field) { + return orderByDescPrimitive(field); + } + + public Query orderByDesc(short field) { + return orderByDescPrimitive(field); + } + + public Query orderByDesc(int field) { + return orderByDescPrimitive(field); + } + + public Query orderByDesc(long field) { + return orderByDescPrimitive(field); + } + + public Query orderByDesc(float field) { + return orderByDescPrimitive(field); + } + + public Query orderByDesc(double field) { + return orderByDescPrimitive(field); + } + + Query orderByDescPrimitive(Object field) { + Object alias = getPrimitiveAliasByValue(field); + if (alias == null) { + return orderByDesc(field); + } + return orderByDesc(alias); + } + public Query orderByDesc(Object expr) { OrderExpression e = new OrderExpression(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 models = PrimitivesModel.getList(); - PrimitivesModel model = models.get(0); Collections.reverse(models); // insert them in reverse order db.insertAll(models); PrimitivesModel p = new PrimitivesModel(); - List list = db.from(p)/*.orderByDesc(p.myLong)*/.select(p.myLong); + List 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()); } }