/** * Add an inner {@link Join} to this query using the ON clause * * @param table the table to join on * @param onCriterions one or more criterions to use for the "on" clause * @return this Query object, to allow chaining method calls */ public Query innerJoin(SqlTable<?> table, Criterion... onCriterions) { return join(Join.inner(table, onCriterions)); }
/** * Add an inner {@link Join} to this query using the USING clause * * @param table the table to join on * @param usingColumns one or more columns to use for the "using" clause * @return this Query object, to allow chaining method calls */ public Query innerJoin(SqlTable<?> table, Property<?>... usingColumns) { return join(Join.inner(table, usingColumns)); }
public void testFunctionOnAmbiguousColumnName() { IntegerProperty happyCount = IntegerProperty.countProperty(Employee.IS_HAPPY, false); Query test = Query.select(TestModel.ID, TestModel.FIRST_NAME, TestModel.IS_HAPPY, happyCount) .join(Join.inner(Employee.TABLE, Employee.IS_HAPPY.eq(TestModel.IS_HAPPY))); // just test that the query compiles with the function database.query(TestModel.class, test); }
StringProperty managerName = Employee.NAME.as(managerTable, "managerName"); LongProperty managerId = managerTable.qualifyField(Employee.ID); Join join = Join.inner(managerTable, Employee.MANAGER_ID.eq(managerId)); Query query = Query.select(employeeName, managerName).from(Employee.TABLE).join(join).orderBy(managerId.asc());
/** * Add an inner {@link Join} to this query using the USING clause * * @param table the table to join on * @param usingColumns one or more columns to use for the "using" clause * @return this Query object, to allow chaining method calls */ public Query innerJoin(SqlTable<?> table, Property<?>... usingColumns) { return join(Join.inner(table, usingColumns)); }
/** * Add an inner {@link Join} to this query using the ON clause * * @param table the table to join on * @param onCriterions one or more criterions to use for the "on" clause * @return this Query object, to allow chaining method calls */ public Query innerJoin(SqlTable<?> table, Criterion... onCriterions) { return join(Join.inner(table, onCriterions)); }
public void testSubqueryJoin() { StringProperty managerName = Employee.NAME.as("managerName"); Query query = Query .fromSubquery(Query.select(Employee.MANAGER_ID).from(Employee.TABLE).groupBy(Employee.MANAGER_ID), "subquery"); query.selectMore(managerName); query.join(Join.inner(Employee.TABLE, query.getTable().qualifyField(Employee.MANAGER_ID).eq(Employee.ID))) .orderBy(Employee.MANAGER_ID.asc()); SquidCursor<Employee> cursor = database.query(Employee.class, query); try { assertEquals(3, cursor.getCount()); cursor.moveToFirst(); assertEquals("bigBird", cursor.get(managerName)); cursor.moveToNext(); assertEquals("cookieMonster", cursor.get(managerName)); cursor.moveToNext(); assertEquals("bert", cursor.get(managerName)); } finally { cursor.close(); } }
public void testJoinOnLiteralValue() { TestModel modelOne = new TestModel().setFirstName("Sam").setLastName("Bosley"); TestModel modelTwo = new TestModel().setFirstName("Kevin").setLastName("Lim"); TestModel modelThree = new TestModel().setFirstName("Jonathan").setLastName("Koren"); Thing thingOne = new Thing().setFoo("Thing1").setBar(5); Thing thingTwo = new Thing().setFoo("Thing2").setBar(-1); Thing thingThree = new Thing().setFoo("Thing3").setBar(100); database.persist(modelOne); database.persist(modelTwo); database.persist(modelThree); database.persist(thingOne); database.persist(thingTwo); database.persist(thingThree); Query query = Query.select(TestModel.FIRST_NAME, TestModel.LAST_NAME).selectMore(Thing.FOO, Thing.BAR) .from(TestModel.TABLE) .join(Join.inner(Thing.TABLE, Thing.BAR.gt(0))); SquidCursor<TestModel> cursor = database.query(TestModel.class, query); try { assertEquals(6, cursor.getCount()); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { assertTrue(cursor.get(Thing.BAR) > 0); } } finally { cursor.close(); } }