Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
764c9495
提交
764c9495
authored
1月 06, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Formatting, javadocs, improve testability
上级
8f38fa77
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
138 行增加
和
72 行删除
+138
-72
JdbcArray.java
h2/src/main/org/h2/jdbc/JdbcArray.java
+6
-12
JdbcConnection.java
h2/src/main/org/h2/jdbc/JdbcConnection.java
+7
-1
JdbcDataSource.java
h2/src/main/org/h2/jdbcx/JdbcDataSource.java
+3
-5
Cursor.java
h2/src/main/org/h2/mvstore/Cursor.java
+2
-2
DataUtils.java
h2/src/main/org/h2/mvstore/DataUtils.java
+4
-4
FileStore.java
h2/src/main/org/h2/mvstore/FileStore.java
+1
-1
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+2
-2
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+1
-1
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+11
-0
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+87
-31
ResultTempTable.java
h2/src/main/org/h2/result/ResultTempTable.java
+1
-1
LobStorageBackend.java
h2/src/main/org/h2/store/LobStorageBackend.java
+8
-8
FunctionTable.java
h2/src/main/org/h2/table/FunctionTable.java
+4
-3
TableView.java
h2/src/main/org/h2/table/TableView.java
+1
-1
没有找到文件。
h2/src/main/org/h2/jdbc/JdbcArray.java
浏览文件 @
764c9495
...
...
@@ -62,7 +62,7 @@ public class JdbcArray extends TraceObject implements Array {
public
Object
getArray
(
Map
<
String
,
Class
<?>>
map
)
throws
SQLException
{
try
{
debugCode
(
"getArray("
+
quoteMap
(
map
)+
");"
);
checkMap
(
map
);
JdbcConnection
.
checkMap
(
map
);
checkClosed
();
return
get
();
}
catch
(
Exception
e
)
{
...
...
@@ -105,7 +105,7 @@ public class JdbcArray extends TraceObject implements Array {
try
{
debugCode
(
"getArray("
+
index
+
", "
+
count
+
", "
+
quoteMap
(
map
)+
");"
);
checkClosed
();
checkMap
(
map
);
JdbcConnection
.
checkMap
(
map
);
return
get
(
index
,
count
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
...
...
@@ -176,7 +176,7 @@ public class JdbcArray extends TraceObject implements Array {
try
{
debugCode
(
"getResultSet("
+
quoteMap
(
map
)+
");"
);
checkClosed
();
checkMap
(
map
);
JdbcConnection
.
checkMap
(
map
);
return
getResultSet
(
get
(),
0
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
...
...
@@ -198,7 +198,7 @@ public class JdbcArray extends TraceObject implements Array {
try
{
debugCode
(
"getResultSet("
+
index
+
", "
+
count
+
");"
);
checkClosed
();
return
getResultSet
(
get
(
index
,
count
),
index
);
return
getResultSet
(
get
(
index
,
count
),
index
-
1
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
...
...
@@ -221,8 +221,8 @@ public class JdbcArray extends TraceObject implements Array {
try
{
debugCode
(
"getResultSet("
+
index
+
", "
+
count
+
", "
+
quoteMap
(
map
)+
");"
);
checkClosed
();
checkMap
(
map
);
return
getResultSet
(
get
(
index
,
count
),
index
);
JdbcConnection
.
checkMap
(
map
);
return
getResultSet
(
get
(
index
,
count
),
index
-
1
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
...
...
@@ -274,12 +274,6 @@ public class JdbcArray extends TraceObject implements Array {
return
subset
;
}
private
static
void
checkMap
(
Map
<
String
,
Class
<?>>
map
)
{
if
(
map
!=
null
&&
map
.
size
()
>
0
)
{
throw
DbException
.
getUnsupportedException
(
"map.size > 0"
);
}
}
/**
* INTERNAL
*/
...
...
h2/src/main/org/h2/jdbc/JdbcConnection.java
浏览文件 @
764c9495
...
...
@@ -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
)
{
throw
DbException
.
getUnsupportedException
(
"map.size > 0"
);
}
...
...
h2/src/main/org/h2/jdbcx/JdbcDataSource.java
浏览文件 @
764c9495
...
...
@@ -212,13 +212,12 @@ public class JdbcDataSource extends TraceObject
debugCodeCall
(
"setURL"
,
url
);
this
.
url
=
url
;
}
/**
* Get the current URL.
* <p>
* This method does the same as getURL, but this methods signature conforms
* the JavaBean naming convention.
*
*
* @return the URL
*/
public
String
getUrl
()
{
...
...
@@ -228,10 +227,9 @@ public class JdbcDataSource extends TraceObject
/**
* Set the current URL.
* <p>
* This method does the same as setURL, but this methods signature conforms
* the JavaBean naming convention.
*
*
* @param url the new URL
*/
public
void
setUrl
(
String
url
)
{
...
...
h2/src/main/org/h2/mvstore/Cursor.java
浏览文件 @
764c9495
...
...
@@ -48,10 +48,10 @@ public class Cursor<K, V> implements Iterator<K> {
fetchNext
();
return
c
;
}
/**
* Get the last read value if there was one.
*
*
* @return the value or null
*/
public
V
getValue
()
{
...
...
h2/src/main/org/h2/mvstore/DataUtils.java
浏览文件 @
764c9495
...
...
@@ -854,7 +854,7 @@ public class DataUtils {
return
errorValue
;
}
}
/**
* An entry of a map.
*
...
...
@@ -862,10 +862,10 @@ public class DataUtils {
* @param <V> the value type
*/
public
static
class
MapEntry
<
K
,
V
>
implements
Map
.
Entry
<
K
,
V
>
{
private
final
K
key
;
private
V
value
;
public
MapEntry
(
K
key
,
V
value
)
{
this
.
key
=
key
;
this
.
value
=
value
;
...
...
@@ -886,7 +886,7 @@ public class DataUtils {
throw
DataUtils
.
newUnsupportedOperationException
(
"Updating the value is not supported"
);
}
}
}
h2/src/main/org/h2/mvstore/FileStore.java
浏览文件 @
764c9495
...
...
@@ -113,7 +113,7 @@ public class FileStore {
*/
public
void
open
(
String
fileName
,
boolean
readOnly
,
char
[]
encryptionKey
)
{
if
(
fileName
!=
null
)
{
if
(
FilePath
.
get
(
fileName
)
instanceof
FilePathDisk
)
{
if
(
FilePath
.
get
(
fileName
)
instanceof
FilePathDisk
)
{
// NIO is used, unless a different file system is specified
// the following line is to ensure the NIO file system is compiled
FilePathNio
.
class
.
getName
();
...
...
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
764c9495
...
...
@@ -753,10 +753,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
public
Iterator
<
K
>
keyIterator
(
K
from
)
{
return
new
Cursor
<
K
,
V
>(
this
,
root
,
from
);
}
/**
* Get a cursor to iterate over a number of keys and values.
*
*
* @param from the first key to return
* @return the cursor
*/
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
764c9495
...
...
@@ -2166,7 +2166,7 @@ public class MVStore {
* KB for in-memory stores. This is not a limit in the page size, as
* pages with one entry can get larger. It is just the point where pages
* that contain more than one entry are split.
*
*
* @param pageSplitSize the page size
* @return this
*/
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
764c9495
...
...
@@ -39,8 +39,19 @@ import org.h2.value.ValueNull;
*/
public
class
MVPrimaryIndex
extends
BaseIndex
{
/**
* The minimum long value.
*/
static
final
ValueLong
MIN
=
ValueLong
.
get
(
Long
.
MIN_VALUE
);
/**
* The maximum long value.
*/
static
final
ValueLong
MAX
=
ValueLong
.
get
(
Long
.
MAX_VALUE
);
/**
* The zero long value.
*/
static
final
ValueLong
ZERO
=
ValueLong
.
get
(
0
);
private
final
MVTable
mvTable
;
...
...
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
764c9495
...
...
@@ -28,7 +28,7 @@ import org.h2.util.New;
* A store that supports concurrent transactions.
*/
public
class
TransactionStore
{
/**
* Whether the concurrent maps should be used.
*/
...
...
@@ -61,7 +61,7 @@ public class TransactionStore {
* The lock timeout in milliseconds. 0 means timeout immediately.
*/
long
lockTimeout
;
/**
* The map of maps.
*/
...
...
@@ -70,7 +70,7 @@ public class TransactionStore {
private
final
DataType
dataType
;
private
int
lastTransactionId
;
private
int
maxTransactionId
=
0xffff
;
/**
...
...
@@ -104,30 +104,49 @@ public class TransactionStore {
undoLog
=
store
.
openMap
(
"undoLog"
,
builder
);
init
();
}
/**
* Set the maximum transaction id, after which ids are re-used. If the old
* transaction is still in use when re-using an old id, the new transaction
* fails.
*
*
* @param max the maximum id
*/
public
void
setMaxTransactionId
(
int
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
)
{
DataUtils
.
checkArgument
(
transactionId
>=
0
&&
transactionId
<
(
1
<<
24
),
DataUtils
.
checkArgument
(
transactionId
>=
0
&&
transactionId
<
(
1
<<
24
),
"Transaction id out of range: {0}"
,
transactionId
);
DataUtils
.
checkArgument
(
logId
>=
0
&&
logId
<
(
1L
<<
40
),
DataUtils
.
checkArgument
(
logId
>=
0
&&
logId
<
(
1L
<<
40
),
"Transaction log id out of range: {0}"
,
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
)
{
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
)
{
return
operationId
&
((
1L
<<
40
)
-
1
);
}
...
...
@@ -226,8 +245,8 @@ public class TransactionStore {
if
(
logId
==
0
)
{
if
(
undoLog
.
containsKey
(
undoKey
))
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_TRANSACTION_STILL_OPEN
,
"An old transaction with the same id is still open: {0}"
,
DataUtils
.
ERROR_TRANSACTION_STILL_OPEN
,
"An old transaction with the same id is still open: {0}"
,
t
.
getId
());
}
}
...
...
@@ -247,7 +266,14 @@ public class TransactionStore {
undoLog
.
remove
(
undoKey
);
}
}
/**
* 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
)
{
maps
.
remove
(
map
.
mapId
);
store
.
removeMap
(
map
.
map
);
...
...
@@ -301,8 +327,18 @@ public class TransactionStore {
}
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
)
{
keyType
=
new
ObjectDataType
();
}
...
...
@@ -312,12 +348,12 @@ public class TransactionStore {
VersionedValueType
vt
=
new
VersionedValueType
(
valueType
);
MVMap
<
K
,
VersionedValue
>
map
;
if
(
CONCURRENT
)
{
MVMapConcurrent
.
Builder
<
K
,
VersionedValue
>
builder
=
MVMapConcurrent
.
Builder
<
K
,
VersionedValue
>
builder
=
new
MVMapConcurrent
.
Builder
<
K
,
VersionedValue
>().
keyType
(
keyType
).
valueType
(
vt
);
map
=
store
.
openMap
(
name
,
builder
);
}
else
{
MVMap
.
Builder
<
K
,
VersionedValue
>
builder
=
MVMap
.
Builder
<
K
,
VersionedValue
>
builder
=
new
MVMap
.
Builder
<
K
,
VersionedValue
>().
keyType
(
keyType
).
valueType
(
vt
);
map
=
store
.
openMap
(
name
,
builder
);
...
...
@@ -328,6 +364,12 @@ public class TransactionStore {
return
map
;
}
/**
* Open the map with the given id.
*
* @param mapId the id
* @return the map
*/
synchronized
MVMap
<
Object
,
VersionedValue
>
openMap
(
int
mapId
)
{
MVMap
<
Object
,
VersionedValue
>
map
=
maps
.
get
(
mapId
);
if
(
map
!=
null
)
{
...
...
@@ -731,7 +773,7 @@ public class TransactionStore {
public
<
K
,
V
>
void
removeMap
(
TransactionMap
<
K
,
V
>
map
)
{
store
.
removeMap
(
map
);
}
@Override
public
String
toString
()
{
return
""
+
transactionId
;
...
...
@@ -751,7 +793,7 @@ public class TransactionStore {
* The map id.
*/
final
int
mapId
;
/**
* If a record was read that was updated by this transaction, and the
* update occurred before this log id, the older version is read. This
...
...
@@ -767,7 +809,7 @@ public class TransactionStore {
* Value: { transactionId, oldVersion, value }
*/
final
MVMap
<
K
,
VersionedValue
>
map
;
private
Transaction
transaction
;
TransactionMap
(
Transaction
transaction
,
MVMap
<
K
,
VersionedValue
>
map
,
int
mapId
)
{
...
...
@@ -798,7 +840,7 @@ public class TransactionStore {
m
.
setSavepoint
(
savepoint
);
return
m
;
}
/**
* Get the size of the raw map.
*
...
...
@@ -1060,7 +1102,15 @@ public class TransactionStore {
VersionedValue
data
=
map
.
get
(
key
);
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
)
{
while
(
true
)
{
if
(
data
==
null
)
{
...
...
@@ -1085,13 +1135,13 @@ public class TransactionStore {
d
=
transaction
.
store
.
undoLog
.
get
(
id
);
}
if
(
d
==
null
)
{
// this entry was committed or rolled back
// this entry was committed or rolled back
// in the meantime (the transaction might still be open)
data
=
map
.
get
(
key
);
}
else
{
data
=
(
VersionedValue
)
d
[
2
];
}
// verify this is either committed,
// verify this is either committed,
// or the same transaction and earlier
if
(
data
!=
null
)
{
long
id2
=
data
.
operationId
;
...
...
@@ -1109,7 +1159,7 @@ public class TransactionStore {
}
}
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_TRANSACTION_CORRUPT
,
DataUtils
.
ERROR_TRANSACTION_CORRUPT
,
"The transaction log might be corrupt for key {0}"
,
key
);
}
...
...
@@ -1238,7 +1288,13 @@ public class TransactionStore {
Iterator
<
K
>
it
=
map
.
keyIterator
(
from
);
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
)
{
final
Cursor
<
K
,
VersionedValue
>
cursor
=
map
.
cursor
(
from
);
return
new
Iterator
<
Entry
<
K
,
V
>>()
{
...
...
@@ -1279,11 +1335,11 @@ public class TransactionStore {
public
void
remove
()
{
throw
DataUtils
.
newUnsupportedOperationException
(
"Removing is not supported"
);
}
}
};
}
/**
* Iterate over keys.
*
...
...
@@ -1408,12 +1464,12 @@ public class TransactionStore {
* The value.
*/
public
Object
value
;
@Override
public
String
toString
()
{
return
value
+
(
operationId
==
0
?
""
:
(
" "
+
getTransactionId
(
operationId
)
+
"/"
+
" "
+
getTransactionId
(
operationId
)
+
"/"
+
getLogId
(
operationId
)));
}
...
...
h2/src/main/org/h2/result/ResultTempTable.java
浏览文件 @
764c9495
...
...
@@ -69,7 +69,7 @@ public class ResultTempTable implements ResultExternal {
}
else
{
index
=
new
PageBtreeIndex
((
RegularTable
)
table
,
indexId
,
data
.
tableName
,
indexCols
,
indexType
,
true
,
session
);
index
.
setTemporary
(
true
);
table
.
getIndexes
().
add
(
index
);
table
.
getIndexes
().
add
(
index
);
}
parent
=
null
;
}
...
...
h2/src/main/org/h2/store/LobStorageBackend.java
浏览文件 @
764c9495
...
...
@@ -45,7 +45,7 @@ import org.h2.value.ValueLobDb;
* take a very long time. If we did them on a normal session, we would be
* locking the LOB tables for long periods of time, which is extremely
* detrimental to the rest of the system. Perhaps when we shift to the MVStore
* engine, we can revisit this design decision
* engine, we can revisit this design decision
* (using the StreamStore, that is, no connection at all).
* <p>
* Locking
...
...
@@ -783,20 +783,20 @@ public class LobStorageBackend implements LobStorageInterface {
}
}
/**
* An input stream that reads the data from a reader.
*/
public
static
class
CountingReaderInputStream
extends
InputStream
{
private
final
Reader
reader
;
private
final
CharBuffer
charBuffer
=
CharBuffer
.
allocate
(
Constants
.
IO_BUFFER_SIZE
);
private
final
CharsetEncoder
encoder
=
Constants
.
UTF8
.
newEncoder
().
onMalformedInput
(
CodingErrorAction
.
REPLACE
).
onUnmappableCharacter
(
CodingErrorAction
.
REPLACE
);
private
ByteBuffer
byteBuffer
=
ByteBuffer
.
allocate
(
0
);
private
long
length
;
private
long
remaining
;
...
...
@@ -823,7 +823,7 @@ public class LobStorageBackend implements LobStorageInterface {
}
return
byteBuffer
.
get
()
&
255
;
}
private
boolean
fetch
()
throws
IOException
{
if
(
byteBuffer
!=
null
&&
byteBuffer
.
remaining
()
==
0
)
{
fillBuffer
();
...
...
@@ -858,11 +858,11 @@ public class LobStorageBackend implements LobStorageInterface {
charBuffer
.
flip
();
charBuffer
.
position
(
charBuffer
.
limit
());
}
/**
* The number of characters read so far (but there might still be some bytes
* in the buffer).
*
*
* @return the number of characters
*/
public
long
getLength
()
{
...
...
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
764c9495
...
...
@@ -70,8 +70,8 @@ public class FunctionTable extends Table {
int
columnCount
=
meta
.
getColumnCount
();
Column
[]
cols
=
new
Column
[
columnCount
];
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
cols
[
i
]
=
new
Column
(
meta
.
getColumnName
(
i
+
1
),
DataType
.
getValueTypeFromResultSet
(
meta
,
i
+
1
),
cols
[
i
]
=
new
Column
(
meta
.
getColumnName
(
i
+
1
),
DataType
.
getValueTypeFromResultSet
(
meta
,
i
+
1
),
meta
.
getPrecision
(
i
+
1
),
meta
.
getScale
(
i
+
1
),
meta
.
getColumnDisplaySize
(
i
+
1
));
}
...
...
@@ -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
* @return the result
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
764c9495
...
...
@@ -506,7 +506,7 @@ public class TableView extends Table {
public
boolean
isTableExpression
()
{
return
tableExpression
;
}
@Override
public
void
addDependencies
(
HashSet
<
DbObject
>
dependencies
)
{
super
.
addDependencies
(
dependencies
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论