/** * 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)); }
/** * 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)); }
/** * 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)); }
/** * Add a {@link Join} to this query * * @param joins one or more joins to apply to this query * @return this Query object, to allow chaining method calls */ public Query join(Join... joins) { if (immutable) { return fork().join(joins); } if (this.joins == null) { this.joins = new ArrayList<>(); } SquidUtilities.addAll(this.joins, joins); if (selectAllCache != null) { selectAllCache.clear(); } invalidateCompileCache(); return this; }
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); }
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 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)); }
/** * 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)); }
/** * 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)); }
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(); } } }
/** * Add a {@link Join} to this query * * @param joins one or more joins to apply to this query * @return this Query object, to allow chaining method calls */ public Query join(Join... joins) { if (immutable) { return fork().join(joins); } if (this.joins == null) { this.joins = new ArrayList<>(); } SquidUtilities.addAll(this.joins, joins); if (selectAllCache != null) { selectAllCache.clear(); } invalidateCompileCache(); return this; }
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 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(); } } }
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(); } }