Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
32bae90e
提交
32bae90e
authored
12 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A persistent multi-version map (work in progress).
上级
6ab864dc
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
616 行增加
和
406 行删除
+616
-406
RowType.java
h2/src/test/org/h2/test/store/RowType.java
+3
-3
RtreeMap.java
h2/src/test/org/h2/test/store/RtreeMap.java
+26
-0
SequenceMap.java
h2/src/test/org/h2/test/store/SequenceMap.java
+67
-0
TestBtreeMapStore.java
h2/src/test/org/h2/test/store/TestBtreeMapStore.java
+19
-5
TestMapFactory.java
h2/src/test/org/h2/test/store/TestMapFactory.java
+19
-5
BtreeMap.java
h2/src/tools/org/h2/dev/store/btree/BtreeMap.java
+303
-10
BtreeMapStore.java
h2/src/tools/org/h2/dev/store/btree/BtreeMapStore.java
+68
-49
Cursor.java
h2/src/tools/org/h2/dev/store/btree/Cursor.java
+8
-5
DataType.java
h2/src/tools/org/h2/dev/store/btree/DataType.java
+3
-2
MapFactory.java
h2/src/tools/org/h2/dev/store/btree/MapFactory.java
+46
-0
Page.java
h2/src/tools/org/h2/dev/store/btree/Page.java
+54
-327
没有找到文件。
h2/src/test/org/h2/test/store/RowType.java
浏览文件 @
32bae90e
...
...
@@ -8,7 +8,7 @@ package org.h2.test.store;
import
java.nio.ByteBuffer
;
import
org.h2.dev.store.btree.DataType
;
import
org.h2.dev.store.btree.
DataType
Factory
;
import
org.h2.dev.store.btree.
Map
Factory
;
import
org.h2.dev.store.btree.DataUtils
;
import
org.h2.util.StringUtils
;
...
...
@@ -115,7 +115,7 @@ public class RowType implements DataType {
* @param factory the data type factory
* @return the row type
*/
static
RowType
fromString
(
String
t
,
DataType
Factory
factory
)
{
static
RowType
fromString
(
String
t
,
Map
Factory
factory
)
{
if
(!
t
.
startsWith
(
"r("
)
||
!
t
.
endsWith
(
")"
))
{
throw
new
RuntimeException
(
"Unknown type: "
+
t
);
}
...
...
@@ -123,7 +123,7 @@ public class RowType implements DataType {
String
[]
array
=
StringUtils
.
arraySplit
(
t
,
','
,
false
);
DataType
[]
types
=
new
DataType
[
array
.
length
];
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
types
[
i
]
=
factory
.
fromString
(
array
[
i
]);
types
[
i
]
=
factory
.
buildDataType
(
array
[
i
]);
}
return
new
RowType
(
types
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/RtreeMap.java
0 → 100644
浏览文件 @
32bae90e
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
store
;
import
org.h2.dev.store.btree.BtreeMap
;
import
org.h2.dev.store.btree.BtreeMapStore
;
import
org.h2.dev.store.btree.DataType
;
/**
* A stored r-tree.
*
* @param <K> the key class
* @param <V> the value class
*/
public
class
RtreeMap
<
K
,
V
>
extends
BtreeMap
<
K
,
V
>
{
RtreeMap
(
BtreeMapStore
store
,
int
id
,
String
name
,
DataType
keyType
,
DataType
valueType
,
long
createVersion
)
{
super
(
store
,
id
,
name
,
keyType
,
valueType
,
createVersion
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/SequenceMap.java
0 → 100644
浏览文件 @
32bae90e
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
store
;
import
java.util.AbstractSet
;
import
java.util.Iterator
;
import
java.util.Set
;
import
org.h2.dev.store.btree.BtreeMap
;
import
org.h2.dev.store.btree.BtreeMapStore
;
import
org.h2.dev.store.btree.DataType
;
/**
* A custom map returning the values 1 .. 10.
*
* @param <K> the key type
* @param <V> the key type
*/
public
class
SequenceMap
<
K
,
V
>
extends
BtreeMap
<
K
,
V
>
{
int
min
=
1
,
max
=
10
;
SequenceMap
(
BtreeMapStore
store
,
int
id
,
String
name
,
DataType
keyType
,
DataType
valueType
,
long
createVersion
)
{
super
(
store
,
id
,
name
,
keyType
,
valueType
,
createVersion
);
setReadOnly
(
true
);
}
public
Set
<
K
>
keySet
()
{
return
new
AbstractSet
<
K
>()
{
@Override
public
Iterator
<
K
>
iterator
()
{
return
new
Iterator
<
K
>()
{
int
x
=
min
;
@Override
public
boolean
hasNext
()
{
return
x
<=
max
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
K
next
()
{
return
(
K
)
Integer
.
valueOf
(
x
++);
}
@Override
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
}
};
}
@Override
public
int
size
()
{
return
max
-
min
+
1
;
}
};
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestBtreeMapStore.java
浏览文件 @
32bae90e
...
...
@@ -29,6 +29,7 @@ public class TestBtreeMapStore extends TestBase {
}
public
void
test
()
{
testCustomMapType
();
testTruncateFile
();
testFastDelete
();
testRollbackInMemory
();
...
...
@@ -44,6 +45,20 @@ public class TestBtreeMapStore extends TestBase {
testSimple
();
}
private
void
testCustomMapType
()
{
String
fileName
=
getBaseDir
()
+
"/testMeta.h3"
;
FileUtils
.
delete
(
fileName
);
BtreeMapStore
s
;
s
=
openStore
(
fileName
);
SequenceMap
<
Integer
,
String
>
seq
=
s
.
openMap
(
"data"
,
"s"
,
"i"
,
""
).
cast
();
StringBuilder
buff
=
new
StringBuilder
();
for
(
int
x
:
seq
.
keySet
())
{
buff
.
append
(
x
).
append
(
';'
);
}
assertEquals
(
"1;2;3;4;5;6;7;8;9;10;"
,
buff
.
toString
());
s
.
close
();
}
private
void
testTruncateFile
()
{
String
fileName
=
getBaseDir
()
+
"/testMeta.h3"
;
FileUtils
.
delete
(
fileName
);
...
...
@@ -233,11 +248,11 @@ public class TestBtreeMapStore extends TestBase {
data
.
put
(
"1"
,
"Hello"
);
data
.
put
(
"2"
,
"World"
);
s
.
store
();
assertEquals
(
"1/1//"
,
m
.
get
(
"map.data"
));
assertEquals
(
"1/1//
/
"
,
m
.
get
(
"map.data"
));
assertTrue
(
m
.
containsKey
(
"chunk.1"
));
data
.
put
(
"1"
,
"Hallo"
);
s
.
store
();
assertEquals
(
"1/1//"
,
m
.
get
(
"map.data"
));
assertEquals
(
"1/1//
/
"
,
m
.
get
(
"map.data"
));
assertTrue
(
m
.
get
(
"root.1"
).
length
()
>
0
);
assertTrue
(
m
.
containsKey
(
"chunk.1"
));
assertTrue
(
m
.
containsKey
(
"chunk.2"
));
...
...
@@ -255,8 +270,7 @@ public class TestBtreeMapStore extends TestBase {
BtreeMapStore
s
=
openStore
(
fileName
);
// s.setCompressor(null);
s
.
setMaxPageSize
(
40
);
RowType
rowType
=
RowType
.
fromString
(
"r(i,,)"
,
new
TestTypeFactory
());
BtreeMap
<
Integer
,
Object
[]>
m
=
s
.
openMap
(
"data"
,
new
IntegerType
(),
rowType
);
BtreeMap
<
Integer
,
Object
[]>
m
=
s
.
openMap
(
"data"
,
""
,
"i"
,
"r(i,,)"
);
int
i
=
0
;
// long t = System.currentTimeMillis();
for
(;
i
<
len
;)
{
...
...
@@ -540,7 +554,7 @@ public class TestBtreeMapStore extends TestBase {
}
private
static
BtreeMapStore
openStore
(
String
fileName
)
{
BtreeMapStore
store
=
BtreeMapStore
.
open
(
fileName
,
new
Test
Type
Factory
());
BtreeMapStore
store
=
BtreeMapStore
.
open
(
fileName
,
new
Test
Map
Factory
());
store
.
setMaxPageSize
(
10
);
return
store
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/Test
Type
Factory.java
→
h2/src/test/org/h2/test/store/Test
Map
Factory.java
浏览文件 @
32bae90e
...
...
@@ -5,16 +5,29 @@
*/
package
org
.
h2
.
test
.
store
;
import
org.h2.dev.store.btree.BtreeMap
;
import
org.h2.dev.store.btree.BtreeMapStore
;
import
org.h2.dev.store.btree.DataType
;
import
org.h2.dev.store.btree.
DataType
Factory
;
import
org.h2.dev.store.btree.
Map
Factory
;
import
org.h2.dev.store.btree.StringType
;
/**
* A data type factory.
*/
public
class
Test
TypeFactory
implements
DataType
Factory
{
public
class
Test
MapFactory
implements
Map
Factory
{
public
DataType
fromString
(
String
s
)
{
@Override
public
<
K
,
V
>
BtreeMap
<
K
,
V
>
buildMap
(
String
mapType
,
BtreeMapStore
store
,
int
id
,
String
name
,
DataType
keyType
,
DataType
valueType
,
long
createVersion
)
{
if
(
mapType
.
equals
(
"s"
))
{
return
new
SequenceMap
<
K
,
V
>(
store
,
id
,
name
,
keyType
,
valueType
,
createVersion
);
}
throw
new
RuntimeException
(
"Unsupported map type "
+
mapType
);
}
@Override
public
DataType
buildDataType
(
String
s
)
{
if
(
s
.
length
()
==
0
)
{
return
new
StringType
();
}
...
...
@@ -27,9 +40,10 @@ public class TestTypeFactory implements DataTypeFactory {
throw
new
RuntimeException
(
"Unknown data type "
+
s
);
}
public
DataType
getDataType
(
Class
<?>
objectClass
)
{
@Override
public
String
getDataType
(
Class
<?>
objectClass
)
{
if
(
objectClass
==
Integer
.
class
)
{
return
new
IntegerType
()
;
return
"i"
;
}
throw
new
RuntimeException
(
"Unsupported object class "
+
objectClass
.
toString
());
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/store/btree/BtreeMap.java
浏览文件 @
32bae90e
差异被折叠。
点击展开。
h2/src/tools/org/h2/dev/store/btree/BtreeMapStore.java
浏览文件 @
32bae90e
差异被折叠。
点击展开。
h2/src/tools/org/h2/dev/store/btree/Cursor.java
浏览文件 @
32bae90e
...
...
@@ -13,14 +13,17 @@ import java.util.Iterator;
* A cursor to iterate over elements in ascending order.
*
* @param <K> the key type
* @param <V> the value type
*/
class
Cursor
<
K
>
implements
Iterator
<
K
>
{
class
Cursor
<
K
,
V
>
implements
Iterator
<
K
>
{
private
ArrayList
<
CursorPos
>
parents
=
new
ArrayList
<
CursorPos
>();
private
final
BtreeMap
<
K
,
V
>
map
;
private
final
ArrayList
<
CursorPos
>
parents
=
new
ArrayList
<
CursorPos
>();
private
K
current
;
Cursor
(
Page
root
,
K
from
)
{
Page
.
min
(
root
,
parents
,
from
);
Cursor
(
BtreeMap
<
K
,
V
>
map
,
Page
root
,
K
from
)
{
this
.
map
=
map
;
map
.
min
(
root
,
parents
,
from
);
fetchNext
();
}
...
...
@@ -34,7 +37,7 @@ class Cursor<K> implements Iterator<K> {
@SuppressWarnings
(
"unchecked"
)
private
void
fetchNext
()
{
current
=
(
K
)
Page
.
nextKey
(
parents
);
current
=
(
K
)
map
.
nextKey
(
parents
);
}
public
boolean
hasNext
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/store/btree/DataType.java
浏览文件 @
32bae90e
...
...
@@ -64,9 +64,10 @@ public interface DataType {
Object
read
(
ByteBuffer
buff
);
/**
* Get the string representation of this type.
* Get the stable string representation that is used to build this data
* type.
*
* @return the string
* @return the string
representation
*/
String
asString
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/store/btree/
DataType
Factory.java
→
h2/src/tools/org/h2/dev/store/btree/
Map
Factory.java
浏览文件 @
32bae90e
...
...
@@ -9,15 +9,31 @@ package org.h2.dev.store.btree;
/**
* A factory for data types.
*/
public
interface
DataType
Factory
{
public
interface
Map
Factory
{
/**
*
Read the data type
.
*
Build a map
.
*
* @param s the string
* @param mapType the map type and type specific meta data
* @param store the store
* @param id the unique map id
* @param name the map name
* @param keyType the key type
* @param valueType the value type
* @param createVersion when the map was created
* @return the map
*/
<
K
,
V
>
BtreeMap
<
K
,
V
>
buildMap
(
String
mapType
,
BtreeMapStore
store
,
int
id
,
String
name
,
DataType
keyType
,
DataType
valueType
,
long
createVersion
);
/**
* Parse the data type.
*
* @param dataType the string and type specific meta data
* @return the type
*/
DataType
fromString
(
String
s
);
DataType
buildDataType
(
String
dataType
);
/**
* Get the data type object for the given class.
...
...
@@ -25,6 +41,6 @@ public interface DataTypeFactory {
* @param objectClass the class
* @return the data type object
*/
DataType
getDataType
(
Class
<?>
objectClass
);
String
getDataType
(
Class
<?>
objectClass
);
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/store/btree/Page.java
浏览文件 @
32bae90e
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论