com.yahoo.squidb.sql.Query.join()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(296)

本文整理了Java中com.yahoo.squidb.sql.Query.join方法的一些代码示例,展示了Query.join的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.join方法的具体详情如下:
包路径:com.yahoo.squidb.sql.Query
类名称:Query
方法名:join

Query.join介绍

[英]Add a Join to this query
[中]将联接添加到此查询

代码示例

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Add a left {@link Join} to this query using the ON clause
  3. *
  4. * @param table the table to join on
  5. * @param onCriterions one or more criterions to use for the "on" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query leftJoin(SqlTable<?> table, Criterion... onCriterions) {
  9. return join(Join.left(table, onCriterions));
  10. }

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Add a left {@link Join} to this query using the USING clause
  3. *
  4. * @param table the table to join on
  5. * @param usingColumns one or more columns to use for the "using" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query leftJoin(SqlTable<?> table, Property<?>... usingColumns) {
  9. return join(Join.left(table, usingColumns));
  10. }

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Add an inner {@link Join} to this query using the ON clause
  3. *
  4. * @param table the table to join on
  5. * @param onCriterions one or more criterions to use for the "on" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query innerJoin(SqlTable<?> table, Criterion... onCriterions) {
  9. return join(Join.inner(table, onCriterions));
  10. }

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Add an inner {@link Join} to this query using the USING clause
  3. *
  4. * @param table the table to join on
  5. * @param usingColumns one or more columns to use for the "using" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query innerJoin(SqlTable<?> table, Property<?>... usingColumns) {
  9. return join(Join.inner(table, usingColumns));
  10. }

代码示例来源:origin: yahoo/squidb

  1. /**
  2. * Add a {@link Join} to this query
  3. *
  4. * @param joins one or more joins to apply to this query
  5. * @return this Query object, to allow chaining method calls
  6. */
  7. public Query join(Join... joins) {
  8. if (immutable) {
  9. return fork().join(joins);
  10. }
  11. if (this.joins == null) {
  12. this.joins = new ArrayList<>();
  13. }
  14. SquidUtilities.addAll(this.joins, joins);
  15. if (selectAllCache != null) {
  16. selectAllCache.clear();
  17. }
  18. invalidateCompileCache();
  19. return this;
  20. }

代码示例来源:origin: yahoo/squidb

  1. public void testFunctionOnAmbiguousColumnName() {
  2. IntegerProperty happyCount = IntegerProperty.countProperty(Employee.IS_HAPPY, false);
  3. Query test = Query.select(TestModel.ID, TestModel.FIRST_NAME, TestModel.IS_HAPPY, happyCount)
  4. .join(Join.inner(Employee.TABLE, Employee.IS_HAPPY.eq(TestModel.IS_HAPPY)));
  5. // just test that the query compiles with the function
  6. database.query(TestModel.class, test);
  7. }

