提交 4867529d authored 作者: Noel Grandin's avatar Noel Grandin

javadoc update

上级 8722b796
...@@ -114,6 +114,9 @@ public class Select extends Query { ...@@ -114,6 +114,9 @@ public class Select extends Query {
private int[] groupByCopies; private int[] groupByCopies;
/**
* Whether this query contains aggregate functions.
*/
boolean isGroupQuery; boolean isGroupQuery;
private boolean isGroupSortedQuery; private boolean isGroupSortedQuery;
private boolean isWindowQuery; private boolean isWindowQuery;
...@@ -194,6 +197,12 @@ public class Select extends Query { ...@@ -194,6 +197,12 @@ public class Select extends Query {
return group; return group;
} }
/**
* Get the group data if there is currently a group-by active.
*
* @param window is this a window function
* @return the grouped data
*/
public SelectGroups getGroupDataIfCurrent(boolean window) { public SelectGroups getGroupDataIfCurrent(boolean window) {
return groupData != null && (window || groupData.isCurrentGroup()) ? groupData : null; return groupData != null && (window || groupData.isCurrentGroup()) ? groupData : null;
} }
...@@ -471,6 +480,12 @@ public class Select extends Query { ...@@ -471,6 +480,12 @@ public class Select extends Query {
groupData.done(); groupData.done();
} }
/**
* Update any aggregate expressions with the query stage.
* @param columnCount number of columns
* @param stage stage of query (window or normal)
*/
void updateAgg(int columnCount, int stage) { void updateAgg(int columnCount, int stage) {
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
if ((groupByExpression == null || !groupByExpression[i]) if ((groupByExpression == null || !groupByExpression[i])
......
...@@ -40,6 +40,12 @@ public abstract class Expression { ...@@ -40,6 +40,12 @@ public abstract class Expression {
private boolean addedToFilter; private boolean addedToFilter;
/**
* Get the SQL snippet for a list of expressions.
*
* @param builder the builder to append the SQL to
* @param expressions the list of expressions
*/
public static void writeExpressions(StringBuilder builder, List<? extends Expression> expressions) { public static void writeExpressions(StringBuilder builder, List<? extends Expression> expressions) {
for (int i = 0, length = expressions.size(); i < length; i++) { for (int i = 0, length = expressions.size(); i < length; i++) {
if (i > 0) { if (i > 0) {
...@@ -49,6 +55,12 @@ public abstract class Expression { ...@@ -49,6 +55,12 @@ public abstract class Expression {
} }
} }
/**
* Get the SQL snippet for an array of expressions.
*
* @param builder the builder to append the SQL to
* @param expressions the list of expressions
*/
public static void writeExpressions(StringBuilder builder, Expression[] expressions) { public static void writeExpressions(StringBuilder builder, Expression[] expressions) {
for (int i = 0, length = expressions.length; i < length; i++) { for (int i = 0, length = expressions.length; i < length; i++) {
if (i > 0) { if (i > 0) {
......
...@@ -271,6 +271,12 @@ public class ExpressionVisitor { ...@@ -271,6 +271,12 @@ public class ExpressionVisitor {
columns1.add(column); columns1.add(column);
} }
/**
* Add a new column to the set of columns.
* This is used for GET_COLUMNS2 visitors.
*
* @param column the additional column.
*/
void addColumn2(Column column) { void addColumn2(Column column) {
if (table == null || table == column.getTable()) { if (table == null || table == column.getTable()) {
columns2.add(column); columns2.add(column);
...@@ -367,6 +373,7 @@ public class ExpressionVisitor { ...@@ -367,6 +373,7 @@ public class ExpressionVisitor {
* Get the set of columns of all tables. * Get the set of columns of all tables.
* *
* @param filters the filters * @param filters the filters
* @param allColumnsSet the on-demand all-columns set
*/ */
public static void allColumnsForTableFilters(TableFilter[] filters, AllColumnsForPlan allColumnsSet) { public static void allColumnsForTableFilters(TableFilter[] filters, AllColumnsForPlan allColumnsSet) {
for (TableFilter filter : filters) { for (TableFilter filter : filters) {
......
...@@ -25,8 +25,14 @@ import org.h2.value.Value; ...@@ -25,8 +25,14 @@ import org.h2.value.Value;
*/ */
public abstract class AbstractAggregate extends DataAnalysisOperation { public abstract class AbstractAggregate extends DataAnalysisOperation {
/**
* is this a DISTINCT aggregate
*/
protected final boolean distinct; protected final boolean distinct;
/**
* FILTER condition for aggregate/window
*/
protected Expression filterCondition; protected Expression filterCondition;
AbstractAggregate(Select select, boolean distinct) { AbstractAggregate(Select select, boolean distinct) {
......
...@@ -44,14 +44,31 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -44,14 +44,31 @@ public abstract class DataAnalysisOperation extends Expression {
*/ */
public static final int STAGE_WINDOW = 2; public static final int STAGE_WINDOW = 2;
/**
* SELECT
*/
protected final Select select; protected final Select select;
/**
* Window clause / OVER
*/
protected Window over; protected Window over;
/**
* Sort order for OVER
*/
protected SortOrder overOrderBySort; protected SortOrder overOrderBySort;
private int lastGroupRowId; private int lastGroupRowId;
/**
* Create sort order.
*
* @param session database session
* @param orderBy array of order by expressions
* @param offset index offset
* @return the SortOrder
*/
protected static SortOrder createOrder(Session session, ArrayList<SelectOrderBy> orderBy, int offset) { protected static SortOrder createOrder(Session session, ArrayList<SelectOrderBy> orderBy, int offset) {
int size = orderBy.size(); int size = orderBy.size();
int[] index = new int[size]; int[] index = new int[size];
...@@ -111,6 +128,13 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -111,6 +128,13 @@ public abstract class DataAnalysisOperation extends Expression {
mapColumnsAnalysis(resolver, level, state); mapColumnsAnalysis(resolver, level, state);
} }
/**
* Map the columns of the resolver to expression columns.
*
* @param resolver the column resolver
* @param level the subquery nesting level
* @param innerState one of the Expression MAP_IN_* values
*/
protected void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState) { protected void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState) {
if (over != null) { if (over != null) {
over.mapColumns(resolver, level); over.mapColumns(resolver, level);
...@@ -173,6 +197,13 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -173,6 +197,13 @@ public abstract class DataAnalysisOperation extends Expression {
updateAggregate(session, groupData, groupRowId); updateAggregate(session, groupData, groupRowId);
} }
/**
* Update a row of an aggregate.
*
* @param session the database session
* @param groupData data for the aggregate group
* @param groupRowId row id of group
*/
protected abstract void updateAggregate(Session session, SelectGroups groupData, int groupRowId); protected abstract void updateAggregate(Session session, SelectGroups groupData, int groupRowId);
/** /**
...@@ -207,6 +238,14 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -207,6 +238,14 @@ public abstract class DataAnalysisOperation extends Expression {
*/ */
protected abstract void rememberExpressions(Session session, Value[] array); protected abstract void rememberExpressions(Session session, Value[] array);
/**
* Get the aggregate data for a window clause.
*
* @param session database session
* @param groupData aggregate group data
* @param forOrderBy true if this is for ORDER BY
* @return the aggregate data object, specific to each kind of aggregate.
*/
protected Object getWindowData(Session session, SelectGroups groupData, boolean forOrderBy) { protected Object getWindowData(Session session, SelectGroups groupData, boolean forOrderBy) {
Object data; Object data;
Value key = over.getCurrentKey(session); Value key = over.getCurrentKey(session);
...@@ -220,6 +259,13 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -220,6 +259,13 @@ public abstract class DataAnalysisOperation extends Expression {
return data; return data;
} }
/**
* Get the aggregate group data object from the collector object.
* @param groupData the collector object
* @param ifExists if true, return null if object not found,
* if false, return new object if nothing found
* @return group data object
*/
protected Object getGroupData(SelectGroups groupData, boolean ifExists) { protected Object getGroupData(SelectGroups groupData, boolean ifExists) {
Object data; Object data;
data = groupData.getCurrentGroupExprData(this); data = groupData.getCurrentGroupExprData(this);
...@@ -233,6 +279,11 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -233,6 +279,11 @@ public abstract class DataAnalysisOperation extends Expression {
return data; return data;
} }
/**
* Create aggregate data object specific to the subclass.
*
* @return aggregate-specific data object.
*/
protected abstract Object createAggregateData(); protected abstract Object createAggregateData();
@Override @Override
...@@ -316,6 +367,14 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -316,6 +367,14 @@ public abstract class DataAnalysisOperation extends Expression {
*/ */
protected abstract Value getAggregatedValue(Session session, Object aggregateData); protected abstract Value getAggregatedValue(Session session, Object aggregateData);
/**
* Update a row of an ordered aggregate.
*
* @param session the database session
* @param groupData data for the aggregate group
* @param groupRowId row id of group
* @param orderBy list of order by expressions
*/
protected void updateOrderedAggregate(Session session, SelectGroups groupData, int groupRowId, protected void updateOrderedAggregate(Session session, SelectGroups groupData, int groupRowId,
ArrayList<SelectOrderBy> orderBy) { ArrayList<SelectOrderBy> orderBy) {
int ne = getNumExpressions(); int ne = getNumExpressions();
...@@ -352,6 +411,8 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -352,6 +411,8 @@ public abstract class DataAnalysisOperation extends Expression {
} }
/** /**
* Returns result of this window function or window aggregate.
*
* @param session * @param session
* the session * the session
* @param result * @param result
...@@ -364,6 +425,12 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -364,6 +425,12 @@ public abstract class DataAnalysisOperation extends Expression {
protected abstract void getOrderedResultLoop(Session session, HashMap<Integer, Value> result, protected abstract void getOrderedResultLoop(Session session, HashMap<Integer, Value> result,
ArrayList<Value[]> ordered, int rowIdColumn); ArrayList<Value[]> ordered, int rowIdColumn);
/**
* Used to create SQL for the OVER part of the command.
*
* @param builder string builder
* @return the builder object
*/
protected StringBuilder appendTailConditions(StringBuilder builder) { protected StringBuilder appendTailConditions(StringBuilder builder) {
if (over != null) { if (over != null) {
builder.append(' '); builder.append(' ');
......
...@@ -1167,6 +1167,13 @@ public class Function extends Expression implements FunctionCall { ...@@ -1167,6 +1167,13 @@ public class Function extends Expression implements FunctionCall {
return v; return v;
} }
/**
* Return the resulting value for the given expression arguments.
*
* @param session the session
* @param args argument expressions
* @return the result
*/
protected Value getValueWithArgs(Session session, Expression[] args) { protected Value getValueWithArgs(Session session, Expression[] args) {
Value[] values = new Value[args.length]; Value[] values = new Value[args.length];
if (info.nullIfParameterIsNull) { if (info.nullIfParameterIsNull) {
......
...@@ -493,6 +493,9 @@ public class CacheLongKeyLIRS<V> { ...@@ -493,6 +493,9 @@ public class CacheLongKeyLIRS<V> {
} }
} }
/**
* Loop through segments, trimming the non resident queue.
*/
public void trimNonResidentQueue() { public void trimNonResidentQueue() {
for (Segment<V> s : segments) { for (Segment<V> s : segments) {
synchronized (s) { synchronized (s) {
......
...@@ -209,6 +209,12 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -209,6 +209,12 @@ public class MVPrimaryIndex extends BaseIndex {
} }
} }
/**
* Lock a set of rows.
*
* @param session database session
* @param rowsForUpdate rows to lock
*/
void lockRows(Session session, Iterable<Row> rowsForUpdate) { void lockRows(Session session, Iterable<Row> rowsForUpdate) {
TransactionMap<Value, Value> map = getMap(session); TransactionMap<Value, Value> map = getMap(session);
for (Row row : rowsForUpdate) { for (Row row : rowsForUpdate) {
...@@ -217,6 +223,13 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -217,6 +223,13 @@ public class MVPrimaryIndex extends BaseIndex {
} }
} }
/**
* Lock a single row.
*
* @param session database session
* @param row to lock
* @return row object if it exists
*/
Row lockRow(Session session, Row row) { Row lockRow(Session session, Row row) {
TransactionMap<Value, Value> map = getMap(session); TransactionMap<Value, Value> map = getMap(session);
long key = row.getKey(); long key = row.getKey();
...@@ -273,7 +286,7 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -273,7 +286,7 @@ public class MVPrimaryIndex extends BaseIndex {
return getRow(session, key, (ValueArray) v); return getRow(session, key, (ValueArray) v);
} }
public Row getRow(Session session, long key, ValueArray array) { private Row getRow(Session session, long key, ValueArray array) {
Row row = session.createRow(array.getList(), 0); Row row = session.createRow(array.getList(), 0);
row.setKey(key); row.setKey(key);
return row; return row;
......
...@@ -97,6 +97,12 @@ public class MVTableEngine implements TableEngine { ...@@ -97,6 +97,12 @@ public class MVTableEngine implements TableEngine {
return store; return store;
} }
/**
* Convert password from byte[] to char[].
*
* @param key password as byte[]
* @return password as char[].
*/
static char[] decodePassword(byte[] key) { static char[] decodePassword(byte[] key) {
char[] password = new char[key.length / 2]; char[] password = new char[key.length / 2];
for (int i = 0; i < password.length; i++) { for (int i = 0; i < password.length; i++) {
...@@ -210,6 +216,12 @@ public class MVTableEngine implements TableEngine { ...@@ -210,6 +216,12 @@ public class MVTableEngine implements TableEngine {
return transactionStore; return transactionStore;
} }
/**
* Get MVTable by table name.
*
* @param tableName table name
* @return MVTable
*/
public MVTable getTable(String tableName) { public MVTable getTable(String tableName) {
return tableMap.get(tableName); return tableMap.get(tableName);
} }
......
...@@ -179,7 +179,7 @@ public class TransactionStore { ...@@ -179,7 +179,7 @@ public class TransactionStore {
assert committed || getTransactionId(lastUndoKey) == transactionId; assert committed || getTransactionId(lastUndoKey) == transactionId;
long logId = lastUndoKey == null ? 0 : getLogId(lastUndoKey) + 1; long logId = lastUndoKey == null ? 0 : getLogId(lastUndoKey) + 1;
registerTransaction(transactionId, status, name, logId, timeoutMillis, 0, registerTransaction(transactionId, status, name, logId, timeoutMillis, 0,
RollbackListener.NONE); ROLLBACK_LISTENER_NONE);
continue; continue;
} }
} }
...@@ -307,7 +307,7 @@ public class TransactionStore { ...@@ -307,7 +307,7 @@ public class TransactionStore {
* @return the transaction * @return the transaction
*/ */
public Transaction begin() { public Transaction begin() {
return begin(RollbackListener.NONE, timeoutMillis, 0); return begin(ROLLBACK_LISTENER_NONE, timeoutMillis, 0);
} }
/** /**
...@@ -387,6 +387,7 @@ public class TransactionStore { ...@@ -387,6 +387,7 @@ public class TransactionStore {
* @param transactionId id of the transaction * @param transactionId id of the transaction
* @param logId sequential number of the log record within transaction * @param logId sequential number of the log record within transaction
* @param undoLogRecord Object[mapId, key, previousValue] * @param undoLogRecord Object[mapId, key, previousValue]
* @return undo key
*/ */
long addUndoLogRecord(int transactionId, long logId, Object[] undoLogRecord) { long addUndoLogRecord(int transactionId, long logId, Object[] undoLogRecord) {
MVMap<Long, Object[]> undoLog = undoLogs[transactionId]; MVMap<Long, Object[]> undoLog = undoLogs[transactionId];
...@@ -582,6 +583,12 @@ public class TransactionStore { ...@@ -582,6 +583,12 @@ public class TransactionStore {
return true; return true;
} }
/**
* Get Transaction object for a transaction id.
*
* @param transactionId id for an open transaction
* @return Transaction object.
*/
Transaction getTransaction(int transactionId) { Transaction getTransaction(int transactionId) {
return transactions.get(transactionId); return transactions.get(transactionId);
} }
...@@ -711,14 +718,6 @@ public class TransactionStore { ...@@ -711,14 +718,6 @@ public class TransactionStore {
*/ */
public interface RollbackListener { public interface RollbackListener {
RollbackListener NONE = new RollbackListener() {
@Override
public void onRollback(MVMap<Object, VersionedValue> map, Object key,
VersionedValue existingValue, VersionedValue restoredValue) {
// do nothing
}
};
/** /**
* Notified of a single map change (add/update/remove) * Notified of a single map change (add/update/remove)
* @param map modified * @param map modified
...@@ -730,6 +729,14 @@ public class TransactionStore { ...@@ -730,6 +729,14 @@ public class TransactionStore {
VersionedValue existingValue, VersionedValue restoredValue); VersionedValue existingValue, VersionedValue restoredValue);
} }
private static RollbackListener ROLLBACK_LISTENER_NONE = new RollbackListener() {
@Override
public void onRollback(MVMap<Object, VersionedValue> map, Object key,
VersionedValue existingValue, VersionedValue restoredValue) {
// do nothing
}
};
/** /**
* A data type that contains an array of objects with the specified data * A data type that contains an array of objects with the specified data
* types. * types.
......
...@@ -22,6 +22,11 @@ class VersionedValueCommitted extends VersionedValue { ...@@ -22,6 +22,11 @@ class VersionedValueCommitted extends VersionedValue {
this.value = value; this.value = value;
} }
/**
* Either cast to VersionedValue, or wrap in VersionedValueCommitted
* @param value the object to cast/wrap
* @return VersionedValue instance
*/
static VersionedValue getInstance(Object value) { static VersionedValue getInstance(Object value) {
assert value != null; assert value != null;
return value instanceof VersionedValue ? (VersionedValue) value : new VersionedValueCommitted(value); return value instanceof VersionedValue ? (VersionedValue) value : new VersionedValueCommitted(value);
......
...@@ -23,6 +23,14 @@ class VersionedValueUncommitted extends VersionedValueCommitted { ...@@ -23,6 +23,14 @@ class VersionedValueUncommitted extends VersionedValueCommitted {
this.committedValue = committedValue; this.committedValue = committedValue;
} }
/**
* Create new VersionedValueUncommitted.
*
* @param operationId combined log/transaction id
* @param value value before commit
* @param committedValue value after commit
* @return VersionedValue instance
*/
static VersionedValue getInstance(long operationId, Object value, Object committedValue) { static VersionedValue getInstance(long operationId, Object value, Object committedValue) {
return new VersionedValueUncommitted(operationId, value, committedValue); return new VersionedValueUncommitted(operationId, value, committedValue);
} }
......
...@@ -328,7 +328,8 @@ public class IntervalUtils { ...@@ -328,7 +328,8 @@ public class IntervalUtils {
return ValueInterval.from(qualifier, negative, leading, remaining); return ValueInterval.from(qualifier, negative, leading, remaining);
} }
private static ValueInterval parseInterval2(IntervalQualifier qualifier, String s, char ch, int max, boolean negative) { private static ValueInterval parseInterval2(IntervalQualifier qualifier, String s,
char ch, int max, boolean negative) {
long leading; long leading;
long remaining; long remaining;
int dash = s.indexOf(ch, 1); int dash = s.indexOf(ch, 1);
......
...@@ -13,6 +13,9 @@ package org.h2.value; ...@@ -13,6 +13,9 @@ package org.h2.value;
*/ */
public class VersionedValue { public class VersionedValue {
/**
* Used when we don't care about a VersionedValue instance.
*/
public static final VersionedValue DUMMY = new VersionedValue(); public static final VersionedValue DUMMY = new VersionedValue();
protected VersionedValue() {} protected VersionedValue() {}
......
...@@ -805,4 +805,4 @@ queryparser tokenized freeze factorings recompilation unenclosed rfe dsync ...@@ -805,4 +805,4 @@ queryparser tokenized freeze factorings recompilation unenclosed rfe dsync
econd irst bcef ordinality nord unnest econd irst bcef ordinality nord unnest
analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin doctor businessman artist ashan analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin doctor businessman artist ashan
corrupts splitted disruption unintentional octets preconditions predicates subq objectweb insn opcodes corrupts splitted disruption unintentional octets preconditions predicates subq objectweb insn opcodes
preserves masking holder unboxing avert iae preserves masking holder unboxing avert iae transformed
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论