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

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

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

Query.selectMore介绍

[英]Add more Field to be selected
[中]添加更多要选择的字段

代码示例

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

/**
 * Add more {@link Field Fields} to be selected
 *
 * @param fields the additional Fields to be selected
 * @return this Query object, to allow chaining method calls
 */
public Query selectMore(List<Field<?>> fields) {
  if (immutable) {
    return fork().selectMore(fields);
  }
  if (!isEmpty(fields)) {
    if (this.fields == null) {
      this.fields = new ArrayList<>(fields);
    } else {
      this.fields.addAll(fields);
    }
    if (selectAllCache != null) {
      selectAllCache.clear();
    }
    invalidateCompileCache();
  }
  return this;
}

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

/**
 * Add more {@link Field Fields} to be selected
 *
 * @param fields the additional Fields to be selected
 * @return this Query object, to allow chaining method calls
 */
public Query selectMore(Field<?>... fields) {
  if (immutable) {
    return fork().selectMore(fields);
  }
  if (!isEmpty(fields)) {
    if (this.fields == null) {
      this.fields = new ArrayList<>();
    }
    SquidUtilities.addAll(this.fields, fields);
    if (selectAllCache != null) {
      selectAllCache.clear();
    }
    invalidateCompileCache();
  }
  return this;
}

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

public void testSelectFunction() {
  Function<String> upper = Function.upper(TestModel.LAST_NAME);
  SquidCursor<TestModel> cursor = database
      .query(TestModel.class, Query.select(TestModel.PROPERTIES).selectMore(upper));
  try {
    cursor.moveToFirst();
    new TestModel(cursor); // Should succeed without throwing an exception
  } finally {
    cursor.close();
  }
}

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

public void testCustomIdColumn() {
  Function<Long> idSquared = Function.rawFunction("_id * _id");
  LongProperty idSquaredProperty = LongProperty.fromFunction(idSquared, "idSquared");
  Query query = Query.select(TestModel.PROPERTIES).selectMore(idSquaredProperty).orderBy(TestModel.ID.asc());
  testCursorAdapterInternal(new TestModel(), idSquaredProperty, query, new CursorAdapterTest() {
    @Override
    public void testCursorAdapter(SquidCursorAdapter<AbstractModel> adapter) {
      assertTrue(adapter.hasStableIds());
      assertEquals(1, adapter.getItemId(0));
      assertEquals(4, adapter.getItemId(1));
    }
  });
}

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

private void testRecyclerAdapterInternal(LongProperty idProperty, RecyclerAdapterTest test) {
  Query query = Query.select(TestModel.PROPERTIES)
      .orderBy(TestModel.BIRTHDAY.asc())
      .limit(2);
  if (idProperty != null) {
    query.selectMore(idProperty);
  }
  SquidCursor<TestModel> cursor = database.query(TestModel.class, query);
  TestRecyclerAdapter adapter = new TestRecyclerAdapter(idProperty);
  adapter.changeCursor(cursor);
  try {
    test.testRecyclerAdapter(adapter);
  } finally {
    cursor.close();
  }
}

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

public void testAggregateCount() {
  TestModel model1 = insertBasicTestModel();
  TestModel model2 = new TestModel().setFirstName(model1.getFirstName()).setLastName("Smith");
  database.persist(model2);
  IntegerProperty groupCount = IntegerProperty.countProperty(TestModel.FIRST_NAME, false);
  Query query = Query.select(TestModel.PROPERTIES).selectMore(groupCount).groupBy(TestModel.FIRST_NAME);
  SquidCursor<TestModel> groupedCursor = database.query(TestModel.class, query);
  try {
    groupedCursor.moveToFirst();
    assertEquals(1, groupedCursor.getCount());
    assertEquals(2, groupedCursor.get(groupCount).intValue());
  } finally {
    groupedCursor.close();
  }
}

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

public void testNeedsValidationUpdatedByQueryFunction() {
  Query subquery = Query.select(Function.max(Thing.ID)).from(Thing.TABLE).where(Criterion.literal(123));
  subquery.requestValidation();
  assertTrue(subquery.compile(database.getCompileContext()).sql.contains("WHERE (?)"));
  Query baseTestQuery = Query.select().from(Thing.TABLE).where(Thing.FOO.isNotEmpty()).freeze();
  assertFalse(baseTestQuery.needsValidation());
  Query testQuery = baseTestQuery.selectMore(subquery.asFunction());
  assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
}

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

Query query = Query.select(Employee.PROPERTIES).selectMore(coworkers)
    .from(Employee.TABLE);
if (leftJoin) {

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

/**
 * Add more {@link Field Fields} to be selected
 *
 * @param fields the additional Fields to be selected
 * @return this Query object, to allow chaining method calls
 */
public Query selectMore(List<Field<?>> fields) {
  if (immutable) {
    return fork().selectMore(fields);
  }
  if (!isEmpty(fields)) {
    if (this.fields == null) {
      this.fields = new ArrayList<>(fields);
    } else {
      this.fields.addAll(fields);
    }
    if (selectAllCache != null) {
      selectAllCache.clear();
    }
    invalidateCompileCache();
  }
  return this;
}

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

/**
 * Add more {@link Field Fields} to be selected
 *
 * @param fields the additional Fields to be selected
 * @return this Query object, to allow chaining method calls
 */
public Query selectMore(Field<?>... fields) {
  if (immutable) {
    return fork().selectMore(fields);
  }
  if (!isEmpty(fields)) {
    if (this.fields == null) {
      this.fields = new ArrayList<>();
    }
    SquidUtilities.addAll(this.fields, fields);
    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 testCoalesce() {
  model2.setFirstName(null); // coalesce should find last name
  database.persist(model2);
  model3.setFirstName(null).setLastName(null); // coalesce should find fallback name
  database.persist(model3);
  final String FALLBACK_NAME = "Squid";
  Function<String> coalesce = Function.coalesce(TestModel.FIRST_NAME, TestModel.LAST_NAME, FALLBACK_NAME);
  StringProperty modelName = StringProperty.fromFunction(coalesce, "name");
  // select *, coalesce(firstName, lastName, 'Squid') as name from testModel order by _id asc;
  SquidCursor<TestModel> cursor = database.query(TestModel.class, Query.select(TestModel.PROPERTIES)
      .selectMore(modelName).orderBy(TestModel.ID.asc()));
  assertEquals(3, cursor.getCount());
  try {
    cursor.moveToFirst();
    assertEquals(model1.getFirstName(), cursor.get(modelName));
    cursor.moveToNext();
    assertEquals(model2.getLastName(), cursor.get(modelName));
    cursor.moveToNext();
    assertEquals(FALLBACK_NAME, cursor.get(modelName));
  } finally {
    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();
  }
}

相关文章