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

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

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

Query.union介绍

[英]Form a compound select with the given query using the UNION operator
[中]使用UNION运算符与给定查询形成复合select

代码示例

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

  1. /**
  2. * Form a compound select with the given query using the UNION operator
  3. *
  4. * @param query a Query object to append with the UNION operator
  5. * @return this Query object, to allow chaining method calls
  6. * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a>
  7. */
  8. public Query union(Query query) {
  9. if (immutable) {
  10. return fork().union(query);
  11. }
  12. addCompoundSelect(CompoundSelect.union(query));
  13. return this;
  14. }

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

  1. public void testValidationPropagatesToSubqueryJoinAndCompoundSelect() {
  2. Query subquery = Query.select(Thing.FOO).from(Thing.TABLE).where(Thing.BAR.gt(0));
  3. Query joinSubquery = Query.select(Thing.BAR).from(Thing.TABLE).where(Thing.FOO.isNotEmpty());
  4. Query compoundSubquery = Query.select(Thing.BAZ).from(Thing.TABLE).where(Thing.IS_ALIVE.isTrue());
  5. SubqueryTable subqueryTable = subquery.as("t1");
  6. SubqueryTable joinTable = joinSubquery.as("t2");
  7. Query query = Query.select().from(subqueryTable).innerJoin(joinTable, (Criterion[]) null)
  8. .union(compoundSubquery);
  9. final int queryLength = query.compile(database.getCompileContext()).sql.length();
  10. String withValidation = query.sqlForValidation(database.getCompileContext());
  11. assertEquals(queryLength + 6, withValidation.length());
  12. }

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

  1. public void testNeedsValidationUpdatedBySubqueryTable() {
  2. Query subquery = Query.select(Thing.PROPERTIES).from(Thing.TABLE).where(Criterion.literal(123));
  3. subquery.requestValidation();
  4. assertTrue(subquery.compile(database.getCompileContext()).sql.contains("WHERE (?)"));
  5. Query baseTestQuery = Query.select().from(Thing.TABLE).where(Thing.FOO.isNotEmpty()).freeze();
  6. assertFalse(baseTestQuery.needsValidation());
  7. Query testQuery = baseTestQuery.from(subquery.as("t1"));
  8. assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  9. assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  10. testQuery = baseTestQuery.innerJoin(subquery.as("t2"), (Criterion[]) null);
  11. assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  12. assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  13. testQuery = baseTestQuery.union(subquery);
  14. assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  15. assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  16. }

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

  1. /**
  2. * Form a compound select with the given query using the UNION operator
  3. *
  4. * @param query a Query object to append with the UNION operator
  5. * @return this Query object, to allow chaining method calls
  6. * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a>
  7. */
  8. public Query union(Query query) {
  9. if (immutable) {
  10. return fork().union(query);
  11. }
  12. addCompoundSelect(CompoundSelect.union(query));
  13. return this;
  14. }

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

  1. public void testUnion() {
  2. Query query = Query.select().from(Employee.TABLE).where(Employee.MANAGER_ID.eq(1))
  3. .union(Query.select().from(Employee.TABLE).where(Employee.ID.eq(2)))
  4. .orderBy(Employee.ID.asc());
  5. SquidCursor<Employee> cursor = database.query(Employee.class, query);
  6. try {
  7. assertEquals(3, cursor.getCount());
  8. cursor.moveToFirst();
  9. assertEquals(cookieMonster, new Employee(cursor));
  10. cursor.moveToNext();
  11. assertEquals(elmo, new Employee(cursor));
  12. cursor.moveToNext();
  13. assertEquals(oscar, new Employee(cursor));
  14. } finally {
  15. cursor.close();
  16. }
  17. }

相关文章