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

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

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

Query.select介绍

[英]Construct a new Select statement that queries for the specified Field
[中]构造查询指定字段的新Select语句

代码示例

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

  1. /**
  2. * Construct a new Select statement that queries all the {@link Field Fields} of the given {@link View}
  3. *
  4. * @param view the View to select from
  5. * @return a new Query object
  6. */
  7. public static Query fromView(View view) {
  8. return Query.select(view.qualifiedFields()).from(view);
  9. }

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

  1. public void testSelectFunction() {
  2. Function<String> upper = Function.upper(TestModel.LAST_NAME);
  3. SquidCursor<TestModel> cursor = database
  4. .query(TestModel.class, Query.select(TestModel.PROPERTIES).selectMore(upper));
  5. try {
  6. cursor.moveToFirst();
  7. new TestModel(cursor); // Should succeed without throwing an exception
  8. } finally {
  9. cursor.close();
  10. }
  11. }

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

  1. protected <TYPE extends AbstractModel> SquidCursor<TYPE> fetchFirstItem(Class<TYPE> modelClass,
  2. Criterion criterion, Property<?>... properties) {
  3. return fetchFirstItem(modelClass, Query.select(properties).where(criterion));
  4. }

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

  1. /**
  2. * Construct a new Select statement that queries all the {@link Field}s of the given subquery
  3. *
  4. * @param subquery the inner Query object
  5. * @param subqueryAlias the name to alias the subquery
  6. * @return a new Query object
  7. */
  8. public static Query fromSubquery(Query subquery, String subqueryAlias) {
  9. SubqueryTable table = subquery.as(subqueryAlias);
  10. return Query.select(table.qualifiedFields()).from(table);
  11. }

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

  1. /**
  2. * Count the number of rows matching a given {@link Criterion}. Use null to count all rows.
  3. *
  4. * @param modelClass the model class corresponding to the table
  5. * @param criterion the criterion to match
  6. * @return the number of rows matching the given criterion
  7. */
  8. public int count(Class<? extends AbstractModel> modelClass, Criterion criterion) {
  9. Property.IntegerProperty countProperty = Property.IntegerProperty.countProperty();
  10. Query query = Query.select(countProperty);
  11. if (criterion != null) {
  12. query.where(criterion);
  13. }
  14. query = inferTableForQuery(modelClass, query);
  15. CompiledStatement compiled = query.compile(getCompileContext());
  16. acquireNonExclusiveLock();
  17. try {
  18. return (int) getDatabase().simpleQueryForLong(compiled.sql, compiled.sqlArgs);
  19. } finally {
  20. releaseNonExclusiveLock();
  21. }
  22. }

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

  1. /**
  2. * Build a {@link Query} combining this object's internal state with the arguments passed. If a
  3. * {@link ProjectionMap} is set, the projection elements will be evaluated and transformed accordingly. If the
  4. * sortOrder is null or empty, the default order will be used (if one was set).
  5. *
  6. * @param projection the raw column names to be selected
  7. * @param selection a raw selection string
  8. * @param selectionArgs array of strings which substitute replaceable arguments in the selection string
  9. * @param sortOrder a raw ordering clause
  10. * @return a {@link Query} using the projection, selection, selection args, and sort order
  11. */
  12. public Query build(String[] projection, String selection, String[] selectionArgs, String sortOrder) {
  13. Query query = Query.select(computeProjection(projection)).from(dataSource);
  14. boolean hasUserSelection = !SqlUtils.isEmpty(selection);
  15. if (hasUserSelection) {
  16. query.where(Criterion.fromRawSelection(selection, selectionArgs));
  17. }
  18. if (!SqlUtils.isEmpty(sortOrder)) {
  19. query.orderBy(Order.fromExpression(sortOrder));
  20. } else if (defaultOrder != null && defaultOrder.length > 0) {
  21. query.orderBy(defaultOrder);
  22. }
  23. if (strictMode && hasUserSelection) {
  24. query.requestValidation();
  25. }
  26. return query;
  27. }

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

  1. @Override
  2. public void run() {
  3. Function<String> json = JSONFunctions.json(" { \"this\" : \"is\", \"a\": [ \"test\" ] } ");
  4. String minified = database.simpleQueryForString(Query.select(json));
  5. assertEquals("{\"this\":\"is\",\"a\":[\"test\"]}", minified);
  6. }
  7. });

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

  1. @Override
  2. public void run() {
  3. Function<Integer> valid = JSONFunctions.jsonValid(" { \"this\" : \"is\", \"a\": [ \"test\" ] } ");
  4. Function<Integer> invalid = JSONFunctions.jsonValid(" { \"this\" : \"is\", \"a\": [ \"test\" } ");
  5. long validResult = database.simpleQueryForLong(Query.select(valid));
  6. assertEquals(1, validResult);
  7. long invalidResult = database.simpleQueryForLong(Query.select(invalid));
  8. assertEquals(0, invalidResult);
  9. }
  10. });

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

  1. public void testObservableEmitsCustomObject() {
  2. final AtomicBoolean objectsMatch = new AtomicBoolean(false);
  3. final Query originalQuery = Query.select().from(TestModel.TABLE);
  4. Observable<Query> observable = database.observeTableAndEmit(TestModel.TABLE, originalQuery, true);
  5. observable.subscribe(new Action1<Query>() {
  6. @Override
  7. public void call(Query query) {
  8. objectsMatch.set(originalQuery == query);
  9. }
  10. });
  11. assertTrue(objectsMatch.get());
  12. }

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

  1. @Override
  2. public void run() {
  3. database.query(TestModel.class, Query.select().from(TestModel.TABLE));
  4. }
  5. });

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

  1. private boolean isJson1ExtensionEnabled() {
  2. try {
  3. return database.simpleQueryForLong(Query.select(JSONFunctions.jsonValid("{ \"a\" : \"b\" }"))) != 0;
  4. } catch (RuntimeException e) {
  5. Logger.d("JSONFunctionTest", "JSON1 extension not available", e);
  6. return false;
  7. }
  8. }

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

  1. public void testReusableQuery() {
  2. AtomicReference<String> name = new AtomicReference<>();
  3. Query query = Query.select().where(Employee.NAME.eq(name));
  4. testReusableQueryInternal(name, "bigBird", query);
  5. testReusableQueryInternal(name, "cookieMonster", query);
  6. testReusableQueryInternal(name, "elmo", query);
  7. }

