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

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

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

Query.getFields介绍

暂无

代码示例

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

  1. /**
  2. * @return the selected {@link Field}s of the underlying query, qualified by this table's name
  3. */
  4. public Field<?>[] qualifiedFields() {
  5. return qualifyFields(query.getFields());
  6. }

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

  1. private void assertValues() {
  2. if (!valuesToInsert.isEmpty()) {
  3. if (columns.isEmpty()) {
  4. throw new IllegalStateException("No columns were specified to insert into.");
  5. }
  6. assertValueSetSizes(columns.size());
  7. } else if (query != null) {
  8. if (columns.size() != query.getFields().size()) {
  9. throw new IllegalStateException("Number of properties being selected must match the number of columns "
  10. + "specified.");
  11. }
  12. } else if (!defaultValues) {
  13. throw new IllegalStateException("No values to insert were specified.");
  14. }
  15. }

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

  1. private void visitSelectClause(SqlBuilder builder, boolean forSqlValidation) {
  2. builder.sql.append("SELECT ");
  3. if (distinct) {
  4. builder.sql.append("DISTINCT ");
  5. }
  6. List<Field<?>> toSelect;
  7. if (isEmpty(fields)) {
  8. // SELECT * may yield unexpected column names, so we get the full list of fields to specify explicit aliases
  9. toSelect = getFields();
  10. } else {
  11. toSelect = fields;
  12. }
  13. builder.appendConcatenatedCompilables(toSelect, ", ", forSqlValidation);
  14. }

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

  1. /**
  2. * Query the database
  3. *
  4. * @param modelClass the type to parameterize the cursor by. If the query does not contain a FROM clause, the table
  5. * or view corresponding to this model class will be used.
  6. * @param query the query to execute
  7. * @return a {@link SquidCursor} containing the query results
  8. */
  9. public <TYPE extends AbstractModel> SquidCursor<TYPE> query(Class<TYPE> modelClass, Query query) {
  10. query = inferTableForQuery(modelClass, query);
  11. CompiledStatement compiled = query.compile(getCompileContext());
  12. if (compiled.needsValidation) {
  13. String validateSql = query.sqlForValidation(getCompileContext());
  14. ensureSqlCompiles(validateSql); // throws if the statement fails to compile
  15. }
  16. ICursor cursor = rawQuery(compiled.sql, compiled.sqlArgs);
  17. return new SquidCursor<>(cursor, modelClass, query.getFields());
  18. }

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

  1. public void testInvalidProjectionIgnored() {
  2. ContentProviderQueryBuilder builder = getBuilder();
  3. final String IGNORE = "foo";
  4. String[] projection = {IGNORE, COL_GIVEN_NAME, COL_SURNAME, COL_LUCKY_NUMBER};
  5. Query query = builder.setDataSource(TestModel.TABLE).build(projection, null, null, null);
  6. List<Field<?>> fields = query.getFields();
  7. assertEquals(3, fields.size());
  8. for (int i = 0; i < fields.size(); i++) {
  9. if (IGNORE.equals(fields.get(i).getName())) {
  10. fail("Invalid projection not ignored!");
  11. }
  12. }
  13. }

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

  1. public void testAllFields() {
  2. Query query = Query.select().from(TestViewModel.VIEW)
  3. .leftJoin(Thing.TABLE, TestViewModel.TEST_MODEL_ID.eq(Thing.ID));
  4. List<Field<?>> fields = query.getFields();
  5. for (Property<?> p : TestViewModel.PROPERTIES) {
  6. assertTrue(fields.contains(p));
  7. }
  8. for (Property<?> p : Thing.PROPERTIES) {
  9. assertTrue(fields.contains(p));
  10. }
  11. assertEquals(TestViewModel.PROPERTIES.length + Thing.PROPERTIES.length, fields.size());
  12. }

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

  1. public void testBuilderFromModel() {
  2. ContentProviderQueryBuilder builder = new ContentProviderQueryBuilder(TestSubqueryModel.PROPERTIES,
  3. TestSubqueryModel.SUBQUERY);
  4. Query query = builder.build(null, null, null, null);
  5. assertEquals(Arrays.asList(TestSubqueryModel.PROPERTIES), query.getFields());
  6. assertEquals(TestSubqueryModel.SUBQUERY, query.getTable());
  7. }

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

  1. public void testEmptyProjectionWithMapUsesDefault() {
  2. final Field<?>[] expectedProjection = new Field<?>[]{
  3. TestModel.ID,
  4. TestModel.FIRST_NAME.as(COL_GIVEN_NAME),
  5. TestModel.LAST_NAME.as(COL_SURNAME),
  6. TestModel.LUCKY_NUMBER,
  7. TestModel.IS_HAPPY
  8. };
  9. ContentProviderQueryBuilder builder = getBuilder();
  10. Query query = builder.setDataSource(TestModel.TABLE).build(null, null, null, null);
  11. assertEquals(Arrays.asList(expectedProjection), query.getFields());
  12. }

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

  1. public void testNonEmptyProjectionWithoutMapCreatesFields() {
  2. final Field<?>[] expectedProjection = new Field<?>[]{Field.field("foo"), Field.field("bar")};
  3. ContentProviderQueryBuilder builder = new ContentProviderQueryBuilder();
  4. Query query = builder.setDataSource(TestModel.TABLE).build(new String[]{"foo", "bar"}, null, null, null);
  5. assertEquals(Arrays.asList(expectedProjection), query.getFields());
  6. }

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

  1. /**
  2. * @return the selected {@link Field}s of the underlying query, qualified by this table's name
  3. */
  4. public Field<?>[] qualifiedFields() {
  5. return qualifyFields(query.getFields());
  6. }

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

  1. private void assertValues() {
  2. if (!valuesToInsert.isEmpty()) {
  3. if (columns.isEmpty()) {
  4. throw new IllegalStateException("No columns were specified to insert into.");
  5. }
  6. assertValueSetSizes(columns.size());
  7. } else if (query != null) {
  8. if (columns.size() != query.getFields().size()) {
  9. throw new IllegalStateException("Number of properties being selected must match the number of columns "
  10. + "specified.");
  11. }
  12. } else if (!defaultValues) {
  13. throw new IllegalStateException("No values to insert were specified.");
  14. }
  15. }

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

  1. private void visitSelectClause(SqlBuilder builder, boolean forSqlValidation) {
  2. builder.sql.append("SELECT ");
  3. if (distinct) {
  4. builder.sql.append("DISTINCT ");
  5. }
  6. List<Field<?>> toSelect;
  7. if (isEmpty(fields)) {
  8. // SELECT * may yield unexpected column names, so we get the full list of fields to specify explicit aliases
  9. toSelect = getFields();
  10. } else {
  11. toSelect = fields;
  12. }
  13. builder.appendConcatenatedCompilables(toSelect, ", ", forSqlValidation);
  14. }

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

  1. /**
  2. * Query the database
  3. *
  4. * @param modelClass the type to parameterize the cursor by. If the query does not contain a FROM clause, the table
  5. * or view corresponding to this model class will be used.
  6. * @param query the query to execute
  7. * @return a {@link SquidCursor} containing the query results
  8. */
  9. public <TYPE extends AbstractModel> SquidCursor<TYPE> query(Class<TYPE> modelClass, Query query) {
  10. query = inferTableForQuery(modelClass, query);
  11. CompiledStatement compiled = query.compile(getCompileContext());
  12. if (compiled.needsValidation) {
  13. String validateSql = query.sqlForValidation(getCompileContext());
  14. ensureSqlCompiles(validateSql); // throws if the statement fails to compile
  15. }
  16. ICursor cursor = rawQuery(compiled.sql, compiled.sqlArgs);
  17. return new SquidCursor<>(cursor, modelClass, query.getFields());
  18. }

相关文章