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

--no commit message

--no commit message
上级 3954b942
...@@ -36,9 +36,8 @@ import org.h2.value.ValueNull; ...@@ -36,9 +36,8 @@ import org.h2.value.ValueNull;
import org.h2.value.ValueString; import org.h2.value.ValueString;
/** /**
* @author Thomas * Implements the integrated aggregate functions, such as COUNT, MAX, SUM.
*/ */
public class Aggregate extends Expression { public class Aggregate extends Expression {
// TODO incompatibility to hsqldb: aggregates: hsqldb uses automatic data // TODO incompatibility to hsqldb: aggregates: hsqldb uses automatic data
// type for sum if value is too big, // type for sum if value is too big,
...@@ -344,7 +343,7 @@ public class Aggregate extends Expression { ...@@ -344,7 +343,7 @@ public class Aggregate extends Expression {
public long getPrecision() { public long getPrecision() {
return precision; return precision;
} }
public int getDisplaySize() { public int getDisplaySize() {
return displaySize; return displaySize;
} }
......
...@@ -18,6 +18,9 @@ import org.h2.value.ValueInt; ...@@ -18,6 +18,9 @@ import org.h2.value.ValueInt;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/**
* Data stored while calculating an aggregate.
*/
public class AggregateData { public class AggregateData {
private final int aggregateType; private final int aggregateType;
private long count; private long count;
......
...@@ -12,11 +12,9 @@ import org.h2.table.ColumnResolver; ...@@ -12,11 +12,9 @@ import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
* @author Thomas * A column alias as in SELECT 'Hello' AS NAME ...
*/ */
public class Alias extends Expression { public class Alias extends Expression {
private final String alias; private final String alias;
...@@ -26,7 +24,7 @@ public class Alias extends Expression { ...@@ -26,7 +24,7 @@ public class Alias extends Expression {
this.expr = expression; this.expr = expression;
this.alias = alias; this.alias = alias;
} }
public Expression getNonAliasExpression() { public Expression getNonAliasExpression() {
return expr; return expr;
} }
...@@ -59,23 +57,23 @@ public class Alias extends Expression { ...@@ -59,23 +57,23 @@ public class Alias extends Expression {
public long getPrecision() { public long getPrecision() {
return expr.getPrecision(); return expr.getPrecision();
} }
public int getDisplaySize() { public int getDisplaySize() {
return expr.getDisplaySize(); return expr.getDisplaySize();
} }
public boolean isAutoIncrement() { public boolean isAutoIncrement() {
return expr.isAutoIncrement(); return expr.isAutoIncrement();
} }
public String getSQL() { public String getSQL() {
return expr.getSQL() + " AS " + Parser.quoteIdentifier(alias); return expr.getSQL() + " AS " + Parser.quoteIdentifier(alias);
} }
public void updateAggregate(Session session) throws SQLException { public void updateAggregate(Session session) throws SQLException {
expr.updateAggregate(session); expr.updateAggregate(session);
} }
public String getAlias() { public String getAlias() {
return alias; return alias;
} }
...@@ -87,7 +85,7 @@ public class Alias extends Expression { ...@@ -87,7 +85,7 @@ public class Alias extends Expression {
public boolean isEverything(ExpressionVisitor visitor) { public boolean isEverything(ExpressionVisitor visitor) {
return expr.isEverything(visitor); return expr.isEverything(visitor);
} }
public int getCost() { public int getCost() {
return expr.getCost(); return expr.getCost();
} }
......
...@@ -22,9 +22,8 @@ import org.h2.value.ValueNull; ...@@ -22,9 +22,8 @@ import org.h2.value.ValueNull;
import org.h2.value.ValueString; import org.h2.value.ValueString;
/** /**
* @author Thomas * Pattern matching comparison expression: WHERE NAME LIKE ?
*/ */
public class CompareLike extends Condition { public class CompareLike extends Condition {
private final CompareMode compareMode; private final CompareMode compareMode;
...@@ -129,7 +128,7 @@ public class CompareLike extends Condition { ...@@ -129,7 +128,7 @@ public class CompareLike extends Condition {
// (at prepare time) // (at prepare time)
// otherwise we would need to prepare at execute time, // otherwise we would need to prepare at execute time,
// which is maybe slower (but maybe not in this case!) // 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()) { if (!right.isValueSet()) {
return; return;
} }
......
...@@ -8,7 +8,7 @@ import org.h2.value.Value; ...@@ -8,7 +8,7 @@ import org.h2.value.Value;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
/** /**
* @author Thomas * Represents a condition returning a boolean value, or NULL.
*/ */
public abstract class Condition extends Expression { public abstract class Condition extends Expression {
...@@ -23,7 +23,7 @@ public abstract class Condition extends Expression { ...@@ -23,7 +23,7 @@ public abstract class Condition extends Expression {
public long getPrecision() { public long getPrecision() {
return ValueBoolean.PRECISION; return ValueBoolean.PRECISION;
} }
public int getDisplaySize() { public int getDisplaySize() {
return ValueBoolean.DISPLAY_SIZE; return ValueBoolean.DISPLAY_SIZE;
} }
......
...@@ -17,7 +17,7 @@ import org.h2.value.ValueBoolean; ...@@ -17,7 +17,7 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
* @author Thomas * An 'and' or 'or' condition as in WHERE ID=1 AND NAME=?
*/ */
public class ConditionAndOr extends Condition { public class ConditionAndOr extends Condition {
...@@ -126,7 +126,7 @@ public class ConditionAndOr extends Condition { ...@@ -126,7 +126,7 @@ public class ConditionAndOr extends Condition {
} }
// TODO optimization: convert ((A=1 AND B=2) OR (A=1 AND B=3)) to (A=1 AND (B=2 OR B=3)) // TODO optimization: convert ((A=1 AND B=2) OR (A=1 AND B=3)) to (A=1 AND (B=2 OR B=3))
// this optimization does not work in the following case, but NOT is optimized before: // this optimization does not work in the following case, but NOT is optimized before:
// CREATE TABLE TEST(A INT, B INT); // CREATE TABLE TEST(A INT, B INT);
// INSERT INTO TEST VALUES(1, NULL); // INSERT INTO TEST VALUES(1, NULL);
// SELECT * FROM TEST WHERE NOT (B=A AND B=0); // no rows // SELECT * FROM TEST WHERE NOT (B=A AND B=0); // no rows
// SELECT * FROM TEST WHERE NOT (B=A AND B=0 AND A=0); // 1, NULL // SELECT * FROM TEST WHERE NOT (B=A AND B=0 AND A=0); // 1, NULL
...@@ -219,7 +219,7 @@ public class ConditionAndOr extends Condition { ...@@ -219,7 +219,7 @@ public class ConditionAndOr extends Condition {
public int getCost() { public int getCost() {
return left.getCost() + right.getCost(); return left.getCost() + right.getCost();
} }
public Expression optimizeInJoin(Session session, Select select) throws SQLException { public Expression optimizeInJoin(Session session, Select select) throws SQLException {
if (andOrType == AND) { if (andOrType == AND) {
Expression l = left.optimizeInJoin(session, select); Expression l = left.optimizeInJoin(session, select);
......
...@@ -15,9 +15,8 @@ import org.h2.value.Value; ...@@ -15,9 +15,8 @@ import org.h2.value.Value;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
/** /**
* @author Thomas * An 'exists' condition as in WHERE EXISTS(SELECT ...)
*/ */
public class ConditionExists extends Condition { public class ConditionExists extends Condition {
private final Query query; private final Query query;
......
...@@ -24,9 +24,8 @@ import org.h2.value.ValueBoolean; ...@@ -24,9 +24,8 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull; 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 { public class ConditionIn extends Condition {
private final Database database; private final Database database;
......
...@@ -21,7 +21,7 @@ import org.h2.value.ValueBoolean; ...@@ -21,7 +21,7 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
* @author Thomas * An 'in' condition with a subquery, as in WHERE ID IN(SELECT ...)
*/ */
public class ConditionInSelect extends Condition { public class ConditionInSelect extends Condition {
private Database database; private Database database;
......
...@@ -13,6 +13,9 @@ import org.h2.table.TableFilter; ...@@ -13,6 +13,9 @@ import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/**
* A NOT condition.
*/
public class ConditionNot extends Condition { public class ConditionNot extends Condition {
private Expression condition; private Expression condition;
......
...@@ -14,101 +14,287 @@ import org.h2.table.TableFilter; ...@@ -14,101 +14,287 @@ import org.h2.table.TableFilter;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
* An expression is a operation, a value, or a function in a query. * An expression is a operation, a value, or a function in a query.
*/ */
public abstract class Expression { public abstract class Expression {
private boolean addedToFilter; 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; 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(); 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; 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 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(); public abstract int getScale();
/**
* Get the precision of this expression.
*
* @return the precision
*/
public abstract long getPrecision(); public abstract long getPrecision();
/**
* Get the display size of this expression.
*
* @return the display size
*/
public abstract int getDisplaySize(); 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(); 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; 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); 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(); 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) { public final boolean isEverything(int expressionVisitorType) {
ExpressionVisitor visitor = ExpressionVisitor.get(expressionVisitorType); ExpressionVisitor visitor = ExpressionVisitor.get(expressionVisitorType);
return isEverything(visitor); 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) { public Expression getNotIfPossible(Session session) {
// by default it is not possible // by default it is not possible
return null; return null;
} }
/**
* Check if this expression will always return the same value.
*
* @return if the expression is constant
*/
public boolean isConstant() { public boolean isConstant() {
return false; return false;
} }
/**
* Is the value of a parameter set.
*
* @return if it is set
*/
public boolean isValueSet() { public boolean isValueSet() {
return false; return false;
} }
/**
* Check if this is an auto-increment column.
*
* @return true if it is an auto-increment column
*/
public boolean isAutoIncrement() { public boolean isAutoIncrement() {
return false; 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 { public Boolean getBooleanValue(Session session) throws SQLException {
// TODO optimization: is this required?
return getValue(session).getBoolean(); 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 { public void createIndexConditions(Session session, TableFilter filter) throws SQLException {
// default is do nothing // default is do nothing
} }
/**
* Get the column name or alias name of this expression.
*
* @return the column name
*/
public String getColumnName() { public String getColumnName() {
return getAlias(); return getAlias();
} }
/**
* Get the schema name, or null
*
* @return the schema name
*/
public String getSchemaName() { public String getSchemaName() {
return null; return null;
} }
/**
* Get the table name, or null
*
* @return the table name
*/
public String getTableName() { public String getTableName() {
return null; return null;
} }
/**
* Check whether this expression is a column and can store null values.
*
* @return whether null values are allowed
*/
public int getNullable() { public int getNullable() {
return Column.NULLABLE_UNKNOWN; 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() { public String getTableAlias() {
return null; 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() { public String getAlias() {
return StringUtils.unEnclose(getSQL()); return StringUtils.unEnclose(getSQL());
} }
/**
* Only returns true if the expression is a wildcard.
*
* @return if this expression is a wildcard
*/
public boolean isWildcard() { public boolean isWildcard() {
return false; return false;
} }
/**
* Returns the main expression, skipping aliases.
*
* @return the expression
*/
public Expression getNonAliasExpression() { public Expression getNonAliasExpression() {
return this; 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) { public void addFilterConditions(TableFilter filter, boolean outerJoin) {
if (!addedToFilter && !outerJoin && isEverything(ExpressionVisitor.EVALUATABLE)) { if (!addedToFilter && !outerJoin && isEverything(ExpressionVisitor.EVALUATABLE)) {
filter.addFilterCondition(this, false); filter.addFilterCondition(this, false);
addedToFilter = true; addedToFilter = true;
} }
} }
/**
* Convert this expression to a String.
*
* @return the string representation
*/
public String toString() { public String toString() {
return getSQL(); 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 { public Expression optimizeInJoin(Session session, Select select) throws SQLException {
return this; return this;
} }
......
...@@ -23,6 +23,9 @@ import org.h2.table.TableFilter; ...@@ -23,6 +23,9 @@ import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
/**
* A expression that represents a column of a table or view.
*/
public class ExpressionColumn extends Expression { public class ExpressionColumn extends Expression {
private Database database; private Database database;
private String schemaName; private String schemaName;
......
...@@ -12,6 +12,10 @@ import org.h2.table.TableFilter; ...@@ -12,6 +12,10 @@ import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; 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 { public class ExpressionList extends Expression {
private Expression[] list; private Expression[] list;
...@@ -66,7 +70,7 @@ public class ExpressionList extends Expression { ...@@ -66,7 +70,7 @@ public class ExpressionList extends Expression {
public long getPrecision() { public long getPrecision() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
public int getDisplaySize() { public int getDisplaySize() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
......
...@@ -7,25 +7,29 @@ package org.h2.expression; ...@@ -7,25 +7,29 @@ package org.h2.expression;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.Table; 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 { 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) // 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; public static final int INDEPENDENT = 0;
// Are all aggregates MIN(column), MAX(column), or COUNT(*)? // Are all aggregates MIN(column), MAX(column), or COUNT(*)?
public static final int OPTIMIZABLE_MIN_MAX_COUNT_ALL = 1; public static final int OPTIMIZABLE_MIN_MAX_COUNT_ALL = 1;
// Does the expression return the same results for the same parameters? // Does the expression return the same results for the same parameters?
public static final int DETERMINISTIC = 2; public static final int DETERMINISTIC = 2;
// Can the expression be evaluated, that means are all columns set to 'evaluatable'? // Can the expression be evaluated, that means are all columns set to 'evaluatable'?
public static final int EVALUATABLE = 3; public static final int EVALUATABLE = 3;
// Request to set the latest modification id // Request to set the latest modification id
public static final int SET_MAX_DATA_MODIFICATION_ID = 4; public static final int SET_MAX_DATA_MODIFICATION_ID = 4;
// Does the expression have no side effects (change the data)? // Does the expression have no side effects (change the data)?
public static final int READONLY = 5; public static final int READONLY = 5;
// Does an expression have no relation to the given table filter? // Does an expression have no relation to the given table filter?
public static final int NOT_FROM_RESOLVER = 6; public static final int NOT_FROM_RESOLVER = 6;
...@@ -34,23 +38,23 @@ public class ExpressionVisitor { ...@@ -34,23 +38,23 @@ public class ExpressionVisitor {
public int type; public int type;
private long maxDataModificationId; private long maxDataModificationId;
private ColumnResolver resolver; private ColumnResolver resolver;
public static ExpressionVisitor get(int type) { public static ExpressionVisitor get(int type) {
return new ExpressionVisitor(type); return new ExpressionVisitor(type);
} }
public long getMaxDataModificationId() { public long getMaxDataModificationId() {
return maxDataModificationId; return maxDataModificationId;
} }
private ExpressionVisitor(int type) { private ExpressionVisitor(int type) {
this.type = type; this.type = type;
} }
public void queryLevel(int offset) { public void queryLevel(int offset) {
queryLevel += offset; queryLevel += offset;
} }
public ColumnResolver getResolver() { public ColumnResolver getResolver() {
return resolver; return resolver;
} }
......
...@@ -56,9 +56,8 @@ import org.h2.value.ValueTimestamp; ...@@ -56,9 +56,8 @@ import org.h2.value.ValueTimestamp;
import org.h2.value.ValueUuid; import org.h2.value.ValueUuid;
/** /**
* @author Thomas * This class implements most built-in functions of this database.
*/ */
public class Function extends Expression implements FunctionCall { public class Function extends Expression implements FunctionCall {
// TODO functions: add function hashcode(value) // TODO functions: add function hashcode(value)
...@@ -1707,7 +1706,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -1707,7 +1706,7 @@ public class Function extends Expression implements FunctionCall {
ValueResultSet vr = ValueResultSet.get(getSimpleResultSet(result, Integer.MAX_VALUE)); ValueResultSet vr = ValueResultSet.get(getSimpleResultSet(result, Integer.MAX_VALUE));
return vr; return vr;
} }
SimpleResultSet getSimpleResultSet(LocalResult rs, int maxrows) throws SQLException { SimpleResultSet getSimpleResultSet(LocalResult rs, int maxrows) throws SQLException {
int columnCount = rs.getVisibleColumnCount(); int columnCount = rs.getVisibleColumnCount();
SimpleResultSet simple = new SimpleResultSet(); SimpleResultSet simple = new SimpleResultSet();
......
...@@ -10,6 +10,10 @@ import org.h2.engine.Session; ...@@ -10,6 +10,10 @@ import org.h2.engine.Session;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueResultSet; import org.h2.value.ValueResultSet;
/**
* This interface is used by the built-in functions,
* as well as the user defined functions.
*/
public interface FunctionCall { public interface FunctionCall {
String getName(); String getName();
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
*/ */
package org.h2.expression; package org.h2.expression;
/**
* This class contains information about a built-in function.
*/
class FunctionInfo { class FunctionInfo {
String name; String name;
int type; int type;
......
...@@ -21,8 +21,11 @@ import org.h2.value.DataType; ...@@ -21,8 +21,11 @@ import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/**
* This class wrapps a user defined aggregate.
*/
public class JavaAggregate extends Expression { public class JavaAggregate extends Expression {
private final UserAggregate userAggregate; private final UserAggregate userAggregate;
private final Select select; private final Select select;
private AggregateFunction aggregate; private AggregateFunction aggregate;
...@@ -48,11 +51,11 @@ public class JavaAggregate extends Expression { ...@@ -48,11 +51,11 @@ public class JavaAggregate extends Expression {
public long getPrecision() { public long getPrecision() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
public int getDisplaySize() { public int getDisplaySize() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
public int getScale() { public int getScale() {
return 0; return 0;
} }
...@@ -115,7 +118,7 @@ public class JavaAggregate extends Expression { ...@@ -115,7 +118,7 @@ public class JavaAggregate extends Expression {
args[i].setEvaluatable(tableFilter, b); args[i].setEvaluatable(tableFilter, b);
} }
} }
private AggregateFunction getInstance() throws SQLException { private AggregateFunction getInstance() throws SQLException {
AggregateFunction agg = userAggregate.getInstance(); AggregateFunction agg = userAggregate.getInstance();
agg.init(userConnection); agg.init(userConnection);
...@@ -164,5 +167,5 @@ public class JavaAggregate extends Expression { ...@@ -164,5 +167,5 @@ public class JavaAggregate extends Expression {
agg.add(argValues); agg.add(argValues);
} }
} }
} }
...@@ -15,6 +15,9 @@ import org.h2.value.Value; ...@@ -15,6 +15,9 @@ import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
import org.h2.value.ValueResultSet; import org.h2.value.ValueResultSet;
/**
* This class wrapps a user defined function.
*/
public class JavaFunction extends Expression implements FunctionCall { public class JavaFunction extends Expression implements FunctionCall {
private FunctionAlias functionAlias; private FunctionAlias functionAlias;
......
...@@ -16,6 +16,9 @@ import org.h2.value.Value; ...@@ -16,6 +16,9 @@ import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
import org.h2.value.ValueString; import org.h2.value.ValueString;
/**
* A mathematical expression, or string concatenation.
*/
public class Operation extends Expression { public class Operation extends Expression {
public static final int CONCAT = 0, PLUS = 1, MINUS = 2, MULTIPLY = 3, DIVIDE = 4, NEGATE = 5; public static final int CONCAT = 0, PLUS = 1, MINUS = 2, MULTIPLY = 3, DIVIDE = 4, NEGATE = 5;
private int opType; private int opType;
...@@ -202,7 +205,7 @@ public class Operation extends Expression { ...@@ -202,7 +205,7 @@ public class Operation extends Expression {
} }
return left.getPrecision(); return left.getPrecision();
} }
public int getDisplaySize() { public int getDisplaySize() {
if (right != null) { if (right != null) {
switch (opType) { switch (opType) {
......
...@@ -15,7 +15,7 @@ import org.h2.value.ValueBoolean; ...@@ -15,7 +15,7 @@ import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
* @author Thomas * A parameter of a prepared statement.
*/ */
public class Parameter extends Expression implements ParameterInterface { public class Parameter extends Expression implements ParameterInterface {
...@@ -72,7 +72,7 @@ public class Parameter extends Expression implements ParameterInterface { ...@@ -72,7 +72,7 @@ public class Parameter extends Expression implements ParameterInterface {
public boolean isConstant() { public boolean isConstant() {
return false; return false;
} }
public boolean isValueSet() { public boolean isValueSet() {
return value != null; return value != null;
} }
...@@ -88,10 +88,10 @@ public class Parameter extends Expression implements ParameterInterface { ...@@ -88,10 +88,10 @@ public class Parameter extends Expression implements ParameterInterface {
public long getPrecision() { public long getPrecision() {
return value == null ? 0 : value.getPrecision(); return value == null ? 0 : value.getPrecision();
} }
public int getDisplaySize() { public int getDisplaySize() {
return value == null ? 0 : value.getDisplaySize(); return value == null ? 0 : value.getDisplaySize();
} }
public void updateAggregate(Session session) { public void updateAggregate(Session session) {
// nothing to do // nothing to do
...@@ -118,11 +118,11 @@ public class Parameter extends Expression implements ParameterInterface { ...@@ -118,11 +118,11 @@ public class Parameter extends Expression implements ParameterInterface {
throw Message.getInternalError("type="+visitor.type); throw Message.getInternalError("type="+visitor.type);
} }
} }
public int getCost() { public int getCost() {
return 0; return 0;
} }
public Expression getNotIfPossible(Session session) { public Expression getNotIfPossible(Session session) {
return new Comparison(session, Comparison.EQUAL, this, ValueExpression.get(ValueBoolean.get(false))); return new Comparison(session, Comparison.EQUAL, this, ValueExpression.get(ValueBoolean.get(false)));
} }
......
...@@ -8,6 +8,9 @@ import java.sql.SQLException; ...@@ -8,6 +8,9 @@ import java.sql.SQLException;
import org.h2.value.Value; import org.h2.value.Value;
/**
* The interface for client side (remote) and server side parameters.
*/
public interface ParameterInterface { public interface ParameterInterface {
void setValue(Value value); void setValue(Value value);
Value getParamValue() throws SQLException; Value getParamValue() throws SQLException;
......
...@@ -10,15 +10,18 @@ import org.h2.constant.ErrorCode; ...@@ -10,15 +10,18 @@ import org.h2.constant.ErrorCode;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.value.Value; import org.h2.value.Value;
/**
* A client side (remote) parameter.
*/
public class ParameterRemote implements ParameterInterface { public class ParameterRemote implements ParameterInterface {
private Value value; private Value value;
private int index; private int index;
public ParameterRemote(int index) { public ParameterRemote(int index) {
this.index = index; this.index = index;
} }
public void setValue(Value value) { public void setValue(Value value) {
this.value = value; this.value = value;
} }
...@@ -26,7 +29,7 @@ public class ParameterRemote implements ParameterInterface { ...@@ -26,7 +29,7 @@ public class ParameterRemote implements ParameterInterface {
public Value getParamValue() { public Value getParamValue() {
return value; return value;
} }
public void checkSet() throws SQLException { public void checkSet() throws SQLException {
if (value == null) { if (value == null) {
throw Message.getSQLException(ErrorCode.PARAMETER_NOT_SET_1, "#" + (index + 1)); throw Message.getSQLException(ErrorCode.PARAMETER_NOT_SET_1, "#" + (index + 1));
......
...@@ -14,10 +14,13 @@ import org.h2.table.TableFilter; ...@@ -14,10 +14,13 @@ import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
/**
* Represents the ROWNUM function.
*/
public class Rownum extends Expression { public class Rownum extends Expression {
private Prepared prepared; private Prepared prepared;
public Rownum(Prepared prepared) { public Rownum(Prepared prepared) {
this.prepared = prepared; this.prepared = prepared;
} }
...@@ -47,7 +50,7 @@ public class Rownum extends Expression { ...@@ -47,7 +50,7 @@ public class Rownum extends Expression {
public long getPrecision() { public long getPrecision() {
return ValueInt.PRECISION; return ValueInt.PRECISION;
} }
public int getDisplaySize() { public int getDisplaySize() {
return ValueInt.DISPLAY_SIZE; return ValueInt.DISPLAY_SIZE;
} }
...@@ -80,7 +83,7 @@ public class Rownum extends Expression { ...@@ -80,7 +83,7 @@ public class Rownum extends Expression {
throw Message.getInternalError("type="+visitor.type); throw Message.getInternalError("type="+visitor.type);
} }
} }
public int getCost() { public int getCost() {
return 0; return 0;
} }
......
...@@ -15,6 +15,9 @@ import org.h2.value.Value; ...@@ -15,6 +15,9 @@ import org.h2.value.Value;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
/**
* Wraps a sequence when used in a statement.
*/
public class SequenceValue extends Expression { public class SequenceValue extends Expression {
private Sequence sequence; private Sequence sequence;
...@@ -56,10 +59,10 @@ public class SequenceValue extends Expression { ...@@ -56,10 +59,10 @@ public class SequenceValue extends Expression {
public long getPrecision() { public long getPrecision() {
return ValueInt.PRECISION; return ValueInt.PRECISION;
} }
public int getDisplaySize() { public int getDisplaySize() {
return ValueInt.DISPLAY_SIZE; return ValueInt.DISPLAY_SIZE;
} }
public String getSQL() { public String getSQL() {
return "(NEXT VALUE FOR " + sequence.getSQL() +")"; return "(NEXT VALUE FOR " + sequence.getSQL() +")";
...@@ -89,9 +92,9 @@ public class SequenceValue extends Expression { ...@@ -89,9 +92,9 @@ public class SequenceValue extends Expression {
throw Message.getInternalError("type="+visitor.type); throw Message.getInternalError("type="+visitor.type);
} }
} }
public int getCost() { public int getCost() {
return 1; return 1;
} }
} }
...@@ -18,9 +18,9 @@ import org.h2.value.ValueArray; ...@@ -18,9 +18,9 @@ import org.h2.value.ValueArray;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
* @author Thomas * A query returning a single value.
* Subqueries are used inside other statements.
*/ */
public class Subquery extends Expression { public class Subquery extends Expression {
private Query query; private Query query;
...@@ -79,10 +79,10 @@ public class Subquery extends Expression { ...@@ -79,10 +79,10 @@ public class Subquery extends Expression {
public long getPrecision() { public long getPrecision() {
return getExpression().getPrecision(); return getExpression().getPrecision();
} }
public int getDisplaySize() { public int getDisplaySize() {
return getExpression().getDisplaySize(); return getExpression().getDisplaySize();
} }
public String getSQL() { public String getSQL() {
return "(" + query.getPlanSQL() + ")"; return "(" + query.getPlanSQL() + ")";
......
...@@ -15,6 +15,9 @@ import org.h2.value.Value; ...@@ -15,6 +15,9 @@ import org.h2.value.Value;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/**
* An expression representing a constant value.
*/
public class ValueExpression extends Expression { public class ValueExpression extends Expression {
private Value value; private Value value;
...@@ -62,10 +65,10 @@ public class ValueExpression extends Expression { ...@@ -62,10 +65,10 @@ public class ValueExpression extends Expression {
public boolean isConstant() { public boolean isConstant() {
return true; return true;
} }
public boolean isValueSet() { public boolean isValueSet() {
return true; return true;
} }
public void setEvaluatable(TableFilter tableFilter, boolean b) { public void setEvaluatable(TableFilter tableFilter, boolean b) {
} }
...@@ -77,7 +80,7 @@ public class ValueExpression extends Expression { ...@@ -77,7 +80,7 @@ public class ValueExpression extends Expression {
public long getPrecision() { public long getPrecision() {
return value.getPrecision(); return value.getPrecision();
} }
public int getDisplaySize() { public int getDisplaySize() {
return value.getDisplaySize(); return value.getDisplaySize();
} }
......
...@@ -13,11 +13,11 @@ import org.h2.table.ColumnResolver; ...@@ -13,11 +13,11 @@ import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.Value; 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 { public class Wildcard extends Expression {
private String schema; private String schema;
private String table; private String table;
...@@ -80,13 +80,13 @@ public class Wildcard extends Expression { ...@@ -80,13 +80,13 @@ public class Wildcard extends Expression {
} }
public void updateAggregate(Session session) { public void updateAggregate(Session session) {
throw Message.getInternalError(); throw Message.getInternalError();
} }
public boolean isEverything(ExpressionVisitor visitor) { public boolean isEverything(ExpressionVisitor visitor) {
throw Message.getInternalError(); throw Message.getInternalError();
} }
public int getCost() { public int getCost() {
throw Message.getInternalError(); throw Message.getInternalError();
} }
......
...@@ -14,6 +14,9 @@ import java.util.HashSet; ...@@ -14,6 +14,9 @@ import java.util.HashSet;
import org.h2.util.ObjectUtils; import org.h2.util.ObjectUtils;
/**
* The global settings of a full text search.
*/
public class FullTextSettings { public class FullTextSettings {
private static HashMap settings = new HashMap(); private static HashMap settings = new HashMap();
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
*/ */
package org.h2.fulltext; package org.h2.fulltext;
/**
* The settings of one full text search index.
*/
public class IndexInfo { public class IndexInfo {
int id; int id;
String schemaName; String schemaName;
......
...@@ -9,14 +9,13 @@ import java.io.InputStream; ...@@ -9,14 +9,13 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.sql.SQLException; import java.sql.SQLException;
public abstract class FileSystem { public abstract class FileSystem {
public static final String MEMORY_PREFIX = "memFS:"; public static final String MEMORY_PREFIX = "memFS:";
public static final String MEMORY_PREFIX_LZF = "memLZF:"; public static final String MEMORY_PREFIX_LZF = "memLZF:";
public static final String DB_PREFIX = "jdbc:"; public static final String DB_PREFIX = "jdbc:";
public static final String ZIP_PREFIX = "zip:"; public static final String ZIP_PREFIX = "zip:";
public static FileSystem getInstance(String fileName) { public static FileSystem getInstance(String fileName) {
if (isInMemory(fileName)) { if (isInMemory(fileName)) {
return FileSystemMemory.getInstance(); return FileSystemMemory.getInstance();
...@@ -27,27 +26,27 @@ public abstract class FileSystem { ...@@ -27,27 +26,27 @@ public abstract class FileSystem {
} }
return FileSystemDisk.getInstance(); return FileSystemDisk.getInstance();
} }
private static boolean isInMemory(String fileName) { private static boolean isInMemory(String fileName) {
return fileName != null && (fileName.startsWith(MEMORY_PREFIX) || fileName.startsWith(MEMORY_PREFIX_LZF)); return fileName != null && (fileName.startsWith(MEMORY_PREFIX) || fileName.startsWith(MEMORY_PREFIX_LZF));
} }
public abstract long length(String fileName); public abstract long length(String fileName);
public abstract void rename(String oldName, String newName) throws SQLException; public abstract void rename(String oldName, String newName) throws SQLException;
public abstract boolean createNewFile(String fileName) throws SQLException; public abstract boolean createNewFile(String fileName) throws SQLException;
public abstract boolean exists(String fileName); public abstract boolean exists(String fileName);
public abstract void delete(String fileName) throws SQLException; public abstract void delete(String fileName) throws SQLException;
public abstract boolean tryDelete(String fileName); public abstract boolean tryDelete(String fileName);
public abstract String createTempFile(String prefix, String suffix, boolean deleteOnExit, boolean inTempDir) throws IOException; public abstract String createTempFile(String prefix, String suffix, boolean deleteOnExit, boolean inTempDir) throws IOException;
public abstract String[] listFiles(String path) throws SQLException; public abstract String[] listFiles(String path) throws SQLException;
public abstract void deleteRecursive(String fileName) throws SQLException; public abstract void deleteRecursive(String fileName) throws SQLException;
public abstract boolean isReadOnly(String fileName); public abstract boolean isReadOnly(String fileName);
...@@ -59,7 +58,7 @@ public abstract class FileSystem { ...@@ -59,7 +58,7 @@ public abstract class FileSystem {
public abstract boolean isDirectory(String fileName); public abstract boolean isDirectory(String fileName);
public abstract boolean isAbsolute(String fileName); public abstract boolean isAbsolute(String fileName);
public abstract String getAbsolutePath(String fileName); public abstract String getAbsolutePath(String fileName);
public abstract long getLastModified(String fileName); public abstract long getLastModified(String fileName);
...@@ -67,20 +66,20 @@ public abstract class FileSystem { ...@@ -67,20 +66,20 @@ public abstract class FileSystem {
public abstract boolean canWrite(String fileName); public abstract boolean canWrite(String fileName);
public abstract void copy(String original, String copy) throws SQLException; public abstract void copy(String original, String copy) throws SQLException;
public void mkdirs(String directoryName) throws SQLException { public void mkdirs(String directoryName) throws SQLException {
createDirs(directoryName + "/x"); createDirs(directoryName + "/x");
} }
public abstract void createDirs(String fileName) throws SQLException; public abstract void createDirs(String fileName) throws SQLException;
public abstract String getFileName(String name) throws SQLException; public abstract String getFileName(String name) throws SQLException;
public abstract boolean fileStartsWith(String fileName, String prefix); public abstract boolean fileStartsWith(String fileName, String prefix);
public abstract OutputStream openFileOutputStream(String fileName, boolean append) throws SQLException; public abstract OutputStream openFileOutputStream(String fileName, boolean append) throws SQLException;
public abstract FileObject openFileObject(String fileName, String mode) throws IOException; public abstract FileObject openFileObject(String fileName, String mode) throws IOException;
public abstract InputStream openFileInputStream(String fileName) throws IOException; public abstract InputStream openFileInputStream(String fileName) throws IOException;
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论