提交 faecae21 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 3954b942
......@@ -36,9 +36,8 @@ import org.h2.value.ValueNull;
import org.h2.value.ValueString;
/**
* @author Thomas
* Implements the integrated aggregate functions, such as COUNT, MAX, SUM.
*/
public class Aggregate extends Expression {
// TODO incompatibility to hsqldb: aggregates: hsqldb uses automatic data
// type for sum if value is too big,
......
......@@ -18,6 +18,9 @@ import org.h2.value.ValueInt;
import org.h2.value.ValueLong;
import org.h2.value.ValueNull;
/**
* Data stored while calculating an aggregate.
*/
public class AggregateData {
private final int aggregateType;
private long count;
......
......@@ -12,11 +12,9 @@ import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.Value;
/**
* @author Thomas
* A column alias as in SELECT 'Hello' AS NAME ...
*/
public class Alias extends Expression {
private final String alias;
......
......@@ -22,9 +22,8 @@ import org.h2.value.ValueNull;
import org.h2.value.ValueString;
/**
* @author Thomas
* Pattern matching comparison expression: WHERE NAME LIKE ?
*/
public class CompareLike extends Condition {
private final CompareMode compareMode;
......@@ -129,7 +128,7 @@ public class CompareLike extends Condition {
// (at prepare time)
// otherwise we would need to prepare at execute time,
// which is maybe slower (but maybe not in this case!)
// TODO optimizer: like: check what other databases do!
// TODO optimizer: like: check what other databases do
if (!right.isValueSet()) {
return;
}
......
......@@ -8,7 +8,7 @@ import org.h2.value.Value;
import org.h2.value.ValueBoolean;
/**
* @author Thomas
* Represents a condition returning a boolean value, or NULL.
*/
public abstract class Condition extends Expression {
......
......@@ -17,7 +17,7 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull;
/**
* @author Thomas
* An 'and' or 'or' condition as in WHERE ID=1 AND NAME=?
*/
public class ConditionAndOr extends Condition {
......
......@@ -15,9 +15,8 @@ import org.h2.value.Value;
import org.h2.value.ValueBoolean;
/**
* @author Thomas
* An 'exists' condition as in WHERE EXISTS(SELECT ...)
*/
public class ConditionExists extends Condition {
private final Query query;
......
......@@ -24,9 +24,8 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull;
/**
* @author Thomas
* An 'in' condition with a list of values, as in WHERE NAME IN(...)
*/
public class ConditionIn extends Condition {
private final Database database;
......
......@@ -21,7 +21,7 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull;
/**
* @author Thomas
* An 'in' condition with a subquery, as in WHERE ID IN(SELECT ...)
*/
public class ConditionInSelect extends Condition {
private Database database;
......
......@@ -13,6 +13,9 @@ import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueNull;
/**
* A NOT condition.
*/
public class ConditionNot extends Condition {
private Expression condition;
......
......@@ -14,7 +14,6 @@ import org.h2.table.TableFilter;
import org.h2.util.StringUtils;
import org.h2.value.Value;
/**
* An expression is a operation, a value, or a function in a query.
*/
......@@ -22,82 +21,257 @@ public abstract class Expression {
private boolean addedToFilter;
/**
* Return the resulting value for the current row.
*
* @param session the session
* @return the result
*/
public abstract Value getValue(Session session) throws SQLException;
/**
* Return the data type. The data type may not be known before the optimization phase.
*
* @param session the session
* @return the type
*/
public abstract int getType();
/**
* Map the columns of the resolver to expression columns.
*
* @param resolver the column resolver
* @return level the subquery nesting level
*/
public abstract void mapColumns(ColumnResolver resolver, int level) throws SQLException;
/**
* Try to optimize the expression.
*
* @param session the session
* @return the optimized expression
*/
public abstract Expression optimize(Session session) throws SQLException;
public abstract void setEvaluatable(TableFilter tableFilter, boolean b);
/**
* Tell the expression columns whether the table filter can return values now.
* This is used when optimizing the query.
*
* @param tableFilter the table filter
* @param value true if the table filter can return value
*/
public abstract void setEvaluatable(TableFilter tableFilter, boolean value);
/**
* Get the scale of this expression.
*
* @return the scale
*/
public abstract int getScale();
/**
* Get the precision of this expression.
*
* @return the precision
*/
public abstract long getPrecision();
/**
* Get the display size of this expression.
*
* @return the display size
*/
public abstract int getDisplaySize();
/**
* Get the SQL statement of this expression.
* This may not always be the original SQL statement,
* specially after optimization.
*
* @return the SQL statement
*/
public abstract String getSQL();
/**
* Update an aggregate value.
* This method is called at statement execution time once for each row.
*
* @param session the session
*/
public abstract void updateAggregate(Session session) throws SQLException;
/**
* Check if this expression and all sub-expressions can fulfill a criteria.
* If any part returns false, the result is false.
*
* @param visitor the visitor
* @return if the criteria can be fulfilled
*/
public abstract boolean isEverything(ExpressionVisitor visitor);
/**
* Estimate the cost to process the expression.
* Used when optimizing the query, to calculate the query plan
* with the lowest estimated cost.
*
* @return the estimated cost
*/
public abstract int getCost();
/**
* Check if this expression and all sub-expressions can fulfill a criteria.
* This is a convenience function.
*
* @param expressionVisitorType the visitor type
* @return if the criteria can be fulfilled
*/
public final boolean isEverything(int expressionVisitorType) {
ExpressionVisitor visitor = ExpressionVisitor.get(expressionVisitorType);
return isEverything(visitor);
}
/**
* If it is possible, return the negated expression. This is used
* to optimize NOT expressions: NOT ID>10 can be converted to
* ID<=10. Returns null if negating is not possible.
*
* @param session the session
* @return the negated expression, or null
*/
public Expression getNotIfPossible(Session session) {
// by default it is not possible
return null;
}
/**
* Check if this expression will always return the same value.
*
* @return if the expression is constant
*/
public boolean isConstant() {
return false;
}
/**
* Is the value of a parameter set.
*
* @return if it is set
*/
public boolean isValueSet() {
return false;
}
/**
* Check if this is an auto-increment column.
*
* @return true if it is an auto-increment column
*/
public boolean isAutoIncrement() {
return false;
}
/**
* Get the value in form of a boolean expression.
* Returns true, false, or null.
* In this database, everything can be a condition.
*
* @param session the session
* @return the result
*/
public Boolean getBooleanValue(Session session) throws SQLException {
// TODO optimization: is this required?
return getValue(session).getBoolean();
}
/**
* Create index conditions if possible and attach them to the table filter.
*
* @param session the session
* @param filter the table filter
*/
public void createIndexConditions(Session session, TableFilter filter) throws SQLException {
// default is do nothing
}
/**
* Get the column name or alias name of this expression.
*
* @return the column name
*/
public String getColumnName() {
return getAlias();
}
/**
* Get the schema name, or null
*
* @return the schema name
*/
public String getSchemaName() {
return null;
}
/**
* Get the table name, or null
*
* @return the table name
*/
public String getTableName() {
return null;
}
/**
* Check whether this expression is a column and can store null values.
*
* @return whether null values are allowed
*/
public int getNullable() {
return Column.NULLABLE_UNKNOWN;
}
/**
* Get the table alias name or null
* if this expression does not represent a column.
*
* @return the table alias name
*/
public String getTableAlias() {
return null;
}
/**
* Get the alias name of a column or SQL expression
* if it is not an aliased expression.
*
* @return the alias name
*/
public String getAlias() {
return StringUtils.unEnclose(getSQL());
}
/**
* Only returns true if the expression is a wildcard.
*
* @return if this expression is a wildcard
*/
public boolean isWildcard() {
return false;
}
/**
* Returns the main expression, skipping aliases.
*
* @return the expression
*/
public Expression getNonAliasExpression() {
return this;
}
/**
* Add conditions to a table filter if they can be evaluated.
*
* @param filter the table filter
* @param outerJoin if the expression is part of an outer join
*/
public void addFilterConditions(TableFilter filter, boolean outerJoin) {
if (!addedToFilter && !outerJoin && isEverything(ExpressionVisitor.EVALUATABLE)) {
filter.addFilterCondition(this, false);
......@@ -105,10 +279,22 @@ public abstract class Expression {
}
}
/**
* Convert this expression to a String.
*
* @return the string representation
*/
public String toString() {
return getSQL();
}
/**
* Optimize IN(...) expressions if possible.
*
* @param session the session
* @param select the query
* @return the optimized expression
*/
public Expression optimizeInJoin(Session session, Select select) throws SQLException {
return this;
}
......
......@@ -23,6 +23,9 @@ import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueBoolean;
/**
* A expression that represents a column of a table or view.
*/
public class ExpressionColumn extends Expression {
private Database database;
private String schemaName;
......
......@@ -12,6 +12,10 @@ import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueArray;
/**
* A list of expressions, as in (ID, NAME).
* The result of this expression is an array.
*/
public class ExpressionList extends Expression {
private Expression[] list;
......
......@@ -7,6 +7,10 @@ package org.h2.expression;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
/**
* The visitor pattern is used to iterate through all expressions of a query
* to optimize a statement.
*/
public class ExpressionVisitor {
// Is the value independent on unset parameters or on columns of a higher level query, or sequence values (that means can it be evaluated right now)
public static final int INDEPENDENT = 0;
......
......@@ -56,9 +56,8 @@ import org.h2.value.ValueTimestamp;
import org.h2.value.ValueUuid;
/**
* @author Thomas
* This class implements most built-in functions of this database.
*/
public class Function extends Expression implements FunctionCall {
// TODO functions: add function hashcode(value)
......
......@@ -10,6 +10,10 @@ import org.h2.engine.Session;
import org.h2.value.Value;
import org.h2.value.ValueResultSet;
/**
* This interface is used by the built-in functions,
* as well as the user defined functions.
*/
public interface FunctionCall {
String getName();
......
......@@ -4,6 +4,9 @@
*/
package org.h2.expression;
/**
* This class contains information about a built-in function.
*/
class FunctionInfo {
String name;
int type;
......
......@@ -21,6 +21,9 @@ import org.h2.value.DataType;
import org.h2.value.Value;
import org.h2.value.ValueNull;
/**
* This class wrapps a user defined aggregate.
*/
public class JavaAggregate extends Expression {
private final UserAggregate userAggregate;
......
......@@ -15,6 +15,9 @@ import org.h2.value.Value;
import org.h2.value.ValueNull;
import org.h2.value.ValueResultSet;
/**
* This class wrapps a user defined function.
*/
public class JavaFunction extends Expression implements FunctionCall {
private FunctionAlias functionAlias;
......
......@@ -16,6 +16,9 @@ import org.h2.value.Value;
import org.h2.value.ValueNull;
import org.h2.value.ValueString;
/**
* A mathematical expression, or string concatenation.
*/
public class Operation extends Expression {
public static final int CONCAT = 0, PLUS = 1, MINUS = 2, MULTIPLY = 3, DIVIDE = 4, NEGATE = 5;
private int opType;
......
......@@ -15,7 +15,7 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull;
/**
* @author Thomas
* A parameter of a prepared statement.
*/
public class Parameter extends Expression implements ParameterInterface {
......
......@@ -8,6 +8,9 @@ import java.sql.SQLException;
import org.h2.value.Value;
/**
* The interface for client side (remote) and server side parameters.
*/
public interface ParameterInterface {
void setValue(Value value);
Value getParamValue() throws SQLException;
......
......@@ -10,6 +10,9 @@ import org.h2.constant.ErrorCode;
import org.h2.message.Message;
import org.h2.value.Value;
/**
* A client side (remote) parameter.
*/
public class ParameterRemote implements ParameterInterface {
private Value value;
......
......@@ -14,6 +14,9 @@ import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueInt;
/**
* Represents the ROWNUM function.
*/
public class Rownum extends Expression {
private Prepared prepared;
......
......@@ -15,6 +15,9 @@ import org.h2.value.Value;
import org.h2.value.ValueInt;
import org.h2.value.ValueLong;
/**
* Wraps a sequence when used in a statement.
*/
public class SequenceValue extends Expression {
private Sequence sequence;
......
......@@ -18,9 +18,9 @@ import org.h2.value.ValueArray;
import org.h2.value.ValueNull;
/**
* @author Thomas
* A query returning a single value.
* Subqueries are used inside other statements.
*/
public class Subquery extends Expression {
private Query query;
......
......@@ -15,6 +15,9 @@ import org.h2.value.Value;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull;
/**
* An expression representing a constant value.
*/
public class ValueExpression extends Expression {
private Value value;
......
......@@ -13,11 +13,11 @@ import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.Value;
/**
* @author Thomas
* A wildcard expression as in SELECT * FROM TEST.
* This object is only used temporarily during the parsing phase, and later
* replaced by column expressions.
*/
public class Wildcard extends Expression {
private String schema;
private String table;
......
......@@ -14,6 +14,9 @@ import java.util.HashSet;
import org.h2.util.ObjectUtils;
/**
* The global settings of a full text search.
*/
public class FullTextSettings {
private static HashMap settings = new HashMap();
......
......@@ -4,6 +4,9 @@
*/
package org.h2.fulltext;
/**
* The settings of one full text search index.
*/
public class IndexInfo {
int id;
String schemaName;
......
......@@ -9,7 +9,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
public abstract class FileSystem {
public static final String MEMORY_PREFIX = "memFS:";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论