Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.lealone.sql.query;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.lealone.common.exceptions.DbException;
import org.lealone.db.CommandParameter;
import org.lealone.db.Database;
import org.lealone.db.api.ErrorCode;
import org.lealone.db.async.AsyncHandler;
import org.lealone.db.async.AsyncResult;
import org.lealone.db.index.IndexConditionType;
import org.lealone.db.result.Result;
import org.lealone.db.result.ResultTarget;
import org.lealone.db.result.SortOrder;
import org.lealone.db.session.ServerSession;
import org.lealone.db.table.Column;
import org.lealone.db.table.Table;
import org.lealone.db.value.Value;
import org.lealone.db.value.ValueInt;
import org.lealone.db.value.ValueNull;
import org.lealone.sql.dml.ManipulationStatement;
import org.lealone.sql.executor.YieldableBase;
import org.lealone.sql.expression.Alias;
import org.lealone.sql.expression.Expression;
import org.lealone.sql.expression.ExpressionColumn;
import org.lealone.sql.expression.Parameter;
import org.lealone.sql.expression.SelectOrderBy;
import org.lealone.sql.expression.ValueExpression;
import org.lealone.sql.expression.condition.Comparison;
import org.lealone.sql.expression.visitor.ExpressionVisitor;
import org.lealone.sql.expression.visitor.ExpressionVisitorFactory;
import org.lealone.sql.expression.visitor.MaxModificationIdVisitor;
import org.lealone.sql.optimizer.ColumnResolver;
import org.lealone.sql.optimizer.TableFilter;
/**
* Represents a SELECT statement (simple, or union).
*/
public abstract class Query extends ManipulationStatement implements org.lealone.sql.IQuery {
/**
* The limit expression as specified in the LIMIT or TOP clause.
*/
protected Expression limitExpr;
/**
* The offset expression as specified in the LIMIT .. OFFSET clause.
*/
protected Expression offsetExpr;
/**
* The sample size expression as specified in the SAMPLE_SIZE clause.
*/
protected Expression sampleSizeExpr;
/**
* Whether the result must only contain distinct rows.
*/
protected boolean distinct;
// 存放原始表达式的Alias和ColumnName,用于给客户端返回最原始的信息
protected ArrayList rawExpressionInfoList;
protected ArrayList expressions;
protected Expression[] expressionArray;
protected ArrayList orderList;
protected SortOrder sort;
protected boolean isPrepared, checkInit;
protected boolean isForUpdate;
Query(ServerSession session) {
super(session);
}
/**
* Initialize the query.
*/
public abstract void init();
/**
* The the list of select expressions.
* This may include invisible expressions such as order by expressions.
*
* @return the list of expressions
*/
@Override
public ArrayList getExpressions() {
return expressions;
}
/**
* Calculate the cost to execute this query.
*
* @return the cost
*/
@Override
public abstract double getCost();
/**
* Calculate the cost when used as a subquery.
* This method returns a value between 10 and 1000000,
* to ensure adding other values can't result in an integer overflow.
*
* @return the estimated cost as an integer
*/
public int getCostAsExpression() {
// ensure the cost is not larger than 1 million,
// so that adding other values can't overflow
return (int) Math.min(1000000.0, 10.0 + 10.0 * getCost());
}
/**
* Get all tables that are involved in this query.
*
* @return the set of tables
*/
@Override
public abstract HashSet