Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bd00e7d3
提交
bd00e7d3
authored
9月 16, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved compatibility with the Java 7 FileSystem abstraction.
上级
abc9cec3
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
55 行增加
和
442 行删除
+55
-442
FileStore.java
h2/src/main/org/h2/store/FileStore.java
+17
-5
FileObject.java
h2/src/main/org/h2/store/fs/FileObject.java
+3
-7
FileObjectDisk.java
h2/src/main/org/h2/store/fs/FileObjectDisk.java
+2
-22
FileObjectMem.java
h2/src/main/org/h2/store/fs/FileObjectMem.java
+3
-6
FileObjectNio.java
h2/src/main/org/h2/store/fs/FileObjectNio.java
+2
-22
FileObjectNioMapped.java
h2/src/main/org/h2/store/fs/FileObjectNioMapped.java
+2
-22
FileObjectRec.java
h2/src/main/org/h2/store/fs/FileObjectRec.java
+2
-5
FileObjectSplit.java
h2/src/main/org/h2/store/fs/FileObjectSplit.java
+2
-5
FileObjectZip.java
h2/src/main/org/h2/store/fs/FileObjectZip.java
+3
-6
FilePath.java
h2/src/main/org/h2/store/fs/FilePath.java
+1
-1
FilePathNio.java
h2/src/main/org/h2/store/fs/FilePathNio.java
+1
-1
FilePathNioMapped.java
h2/src/main/org/h2/store/fs/FilePathNioMapped.java
+1
-1
FileUtils.java
h2/src/main/org/h2/store/fs/FileUtils.java
+0
-318
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+9
-4
FileDebug.java
h2/src/test/org/h2/test/utils/FileDebug.java
+2
-6
FileObjectCrypt.java
h2/src/tools/org/h2/dev/fs/FileObjectCrypt.java
+2
-5
FileObjectZip2.java
h2/src/tools/org/h2/dev/fs/FileObjectZip2.java
+3
-6
没有找到文件。
h2/src/main/org/h2/store/FileStore.java
浏览文件 @
bd00e7d3
...
...
@@ -54,6 +54,7 @@ public class FileStore {
private
String
mode
;
private
TempFileDeleter
tempFileDeleter
;
private
boolean
textMode
;
private
java
.
nio
.
channels
.
FileLock
lock
;
/**
* Create a new file using the given settings.
...
...
@@ -492,16 +493,27 @@ public class FileStore {
*
* @return true if successful
*/
public
boolean
tryLock
()
{
return
file
.
tryLock
();
public
synchronized
boolean
tryLock
()
{
try
{
lock
=
file
.
tryLock
();
return
true
;
}
catch
(
IOException
e
)
{
// ignore
return
false
;
}
}
/**
* Release the file lock.
*/
public
void
releaseLock
()
{
if
(
file
!=
null
)
{
file
.
releaseLock
();
public
synchronized
void
releaseLock
()
{
if
(
file
!=
null
&&
lock
!=
null
)
{
try
{
lock
.
release
();
}
catch
(
IOException
e
)
{
// ignore
}
lock
=
null
;
}
}
...
...
h2/src/main/org/h2/store/fs/FileObject.java
浏览文件 @
bd00e7d3
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
store
.
fs
;
import
java.io.IOException
;
import
java.nio.channels.FileLock
;
/**
* This interface represents a random access file.
...
...
@@ -71,13 +72,8 @@ public interface FileObject {
/**
* Try to lock the file exclusively.
*
* @return
true if locking was successful
* @return
a lock object if successful, or null if not
*/
boolean
tryLock
();
/**
* Release the file lock.
*/
void
releaseLock
();
FileLock
tryLock
()
throws
IOException
;
}
h2/src/main/org/h2/store/fs/FileObjectDisk.java
浏览文件 @
bd00e7d3
...
...
@@ -19,7 +19,6 @@ public class FileObjectDisk implements FileObject {
private
final
RandomAccessFile
file
;
private
final
String
name
;
private
FileLock
lock
;
FileObjectDisk
(
String
fileName
,
String
mode
)
throws
FileNotFoundException
{
this
.
file
=
new
RandomAccessFile
(
fileName
,
mode
);
...
...
@@ -48,27 +47,8 @@ public class FileObjectDisk implements FileObject {
}
}
public
synchronized
boolean
tryLock
()
{
if
(
lock
==
null
)
{
try
{
lock
=
file
.
getChannel
().
tryLock
();
}
catch
(
Exception
e
)
{
// could not lock (OverlappingFileLockException)
}
return
lock
!=
null
;
}
return
false
;
}
public
synchronized
void
releaseLock
()
{
if
(
lock
!=
null
)
{
try
{
lock
.
release
();
}
catch
(
IOException
e
)
{
// ignore
}
lock
=
null
;
}
public
synchronized
FileLock
tryLock
()
throws
IOException
{
return
file
.
getChannel
().
tryLock
();
}
public
void
close
()
throws
IOException
{
...
...
h2/src/main/org/h2/store/fs/FileObjectMem.java
浏览文件 @
bd00e7d3
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
store
.
fs
;
import
java.io.IOException
;
import
java.nio.channels.FileLock
;
/**
* This class represents an in-memory file.
...
...
@@ -60,12 +61,8 @@ public class FileObjectMem implements FileObject {
// do nothing
}
public
boolean
tryLock
()
{
return
data
.
tryLock
();
}
public
void
releaseLock
()
{
data
.
releaseLock
();
public
FileLock
tryLock
()
{
return
null
;
}
}
h2/src/main/org/h2/store/fs/FileObjectNio.java
浏览文件 @
bd00e7d3
...
...
@@ -22,7 +22,6 @@ public class FileObjectNio implements FileObject {
private
final
String
name
;
private
final
RandomAccessFile
file
;
private
final
FileChannel
channel
;
private
FileLock
lock
;
private
long
length
;
FileObjectNio
(
String
fileName
,
String
mode
)
throws
IOException
{
...
...
@@ -94,27 +93,8 @@ public class FileObjectNio implements FileObject {
}
}
public
synchronized
boolean
tryLock
()
{
if
(
lock
==
null
)
{
try
{
lock
=
channel
.
tryLock
();
}
catch
(
IOException
e
)
{
// could not lock
}
return
lock
!=
null
;
}
return
false
;
}
public
synchronized
void
releaseLock
()
{
if
(
lock
!=
null
)
{
try
{
lock
.
release
();
}
catch
(
IOException
e
)
{
// ignore
}
lock
=
null
;
}
public
synchronized
FileLock
tryLock
()
throws
IOException
{
return
channel
.
tryLock
();
}
public
String
toString
()
{
...
...
h2/src/main/org/h2/store/fs/FileObjectNioMapped.java
浏览文件 @
bd00e7d3
...
...
@@ -28,7 +28,6 @@ public class FileObjectNioMapped implements FileObject {
private
final
MapMode
mode
;
private
RandomAccessFile
file
;
private
MappedByteBuffer
mapped
;
private
FileLock
lock
;
/**
* The position within the file. Can't use the position of the mapped buffer
...
...
@@ -202,27 +201,8 @@ public class FileObjectNioMapped implements FileObject {
pos
+=
len
;
}
public
synchronized
boolean
tryLock
()
{
if
(
lock
==
null
)
{
try
{
lock
=
file
.
getChannel
().
tryLock
();
}
catch
(
IOException
e
)
{
// could not lock
}
return
lock
!=
null
;
}
return
false
;
}
public
synchronized
void
releaseLock
()
{
if
(
lock
!=
null
)
{
try
{
lock
.
release
();
}
catch
(
IOException
e
)
{
// ignore
}
lock
=
null
;
}
public
synchronized
FileLock
tryLock
()
throws
IOException
{
return
file
.
getChannel
().
tryLock
();
}
}
h2/src/main/org/h2/store/fs/FileObjectRec.java
浏览文件 @
bd00e7d3
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
store
.
fs
;
import
java.io.IOException
;
import
java.nio.channels.FileLock
;
/**
* A file object that records all write operations and can re-play them.
...
...
@@ -62,12 +63,8 @@ public class FileObjectRec implements FileObject {
fs
.
log
(
Recorder
.
WRITE
,
name
,
buff
,
file
.
position
());
}
public
boolean
tryLock
()
{
public
FileLock
tryLock
()
throws
IOException
{
return
file
.
tryLock
();
}
public
void
releaseLock
()
{
file
.
releaseLock
();
}
}
\ No newline at end of file
h2/src/main/org/h2/store/fs/FileObjectSplit.java
浏览文件 @
bd00e7d3
...
...
@@ -8,6 +8,7 @@ package org.h2.store.fs;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.nio.channels.FileLock
;
import
org.h2.message.DbException
;
/**
...
...
@@ -153,12 +154,8 @@ public class FileObjectSplit implements FileObject {
return
l
;
}
public
boolean
tryLock
()
{
public
FileLock
tryLock
()
throws
IOException
{
return
list
[
0
].
tryLock
();
}
public
void
releaseLock
()
{
list
[
0
].
releaseLock
();
}
}
h2/src/main/org/h2/store/fs/FileObjectZip.java
浏览文件 @
bd00e7d3
...
...
@@ -9,6 +9,7 @@ package org.h2.store.fs;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.channels.FileLock
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
...
...
@@ -103,12 +104,8 @@ public class FileObjectZip implements FileObject {
throw
new
IOException
(
"File is read-only"
);
}
public
boolean
tryLock
()
{
return
false
;
}
public
void
releaseLock
()
{
// ignore
public
FileLock
tryLock
()
{
return
null
;
}
}
h2/src/main/org/h2/store/fs/FilePath.java
浏览文件 @
bd00e7d3
...
...
@@ -29,7 +29,7 @@ public abstract class FilePath {
private
static
Map
<
String
,
FilePath
>
providers
;
/**
* The prefix for temporary files.
See also TestClearReferences.
* The prefix for temporary files.
*/
private
static
String
tempRandom
;
private
static
long
tempSequence
;
...
...
h2/src/main/org/h2/store/fs/FilePathNio.java
浏览文件 @
bd00e7d3
...
...
@@ -15,7 +15,7 @@ import java.io.IOException;
public
class
FilePathNio
extends
FilePathWrapper
{
public
FileObject
openFileObject
(
String
mode
)
throws
IOException
{
return
new
FileObjectNio
(
name
,
mode
);
return
new
FileObjectNio
(
name
.
substring
(
getScheme
().
length
()
+
1
)
,
mode
);
}
public
String
getScheme
()
{
...
...
h2/src/main/org/h2/store/fs/FilePathNioMapped.java
浏览文件 @
bd00e7d3
...
...
@@ -15,7 +15,7 @@ import java.io.IOException;
public
class
FilePathNioMapped
extends
FilePathNio
{
public
FileObject
openFileObject
(
String
mode
)
throws
IOException
{
return
new
FileObjectNioMapped
(
name
,
mode
);
return
new
FileObjectNioMapped
(
name
.
substring
(
getScheme
().
length
()
+
1
)
,
mode
);
}
public
String
getScheme
()
{
...
...
h2/src/main/org/h2/store/fs/FileUtils.java
浏览文件 @
bd00e7d3
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
bd00e7d3
...
...
@@ -12,6 +12,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.RandomAccessFile
;
import
java.nio.channels.FileLock
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
...
...
@@ -112,9 +113,11 @@ public class TestFileSystem extends TestBase {
FileObject
o
=
FileUtils
.
openFileObject
(
f
,
"rw"
);
o
.
position
(
4000
);
o
.
write
(
new
byte
[
1
],
0
,
1
);
o
.
tryLock
();
FileLock
lock
=
o
.
tryLock
();
o
.
truncate
(
0
);
o
.
releaseLock
();
if
(
lock
!=
null
)
{
lock
.
release
();
}
o
.
close
();
}
...
...
@@ -245,8 +248,10 @@ public class TestFileSystem extends TestBase {
can
=
FilePath
.
get
(
fsBase
).
getCanonicalPath
().
toString
();
String
can2
=
FileUtils
.
getCanonicalPath
(
FileUtils
.
getParent
(
path
));
assertEquals
(
can
,
can2
);
fo
.
tryLock
();
fo
.
releaseLock
();
FileLock
lock
=
fo
.
tryLock
();
if
(
lock
!=
null
)
{
lock
.
release
();
}
assertEquals
(
10000
,
fo
.
size
());
fo
.
close
();
assertEquals
(
10000
,
FileUtils
.
size
(
fsBase
+
"/test"
));
...
...
h2/src/test/org/h2/test/utils/FileDebug.java
浏览文件 @
bd00e7d3
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
test
.
utils
;
import
java.io.IOException
;
import
java.nio.channels.FileLock
;
import
org.h2.store.fs.FileObject
;
/**
...
...
@@ -83,14 +84,9 @@ public class FileDebug implements FileObject {
}
}
public
boolean
tryLock
()
{
public
FileLock
tryLock
()
throws
IOException
{
debug
(
"tryLock"
);
return
file
.
tryLock
();
}
public
void
releaseLock
()
{
debug
(
"releaseLock"
);
file
.
releaseLock
();
}
}
\ No newline at end of file
h2/src/tools/org/h2/dev/fs/FileObjectCrypt.java
浏览文件 @
bd00e7d3
...
...
@@ -8,6 +8,7 @@ package org.h2.dev.fs;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.nio.channels.FileLock
;
import
org.h2.engine.Constants
;
import
org.h2.security.BlockCipher
;
import
org.h2.security.CipherFactory
;
...
...
@@ -80,10 +81,6 @@ public class FileObjectCrypt implements FileObject {
return
Math
.
max
(
0
,
file
.
size
()
-
HEADER_LENGTH
-
BLOCK_SIZE
);
}
public
void
releaseLock
()
{
file
.
releaseLock
();
}
public
void
position
(
long
pos
)
throws
IOException
{
file
.
position
(
pos
+
HEADER_LENGTH
);
}
...
...
@@ -92,7 +89,7 @@ public class FileObjectCrypt implements FileObject {
file
.
sync
();
}
public
boolean
tryLock
()
{
public
FileLock
tryLock
()
throws
IOException
{
return
file
.
tryLock
();
}
...
...
h2/src/tools/org/h2/dev/fs/FileObjectZip2.java
浏览文件 @
bd00e7d3
...
...
@@ -9,6 +9,7 @@ package org.h2.dev.fs;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.channels.FileLock
;
import
java.util.zip.ZipInputStream
;
import
org.h2.store.fs.FileObject
;
...
...
@@ -109,12 +110,8 @@ public class FileObjectZip2 implements FileObject {
throw
new
IOException
(
"File is read-only"
);
}
public
boolean
tryLock
()
{
return
false
;
}
public
void
releaseLock
()
{
// ignore
public
FileLock
tryLock
()
{
return
null
;
}
public
String
toString
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论