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

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

本文整理了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

/**
 * 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));
}

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

/**
 * 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));
}

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

/**
 * 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));
}

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

/**
 * 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));
}

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

/**
 * 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;
}

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

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);
}

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

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());

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

/**
 * 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));
}

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

/**
 * 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));
}

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

/**
 * 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));
}

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

/**
 * 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));
}

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

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();
    }
  }
}

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

/**
 * 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;
}

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

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();
  }
}

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

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();
    }
  }
}

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

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();
  }
}

相关文章