Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f076058c
提交
f076058c
authored
1月 06, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable warning for 'Local variable declaration hides another field or variable'.
上级
162c96c0
隐藏空白字符变更
内嵌
并排
正在显示
35 个修改的文件
包含
310 行增加
和
314 行删除
+310
-314
Data.java
h2/src/main/org/h2/store/Data.java
+3
-3
DataPage.java
h2/src/main/org/h2/store/DataPage.java
+1
-3
DiskFile.java
h2/src/main/org/h2/store/DiskFile.java
+8
-8
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+9
-9
PageInputStream.java
h2/src/main/org/h2/store/PageInputStream.java
+3
-3
PageLog.java
h2/src/main/org/h2/store/PageLog.java
+23
-24
PageOutputStream.java
h2/src/main/org/h2/store/PageOutputStream.java
+5
-5
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+4
-4
FileObjectMemory.java
h2/src/main/org/h2/store/fs/FileObjectMemory.java
+2
-2
FileObjectZip.java
h2/src/main/org/h2/store/fs/FileObjectZip.java
+2
-2
Column.java
h2/src/main/org/h2/table/Column.java
+11
-11
FunctionTable.java
h2/src/main/org/h2/table/FunctionTable.java
+1
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+27
-27
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+1
-1
SingleColumnResolver.java
h2/src/main/org/h2/table/SingleColumnResolver.java
+2
-2
Table.java
h2/src/main/org/h2/table/Table.java
+2
-2
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+21
-21
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+7
-9
TableView.java
h2/src/main/org/h2/table/TableView.java
+5
-1
ChangeFileEncryption.java
h2/src/main/org/h2/tools/ChangeFileEncryption.java
+7
-7
Recover.java
h2/src/main/org/h2/tools/Recover.java
+35
-35
Restore.java
h2/src/main/org/h2/tools/Restore.java
+5
-5
Script.java
h2/src/main/org/h2/tools/Script.java
+7
-7
Shell.java
h2/src/main/org/h2/tools/Shell.java
+6
-6
SimpleResultSet.java
h2/src/main/org/h2/tools/SimpleResultSet.java
+1
-1
CacheLRU.java
h2/src/main/org/h2/util/CacheLRU.java
+20
-20
CacheObject.java
h2/src/main/org/h2/util/CacheObject.java
+4
-4
NetUtils.java
h2/src/main/org/h2/util/NetUtils.java
+4
-4
SourceCompiler.java
h2/src/main/org/h2/util/SourceCompiler.java
+12
-12
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+3
-6
ValueByte.java
h2/src/main/org/h2/value/ValueByte.java
+3
-3
ValueDecimal.java
h2/src/main/org/h2/value/ValueDecimal.java
+6
-6
ValueInt.java
h2/src/main/org/h2/value/ValueInt.java
+3
-3
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+54
-54
ValueShort.java
h2/src/main/org/h2/value/ValueShort.java
+3
-3
没有找到文件。
h2/src/main/org/h2/store/Data.java
浏览文件 @
f076058c
...
...
@@ -581,9 +581,9 @@ public class Data extends DataPage {
case
Value
.
DECIMAL
:
{
int
scale
=
readVarInt
();
int
len
=
readVarInt
();
byte
[]
data
=
MemoryUtils
.
newBytes
(
len
);
read
(
data
,
0
,
len
);
BigInteger
b
=
new
BigInteger
(
data
);
byte
[]
buff
=
MemoryUtils
.
newBytes
(
len
);
read
(
buff
,
0
,
len
);
BigInteger
b
=
new
BigInteger
(
buff
);
return
ValueDecimal
.
get
(
new
BigDecimal
(
b
,
scale
));
}
case
Value
.
DATE
:
{
...
...
h2/src/main/org/h2/store/DataPage.java
浏览文件 @
f076058c
...
...
@@ -397,9 +397,7 @@ public class DataPage {
* @param v the value
*/
public
void
writeValue
(
Value
v
)
throws
SQLException
{
if
(
SysProperties
.
CHECK
)
{
checkCapacity
(
8
);
}
checkCapacity
(
8
);
// TODO text output: could be in the Value... classes
if
(
v
==
ValueNull
.
INSTANCE
)
{
data
[
pos
++]
=
'-'
;
...
...
h2/src/main/org/h2/store/DiskFile.java
浏览文件 @
f076058c
...
...
@@ -1164,14 +1164,14 @@ public class DiskFile implements CacheWriter {
System
.
arraycopy
(
all
.
getBytes
(),
0
,
data
,
0
,
all
.
length
());
}
for
(
int
i
=
0
;
i
<
blockCount
;
i
++)
{
RedoLogRecord
log
=
new
RedoLogRecord
();
log
.
recordId
=
recordId
+
i
;
log
.
offset
=
i
*
BLOCK_SIZE
;
log
.
storage
=
storage
;
log
.
data
=
data
;
log
.
sequenceId
=
redoBuffer
.
size
();
redoBuffer
.
add
(
log
);
redoBufferSize
+=
log
.
getSize
();
RedoLogRecord
redo
=
new
RedoLogRecord
();
redo
.
recordId
=
recordId
+
i
;
redo
.
offset
=
i
*
BLOCK_SIZE
;
redo
.
storage
=
storage
;
redo
.
data
=
data
;
redo
.
sequenceId
=
redoBuffer
.
size
();
redoBuffer
.
add
(
redo
);
redoBufferSize
+=
redo
.
getSize
();
}
if
(
redoBufferSize
>
SysProperties
.
REDO_BUFFER_SIZE
)
{
flushRedoLog
();
...
...
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
f076058c
...
...
@@ -73,7 +73,7 @@ public class FileLock {
/**
* The server socket (only used when using the SOCKET mode).
*/
volatile
ServerSocket
socket
;
volatile
ServerSocket
s
erverS
ocket
;
/**
* The file system.
...
...
@@ -154,14 +154,14 @@ public class FileLock {
fs
.
delete
(
fileName
);
}
}
if
(
socket
!=
null
)
{
socket
.
close
();
if
(
s
erverS
ocket
!=
null
)
{
s
erverS
ocket
.
close
();
}
}
catch
(
Exception
e
)
{
trace
.
debug
(
"unlock"
,
e
);
}
finally
{
fileName
=
null
;
socket
=
null
;
s
erverS
ocket
=
null
;
locked
=
false
;
}
try
{
...
...
@@ -428,23 +428,23 @@ public class FileLock {
}
try
{
// 0 to use any free port
socket
=
NetUtils
.
createServerSocket
(
0
,
false
);
int
port
=
socket
.
getLocalPort
();
s
erverS
ocket
=
NetUtils
.
createServerSocket
(
0
,
false
);
int
port
=
s
erverS
ocket
.
getLocalPort
();
properties
.
setProperty
(
"ipAddress"
,
ipAddress
);
properties
.
setProperty
(
"port"
,
String
.
valueOf
(
port
));
}
catch
(
Exception
e
)
{
trace
.
debug
(
"lock"
,
e
);
socket
=
null
;
s
erverS
ocket
=
null
;
lockFile
();
return
;
}
save
();
watchdog
=
new
Thread
(
new
Runnable
()
{
public
void
run
()
{
while
(
socket
!=
null
)
{
while
(
s
erverS
ocket
!=
null
)
{
try
{
trace
.
debug
(
"watchdog accept"
);
Socket
s
=
socket
.
accept
();
Socket
s
=
s
erverS
ocket
.
accept
();
s
.
close
();
}
catch
(
Exception
e
)
{
trace
.
debug
(
"watchdog"
,
e
);
...
...
h2/src/main/org/h2/store/PageInputStream.java
浏览文件 @
f076058c
...
...
@@ -21,7 +21,7 @@ public class PageInputStream extends InputStream {
private
PageStore
store
;
private
final
Trace
trace
;
private
int
firstTrunkPage
;
private
PageStreamTrunk
.
Iterator
it
;
private
PageStreamTrunk
.
Iterator
trunkIterator
;
private
int
dataPage
;
private
PageStreamTrunk
trunk
;
private
PageStreamData
data
;
...
...
@@ -36,7 +36,7 @@ public class PageInputStream extends InputStream {
// minus one because we increment before comparing
this
.
logKey
=
logKey
-
1
;
this
.
firstTrunkPage
=
firstTrunkPage
;
it
=
new
PageStreamTrunk
.
Iterator
(
store
,
firstTrunkPage
);
trunkIterator
=
new
PageStreamTrunk
.
Iterator
(
store
,
firstTrunkPage
);
this
.
dataPage
=
dataPage
;
}
...
...
@@ -88,7 +88,7 @@ public class PageInputStream extends InputStream {
int
next
;
while
(
true
)
{
if
(
trunk
==
null
)
{
trunk
=
it
.
next
();
trunk
=
trunkIterator
.
next
();
logKey
++;
if
(
trunk
==
null
||
trunk
.
getLogKey
()
!=
logKey
)
{
endOfFile
=
true
;
...
...
h2/src/main/org/h2/store/PageLog.java
浏览文件 @
f076058c
...
...
@@ -116,16 +116,14 @@ public class PageLog {
private
static
final
boolean
COMPRESS_UNDO
=
true
;
private
final
PageStore
store
;
private
int
pos
;
private
Trace
trace
;
private
Data
writeBuffer
;
private
PageInputStream
pageIn
;
private
PageOutputStream
pageOut
;
private
DataReader
in
;
private
int
firstTrunkPage
;
private
int
firstDataPage
;
private
Data
data
;
private
Data
data
Buffer
;
private
int
logKey
;
private
int
logSectionId
,
logPos
;
private
int
firstSectionId
;
...
...
@@ -164,7 +162,7 @@ public class PageLog {
PageLog
(
PageStore
store
)
{
this
.
store
=
store
;
data
=
store
.
createData
();
data
Buffer
=
store
.
createData
();
trace
=
store
.
getTrace
();
compress
=
new
CompressLZF
();
compressBuffer
=
new
byte
[
store
.
getPageSize
()
*
2
];
...
...
@@ -174,17 +172,17 @@ public class PageLog {
* Open the log for writing. For an existing database, the recovery
* must be run first.
*
* @param
f
irstTrunkPage the first trunk page
* @param
newF
irstTrunkPage the first trunk page
* @param atEnd whether only pages at the end of the file should be used
*/
void
openForWriting
(
int
f
irstTrunkPage
,
boolean
atEnd
)
throws
SQLException
{
trace
.
debug
(
"log openForWriting firstPage:"
+
f
irstTrunkPage
);
this
.
firstTrunkPage
=
f
irstTrunkPage
;
void
openForWriting
(
int
newF
irstTrunkPage
,
boolean
atEnd
)
throws
SQLException
{
trace
.
debug
(
"log openForWriting firstPage:"
+
newF
irstTrunkPage
);
this
.
firstTrunkPage
=
newF
irstTrunkPage
;
logKey
++;
pageOut
=
new
PageOutputStream
(
store
,
f
irstTrunkPage
,
undoAll
,
logKey
,
atEnd
);
pageOut
=
new
PageOutputStream
(
store
,
newF
irstTrunkPage
,
undoAll
,
logKey
,
atEnd
);
pageOut
.
reserve
(
1
);
// pageBuffer = new BufferedOutputStream(pageOut, 8 * 1024);
store
.
setLogFirstPage
(
logKey
,
f
irstTrunkPage
,
pageOut
.
getCurrentDataPageId
());
store
.
setLogFirstPage
(
logKey
,
newF
irstTrunkPage
,
pageOut
.
getCurrentDataPageId
());
writeBuffer
=
store
.
createData
();
}
...
...
@@ -212,14 +210,14 @@ public class PageLog {
/**
* Open the log for reading.
*
* @param
l
ogKey the first expected log key
* @param
f
irstTrunkPage the first trunk page
* @param
f
irstDataPage the index of the first data page
*/
void
openForReading
(
int
logKey
,
int
firstTrunkPage
,
int
f
irstDataPage
)
{
this
.
logKey
=
l
ogKey
;
this
.
firstTrunkPage
=
f
irstTrunkPage
;
this
.
firstDataPage
=
f
irstDataPage
;
* @param
newL
ogKey the first expected log key
* @param
newF
irstTrunkPage the first trunk page
* @param
newF
irstDataPage the index of the first data page
*/
void
openForReading
(
int
newLogKey
,
int
newFirstTrunkPage
,
int
newF
irstDataPage
)
{
this
.
logKey
=
newL
ogKey
;
this
.
firstTrunkPage
=
newF
irstTrunkPage
;
this
.
firstDataPage
=
newF
irstDataPage
;
}
/**
...
...
@@ -241,11 +239,11 @@ public class PageLog {
return
;
}
pageIn
=
new
PageInputStream
(
store
,
logKey
,
firstTrunkPage
,
firstDataPage
);
in
=
new
DataReader
(
pageIn
);
DataReader
in
=
new
DataReader
(
pageIn
);
int
logId
=
0
;
Data
data
=
store
.
createData
();
try
{
pos
=
0
;
int
pos
=
0
;
while
(
true
)
{
int
x
=
in
.
read
();
if
(
x
<
0
)
{
...
...
@@ -576,6 +574,7 @@ public class PageLog {
session
.
addLogPos
(
logSectionId
,
logPos
);
row
.
setLastLog
(
logSectionId
,
logPos
);
logPos
++;
Data
data
=
dataBuffer
;
data
.
reset
();
int
columns
=
row
.
getColumnCount
();
data
.
writeVarInt
(
columns
);
...
...
@@ -684,21 +683,21 @@ public class PageLog {
/**
* Remove all pages until the given data page.
*
* @param
firstT
runkPage the first trunk page
* @param
t
runkPage the first trunk page
* @param firstDataPageToKeep the first data page to keep
* @return the trunk page of the data page to keep
*/
private
int
removeUntil
(
int
firstT
runkPage
,
int
firstDataPageToKeep
)
throws
SQLException
{
private
int
removeUntil
(
int
t
runkPage
,
int
firstDataPageToKeep
)
throws
SQLException
{
trace
.
debug
(
"log.removeUntil "
+
firstDataPageToKeep
);
while
(
true
)
{
Page
p
=
store
.
getPage
(
firstT
runkPage
);
Page
p
=
store
.
getPage
(
t
runkPage
);
PageStreamTrunk
t
=
(
PageStreamTrunk
)
p
;
logKey
=
t
.
getLogKey
();
t
.
resetIndex
();
if
(
t
.
contains
(
firstDataPageToKeep
))
{
return
t
.
getPos
();
}
firstT
runkPage
=
t
.
getNextTrunk
();
t
runkPage
=
t
.
getNextTrunk
();
IntArray
list
=
new
IntArray
();
list
.
add
(
t
.
getPos
());
while
(
true
)
{
...
...
h2/src/main/org/h2/store/PageOutputStream.java
浏览文件 @
f076058c
...
...
@@ -33,7 +33,7 @@ public class PageOutputStream extends OutputStream {
private
byte
[]
buffer
=
new
byte
[
1
];
private
boolean
needFlush
;
private
boolean
writing
;
private
int
page
s
;
private
int
page
Count
;
private
boolean
atEnd
;
private
int
logKey
;
...
...
@@ -106,13 +106,13 @@ public class PageOutputStream extends OutputStream {
trunkNext
=
reservedPages
.
get
(
len
);
logKey
++;
trunk
=
PageStreamTrunk
.
create
(
store
,
parent
,
trunkPageId
,
trunkNext
,
logKey
,
pageIds
);
page
s
++;
page
Count
++;
trunk
.
write
(
null
);
reservedPages
.
removeRange
(
0
,
len
+
1
);
nextData
=
trunk
.
getNextPageData
();
}
data
=
PageStreamData
.
create
(
store
,
nextData
,
trunk
.
getPos
(),
logKey
);
page
s
++;
page
Count
++;
data
.
initWrite
();
}
...
...
@@ -186,7 +186,7 @@ public class PageOutputStream extends OutputStream {
}
long
getSize
()
{
return
page
s
*
store
.
getPageSize
();
return
page
Count
*
store
.
getPageSize
();
}
/**
...
...
@@ -195,7 +195,7 @@ public class PageOutputStream extends OutputStream {
* @param t the trunk page
*/
void
free
(
PageStreamTrunk
t
)
throws
SQLException
{
page
s
-=
t
.
free
();
page
Count
-=
t
.
free
();
}
int
getCurrentLogKey
()
{
...
...
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
f076058c
...
...
@@ -555,10 +555,10 @@ public class PageStore implements CacheWriter {
int
firstUncommittedSection
=
log
.
getLogSectionId
();
for
(
int
i
=
0
;
i
<
sessions
.
length
;
i
++)
{
Session
session
=
sessions
[
i
];
int
log
=
session
.
getFirstUncommittedLog
();
if
(
log
!=
LogSystem
.
LOG_WRITTEN
)
{
if
(
log
<
firstUncommittedSection
)
{
firstUncommittedSection
=
log
;
int
firstUncommitted
=
session
.
getFirstUncommittedLog
();
if
(
firstUncommitted
!=
LogSystem
.
LOG_WRITTEN
)
{
if
(
firstUncommitted
<
firstUncommittedSection
)
{
firstUncommittedSection
=
firstUncommitted
;
}
}
}
...
...
h2/src/main/org/h2/store/fs/FileObjectMemory.java
浏览文件 @
f076058c
...
...
@@ -178,8 +178,8 @@ public class FileObjectMemory implements FileObject {
}
}
public
void
seek
(
long
p
os
)
{
this
.
pos
=
(
int
)
p
os
;
public
void
seek
(
long
newP
os
)
{
this
.
pos
=
(
int
)
newP
os
;
}
private
void
changeLength
(
long
len
)
{
...
...
h2/src/main/org/h2/store/fs/FileObjectZip.java
浏览文件 @
f076058c
...
...
@@ -87,8 +87,8 @@ public class FileObjectZip implements FileObject {
inPos
+=
len
;
}
public
void
seek
(
long
p
os
)
{
this
.
pos
=
p
os
;
public
void
seek
(
long
newP
os
)
{
this
.
pos
=
newP
os
;
}
public
void
setFileLength
(
long
newLength
)
throws
IOException
{
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
f076058c
...
...
@@ -326,16 +326,16 @@ public class Column {
private
void
updateSequenceIfRequired
(
Session
session
,
Value
value
)
throws
SQLException
{
if
(
sequence
!=
null
)
{
long
current
=
sequence
.
getCurrentValue
();
long
inc
rement
=
sequence
.
getIncrement
();
long
inc
=
sequence
.
getIncrement
();
long
now
=
value
.
getLong
();
boolean
update
=
false
;
if
(
inc
rement
>
0
&&
now
>
current
)
{
if
(
inc
>
0
&&
now
>
current
)
{
update
=
true
;
}
else
if
(
inc
rement
<
0
&&
now
<
current
)
{
}
else
if
(
inc
<
0
&&
now
<
current
)
{
update
=
true
;
}
if
(
update
)
{
sequence
.
setStartValue
(
now
+
inc
rement
);
sequence
.
setStartValue
(
now
+
inc
);
session
.
setLastIdentity
(
ValueLong
.
get
(
now
));
sequence
.
flush
(
session
);
}
...
...
@@ -370,16 +370,16 @@ public class Column {
break
;
}
}
Sequence
seq
uence
=
new
Sequence
(
schema
,
id
,
sequenceName
,
true
);
seq
uence
.
setStartValue
(
start
);
seq
uence
.
setIncrement
(
increment
);
Sequence
seq
=
new
Sequence
(
schema
,
id
,
sequenceName
,
true
);
seq
.
setStartValue
(
start
);
seq
.
setIncrement
(
increment
);
if
(!
temporary
)
{
session
.
getDatabase
().
addSchemaObject
(
session
,
seq
uence
);
session
.
getDatabase
().
addSchemaObject
(
session
,
seq
);
}
setAutoIncrement
(
false
,
0
,
0
);
SequenceValue
seq
=
new
SequenceValue
(
sequence
);
setDefaultExpression
(
session
,
seq
);
setSequence
(
seq
uence
);
SequenceValue
seq
Value
=
new
SequenceValue
(
seq
);
setDefaultExpression
(
session
,
seq
Value
);
setSequence
(
seq
);
}
/**
...
...
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
f076058c
...
...
@@ -92,7 +92,7 @@ public class FunctionTable extends Table {
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
c
omment
)
throws
SQLException
{
int
headPos
,
String
indexC
omment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"ALIAS"
);
}
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
f076058c
...
...
@@ -104,7 +104,7 @@ public class MetaTable extends Table {
private
final
int
type
;
private
final
int
indexColumn
;
private
MetaIndex
i
ndex
;
private
MetaIndex
metaI
ndex
;
/**
* Create a new metadata table.
...
...
@@ -513,7 +513,7 @@ public class MetaTable extends Table {
}
else
{
indexColumn
=
getColumn
(
indexColumnName
).
getColumnId
();
IndexColumn
[]
indexCols
=
IndexColumn
.
wrap
(
new
Column
[]
{
cols
[
indexColumn
]
});
i
ndex
=
new
MetaIndex
(
this
,
indexCols
,
false
);
metaI
ndex
=
new
MetaIndex
(
this
,
indexCols
,
false
);
}
}
...
...
@@ -522,16 +522,16 @@ public class MetaTable extends Table {
for
(
int
i
=
0
;
i
<
names
.
length
;
i
++)
{
String
nameType
=
names
[
i
];
int
idx
=
nameType
.
indexOf
(
' '
);
int
t
ype
;
int
dataT
ype
;
String
name
;
if
(
idx
<
0
)
{
t
ype
=
Value
.
STRING
;
dataT
ype
=
Value
.
STRING
;
name
=
nameType
;
}
else
{
t
ype
=
DataType
.
getTypeByName
(
nameType
.
substring
(
idx
+
1
)).
type
;
dataT
ype
=
DataType
.
getTypeByName
(
nameType
.
substring
(
idx
+
1
)).
type
;
name
=
nameType
.
substring
(
0
,
idx
);
}
cols
[
i
]
=
new
Column
(
name
,
t
ype
);
cols
[
i
]
=
new
Column
(
name
,
dataT
ype
);
}
return
cols
;
}
...
...
@@ -545,7 +545,7 @@ public class MetaTable extends Table {
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
c
omment
)
throws
SQLException
{
int
headPos
,
String
indexC
omment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"META"
);
}
...
...
@@ -1017,7 +1017,7 @@ public class MetaTable extends Table {
for
(
Right
r
:
database
.
getAllRights
())
{
Role
role
=
r
.
getGrantedRole
();
DbObject
grantee
=
r
.
getGrantee
();
String
t
ype
=
grantee
.
getType
()
==
DbObject
.
USER
?
"USER"
:
"ROLE"
;
String
rightT
ype
=
grantee
.
getType
()
==
DbObject
.
USER
?
"USER"
:
"ROLE"
;
if
(
role
==
null
)
{
Table
granted
=
r
.
getGrantedTable
();
String
tableName
=
identifier
(
granted
.
getName
());
...
...
@@ -1028,7 +1028,7 @@ public class MetaTable extends Table {
// GRANTEE
identifier
(
grantee
.
getName
()),
// GRANTEETYPE
t
ype
,
rightT
ype
,
// GRANTEDROLE
""
,
// RIGHTS
...
...
@@ -1045,7 +1045,7 @@ public class MetaTable extends Table {
// GRANTEE
identifier
(
grantee
.
getName
()),
// GRANTEETYPE
t
ype
,
rightT
ype
,
// GRANTEDROLE
identifier
(
role
.
getName
()),
// RIGHTS
...
...
@@ -1122,11 +1122,11 @@ public class MetaTable extends Table {
case
FUNCTION_COLUMNS:
{
for
(
FunctionAlias
alias
:
database
.
getAllFunctionAliases
())
{
for
(
FunctionAlias
.
JavaMethod
method
:
alias
.
getJavaMethods
())
{
Class
<
?
>[]
column
s
=
method
.
getColumnClasses
();
for
(
int
k
=
0
;
k
<
column
s
.
length
;
k
++)
{
Class
<
?
>
clazz
=
column
s
[
k
];
int
t
ype
=
DataType
.
getTypeFromClass
(
clazz
);
DataType
dt
=
DataType
.
getDataType
(
t
ype
);
Class
<
?
>[]
column
List
=
method
.
getColumnClasses
();
for
(
int
k
=
0
;
k
<
column
List
.
length
;
k
++)
{
Class
<
?
>
clazz
=
column
List
[
k
];
int
dataT
ype
=
DataType
.
getTypeFromClass
(
clazz
);
DataType
dt
=
DataType
.
getDataType
(
dataT
ype
);
int
nullable
=
clazz
.
isPrimitive
()
?
DatabaseMetaData
.
columnNoNulls
:
DatabaseMetaData
.
columnNullable
;
add
(
rows
,
...
...
@@ -1338,9 +1338,9 @@ public class MetaTable extends Table {
case
CONSTRAINTS:
{
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
))
{
Constraint
constraint
=
(
Constraint
)
obj
;
String
t
ype
=
constraint
.
getConstraintType
();
String
constraintT
ype
=
constraint
.
getConstraintType
();
String
checkExpression
=
null
;
IndexColumn
[]
c
olumns
=
null
;
IndexColumn
[]
indexC
olumns
=
null
;
Table
table
=
constraint
.
getTable
();
Index
index
=
constraint
.
getUniqueIndex
();
String
uniqueIndexName
=
null
;
...
...
@@ -1351,17 +1351,17 @@ public class MetaTable extends Table {
if
(!
checkIndex
(
session
,
tableName
,
indexFrom
,
indexTo
))
{
continue
;
}
if
(
t
ype
.
equals
(
Constraint
.
CHECK
))
{
if
(
constraintT
ype
.
equals
(
Constraint
.
CHECK
))
{
checkExpression
=
((
ConstraintCheck
)
constraint
).
getExpression
().
getSQL
();
}
else
if
(
type
.
equals
(
Constraint
.
UNIQUE
)
||
t
ype
.
equals
(
Constraint
.
PRIMARY_KEY
))
{
c
olumns
=
((
ConstraintUnique
)
constraint
).
getColumns
();
}
else
if
(
t
ype
.
equals
(
Constraint
.
REFERENTIAL
))
{
c
olumns
=
((
ConstraintReferential
)
constraint
).
getColumns
();
}
else
if
(
constraintType
.
equals
(
Constraint
.
UNIQUE
)
||
constraintT
ype
.
equals
(
Constraint
.
PRIMARY_KEY
))
{
indexC
olumns
=
((
ConstraintUnique
)
constraint
).
getColumns
();
}
else
if
(
constraintT
ype
.
equals
(
Constraint
.
REFERENTIAL
))
{
indexC
olumns
=
((
ConstraintReferential
)
constraint
).
getColumns
();
}
String
columnList
=
null
;
if
(
c
olumns
!=
null
)
{
if
(
indexC
olumns
!=
null
)
{
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
IndexColumn
col
:
c
olumns
)
{
for
(
IndexColumn
col
:
indexC
olumns
)
{
buff
.
appendExceptFirst
(
","
);
buff
.
append
(
col
.
column
.
getName
());
}
...
...
@@ -1375,7 +1375,7 @@ public class MetaTable extends Table {
// CONSTRAINT_NAME
identifier
(
constraint
.
getName
()),
// CONSTRAINT_TYPE
t
ype
,
constraintT
ype
,
// TABLE_CATALOG
catalog
,
// TABLE_SCHEMA
...
...
@@ -1731,13 +1731,13 @@ public class MetaTable extends Table {
}
public
ObjectArray
<
Index
>
getIndexes
()
{
if
(
i
ndex
==
null
)
{
if
(
metaI
ndex
==
null
)
{
return
null
;
}
ObjectArray
<
Index
>
list
=
ObjectArray
.
newInstance
();
list
.
add
(
new
MetaIndex
(
this
,
IndexColumn
.
wrap
(
columns
),
true
));
// TODO fixed scan index
list
.
add
(
i
ndex
);
list
.
add
(
metaI
ndex
);
return
list
;
}
...
...
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
f076058c
...
...
@@ -78,7 +78,7 @@ public class RangeTable extends Table {
return
false
;
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
c
omment
)
throws
SQLException
{
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
indexC
omment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"SYSTEM_RANGE"
);
}
...
...
h2/src/main/org/h2/table/SingleColumnResolver.java
浏览文件 @
f076058c
...
...
@@ -32,7 +32,7 @@ public class SingleColumnResolver implements ColumnResolver {
this
.
value
=
value
;
}
public
Value
getValue
(
Column
col
umn
)
{
public
Value
getValue
(
Column
col
)
{
return
value
;
}
...
...
@@ -56,7 +56,7 @@ public class SingleColumnResolver implements ColumnResolver {
return
null
;
}
public
Expression
optimize
(
ExpressionColumn
expressionColumn
,
Column
col
umn
)
{
public
Expression
optimize
(
ExpressionColumn
expressionColumn
,
Column
col
)
{
return
expressionColumn
;
}
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
f076058c
...
...
@@ -152,11 +152,11 @@ public abstract class Table extends SchemaObjectBase {
* @param cols the index columns
* @param indexType the index type
* @param headPos the position of the head (if the index already exists)
* @param
c
omment the comment
* @param
indexC
omment the comment
* @return the index
*/
public
abstract
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
c
omment
)
throws
SQLException
;
int
headPos
,
String
indexC
omment
)
throws
SQLException
;
/**
* Remove a row from the table and all indexes.
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
f076058c
...
...
@@ -111,30 +111,30 @@ public class TableFilter implements ColumnResolver {
/**
* Lock the table. This will also lock joined tables.
*
* @param s
ession
the session
* @param s the session
* @param exclusive true if an exclusive lock is required
* @param force lock even in the MVCC mode
*/
public
void
lock
(
Session
s
ession
,
boolean
exclusive
,
boolean
force
)
throws
SQLException
{
table
.
lock
(
s
ession
,
exclusive
,
force
);
public
void
lock
(
Session
s
,
boolean
exclusive
,
boolean
force
)
throws
SQLException
{
table
.
lock
(
s
,
exclusive
,
force
);
if
(
join
!=
null
)
{
join
.
lock
(
s
ession
,
exclusive
,
force
);
join
.
lock
(
s
,
exclusive
,
force
);
}
}
/**
* Get the best plan item (index, cost) to use use for the current join order.
*
* @param s
ession
the session
* @param s the session
* @param level 1 for the first table in a join, 2 for the second, and so on
* @return the best plan item
*/
public
PlanItem
getBestPlanItem
(
Session
s
ession
,
int
level
)
throws
SQLException
{
public
PlanItem
getBestPlanItem
(
Session
s
,
int
level
)
throws
SQLException
{
PlanItem
item
;
if
(
indexConditions
.
size
()
==
0
)
{
item
=
new
PlanItem
();
item
.
setIndex
(
table
.
getScanIndex
(
s
ession
));
item
.
cost
=
item
.
getIndex
().
getCost
(
s
ession
,
null
);
item
.
setIndex
(
table
.
getScanIndex
(
s
));
item
.
cost
=
item
.
getIndex
().
getCost
(
s
,
null
);
}
else
{
int
len
=
table
.
getColumns
().
length
;
int
[]
masks
=
new
int
[
len
];
...
...
@@ -148,7 +148,7 @@ public class TableFilter implements ColumnResolver {
masks
[
id
]
|=
condition
.
getMask
(
indexConditions
.
size
());
}
}
item
=
table
.
getBestPlanItem
(
s
ession
,
masks
);
item
=
table
.
getBestPlanItem
(
s
,
masks
);
// the more index conditions, the earlier the table
// to ensure joins without indexes are evaluated:
// x (x.a=10); y (x.b=y.b) - see issue 113
...
...
@@ -156,7 +156,7 @@ public class TableFilter implements ColumnResolver {
}
if
(
join
!=
null
)
{
setEvaluatable
(
join
);
item
.
setJoinPlan
(
join
.
getBestPlanItem
(
s
ession
,
level
));
item
.
setJoinPlan
(
join
.
getBestPlanItem
(
s
,
level
));
// TODO optimizer: calculate cost of a join: should use separate
// expected row number and lookup cost
item
.
cost
+=
item
.
cost
*
item
.
getJoinPlan
().
cost
;
...
...
@@ -222,13 +222,13 @@ public class TableFilter implements ColumnResolver {
/**
* Start the query. This will reset the scan counts.
*
* @param s
ession
the session
* @param s the session
*/
public
void
startQuery
(
Session
s
ession
)
{
this
.
session
=
s
ession
;
public
void
startQuery
(
Session
s
)
{
this
.
session
=
s
;
scanCount
=
0
;
if
(
join
!=
null
)
{
join
.
startQuery
(
s
ession
);
join
.
startQuery
(
s
);
}
}
...
...
@@ -382,10 +382,10 @@ public class TableFilter implements ColumnResolver {
* Add a filter condition.
*
* @param condition the condition
* @param
j
oin if this is in fact a join condition
* @param
isJ
oin if this is in fact a join condition
*/
public
void
addFilterCondition
(
Expression
condition
,
boolean
j
oin
)
{
if
(
j
oin
)
{
public
void
addFilterCondition
(
Expression
condition
,
boolean
isJ
oin
)
{
if
(
isJ
oin
)
{
if
(
joinCondition
==
null
)
{
joinCondition
=
condition
;
}
else
{
...
...
@@ -460,12 +460,12 @@ public class TableFilter implements ColumnResolver {
/**
* Get the query execution plan text to use for this table filter.
*
* @param
j
oin if this is a joined table
* @param
isJ
oin if this is a joined table
* @return the SQL statement snippet
*/
public
String
getPlanSQL
(
boolean
j
oin
)
{
public
String
getPlanSQL
(
boolean
isJ
oin
)
{
StringBuilder
buff
=
new
StringBuilder
();
if
(
j
oin
)
{
if
(
isJ
oin
)
{
if
(
outerJoin
)
{
buff
.
append
(
"LEFT OUTER JOIN "
);
}
else
{
...
...
@@ -490,7 +490,7 @@ public class TableFilter implements ColumnResolver {
String
plan
=
StringUtils
.
quoteRemarkSQL
(
planBuff
.
toString
());
buff
.
append
(
plan
).
append
(
" */"
);
}
if
(
j
oin
)
{
if
(
isJ
oin
)
{
buff
.
append
(
" ON "
);
if
(
joinCondition
==
null
)
{
// need to have a ON expression, otherwise the nesting is unclear
...
...
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
f076058c
...
...
@@ -23,7 +23,6 @@ import org.h2.index.LinkedIndex;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.log.UndoLogRecord
;
import
org.h2.message.Message
;
import
org.h2.message.Trace
;
import
org.h2.result.Row
;
import
org.h2.result.RowList
;
import
org.h2.schema.Schema
;
...
...
@@ -48,7 +47,7 @@ public class TableLink extends Table {
private
String
driver
,
url
,
user
,
password
,
originalSchema
,
originalTable
,
qualifiedTableName
;
private
TableLinkConnection
conn
;
private
HashMap
<
String
,
PreparedStatement
>
prepared
=
New
.
hashMap
();
private
HashMap
<
String
,
PreparedStatement
>
prepared
Map
=
New
.
hashMap
();
private
final
ObjectArray
<
Index
>
indexes
=
ObjectArray
.
newInstance
();
private
final
boolean
emitUpdates
;
private
LinkedIndex
linkedIndex
;
...
...
@@ -332,7 +331,7 @@ public class TableLink extends Table {
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
c
omment
)
throws
SQLException
{
int
headPos
,
String
indexC
omment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"LINK"
);
}
...
...
@@ -413,20 +412,19 @@ public class TableLink extends Table {
* @return the prepared statement
*/
public
PreparedStatement
getPreparedStatement
(
String
sql
,
boolean
exclusive
)
throws
SQLException
{
Trace
trace
=
database
.
getTrace
(
Trace
.
TABLE
);
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
getName
()
+
":\n"
+
sql
);
}
if
(
conn
==
null
)
{
throw
connectException
;
}
PreparedStatement
prep
=
prepared
.
get
(
sql
);
PreparedStatement
prep
=
prepared
Map
.
get
(
sql
);
if
(
prep
==
null
)
{
prep
=
conn
.
getConnection
().
prepareStatement
(
sql
);
prepared
.
put
(
sql
,
prep
);
prepared
Map
.
put
(
sql
,
prep
);
}
if
(
exclusive
)
{
prepared
.
remove
(
sql
);
prepared
Map
.
remove
(
sql
);
}
return
prep
;
}
...
...
@@ -465,7 +463,7 @@ public class TableLink extends Table {
database
.
removeMeta
(
session
,
getId
());
driver
=
null
;
url
=
user
=
password
=
originalTable
=
null
;
prepared
=
null
;
prepared
Map
=
null
;
invalidate
();
}
...
...
@@ -536,7 +534,7 @@ public class TableLink extends Table {
* @param sql the SQL statement
*/
public
void
reusePreparedStatement
(
PreparedStatement
prep
,
String
sql
)
{
prepared
.
put
(
sql
,
prep
);
prepared
Map
.
put
(
sql
,
prep
);
}
public
boolean
isDeterministic
()
{
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
f076058c
...
...
@@ -200,7 +200,7 @@ public class TableView extends Table {
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
c
omment
)
throws
SQLException
{
int
headPos
,
String
indexC
omment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"VIEW"
);
}
...
...
@@ -253,6 +253,10 @@ public class TableView extends Table {
return
super
.
getSQL
();
}
public
String
getQuery
()
{
return
querySQL
;
}
public
Index
getScanIndex
(
Session
session
)
throws
SQLException
{
if
(
createException
!=
null
)
{
String
msg
=
createException
.
getMessage
();
...
...
h2/src/main/org/h2/tools/ChangeFileEncryption.java
浏览文件 @
f076058c
...
...
@@ -25,8 +25,8 @@ import org.h2.util.Tool;
*/
public
class
ChangeFileEncryption
extends
Tool
{
private
String
dir
;
private
String
cipher
;
private
String
dir
ectory
;
private
String
cipher
Type
;
private
byte
[]
decrypt
;
private
byte
[]
encrypt
;
...
...
@@ -133,8 +133,8 @@ public class ChangeFileEncryption extends Tool {
}
}
change
.
out
=
out
;
change
.
dir
=
dir
;
change
.
cipher
=
cipher
;
change
.
dir
ectory
=
dir
;
change
.
cipher
Type
=
cipher
;
change
.
decrypt
=
getFileEncryptionKey
(
decryptPassword
);
change
.
encrypt
=
getFileEncryptionKey
(
encryptPassword
);
...
...
@@ -168,7 +168,7 @@ public class ChangeFileEncryption extends Tool {
if
(
decrypt
==
null
)
{
in
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
}
else
{
in
=
FileStore
.
open
(
null
,
fileName
,
"r"
,
cipher
,
decrypt
);
in
=
FileStore
.
open
(
null
,
fileName
,
"r"
,
cipher
Type
,
decrypt
);
}
in
.
init
();
copy
(
fileName
,
in
,
encrypt
);
...
...
@@ -178,13 +178,13 @@ public class ChangeFileEncryption extends Tool {
if
(
FileUtils
.
isDirectory
(
fileName
))
{
return
;
}
String
temp
=
dir
+
"/temp.db"
;
String
temp
=
dir
ectory
+
"/temp.db"
;
FileUtils
.
delete
(
temp
);
FileStore
fileOut
;
if
(
key
==
null
)
{
fileOut
=
FileStore
.
open
(
null
,
temp
,
"rw"
);
}
else
{
fileOut
=
FileStore
.
open
(
null
,
temp
,
"rw"
,
cipher
,
key
);
fileOut
=
FileStore
.
open
(
null
,
temp
,
"rw"
,
cipher
Type
,
key
);
}
fileOut
.
init
();
byte
[]
buffer
=
new
byte
[
4
*
1024
];
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
f076058c
...
...
@@ -201,18 +201,18 @@ public class Recover extends Tool implements DataHandler {
return
;
}
setDatabaseName
(
fileName
.
substring
(
fileName
.
length
()
-
Constants
.
SUFFIX_DATA_FILE
.
length
()));
FileStore
s
tore
=
FileStore
.
open
(
null
,
fileName
,
"rw"
);
long
length
=
s
tore
.
length
();
FileStore
fileS
tore
=
FileStore
.
open
(
null
,
fileName
,
"rw"
);
long
length
=
fileS
tore
.
length
();
int
offset
=
FileStore
.
HEADER_LENGTH
;
int
blockSize
=
DiskFile
.
BLOCK_SIZE
;
int
blocks
=
(
int
)
(
length
/
blockSize
);
blockCount
=
1
;
for
(
int
b
lock
=
0
;
block
<
blocks
;
block
+=
blockCount
)
{
store
.
seek
(
offset
+
(
long
)
block
*
blockSize
);
for
(
int
b
=
0
;
b
<
blocks
;
b
+=
blockCount
)
{
fileStore
.
seek
(
offset
+
(
long
)
b
*
blockSize
);
byte
[]
bytes
=
new
byte
[
blockSize
];
DataPage
s
=
DataPage
.
create
(
this
,
bytes
);
long
start
=
s
tore
.
getFilePointer
();
s
tore
.
readFully
(
bytes
,
0
,
blockSize
);
long
start
=
fileS
tore
.
getFilePointer
();
fileS
tore
.
readFully
(
bytes
,
0
,
blockSize
);
blockCount
=
s
.
readInt
();
setStorage
(-
1
);
recordLength
=
-
1
;
...
...
@@ -232,7 +232,7 @@ public class Recover extends Tool implements DataHandler {
continue
;
}
if
(
blockCount
>
1
)
{
s
tore
.
readFully
(
s
.
getBytes
(),
blockSize
,
blockCount
*
blockSize
-
blockSize
);
fileS
tore
.
readFully
(
s
.
getBytes
(),
blockSize
,
blockCount
*
blockSize
-
blockSize
);
}
try
{
s
.
check
(
blockCount
*
blockSize
);
...
...
@@ -297,8 +297,8 @@ public class Recover extends Tool implements DataHandler {
System
.
arraycopy
(
replacement
,
0
,
s
.
getBytes
(),
at
,
replacement
.
length
);
s
.
fill
(
blockCount
*
blockSize
);
s
.
updateChecksum
();
s
tore
.
seek
(
start
);
s
tore
.
write
(
s
.
getBytes
(),
0
,
s
.
length
());
fileS
tore
.
seek
(
start
);
fileS
tore
.
write
(
s
.
getBytes
(),
0
,
s
.
length
());
if
(
trace
)
{
out
.
println
(
"User: "
+
userName
);
}
...
...
@@ -308,7 +308,7 @@ public class Recover extends Tool implements DataHandler {
}
}
}
closeSilently
(
s
tore
);
closeSilently
(
fileS
tore
);
}
/**
...
...
@@ -377,15 +377,15 @@ public class Recover extends Tool implements DataHandler {
private
void
dumpLob
(
String
fileName
,
boolean
lobCompression
)
{
OutputStream
fileOut
=
null
;
FileStore
s
tore
=
null
;
FileStore
fileS
tore
=
null
;
int
size
=
0
;
String
n
=
fileName
+
(
lobCompression
?
".comp"
:
""
)
+
".txt"
;
InputStream
in
=
null
;
try
{
fileOut
=
FileUtils
.
openFileOutputStream
(
n
,
false
);
s
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
s
tore
.
init
();
in
=
new
BufferedInputStream
(
new
FileStoreInputStream
(
s
tore
,
this
,
lobCompression
,
false
));
fileS
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
fileS
tore
.
init
();
in
=
new
BufferedInputStream
(
new
FileStoreInputStream
(
fileS
tore
,
this
,
lobCompression
,
false
));
byte
[]
buffer
=
new
byte
[
Constants
.
IO_BUFFER_SIZE
];
while
(
true
)
{
int
l
=
in
.
read
(
buffer
);
...
...
@@ -402,7 +402,7 @@ public class Recover extends Tool implements DataHandler {
}
finally
{
IOUtils
.
closeSilently
(
fileOut
);
IOUtils
.
closeSilently
(
in
);
closeSilently
(
s
tore
);
closeSilently
(
fileS
tore
);
}
if
(
size
==
0
)
{
try
{
...
...
@@ -488,7 +488,7 @@ public class Recover extends Tool implements DataHandler {
private
void
dumpLog
(
String
fileName
,
boolean
onlySetSessionState
)
{
PrintWriter
writer
=
null
;
FileStore
s
tore
=
null
;
FileStore
fileS
tore
=
null
;
boolean
containsUncommitted
=
false
;
try
{
if
(
onlySetSessionState
)
{
...
...
@@ -498,8 +498,8 @@ public class Recover extends Tool implements DataHandler {
if
(!
onlySetSessionState
)
{
writer
=
getWriter
(
fileName
,
".txt"
);
}
s
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
long
length
=
s
tore
.
length
();
fileS
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
long
length
=
fileS
tore
.
length
();
if
(!
onlySetSessionState
)
{
writer
.
println
(
"// length: "
+
length
);
}
...
...
@@ -518,8 +518,8 @@ public class Recover extends Tool implements DataHandler {
}
return
;
}
s
tore
.
seek
(
offset
);
s
tore
.
readFully
(
s
.
getBytes
(),
0
,
len
);
fileS
tore
.
seek
(
offset
);
fileS
tore
.
readFully
(
s
.
getBytes
(),
0
,
len
);
int
id
=
s
.
readInt
();
int
firstUncommittedPos
=
s
.
readInt
();
int
firstUnwrittenPos
=
s
.
readInt
();
...
...
@@ -531,12 +531,12 @@ public class Recover extends Tool implements DataHandler {
writer
.
println
(
"// max: "
+
max
);
}
while
(
true
)
{
int
pos
=
(
int
)
(
s
tore
.
getFilePointer
()
/
blockSize
);
int
pos
=
(
int
)
(
fileS
tore
.
getFilePointer
()
/
blockSize
);
if
((
long
)
pos
*
blockSize
>=
length
)
{
break
;
}
buff
=
new
byte
[
blockSize
];
s
tore
.
readFully
(
buff
,
0
,
blockSize
);
fileS
tore
.
readFully
(
buff
,
0
,
blockSize
);
s
=
DataPage
.
create
(
this
,
buff
);
// Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE
blocks
=
MathUtils
.
convertLongToInt
(
Math
.
abs
(
s
.
readInt
()));
...
...
@@ -545,7 +545,7 @@ public class Recover extends Tool implements DataHandler {
System
.
arraycopy
(
buff
,
0
,
b2
,
0
,
blockSize
);
buff
=
b2
;
try
{
s
tore
.
readFully
(
buff
,
blockSize
,
blocks
*
blockSize
-
blockSize
);
fileS
tore
.
readFully
(
buff
,
blockSize
,
blocks
*
blockSize
-
blockSize
);
}
catch
(
SQLException
e
)
{
break
;
}
...
...
@@ -656,7 +656,7 @@ public class Recover extends Tool implements DataHandler {
writeError
(
writer
,
e
);
}
finally
{
IOUtils
.
closeSilently
(
writer
);
closeSilently
(
s
tore
);
closeSilently
(
fileS
tore
);
}
}
...
...
@@ -1554,25 +1554,25 @@ public class Recover extends Tool implements DataHandler {
private
void
dumpData
(
String
fileName
,
String
outputName
,
int
offset
)
{
PrintWriter
writer
=
null
;
FileStore
s
tore
=
null
;
FileStore
fileS
tore
=
null
;
try
{
writer
=
getWriter
(
outputName
,
".sql"
);
writer
.
println
(
"CREATE ALIAS IF NOT EXISTS READ_CLOB FOR \""
+
this
.
getClass
().
getName
()
+
".readClob\";"
);
writer
.
println
(
"CREATE ALIAS IF NOT EXISTS READ_BLOB FOR \""
+
this
.
getClass
().
getName
()
+
".readBlob\";"
);
resetSchema
();
s
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
long
length
=
s
tore
.
length
();
fileS
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
long
length
=
fileS
tore
.
length
();
int
blockSize
=
DiskFile
.
BLOCK_SIZE
;
int
blocks
=
(
int
)
(
length
/
blockSize
);
blockCount
=
1
;
int
pageCount
=
blocks
/
DiskFile
.
BLOCKS_PER_PAGE
;
int
[]
pageOwners
=
new
int
[
pageCount
+
1
];
for
(
block
=
0
;
block
<
blocks
;
block
+=
blockCount
)
{
s
tore
.
seek
(
offset
+
(
long
)
block
*
blockSize
);
fileS
tore
.
seek
(
offset
+
(
long
)
block
*
blockSize
);
byte
[]
buff
=
new
byte
[
blockSize
];
DataPage
s
=
DataPage
.
create
(
this
,
buff
);
try
{
s
tore
.
readFully
(
buff
,
0
,
blockSize
);
fileS
tore
.
readFully
(
buff
,
0
,
blockSize
);
}
catch
(
SQLException
e
)
{
writer
.
println
(
"-- ERROR: can not read: "
+
e
);
break
;
...
...
@@ -1609,11 +1609,11 @@ public class Recover extends Tool implements DataHandler {
continue
;
}
try
{
s
tore
.
readFully
(
s
.
getBytes
(),
blockSize
,
blockCount
*
blockSize
-
blockSize
);
fileS
tore
.
readFully
(
s
.
getBytes
(),
blockSize
,
blockCount
*
blockSize
-
blockSize
);
}
catch
(
Throwable
e
)
{
writeDataError
(
writer
,
"eof"
,
s
.
getBytes
(),
1
);
blockCount
=
1
;
s
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
fileS
tore
=
FileStore
.
open
(
null
,
fileName
,
"r"
);
continue
;
}
}
...
...
@@ -1648,7 +1648,7 @@ public class Recover extends Tool implements DataHandler {
writeError
(
writer
,
e
);
}
finally
{
IOUtils
.
closeSilently
(
writer
);
closeSilently
(
s
tore
);
closeSilently
(
fileS
tore
);
}
}
...
...
@@ -1730,9 +1730,9 @@ public class Recover extends Tool implements DataHandler {
}
private
void
closeSilently
(
FileStore
s
tore
)
{
if
(
s
tore
!=
null
)
{
s
tore
.
closeSilently
();
private
void
closeSilently
(
FileStore
fileS
tore
)
{
if
(
fileS
tore
!=
null
)
{
fileS
tore
.
closeSilently
();
}
}
...
...
h2/src/main/org/h2/tools/Restore.java
浏览文件 @
f076058c
...
...
@@ -174,13 +174,13 @@ public class Restore extends Tool {
copy
=
true
;
}
if
(
copy
)
{
OutputStream
o
ut
=
null
;
OutputStream
o
=
null
;
try
{
o
ut
=
FileUtils
.
openFileOutputStream
(
directory
+
File
.
separator
+
fileName
,
false
);
IOUtils
.
copy
(
zipIn
,
o
ut
);
o
ut
.
close
();
o
=
FileUtils
.
openFileOutputStream
(
directory
+
File
.
separator
+
fileName
,
false
);
IOUtils
.
copy
(
zipIn
,
o
);
o
.
close
();
}
finally
{
IOUtils
.
closeSilently
(
o
ut
);
IOUtils
.
closeSilently
(
o
);
}
}
zipIn
.
closeEntry
();
...
...
h2/src/main/org/h2/tools/Script.java
浏览文件 @
f076058c
...
...
@@ -150,12 +150,12 @@ public class Script extends Tool {
* @param fileName the script file
*/
void
process
(
String
url
,
String
user
,
String
password
,
String
fileName
)
throws
SQLException
{
OutputStream
o
ut
=
null
;
OutputStream
o
=
null
;
try
{
o
ut
=
FileUtils
.
openFileOutputStream
(
fileName
,
false
);
process
(
url
,
user
,
password
,
o
ut
);
o
=
FileUtils
.
openFileOutputStream
(
fileName
,
false
);
process
(
url
,
user
,
password
,
o
);
}
finally
{
IOUtils
.
closeSilently
(
o
ut
);
IOUtils
.
closeSilently
(
o
);
}
}
...
...
@@ -165,16 +165,16 @@ public class Script extends Tool {
* @param url the database URL
* @param user the user name
* @param password the password
* @param o
ut
the output stream
* @param o the output stream
*/
void
process
(
String
url
,
String
user
,
String
password
,
OutputStream
o
ut
)
throws
SQLException
{
void
process
(
String
url
,
String
user
,
String
password
,
OutputStream
o
)
throws
SQLException
{
Connection
conn
=
null
;
Statement
stat
=
null
;
try
{
org
.
h2
.
Driver
.
load
();
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
stat
=
conn
.
createStatement
();
PrintWriter
writer
=
new
PrintWriter
(
IOUtils
.
getWriter
(
o
ut
));
PrintWriter
writer
=
new
PrintWriter
(
IOUtils
.
getWriter
(
o
));
ResultSet
rs
=
stat
.
executeQuery
(
"SCRIPT"
);
while
(
rs
.
next
())
{
String
s
=
rs
.
getString
(
1
);
...
...
h2/src/main/org/h2/tools/Shell.java
浏览文件 @
f076058c
...
...
@@ -476,7 +476,7 @@ public class Shell extends Tool {
}
}
private
int
printResult
(
ResultSet
rs
,
boolean
listMode
)
throws
SQLException
{
private
int
printResult
(
ResultSet
rs
,
boolean
asList
)
throws
SQLException
{
ResultSetMetaData
meta
=
rs
.
getMetaData
();
int
longest
=
0
;
int
len
=
meta
.
getColumnCount
();
...
...
@@ -486,7 +486,7 @@ public class Shell extends Tool {
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
String
s
=
meta
.
getColumnLabel
(
i
+
1
);
int
l
=
s
.
length
();
if
(!
listMode
)
{
if
(!
asList
)
{
l
=
Math
.
max
(
l
,
meta
.
getColumnDisplaySize
(
i
+
1
));
l
=
Math
.
min
(
maxColumnSize
,
l
);
}
...
...
@@ -499,7 +499,7 @@ public class Shell extends Tool {
total
+=
l
;
}
StringBuilder
buff
=
new
StringBuilder
();
if
(!
listMode
)
{
if
(!
asList
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
boxVertical
);
...
...
@@ -519,7 +519,7 @@ public class Shell extends Tool {
while
(
rs
.
next
())
{
rowCount
++;
buff
.
setLength
(
0
);
if
(
listMode
)
{
if
(
asList
)
{
if
(
rowCount
>
1
)
{
println
(
""
);
}
...
...
@@ -545,7 +545,7 @@ public class Shell extends Tool {
}
int
m
=
columnSizes
[
i
];
// only truncate if more than once column
if
(
len
>
1
&&
!
listMode
&&
s
.
length
()
>
m
)
{
if
(
len
>
1
&&
!
asList
&&
s
.
length
()
>
m
)
{
s
=
s
.
substring
(
0
,
m
);
truncated
=
true
;
}
...
...
@@ -559,7 +559,7 @@ public class Shell extends Tool {
}
println
(
buff
.
toString
());
}
if
(
rowCount
==
0
&&
listMode
)
{
if
(
rowCount
==
0
&&
asList
)
{
for
(
String
label
:
columns
)
{
buff
.
append
(
label
).
append
(
'\n'
);
}
...
...
h2/src/main/org/h2/tools/SimpleResultSet.java
浏览文件 @
f076058c
...
...
@@ -1101,7 +1101,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
/**
* INTERNAL
*/
public
boolean
relative
(
int
rows
)
throws
SQLException
{
public
boolean
relative
(
int
offset
)
throws
SQLException
{
throw
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/util/CacheLRU.java
浏览文件 @
f076058c
...
...
@@ -75,7 +75,7 @@ public class CacheLRU implements Cache {
}
public
void
clear
()
{
head
.
next
=
head
.
p
revious
=
head
;
head
.
cacheNext
=
head
.
cacheP
revious
=
head
;
// first set to null - avoiding out of memory
values
=
null
;
values
=
new
CacheObject
[
len
];
...
...
@@ -94,7 +94,7 @@ public class CacheLRU implements Cache {
}
}
int
index
=
rec
.
getPos
()
&
mask
;
rec
.
chained
=
values
[
index
];
rec
.
c
acheC
hained
=
values
[
index
];
values
[
index
]
=
rec
;
recordCount
++;
sizeMemory
+=
rec
.
getMemorySize
();
...
...
@@ -131,10 +131,10 @@ public class CacheLRU implements Cache {
int
mem
=
sizeMemory
;
int
rc
=
recordCount
;
boolean
flushed
=
false
;
CacheObject
next
=
head
.
n
ext
;
CacheObject
next
=
head
.
cacheN
ext
;
while
(
mem
*
4
>
maxSize
*
3
&&
rc
>
Constants
.
CACHE_MIN_RECORDS
)
{
CacheObject
check
=
next
;
next
=
check
.
n
ext
;
next
=
check
.
cacheN
ext
;
i
++;
if
(
i
>=
recordCount
)
{
if
(!
flushed
)
{
...
...
@@ -185,7 +185,7 @@ public class CacheLRU implements Cache {
CacheObject
rec
=
changed
.
get
(
i
);
remove
(
rec
.
getPos
());
if
(
SysProperties
.
CHECK
)
{
if
(
rec
.
n
ext
!=
null
)
{
if
(
rec
.
cacheN
ext
!=
null
)
{
throw
Message
.
throwInternalError
();
}
}
...
...
@@ -197,22 +197,22 @@ public class CacheLRU implements Cache {
if
(
SysProperties
.
CHECK
&&
rec
==
head
)
{
Message
.
throwInternalError
(
"try to move head"
);
}
rec
.
n
ext
=
head
;
rec
.
previous
=
head
.
p
revious
;
rec
.
previous
.
n
ext
=
rec
;
head
.
p
revious
=
rec
;
rec
.
cacheN
ext
=
head
;
rec
.
cachePrevious
=
head
.
cacheP
revious
;
rec
.
cachePrevious
.
cacheN
ext
=
rec
;
head
.
cacheP
revious
=
rec
;
}
private
void
removeFromLinkedList
(
CacheObject
rec
)
{
if
(
SysProperties
.
CHECK
&&
rec
==
head
)
{
Message
.
throwInternalError
(
"try to remove head"
);
}
rec
.
previous
.
next
=
rec
.
n
ext
;
rec
.
next
.
previous
=
rec
.
p
revious
;
rec
.
cachePrevious
.
cacheNext
=
rec
.
cacheN
ext
;
rec
.
cacheNext
.
cachePrevious
=
rec
.
cacheP
revious
;
// TODO cache: mystery: why is this required? needs more memory if we
// don't do this
rec
.
n
ext
=
null
;
rec
.
p
revious
=
null
;
rec
.
cacheN
ext
=
null
;
rec
.
cacheP
revious
=
null
;
}
public
void
remove
(
int
pos
)
{
...
...
@@ -222,23 +222,23 @@ public class CacheLRU implements Cache {
return
;
}
if
(
rec
.
getPos
()
==
pos
)
{
values
[
index
]
=
rec
.
chained
;
values
[
index
]
=
rec
.
c
acheC
hained
;
}
else
{
CacheObject
last
;
do
{
last
=
rec
;
rec
=
rec
.
chained
;
rec
=
rec
.
c
acheC
hained
;
if
(
rec
==
null
)
{
return
;
}
}
while
(
rec
.
getPos
()
!=
pos
);
last
.
c
hained
=
rec
.
c
hained
;
last
.
c
acheChained
=
rec
.
cacheC
hained
;
}
recordCount
--;
sizeMemory
-=
rec
.
getMemorySize
();
removeFromLinkedList
(
rec
);
if
(
SysProperties
.
CHECK
)
{
rec
.
chained
=
null
;
rec
.
c
acheC
hained
=
null
;
CacheObject
o
=
find
(
pos
);
if
(
o
!=
null
)
{
Message
.
throwInternalError
(
"not removed: "
+
o
);
...
...
@@ -249,7 +249,7 @@ public class CacheLRU implements Cache {
public
CacheObject
find
(
int
pos
)
{
CacheObject
rec
=
values
[
pos
&
mask
];
while
(
rec
!=
null
&&
rec
.
getPos
()
!=
pos
)
{
rec
=
rec
.
chained
;
rec
=
rec
.
c
acheC
hained
;
}
return
rec
;
}
...
...
@@ -297,12 +297,12 @@ public class CacheLRU implements Cache {
// testConsistency();
// }
ObjectArray
<
CacheObject
>
list
=
ObjectArray
.
newInstance
();
CacheObject
rec
=
head
.
n
ext
;
CacheObject
rec
=
head
.
cacheN
ext
;
while
(
rec
!=
head
)
{
if
(
rec
.
isChanged
())
{
list
.
add
(
rec
);
}
rec
=
rec
.
n
ext
;
rec
=
rec
.
cacheN
ext
;
}
return
list
;
}
...
...
h2/src/main/org/h2/util/CacheObject.java
浏览文件 @
f076058c
...
...
@@ -39,18 +39,18 @@ public abstract class CacheObject {
* The previous element in the LRU linked list. If the previous element is
* the head, then this element is the most recently used object.
*/
public
CacheObject
p
revious
;
public
CacheObject
cacheP
revious
;
/**
* The next element in the LRU linked list. If the next element is the head,
* then this element is the least recently used object.
*/
public
CacheObject
n
ext
;
public
CacheObject
cacheN
ext
;
/**
* The next element in the hash chain.
*/
public
CacheObject
chained
;
public
CacheObject
c
acheC
hained
;
/**
* The cache queue identifier. This field is only used for the 2Q cache
...
...
@@ -92,7 +92,7 @@ public abstract class CacheObject {
}
public
void
setPos
(
int
pos
)
{
if
(
SysProperties
.
CHECK
&&
(
previous
!=
null
||
next
!=
null
||
c
hained
!=
null
))
{
if
(
SysProperties
.
CHECK
&&
(
cachePrevious
!=
null
||
cacheNext
!=
null
||
cacheC
hained
!=
null
))
{
Message
.
throwInternalError
(
"setPos too late"
);
}
this
.
pos
=
pos
;
...
...
h2/src/main/org/h2/util/NetUtils.java
浏览文件 @
f076058c
...
...
@@ -27,7 +27,7 @@ import org.h2.security.SecureSocketFactory;
public
class
NetUtils
{
private
static
final
int
CACHE_MILLIS
=
1000
;
private
static
InetAddress
b
indAddress
;
private
static
InetAddress
cachedB
indAddress
;
private
static
String
cachedLocalAddress
;
private
static
long
cachedLocalAddressTime
;
...
...
@@ -140,11 +140,11 @@ public class NetUtils {
return
null
;
}
synchronized
(
NetUtils
.
class
)
{
if
(
b
indAddress
==
null
)
{
b
indAddress
=
InetAddress
.
getByName
(
host
);
if
(
cachedB
indAddress
==
null
)
{
cachedB
indAddress
=
InetAddress
.
getByName
(
host
);
}
}
return
b
indAddress
;
return
cachedB
indAddress
;
}
private
static
ServerSocket
createServerSocketTry
(
int
port
,
boolean
ssl
)
throws
SQLException
{
...
...
h2/src/main/org/h2/util/SourceCompiler.java
浏览文件 @
f076058c
...
...
@@ -66,20 +66,20 @@ public class SourceCompiler {
/**
* Get the class object for the given name.
*
* @param
n
ame the class name
* @param
packageAndClassN
ame the class name
* @return the class
*/
private
Class
<
?
>
getClass
(
String
n
ame
)
throws
ClassNotFoundException
{
private
Class
<
?
>
getClass
(
String
packageAndClassN
ame
)
throws
ClassNotFoundException
{
Class
<
?
>
c
lazz
=
compiled
.
get
(
n
ame
);
if
(
c
lazz
!=
null
)
{
return
c
lazz
;
Class
<
?
>
c
ompiledClass
=
compiled
.
get
(
packageAndClassN
ame
);
if
(
c
ompiledClass
!=
null
)
{
return
c
ompiledClass
;
}
ClassLoader
classLoader
=
new
ClassLoader
(
getClass
().
getClassLoader
())
{
public
Class
<
?
>
findClass
(
String
name
)
throws
ClassNotFoundException
{
Class
<
?
>
cla
zz
=
compiled
.
get
(
name
);
if
(
cla
zz
==
null
)
{
Class
<
?
>
cla
ssInstance
=
compiled
.
get
(
name
);
if
(
cla
ssInstance
==
null
)
{
String
source
=
sources
.
get
(
name
);
String
packageName
=
null
;
int
idx
=
name
.
lastIndexOf
(
'.'
);
...
...
@@ -92,16 +92,16 @@ public class SourceCompiler {
}
byte
[]
data
=
javacCompile
(
packageName
,
className
,
source
);
if
(
data
==
null
)
{
cla
zz
=
findSystemClass
(
name
);
cla
ssInstance
=
findSystemClass
(
name
);
}
else
{
cla
zz
=
defineClass
(
name
,
data
,
0
,
data
.
length
);
compiled
.
put
(
name
,
cla
zz
);
cla
ssInstance
=
defineClass
(
name
,
data
,
0
,
data
.
length
);
compiled
.
put
(
name
,
cla
ssInstance
);
}
}
return
cla
zz
;
return
cla
ssInstance
;
}
};
return
classLoader
.
loadClass
(
n
ame
);
return
classLoader
.
loadClass
(
packageAndClassN
ame
);
}
/**
...
...
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
f076058c
...
...
@@ -12,7 +12,6 @@ import java.io.BufferedWriter;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.Reader
;
import
java.io.Writer
;
...
...
@@ -25,7 +24,6 @@ import java.sql.ResultSetMetaData;
import
java.sql.SQLException
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.SessionInterface
;
...
...
@@ -364,8 +362,7 @@ public class Transfer {
throw
Message
.
getSQLException
(
ErrorCode
.
CONNECTION_BROKEN_1
,
"length="
+
length
);
}
writeLong
(
length
);
InputStream
in
=
v
.
getInputStream
();
long
written
=
IOUtils
.
copyAndCloseInput
(
in
,
out
);
long
written
=
IOUtils
.
copyAndCloseInput
(
v
.
getInputStream
(),
out
);
if
(
written
!=
length
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
CONNECTION_BROKEN_1
,
"length:"
+
length
+
" written:"
+
written
);
}
...
...
@@ -564,9 +561,9 @@ public class Transfer {
public
Transfer
openNewConnection
()
throws
IOException
{
InetAddress
address
=
socket
.
getInetAddress
();
int
port
=
socket
.
getPort
();
Socket
s
ocket
=
NetUtils
.
createSocket
(
address
,
port
,
ssl
);
Socket
s
2
=
NetUtils
.
createSocket
(
address
,
port
,
ssl
);
Transfer
trans
=
new
Transfer
(
null
);
trans
.
setSocket
(
s
ocket
);
trans
.
setSocket
(
s
2
);
trans
.
setSSL
(
ssl
);
return
trans
;
}
...
...
h2/src/main/org/h2/value/ValueByte.java
浏览文件 @
f076058c
...
...
@@ -43,11 +43,11 @@ public class ValueByte extends Value {
return
ValueByte
.
get
((
byte
)
(
value
+
other
.
value
));
}
private
ValueByte
checkRange
(
int
value
)
throws
SQLException
{
if
(
value
<
Byte
.
MIN_VALUE
||
value
>
Byte
.
MAX_VALUE
)
{
private
ValueByte
checkRange
(
int
x
)
throws
SQLException
{
if
(
x
<
Byte
.
MIN_VALUE
||
x
>
Byte
.
MAX_VALUE
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
OVERFLOW_FOR_TYPE_1
,
DataType
.
getDataType
(
Value
.
BYTE
).
name
);
}
return
ValueByte
.
get
((
byte
)
value
);
return
ValueByte
.
get
((
byte
)
x
);
}
public
int
getSignum
()
{
...
...
h2/src/main/org/h2/value/ValueDecimal.java
浏览文件 @
f076058c
...
...
@@ -140,11 +140,11 @@ public class ValueDecimal extends Value {
return
precision
;
}
public
boolean
checkPrecision
(
long
prec
ision
)
{
if
(
prec
ision
==
DEFAULT_PRECISION
)
{
public
boolean
checkPrecision
(
long
prec
)
{
if
(
prec
==
DEFAULT_PRECISION
)
{
return
true
;
}
return
getPrecision
()
<=
prec
ision
;
return
getPrecision
()
<=
prec
;
}
public
int
getScale
()
{
...
...
@@ -176,11 +176,11 @@ public class ValueDecimal extends Value {
return
ValueDecimal
.
get
(
bd
);
}
public
Value
convertPrecision
(
long
p
recision
)
throws
SQLException
{
if
(
getPrecision
()
<=
p
recision
)
{
public
Value
convertPrecision
(
long
newP
recision
)
throws
SQLException
{
if
(
getPrecision
()
<=
newP
recision
)
{
return
this
;
}
throw
Message
.
getSQLException
(
ErrorCode
.
VALUE_TOO_LARGE_FOR_PRECISION_1
,
""
+
p
recision
);
throw
Message
.
getSQLException
(
ErrorCode
.
VALUE_TOO_LARGE_FOR_PRECISION_1
,
""
+
newP
recision
);
}
/**
...
...
h2/src/main/org/h2/value/ValueInt.java
浏览文件 @
f076058c
...
...
@@ -73,11 +73,11 @@ public class ValueInt extends Value {
return
ValueInt
.
get
(
value
+
other
.
value
);
}
private
ValueInt
checkRange
(
long
value
)
throws
SQLException
{
if
(
value
<
Integer
.
MIN_VALUE
||
value
>
Integer
.
MAX_VALUE
)
{
private
ValueInt
checkRange
(
long
x
)
throws
SQLException
{
if
(
x
<
Integer
.
MIN_VALUE
||
x
>
Integer
.
MAX_VALUE
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
OVERFLOW_FOR_TYPE_1
,
DataType
.
getDataType
(
Value
.
INT
).
name
);
}
return
ValueInt
.
get
((
int
)
value
);
return
ValueInt
.
get
((
int
)
x
);
}
public
int
getSignum
()
{
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
f076058c
...
...
@@ -205,10 +205,10 @@ public class ValueLob extends Value {
return
(
int
)
m
;
}
private
void
createFromReader
(
char
[]
buff
,
int
len
,
Reader
in
,
long
remaining
,
DataHandler
h
andler
)
throws
SQLException
{
private
void
createFromReader
(
char
[]
buff
,
int
len
,
Reader
in
,
long
remaining
,
DataHandler
h
)
throws
SQLException
{
try
{
FileStoreOutputStream
out
=
initLarge
(
h
andler
);
boolean
compress
=
h
andler
.
getLobCompressionAlgorithm
(
Value
.
CLOB
)
!=
null
;
FileStoreOutputStream
out
=
initLarge
(
h
);
boolean
compress
=
h
.
getLobCompressionAlgorithm
(
Value
.
CLOB
)
!=
null
;
try
{
while
(
true
)
{
precision
+=
len
;
...
...
@@ -218,7 +218,7 @@ public class ValueLob extends Value {
if
(
remaining
<=
0
)
{
break
;
}
len
=
getBufferSize
(
h
andler
,
compress
,
remaining
);
len
=
getBufferSize
(
h
,
compress
,
remaining
);
len
=
IOUtils
.
readFully
(
in
,
buff
,
len
);
if
(
len
<=
0
)
{
break
;
...
...
@@ -250,13 +250,13 @@ public class ValueLob extends Value {
return
name
;
}
private
int
getNewObjectId
(
DataHandler
h
andler
)
throws
SQLException
{
String
path
=
h
andler
.
getDatabasePath
();
int
object
Id
=
0
;
private
int
getNewObjectId
(
DataHandler
h
)
throws
SQLException
{
String
path
=
h
.
getDatabasePath
();
int
new
Id
=
0
;
int
lobsPerDir
=
SysProperties
.
LOB_FILES_PER_DIRECTORY
;
while
(
true
)
{
String
dir
=
getFileNamePrefix
(
path
,
object
Id
);
String
[]
list
=
getFileList
(
h
andler
,
dir
);
String
dir
=
getFileNamePrefix
(
path
,
new
Id
);
String
[]
list
=
getFileList
(
h
,
dir
);
int
fileCount
=
0
;
boolean
[]
used
=
new
boolean
[
lobsPerDir
];
for
(
String
name
:
list
)
{
...
...
@@ -285,13 +285,13 @@ public class ValueLob extends Value {
}
}
if
(
fileId
>
0
)
{
object
Id
+=
fileId
;
invalidateFileList
(
h
andler
,
dir
);
new
Id
+=
fileId
;
invalidateFileList
(
h
,
dir
);
break
;
}
if
(
object
Id
>
Integer
.
MAX_VALUE
/
lobsPerDir
)
{
if
(
new
Id
>
Integer
.
MAX_VALUE
/
lobsPerDir
)
{
// this directory path is full: start from zero
object
Id
=
0
;
new
Id
=
0
;
dirCounter
=
RandomUtils
.
nextInt
(
lobsPerDir
-
1
)
*
lobsPerDir
;
}
else
{
// calculate the directory
...
...
@@ -300,11 +300,11 @@ public class ValueLob extends Value {
// (but that would generate more directories):
// int dirId = RandomUtils.nextInt(lobsPerDir - 1) + 1;
int
dirId
=
(
dirCounter
++
/
(
lobsPerDir
-
1
))
+
1
;
objectId
=
object
Id
*
lobsPerDir
;
object
Id
+=
dirId
*
lobsPerDir
;
newId
=
new
Id
*
lobsPerDir
;
new
Id
+=
dirId
*
lobsPerDir
;
}
}
return
object
Id
;
return
new
Id
;
}
/**
...
...
@@ -315,8 +315,8 @@ public class ValueLob extends Value {
dirCounter
=
0
;
}
private
void
invalidateFileList
(
DataHandler
h
andler
,
String
dir
)
{
SmallLRUCache
<
String
,
String
[]>
cache
=
h
andler
.
getLobFileListCache
();
private
void
invalidateFileList
(
DataHandler
h
,
String
dir
)
{
SmallLRUCache
<
String
,
String
[]>
cache
=
h
.
getLobFileListCache
();
if
(
cache
!=
null
)
{
synchronized
(
cache
)
{
cache
.
remove
(
dir
);
...
...
@@ -324,8 +324,8 @@ public class ValueLob extends Value {
}
}
private
String
[]
getFileList
(
DataHandler
h
andler
,
String
dir
)
throws
SQLException
{
SmallLRUCache
<
String
,
String
[]>
cache
=
h
andler
.
getLobFileListCache
();
private
String
[]
getFileList
(
DataHandler
h
,
String
dir
)
throws
SQLException
{
SmallLRUCache
<
String
,
String
[]>
cache
=
h
.
getLobFileListCache
();
String
[]
list
;
if
(
cache
==
null
)
{
list
=
FileUtils
.
listFiles
(
dir
);
...
...
@@ -378,35 +378,35 @@ public class ValueLob extends Value {
}
}
private
FileStoreOutputStream
initLarge
(
DataHandler
h
andler
)
throws
SQLException
{
this
.
handler
=
h
andler
;
private
FileStoreOutputStream
initLarge
(
DataHandler
h
)
throws
SQLException
{
this
.
handler
=
h
;
this
.
tableId
=
0
;
this
.
linked
=
false
;
this
.
precision
=
0
;
this
.
small
=
null
;
this
.
hash
=
0
;
String
compressionAlgorithm
=
h
andler
.
getLobCompressionAlgorithm
(
type
);
String
compressionAlgorithm
=
h
.
getLobCompressionAlgorithm
(
type
);
this
.
compression
=
compressionAlgorithm
!=
null
;
synchronized
(
h
andler
)
{
if
(
h
andler
.
getLobFilesInDirectories
())
{
objectId
=
getNewObjectId
(
h
andler
);
fileName
=
getFileNamePrefix
(
h
andler
.
getDatabasePath
(),
objectId
)
+
Constants
.
SUFFIX_TEMP_FILE
;
synchronized
(
h
)
{
if
(
h
.
getLobFilesInDirectories
())
{
objectId
=
getNewObjectId
(
h
);
fileName
=
getFileNamePrefix
(
h
.
getDatabasePath
(),
objectId
)
+
Constants
.
SUFFIX_TEMP_FILE
;
}
else
{
objectId
=
h
andler
.
allocateObjectId
(
false
,
true
);
fileName
=
h
andler
.
createTempFile
();
objectId
=
h
.
allocateObjectId
(
false
,
true
);
fileName
=
h
.
createTempFile
();
}
tempFile
=
h
andler
.
openFile
(
fileName
,
"rw"
,
false
);
tempFile
=
h
.
openFile
(
fileName
,
"rw"
,
false
);
tempFile
.
autoDelete
();
}
FileStoreOutputStream
out
=
new
FileStoreOutputStream
(
tempFile
,
h
andler
,
compressionAlgorithm
);
FileStoreOutputStream
out
=
new
FileStoreOutputStream
(
tempFile
,
h
,
compressionAlgorithm
);
return
out
;
}
private
void
createFromStream
(
byte
[]
buff
,
int
len
,
InputStream
in
,
long
remaining
,
DataHandler
h
andler
)
private
void
createFromStream
(
byte
[]
buff
,
int
len
,
InputStream
in
,
long
remaining
,
DataHandler
h
)
throws
SQLException
{
try
{
FileStoreOutputStream
out
=
initLarge
(
h
andler
);
boolean
compress
=
h
andler
.
getLobCompressionAlgorithm
(
Value
.
BLOB
)
!=
null
;
FileStoreOutputStream
out
=
initLarge
(
h
);
boolean
compress
=
h
.
getLobCompressionAlgorithm
(
Value
.
BLOB
)
!=
null
;
try
{
while
(
true
)
{
precision
+=
len
;
...
...
@@ -415,7 +415,7 @@ public class ValueLob extends Value {
if
(
remaining
<=
0
)
{
break
;
}
len
=
getBufferSize
(
h
andler
,
compress
,
remaining
);
len
=
getBufferSize
(
h
,
compress
,
remaining
);
len
=
IOUtils
.
readFully
(
in
,
buff
,
0
,
len
);
if
(
len
<=
0
)
{
break
;
...
...
@@ -494,33 +494,33 @@ public class ValueLob extends Value {
}
}
public
Value
link
(
DataHandler
h
andler
,
int
tabId
)
throws
SQLException
{
public
Value
link
(
DataHandler
h
,
int
tabId
)
throws
SQLException
{
if
(
fileName
==
null
)
{
this
.
tableId
=
tabId
;
return
this
;
}
if
(
linked
)
{
ValueLob
copy
=
ValueLob
.
copy
(
this
);
if
(
h
andler
.
getLobFilesInDirectories
())
{
copy
.
objectId
=
getNewObjectId
(
h
andler
);
if
(
h
.
getLobFilesInDirectories
())
{
copy
.
objectId
=
getNewObjectId
(
h
);
}
else
{
copy
.
objectId
=
h
andler
.
allocateObjectId
(
false
,
true
);
copy
.
objectId
=
h
.
allocateObjectId
(
false
,
true
);
}
copy
.
tableId
=
tabId
;
String
live
=
getFileName
(
h
andler
,
copy
.
tableId
,
copy
.
objectId
);
copyFile
(
handler
,
fileName
,
live
);
String
live
=
getFileName
(
h
,
copy
.
tableId
,
copy
.
objectId
);
copyFile
To
(
h
,
fileName
,
live
);
copy
.
fileName
=
live
;
copy
.
linked
=
true
;
return
copy
;
}
if
(!
linked
)
{
this
.
tableId
=
tabId
;
String
live
=
getFileName
(
h
andler
,
tableId
,
objectId
);
String
live
=
getFileName
(
h
,
tableId
,
objectId
);
if
(
tempFile
!=
null
)
{
tempFile
.
stopAutoDelete
();
tempFile
=
null
;
}
renameFile
(
h
andler
,
fileName
,
live
);
renameFile
(
h
,
fileName
,
live
);
fileName
=
live
;
linked
=
true
;
}
...
...
@@ -723,19 +723,19 @@ public class ValueLob extends Value {
* Store the lob data to a file if the size of the buffer it larger than the
* maximum size for an in-place lob.
*
* @param h
andler
the data handler
* @param h the data handler
*/
public
void
convertToFileIfRequired
(
DataHandler
h
andler
)
throws
SQLException
{
if
(
Constants
.
AUTO_CONVERT_LOB_TO_FILES
&&
small
!=
null
&&
small
.
length
>
h
andler
.
getMaxLengthInplaceLob
())
{
boolean
compress
=
h
andler
.
getLobCompressionAlgorithm
(
type
)
!=
null
;
int
len
=
getBufferSize
(
h
andler
,
compress
,
Long
.
MAX_VALUE
);
public
void
convertToFileIfRequired
(
DataHandler
h
)
throws
SQLException
{
if
(
Constants
.
AUTO_CONVERT_LOB_TO_FILES
&&
small
!=
null
&&
small
.
length
>
h
.
getMaxLengthInplaceLob
())
{
boolean
compress
=
h
.
getLobCompressionAlgorithm
(
type
)
!=
null
;
int
len
=
getBufferSize
(
h
,
compress
,
Long
.
MAX_VALUE
);
int
tabId
=
tableId
;
if
(
type
==
Value
.
BLOB
)
{
createFromStream
(
MemoryUtils
.
newBytes
(
len
),
0
,
getInputStream
(),
Long
.
MAX_VALUE
,
h
andler
);
createFromStream
(
MemoryUtils
.
newBytes
(
len
),
0
,
getInputStream
(),
Long
.
MAX_VALUE
,
h
);
}
else
{
createFromReader
(
new
char
[
len
],
0
,
getReader
(),
Long
.
MAX_VALUE
,
h
andler
);
createFromReader
(
new
char
[
len
],
0
,
getReader
(),
Long
.
MAX_VALUE
,
h
);
}
Value
v2
=
link
(
h
andler
,
tabId
);
Value
v2
=
link
(
h
,
tabId
);
if
(
SysProperties
.
CHECK
&&
v2
!=
this
)
{
Message
.
throwInternalError
();
}
...
...
@@ -821,9 +821,9 @@ public class ValueLob extends Value {
}
}
private
void
copyFile
(
DataHandler
handler
,
String
fileName
,
String
liv
e
)
throws
SQLException
{
synchronized
(
h
andler
.
getLobSyncObject
())
{
FileSystem
.
getInstance
(
fileName
).
copy
(
fileName
,
liv
e
);
private
void
copyFile
To
(
DataHandler
h
,
String
sourceFileName
,
String
targetFileNam
e
)
throws
SQLException
{
synchronized
(
h
.
getLobSyncObject
())
{
FileSystem
.
getInstance
(
sourceFileName
).
copy
(
sourceFileName
,
targetFileNam
e
);
}
}
...
...
h2/src/main/org/h2/value/ValueShort.java
浏览文件 @
f076058c
...
...
@@ -43,11 +43,11 @@ public class ValueShort extends Value {
return
ValueShort
.
get
((
short
)
(
value
+
other
.
value
));
}
private
ValueShort
checkRange
(
int
value
)
throws
SQLException
{
if
(
value
<
Short
.
MIN_VALUE
||
value
>
Short
.
MAX_VALUE
)
{
private
ValueShort
checkRange
(
int
x
)
throws
SQLException
{
if
(
x
<
Short
.
MIN_VALUE
||
x
>
Short
.
MAX_VALUE
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
OVERFLOW_FOR_TYPE_1
,
DataType
.
getDataType
(
Value
.
SHORT
).
name
);
}
return
ValueShort
.
get
((
short
)
value
);
return
ValueShort
.
get
((
short
)
x
);
}
public
int
getSignum
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论