org.h2.command.dml.Query类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(328)

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

Query介绍

[英]Represents a SELECT statement (simple, or union).
[中]表示SELECT语句(简单或联合)。

代码示例

代码示例来源:origin: com.h2database/h2

  1. @Override
  2. public void init() {
  3. if (SysProperties.CHECK && checkInit) {
  4. DbException.throwInternalError();
  5. }
  6. checkInit = true;
  7. left.init();
  8. right.init();
  9. int len = left.getColumnCount();
  10. if (len != right.getColumnCount()) {
  11. throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
  12. }
  13. ArrayList<Expression> le = left.getExpressions();
  14. // set the expressions to get the right column count and names,
  15. // but can't validate at this time
  16. expressions = New.arrayList();
  17. for (int i = 0; i < len; i++) {
  18. Expression l = le.get(i);
  19. expressions.add(l);
  20. }
  21. }

代码示例来源:origin: com.h2database/h2

  1. return q;
  2. if (!q.allowGlobalConditions()) {
  3. return q;
  4. if ((mask & IndexCondition.EQUALITY) != 0) {
  5. Parameter param = new Parameter(firstIndexParam + i);
  6. q.addGlobalCondition(param, idx, Comparison.EQUAL_NULL_SAFE);
  7. i++;
  8. q.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
  9. i++;
  10. q.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
  11. i++;
  12. q.addGlobalCondition(param, idx, Comparison.SPATIAL_INTERSECTS);
  13. i++;
  14. String sql = q.getPlanSQL();
  15. q = prepareSubQuery(sql, session, masks, filters, filter, sortOrder);
  16. return q;

代码示例来源:origin: com.h2database/h2

  1. if (isUnion()) {
  2. return queryWithoutCacheLazyCheck(limit, target);
  3. fireBeforeSelectTriggers();
  4. if (noCache || !session.getDatabase().getOptimizeReuseResults() ||
  5. session.isLazyQueryExecution()) {
  6. return queryWithoutCacheLazyCheck(limit, target);
  7. Value[] params = getParameterValues();
  8. long now = session.getDatabase().getModificationDataId();
  9. if (isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR)) {
  10. if (lastResult != null && !lastResult.isClosed() &&
  11. limit == lastLimit) {
  12. if (sameResultAsLast(session, params, lastParameters,
  13. lastEvaluated)) {
  14. lastResult = lastResult.createShallowCopy(session);
  15. closeLastResult();
  16. ResultInterface r = queryWithoutCacheLazyCheck(limit, target);
  17. lastResult = r;
  18. this.lastEvaluated = now;

代码示例来源:origin: com.h2database/h2

  1. private Expression getExpression() {
  2. if (expression == null) {
  3. ArrayList<Expression> expressions = query.getExpressions();
  4. int columnCount = query.getColumnCount();
  5. if (columnCount == 1) {
  6. expression = expressions.get(0);
  7. } else {
  8. Expression[] list = new Expression[columnCount];
  9. for (int i = 0; i < columnCount; i++) {
  10. list[i] = expressions.get(i);
  11. }
  12. expression = new ExpressionList(list);
  13. }
  14. }
  15. return expression;
  16. }

代码示例来源:origin: com.h2database/h2

  1. @Override
  2. public Expression optimize(Session session) {
  3. left = left.optimize(session);
  4. query.setRandomAccessResult(true);
  5. session.optimizeQueryExpression(query);
  6. if (query.getColumnCount() != 1) {
  7. throw DbException.get(ErrorCode.SUBQUERY_IS_NOT_SINGLE_COLUMN);
  8. }
  9. // Can not optimize: the data may change
  10. return this;
  11. }

代码示例来源:origin: com.eventsourcing/h2

  1. fireBeforeSelectTriggers();
  2. if (noCache || !session.getDatabase().getOptimizeReuseResults()) {
  3. return queryWithoutCache(limit, target);
  4. Value[] params = getParameterValues();
  5. long now = session.getDatabase().getModificationDataId();
  6. if (isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR)) {
  7. if (lastResult != null && !lastResult.isClosed() &&
  8. limit == lastLimit) {
  9. if (sameResultAsLast(session, params, lastParameters,
  10. lastEvaluated)) {
  11. lastResult = lastResult.createShallowCopy(session);
  12. closeLastResult();
  13. LocalResult r = queryWithoutCache(limit, target);
  14. lastResult = r;
  15. this.lastEvaluated = now;

代码示例来源:origin: com.h2database/h2

  1. try {
  2. Query compiledQuery = compileViewQuery(session, querySQL, literalsChecked, getName());
  3. this.querySQL = compiledQuery.getPlanSQL();
  4. tables = new ArrayList<>(compiledQuery.getTables());
  5. ArrayList<Expression> expressions = compiledQuery.getExpressions();
  6. ArrayList<Column> list = New.arrayList();
  7. ColumnNamer columnNamer = new ColumnNamer(session);
  8. for (int i = 0, count = compiledQuery.getColumnCount(); i < count; i++) {
  9. Expression expr = expressions.get(i);
  10. String name = null;

代码示例来源:origin: com.h2database/h2

  1. Query theQuery, String[] querySQLOutput) {
  2. List<Column> columnTemplateList = new ArrayList<>();
  3. theQuery.prepare();
  4. querySQLOutput[0] = StringUtils.cache(theQuery.getPlanSQL());
  5. ColumnNamer columnNamer = new ColumnNamer(theQuery.getSession());
  6. ArrayList<Expression> withExpressions = theQuery.getExpressions();
  7. for (int i = 0; i < withExpressions.size(); ++i) {
  8. Expression columnExp = withExpressions.get(i);

代码示例来源:origin: com.h2database/h2

  1. left.prepare();
  2. right.prepare();
  3. int len = left.getColumnCount();
  4. ArrayList<Expression> le = left.getExpressions();
  5. ArrayList<Expression> re = right.getExpressions();
  6. ColumnNamer columnNamer= new ColumnNamer(session);
  7. for (int i = 0; i < len; i++) {

代码示例来源:origin: com.h2database/h2

  1. /**
  2. * Create a temporary view out of the given query.
  3. *
  4. * @param session the session
  5. * @param owner the owner of the query
  6. * @param name the view name
  7. * @param query the query
  8. * @param topQuery the top level query
  9. * @return the view table
  10. */
  11. public static TableView createTempView(Session session, User owner,
  12. String name, Query query, Query topQuery) {
  13. Schema mainSchema = session.getDatabase().getSchema(Constants.SCHEMA_MAIN);
  14. String querySQL = query.getPlanSQL();
  15. TableView v = new TableView(mainSchema, 0, name,
  16. querySQL, query.getParameters(), null /* column templates */, session,
  17. false/* allow recursive */, true /* literals have already been checked when parsing original query */,
  18. false /* is table expression */, false/* is persistent*/);
  19. if (v.createException != null) {
  20. throw v.createException;
  21. }
  22. v.setTopQuery(topQuery);
  23. v.setOwner(owner);
  24. v.setTemporary(true);
  25. return v;
  26. }

代码示例来源:origin: com.h2database/h2

  1. query.prepare();
  2. if (query.getColumnCount() != columns.length) {
  3. throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);

代码示例来源:origin: com.h2database/h2

  1. private boolean sameResultAsLast(Session s, Value[] params,
  2. Value[] lastParams, long lastEval) {
  3. if (!cacheableChecked) {
  4. long max = getMaxDataModificationId();
  5. noCache = max == Long.MAX_VALUE;
  6. cacheableChecked = true;
  7. }
  8. if (noCache) {
  9. return false;
  10. }
  11. Database db = s.getDatabase();
  12. for (int i = 0; i < params.length; i++) {
  13. Value a = lastParams[i], b = params[i];
  14. if (a.getType() != b.getType() || !db.areEqual(a, b)) {
  15. return false;
  16. }
  17. }
  18. if (!isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR) ||
  19. !isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)) {
  20. return false;
  21. }
  22. if (db.getModificationDataId() > lastEval &&
  23. getMaxDataModificationId() > lastEval) {
  24. return false;
  25. }
  26. return true;
  27. }

代码示例来源:origin: com.h2database/com.springsource.org.h2

  1. public LocalResult query(int limit) throws SQLException {
  2. if (!session.getDatabase().getOptimizeReuseResults()) {
  3. return queryWithoutCache(limit);
  4. }
  5. Value[] params = getParameterValues();
  6. long now = session.getDatabase().getModificationDataId();
  7. if (lastResult != null && !lastResult.isClosed() && limit == lastLimit) {
  8. if (sameResultAsLast(session, params, lastParameters, lastEvaluated)) {
  9. lastResult = lastResult.createShallowCopy(session);
  10. if (lastResult != null) {
  11. lastResult.reset();
  12. return lastResult;
  13. }
  14. }
  15. }
  16. lastParameters = params;
  17. closeLastResult();
  18. lastResult = queryWithoutCache(limit);
  19. this.lastEvaluated = now;
  20. lastLimit = limit;
  21. return lastResult;
  22. }

代码示例来源:origin: com.h2database/com.springsource.org.h2

  1. columns[i] = col;
  2. int mask = masks[idx];
  3. int nextParamIndex = query.getParameters().size();
  4. if ((mask & IndexCondition.EQUALITY) != 0) {
  5. Parameter param = new Parameter(nextParamIndex);
  6. query.addGlobalCondition(param, idx, Comparison.EQUAL);
  7. } else {
  8. if ((mask & IndexCondition.START) != 0) {
  9. Parameter param = new Parameter(nextParamIndex);
  10. query.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
  11. query.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
  12. return 10;
  13. String sql = query.getPlanSQL();
  14. query = (Query) session.prepare(sql);
  15. double cost = query.getCost();
  16. cachedCost = new CostElement();
  17. cachedCost.evaluatedAt = System.currentTimeMillis();

代码示例来源:origin: com.h2database/h2

  1. @Override
  2. public String getPlanSQL() {
  3. return query == null ? null : query.getPlanSQL();
  4. }

代码示例来源:origin: com.h2database/h2

  1. @Override
  2. public double getCost(Session session, int[] masks,
  3. TableFilter[] filters, int filter, SortOrder sortOrder,
  4. HashSet<Column> allColumnsSet) {
  5. return recursive ? 1000 : query.getCost();
  6. }

代码示例来源:origin: com.h2database/h2

  1. if (sort == null && !distinct && maxRows == 0 &&
  2. offsetExpr == null && limitExpr == null) {
  3. left.query(0, target);
  4. right.query(0, target);
  5. return null;
  6. int columnCount = left.getColumnCount();
  7. if (session.isLazyQueryExecution() && unionType == UnionType.UNION_ALL && !distinct &&
  8. sort == null && !randomAccessResult && !isForUpdate &&
  9. left.setDistinct(true);
  10. right.setDistinct(true);
  11. result.setDistinct();
  12. case UNION:
  13. case EXCEPT:
  14. left.setDistinct(true);
  15. right.setDistinct(true);
  16. result.setDistinct();
  17. break;
  18. break;
  19. case INTERSECT:
  20. left.setDistinct(true);
  21. right.setDistinct(true);
  22. break;
  23. default:
  24. DbException.throwInternalError("type=" + unionType);

代码示例来源:origin: com.h2database/com.springsource.org.h2

  1. try {
  2. Query query = recompileQuery(session);
  3. tables = new ObjectArray(query.getTables());
  4. ObjectArray expressions = query.getExpressions();
  5. ObjectArray list = new ObjectArray();
  6. for (int i = 0; i < query.getColumnCount(); i++) {
  7. Expression expr = (Expression) expressions.get(i);
  8. String name = null;

代码示例来源:origin: apache/ignite

  1. /**
  2. * @param qry Query.
  3. * @param expCol Expression column.
  4. * @param validate Query validation flag.
  5. * @return {@code true} It it is an affinity column.
  6. */
  7. private static boolean isAffinityColumn(Query qry, ExpressionColumn expCol, boolean validate) {
  8. if (qry.isUnion()) {
  9. SelectUnion union = (SelectUnion)qry;
  10. return isAffinityColumn(union.getLeft(), expCol, validate) && isAffinityColumn(union.getRight(), expCol, validate);
  11. }
  12. Expression exp = qry.getExpressions().get(expCol.getColumn().getColumnId()).getNonAliasExpression();
  13. if (exp instanceof ExpressionColumn) {
  14. expCol = (ExpressionColumn)exp;
  15. return isAffinityColumn(expCol.getTableFilter(), expCol, validate);
  16. }
  17. return false;
  18. }

代码示例来源:origin: com.h2database/h2

  1. public final Value[] getParameterValues() {
  2. ArrayList<Parameter> list = getParameters();
  3. if (list == null) {
  4. list = New.arrayList();
  5. }
  6. int size = list.size();
  7. Value[] params = new Value[size];
  8. for (int i = 0; i < size; i++) {
  9. Value v = list.get(i).getParamValue();
  10. params[i] = v;
  11. }
  12. return params;
  13. }

相关文章