%BEGINCODE%\r
final Customer c = new Customer();\r
final Order o = new Order();\r
+\r
+List<Customer> customersWithLargeOrders =\r
+ db.from(c).\r
+ innerJoin(o).on(c.customerId).is(o.customerId).\r
+ where(o.total).greaterThan(new BigDecimal("500.00")).\r
+ groupBy(c.customerId).select();\r
+\r
+\r
List<CustOrder> orders =\r
db.from(c).\r
innerJoin(o).on(c.customerId).is(o.customerId).\r
\r
- Fixed joins on primitives\r
- Fixed group by on primitives\r
+- Improved fluent/type-safety of joins\r
\r
### Older Releases\r
\r
*/\r
\r
@SuppressWarnings({ "unchecked", "rawtypes" })\r
- public <U> QueryJoin innerJoin(U alias) {\r
+ public <A> QueryJoin<T> innerJoin(A alias) {\r
TableDefinition<T> def = (TableDefinition<T>) db.define(alias.getClass());\r
SelectTable<T> join = new SelectTable(db, this, alias, false);\r
def.initSelectObject(join, alias, aliasMap);\r
* This class represents a query with a join.\r
*/\r
\r
-public class QueryJoin {\r
+public class QueryJoin<T> {\r
\r
- private Query<?> query;\r
- private SelectTable<?> join;\r
+ private Query<T> query;\r
+ private SelectTable<T> join;\r
\r
- QueryJoin(Query<?> query, SelectTable<?> join) {\r
+ QueryJoin(Query<T> query, SelectTable<T> join) {\r
this.query = query;\r
this.join = join;\r
}\r
\r
- public QueryJoinCondition<Boolean> on(boolean x) {\r
+ public QueryJoinCondition<T, Boolean> on(boolean x) {\r
return addPrimitive(x);\r
}\r
\r
- public QueryJoinCondition<Byte> on(byte x) {\r
+ public QueryJoinCondition<T, Byte> on(byte x) {\r
return addPrimitive(x);\r
}\r
\r
- public QueryJoinCondition<Short> on(short x) {\r
+ public QueryJoinCondition<T, Short> on(short x) {\r
return addPrimitive(x);\r
}\r
\r
- public QueryJoinCondition<Integer> on(int x) {\r
+ public QueryJoinCondition<T, Integer> on(int x) {\r
return addPrimitive(x);\r
}\r
\r
- public QueryJoinCondition<Long> on(long x) {\r
+ public QueryJoinCondition<T, Long> on(long x) {\r
return addPrimitive(x);\r
}\r
\r
- public QueryJoinCondition<Float> on(float x) {\r
+ public QueryJoinCondition<T, Float> on(float x) {\r
return addPrimitive(x);\r
}\r
\r
- public QueryJoinCondition<Double> on(double x) {\r
+ public QueryJoinCondition<T, Double> on(double x) {\r
return addPrimitive(x);\r
}\r
\r
- private <A> QueryJoinCondition<A> addPrimitive(A x) { \r
+ private <A> QueryJoinCondition<T, A> addPrimitive(A x) { \r
A alias = query.getPrimitiveAliasByValue(x);\r
if (alias == null) {\r
// this will result in an unmapped field exception\r
- return new QueryJoinCondition<A>(query, join, x);\r
+ return new QueryJoinCondition<T, A>(query, join, x);\r
}\r
- return new QueryJoinCondition<A>(query, join, alias);\r
+ return new QueryJoinCondition<T, A>(query, join, alias);\r
}\r
\r
- public <A> QueryJoinCondition<A> on(A x) {\r
- return new QueryJoinCondition<A>(query, join, x);\r
+ public <A> QueryJoinCondition<T, A> on(A x) {\r
+ return new QueryJoinCondition<T, A>(query, join, x);\r
}\r
}\r
* the incomplete condition data type\r
*/\r
\r
-public class QueryJoinCondition<A> {\r
+public class QueryJoinCondition<T, A> {\r
\r
- private Query<?> query;\r
- private SelectTable<?> join;\r
+ private Query<T> query;\r
+ private SelectTable<T> join;\r
private A x;\r
\r
- QueryJoinCondition(Query<?> query, SelectTable<?> join, A x) {\r
+ QueryJoinCondition(Query<T> query, SelectTable<T> join, A x) {\r
this.query = query;\r
this.join = join;\r
this.x = x;\r
}\r
\r
- public Query<?> is(boolean y) {\r
+ public Query<T> is(boolean y) {\r
return addPrimitive(y);\r
} \r
\r
- public Query<?> is(byte y) {\r
+ public Query<T> is(byte y) {\r
return addPrimitive(y);\r
} \r
\r
- public Query<?> is(short y) {\r
+ public Query<T> is(short y) {\r
return addPrimitive(y);\r
} \r
\r
- public Query<?> is(int y) {\r
+ public Query<T> is(int y) {\r
return addPrimitive(y);\r
}\r
\r
- public Query<?> is(long y) {\r
+ public Query<T> is(long y) {\r
return addPrimitive(y);\r
} \r
\r
- public Query<?> is(float y) {\r
+ public Query<T> is(float y) {\r
return addPrimitive(y);\r
} \r
\r
- public Query<?> is(double y) {\r
+ public Query<T> is(double y) {\r
return addPrimitive(y);\r
} \r
\r
@SuppressWarnings("unchecked")\r
- private Query<?> addPrimitive(Object o) { \r
+ private Query<T> addPrimitive(Object o) { \r
A alias = query.getPrimitiveAliasByValue((A) o);\r
if (alias == null) {\r
join.addConditionToken(new Condition<A>(x, (A) o, CompareType.EQUAL));\r
return query; \r
}\r
\r
- public Query<?> is(A y) {\r
+ public Query<T> is(A y) {\r
join.addConditionToken(new Condition<A>(x, y, CompareType.EQUAL));\r
return query;\r
}\r
import com.iciql.Db;
import com.iciql.Iciql.IQColumn;
import com.iciql.Iciql.IQTable;
-import com.iciql.util.IciqlLogger;
/**
* Tests of Joins.
final UserNote n = new UserNote();
// this query returns 1 UserId if the user has a note
- List<UserId> users = (List<UserId>) db.from(u).innerJoin(n).on(u.id).is(n.userId).groupBy(u.id).where(u.id).is(2).select();
+ List<UserId> users = db.from(u).innerJoin(n).on(u.id).is(n.userId).groupBy(u.id).where(u.id).is(2).select();
db.dropTable(UserId.class);
db.dropTable(UserNote.class);