/** * 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 a left {@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 leftJoin(SqlTable<?> table, Property<?>... usingColumns) { return join(Join.left(table, usingColumns)); }
/** * Construct a CROSS join with an ON clause. A CROSS join produces the same result as an INNER join, but prohibits * the query optimizer from reordering the tables in the join. Avoid using CROSS join except in specific situations * where manual control of the query optimizer is desired. * * @param table the table to join on * @param criterions criterions to use for the ON clause */ public static Join cross(SqlTable<?> table, Criterion... criterions) { return new Join(table, JoinType.CROSS, criterions); }
/** * 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 a left {@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 leftJoin(SqlTable<?> table, Criterion... onCriterions) { return join(Join.left(table, onCriterions)); }
/** * Construct an INNER join with a USING clause. * * @param table the table to join on * @param usingColumns columns to use for the USING clause */ public static Join inner(SqlTable<?> table, Property<?>... usingColumns) { return new Join(table, JoinType.INNER, 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); }
/** * Add a left {@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 leftJoin(SqlTable<?> table, Criterion... onCriterions) { return join(Join.left(table, onCriterions)); }
/** * Construct a LEFT join with a USING clause. Left joins return all the rows an INNER join would return, plus an * extra row for each row in the left-hand dataset that corresponds to no rows at all in the composite dataset (if * any). The added rows contain NULL values in the columns from the right-hand dataset. * * @param table the table to join on * @param usingColumns columns to use for the USING clause */ public static Join left(SqlTable<?> table, Property<?>... usingColumns) { return new Join(table, JoinType.LEFT, usingColumns); }
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 a left {@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 leftJoin(SqlTable<?> table, Property<?>... usingColumns) { return join(Join.left(table, usingColumns)); }
/** * Construct an INNER join with an ON clause. * * @param table the table to join on * @param criterions criterions to use for the ON clause */ public static Join inner(SqlTable<?> table, Criterion... criterions) { return new Join(table, JoinType.INNER, criterions); }
/** * 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 testViewlessViewModel() { SquidCursor<ViewlessViewModel> cursor = null; try { cursor = database.query(ViewlessViewModel.class, Query.select(ViewlessViewModel.PROPERTIES) .from(TestModel.TABLE) .join(Join.left(Employee.TABLE, TestModel.ID.eq(Employee.ID))) .where(TestModel.FIRST_NAME.gt("S")) .orderBy(TestModel.FIRST_NAME.asc())); assertEquals(2, cursor.getCount()); cursor.moveToFirst(); ViewlessViewModel model = new ViewlessViewModel(cursor); assertEquals(t1.getRowId(), model.getTestModelId().longValue()); assertEquals(e1.getRowId(), model.getEmployeeModelId().longValue()); assertEquals(t1.getFirstName(), model.getTestName()); assertEquals(e1.getName(), model.getEmployeeName()); assertEquals(e1.getName().toUpperCase(), model.getUppercaseName()); cursor.moveToNext(); model.readPropertiesFromCursor(cursor); assertEquals(t2.getRowId(), model.getTestModelId().longValue()); assertEquals(e2.getRowId(), model.getEmployeeModelId().longValue()); assertEquals(t2.getFirstName(), model.getTestName()); assertEquals(e2.getName(), model.getEmployeeName()); assertEquals(e2.getName().toUpperCase(), model.getUppercaseName()); } finally { if (cursor != null) { cursor.close(); } } }
/** * Construct a CROSS join with a USING clause. A CROSS join produces the same result as an INNER join, but * prohibits the query optimizer from reordering the tables in the join. Avoid using CROSS join except in specific * situations where manual control of the query optimizer is desired. * * @param table the table to join on * @param usingColumns columns to use for the USING clause */ public static Join cross(SqlTable<?> table, Property<?>... usingColumns) { return new Join(table, JoinType.CROSS, 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 testViewlessViewModelMapping() { SquidCursor<ViewlessViewModel> cursor = null; try { cursor = database.query(ViewlessViewModel.class, Query.select(ViewlessViewModel.PROPERTIES) .from(TestModel.TABLE) .join(Join.left(Employee.TABLE, TestModel.ID.eq(Employee.ID))) .where(TestModel.FIRST_NAME.gt("S")) .orderBy(TestModel.FIRST_NAME.asc())); cursor.moveToFirst(); ViewlessViewModel model = new ViewlessViewModel(cursor); TestModel testModel = new TestModel(); model.mapToModel(testModel); assertEquals(t1.getRowId(), testModel.getRowId()); assertEquals(t1.getFirstName(), testModel.getFirstName()); assertFalse(testModel.containsValue(Employee.NAME)); assertFalse(testModel.containsValue(TestViewModel.UPPERCASE_NAME)); Employee employee = new Employee(); model.mapToModel(employee); assertEquals(e1.getRowId(), employee.getRowId()); assertEquals(e1.getName(), employee.getName()); assertFalse(employee.containsValue(TestModel.FIRST_NAME)); assertFalse(employee.containsValue(TestViewModel.UPPERCASE_NAME)); } finally { if (cursor != null) { cursor.close(); } } }
/** * Construct a LEFT join with an ON clause. Left joins return all the rows an INNER join would return, plus an * extra row for each row in the left-hand dataset that corresponds to no rows at all in the composite dataset (if * any). The added rows contain NULL values in the columns from the right-hand dataset. * * @param table the table to join on * @param criterions criterions to use for the ON clause */ public static Join left(SqlTable<?> table, Criterion... criterions) { return new Join(table, JoinType.LEFT, criterions); }
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(); } }
/** * Construct a LEFT join with an ON clause. Left joins return all the rows an INNER join would return, plus an * extra row for each row in the left-hand dataset that corresponds to no rows at all in the composite dataset (if * any). The added rows contain NULL values in the columns from the right-hand dataset. * * @param table the table to join on * @param criterions criterions to use for the ON clause */ public static Join left(SqlTable<?> table, Criterion... criterions) { return new Join(table, JoinType.LEFT, criterions); }