Unverified 提交 78155dab authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1643 from grandinj/javadoc4

more javadoc update
...@@ -114,6 +114,10 @@ public class Select extends Query { ...@@ -114,6 +114,10 @@ public class Select extends Query {
private int[] groupByCopies; private int[] groupByCopies;
/**
* This flag is set when SELECT statement contains (non-window) aggregate
* functions, GROUP BY clause or HAVING clause.
*/
boolean isGroupQuery; boolean isGroupQuery;
private boolean isGroupSortedQuery; private boolean isGroupSortedQuery;
private boolean isWindowQuery; private boolean isWindowQuery;
...@@ -173,7 +177,8 @@ public class Select extends Query { ...@@ -173,7 +177,8 @@ public class Select extends Query {
} }
/** /**
* Called if this query contains aggregate functions. * Set when SELECT statement contains (non-window) aggregate functions,
* GROUP BY clause or HAVING clause.
*/ */
public void setGroupQuery() { public void setGroupQuery() {
isGroupQuery = true; isGroupQuery = true;
...@@ -194,6 +199,12 @@ public class Select extends Query { ...@@ -194,6 +199,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;
} }
...@@ -208,7 +219,7 @@ public class Select extends Query { ...@@ -208,7 +219,7 @@ public class Select extends Query {
/** /**
* Set the DISTINCT ON expressions. * Set the DISTINCT ON expressions.
* *
* @param distinctExpressions array of expressions * @param distinctExpressions array of expressions
*/ */
public void setDistinct(Expression[] distinctExpressions) { public void setDistinct(Expression[] distinctExpressions) {
...@@ -471,6 +482,12 @@ public class Select extends Query { ...@@ -471,6 +482,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 see STAGE_RESET/STAGE_GROUP/STAGE_WINDOW in DataAnalysisOperation
*/
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
*/
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;
/**
* OVER clause
*/
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 and FILTER clauses.
*
* @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(' ');
......
...@@ -1144,7 +1144,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -1144,7 +1144,7 @@ public class Function extends Expression implements FunctionCall {
/** /**
* Get value transformed by expression, or null if i is out of range or * Get value transformed by expression, or null if i is out of range or
* the input value is null. * the input value is null.
* *
* @param session database session * @param session database session
* @param args expressions * @param args expressions
* @param values array of input values * @param values array of input values
...@@ -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) {
......
...@@ -109,6 +109,11 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -109,6 +109,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
this.singleWriter = singleWriter; this.singleWriter = singleWriter;
} }
/**
* Clone the current map.
*
* @return clone of this.
*/
protected MVMap<K, V> cloneIt() { protected MVMap<K, V> cloneIt() {
return new MVMap<>(this); return new MVMap<>(this);
} }
...@@ -786,6 +791,11 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -786,6 +791,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return root.get(); return root.get();
} }
/**
* Get the root reference, flushing any current append buffer.
*
* @return current root reference
*/
public RootReference flushAndGetRoot() { public RootReference flushAndGetRoot() {
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
if (singleWriter && rootReference.getAppendCounter() > 0) { if (singleWriter && rootReference.getAppendCounter() > 0) {
...@@ -799,6 +809,12 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -799,6 +809,12 @@ public class MVMap<K, V> extends AbstractMap<K, V>
while (setNewRoot(null, rootPage, ++attempt, false) == null) {/**/} while (setNewRoot(null, rootPage, ++attempt, false) == null) {/**/}
} }
/**
* Set the initial root.
*
* @param rootPage root page
* @param version initial version
*/
final void setInitialRoot(Page rootPage, long version) { final void setInitialRoot(Page rootPage, long version) {
root.set(new RootReference(rootPage, version)); root.set(new RootReference(rootPage, version));
} }
...@@ -860,6 +876,11 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -860,6 +876,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
} }
/**
* Roll the root back to the specified version.
*
* @param version to rollback to
*/
void rollbackRoot(long version) void rollbackRoot(long version)
{ {
RootReference rootReference = flushAndGetRoot(); RootReference rootReference = flushAndGetRoot();
...@@ -1071,6 +1092,12 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1071,6 +1092,12 @@ public class MVMap<K, V> extends AbstractMap<K, V>
rootReference.version : previous.version; rootReference.version : previous.version;
} }
/**
* Does the root have changes since the specified version?
*
* @param version root version
* @return true if has changes
*/
final boolean hasChangesSince(long version) { final boolean hasChangesSince(long version) {
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
Page root = rootReference.root; Page root = rootReference.root;
...@@ -1144,10 +1171,20 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1144,10 +1171,20 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
} }
/**
* Create empty leaf node page.
*
* @return new page
*/
public Page createEmptyLeaf() { public Page createEmptyLeaf() {
return Page.createEmptyLeaf(this); return Page.createEmptyLeaf(this);
} }
/**
* Create empty internal node page.
*
* @return new page
*/
protected Page createEmptyNode() { protected Page createEmptyNode() {
return Page.createEmptyNode(this); return Page.createEmptyNode(this);
} }
...@@ -1601,6 +1638,11 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1601,6 +1638,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return create(config); return create(config);
} }
/**
* Create map from config.
* @param config config map
* @return new map
*/
protected abstract M create(Map<String, Object> config); protected abstract M create(Map<String, Object> config);
} }
...@@ -1665,6 +1707,9 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1665,6 +1707,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/ */
public abstract static class DecisionMaker<V> public abstract static class DecisionMaker<V>
{ {
/**
* Decision maker for transaction rollback.
*/
public static final DecisionMaker<Object> DEFAULT = new DecisionMaker<Object>() { public static final DecisionMaker<Object> DEFAULT = new DecisionMaker<Object>() {
@Override @Override
public Decision decide(Object existingValue, Object providedValue) { public Decision decide(Object existingValue, Object providedValue) {
...@@ -1677,6 +1722,9 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1677,6 +1722,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
}; };
/**
* Decision maker for put().
*/
public static final DecisionMaker<Object> PUT = new DecisionMaker<Object>() { public static final DecisionMaker<Object> PUT = new DecisionMaker<Object>() {
@Override @Override
public Decision decide(Object existingValue, Object providedValue) { public Decision decide(Object existingValue, Object providedValue) {
...@@ -1689,6 +1737,9 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1689,6 +1737,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
}; };
/**
* Decision maker for remove().
*/
public static final DecisionMaker<Object> REMOVE = new DecisionMaker<Object>() { public static final DecisionMaker<Object> REMOVE = new DecisionMaker<Object>() {
@Override @Override
public Decision decide(Object existingValue, Object providedValue) { public Decision decide(Object existingValue, Object providedValue) {
...@@ -1701,6 +1752,9 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1701,6 +1752,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
}; };
/**
* Decision maker for putIfAbsent() key/value.
*/
static final DecisionMaker<Object> IF_ABSENT = new DecisionMaker<Object>() { static final DecisionMaker<Object> IF_ABSENT = new DecisionMaker<Object>() {
@Override @Override
public Decision decide(Object existingValue, Object providedValue) { public Decision decide(Object existingValue, Object providedValue) {
...@@ -1713,7 +1767,10 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1713,7 +1767,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
}; };
static final DecisionMaker<Object> IF_PRESENT = new DecisionMaker<Object>() { /**
* Decision maker for replace().
*/
static final DecisionMaker<Object> IF_PRESENT= new DecisionMaker<Object>() {
@Override @Override
public Decision decide(Object existingValue, Object providedValue) { public Decision decide(Object existingValue, Object providedValue) {
return existingValue != null ? Decision.PUT : Decision.ABORT; return existingValue != null ? Decision.PUT : Decision.ABORT;
...@@ -1757,6 +1814,14 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1757,6 +1814,14 @@ public class MVMap<K, V> extends AbstractMap<K, V>
public void reset() {} public void reset() {}
} }
/**
* Apply an operation to a key-value pair.
*
* @param key key to operate on
* @param value new value
* @param decisionMaker command object to make choices during transaction.
* @return new value
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public V operate(K key, V value, DecisionMaker<? super V> decisionMaker) { public V operate(K key, V value, DecisionMaker<? super V> decisionMaker) {
beforeWrite(); beforeWrite();
......
...@@ -529,6 +529,14 @@ public class MVStore implements AutoCloseable { ...@@ -529,6 +529,14 @@ public class MVStore implements AutoCloseable {
} }
} }
/**
* Get map by id.
*
* @param <K> the key type
* @param <V> the value type
* @param id map id
* @return Map
*/
public <K, V> MVMap<K,V> getMap(int id) { public <K, V> MVMap<K,V> getMap(int id) {
checkOpen(); checkOpen();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -609,6 +617,12 @@ public class MVStore implements AutoCloseable { ...@@ -609,6 +617,12 @@ public class MVStore implements AutoCloseable {
return meta.containsKey("name." + name); return meta.containsKey("name." + name);
} }
/**
* Check whether a given map exists and has data.
*
* @param name the map name
* @return true if it exists and has data.
*/
public boolean hasData(String name) { public boolean hasData(String name) {
return hasMap(name) && getRootPos(meta, getMapId(name)) != 0; return hasMap(name) && getRootPos(meta, getMapId(name)) != 0;
} }
...@@ -969,6 +983,13 @@ public class MVStore implements AutoCloseable { ...@@ -969,6 +983,13 @@ public class MVStore implements AutoCloseable {
} }
} }
/**
* Read a page of data into a ByteBuffer.
*
* @param pos page pos
* @param expectedMapId expected map id for the page
* @return ByteBuffer containing page data.
*/
ByteBuffer readBufferForPage(long pos, int expectedMapId) { ByteBuffer readBufferForPage(long pos, int expectedMapId) {
Chunk c = getChunk(pos); Chunk c = getChunk(pos);
long filePos = c.block * BLOCK_SIZE; long filePos = c.block * BLOCK_SIZE;
...@@ -1493,6 +1514,13 @@ public class MVStore implements AutoCloseable { ...@@ -1493,6 +1514,13 @@ public class MVStore implements AutoCloseable {
return new HashSet<>(referencedChunks.keySet()); return new HashSet<>(referencedChunks.keySet());
} }
/**
* Visit a page on a chunk and collect ids for it and its children.
*
* @param page the page to visit
* @param executorService the service to use when doing visit in parallel
* @param executingThreadCounter number of threads currently active
*/
public void visit(Page page, ThreadPoolExecutor executorService, AtomicInteger executingThreadCounter) { public void visit(Page page, ThreadPoolExecutor executorService, AtomicInteger executingThreadCounter) {
long pos = page.getPos(); long pos = page.getPos();
if (DataUtils.isPageSaved(pos)) { if (DataUtils.isPageSaved(pos)) {
...@@ -1515,6 +1543,13 @@ public class MVStore implements AutoCloseable { ...@@ -1515,6 +1543,13 @@ public class MVStore implements AutoCloseable {
cacheCollectedChunkIds(pos, childCollector); cacheCollectedChunkIds(pos, childCollector);
} }
/**
* Visit a page on a chunk and collect ids for it and its children.
*
* @param pos position of the page to visit
* @param executorService the service to use when doing visit in parallel
* @param executingThreadCounter number of threads currently active
*/
public void visit(long pos, ThreadPoolExecutor executorService, AtomicInteger executingThreadCounter) { public void visit(long pos, ThreadPoolExecutor executorService, AtomicInteger executingThreadCounter) {
if (!DataUtils.isPageSaved(pos)) { if (!DataUtils.isPageSaved(pos)) {
return; return;
...@@ -1544,6 +1579,11 @@ public class MVStore implements AutoCloseable { ...@@ -1544,6 +1579,11 @@ public class MVStore implements AutoCloseable {
} }
} }
/**
* Add chunk to list of referenced chunks.
*
* @param chunkId chunk id
*/
void registerChunk(int chunkId) { void registerChunk(int chunkId) {
if (referencedChunks.put(chunkId, 1) == null && parent != null) { if (referencedChunks.put(chunkId, 1) == null && parent != null) {
parent.registerChunk(chunkId); parent.registerChunk(chunkId);
...@@ -2603,6 +2643,12 @@ public class MVStore implements AutoCloseable { ...@@ -2603,6 +2643,12 @@ public class MVStore implements AutoCloseable {
removeMap(map, true); removeMap(map, true);
} }
/**
* Remove a map.
*
* @param map the map to remove
* @param delayed whether to delay deleting the metadata
*/
public void removeMap(MVMap<?, ?> map, boolean delayed) { public void removeMap(MVMap<?, ?> map, boolean delayed) {
storeLock.lock(); storeLock.lock();
try { try {
...@@ -2637,6 +2683,11 @@ public class MVStore implements AutoCloseable { ...@@ -2637,6 +2683,11 @@ public class MVStore implements AutoCloseable {
} }
} }
/**
* Remove map by name.
*
* @param name the map name
*/
public void removeMap(String name) { public void removeMap(String name) {
int id = getMapId(name); int id = getMapId(name);
if(id > 0) { if(id > 0) {
......
...@@ -137,7 +137,7 @@ public abstract class Page implements Cloneable ...@@ -137,7 +137,7 @@ public abstract class Page implements Cloneable
} }
/** /**
* Create a new, empty page. * Create a new, empty leaf page.
* *
* @param map the map * @param map the map
* @return the new page * @return the new page
...@@ -146,6 +146,12 @@ public abstract class Page implements Cloneable ...@@ -146,6 +146,12 @@ public abstract class Page implements Cloneable
return createLeaf(map, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, PAGE_LEAF_MEMORY); return createLeaf(map, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, PAGE_LEAF_MEMORY);
} }
/**
* Create a new, empty internal node page.
*
* @param map the map
* @return the new page
*/
static Page createEmptyNode(MVMap<?, ?> map) { static Page createEmptyNode(MVMap<?, ?> map) {
return createNode(map, EMPTY_OBJECT_ARRAY, SINGLE_EMPTY, 0, return createNode(map, EMPTY_OBJECT_ARRAY, SINGLE_EMPTY, 0,
PAGE_NODE_MEMORY + MEMORY_POINTER + PAGE_MEMORY_CHILD); // there is always one child PAGE_NODE_MEMORY + MEMORY_POINTER + PAGE_MEMORY_CHILD); // there is always one child
...@@ -396,6 +402,11 @@ public abstract class Page implements Cloneable ...@@ -396,6 +402,11 @@ public abstract class Page implements Cloneable
return buff.toString(); return buff.toString();
} }
/**
* Dump debug data for this page.
*
* @param buff append buffer
*/
protected void dump(StringBuilder buff) { protected void dump(StringBuilder buff) {
buff.append("id: ").append(System.identityHashCode(this)).append('\n'); buff.append("id: ").append(System.identityHashCode(this)).append('\n');
buff.append("pos: ").append(Long.toHexString(pos)).append('\n'); buff.append("pos: ").append(Long.toHexString(pos)).append('\n');
...@@ -490,6 +501,13 @@ public abstract class Page implements Cloneable ...@@ -490,6 +501,13 @@ public abstract class Page implements Cloneable
*/ */
abstract Page split(int at); abstract Page split(int at);
/**
* Split the current keys array into two arrays.
*
* @param aCount size of the first array.
* @param bCount size of the second array/
* @return the second array.
*/
final Object[] splitKeys(int aCount, int bCount) { final Object[] splitKeys(int aCount, int bCount) {
assert aCount + bCount <= getKeyCount(); assert aCount + bCount <= getKeyCount();
Object[] aKeys = createKeyStorage(aCount); Object[] aKeys = createKeyStorage(aCount);
...@@ -502,6 +520,12 @@ public abstract class Page implements Cloneable ...@@ -502,6 +520,12 @@ public abstract class Page implements Cloneable
abstract void expand(int extraKeyCount, Object[] extraKeys, Object[] extraValues); abstract void expand(int extraKeyCount, Object[] extraKeys, Object[] extraValues);
/**
* Expand the keys array.
*
* @param extraKeyCount number of extra key entries to create
* @param extraKeys extra key values
*/
final void expandKeys(int extraKeyCount, Object[] extraKeys) { final void expandKeys(int extraKeyCount, Object[] extraKeys) {
int keyCount = getKeyCount(); int keyCount = getKeyCount();
Object[] newKeys = createKeyStorage(keyCount + extraKeyCount); Object[] newKeys = createKeyStorage(keyCount + extraKeyCount);
...@@ -580,6 +604,12 @@ public abstract class Page implements Cloneable ...@@ -580,6 +604,12 @@ public abstract class Page implements Cloneable
*/ */
public abstract void insertNode(int index, Object key, Page childPage); public abstract void insertNode(int index, Object key, Page childPage);
/**
* Insert a key into the key array
*
* @param index index to insert at
* @param key the key value
*/
final void insertKey(int index, Object key) { final void insertKey(int index, Object key) {
int keyCount = getKeyCount(); int keyCount = getKeyCount();
assert index <= keyCount : index + " > " + keyCount; assert index <= keyCount : index + " > " + keyCount;
...@@ -660,6 +690,11 @@ public abstract class Page implements Cloneable ...@@ -660,6 +690,11 @@ public abstract class Page implements Cloneable
recalculateMemory(); recalculateMemory();
} }
/**
* Read the page payload from the buffer.
*
* @param buff the buffer
*/
protected abstract void readPayLoad(ByteBuffer buff); protected abstract void readPayLoad(ByteBuffer buff);
public final boolean isSaved() { public final boolean isSaved() {
...@@ -748,8 +783,19 @@ public abstract class Page implements Cloneable ...@@ -748,8 +783,19 @@ public abstract class Page implements Cloneable
return typePos + 1; return typePos + 1;
} }
/**
* Write values that the buffer contains to the buff.
*
* @param buff the target buffer
*/
protected abstract void writeValues(WriteBuffer buff); protected abstract void writeValues(WriteBuffer buff);
/**
* Write page children to the buff.
*
* @param buff the target buffer
* @param withCounts true if the descendant counts should be written
*/
protected abstract void writeChildren(WriteBuffer buff, boolean withCounts); protected abstract void writeChildren(WriteBuffer buff, boolean withCounts);
/** /**
...@@ -829,6 +875,11 @@ public abstract class Page implements Cloneable ...@@ -829,6 +875,11 @@ public abstract class Page implements Cloneable
memory = calculateMemory(); memory = calculateMemory();
} }
/**
* Calculate estimated memory used in persistent case.
*
* @return memory in bytes
*/
protected int calculateMemory() { protected int calculateMemory() {
int mem = keys.length * MEMORY_POINTER; int mem = keys.length * MEMORY_POINTER;
DataType keyType = map.getKeyType(); DataType keyType = map.getKeyType();
...@@ -842,6 +893,9 @@ public abstract class Page implements Cloneable ...@@ -842,6 +893,9 @@ public abstract class Page implements Cloneable
return true; return true;
} }
/**
* Called when done with copying page.
*/
public void setComplete() {} public void setComplete() {}
/** /**
...@@ -859,13 +913,28 @@ public abstract class Page implements Cloneable ...@@ -859,13 +913,28 @@ public abstract class Page implements Cloneable
public abstract CursorPos getAppendCursorPos(CursorPos cursorPos); public abstract CursorPos getAppendCursorPos(CursorPos cursorPos);
/**
* Remove all page data recursively.
*/
public abstract void removeAllRecursive(); public abstract void removeAllRecursive();
/**
* Create array for keys storage.
*
* @param size number of entries
* @return values array
*/
private Object[] createKeyStorage(int size) private Object[] createKeyStorage(int size)
{ {
return new Object[size]; return new Object[size];
} }
/**
* Create array for values storage.
*
* @param size number of entries
* @return values array
*/
final Object[] createValueStorage(int size) final Object[] createValueStorage(int size)
{ {
return new Object[size]; return new Object[size];
...@@ -876,6 +945,9 @@ public abstract class Page implements Cloneable ...@@ -876,6 +945,9 @@ public abstract class Page implements Cloneable
*/ */
public static final class PageReference { public static final class PageReference {
/**
* Singleton object used when arrays of PageReference have not yet been filled.
*/
public static final PageReference EMPTY = new PageReference(null, 0, 0); public static final PageReference EMPTY = new PageReference(null, 0, 0);
/** /**
...@@ -928,6 +1000,9 @@ public abstract class Page implements Cloneable ...@@ -928,6 +1000,9 @@ public abstract class Page implements Cloneable
return pos; return pos;
} }
/**
* Re-acquire position from in-memory page.
*/
void resetPos() { void resetPos() {
Page p = page; Page p = page;
if (p != null && p.isSaved()) { if (p != null && p.isSaved()) {
......
...@@ -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 final 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);
......
...@@ -176,7 +176,7 @@ public class StringUtils { ...@@ -176,7 +176,7 @@ public class StringUtils {
* Convert a string to a Java literal using the correct escape sequences. * Convert a string to a Java literal using the correct escape sequences.
* The literal is not enclosed in double quotes. The result can be used in * The literal is not enclosed in double quotes. The result can be used in
* properties files or in Java source code. * properties files or in Java source code.
* *
* @param s the text to convert * @param s the text to convert
* @param buff the Java representation to return * @param buff the Java representation to return
* @param forSQL true if we embedding this inside a STRINGDECODE SQL command * @param forSQL true if we embedding this inside a STRINGDECODE SQL command
......
...@@ -54,7 +54,7 @@ public class ValueInterval extends Value { ...@@ -54,7 +54,7 @@ public class ValueInterval extends Value {
/** /**
* Create a ValueInterval instance. * Create a ValueInterval instance.
* *
* @param qualifier * @param qualifier
* qualifier * qualifier
* @param negative * @param negative
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论