]> source.dussan.org Git - iciql.git/commitdiff
Added support for left outer join.
authorTaichi Uragami <backpaper0@gmail.com>
Fri, 6 Apr 2012 14:52:39 +0000 (23:52 +0900)
committerTaichi Uragami <backpaper0@gmail.com>
Fri, 6 Apr 2012 14:52:39 +0000 (23:52 +0900)
src/com/iciql/Query.java
tests/com/iciql/test/JoinTest.java

index aa0ce4b0617ecc45091bfb71623b7292e08c8fd9..9aefe27cdd22145928ce9abce9b84c8ebdcb706f 100644 (file)
@@ -845,6 +845,15 @@ public class Query<T> {
                return new QueryJoin(this, join);\r
        }\r
 \r
+    @SuppressWarnings({ "unchecked", "rawtypes" })\r
+    public <A> QueryJoin<T> leftJoin(A alias) {\r
+        TableDefinition<T> def = (TableDefinition<T>) db.define(alias.getClass());\r
+        SelectTable<T> join = new SelectTable(db, this, alias, true);\r
+        def.initSelectObject(join, alias, aliasMap);\r
+        joins.add(join);\r
+        return new QueryJoin(this, join);\r
+    }\r
+\r
        Db getDb() {\r
                return db;\r
        }\r
index 07de09824ccaf18e799f52b3472e9657ef41b695..1fea4440d78553203b6f55fb2c65a595e92ee1af 100644 (file)
@@ -81,6 +81,16 @@ public class JoinTest {
                assertEquals(2, users.get(0).id);
        }
 
+    @Test
+    public void testLeftJoin() throws Exception {
+        final UserId u = new UserId();
+        final UserNote n = new UserNote();
+
+        List<UserId> notes = db.from(u).leftJoin(n).on(u.id).is(n.userId).where(u.id).is(4).select();
+        assertEquals(1, notes.size());
+        assertEquals(4, notes.get(0).id);
+    }
+
        @IQTable
        public static class UserId {
 
@@ -104,7 +114,7 @@ public class JoinTest {
                }
 
                public static List<UserId> getList() {
-                       UserId[] list = { new UserId(1, "Tom"), new UserId(2, "Dick"), new UserId(3, "Harry") };
+                       UserId[] list = { new UserId(1, "Tom"), new UserId(2, "Dick"), new UserId(3, "Harry"), new UserId(4, "Jack") };
                        return Arrays.asList(list);
                }
        }