提交 764c9495 authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting, javadocs, improve testability

上级 8f38fa77
...@@ -62,7 +62,7 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -62,7 +62,7 @@ public class JdbcArray extends TraceObject implements Array {
public Object getArray(Map<String, Class<?>> map) throws SQLException { public Object getArray(Map<String, Class<?>> map) throws SQLException {
try { try {
debugCode("getArray("+quoteMap(map)+");"); debugCode("getArray("+quoteMap(map)+");");
checkMap(map); JdbcConnection.checkMap(map);
checkClosed(); checkClosed();
return get(); return get();
} catch (Exception e) { } catch (Exception e) {
...@@ -105,7 +105,7 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -105,7 +105,7 @@ public class JdbcArray extends TraceObject implements Array {
try { try {
debugCode("getArray(" + index + ", " + count + ", " + quoteMap(map)+");"); debugCode("getArray(" + index + ", " + count + ", " + quoteMap(map)+");");
checkClosed(); checkClosed();
checkMap(map); JdbcConnection.checkMap(map);
return get(index, count); return get(index, count);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -176,7 +176,7 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -176,7 +176,7 @@ public class JdbcArray extends TraceObject implements Array {
try { try {
debugCode("getResultSet("+quoteMap(map)+");"); debugCode("getResultSet("+quoteMap(map)+");");
checkClosed(); checkClosed();
checkMap(map); JdbcConnection.checkMap(map);
return getResultSet(get(), 0); return getResultSet(get(), 0);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -198,7 +198,7 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -198,7 +198,7 @@ public class JdbcArray extends TraceObject implements Array {
try { try {
debugCode("getResultSet("+index+", " + count+");"); debugCode("getResultSet("+index+", " + count+");");
checkClosed(); checkClosed();
return getResultSet(get(index, count), index); return getResultSet(get(index, count), index - 1);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -221,8 +221,8 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -221,8 +221,8 @@ public class JdbcArray extends TraceObject implements Array {
try { try {
debugCode("getResultSet("+index+", " + count+", " + quoteMap(map)+");"); debugCode("getResultSet("+index+", " + count+", " + quoteMap(map)+");");
checkClosed(); checkClosed();
checkMap(map); JdbcConnection.checkMap(map);
return getResultSet(get(index, count), index); return getResultSet(get(index, count), index - 1);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -274,12 +274,6 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -274,12 +274,6 @@ public class JdbcArray extends TraceObject implements Array {
return subset; return subset;
} }
private static void checkMap(Map<String, Class<?>> map) {
if (map != null && map.size() > 0) {
throw DbException.getUnsupportedException("map.size > 0");
}
}
/** /**
* INTERNAL * INTERNAL
*/ */
......
...@@ -1807,7 +1807,13 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -1807,7 +1807,13 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
//*/ //*/
private static void checkMap(Map<String, Class<?>> map) { /**
* Check that the given type map is either null or empty.
*
* @param map the type map
* @throws DbException if the map is not empty
*/
static void checkMap(Map<String, Class<?>> map) {
if (map != null && map.size() > 0) { if (map != null && map.size() > 0) {
throw DbException.getUnsupportedException("map.size > 0"); throw DbException.getUnsupportedException("map.size > 0");
} }
......
...@@ -215,7 +215,6 @@ public class JdbcDataSource extends TraceObject ...@@ -215,7 +215,6 @@ public class JdbcDataSource extends TraceObject
/** /**
* Get the current URL. * Get the current URL.
* <p>
* This method does the same as getURL, but this methods signature conforms * This method does the same as getURL, but this methods signature conforms
* the JavaBean naming convention. * the JavaBean naming convention.
* *
...@@ -228,7 +227,6 @@ public class JdbcDataSource extends TraceObject ...@@ -228,7 +227,6 @@ public class JdbcDataSource extends TraceObject
/** /**
* Set the current URL. * Set the current URL.
* <p>
* This method does the same as setURL, but this methods signature conforms * This method does the same as setURL, but this methods signature conforms
* the JavaBean naming convention. * the JavaBean naming convention.
* *
......
...@@ -39,8 +39,19 @@ import org.h2.value.ValueNull; ...@@ -39,8 +39,19 @@ import org.h2.value.ValueNull;
*/ */
public class MVPrimaryIndex extends BaseIndex { public class MVPrimaryIndex extends BaseIndex {
/**
* The minimum long value.
*/
static final ValueLong MIN = ValueLong.get(Long.MIN_VALUE); static final ValueLong MIN = ValueLong.get(Long.MIN_VALUE);
/**
* The maximum long value.
*/
static final ValueLong MAX = ValueLong.get(Long.MAX_VALUE); static final ValueLong MAX = ValueLong.get(Long.MAX_VALUE);
/**
* The zero long value.
*/
static final ValueLong ZERO = ValueLong.get(0); static final ValueLong ZERO = ValueLong.get(0);
private final MVTable mvTable; private final MVTable mvTable;
......
...@@ -116,6 +116,13 @@ public class TransactionStore { ...@@ -116,6 +116,13 @@ public class TransactionStore {
this.maxTransactionId = max; this.maxTransactionId = max;
} }
/**
* Combine the transaction id and the log id to an operation id.
*
* @param transactionId the transaction id
* @param logId the log id
* @return the operation id
*/
static long getOperationId(int transactionId, long logId) { static long getOperationId(int transactionId, long logId) {
DataUtils.checkArgument(transactionId >= 0 && transactionId < (1 << 24), DataUtils.checkArgument(transactionId >= 0 && transactionId < (1 << 24),
"Transaction id out of range: {0}", transactionId); "Transaction id out of range: {0}", transactionId);
...@@ -124,10 +131,22 @@ public class TransactionStore { ...@@ -124,10 +131,22 @@ public class TransactionStore {
return ((long) transactionId << 40) | logId; return ((long) transactionId << 40) | logId;
} }
/**
* Get the transaction id for the given operation id.
*
* @param operationId the operation id
* @return the transaction id
*/
static int getTransactionId(long operationId) { static int getTransactionId(long operationId) {
return (int) (operationId >>> 40); return (int) (operationId >>> 40);
} }
/**
* Get the log id for the given operation id.
*
* @param operationId the operation id
* @return the log id
*/
static long getLogId(long operationId) { static long getLogId(long operationId) {
return operationId & ((1L << 40) - 1); return operationId & ((1L << 40) - 1);
} }
...@@ -248,6 +267,13 @@ public class TransactionStore { ...@@ -248,6 +267,13 @@ public class TransactionStore {
} }
} }
/**
* Remove the given map.
*
* @param <K> the key type
* @param <V> the value type
* @param map the map
*/
synchronized <K, V> void removeMap(TransactionMap<K, V> map) { synchronized <K, V> void removeMap(TransactionMap<K, V> map) {
maps.remove(map.mapId); maps.remove(map.mapId);
store.removeMap(map.map); store.removeMap(map.map);
...@@ -302,7 +328,17 @@ public class TransactionStore { ...@@ -302,7 +328,17 @@ public class TransactionStore {
endTransaction(t); endTransaction(t);
} }
synchronized <K> MVMap<K, VersionedValue> openMap(String name, DataType keyType, DataType valueType) { /**
* Open the map with the given name.
*
* @param <K> the key type
* @param name the map name
* @param keyType the key type
* @param valueType the value type
* @return the map
*/
synchronized <K> MVMap<K, VersionedValue> openMap(String name,
DataType keyType, DataType valueType) {
if (keyType == null) { if (keyType == null) {
keyType = new ObjectDataType(); keyType = new ObjectDataType();
} }
...@@ -328,6 +364,12 @@ public class TransactionStore { ...@@ -328,6 +364,12 @@ public class TransactionStore {
return map; return map;
} }
/**
* Open the map with the given id.
*
* @param mapId the id
* @return the map
*/
synchronized MVMap<Object, VersionedValue> openMap(int mapId) { synchronized MVMap<Object, VersionedValue> openMap(int mapId) {
MVMap<Object, VersionedValue> map = maps.get(mapId); MVMap<Object, VersionedValue> map = maps.get(mapId);
if (map != null) { if (map != null) {
...@@ -1061,6 +1103,14 @@ public class TransactionStore { ...@@ -1061,6 +1103,14 @@ public class TransactionStore {
return getValue(key, maxLog, data); return getValue(key, maxLog, data);
} }
/**
* Get the versioned value for the given key.
*
* @param key the key
* @param maxLog the maximum log id of the entry
* @param data the value stored in the main map
* @return the value
*/
VersionedValue getValue(K key, long maxLog, VersionedValue data) { VersionedValue getValue(K key, long maxLog, VersionedValue data) {
while (true) { while (true) {
if (data == null) { if (data == null) {
...@@ -1239,6 +1289,12 @@ public class TransactionStore { ...@@ -1239,6 +1289,12 @@ public class TransactionStore {
return wrapIterator(it, includeUncommitted); return wrapIterator(it, includeUncommitted);
} }
/**
* Iterate over entries.
*
* @param from the first key to return
* @return the iterator
*/
public Iterator<Entry<K, V>> entryIterator(K from) { public Iterator<Entry<K, V>> entryIterator(K from) {
final Cursor<K, VersionedValue> cursor = map.cursor(from); final Cursor<K, VersionedValue> cursor = map.cursor(from);
return new Iterator<Entry<K, V>>() { return new Iterator<Entry<K, V>>() {
......
...@@ -173,7 +173,8 @@ public class FunctionTable extends Table { ...@@ -173,7 +173,8 @@ public class FunctionTable extends Table {
} }
/** /**
* Read the result from the function. This method buffers the result in a temporary file. * Read the result from the function. This method buffers the result in a
* temporary file.
* *
* @param session the session * @param session the session
* @return the result * @return the result
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论