代码示例来源: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 testIdColumnForTableModels() {
  2. Query query = Query.select(TestModel.PROPERTIES).orderBy(TestModel.ID.asc());
  3. testCursorAdapterInternal(new TestModel(), null, query, new CursorAdapterTest() {
  4. @Override
  5. public void testCursorAdapter(SquidCursorAdapter<AbstractModel> adapter) {
  6. assertTrue(adapter.hasStableIds());
  7. assertEquals(1, adapter.getItemId(0));
  8. assertEquals(2, adapter.getItemId(1));
  9. }
  10. });
  11. }

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

  1. private void testJsonTypeInternal(String json, String path, String expectedType) {
  2. Function<String> type;
  3. if (path == null) {
  4. type = JSONFunctions.jsonType(json);
  5. } else {
  6. type = JSONFunctions.jsonType(json, path);
  7. }
  8. String result = database.simpleQueryForString(Query.select(type));
  9. assertEquals(expectedType, result);
  10. }

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

  1. public void testFunctionOnAmbiguousColumnName() {
  2. IntegerProperty happyCount = IntegerProperty.countProperty(Employee.IS_HAPPY, false);
  3. Query test = Query.select(TestModel.ID, TestModel.FIRST_NAME, TestModel.IS_HAPPY, happyCount)
  4. .join(Join.inner(Employee.TABLE, Employee.IS_HAPPY.eq(TestModel.IS_HAPPY)));
  5. // just test that the query compiles with the function
  6. database.query(TestModel.class, test);
  7. }

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

  1. private <T extends Number> void testMath(Property<T> property, T expectedValue) {
  2. SquidCursor<?> cursor = database.query(null, Query.select(property));
  3. try {
  4. cursor.moveToFirst();
  5. T value = cursor.get(property);
  6. assertEquals(expectedValue, value);
  7. } finally {
  8. cursor.close();
  9. }
  10. }

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

  1. public void testMin() {
  2. LongProperty minId = LongProperty.fromFunction(Function.min(TestModel.ID), "minId");
  3. SquidCursor<TestModel> cursor = database.query(TestModel.class, Query.select(minId));
  4. try {
  5. cursor.moveToFirst();
  6. assertEquals(model1.getRowId(), cursor.get(minId).longValue());
  7. } finally {
  8. cursor.close();
  9. }
  10. }

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

  1. public void testBindArgsProtectsInjection() {
  2. Query q = Query.select().where(Employee.NAME.eq("'Sam'); drop table " + Employee.TABLE.getName() + ";"));
  3. SquidCursor<Employee> cursor = database.query(Employee.class, q);
  4. try {
  5. assertFalse(database.countAll(Employee.class) == 0);
  6. } finally {
  7. cursor.close();
  8. }
  9. }

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

  1. public void testQueryFreeze() {
  2. Query base = Query.select().from(Employee.TABLE).limit(1).freeze();
  3. Query fork = base.limit(2);
  4. assertFalse(base == fork);
  5. assertEquals(Field.field("1"), base.getLimit());
  6. assertEquals(Field.field("2"), fork.getLimit());
  7. assertEquals(base.getTable(), fork.getTable());
  8. }

相关文章