代码示例来源:origin: yahoo/squidb

  1. LongProperty managerId = managerTable.qualifyField(Employee.ID);
  2. Join join = Join.inner(managerTable, Employee.MANAGER_ID.eq(managerId));
  3. Query query = Query.select(employeeName, managerName).from(Employee.TABLE).join(join).orderBy(managerId.asc());

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Add an inner {@link Join} to this query using the ON clause
  3. *
  4. * @param table the table to join on
  5. * @param onCriterions one or more criterions to use for the "on" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query innerJoin(SqlTable<?> table, Criterion... onCriterions) {
  9. return join(Join.inner(table, onCriterions));
  10. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Add an inner {@link Join} to this query using the USING clause
  3. *
  4. * @param table the table to join on
  5. * @param usingColumns one or more columns to use for the "using" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query innerJoin(SqlTable<?> table, Property<?>... usingColumns) {
  9. return join(Join.inner(table, usingColumns));
  10. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Add a left {@link Join} to this query using the ON clause
  3. *
  4. * @param table the table to join on
  5. * @param onCriterions one or more criterions to use for the "on" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query leftJoin(SqlTable<?> table, Criterion... onCriterions) {
  9. return join(Join.left(table, onCriterions));
  10. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Add a left {@link Join} to this query using the USING clause
  3. *
  4. * @param table the table to join on
  5. * @param usingColumns one or more columns to use for the "using" clause
  6. * @return this Query object, to allow chaining method calls
  7. */
  8. public Query leftJoin(SqlTable<?> table, Property<?>... usingColumns) {
  9. return join(Join.left(table, usingColumns));
  10. }

代码示例来源:origin: yahoo/squidb

  1. public void testViewlessViewModel() {
  2. SquidCursor<ViewlessViewModel> cursor = null;
  3. try {
  4. cursor = database.query(ViewlessViewModel.class, Query.select(ViewlessViewModel.PROPERTIES)
  5. .from(TestModel.TABLE)
  6. .join(Join.left(Employee.TABLE, TestModel.ID.eq(Employee.ID)))
  7. .where(TestModel.FIRST_NAME.gt("S"))
  8. .orderBy(TestModel.FIRST_NAME.asc()));
  9. assertEquals(2, cursor.getCount());
  10. cursor.moveToFirst();
  11. ViewlessViewModel model = new ViewlessViewModel(cursor);
  12. assertEquals(t1.getRowId(), model.getTestModelId().longValue());
  13. assertEquals(e1.getRowId(), model.getEmployeeModelId().longValue());
  14. assertEquals(t1.getFirstName(), model.getTestName());
  15. assertEquals(e1.getName(), model.getEmployeeName());
  16. assertEquals(e1.getName().toUpperCase(), model.getUppercaseName());
  17. cursor.moveToNext();
  18. model.readPropertiesFromCursor(cursor);
  19. assertEquals(t2.getRowId(), model.getTestModelId().longValue());
  20. assertEquals(e2.getRowId(), model.getEmployeeModelId().longValue());
  21. assertEquals(t2.getFirstName(), model.getTestName());
  22. assertEquals(e2.getName(), model.getEmployeeName());
  23. assertEquals(e2.getName().toUpperCase(), model.getUppercaseName());
  24. } finally {
  25. if (cursor != null) {
  26. cursor.close();
  27. }
  28. }
  29. }

代码示例来源:origin: com.yahoo.squidb/squidb

  1. /**
  2. * Add a {@link Join} to this query
  3. *
  4. * @param joins one or more joins to apply to this query
  5. * @return this Query object, to allow chaining method calls
  6. */
  7. public Query join(Join... joins) {
  8. if (immutable) {
  9. return fork().join(joins);
  10. }
  11. if (this.joins == null) {
  12. this.joins = new ArrayList<>();
  13. }
  14. SquidUtilities.addAll(this.joins, joins);
  15. if (selectAllCache != null) {
  16. selectAllCache.clear();
  17. }
  18. invalidateCompileCache();
  19. return this;
  20. }

代码示例来源:origin: yahoo/squidb

  1. public void testSubqueryJoin() {
  2. StringProperty managerName = Employee.NAME.as("managerName");
  3. Query query = Query
  4. .fromSubquery(Query.select(Employee.MANAGER_ID).from(Employee.TABLE).groupBy(Employee.MANAGER_ID),
  5. "subquery");
  6. query.selectMore(managerName);
  7. query.join(Join.inner(Employee.TABLE, query.getTable().qualifyField(Employee.MANAGER_ID).eq(Employee.ID)))
  8. .orderBy(Employee.MANAGER_ID.asc());
  9. SquidCursor<Employee> cursor = database.query(Employee.class, query);
  10. try {
  11. assertEquals(3, cursor.getCount());
  12. cursor.moveToFirst();
  13. assertEquals("bigBird", cursor.get(managerName));
  14. cursor.moveToNext();
  15. assertEquals("cookieMonster", cursor.get(managerName));
  16. cursor.moveToNext();
  17. assertEquals("bert", cursor.get(managerName));
  18. } finally {
  19. cursor.close();
  20. }
  21. }

代码示例来源:origin: yahoo/squidb

  1. public void testViewlessViewModelMapping() {
  2. SquidCursor<ViewlessViewModel> cursor = null;
  3. try {
  4. cursor = database.query(ViewlessViewModel.class, Query.select(ViewlessViewModel.PROPERTIES)
  5. .from(TestModel.TABLE)
  6. .join(Join.left(Employee.TABLE, TestModel.ID.eq(Employee.ID)))
  7. .where(TestModel.FIRST_NAME.gt("S"))
  8. .orderBy(TestModel.FIRST_NAME.asc()));
  9. cursor.moveToFirst();
  10. ViewlessViewModel model = new ViewlessViewModel(cursor);
  11. TestModel testModel = new TestModel();
  12. model.mapToModel(testModel);
  13. assertEquals(t1.getRowId(), testModel.getRowId());
  14. assertEquals(t1.getFirstName(), testModel.getFirstName());
  15. assertFalse(testModel.containsValue(Employee.NAME));
  16. assertFalse(testModel.containsValue(TestViewModel.UPPERCASE_NAME));
  17. Employee employee = new Employee();
  18. model.mapToModel(employee);
  19. assertEquals(e1.getRowId(), employee.getRowId());
  20. assertEquals(e1.getName(), employee.getName());
  21. assertFalse(employee.containsValue(TestModel.FIRST_NAME));
  22. assertFalse(employee.containsValue(TestViewModel.UPPERCASE_NAME));
  23. } finally {
  24. if (cursor != null) {
  25. cursor.close();
  26. }
  27. }
  28. }

代码示例来源:origin: yahoo/squidb

  1. public void testJoinOnLiteralValue() {
  2. TestModel modelOne = new TestModel().setFirstName("Sam").setLastName("Bosley");
  3. TestModel modelTwo = new TestModel().setFirstName("Kevin").setLastName("Lim");
  4. TestModel modelThree = new TestModel().setFirstName("Jonathan").setLastName("Koren");
  5. Thing thingOne = new Thing().setFoo("Thing1").setBar(5);
  6. Thing thingTwo = new Thing().setFoo("Thing2").setBar(-1);
  7. Thing thingThree = new Thing().setFoo("Thing3").setBar(100);
  8. database.persist(modelOne);
  9. database.persist(modelTwo);
  10. database.persist(modelThree);
  11. database.persist(thingOne);
  12. database.persist(thingTwo);
  13. database.persist(thingThree);
  14. Query query = Query.select(TestModel.FIRST_NAME, TestModel.LAST_NAME).selectMore(Thing.FOO, Thing.BAR)
  15. .from(TestModel.TABLE)
  16. .join(Join.inner(Thing.TABLE, Thing.BAR.gt(0)));
  17. SquidCursor<TestModel> cursor = database.query(TestModel.class, query);
  18. try {
  19. assertEquals(6, cursor.getCount());
  20. for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
  21. assertTrue(cursor.get(Thing.BAR) > 0);
  22. }
  23. } finally {
  24. cursor.close();
  25. }
  26. }

相关文章