From cb29e503658e2a3339c265651a869fcbe0d5bd7d Mon Sep 17 00:00:00 2001 From: Taichi Uragami Date: Fri, 6 Apr 2012 23:52:39 +0900 Subject: [PATCH] Added support for left outer join. --- src/com/iciql/Query.java | 9 +++++++++ tests/com/iciql/test/JoinTest.java | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/com/iciql/Query.java b/src/com/iciql/Query.java index aa0ce4b..9aefe27 100644 --- a/src/com/iciql/Query.java +++ b/src/com/iciql/Query.java @@ -845,6 +845,15 @@ public class Query { return new QueryJoin(this, join); } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public QueryJoin leftJoin(A alias) { + TableDefinition def = (TableDefinition) db.define(alias.getClass()); + SelectTable join = new SelectTable(db, this, alias, true); + def.initSelectObject(join, alias, aliasMap); + joins.add(join); + return new QueryJoin(this, join); + } + Db getDb() { return db; } diff --git a/tests/com/iciql/test/JoinTest.java b/tests/com/iciql/test/JoinTest.java index 07de098..1fea444 100644 --- a/tests/com/iciql/test/JoinTest.java +++ b/tests/com/iciql/test/JoinTest.java @@ -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 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 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); } } -- 2.39.5