]> source.dussan.org Git - iciql.git/commitdiff
Fixes #21: Order by descending on primitives
authorJames Moger <james.moger@gitblit.com>
Mon, 4 Apr 2016 23:32:44 +0000 (19:32 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 4 Apr 2016 23:32:44 +0000 (19:32 -0400)
releases.moxie
src/main/java/com/iciql/Query.java
src/test/java/com/iciql/test/ModelsTest.java
src/test/java/com/iciql/test/PrimitivesTest.java

index 6a448cbbe3e191a9c3f5bd2944293115c2e5b584..3630f1df28b91ac2dbb92a8eaa0ccf7711f7aac5 100644 (file)
@@ -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: ~
index f8fd4cae260e9ce99d87e14568cd2040c37c2864..7a8a1fffd68fa15737301cc20e9d2fa54c41550a 100644 (file)
@@ -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);
index a5474dfc60806d0fcb3651070aa464cc7fbf9037..4230f4e843de7ecaf987e4bd32315aae4c4758c2 100644 (file)
@@ -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());
        }
 }
index 938fd32ebe30cdcbcccc06d3e29fdf2ceb45d8fa..625064918f591b8338587df379841322517acbd7 100644 (file)
@@ -106,14 +106,13 @@ public class PrimitivesTest {
 \r
                // insert random models in reverse order\r
                List<PrimitivesModel> models = PrimitivesModel.getList();\r
-               PrimitivesModel model = models.get(0);\r
                Collections.reverse(models);\r
                // insert them in reverse order\r
                db.insertAll(models);\r
 \r
                PrimitivesModel p = new PrimitivesModel();\r
-               List<Long> list = db.from(p)/*.orderByDesc(p.myLong)*/.select(p.myLong);\r
+               List<Long> list = db.from(p).orderByDesc(p.myLong).select(p.myLong);\r
                assertEquals(models.size(), list.size());\r
-               assertEquals("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", list.toString());\r
+               assertEquals("[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]", list.toString());\r
        }\r
 }\r