Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
54d90c04
提交
54d90c04
authored
12月 15, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: simplify the builder API a bit
上级
b12bb799
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
122 行增加
和
148 行删除
+122
-148
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+103
-1
MVStoreBuilder.java
h2/src/main/org/h2/mvstore/MVStoreBuilder.java
+0
-127
MVTableEngine.java
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
+6
-8
TestConcurrent.java
h2/src/test/org/h2/test/store/TestConcurrent.java
+1
-2
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+12
-10
没有找到文件。
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
54d90c04
...
@@ -44,7 +44,6 @@ H:3,...
...
@@ -44,7 +44,6 @@ H:3,...
TODO:
TODO:
- cache: change API to better match guava / Android
- MVStore: improved API thanks to Simo Tripodi
- MVStore: improved API thanks to Simo Tripodi
- implement table engine for H2
- implement table engine for H2
- automated 'kill process' and 'power failure' test
- automated 'kill process' and 'power failure' test
...
@@ -1401,4 +1400,107 @@ public class MVStore {
...
@@ -1401,4 +1400,107 @@ public class MVStore {
return
DataUtils
.
parseMap
(
m
).
get
(
"name"
);
return
DataUtils
.
parseMap
(
m
).
get
(
"name"
);
}
}
/**
* A builder for an MVStore.
*/
public
static
class
Builder
{
private
final
HashMap
<
String
,
Object
>
config
=
New
.
hashMap
();
private
Builder
set
(
String
key
,
Object
value
)
{
if
(
config
.
containsKey
(
key
))
{
throw
DataUtils
.
illegalArgumentException
(
"Parameter "
+
config
.
get
(
key
)
+
" is already set"
);
}
config
.
put
(
key
,
value
);
return
this
;
}
/**
* Use the following file name. If the file does not exist, it is
* automatically created.
*
* @param fileName the file name
* @return this
*/
public
Builder
fileName
(
String
fileName
)
{
return
set
(
"fileName"
,
fileName
);
}
/**
* Open the file in read-only mode. In this case, a shared lock will be
* acquired to ensure the file is not concurrently opened in write mode.
* <p>
* If this option is not used, the file is locked exclusively.
* <p>
* Please note a store may only be opened once in every JVM (no matter
* whether it is opened in read-only or read-write mode), because each file
* may be locked only once in a process.
*
* @return this
*/
public
Builder
readOnly
()
{
return
set
(
"openMode"
,
"r"
);
}
/**
* Set the read cache size in MB. The default is 16 MB.
*
* @param mb the cache size
* @return this
*/
public
Builder
cacheSizeMB
(
int
mb
)
{
return
set
(
"cacheSize"
,
Integer
.
toString
(
mb
));
}
/**
* Compress data before writing using the LZF algorithm. This setting only
* affects writes; it is not necessary to enable compression when reading,
* even if compression was enabled when writing.
*
* @return this
*/
public
Builder
compressData
()
{
return
set
(
"compress"
,
"1"
);
}
/**
* Use the given data type factory.
*
* @param factory the data type factory
* @return this
*/
public
Builder
with
(
DataTypeFactory
factory
)
{
return
set
(
"dataTypeFactory"
,
factory
);
}
/**
* Open the store.
*
* @return the opened store
*/
public
MVStore
open
()
{
MVStore
s
=
new
MVStore
(
config
);
s
.
open
();
return
s
;
}
public
String
toString
()
{
return
DataUtils
.
appendMap
(
new
StringBuilder
(),
config
).
toString
();
}
/**
* Read the configuration from a string.
*
* @param s the string representation
* @return the builder
*/
public
static
Builder
fromString
(
String
s
)
{
HashMap
<
String
,
String
>
config
=
DataUtils
.
parseMap
(
s
);
Builder
builder
=
new
Builder
();
builder
.
config
.
putAll
(
config
);
return
builder
;
}
}
}
}
h2/src/main/org/h2/mvstore/MVStoreBuilder.java
deleted
100644 → 0
浏览文件 @
b12bb799
/*
* 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
.
mvstore
;
import
java.util.HashMap
;
import
org.h2.mvstore.type.DataTypeFactory
;
import
org.h2.util.New
;
/**
* A builder for an MVStore.
*/
public
class
MVStoreBuilder
{
private
final
HashMap
<
String
,
Object
>
config
=
New
.
hashMap
();
/**
* Use the following file name. If the file does not exist, it is
* automatically created.
*
* @param fileName the file name
* @return this
*/
public
static
MVStoreBuilder
fileBased
(
String
fileName
)
{
return
new
MVStoreBuilder
().
fileName
(
fileName
);
}
/**
* Open the store in-memory. In this case, no data may be saved.
*
* @return the store
*/
public
static
MVStoreBuilder
inMemory
()
{
return
new
MVStoreBuilder
();
}
private
MVStoreBuilder
set
(
String
key
,
Object
value
)
{
if
(
config
.
containsKey
(
key
))
{
throw
DataUtils
.
illegalArgumentException
(
"Parameter "
+
config
.
get
(
key
)
+
" is already set"
);
}
config
.
put
(
key
,
value
);
return
this
;
}
private
MVStoreBuilder
fileName
(
String
fileName
)
{
return
set
(
"fileName"
,
fileName
);
}
/**
* Open the file in read-only mode. In this case, a shared lock will be
* acquired to ensure the file is not concurrently opened in write mode.
* <p>
* If this option is not used, the file is locked exclusively.
* <p>
* Please note a store may only be opened once in every JVM (no matter
* whether it is opened in read-only or read-write mode), because each file
* may be locked only once in a process.
*
* @return this
*/
public
MVStoreBuilder
readOnly
()
{
return
set
(
"openMode"
,
"r"
);
}
/**
* Set the read cache size in MB. The default is 16 MB.
*
* @param mb the cache size
* @return this
*/
public
MVStoreBuilder
cacheSizeMB
(
int
mb
)
{
return
set
(
"cacheSize"
,
Integer
.
toString
(
mb
));
}
/**
* Compress data before writing using the LZF algorithm. This setting only
* affects writes; it is not necessary to enable compression when reading,
* even if compression was enabled when writing.
*
* @return this
*/
public
MVStoreBuilder
compressData
()
{
return
set
(
"compress"
,
"1"
);
}
/**
* Use the given data type factory.
*
* @param factory the data type factory
* @return this
*/
public
MVStoreBuilder
with
(
DataTypeFactory
factory
)
{
return
set
(
"dataTypeFactory"
,
factory
);
}
/**
* Open the store.
*
* @return the opened store
*/
public
MVStore
open
()
{
MVStore
s
=
new
MVStore
(
config
);
s
.
open
();
return
s
;
}
public
String
toString
()
{
return
DataUtils
.
appendMap
(
new
StringBuilder
(),
config
).
toString
();
}
/**
* Read the configuration from a string.
*
* @param s the string representation
* @return the builder
*/
public
static
MVStoreBuilder
fromString
(
String
s
)
{
HashMap
<
String
,
String
>
config
=
DataUtils
.
parseMap
(
s
);
MVStoreBuilder
builder
=
new
MVStoreBuilder
();
builder
.
config
.
putAll
(
config
);
return
builder
;
}
}
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
浏览文件 @
54d90c04
...
@@ -16,7 +16,6 @@ import org.h2.engine.Constants;
...
@@ -16,7 +16,6 @@ import org.h2.engine.Constants;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVStoreBuilder
;
import
org.h2.mvstore.type.DataTypeFactory
;
import
org.h2.mvstore.type.DataTypeFactory
;
import
org.h2.table.TableBase
;
import
org.h2.table.TableBase
;
import
org.h2.util.New
;
import
org.h2.util.New
;
...
@@ -47,20 +46,19 @@ public class MVTableEngine implements TableEngine {
...
@@ -47,20 +46,19 @@ public class MVTableEngine implements TableEngine {
public
TableBase
createTable
(
CreateTableData
data
)
{
public
TableBase
createTable
(
CreateTableData
data
)
{
Database
db
=
data
.
session
.
getDatabase
();
Database
db
=
data
.
session
.
getDatabase
();
String
storeName
=
db
.
getDatabasePath
();
String
storeName
=
db
.
getDatabasePath
();
MVStore
Builder
storeBuilder
;
MVStore
.
Builder
builder
=
new
MVStore
.
Builder
()
;
Store
store
;
Store
store
;
DataTypeFactory
f
=
new
ValueDataTypeFactory
(
db
.
getCompareMode
(),
db
);
DataTypeFactory
f
=
new
ValueDataTypeFactory
(
db
.
getCompareMode
(),
db
);
if
(
storeName
==
null
)
{
if
(
storeName
==
null
)
{
storeBuilder
=
MVStoreBuilder
.
inMemory
();
builder
.
with
(
f
);
storeBuilder
.
with
(
f
);
store
=
new
Store
(
db
,
builder
.
open
());
store
=
new
Store
(
db
,
storeBuilder
.
open
());
}
else
{
}
else
{
synchronized
(
STORES
)
{
synchronized
(
STORES
)
{
store
=
STORES
.
get
(
storeName
);
store
=
STORES
.
get
(
storeName
);
if
(
store
==
null
)
{
if
(
store
==
null
)
{
storeBuilder
=
MVStoreBuilder
.
fileBased
(
storeName
+
Constants
.
SUFFIX_MV_FILE
);
builder
.
fileName
(
storeName
+
Constants
.
SUFFIX_MV_FILE
);
storeB
uilder
.
with
(
f
);
b
uilder
.
with
(
f
);
store
=
new
Store
(
db
,
storeB
uilder
.
open
());
store
=
new
Store
(
db
,
b
uilder
.
open
());
STORES
.
put
(
storeName
,
store
);
STORES
.
put
(
storeName
,
store
);
}
else
if
(
store
.
db
!=
db
)
{
}
else
if
(
store
.
db
!=
db
)
{
throw
DbException
.
get
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
storeName
);
throw
DbException
.
get
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
storeName
);
...
...
h2/src/test/org/h2/test/store/TestConcurrent.java
浏览文件 @
54d90c04
...
@@ -17,7 +17,6 @@ import java.util.Random;
...
@@ -17,7 +17,6 @@ import java.util.Random;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMapConcurrent
;
import
org.h2.mvstore.MVMapConcurrent
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVStoreBuilder
;
import
org.h2.mvstore.type.ObjectDataTypeFactory
;
import
org.h2.mvstore.type.ObjectDataTypeFactory
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
...
@@ -168,7 +167,7 @@ public class TestConcurrent extends TestMVStore {
...
@@ -168,7 +167,7 @@ public class TestConcurrent extends TestMVStore {
}
}
private
void
testConcurrentIterate
()
{
private
void
testConcurrentIterate
()
{
MVStore
s
=
MVStoreBuilder
.
inMemory
().
MVStore
s
=
new
MVStore
.
Builder
().
with
(
new
ObjectDataTypeFactory
()).
open
();
with
(
new
ObjectDataTypeFactory
()).
open
();
s
.
setPageSize
(
3
);
s
.
setPageSize
(
3
);
final
MVMap
<
Integer
,
Integer
>
map
=
s
.
openMap
(
"test"
);
final
MVMap
<
Integer
,
Integer
>
map
=
s
.
openMap
(
"test"
);
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
54d90c04
...
@@ -16,7 +16,6 @@ import java.util.TreeMap;
...
@@ -16,7 +16,6 @@ import java.util.TreeMap;
import
org.h2.mvstore.Cursor
;
import
org.h2.mvstore.Cursor
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVStoreBuilder
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.mvstore.type.ObjectDataType
;
import
org.h2.mvstore.type.ObjectDataType
;
import
org.h2.mvstore.type.ObjectDataTypeFactory
;
import
org.h2.mvstore.type.ObjectDataTypeFactory
;
...
@@ -106,7 +105,8 @@ public class TestMVStore extends TestBase {
...
@@ -106,7 +105,8 @@ public class TestMVStore extends TestBase {
String
fileName
=
getBaseDir
()
+
"/testCacheSize.h3"
;
String
fileName
=
getBaseDir
()
+
"/testCacheSize.h3"
;
MVStore
s
;
MVStore
s
;
MVMap
<
Integer
,
String
>
map
;
MVMap
<
Integer
,
String
>
map
;
s
=
MVStoreBuilder
.
fileBased
(
fileName
).
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
compressData
().
compressData
().
with
(
new
ObjectDataTypeFactory
()).
open
();
with
(
new
ObjectDataTypeFactory
()).
open
();
map
=
s
.
openMap
(
"test"
);
map
=
s
.
openMap
(
"test"
);
...
@@ -120,7 +120,8 @@ public class TestMVStore extends TestBase {
...
@@ -120,7 +120,8 @@ public class TestMVStore extends TestBase {
3408
,
2590
,
1924
,
1440
,
1102
,
956
,
918
3408
,
2590
,
1924
,
1440
,
1102
,
956
,
918
};
};
for
(
int
cacheSize
=
0
;
cacheSize
<=
6
;
cacheSize
+=
4
)
{
for
(
int
cacheSize
=
0
;
cacheSize
<=
6
;
cacheSize
+=
4
)
{
s
=
MVStoreBuilder
.
fileBased
(
fileName
).
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
cacheSizeMB
(
1
+
3
*
cacheSize
).
cacheSizeMB
(
1
+
3
*
cacheSize
).
with
(
new
ObjectDataTypeFactory
()).
open
();
with
(
new
ObjectDataTypeFactory
()).
open
();
map
=
s
.
openMap
(
"test"
);
map
=
s
.
openMap
(
"test"
);
...
@@ -139,16 +140,16 @@ public class TestMVStore extends TestBase {
...
@@ -139,16 +140,16 @@ public class TestMVStore extends TestBase {
private
void
testConcurrentOpen
()
{
private
void
testConcurrentOpen
()
{
String
fileName
=
getBaseDir
()
+
"/testConcurrentOpen.h3"
;
String
fileName
=
getBaseDir
()
+
"/testConcurrentOpen.h3"
;
MVStore
s
=
MVStoreBuilder
.
fileBased
(
fileName
).
open
();
MVStore
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
open
();
try
{
try
{
MVStore
s1
=
MVStoreBuilder
.
fileBased
(
fileName
).
open
();
MVStore
s1
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
open
();
s1
.
close
();
s1
.
close
();
fail
();
fail
();
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
// expected
// expected
}
}
try
{
try
{
MVStore
s1
=
MVStoreBuilder
.
fileBased
(
fileName
).
readOnly
().
open
();
MVStore
s1
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
readOnly
().
open
();
s1
.
close
();
s1
.
close
();
fail
();
fail
();
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
...
@@ -351,7 +352,7 @@ public class TestMVStore extends TestBase {
...
@@ -351,7 +352,7 @@ public class TestMVStore extends TestBase {
private
void
testIterateOldVersion
()
{
private
void
testIterateOldVersion
()
{
MVStore
s
;
MVStore
s
;
Map
<
Integer
,
Integer
>
map
;
Map
<
Integer
,
Integer
>
map
;
s
=
MVStoreBuilder
.
inMemory
().
s
=
new
MVStore
.
Builder
().
with
(
new
ObjectDataTypeFactory
()).
open
();
with
(
new
ObjectDataTypeFactory
()).
open
();
map
=
s
.
openMap
(
"test"
);
map
=
s
.
openMap
(
"test"
);
int
len
=
100
;
int
len
=
100
;
...
@@ -377,7 +378,7 @@ public class TestMVStore extends TestBase {
...
@@ -377,7 +378,7 @@ public class TestMVStore extends TestBase {
FileUtils
.
delete
(
fileName
);
FileUtils
.
delete
(
fileName
);
MVStore
s
;
MVStore
s
;
Map
<
Object
,
Object
>
map
;
Map
<
Object
,
Object
>
map
;
s
=
MVStoreBuilder
.
fileBased
(
fileName
).
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
with
(
new
ObjectDataTypeFactory
()).
open
();
with
(
new
ObjectDataTypeFactory
()).
open
();
map
=
s
.
openMap
(
"test"
);
map
=
s
.
openMap
(
"test"
);
map
.
put
(
1
,
"Hello"
);
map
.
put
(
1
,
"Hello"
);
...
@@ -385,7 +386,7 @@ public class TestMVStore extends TestBase {
...
@@ -385,7 +386,7 @@ public class TestMVStore extends TestBase {
map
.
put
(
new
Object
[
1
],
new
Object
[]{
1
,
"2"
});
map
.
put
(
new
Object
[
1
],
new
Object
[]{
1
,
"2"
});
s
.
store
();
s
.
store
();
s
.
close
();
s
.
close
();
s
=
MVStoreBuilder
.
fileBased
(
fileName
).
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
with
(
new
ObjectDataTypeFactory
()).
open
();
with
(
new
ObjectDataTypeFactory
()).
open
();
map
=
s
.
openMap
(
"test"
);
map
=
s
.
openMap
(
"test"
);
assertEquals
(
"Hello"
,
map
.
get
(
1
).
toString
());
assertEquals
(
"Hello"
,
map
.
get
(
1
).
toString
());
...
@@ -1133,7 +1134,8 @@ public class TestMVStore extends TestBase {
...
@@ -1133,7 +1134,8 @@ public class TestMVStore extends TestBase {
* @return the store
* @return the store
*/
*/
protected
static
MVStore
openStore
(
String
fileName
)
{
protected
static
MVStore
openStore
(
String
fileName
)
{
MVStore
store
=
MVStoreBuilder
.
fileBased
(
fileName
).
MVStore
store
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
with
(
new
SampleTypeFactory
()).
open
();
with
(
new
SampleTypeFactory
()).
open
();
store
.
setPageSize
(
1000
);
store
.
setPageSize
(
1000
);
return
store
;
return
store
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论