Explorar el Código

Added support for left outer join.

tags/v1.0.0
Taichi Uragami hace 12 años
padre
commit
cb29e50365
Se han modificado 2 ficheros con 20 adiciones y 1 borrados
  1. 9
    0
      src/com/iciql/Query.java
  2. 11
    1
      tests/com/iciql/test/JoinTest.java

+ 9
- 0
src/com/iciql/Query.java Ver fichero

@@ -845,6 +845,15 @@ public class Query<T> {
return new QueryJoin(this, join);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public <A> QueryJoin<T> leftJoin(A alias) {
TableDefinition<T> def = (TableDefinition<T>) db.define(alias.getClass());
SelectTable<T> join = new SelectTable(db, this, alias, true);
def.initSelectObject(join, alias, aliasMap);
joins.add(join);
return new QueryJoin(this, join);
}
Db getDb() {
return db;
}

+ 11
- 1
tests/com/iciql/test/JoinTest.java Ver fichero

@@ -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);
}
}

Cargando…
Cancelar
Guardar