\r
**%VERSION%** ([zip](http://code.google.com/p/iciql/downloads/detail?name=%ZIP%)|[jar](http://code.google.com/p/iciql/downloads/detail?name=%JAR%)) *released %BUILDDATE%*\r
\r
+- Fixed joins on primitives\r
+\r
+### Older Releases\r
+\r
+**0.7.2** *released 2011-11-30*\r
+\r
- generated models are now serializable with a default serial version id of 1\r
- Updated to H2 1.3.162\r
- Updated to HSQL 2.2.6 (100% unit test pass now that [this bug](https://sourceforge.net/tracker/?func=detail&aid=3390047&group_id=23316&atid=378131) was fixed)\r
\r
-### Older Releases\r
-\r
**0.7.1** *released 2011-08-31*\r
\r
- api change release (API v7)\r
\r
// The build script extracts this exact line so be careful editing it\r
// and only use A-Z a-z 0-9 .-_ in the string.\r
- public static final String VERSION = "0.7.2";\r
+ public static final String VERSION = "0.7.3-SNAPSHOT";\r
\r
// The build script extracts this exact line so be careful editing it\r
// and only use A-Z a-z 0-9 .-_ in the string.\r
- public static final String VERSION_DATE = "2011-11-30";\r
+ public static final String VERSION_DATE = "PENDING";\r
\r
// The build script extracts this exact line so be careful editing it\r
// and only use A-Z a-z 0-9 .-_ in the string.\r
this.join = join;\r
}\r
\r
+ public QueryJoinCondition<Boolean> on(boolean x) {\r
+ return addPrimitive(x);\r
+ }\r
+\r
+ public QueryJoinCondition<Byte> on(byte x) {\r
+ return addPrimitive(x);\r
+ }\r
+\r
+ public QueryJoinCondition<Short> on(short x) {\r
+ return addPrimitive(x);\r
+ }\r
+\r
+ public QueryJoinCondition<Integer> on(int x) {\r
+ return addPrimitive(x);\r
+ }\r
+\r
+ public QueryJoinCondition<Long> on(long x) {\r
+ return addPrimitive(x);\r
+ }\r
+\r
+ public QueryJoinCondition<Float> on(float x) {\r
+ return addPrimitive(x);\r
+ }\r
+\r
+ public QueryJoinCondition<Double> on(double x) {\r
+ return addPrimitive(x);\r
+ }\r
+\r
+ private <A> QueryJoinCondition<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
+ }\r
+ return new QueryJoinCondition<A>(query, join, alias);\r
+ }\r
+\r
public <A> QueryJoinCondition<A> on(A x) {\r
return new QueryJoinCondition<A>(query, join, x);\r
}\r
\r
package com.iciql;\r
\r
+\r
/**\r
* This class represents a query with join and an incomplete condition.\r
* \r
this.x = x;\r
}\r
\r
+ public Query<?> is(boolean y) {\r
+ return addPrimitive(y);\r
+ } \r
+\r
+ public Query<?> is(byte y) {\r
+ return addPrimitive(y);\r
+ } \r
+\r
+ public Query<?> is(short y) {\r
+ return addPrimitive(y);\r
+ } \r
+\r
+ public Query<?> is(int y) {\r
+ return addPrimitive(y);\r
+ }\r
+ \r
+ public Query<?> is(long y) {\r
+ return addPrimitive(y);\r
+ } \r
+\r
+ public Query<?> is(float y) {\r
+ return addPrimitive(y);\r
+ } \r
+\r
+ public Query<?> is(double y) {\r
+ return addPrimitive(y);\r
+ } \r
+\r
+ @SuppressWarnings("unchecked")\r
+ private Query<?> 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
+ } else {\r
+ join.addConditionToken(new Condition<A>(x, alias, CompareType.EQUAL));\r
+ }\r
+ return query; \r
+ }\r
+\r
public Query<?> is(A y) {\r
join.addConditionToken(new Condition<A>(x, y, CompareType.EQUAL));\r
return query;\r
@RunWith(Suite.class)\r
@SuiteClasses({ AliasMapTest.class, AnnotationsTest.class, BooleanModelTest.class, ClobTest.class,\r
ConcurrencyTest.class, EnumsTest.class, ModelsTest.class, PrimitivesTest.class,\r
- RuntimeQueryTest.class, SamplesTest.class, UpdateTest.class, UpgradesTest.class, UUIDTest.class })\r
+ RuntimeQueryTest.class, SamplesTest.class, UpdateTest.class, UpgradesTest.class, JoinTest.class,\r
+ UUIDTest.class })\r
public class IciqlSuite {\r
\r
private static final TestDb[] TEST_DBS = {\r
--- /dev/null
+/*
+ * Copyright 2011 James Moger.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.iciql.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.iciql.Db;
+import com.iciql.Iciql.IQColumn;
+import com.iciql.Iciql.IQTable;
+
+/**
+ * Tests of Joins.
+ */
+public class JoinTest {
+
+ Db db;
+
+ @Before
+ public void setup() {
+ db = IciqlSuite.openNewDb();
+ }
+
+ @After
+ public void tearDown() {
+ db.close();
+ }
+
+ @Test
+ public void testPrimitiveJoin() throws Exception {
+ db.insertAll(UserId.getList());
+ db.insertAll(UserNote.getList());
+
+ final UserId u = new UserId();
+ final UserNote n = new UserNote();
+
+ List<UserNote> notes = db.from(u).innerJoin(n).on(u.id).is(n.userId).where(u.id).is(2)
+ .select(new UserNote() {
+ {
+ userId = n.userId;
+ noteId = n.noteId;
+ text = n.text;
+ }
+ });
+
+ db.dropTable(UserId.class);
+ db.dropTable(UserNote.class);
+
+ assertEquals(3, notes.size());
+ }
+
+ @IQTable
+ public static class UserId {
+
+ @IQColumn(primaryKey = true)
+ public int id;
+
+ @IQColumn(length = 10)
+ public String name;
+
+ public UserId() {
+ // public constructor
+ }
+
+ public UserId(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public String toString() {
+ return name + " (" + id + ")";
+ }
+
+ public static List<UserId> getList() {
+ UserId[] list = { new UserId(1, "Tom"), new UserId(2, "Dick"), new UserId(3, "Harry") };
+ return Arrays.asList(list);
+ }
+ }
+
+ @IQTable
+ public static class UserNote {
+
+ @IQColumn(autoIncrement = true, primaryKey = true)
+ public int noteId;
+
+ @IQColumn
+ public int userId;
+
+ @IQColumn(length = 10)
+ public String text;
+
+ public UserNote() {
+ // public constructor
+ }
+
+ public UserNote(int userId, String text) {
+ this.userId = userId;
+ this.text = text;
+ }
+
+ public String toString() {
+ return text;
+ }
+
+ public static List<UserNote> getList() {
+ UserNote[] list = { new UserNote(1, "A"), new UserNote(2, "B"), new UserNote(3, "C"),
+ new UserNote(1, "D"), new UserNote(2, "E"), new UserNote(3, "F"), new UserNote(1, "G"),
+ new UserNote(2, "H"), new UserNote(3, "I"), };
+ return Arrays.asList(list);
+ }
+ }
+}