本文整理了Java中com.yahoo.squidb.sql.Query.getFields
方法的一些代码示例,展示了Query.getFields
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getFields
方法的具体详情如下:
包路径:com.yahoo.squidb.sql.Query
类名称:Query
方法名:getFields
暂无
代码示例来源:origin: yahoo/squidb
/**
* @return the selected {@link Field}s of the underlying query, qualified by this table's name
*/
public Field<?>[] qualifiedFields() {
return qualifyFields(query.getFields());
}
代码示例来源:origin: yahoo/squidb
private void assertValues() {
if (!valuesToInsert.isEmpty()) {
if (columns.isEmpty()) {
throw new IllegalStateException("No columns were specified to insert into.");
}
assertValueSetSizes(columns.size());
} else if (query != null) {
if (columns.size() != query.getFields().size()) {
throw new IllegalStateException("Number of properties being selected must match the number of columns "
+ "specified.");
}
} else if (!defaultValues) {
throw new IllegalStateException("No values to insert were specified.");
}
}
代码示例来源:origin: yahoo/squidb
private void visitSelectClause(SqlBuilder builder, boolean forSqlValidation) {
builder.sql.append("SELECT ");
if (distinct) {
builder.sql.append("DISTINCT ");
}
List<Field<?>> toSelect;
if (isEmpty(fields)) {
// SELECT * may yield unexpected column names, so we get the full list of fields to specify explicit aliases
toSelect = getFields();
} else {
toSelect = fields;
}
builder.appendConcatenatedCompilables(toSelect, ", ", forSqlValidation);
}
代码示例来源:origin: yahoo/squidb
/**
* Query the database
*
* @param modelClass the type to parameterize the cursor by. If the query does not contain a FROM clause, the table
* or view corresponding to this model class will be used.
* @param query the query to execute
* @return a {@link SquidCursor} containing the query results
*/
public <TYPE extends AbstractModel> SquidCursor<TYPE> query(Class<TYPE> modelClass, Query query) {
query = inferTableForQuery(modelClass, query);
CompiledStatement compiled = query.compile(getCompileContext());
if (compiled.needsValidation) {
String validateSql = query.sqlForValidation(getCompileContext());
ensureSqlCompiles(validateSql); // throws if the statement fails to compile
}
ICursor cursor = rawQuery(compiled.sql, compiled.sqlArgs);
return new SquidCursor<>(cursor, modelClass, query.getFields());
}
代码示例来源:origin: yahoo/squidb
public void testInvalidProjectionIgnored() {
ContentProviderQueryBuilder builder = getBuilder();
final String IGNORE = "foo";
String[] projection = {IGNORE, COL_GIVEN_NAME, COL_SURNAME, COL_LUCKY_NUMBER};
Query query = builder.setDataSource(TestModel.TABLE).build(projection, null, null, null);
List<Field<?>> fields = query.getFields();
assertEquals(3, fields.size());
for (int i = 0; i < fields.size(); i++) {
if (IGNORE.equals(fields.get(i).getName())) {
fail("Invalid projection not ignored!");
}
}
}
代码示例来源:origin: yahoo/squidb
public void testAllFields() {
Query query = Query.select().from(TestViewModel.VIEW)
.leftJoin(Thing.TABLE, TestViewModel.TEST_MODEL_ID.eq(Thing.ID));
List<Field<?>> fields = query.getFields();
for (Property<?> p : TestViewModel.PROPERTIES) {
assertTrue(fields.contains(p));
}
for (Property<?> p : Thing.PROPERTIES) {
assertTrue(fields.contains(p));
}
assertEquals(TestViewModel.PROPERTIES.length + Thing.PROPERTIES.length, fields.size());
}
代码示例来源:origin: yahoo/squidb
public void testBuilderFromModel() {
ContentProviderQueryBuilder builder = new ContentProviderQueryBuilder(TestSubqueryModel.PROPERTIES,
TestSubqueryModel.SUBQUERY);
Query query = builder.build(null, null, null, null);
assertEquals(Arrays.asList(TestSubqueryModel.PROPERTIES), query.getFields());
assertEquals(TestSubqueryModel.SUBQUERY, query.getTable());
}
代码示例来源:origin: yahoo/squidb
public void testEmptyProjectionWithMapUsesDefault() {
final Field<?>[] expectedProjection = new Field<?>[]{
TestModel.ID,
TestModel.FIRST_NAME.as(COL_GIVEN_NAME),
TestModel.LAST_NAME.as(COL_SURNAME),
TestModel.LUCKY_NUMBER,
TestModel.IS_HAPPY
};
ContentProviderQueryBuilder builder = getBuilder();
Query query = builder.setDataSource(TestModel.TABLE).build(null, null, null, null);
assertEquals(Arrays.asList(expectedProjection), query.getFields());
}
代码示例来源:origin: yahoo/squidb
public void testNonEmptyProjectionWithoutMapCreatesFields() {
final Field<?>[] expectedProjection = new Field<?>[]{Field.field("foo"), Field.field("bar")};
ContentProviderQueryBuilder builder = new ContentProviderQueryBuilder();
Query query = builder.setDataSource(TestModel.TABLE).build(new String[]{"foo", "bar"}, null, null, null);
assertEquals(Arrays.asList(expectedProjection), query.getFields());
}
代码示例来源:origin: com.yahoo.squidb/squidb
/**
* @return the selected {@link Field}s of the underlying query, qualified by this table's name
*/
public Field<?>[] qualifiedFields() {
return qualifyFields(query.getFields());
}
代码示例来源:origin: com.yahoo.squidb/squidb
private void assertValues() {
if (!valuesToInsert.isEmpty()) {
if (columns.isEmpty()) {
throw new IllegalStateException("No columns were specified to insert into.");
}
assertValueSetSizes(columns.size());
} else if (query != null) {
if (columns.size() != query.getFields().size()) {
throw new IllegalStateException("Number of properties being selected must match the number of columns "
+ "specified.");
}
} else if (!defaultValues) {
throw new IllegalStateException("No values to insert were specified.");
}
}
代码示例来源:origin: com.yahoo.squidb/squidb
private void visitSelectClause(SqlBuilder builder, boolean forSqlValidation) {
builder.sql.append("SELECT ");
if (distinct) {
builder.sql.append("DISTINCT ");
}
List<Field<?>> toSelect;
if (isEmpty(fields)) {
// SELECT * may yield unexpected column names, so we get the full list of fields to specify explicit aliases
toSelect = getFields();
} else {
toSelect = fields;
}
builder.appendConcatenatedCompilables(toSelect, ", ", forSqlValidation);
}
代码示例来源:origin: com.yahoo.squidb/squidb
/**
* Query the database
*
* @param modelClass the type to parameterize the cursor by. If the query does not contain a FROM clause, the table
* or view corresponding to this model class will be used.
* @param query the query to execute
* @return a {@link SquidCursor} containing the query results
*/
public <TYPE extends AbstractModel> SquidCursor<TYPE> query(Class<TYPE> modelClass, Query query) {
query = inferTableForQuery(modelClass, query);
CompiledStatement compiled = query.compile(getCompileContext());
if (compiled.needsValidation) {
String validateSql = query.sqlForValidation(getCompileContext());
ensureSqlCompiles(validateSql); // throws if the statement fails to compile
}
ICursor cursor = rawQuery(compiled.sql, compiled.sqlArgs);
return new SquidCursor<>(cursor, modelClass, query.getFields());
}
内容来源于网络,如有侵权,请联系作者删除!