Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
75e1a835
提交
75e1a835
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused code.
上级
96cf5428
无相关合并请求
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
81 个修改的文件
包含
461 行增加
和
1498 行删除
+461
-1498
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
roadmap.html
h2/src/docsrc/html/roadmap.html
+1
-0
CommandRemote.java
h2/src/main/org/h2/command/CommandRemote.java
+1
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
Prepared.java
h2/src/main/org/h2/command/Prepared.java
+6
-7
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+2
-2
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+1
-1
CreateIndex.java
h2/src/main/org/h2/command/ddl/CreateIndex.java
+1
-1
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+1
-1
CreateTableData.java
h2/src/main/org/h2/command/ddl/CreateTableData.java
+2
-2
Optimizer.java
h2/src/main/org/h2/command/dml/Optimizer.java
+4
-6
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-2
SysProperties.java
h2/src/main/org/h2/constant/SysProperties.java
+0
-6
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+1
-1
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+1
-1
Constants.java
h2/src/main/org/h2/engine/Constants.java
+2
-39
Database.java
h2/src/main/org/h2/engine/Database.java
+9
-12
DbObject.java
h2/src/main/org/h2/engine/DbObject.java
+0
-6
DbObjectBase.java
h2/src/main/org/h2/engine/DbObjectBase.java
+0
-4
MetaRecord.java
h2/src/main/org/h2/engine/MetaRecord.java
+2
-5
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+6
-12
Function.java
h2/src/main/org/h2/expression/Function.java
+3
-4
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+4
-0
Index.java
h2/src/main/org/h2/index/Index.java
+10
-5
MultiVersionIndex.java
h2/src/main/org/h2/index/MultiVersionIndex.java
+4
-4
PageBtreeIndex.java
h2/src/main/org/h2/index/PageBtreeIndex.java
+3
-3
PageDataIndex.java
h2/src/main/org/h2/index/PageDataIndex.java
+3
-4
PageDelegateIndex.java
h2/src/main/org/h2/index/PageDelegateIndex.java
+2
-2
PageIndex.java
h2/src/main/org/h2/index/PageIndex.java
+0
-4
RowIndex.java
h2/src/main/org/h2/index/RowIndex.java
+0
-28
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+1
-1
JdbcConnection.java
h2/src/main/org/h2/jdbc/JdbcConnection.java
+2
-2
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+4
-4
UndoLogRecord.java
h2/src/main/org/h2/log/UndoLogRecord.java
+0
-2
ResultDiskBuffer.java
h2/src/main/org/h2/result/ResultDiskBuffer.java
+0
-2
ResultTempTable.java
h2/src/main/org/h2/result/ResultTempTable.java
+2
-2
Row.java
h2/src/main/org/h2/result/Row.java
+2
-3
RowList.java
h2/src/main/org/h2/result/RowList.java
+1
-5
TcpServerThread.java
h2/src/main/org/h2/server/TcpServerThread.java
+4
-10
Data.java
h2/src/main/org/h2/store/Data.java
+55
-2
DiskFile.java
h2/src/main/org/h2/store/DiskFile.java
+0
-31
FileLister.java
h2/src/main/org/h2/store/FileLister.java
+1
-9
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+2
-2
FileStoreInputStream.java
h2/src/main/org/h2/store/FileStoreInputStream.java
+1
-1
FileStoreOutputStream.java
h2/src/main/org/h2/store/FileStoreOutputStream.java
+2
-2
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+10
-14
FunctionTable.java
h2/src/main/org/h2/table/FunctionTable.java
+1
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+1
-2
Plan.java
h2/src/main/org/h2/table/Plan.java
+1
-3
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+1
-1
Table.java
h2/src/main/org/h2/table/Table.java
+2
-2
TableData.java
h2/src/main/org/h2/table/TableData.java
+5
-10
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+1
-1
TableLinkConnection.java
h2/src/main/org/h2/table/TableLinkConnection.java
+5
-5
TableView.java
h2/src/main/org/h2/table/TableView.java
+1
-1
Backup.java
h2/src/main/org/h2/tools/Backup.java
+0
-3
Recover.java
h2/src/main/org/h2/tools/Recover.java
+18
-749
Shell.java
h2/src/main/org/h2/tools/Shell.java
+1
-2
ByteUtils.java
h2/src/main/org/h2/util/ByteUtils.java
+49
-0
DateTimeIso8601Utils.java
h2/src/main/org/h2/util/DateTimeIso8601Utils.java
+0
-80
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+65
-0
JdbcDriverUtils.java
h2/src/main/org/h2/util/JdbcDriverUtils.java
+0
-78
JdbcUtils.java
h2/src/main/org/h2/util/JdbcUtils.java
+61
-1
ObjectArray.java
h2/src/main/org/h2/util/ObjectArray.java
+1
-1
ObjectUtils.java
h2/src/main/org/h2/util/ObjectUtils.java
+0
-99
SmallMap.java
h2/src/main/org/h2/util/SmallMap.java
+1
-0
DataType.java
h2/src/main/org/h2/value/DataType.java
+3
-3
ValueByte.java
h2/src/main/org/h2/value/ValueByte.java
+4
-17
ValueInt.java
h2/src/main/org/h2/value/ValueInt.java
+4
-17
ValueJavaObject.java
h2/src/main/org/h2/value/ValueJavaObject.java
+2
-2
ValueLong.java
h2/src/main/org/h2/value/ValueLong.java
+40
-52
ValueShort.java
h2/src/main/org/h2/value/ValueShort.java
+4
-17
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+11
-8
Db.java
h2/src/test/org/h2/test/db/Db.java
+2
-2
TestLob.java
h2/src/test/org/h2/test/db/TestLob.java
+2
-2
TestReadOnly.java
h2/src/test/org/h2/test/db/TestReadOnly.java
+0
-18
TestDataPage.java
h2/src/test/org/h2/test/unit/TestDataPage.java
+2
-2
TestDateIso8601.java
h2/src/test/org/h2/test/unit/TestDateIso8601.java
+4
-4
TestOverflow.java
h2/src/test/org/h2/test/unit/TestOverflow.java
+1
-3
TestPageStore.java
h2/src/test/org/h2/test/unit/TestPageStore.java
+0
-49
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+8
-7
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
75e1a835
...
...
@@ -20,6 +20,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The database URL option ACCESS_MODE_LOG is no longer supported.
</li><li>
The database URL option RECOVER has currently no effect.
</li><li>
Converting an old (non-page store) database is no longer supported using this version.
</li><li>
The system property "h2.overflowExceptions" is no longer supported.
</li><li>
The system property "h2.optimizeDropDependencies" is no longer supported.
</li><li>
The system property "h2.optimizeGroupSorted" is no longer supported.
</li><li>
The system property "h2.optimizeMinMax" is no longer supported.
...
...
This diff is collapsed.
Click to expand it.
h2/src/docsrc/html/roadmap.html
浏览文件 @
75e1a835
...
...
@@ -477,6 +477,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>
Delay creating the information schema, and share metadata columns.
</li><li>
TCP Server: use a nonce (number used once) to protect unencrypted channels against replay attacks.
</li><li>
Simplify running scripts and recovery: CREATE FORCE USER (overwrites an existing user).
</li><li>
Support CREATE DATABASE LINK (a custom JDBC driver is already supported).
</li></ul>
<h2>
Not Planned
</h2>
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/CommandRemote.java
浏览文件 @
75e1a835
...
...
@@ -56,7 +56,7 @@ public class CommandRemote implements CommandInterface {
private
void
prepare
(
SessionRemote
s
,
boolean
createParams
)
throws
SQLException
{
id
=
s
.
getNextId
();
paramCount
=
0
;
boolean
readParams
=
s
.
getClientVersion
()
>=
Constants
.
TCP_PROTOCOL_VERSION
_6
;
boolean
readParams
=
s
.
getClientVersion
()
>=
Constants
.
TCP_PROTOCOL_VERSION
;
for
(
int
i
=
0
,
count
=
0
;
i
<
transferList
.
size
();
i
++)
{
try
{
Transfer
transfer
=
transferList
.
get
(
i
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
75e1a835
...
...
@@ -3869,7 +3869,7 @@ public class Parser {
data
.
temporary
=
true
;
data
.
persistData
=
true
;
data
.
persistIndexes
=
false
;
data
.
headPos
=
Index
.
EMPTY_HEAD
;
data
.
create
=
true
;
data
.
session
=
session
;
recursiveTable
=
schema
.
createTable
(
data
);
session
.
addLocalTempTable
(
recursiveTable
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Prepared.java
浏览文件 @
75e1a835
...
...
@@ -13,7 +13,6 @@ import org.h2.engine.Database;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Parameter
;
import
org.h2.index.Index
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.message.Message
;
import
org.h2.result.ResultInterface
;
...
...
@@ -37,9 +36,9 @@ public abstract class Prepared {
protected
String
sqlStatement
;
/**
*
The position of the head record (used
for indexes).
*
Whether to create a new object (
for indexes).
*/
protected
int
headPos
=
Index
.
EMPTY_HEAD
;
protected
boolean
create
=
true
;
/**
* The list of parameters.
...
...
@@ -282,12 +281,12 @@ public abstract class Prepared {
}
/**
* Set
the head position
.
* Set
whether to create a new object
.
*
* @param
headPos the head position
* @param
create the new value
*/
public
void
set
HeadPos
(
int
headPos
)
{
this
.
headPos
=
headPos
;
public
void
set
Create
(
boolean
create
)
{
this
.
create
=
create
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
75e1a835
...
...
@@ -139,7 +139,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
String
indexName
=
table
.
getSchema
().
getUniqueIndexName
(
session
,
table
,
Constants
.
PREFIX_PRIMARY_KEY
);
int
id
=
getObjectId
();
try
{
index
=
table
.
addIndex
(
session
,
indexName
,
id
,
indexColumns
,
indexType
,
Index
.
EMPTY_HEAD
,
null
);
index
=
table
.
addIndex
(
session
,
indexName
,
id
,
indexColumns
,
indexType
,
true
,
null
);
}
finally
{
getSchema
().
freeUniqueName
(
indexName
);
}
...
...
@@ -272,7 +272,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
String
prefix
=
constraintName
==
null
?
"CONSTRAINT"
:
constraintName
;
String
indexName
=
t
.
getSchema
().
getUniqueIndexName
(
session
,
t
,
prefix
+
"_INDEX_"
);
try
{
return
t
.
addIndex
(
session
,
indexName
,
indexId
,
cols
,
indexType
,
Index
.
EMPTY_HEAD
,
null
);
return
t
.
addIndex
(
session
,
indexName
,
indexId
,
cols
,
indexType
,
true
,
null
);
}
finally
{
getSchema
().
freeUniqueName
(
indexName
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
75e1a835
...
...
@@ -282,7 +282,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
data
.
temporary
=
table
.
isTemporary
();
data
.
persistData
=
table
.
isPersistData
();
data
.
persistIndexes
=
table
.
isPersistIndexes
();
data
.
headPos
=
Index
.
EMPTY_HEAD
;
data
.
create
=
true
;
data
.
session
=
session
;
TableData
newTable
=
getSchema
().
createTable
(
data
);
newTable
.
setComment
(
table
.
getComment
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/CreateIndex.java
浏览文件 @
75e1a835
...
...
@@ -88,7 +88,7 @@ public class CreateIndex extends SchemaCommand {
indexType
=
IndexType
.
createNonUnique
(
persistent
,
hash
);
}
IndexColumn
.
mapColumns
(
indexColumns
,
table
);
table
.
addIndex
(
session
,
indexName
,
id
,
indexColumns
,
indexType
,
headPos
,
comment
);
table
.
addIndex
(
session
,
indexName
,
id
,
indexColumns
,
indexType
,
create
,
comment
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
75e1a835
...
...
@@ -135,7 +135,7 @@ public class CreateTable extends SchemaCommand {
}
}
data
.
id
=
getObjectId
();
data
.
headPos
=
headPos
;
data
.
create
=
create
;
data
.
session
=
session
;
TableData
table
=
getSchema
().
createTable
(
data
);
table
.
setComment
(
comment
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/CreateTableData.java
浏览文件 @
75e1a835
...
...
@@ -52,9 +52,9 @@ public class CreateTableData {
public
boolean
persistData
;
/**
*
The head position
.
*
Whether to create a new table
.
*/
public
int
headPos
;
public
boolean
create
;
/**
* The session.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Optimizer.java
浏览文件 @
75e1a835
...
...
@@ -9,13 +9,11 @@ package org.h2.command.dml;
import
java.sql.SQLException
;
import
java.util.BitSet
;
import
java.util.Random
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.table.Plan
;
import
org.h2.table.PlanItem
;
import
org.h2.table.TableFilter
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.Permutations
;
/**
...
...
@@ -157,20 +155,20 @@ public class Optimizer {
}
boolean
generateRandom
=
(
x
&
127
)
==
0
;
if
(!
generateRandom
)
{
ObjectUtils
.
arrayCopy
(
best
,
list
,
filters
.
length
);
System
.
arraycopy
(
best
,
0
,
list
,
0
,
filters
.
length
);
if
(!
shuffleTwo
(
list
))
{
generateRandom
=
true
;
}
}
if
(
generateRandom
)
{
switched
=
new
BitSet
();
ObjectUtils
.
arrayCopy
(
filters
,
best
,
filters
.
length
);
System
.
arraycopy
(
filters
,
0
,
best
,
0
,
filters
.
length
);
shuffleAll
(
best
);
ObjectUtils
.
arrayCopy
(
best
,
list
,
filters
.
length
);
System
.
arraycopy
(
best
,
0
,
list
,
0
,
filters
.
length
);
}
if
(
testPlan
(
list
))
{
switched
=
new
BitSet
();
ObjectUtils
.
arrayCopy
(
list
,
best
,
filters
.
length
);
System
.
arraycopy
(
list
,
0
,
best
,
0
,
filters
.
length
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
75e1a835
...
...
@@ -39,7 +39,6 @@ import org.h2.table.Table;
import
org.h2.table.TableFilter
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.ValueHashMap
;
...
...
@@ -216,7 +215,7 @@ public class Select extends Query {
}
// remove columns so that 'distinct' can filter duplicate rows
Value
[]
r2
=
new
Value
[
distinctColumnCount
];
ObjectUtils
.
arrayCopy
(
row
,
r2
,
distinctColumnCount
);
System
.
arraycopy
(
row
,
0
,
r2
,
0
,
distinctColumnCount
);
return
r2
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constant/SysProperties.java
浏览文件 @
75e1a835
...
...
@@ -406,12 +406,6 @@ public class SysProperties {
*/
public
static
final
boolean
OPTIMIZE_TWO_EQUALS
=
getBooleanSetting
(
"h2.optimizeTwoEquals"
,
true
);
/**
* System property <code>h2.overflowExceptions</code> (default: true).<br />
* Throw an exception on integer overflows.
*/
public
static
final
boolean
OVERFLOW_EXCEPTIONS
=
getBooleanSetting
(
"h2.overflowExceptions"
,
true
);
/**
* System property <code>h2.pageSize</code> (default: 2048).<br />
* The page size to use for new databases.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
75e1a835
...
...
@@ -54,7 +54,7 @@ public class ConstraintCheck extends Constraint {
return
buff
.
toString
();
}
p
ublic
String
getShortDescription
()
{
p
rivate
String
getShortDescription
()
{
return
getName
()
+
": "
+
expr
.
getSQL
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
75e1a835
...
...
@@ -164,7 +164,7 @@ public class ConstraintReferential extends Constraint {
*
* @return the description
*/
p
ublic
String
getShortDescription
()
{
p
rivate
String
getShortDescription
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
getName
());
buff
.
append
(
": "
).
append
(
table
.
getSQL
()).
append
(
" FOREIGN KEY("
);
for
(
IndexColumn
c
:
columns
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
75e1a835
...
...
@@ -40,16 +40,10 @@ public class Constants {
public
static
final
String
BUILD_DATE_STABLE
=
"2010-01-15"
;
/**
* The TCP protocol version number
5
. This protocol is used by the TCP
* The TCP protocol version number. This protocol is used by the TCP
* server and remote JDBC client.
*/
public
static
final
int
TCP_PROTOCOL_VERSION_5
=
5
;
/**
* The TCP protocol version number 6. This protocol is used by the TCP
* server and remote JDBC client.
*/
public
static
final
int
TCP_PROTOCOL_VERSION_6
=
6
;
public
static
final
int
TCP_PROTOCOL_VERSION
=
6
;
/**
* The major version of this database.
...
...
@@ -66,12 +60,6 @@ public class Constants {
*/
public
static
final
double
VERSION
=
VERSION_MAJOR
+
VERSION_MINOR
/
10
.;
/**
* If empty b-tree pages are allowed. This is supported for backward
* compatibility.
*/
public
static
final
boolean
ALLOW_EMPTY_BTREE_PAGES
=
true
;
/**
* Constant meaning both numbers and text is allowed in SQL statements.
*/
...
...
@@ -386,11 +374,6 @@ public class Constants {
*/
public
static
final
long
SLOW_QUERY_LIMIT_MS
=
100
;
/**
* The file name suffix of data files.
*/
public
static
final
String
SUFFIX_DATA_FILE
=
".data.db"
;
/**
* The file name suffix of page files.
*/
...
...
@@ -401,11 +384,6 @@ public class Constants {
*/
public
static
final
String
SUFFIX_DB_FILE
=
".db"
;
/**
* The file name suffix of index files.
*/
public
static
final
String
SUFFIX_INDEX_FILE
=
".index.db"
;
/**
* The file name suffix of file lock files that are used to make sure a
* database is open by only one process at any time.
...
...
@@ -423,11 +401,6 @@ public class Constants {
*/
public
static
final
String
SUFFIX_LOBS_DIRECTORY
=
".lobs.db"
;
/**
* The file name suffix of transaction log files.
*/
public
static
final
String
SUFFIX_LOG_FILE
=
".log.db"
;
/**
* The file name suffix of temporary files.
*/
...
...
@@ -459,16 +432,6 @@ public class Constants {
*/
public
static
final
String
UTF8
=
"UTF8"
;
/**
* The major version number of the supported JDBC API.
*/
public
static
final
int
VERSION_JDBC_MAJOR
=
3
;
/**
* The minor version number of the supported JDBC API.
*/
public
static
final
int
VERSION_JDBC_MINOR
=
0
;
/**
* The maximum time in milliseconds to keep the cost of a view.
* 10000 means 10 seconds.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Database.java
浏览文件 @
75e1a835
...
...
@@ -49,7 +49,6 @@ import org.h2.table.TableData;
import
org.h2.table.TableLinkConnection
;
import
org.h2.table.TableView
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Recover
;
import
org.h2.tools.Server
;
import
org.h2.util.BitField
;
import
org.h2.util.ByteUtils
;
...
...
@@ -71,7 +70,7 @@ import org.h2.value.ValueLob;
* There is one database object per open database.
*
* The format of the meta data table is:
* id int,
headPos int (for indexes)
, objectType int, sql varchar
* id int,
0
, objectType int, sql varchar
*
* @since 2004-04-15 22:49
*/
...
...
@@ -430,7 +429,7 @@ public class Database implements DataHandler {
* @return true if one exists
*/
public
static
boolean
exists
(
String
name
)
{
return
FileUtils
.
exists
(
name
+
Constants
.
SUFFIX_PAGE_FILE
)
|
FileUtils
.
exists
(
name
+
Constants
.
SUFFIX_DATA_FILE
)
;
return
FileUtils
.
exists
(
name
+
Constants
.
SUFFIX_PAGE_FILE
);
}
/**
...
...
@@ -490,15 +489,13 @@ public class Database implements DataHandler {
private
synchronized
void
open
(
int
traceLevelFile
,
int
traceLevelSystemOut
)
throws
SQLException
{
if
(
persistent
)
{
String
dataFileName
=
databaseName
+
Constants
.
SUFFIX_DATA_FILE
;
String
dataFileName
=
databaseName
+
".data.db"
;
boolean
existsData
=
FileUtils
.
exists
(
dataFileName
);
String
pageFileName
=
databaseName
+
Constants
.
SUFFIX_PAGE_FILE
;
boolean
existsPage
=
FileUtils
.
exists
(
pageFileName
);
if
(
existsData
&&
!
existsPage
)
{
String
dir
=
FileUtils
.
getParent
(
databaseName
);
String
db
=
FileUtils
.
getFileName
(
databaseName
);
Recover
.
convert
(
dir
,
db
);
existsPage
=
true
;
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_VERSION_ERROR_1
,
"Old database: "
+
dataFileName
+
" - please convert the database to a SQL script and re-create it."
);
}
if
(
existsPage
&&
FileUtils
.
isReadOnly
(
pageFileName
))
{
// if it is already read-only because ACCESS_MODE_DATA=r
...
...
@@ -564,21 +561,21 @@ public class Database implements DataHandler {
cols
.
add
(
new
Column
(
"HEAD"
,
Value
.
INT
));
cols
.
add
(
new
Column
(
"TYPE"
,
Value
.
INT
));
cols
.
add
(
new
Column
(
"SQL"
,
Value
.
STRING
));
int
headPos
=
0
;
boolean
create
=
true
;
if
(
pageStore
!=
null
)
{
headPos
=
pageStore
.
getSystemTableHeadPos
();
create
=
pageStore
.
isNew
();
}
data
.
tableName
=
"SYS"
;
data
.
id
=
0
;
data
.
temporary
=
false
;
data
.
persistData
=
persistent
;
data
.
persistIndexes
=
persistent
;
data
.
headPos
=
headPos
;
data
.
create
=
create
;
data
.
session
=
systemSession
;
meta
=
mainSchema
.
createTable
(
data
);
IndexColumn
[]
pkCols
=
IndexColumn
.
wrap
(
new
Column
[]
{
columnId
});
metaIdIndex
=
meta
.
addIndex
(
systemSession
,
"SYS_ID"
,
0
,
pkCols
,
IndexType
.
createPrimaryKey
(
false
,
false
),
Index
.
EMPTY_HEAD
,
null
);
false
,
false
),
true
,
null
);
objectIds
.
set
(
0
);
starting
=
true
;
Cursor
cursor
=
metaIdIndex
.
find
(
systemSession
,
null
,
null
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/DbObject.java
浏览文件 @
75e1a835
...
...
@@ -219,10 +219,4 @@ public interface DbObject {
*/
String
getComment
();
/**
* Get the position of the head record.
*
* @return the head position
*/
int
getHeadPos
();
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/DbObjectBase.java
浏览文件 @
75e1a835
...
...
@@ -145,10 +145,6 @@ public abstract class DbObjectBase implements DbObject {
objectName
=
null
;
}
public
int
getHeadPos
()
{
return
0
;
}
public
void
rename
(
String
newName
)
throws
SQLException
{
checkRename
();
objectName
=
newName
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/MetaRecord.java
浏览文件 @
75e1a835
...
...
@@ -25,12 +25,10 @@ public class MetaRecord {
private
int
id
;
private
int
objectType
;
private
int
headPos
;
private
String
sql
;
public
MetaRecord
(
SearchRow
r
)
throws
SQLException
{
id
=
r
.
getValue
(
0
).
getInt
();
headPos
=
r
.
getValue
(
1
).
getInt
();
objectType
=
r
.
getValue
(
2
).
getInt
();
sql
=
r
.
getValue
(
3
).
getString
();
}
...
...
@@ -38,7 +36,6 @@ public class MetaRecord {
MetaRecord
(
DbObject
obj
)
{
id
=
obj
.
getId
();
objectType
=
obj
.
getType
();
headPos
=
obj
.
getHeadPos
();
sql
=
obj
.
getCreateSQL
();
}
...
...
@@ -62,7 +59,7 @@ public class MetaRecord {
void
setRecord
(
SearchRow
r
)
{
r
.
setValue
(
0
,
ValueInt
.
get
(
id
));
r
.
setValue
(
1
,
ValueInt
.
get
(
headPos
));
r
.
setValue
(
1
,
ValueInt
.
get
(
0
));
r
.
setValue
(
2
,
ValueInt
.
get
(
objectType
));
r
.
setValue
(
3
,
ValueString
.
get
(
sql
));
}
...
...
@@ -78,7 +75,7 @@ public class MetaRecord {
try
{
Prepared
command
=
systemSession
.
prepare
(
sql
);
command
.
setObjectId
(
id
);
command
.
set
HeadPos
(
headPos
);
command
.
set
Create
(
false
);
command
.
update
();
}
catch
(
Exception
e
)
{
SQLException
s
=
Message
.
addSQL
(
Message
.
convert
(
e
),
sql
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
75e1a835
...
...
@@ -76,7 +76,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
private
byte
[]
fileEncryptionKey
;
private
Object
lobSyncObject
=
new
Object
();
private
String
sessionId
;
private
int
clientVersion
=
Constants
.
TCP_PROTOCOL_VERSION
_5
;
private
int
clientVersion
=
Constants
.
TCP_PROTOCOL_VERSION
;
private
boolean
autoReconnect
;
private
int
lastReconnect
;
private
SessionInterface
embedded
;
...
...
@@ -97,7 +97,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
trans
.
setSSL
(
ci
.
isSSL
());
trans
.
init
();
trans
.
writeInt
(
clientVersion
);
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
_6
)
{
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
)
{
trans
.
writeInt
(
clientVersion
);
}
trans
.
writeString
(
db
);
...
...
@@ -112,7 +112,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
}
try
{
done
(
trans
);
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
_6
)
{
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
)
{
clientVersion
=
trans
.
readInt
();
}
}
catch
(
SQLException
e
)
{
...
...
@@ -135,18 +135,12 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
* @param id the statement id
*/
public
void
cancelStatement
(
int
id
)
{
if
(
clientVersion
<=
Constants
.
TCP_PROTOCOL_VERSION_5
)
{
// older servers don't support this feature
return
;
}
for
(
Transfer
transfer
:
transferList
)
{
try
{
Transfer
trans
=
transfer
.
openNewConnection
();
trans
.
init
();
trans
.
writeInt
(
clientVersion
);
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION_6
)
{
trans
.
writeInt
(
clientVersion
);
}
trans
.
writeInt
(
clientVersion
);
trans
.
writeString
(
null
);
trans
.
writeString
(
null
);
trans
.
writeString
(
sessionId
);
...
...
@@ -363,7 +357,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
Value
[]
v
=
result
.
currentRow
();
int
version
=
v
[
0
].
getInt
();
if
(
version
>
71
)
{
clientVersion
=
Constants
.
TCP_PROTOCOL_VERSION
_6
;
clientVersion
=
Constants
.
TCP_PROTOCOL_VERSION
;
}
}
result
.
close
();
...
...
@@ -371,7 +365,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
trace
.
error
(
"Error trying to upgrade client version"
,
e
);
// ignore
}
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
_6
)
{
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
)
{
sessionId
=
ByteUtils
.
convertBytesToString
(
RandomUtils
.
getSecureBytes
(
32
));
synchronized
(
this
)
{
for
(
Transfer
transfer
:
transferList
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/Function.java
浏览文件 @
75e1a835
...
...
@@ -41,7 +41,6 @@ import org.h2.table.TableFilter;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.Csv
;
import
org.h2.util.AutoCloseInputStream
;
import
org.h2.util.DateTimeIso8601Utils
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.MathUtils
;
...
...
@@ -648,13 +647,13 @@ public class Function extends Expression implements FunctionCall {
result
=
ValueInt
.
get
(
DateTimeUtils
.
getDatePart
(
v0
.
getDateNoCopy
(),
Calendar
.
YEAR
));
break
;
case
ISO_YEAR:
result
=
ValueInt
.
get
(
DateTime
Iso8601
Utils
.
getIsoYear
(
v0
.
getDateNoCopy
()));
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoYear
(
v0
.
getDateNoCopy
()));
break
;
case
ISO_WEEK:
result
=
ValueInt
.
get
(
DateTime
Iso8601
Utils
.
getIsoWeek
(
v0
.
getDateNoCopy
()));
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoWeek
(
v0
.
getDateNoCopy
()));
break
;
case
ISO_DAY_OF_WEEK:
result
=
ValueInt
.
get
(
DateTime
Iso8601
Utils
.
getIsoDayOfWeek
(
v0
.
getDateNoCopy
()));
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoDayOfWeek
(
v0
.
getDateNoCopy
()));
break
;
case
CURDATE:
case
CURRENT_DATE:
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
75e1a835
...
...
@@ -365,4 +365,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
this
.
isMultiVersion
=
multiVersion
;
}
public
Row
getRow
(
Session
session
,
long
key
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
toString
());
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/Index.java
浏览文件 @
75e1a835
...
...
@@ -21,11 +21,6 @@ import org.h2.table.Table;
*/
public
interface
Index
extends
SchemaObject
{
/**
* Indicates that there is no head record yet.
*/
int
EMPTY_HEAD
=
-
1
;
/**
* Create a duplicate key exception with a message that contains the index name
*
...
...
@@ -263,4 +258,14 @@ public interface Index extends SchemaObject {
*/
int
getRootPageId
();
/**
* Get the row with the given key.
*
* @param session the session
* @param key the unique key
* @return the row
*/
Row
getRow
(
Session
session
,
long
key
)
throws
SQLException
;
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/MultiVersionIndex.java
浏览文件 @
75e1a835
...
...
@@ -277,10 +277,6 @@ public class MultiVersionIndex implements Index {
return
base
.
getDatabase
();
}
public
int
getHeadPos
()
{
return
base
.
getHeadPos
();
}
public
int
getId
()
{
return
base
.
getId
();
}
...
...
@@ -321,4 +317,8 @@ public class MultiVersionIndex implements Index {
return
base
;
}
public
Row
getRow
(
Session
session
,
long
key
)
throws
SQLException
{
return
base
.
getRow
(
session
,
key
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/PageBtreeIndex.java
浏览文件 @
75e1a835
...
...
@@ -36,7 +36,7 @@ public class PageBtreeIndex extends PageIndex {
private
long
rowCount
;
public
PageBtreeIndex
(
TableData
table
,
int
id
,
String
indexName
,
IndexColumn
[]
columns
,
IndexType
indexType
,
int
headPos
,
Session
session
)
throws
SQLException
{
IndexType
indexType
,
boolean
create
,
Session
session
)
throws
SQLException
{
initBaseIndex
(
table
,
id
,
indexName
,
columns
,
indexType
);
// int test;
// trace.setLevel(TraceSystem.DEBUG);
...
...
@@ -46,7 +46,7 @@ public class PageBtreeIndex extends PageIndex {
}
this
.
store
=
database
.
getPageStore
();
store
.
addIndex
(
this
);
if
(
headPos
==
Index
.
EMPTY_HEAD
)
{
if
(
create
)
{
// new index
rootPageId
=
store
.
allocatePage
();
needRebuild
=
true
;
...
...
@@ -283,7 +283,7 @@ public class PageBtreeIndex extends PageIndex {
* @param key the row key
* @return the row
*/
Row
getRow
(
Session
session
,
long
key
)
throws
SQLException
{
public
Row
getRow
(
Session
session
,
long
key
)
throws
SQLException
{
return
tableData
.
getRow
(
session
,
key
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/PageDataIndex.java
浏览文件 @
75e1a835
...
...
@@ -36,7 +36,7 @@ import org.h2.value.ValueNull;
* all rows of a table. Each regular table has one such object, even if no
* primary key or indexes are defined.
*/
public
class
PageDataIndex
extends
PageIndex
implements
RowIndex
{
public
class
PageDataIndex
extends
PageIndex
{
private
PageStore
store
;
private
TableData
tableData
;
...
...
@@ -49,7 +49,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
private
SQLException
fastDuplicateKeyException
;
private
int
memorySizePerPage
;
public
PageDataIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
,
int
headPos
,
Session
session
)
throws
SQLException
{
public
PageDataIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
,
boolean
create
,
Session
session
)
throws
SQLException
{
initBaseIndex
(
table
,
id
,
table
.
getName
()
+
"_DATA"
,
columns
,
indexType
);
// trace = database.getTrace(Trace.PAGE_STORE + "_di");
...
...
@@ -64,8 +64,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
if
(!
database
.
isPersistent
())
{
throw
Message
.
throwInternalError
(
table
.
getName
());
}
if
(
headPos
==
Index
.
EMPTY_HEAD
)
{
// new table
if
(
create
)
{
rootPageId
=
store
.
allocatePage
();
store
.
addMeta
(
this
,
session
);
PageDataLeaf
root
=
PageDataLeaf
.
create
(
this
,
rootPageId
,
PageData
.
ROOT
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/PageDelegateIndex.java
浏览文件 @
75e1a835
...
...
@@ -23,7 +23,7 @@ public class PageDelegateIndex extends PageIndex {
private
final
PageDataIndex
mainIndex
;
public
PageDelegateIndex
(
TableData
table
,
int
id
,
String
name
,
IndexType
indexType
,
PageDataIndex
mainIndex
,
int
headPos
,
Session
session
)
throws
SQLException
{
public
PageDelegateIndex
(
TableData
table
,
int
id
,
String
name
,
IndexType
indexType
,
PageDataIndex
mainIndex
,
boolean
create
,
Session
session
)
throws
SQLException
{
IndexColumn
[]
cols
=
IndexColumn
.
wrap
(
new
Column
[]
{
table
.
getColumn
(
mainIndex
.
getMainIndexColumn
())});
this
.
initBaseIndex
(
table
,
id
,
name
,
cols
,
indexType
);
this
.
mainIndex
=
mainIndex
;
...
...
@@ -32,7 +32,7 @@ public class PageDelegateIndex extends PageIndex {
}
PageStore
store
=
database
.
getPageStore
();
store
.
addIndex
(
this
);
if
(
headPos
==
Index
.
EMPTY_HEAD
)
{
if
(
create
)
{
store
.
addMeta
(
this
,
session
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/PageIndex.java
浏览文件 @
75e1a835
...
...
@@ -24,10 +24,6 @@ public abstract class PageIndex extends BaseIndex {
return
rootPageId
;
}
public
int
getHeadPos
()
{
return
0
;
}
/**
* Write back the row count if it has changed.
*/
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/RowIndex.java
deleted
100644 → 0
浏览文件 @
96cf5428
/*
* Copyright 2004-2010 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
.
index
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.result.Row
;
/**
* An index that can address individual rows directly.
*/
public
interface
RowIndex
extends
Index
{
/**
* Get the row with the given key.
*
* @param session the session
* @param key the unique key
* @return the row
*/
Row
getRow
(
Session
session
,
long
key
)
throws
SQLException
;
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
75e1a835
...
...
@@ -31,7 +31,7 @@ import org.h2.value.ValueLob;
* of a table. Each regular table has one such object, even if no primary key or
* indexes are defined.
*/
public
class
ScanIndex
extends
BaseIndex
implements
RowIndex
{
public
class
ScanIndex
extends
BaseIndex
{
private
long
firstFree
=
-
1
;
private
ObjectArray
<
Row
>
rows
=
ObjectArray
.
newInstance
();
private
TableData
tableData
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcConnection.java
浏览文件 @
75e1a835
...
...
@@ -33,8 +33,8 @@ import org.h2.message.Message;
import
org.h2.message.Trace
;
import
org.h2.message.TraceObject
;
import
org.h2.result.ResultInterface
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.ObjectUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueLob
;
...
...
@@ -1679,7 +1679,7 @@ public class JdbcConnection extends TraceObject implements Connection {
break
;
}
case
Value
.
JAVA_OBJECT
:
o
=
Object
Utils
.
deserialize
(
v
.
getBytesNoCopy
());
o
=
Byte
Utils
.
deserialize
(
v
.
getBytesNoCopy
());
break
;
default
:
o
=
v
.
getObject
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
75e1a835
...
...
@@ -2695,21 +2695,21 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
/**
* Gets the major version of the supported JDBC API.
*
* @return the major version
* @return the major version
(3)
*/
public
int
getJDBCMajorVersion
()
{
debugCodeCall
(
"getJDBCMajorVersion"
);
return
Constants
.
VERSION_JDBC_MAJOR
;
return
3
;
}
/**
* Gets the minor version of the supported JDBC API.
*
* @return the minor version
* @return the minor version
(0)
*/
public
int
getJDBCMinorVersion
()
{
debugCodeCall
(
"getJDBCMinorVersion"
);
return
Constants
.
VERSION_JDBC_MINOR
;
return
0
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/log/UndoLogRecord.java
浏览文件 @
75e1a835
...
...
@@ -160,7 +160,6 @@ public class UndoLogRecord {
}
buff
.
fillAligned
();
buff
.
setInt
(
0
,
buff
.
length
()
/
Constants
.
FILE_BLOCK_SIZE
);
buff
.
updateChecksum
();
filePos
=
(
int
)
(
file
.
getFilePointer
()
/
Constants
.
FILE_BLOCK_SIZE
);
file
.
write
(
buff
.
getBytes
(),
0
,
buff
.
length
());
row
=
null
;
...
...
@@ -183,7 +182,6 @@ public class UndoLogRecord {
if
(
len
-
min
>
0
)
{
file
.
readFully
(
buff
.
getBytes
(),
min
,
len
-
min
);
}
buff
.
check
(
len
);
int
op
=
buff
.
readInt
();
if
(
SysProperties
.
CHECK
)
{
if
(
operation
!=
op
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/ResultDiskBuffer.java
浏览文件 @
75e1a835
...
...
@@ -97,7 +97,6 @@ class ResultDiskBuffer implements ResultExternal {
buff
.
fillAligned
();
int
len
=
buff
.
length
();
buff
.
setInt
(
0
,
len
);
buff
.
updateChecksum
();
if
(
maxBufferSize
>
0
)
{
buffer
.
write
(
buff
.
getBytes
(),
0
,
len
);
bufferLen
+=
len
;
...
...
@@ -152,7 +151,6 @@ class ResultDiskBuffer implements ResultExternal {
if
(
len
-
min
>
0
)
{
file
.
readFully
(
buff
.
getBytes
(),
min
,
len
-
min
);
}
buff
.
check
(
len
);
tape
.
pos
+=
len
;
Value
[]
row
=
new
Value
[
columnCount
];
for
(
int
k
=
0
;
k
<
columnCount
;
k
++)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/ResultTempTable.java
浏览文件 @
75e1a835
...
...
@@ -49,7 +49,7 @@ public class ResultTempTable implements ResultExternal {
data
.
temporary
=
true
;
data
.
persistIndexes
=
false
;
data
.
persistData
=
true
;
data
.
headPos
=
Index
.
EMPTY_HEAD
;
data
.
create
=
true
;
data
.
session
=
session
;
table
=
schema
.
createTable
(
data
);
int
indexId
=
session
.
getDatabase
().
allocateObjectId
();
...
...
@@ -59,7 +59,7 @@ public class ResultTempTable implements ResultExternal {
IndexType
indexType
;
indexType
=
IndexType
.
createPrimaryKey
(
true
,
false
);
IndexColumn
[]
indexCols
=
new
IndexColumn
[]{
indexColumn
};
index
=
new
PageBtreeIndex
(
table
,
indexId
,
data
.
tableName
,
indexCols
,
indexType
,
Index
.
EMPTY_HEAD
,
session
);
index
=
new
PageBtreeIndex
(
table
,
indexId
,
data
.
tableName
,
indexCols
,
indexType
,
true
,
session
);
index
.
setTemporary
(
true
);
table
.
getIndexes
().
add
(
index
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/Row.java
浏览文件 @
75e1a835
...
...
@@ -8,7 +8,6 @@ package org.h2.result;
import
java.sql.SQLException
;
import
org.h2.store.Data
;
import
org.h2.store.DiskFile
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
...
...
@@ -83,9 +82,9 @@ public class Row implements SearchRow {
public
int
getMemorySize
()
{
if
(
memory
!=
MEMORY_CALCULATE
)
{
return
(
DiskFile
.
BLOCK_SIZE
/
8
)
+
memory
*
4
;
return
16
+
memory
*
4
;
}
int
m
=
DiskFile
.
BLOCK_SIZE
/
16
;
int
m
=
8
;
for
(
int
i
=
0
;
data
!=
null
&&
i
<
data
.
length
;
i
++)
{
m
+=
data
[
i
].
getMemory
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/RowList.java
浏览文件 @
75e1a835
...
...
@@ -7,13 +7,11 @@
package
org
.
h2
.
result
;
import
java.sql.SQLException
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.store.Data
;
import
org.h2.store.DataPage
;
import
org.h2.store.FileStore
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.Value
;
...
...
@@ -49,7 +47,7 @@ public class RowList {
}
private
void
writeRow
(
Data
buff
,
Row
r
)
throws
SQLException
{
buff
.
checkCapacity
(
1
+
Data
Page
.
LENGTH_INT
*
8
);
buff
.
checkCapacity
(
1
+
Data
.
LENGTH_INT
*
8
);
buff
.
writeByte
((
byte
)
1
);
buff
.
writeInt
(
r
.
getMemorySize
());
buff
.
writeInt
(
r
.
getColumnCount
());
...
...
@@ -121,7 +119,6 @@ public class RowList {
buff
.
writeByte
((
byte
)
0
);
buff
.
fillAligned
();
buff
.
setInt
(
0
,
buff
.
length
()
/
Constants
.
FILE_BLOCK_SIZE
);
buff
.
updateChecksum
();
file
.
write
(
buff
.
getBytes
(),
0
,
buff
.
length
());
}
...
...
@@ -225,7 +222,6 @@ public class RowList {
if
(
len
-
min
>
0
)
{
file
.
readFully
(
buff
.
getBytes
(),
min
,
len
-
min
);
}
buff
.
check
(
len
);
for
(
int
i
=
0
;;
i
++)
{
r
=
readRow
(
buff
);
if
(
r
==
null
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/TcpServerThread.java
浏览文件 @
75e1a835
...
...
@@ -69,14 +69,8 @@ public class TcpServerThread implements Runnable {
if
(!
server
.
allow
(
transfer
.
getSocket
()))
{
throw
Message
.
getSQLException
(
ErrorCode
.
REMOTE_CONNECTION_NOT_ALLOWED
);
}
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION_6
)
{
// version 6 and newer: read max version (currently not used)
transfer
.
readInt
();
}
else
if
(
clientVersion
!=
Constants
.
TCP_PROTOCOL_VERSION_5
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
DRIVER_VERSION_ERROR_2
,
""
+
clientVersion
,
""
+
Constants
.
TCP_PROTOCOL_VERSION_5
);
}
// max version (currently not used)
transfer
.
readInt
();
String
db
=
transfer
.
readString
();
String
originalURL
=
transfer
.
readString
();
if
(
db
==
null
&&
originalURL
==
null
)
{
...
...
@@ -121,9 +115,9 @@ public class TcpServerThread implements Runnable {
session
=
engine
.
getSession
(
ci
);
transfer
.
setSession
(
session
);
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
);
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
_6
)
{
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
)
{
// version 6: reply what version to use
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION
_6
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION
);
}
transfer
.
flush
();
server
.
addConnection
(
threadId
,
originalURL
,
ci
.
getUserName
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/Data.java
浏览文件 @
75e1a835
...
...
@@ -16,6 +16,7 @@ import java.sql.Time;
import
java.sql.Timestamp
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.message.Message
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.MathUtils
;
...
...
@@ -45,10 +46,20 @@ import org.h2.value.ValueUuid;
/**
* A data page is a byte buffer that contains persistent data of a page.
*/
public
class
Data
extends
DataPage
{
public
class
Data
{
/**
* The length of an integer value.
*/
public
static
final
int
LENGTH_INT
=
4
;
private
static
final
int
TEST_OFFSET
=
0
;
/**
* The length of a long value.
*/
private
static
final
int
LENGTH_LONG
=
8
;
private
static
final
int
INT_0_15
=
32
;
private
static
final
int
LONG_0_7
=
48
;
private
static
final
int
DECIMAL_0_1
=
56
;
...
...
@@ -65,8 +76,24 @@ public class Data extends DataPage {
private
static
final
long
MILLIS_PER_MINUTE
=
1000
*
60
;
/**
* The data itself.
*/
private
byte
[]
data
;
/**
* The current write or read position.
*/
private
int
pos
;
/**
* The data handler responsible for lob objects.
*/
private
final
DataHandler
handler
;
private
Data
(
DataHandler
handler
,
byte
[]
data
)
{
super
(
handler
,
data
);
this
.
handler
=
handler
;
this
.
data
=
data
;
}
/**
...
...
@@ -979,4 +1006,30 @@ public class Data extends DataPage {
}
}
/**
* Check if there is still enough capacity in the buffer.
* This method extends the buffer if required.
*
* @param plus the number of additional bytes required
*/
public
void
checkCapacity
(
int
plus
)
{
if
(
pos
+
plus
>=
data
.
length
)
{
byte
[]
d
=
MemoryUtils
.
newBytes
((
data
.
length
+
plus
)
*
2
);
// must copy everything, because pos could be 0 and data may be
// still required
System
.
arraycopy
(
data
,
0
,
d
,
0
,
data
.
length
);
data
=
d
;
}
}
/**
* Fill up the buffer with empty space and an (initially empty) checksum
* until the size is a multiple of Constants.FILE_BLOCK_SIZE.
*/
public
void
fillAligned
()
{
// TODO datapage: fillAligned should not use a fixed constant '2'
// 0..6 > 8, 7..14 > 16, 15..22 > 24, ...
fill
(
MathUtils
.
roundUp
(
pos
+
2
,
Constants
.
FILE_BLOCK_SIZE
));
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/DiskFile.java
deleted
100644 → 0
浏览文件 @
96cf5428
/*
* Copyright 2004-2010 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
.
store
;
/**
* This class represents a file that is usually written to disk.
*/
public
class
DiskFile
{
/**
* The number of bits to shift to divide a position to get the page number.
*/
public
static
final
int
BLOCK_PAGE_PAGE_SHIFT
=
6
;
/**
* The size of a page in blocks.
* Each page contains blocks from the same storage.
*/
public
static
final
int
BLOCKS_PER_PAGE
=
1
<<
BLOCK_PAGE_PAGE_SHIFT
;
/**
* The size of a block in bytes.
* A block is the minimum row size.
*/
public
static
final
int
BLOCK_SIZE
=
128
;
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/FileLister.java
浏览文件 @
75e1a835
...
...
@@ -34,8 +34,6 @@ public class FileLister {
public
static
String
getDatabaseNameFromFileName
(
String
fileName
)
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
))
{
return
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_PAGE_FILE
.
length
());
}
else
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_DATA_FILE
))
{
return
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_DATA_FILE
.
length
());
}
return
null
;
}
...
...
@@ -84,13 +82,7 @@ public class FileLister {
for
(
int
i
=
0
;
list
!=
null
&&
i
<
list
.
length
;
i
++)
{
String
f
=
list
[
i
];
boolean
ok
=
false
;
if
(
f
.
endsWith
(
Constants
.
SUFFIX_DATA_FILE
))
{
ok
=
true
;
}
else
if
(
f
.
endsWith
(
Constants
.
SUFFIX_INDEX_FILE
))
{
ok
=
true
;
}
else
if
(
f
.
endsWith
(
Constants
.
SUFFIX_LOG_FILE
))
{
ok
=
true
;
}
else
if
(
f
.
endsWith
(
Constants
.
SUFFIX_LOBS_DIRECTORY
))
{
if
(
f
.
endsWith
(
Constants
.
SUFFIX_LOBS_DIRECTORY
))
{
if
(
start
==
null
||
FileUtils
.
fileStartsWith
(
f
,
start
+
"."
))
{
files
.
addAll
(
getDatabaseFiles
(
f
,
null
,
all
));
ok
=
true
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
75e1a835
...
...
@@ -224,8 +224,8 @@ public class FileLock {
Transfer
transfer
=
new
Transfer
(
null
);
transfer
.
setSocket
(
socket
);
transfer
.
init
();
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION
_6
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION
_6
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
id
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/FileStoreInputStream.java
浏览文件 @
75e1a835
...
...
@@ -106,7 +106,7 @@ public class FileStoreInputStream extends InputStream {
page
.
checkCapacity
(
remainingInBuffer
);
// get the length to read
if
(
compress
!=
null
)
{
page
.
checkCapacity
(
Data
Page
.
LENGTH_INT
);
page
.
checkCapacity
(
Data
.
LENGTH_INT
);
readInt
();
}
page
.
setPos
(
page
.
length
()
+
remainingInBuffer
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/FileStoreOutputStream.java
浏览文件 @
75e1a835
...
...
@@ -56,12 +56,12 @@ public class FileStoreOutputStream extends OutputStream {
int
uncompressed
=
len
;
buff
=
compress
.
compress
(
buff
,
compressionAlgorithm
);
len
=
buff
.
length
;
page
.
checkCapacity
(
2
*
Data
Page
.
LENGTH_INT
+
len
);
page
.
checkCapacity
(
2
*
Data
.
LENGTH_INT
+
len
);
page
.
writeInt
(
len
);
page
.
writeInt
(
uncompressed
);
page
.
write
(
buff
,
off
,
len
);
}
else
{
page
.
checkCapacity
(
Data
Page
.
LENGTH_INT
+
len
);
page
.
checkCapacity
(
Data
.
LENGTH_INT
+
len
);
page
.
writeInt
(
len
);
page
.
write
(
buff
,
off
,
len
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
75e1a835
...
...
@@ -186,7 +186,7 @@ public class PageStore implements CacheWriter {
* and the value the latest transaction position where this page is used.
*/
private
HashMap
<
Integer
,
Integer
>
reservedPages
;
private
int
systemTableHeadPos
;
private
boolean
isNew
;
// TODO reduce DEFAULT_MAX_LOG_SIZE, and don't divide here
private
long
maxLogSize
=
Constants
.
DEFAULT_MAX_LOG_SIZE
/
10
;
private
Session
systemSession
;
...
...
@@ -284,7 +284,7 @@ public class PageStore implements CacheWriter {
openMetaIndex
();
logFirstTrunkPage
=
allocatePage
();
log
.
openForWriting
(
logFirstTrunkPage
,
false
);
systemTableHeadPos
=
Index
.
EMPTY_HEAD
;
isNew
=
true
;
recoveryRunning
=
false
;
increaseFileSize
(
INCREMENT_PAGES
);
}
...
...
@@ -1051,11 +1051,7 @@ public class PageStore implements CacheWriter {
}
}
PageDataIndex
systemTable
=
(
PageDataIndex
)
metaObjects
.
get
(
0
);
if
(
systemTable
==
null
)
{
systemTableHeadPos
=
Index
.
EMPTY_HEAD
;
}
else
{
systemTableHeadPos
=
systemTable
.
getHeadPos
();
}
isNew
=
systemTable
==
null
;
for
(
Index
openIndex
:
metaObjects
.
values
())
{
if
(
openIndex
.
getTable
().
isTemporary
())
{
openIndex
.
truncate
(
systemSession
);
...
...
@@ -1124,12 +1120,12 @@ public class PageStore implements CacheWriter {
}
/**
*
Get the position of the system table head
.
*
Check whether this is a new database
.
*
* @return t
he system table head
* @return t
rue if it is
*/
public
int
getSystemTableHeadPos
()
{
return
systemTableHeadPos
;
public
boolean
isNew
()
{
return
isNew
;
}
/**
...
...
@@ -1218,7 +1214,7 @@ public class PageStore implements CacheWriter {
data
.
temporary
=
false
;
data
.
persistData
=
true
;
data
.
persistIndexes
=
true
;
data
.
headPos
=
0
;
data
.
create
=
false
;
data
.
session
=
systemSession
;
metaTable
=
new
TableData
(
data
);
metaIndex
=
(
PageDataIndex
)
metaTable
.
getScanIndex
(
...
...
@@ -1291,7 +1287,7 @@ public class PageStore implements CacheWriter {
data
.
temporary
=
ops
[
2
].
equals
(
"temp"
);
data
.
persistData
=
true
;
data
.
persistIndexes
=
true
;
data
.
headPos
=
0
;
data
.
create
=
false
;
data
.
session
=
session
;
TableData
table
=
new
TableData
(
data
);
CompareMode
mode
=
CompareMode
.
getInstance
(
ops
[
0
],
Integer
.
parseInt
(
ops
[
1
]));
...
...
@@ -1328,7 +1324,7 @@ public class PageStore implements CacheWriter {
}
else
{
indexType
=
IndexType
.
createNonUnique
(
true
);
}
meta
=
table
.
addIndex
(
session
,
"I"
+
id
,
id
,
cols
,
indexType
,
id
,
null
);
meta
=
table
.
addIndex
(
session
,
"I"
+
id
,
id
,
cols
,
indexType
,
false
,
null
);
}
PageIndex
index
;
if
(
meta
instanceof
MultiVersionIndex
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
75e1a835
...
...
@@ -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
indexComment
)
throws
SQLException
{
boolean
create
,
String
indexComment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"ALIAS"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
75e1a835
...
...
@@ -544,7 +544,7 @@ public class MetaTable extends Table {
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
indexComment
)
throws
SQLException
{
boolean
create
,
String
indexComment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"META"
);
}
...
...
@@ -857,7 +857,6 @@ public class MetaTable extends Table {
add
(
rows
,
"h2.objectCacheMaxPerElementSize"
,
""
+
SysProperties
.
OBJECT_CACHE_MAX_PER_ELEMENT_SIZE
);
add
(
rows
,
"h2.optimizeInList"
,
""
+
SysProperties
.
OPTIMIZE_IN_LIST
);
add
(
rows
,
"h2.optimizeSubqueryCache"
,
""
+
SysProperties
.
OPTIMIZE_SUBQUERY_CACHE
);
add
(
rows
,
"h2.overflowExceptions"
,
""
+
SysProperties
.
OVERFLOW_EXCEPTIONS
);
add
(
rows
,
"h2.recompileAlways"
,
""
+
SysProperties
.
RECOMPILE_ALWAYS
);
add
(
rows
,
"h2.redoBufferSize"
,
""
+
SysProperties
.
REDO_BUFFER_SIZE
);
add
(
rows
,
"h2.runFinalize"
,
""
+
SysProperties
.
runFinalize
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Plan.java
浏览文件 @
75e1a835
...
...
@@ -8,13 +8,11 @@ package org.h2.table;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ObjectUtils
;
/**
* A possible query execution plan. The time required to execute a query depends
...
...
@@ -35,7 +33,7 @@ public class Plan {
*/
public
Plan
(
TableFilter
[]
filters
,
int
count
,
Expression
condition
)
{
this
.
filters
=
new
TableFilter
[
count
];
ObjectUtils
.
arrayCopy
(
filters
,
this
.
filters
,
count
);
System
.
arraycopy
(
filters
,
0
,
this
.
filters
,
0
,
count
);
ObjectArray
<
Expression
>
allCond
=
ObjectArray
.
newInstance
();
ObjectArray
<
TableFilter
>
all
=
ObjectArray
.
newInstance
();
if
(
condition
!=
null
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
75e1a835
...
...
@@ -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
indexComment
)
throws
SQLException
{
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
boolean
create
,
String
indexComment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"SYSTEM_RANGE"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Table.java
浏览文件 @
75e1a835
...
...
@@ -151,12 +151,12 @@ public abstract class Table extends SchemaObjectBase {
* @param indexId the id
* @param cols the index columns
* @param indexType the index type
* @param
headPos the position of the head (if the index already exists)
* @param
create whether this is a new index
* @param indexComment the comment
* @return the index
*/
public
abstract
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
indexComment
)
throws
SQLException
;
boolean
create
,
String
indexComment
)
throws
SQLException
;
/**
* Remove a row from the table and all indexes.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableData.java
浏览文件 @
75e1a835
...
...
@@ -28,7 +28,6 @@ import org.h2.index.NonUniqueHashIndex;
import
org.h2.index.PageBtreeIndex
;
import
org.h2.index.PageDataIndex
;
import
org.h2.index.PageDelegateIndex
;
import
org.h2.index.RowIndex
;
import
org.h2.index.ScanIndex
;
import
org.h2.index.TreeIndex
;
import
org.h2.message.Message
;
...
...
@@ -51,7 +50,7 @@ import org.h2.value.Value;
* indexes. There is at least one index, the scan index.
*/
public
class
TableData
extends
Table
{
private
Row
Index
scanIndex
;
private
Index
scanIndex
;
private
long
rowCount
;
private
volatile
Session
lockExclusive
;
private
HashSet
<
Session
>
lockShared
=
New
.
hashSet
();
...
...
@@ -76,7 +75,7 @@ public class TableData extends Table {
setColumns
(
cols
);
setTemporary
(
data
.
temporary
);
if
(
data
.
persistData
&&
database
.
isPersistent
())
{
mainIndex
=
new
PageDataIndex
(
this
,
data
.
id
,
IndexColumn
.
wrap
(
cols
),
IndexType
.
createScan
(
data
.
persistData
),
data
.
headPos
,
data
.
session
);
mainIndex
=
new
PageDataIndex
(
this
,
data
.
id
,
IndexColumn
.
wrap
(
cols
),
IndexType
.
createScan
(
data
.
persistData
),
data
.
create
,
data
.
session
);
scanIndex
=
mainIndex
;
}
else
{
scanIndex
=
new
ScanIndex
(
this
,
data
.
id
,
IndexColumn
.
wrap
(
cols
),
IndexType
.
createScan
(
data
.
persistData
));
...
...
@@ -91,10 +90,6 @@ public class TableData extends Table {
traceLock
=
database
.
getTrace
(
Trace
.
LOCK
);
}
public
int
getHeadPos
()
{
return
scanIndex
.
getHeadPos
();
}
public
void
close
(
Session
session
)
throws
SQLException
{
for
(
Index
index
:
indexes
)
{
index
.
close
(
session
);
...
...
@@ -177,7 +172,7 @@ public class TableData extends Table {
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
indexComment
)
throws
SQLException
{
boolean
create
,
String
indexComment
)
throws
SQLException
{
if
(
indexType
.
isPrimaryKey
())
{
for
(
IndexColumn
c
:
cols
)
{
Column
column
=
c
.
column
;
...
...
@@ -199,9 +194,9 @@ public class TableData extends Table {
}
if
(
mainIndexColumn
!=
-
1
)
{
mainIndex
.
setMainIndexColumn
(
mainIndexColumn
);
index
=
new
PageDelegateIndex
(
this
,
indexId
,
indexName
,
indexType
,
mainIndex
,
headPos
,
session
);
index
=
new
PageDelegateIndex
(
this
,
indexId
,
indexName
,
indexType
,
mainIndex
,
create
,
session
);
}
else
{
index
=
new
PageBtreeIndex
(
this
,
indexId
,
indexName
,
cols
,
indexType
,
headPos
,
session
);
index
=
new
PageBtreeIndex
(
this
,
indexId
,
indexName
,
cols
,
indexType
,
create
,
session
);
}
}
else
{
if
(
indexType
.
isHash
())
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
75e1a835
...
...
@@ -331,7 +331,7 @@ public class TableLink extends Table {
}
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
indexComment
)
throws
SQLException
{
boolean
create
,
String
indexComment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"LINK"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableLinkConnection.java
浏览文件 @
75e1a835
...
...
@@ -11,8 +11,8 @@ import java.sql.SQLException;
import
java.util.HashMap
;
import
org.h2.constant.SysProperties
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -90,10 +90,10 @@ public class TableLinkConnection {
}
public
int
hashCode
()
{
return
Object
Utils
.
hashCode
(
driver
)
^
Object
Utils
.
hashCode
(
url
)
^
Object
Utils
.
hashCode
(
user
)
^
Object
Utils
.
hashCode
(
password
);
return
Byte
Utils
.
hashCode
(
driver
)
^
Byte
Utils
.
hashCode
(
url
)
^
Byte
Utils
.
hashCode
(
user
)
^
Byte
Utils
.
hashCode
(
password
);
}
public
boolean
equals
(
Object
o
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableView.java
浏览文件 @
75e1a835
...
...
@@ -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
indexComment
)
throws
SQLException
{
boolean
create
,
String
indexComment
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
(
"VIEW"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Backup.java
浏览文件 @
75e1a835
...
...
@@ -120,9 +120,6 @@ public class Backup extends Tool {
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
))
{
base
=
FileUtils
.
getParent
(
fileName
);
break
;
}
else
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_DATA_FILE
))
{
base
=
FileUtils
.
getParent
(
fileName
);
break
;
}
}
for
(
String
fileName
:
list
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
75e1a835
差异被折叠。
点击展开。
h2/src/main/org/h2/tools/Shell.java
浏览文件 @
75e1a835
...
...
@@ -25,7 +25,6 @@ import org.h2.engine.Constants;
import
org.h2.server.web.ConnectionInfo
;
import
org.h2.util.ClassUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.JdbcDriverUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
import
org.h2.util.SortedProperties
;
...
...
@@ -355,7 +354,7 @@ public class Shell extends Tool {
print
(
"URL "
);
url
=
readLine
(
url
);
if
(
driver
==
null
)
{
driver
=
Jdbc
Driver
Utils
.
getDriver
(
url
);
driver
=
JdbcUtils
.
getDriver
(
url
);
}
if
(
driver
!=
null
)
{
println
(
"[Enter] "
+
driver
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/ByteUtils.java
浏览文件 @
75e1a835
...
...
@@ -6,6 +6,10 @@
*/
package
org
.
h2
.
util
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
...
...
@@ -267,4 +271,49 @@ public class ByteUtils {
return
copy
;
}
/**
* Serialize the object to a byte array.
*
* @param obj the object to serialize
* @return the byte array
*/
public
static
byte
[]
serialize
(
Object
obj
)
throws
SQLException
{
try
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ObjectOutputStream
os
=
new
ObjectOutputStream
(
out
);
os
.
writeObject
(
obj
);
return
out
.
toByteArray
();
}
catch
(
Throwable
e
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
SERIALIZATION_FAILED_1
,
e
,
e
.
toString
());
}
}
/**
* De-serialize the byte array to an object.
*
* @param data the byte array
* @return the object
* @throws SQLException
*/
public
static
Object
deserialize
(
byte
[]
data
)
throws
SQLException
{
try
{
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
data
);
ObjectInputStream
is
=
new
ObjectInputStream
(
in
);
Object
obj
=
is
.
readObject
();
return
obj
;
}
catch
(
Throwable
e
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
DESERIALIZATION_FAILED_1
,
e
,
e
.
toString
());
}
}
/**
* Calculate the hash code of the given object. The object may be null.
*
* @param o the object
* @return the hash code, or 0 if the object is null
*/
public
static
int
hashCode
(
Object
o
)
{
return
o
==
null
?
0
:
o
.
hashCode
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/DateTimeIso8601Utils.java
deleted
100644 → 0
浏览文件 @
96cf5428
/*
* Copyright 2004-2010 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: Robert Rathsack (firstName dot lastName at gmx dot de)
*/
package
org
.
h2
.
util
;
import
java.util.Date
;
import
java.util.Calendar
;
/**
* <p>
* Calculate day of week, week of year and year according to the ISO 8601
* specification. See also http://en.wikipedia.org/wiki/ISO_8601
* </p><p>
* The specification defines that the week starts at Monday. The first week of
* the year is defined as the week which contains at least 4 days of the new
* year. Therefore if January 1st is on Thursday (or earlier) it belongs to the
* first week, otherwise to the last week of the previous year. Hence January
* 4th always belongs to the first week while the December 28th always belongs
* to the last week. The year of a date reflects to this corresponding week
* definition.
* </p>
*/
public
class
DateTimeIso8601Utils
{
/**
* Return the day of week. Week starts at Monday.
*
* @param date the date object which day of week should be calculated
* @return the day of the week, Monday as 1 to Sunday as 7
*/
public
static
int
getIsoDayOfWeek
(
Date
date
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTimeInMillis
(
date
.
getTime
());
int
val
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
return
val
==
0
?
7
:
val
;
}
/**
* Returns the week of the year. The spec defines the first week of the year
* as this week which contains at least 4 days. The week starts at Monday.
* Therefore December 29th - 31th could belong to the next year and January
* 1st - 3th could belong to the previous year.
*
* @param date the date object which week of year should be calculated
* @return the week of the year
*/
public
static
int
getIsoWeek
(
Date
date
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTimeInMillis
(
date
.
getTime
());
c
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
c
.
setMinimalDaysInFirstWeek
(
4
);
return
c
.
get
(
Calendar
.
WEEK_OF_YEAR
);
}
/**
* Returns the year according to the ISO week definition.
*
* @param date the date object which year should be calculated
* @return the year
*/
public
static
int
getIsoYear
(
Date
date
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTimeInMillis
(
date
.
getTime
());
cal
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
cal
.
setMinimalDaysInFirstWeek
(
4
);
int
year
=
cal
.
get
(
Calendar
.
YEAR
);
int
month
=
cal
.
get
(
Calendar
.
MONTH
);
int
week
=
cal
.
get
(
Calendar
.
WEEK_OF_YEAR
);
if
(
month
==
0
&&
week
>
51
)
{
year
--;
}
else
if
(
month
==
11
&&
week
==
1
)
{
year
++;
}
return
year
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
75e1a835
...
...
@@ -3,6 +3,8 @@
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Iso8601:
* Initial Developer: Robert Rathsack (firstName dot lastName at gmx dot de)
*/
package
org
.
h2
.
util
;
...
...
@@ -428,4 +430,67 @@ public class DateTimeUtils {
}
}
/**
* Return the day of week according to the ISO 8601 specification. Week
* starts at Monday. See also http://en.wikipedia.org/wiki/ISO_8601
*
* @author Robert Rathsack
*
* @param date the date object which day of week should be calculated
* @return the day of the week, Monday as 1 to Sunday as 7
*/
public
static
int
getIsoDayOfWeek
(
java
.
util
.
Date
date
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTimeInMillis
(
date
.
getTime
());
int
val
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
return
val
==
0
?
7
:
val
;
}
/**
* Returns the week of the year according to the ISO 8601 specification. The
* spec defines the first week of the year as the week which contains at
* least 4 days of the new year. The week starts at Monday. Therefore
* December 29th - 31th could belong to the next year and January 1st - 3th
* could belong to the previous year. If January 1st is on Thursday (or
* earlier) it belongs to the first week, otherwise to the last week of the
* previous year. Hence January 4th always belongs to the first week while
* the December 28th always belongs to the last week.
*
* @author Robert Rathsack
*
* @param date the date object which week of year should be calculated
* @return the week of the year
*/
public
static
int
getIsoWeek
(
java
.
util
.
Date
date
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTimeInMillis
(
date
.
getTime
());
c
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
c
.
setMinimalDaysInFirstWeek
(
4
);
return
c
.
get
(
Calendar
.
WEEK_OF_YEAR
);
}
/**
* Returns the year according to the ISO week definition.
*
* @author Robert Rathsack
*
* @param date the date object which year should be calculated
* @return the year
*/
public
static
int
getIsoYear
(
java
.
util
.
Date
date
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTimeInMillis
(
date
.
getTime
());
cal
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
cal
.
setMinimalDaysInFirstWeek
(
4
);
int
year
=
cal
.
get
(
Calendar
.
YEAR
);
int
month
=
cal
.
get
(
Calendar
.
MONTH
);
int
week
=
cal
.
get
(
Calendar
.
WEEK_OF_YEAR
);
if
(
month
==
0
&&
week
>
51
)
{
year
--;
}
else
if
(
month
==
11
&&
week
==
1
)
{
year
++;
}
return
year
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/JdbcDriverUtils.java
deleted
100644 → 0
浏览文件 @
96cf5428
/*
* Copyright 2004-2010 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
.
util
;
import
java.sql.SQLException
;
/**
* This class tries to automatically load the right JDBC driver for a given
* database URL.
*/
public
class
JdbcDriverUtils
{
private
static
final
String
[]
DRIVERS
=
{
"jdbc:h2:"
,
"org.h2.Driver"
,
"jdbc:Cache:"
,
"com.intersys.jdbc.CacheDriver"
,
"jdbc:daffodilDB://"
,
"in.co.daffodil.db.rmi.RmiDaffodilDBDriver"
,
"jdbc:daffodil"
,
"in.co.daffodil.db.jdbc.DaffodilDBDriver"
,
"jdbc:db2:"
,
"COM.ibm.db2.jdbc.net.DB2Driver"
,
"jdbc:derby:net:"
,
"org.apache.derby.jdbc.ClientDriver"
,
"jdbc:derby://"
,
"org.apache.derby.jdbc.ClientDriver"
,
"jdbc:derby:"
,
"org.apache.derby.jdbc.EmbeddedDriver"
,
"jdbc:FrontBase:"
,
"com.frontbase.jdbc.FBJDriver"
,
"jdbc:firebirdsql:"
,
"org.firebirdsql.jdbc.FBDriver"
,
"jdbc:hsqldb:"
,
"org.hsqldb.jdbcDriver"
,
"jdbc:informix-sqli:"
,
"com.informix.jdbc.IfxDriver"
,
"jdbc:jtds:"
,
"net.sourceforge.jtds.jdbc.Driver"
,
"jdbc:microsoft:"
,
"com.microsoft.jdbc.sqlserver.SQLServerDriver"
,
"jdbc:mimer:"
,
"com.mimer.jdbc.Driver"
,
"jdbc:mysql:"
,
"com.mysql.jdbc.Driver"
,
"jdbc:odbc:"
,
"sun.jdbc.odbc.JdbcOdbcDriver"
,
"jdbc:oracle:"
,
"oracle.jdbc.driver.OracleDriver"
,
"jdbc:pervasive:"
,
"com.pervasive.jdbc.v2.Driver"
,
"jdbc:pointbase:micro:"
,
"com.pointbase.me.jdbc.jdbcDriver"
,
"jdbc:pointbase:"
,
"com.pointbase.jdbc.jdbcUniversalDriver"
,
"jdbc:postgresql:"
,
"org.postgresql.Driver"
,
"jdbc:sybase:"
,
"com.sybase.jdbc3.jdbc.SybDriver"
,
"jdbc:sqlserver:"
,
"com.microsoft.sqlserver.jdbc.SQLServerDriver"
,
"jdbc:teradata:"
,
"com.ncr.teradata.TeraDriver"
,
};
private
JdbcDriverUtils
()
{
// utility class
}
/**
* Get the driver class name for the given URL, or null if the URL is
* unknown.
*
* @param url the database URL
* @return the driver class name
*/
public
static
String
getDriver
(
String
url
)
{
for
(
int
i
=
0
;
i
<
DRIVERS
.
length
;
i
+=
2
)
{
String
prefix
=
DRIVERS
[
i
];
if
(
url
.
startsWith
(
prefix
))
{
return
DRIVERS
[
i
+
1
];
}
}
return
null
;
}
/**
* Load the driver class for the given URL, if the database URL is known.
*
* @param url the database URL
*/
public
static
void
load
(
String
url
)
throws
SQLException
{
String
driver
=
getDriver
(
url
);
if
(
driver
!=
null
)
{
ClassUtils
.
loadUserClass
(
driver
);
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/JdbcUtils.java
浏览文件 @
75e1a835
...
...
@@ -25,6 +25,34 @@ import org.h2.message.Message;
*/
public
class
JdbcUtils
{
private
static
final
String
[]
DRIVERS
=
{
"h2:"
,
"org.h2.Driver"
,
"Cache:"
,
"com.intersys.jdbc.CacheDriver"
,
"daffodilDB://"
,
"in.co.daffodil.db.rmi.RmiDaffodilDBDriver"
,
"daffodil"
,
"in.co.daffodil.db.jdbc.DaffodilDBDriver"
,
"db2:"
,
"COM.ibm.db2.jdbc.net.DB2Driver"
,
"derby:net:"
,
"org.apache.derby.jdbc.ClientDriver"
,
"derby://"
,
"org.apache.derby.jdbc.ClientDriver"
,
"derby:"
,
"org.apache.derby.jdbc.EmbeddedDriver"
,
"FrontBase:"
,
"com.frontbase.jdbc.FBJDriver"
,
"firebirdsql:"
,
"org.firebirdsql.jdbc.FBDriver"
,
"hsqldb:"
,
"org.hsqldb.jdbcDriver"
,
"informix-sqli:"
,
"com.informix.jdbc.IfxDriver"
,
"jtds:"
,
"net.sourceforge.jtds.jdbc.Driver"
,
"microsoft:"
,
"com.microsoft.jdbc.sqlserver.SQLServerDriver"
,
"mimer:"
,
"com.mimer.jdbc.Driver"
,
"mysql:"
,
"com.mysql.jdbc.Driver"
,
"odbc:"
,
"sun.jdbc.odbc.JdbcOdbcDriver"
,
"oracle:"
,
"oracle.jdbc.driver.OracleDriver"
,
"pervasive:"
,
"com.pervasive.jdbc.v2.Driver"
,
"pointbase:micro:"
,
"com.pointbase.me.jdbc.jdbcDriver"
,
"pointbase:"
,
"com.pointbase.jdbc.jdbcUniversalDriver"
,
"postgresql:"
,
"org.postgresql.Driver"
,
"sybase:"
,
"com.sybase.jdbc3.jdbc.SybDriver"
,
"sqlserver:"
,
"com.microsoft.sqlserver.jdbc.SQLServerDriver"
,
"teradata:"
,
"com.ncr.teradata.TeraDriver"
,
};
private
JdbcUtils
()
{
// utility class
}
...
...
@@ -134,7 +162,7 @@ public class JdbcUtils {
*/
public
static
Connection
getConnection
(
String
driver
,
String
url
,
Properties
prop
)
throws
SQLException
{
if
(
StringUtils
.
isNullOrEmpty
(
driver
))
{
Jdbc
Driver
Utils
.
load
(
url
);
JdbcUtils
.
load
(
url
);
}
else
{
Class
<
?
>
d
=
ClassUtils
.
loadUserClass
(
driver
);
if
(
java
.
sql
.
Driver
.
class
.
isAssignableFrom
(
d
))
{
...
...
@@ -167,4 +195,36 @@ public class JdbcUtils {
return
DriverManager
.
getConnection
(
url
,
prop
);
}
/**
* Get the driver class name for the given URL, or null if the URL is
* unknown.
*
* @param url the database URL
* @return the driver class name
*/
public
static
String
getDriver
(
String
url
)
{
if
(
url
.
startsWith
(
"jdbc:"
))
{
url
=
url
.
substring
(
"jdbc:"
.
length
());
for
(
int
i
=
0
;
i
<
DRIVERS
.
length
;
i
+=
2
)
{
String
prefix
=
DRIVERS
[
i
];
if
(
url
.
startsWith
(
prefix
))
{
return
DRIVERS
[
i
+
1
];
}
}
}
return
null
;
}
/**
* Load the driver class for the given URL, if the database URL is known.
*
* @param url the database URL
*/
public
static
void
load
(
String
url
)
throws
SQLException
{
String
driver
=
getDriver
(
url
);
if
(
driver
!=
null
)
{
ClassUtils
.
loadUserClass
(
driver
);
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/ObjectArray.java
浏览文件 @
75e1a835
...
...
@@ -227,7 +227,7 @@ public class ObjectArray<T> implements Iterable<T> {
* @return the array
*/
public
T
[]
toArray
(
T
[]
array
)
{
ObjectUtils
.
arrayCopy
(
data
,
array
,
size
);
System
.
arraycopy
(
data
,
0
,
array
,
0
,
size
);
return
array
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/ObjectUtils.java
deleted
100644 → 0
浏览文件 @
96cf5428
/*
* Copyright 2004-2010 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
.
util
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.Message
;
/**
* Utility class for object creation and serialization.
* Starting with Java 1.5, some objects are re-used.
*/
public
class
ObjectUtils
{
/**
* The maximum number of elements to copy using a Java loop. This value was
* found by running tests using the Sun JDK 1.4 and JDK 1.6 on Windows XP.
* The biggest difference is for size smaller than 40 (more than 50% saving).
*/
private
static
final
int
MAX_JAVA_LOOP_COPY
=
50
;
private
ObjectUtils
()
{
// utility class
}
/**
* Serialize the object to a byte array.
*
* @param obj the object to serialize
* @return the byte array
*/
public
static
byte
[]
serialize
(
Object
obj
)
throws
SQLException
{
try
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ObjectOutputStream
os
=
new
ObjectOutputStream
(
out
);
os
.
writeObject
(
obj
);
return
out
.
toByteArray
();
}
catch
(
Throwable
e
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
SERIALIZATION_FAILED_1
,
e
,
e
.
toString
());
}
}
/**
* De-serialize the byte array to an object.
*
* @param data the byte array
* @return the object
* @throws SQLException
*/
public
static
Object
deserialize
(
byte
[]
data
)
throws
SQLException
{
try
{
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
data
);
ObjectInputStream
is
=
new
ObjectInputStream
(
in
);
Object
obj
=
is
.
readObject
();
return
obj
;
}
catch
(
Throwable
e
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
DESERIALIZATION_FAILED_1
,
e
,
e
.
toString
());
}
}
/**
* Copy the elements of the source array to the target array.
* System.arraycopy is used for larger arrays, but for very small arrays it
* is faster to use a regular loop.
*
* @param source the source array
* @param target the target array
* @param size the number of elements to copy
*/
public
static
void
arrayCopy
(
Object
[]
source
,
Object
[]
target
,
int
size
)
{
if
(
size
>
MAX_JAVA_LOOP_COPY
)
{
System
.
arraycopy
(
source
,
0
,
target
,
0
,
size
);
}
else
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
target
[
i
]
=
source
[
i
];
}
}
}
/**
* Calculate the hash code of the given object. The object may be null.
*
* @param o the object
* @return the hash code, or 0 if the object is null
*/
public
static
int
hashCode
(
Object
o
)
{
return
o
==
null
?
0
:
o
.
hashCode
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/SmallMap.java
浏览文件 @
75e1a835
...
...
@@ -17,6 +17,7 @@ import org.h2.message.Message;
* A simple hash table with an optimization for the last recently used object.
*/
public
class
SmallMap
{
private
HashMap
<
Integer
,
Object
>
map
=
New
.
hashMap
();
private
Object
cache
;
private
int
cacheId
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/DataType.java
浏览文件 @
75e1a835
...
...
@@ -30,8 +30,8 @@ import org.h2.jdbc.JdbcBlob;
import
org.h2.jdbc.JdbcClob
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.message.Message
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.New
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -827,7 +827,7 @@ public class DataType {
return
ValueNull
.
INSTANCE
;
}
if
(
type
==
Value
.
JAVA_OBJECT
)
{
return
ValueJavaObject
.
getNoCopy
(
Object
Utils
.
serialize
(
x
));
return
ValueJavaObject
.
getNoCopy
(
Byte
Utils
.
serialize
(
x
));
}
if
(
x
instanceof
String
)
{
return
ValueString
.
get
((
String
)
x
);
...
...
@@ -885,7 +885,7 @@ public class DataType {
}
else
if
(
x
instanceof
Character
)
{
return
ValueStringFixed
.
get
(((
Character
)
x
).
toString
());
}
else
{
return
ValueJavaObject
.
getNoCopy
(
Object
Utils
.
serialize
(
x
));
return
ValueJavaObject
.
getNoCopy
(
Byte
Utils
.
serialize
(
x
));
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueByte.java
浏览文件 @
75e1a835
...
...
@@ -9,7 +9,6 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
...
...
@@ -37,10 +36,7 @@ public class ValueByte extends Value {
public
Value
add
(
Value
v
)
throws
SQLException
{
ValueByte
other
=
(
ValueByte
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(
value
+
other
.
value
);
}
return
ValueByte
.
get
((
byte
)
(
value
+
other
.
value
));
return
checkRange
(
value
+
other
.
value
);
}
private
ValueByte
checkRange
(
int
x
)
throws
SQLException
{
...
...
@@ -55,26 +51,17 @@ public class ValueByte extends Value {
}
public
Value
negate
()
throws
SQLException
{
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(-(
int
)
value
);
}
return
ValueByte
.
get
((
byte
)
(-
value
));
return
checkRange
(-(
int
)
value
);
}
public
Value
subtract
(
Value
v
)
throws
SQLException
{
ValueByte
other
=
(
ValueByte
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(
value
-
other
.
value
);
}
return
ValueByte
.
get
((
byte
)
(
value
-
other
.
value
));
return
checkRange
(
value
-
other
.
value
);
}
public
Value
multiply
(
Value
v
)
throws
SQLException
{
ValueByte
other
=
(
ValueByte
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(
value
*
other
.
value
);
}
return
ValueByte
.
get
((
byte
)
(
value
*
other
.
value
));
return
checkRange
(
value
*
other
.
value
);
}
public
Value
divide
(
Value
v
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueInt.java
浏览文件 @
75e1a835
...
...
@@ -9,7 +9,6 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
...
...
@@ -67,10 +66,7 @@ public class ValueInt extends Value {
public
Value
add
(
Value
v
)
throws
SQLException
{
ValueInt
other
=
(
ValueInt
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
((
long
)
value
+
(
long
)
other
.
value
);
}
return
ValueInt
.
get
(
value
+
other
.
value
);
return
checkRange
((
long
)
value
+
(
long
)
other
.
value
);
}
private
ValueInt
checkRange
(
long
x
)
throws
SQLException
{
...
...
@@ -85,26 +81,17 @@ public class ValueInt extends Value {
}
public
Value
negate
()
throws
SQLException
{
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(-(
long
)
value
);
}
return
ValueInt
.
get
(-
value
);
return
checkRange
(-(
long
)
value
);
}
public
Value
subtract
(
Value
v
)
throws
SQLException
{
ValueInt
other
=
(
ValueInt
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
((
long
)
value
-
(
long
)
other
.
value
);
}
return
ValueInt
.
get
(
value
-
other
.
value
);
return
checkRange
((
long
)
value
-
(
long
)
other
.
value
);
}
public
Value
multiply
(
Value
v
)
throws
SQLException
{
ValueInt
other
=
(
ValueInt
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
((
long
)
value
*
(
long
)
other
.
value
);
}
return
ValueInt
.
get
(
value
*
other
.
value
);
return
checkRange
((
long
)
value
*
(
long
)
other
.
value
);
}
public
Value
divide
(
Value
v
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueJavaObject.java
浏览文件 @
75e1a835
...
...
@@ -11,8 +11,8 @@ import java.sql.SQLException;
import
java.sql.Types
;
import
org.h2.constant.SysProperties
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.ObjectUtils
;
/**
* Implementation of the OBJECT data type.
...
...
@@ -48,7 +48,7 @@ public class ValueJavaObject extends ValueBytesBase {
}
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
Object
obj
=
Object
Utils
.
deserialize
(
getBytesNoCopy
());
Object
obj
=
Byte
Utils
.
deserialize
(
getBytesNoCopy
());
prep
.
setObject
(
parameterIndex
,
obj
,
Types
.
JAVA_OBJECT
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueLong.java
浏览文件 @
75e1a835
...
...
@@ -10,7 +10,6 @@ import java.math.BigInteger;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
...
...
@@ -50,21 +49,18 @@ public class ValueLong extends Value {
public
Value
add
(
Value
v
)
throws
SQLException
{
ValueLong
other
=
(
ValueLong
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
long
result
=
value
+
other
.
value
;
int
sv
=
Long
.
signum
(
value
);
int
so
=
Long
.
signum
(
other
.
value
);
int
sr
=
Long
.
signum
(
result
);
// if the operands have different signs overflow can not occur
// if the operands have the same sign,
// and the result has a different sign, then it is an overflow
// it can not be an overflow when one of the operands is 0
if
(
sv
!=
so
||
sr
==
so
||
sv
==
0
||
so
==
0
)
{
return
ValueLong
.
get
(
result
);
}
throw
getOverflow
();
long
result
=
value
+
other
.
value
;
int
sv
=
Long
.
signum
(
value
);
int
so
=
Long
.
signum
(
other
.
value
);
int
sr
=
Long
.
signum
(
result
);
// if the operands have different signs overflow can not occur
// if the operands have the same sign,
// and the result has a different sign, then it is an overflow
// it can not be an overflow when one of the operands is 0
if
(
sv
!=
so
||
sr
==
so
||
sv
==
0
||
so
==
0
)
{
return
ValueLong
.
get
(
result
);
}
return
ValueLong
.
get
(
value
+
other
.
value
);
throw
getOverflow
(
);
}
public
int
getSignum
()
{
...
...
@@ -72,10 +68,8 @@ public class ValueLong extends Value {
}
public
Value
negate
()
throws
SQLException
{
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
if
(
value
==
Long
.
MIN_VALUE
)
{
throw
getOverflow
();
}
if
(
value
==
Long
.
MIN_VALUE
)
{
throw
getOverflow
();
}
return
ValueLong
.
get
(-
value
);
}
...
...
@@ -86,19 +80,16 @@ public class ValueLong extends Value {
public
Value
subtract
(
Value
v
)
throws
SQLException
{
ValueLong
other
=
(
ValueLong
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
int
sv
=
Long
.
signum
(
value
);
int
so
=
Long
.
signum
(
other
.
value
);
// if the operands have the same sign, then overflow can not occur
// if the second operand is 0, then overflow can not occur
if
(
sv
==
so
||
so
==
0
)
{
return
ValueLong
.
get
(
value
-
other
.
value
);
}
// now, if the other value is Long.MIN_VALUE, it must be an overflow
// x - Long.MIN_VALUE overflows for x>=0
return
add
(
other
.
negate
());
int
sv
=
Long
.
signum
(
value
);
int
so
=
Long
.
signum
(
other
.
value
);
// if the operands have the same sign, then overflow can not occur
// if the second operand is 0, then overflow can not occur
if
(
sv
==
so
||
so
==
0
)
{
return
ValueLong
.
get
(
value
-
other
.
value
);
}
return
ValueLong
.
get
(
value
-
other
.
value
);
// now, if the other value is Long.MIN_VALUE, it must be an overflow
// x - Long.MIN_VALUE overflows for x>=0
return
add
(
other
.
negate
());
}
private
boolean
isInteger
(
long
a
)
{
...
...
@@ -107,28 +98,25 @@ public class ValueLong extends Value {
public
Value
multiply
(
Value
v
)
throws
SQLException
{
ValueLong
other
=
(
ValueLong
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
long
result
=
value
*
other
.
value
;
if
(
value
==
0
||
value
==
1
||
other
.
value
==
0
||
other
.
value
==
1
)
{
return
ValueLong
.
get
(
result
);
}
if
(
isInteger
(
value
)
&&
isInteger
(
other
.
value
))
{
return
ValueLong
.
get
(
result
);
}
// just checking one case is not enough: Long.MIN_VALUE * -1
// probably this is correct but I'm not sure
// if(result / value == other.value && result / other.value == value) {
// return ValueLong.get(result);
//}
BigInteger
bv
=
BigInteger
.
valueOf
(
value
);
BigInteger
bo
=
BigInteger
.
valueOf
(
other
.
value
);
BigInteger
br
=
bv
.
multiply
(
bo
);
if
(
br
.
compareTo
(
MIN
)
<
0
||
br
.
compareTo
(
MAX
)
>
0
)
{
throw
getOverflow
();
}
return
ValueLong
.
get
(
br
.
longValue
());
long
result
=
value
*
other
.
value
;
if
(
value
==
0
||
value
==
1
||
other
.
value
==
0
||
other
.
value
==
1
)
{
return
ValueLong
.
get
(
result
);
}
if
(
isInteger
(
value
)
&&
isInteger
(
other
.
value
))
{
return
ValueLong
.
get
(
result
);
}
// just checking one case is not enough: Long.MIN_VALUE * -1
// probably this is correct but I'm not sure
// if(result / value == other.value && result / other.value == value) {
// return ValueLong.get(result);
//}
BigInteger
bv
=
BigInteger
.
valueOf
(
value
);
BigInteger
bo
=
BigInteger
.
valueOf
(
other
.
value
);
BigInteger
br
=
bv
.
multiply
(
bo
);
if
(
br
.
compareTo
(
MIN
)
<
0
||
br
.
compareTo
(
MAX
)
>
0
)
{
throw
getOverflow
();
}
return
ValueLong
.
get
(
value
*
other
.
value
);
return
ValueLong
.
get
(
br
.
longValue
()
);
}
public
Value
divide
(
Value
v
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueShort.java
浏览文件 @
75e1a835
...
...
@@ -9,7 +9,6 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
...
...
@@ -37,10 +36,7 @@ public class ValueShort extends Value {
public
Value
add
(
Value
v
)
throws
SQLException
{
ValueShort
other
=
(
ValueShort
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(
value
+
other
.
value
);
}
return
ValueShort
.
get
((
short
)
(
value
+
other
.
value
));
return
checkRange
(
value
+
other
.
value
);
}
private
ValueShort
checkRange
(
int
x
)
throws
SQLException
{
...
...
@@ -55,26 +51,17 @@ public class ValueShort extends Value {
}
public
Value
negate
()
throws
SQLException
{
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(-(
int
)
value
);
}
return
ValueShort
.
get
((
short
)
(-
value
));
return
checkRange
(-(
int
)
value
);
}
public
Value
subtract
(
Value
v
)
throws
SQLException
{
ValueShort
other
=
(
ValueShort
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(
value
-
other
.
value
);
}
return
ValueShort
.
get
((
short
)
(
value
-
other
.
value
));
return
checkRange
(
value
-
other
.
value
);
}
public
Value
multiply
(
Value
v
)
throws
SQLException
{
ValueShort
other
=
(
ValueShort
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
return
checkRange
(
value
*
other
.
value
);
}
return
ValueShort
.
get
((
short
)
(
value
*
other
.
value
));
return
checkRange
(
value
*
other
.
value
);
}
public
Value
divide
(
Value
v
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
75e1a835
...
...
@@ -287,24 +287,27 @@ java org.h2.test.TestAll timer
/*
Constants.FILE_BLOCK_SIZE and others
simplify SysProperties
combine small classes (StringCache / utils...)
document in performance section:
PreparedStatement prep = conn.prepareStatement(
"select * from table(x int = ?) t inner join test on t.x = test.id");
prep.setObject(1, new Object[] { "1", "2" });
ResultSet rs = prep.executeQuery();
remove Record class; or at least fix javadoc
remove links from Row - Record - Page - DataPage
cleanup SortedProperties
remove unused methods
change test case for migration (download old h2.jar).
move migration to separate classes.
cleanup SortedProperties
headPos > boolean isNew?
verify Row - Page
fix class javadocs
test remote lob (temp file) read write
TestAll deleteIndex
remove DiskFile
move upgrade code from Recover to a separate class
FileStore.sync, Database.sync() (CHECKPOINT SYNC)
data page > buffer
try to reduce number of packages, classes
rename Page classes to normal names
use RuntimeException internally
Verify that Tomcat memory leak protection don't cause exceptions:
http://java.dzone.com/articles/memory-leak-protection-tomcat
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/Db.java
浏览文件 @
75e1a835
...
...
@@ -19,7 +19,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.h2.util.Jdbc
Driver
Utils
;
import
org.h2.util.JdbcUtils
;
/**
* A simple wrapper around the JDBC API.
...
...
@@ -61,7 +61,7 @@ public class Db {
*/
public
static
Db
open
(
String
url
,
String
user
,
String
password
)
{
try
{
Jdbc
Driver
Utils
.
load
(
url
);
JdbcUtils
.
load
(
url
);
return
new
Db
(
DriverManager
.
getConnection
(
url
,
user
,
password
));
}
catch
(
SQLException
e
)
{
throw
convert
(
e
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestLob.java
浏览文件 @
75e1a835
...
...
@@ -28,9 +28,9 @@ import org.h2.store.FileLister;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.ValueLob
;
...
...
@@ -875,7 +875,7 @@ public class TestLob extends TestBase {
conn
.
createStatement
().
execute
(
"drop table test"
);
stat
.
execute
(
"create table test(value other)"
);
prep
=
conn
.
prepareStatement
(
"insert into test values(?)"
);
prep
.
setObject
(
1
,
Object
Utils
.
serialize
(
""
));
prep
.
setObject
(
1
,
Byte
Utils
.
serialize
(
""
));
prep
.
execute
();
rs
=
stat
.
executeQuery
(
"select value from test"
);
while
(
rs
.
next
())
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestReadOnly.java
浏览文件 @
75e1a835
...
...
@@ -13,9 +13,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.store.FileLister
;
import
org.h2.test.TestBase
;
...
...
@@ -135,29 +133,13 @@ public class TestReadOnly extends TestBase {
}
private
void
setReadOnly
()
throws
SQLException
{
String
lastLogFile
=
null
;
ArrayList
<
String
>
list
=
FileLister
.
getDatabaseFiles
(
TestBase
.
baseDir
,
"readonly"
,
true
);
for
(
String
fileName
:
list
)
{
File
file
=
new
File
(
fileName
);
file
.
setReadOnly
();
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_LOG_FILE
))
{
if
(
lastLogFile
==
null
||
lastLogFile
.
compareTo
(
fileName
)
<
0
)
{
lastLogFile
=
fileName
;
}
}
}
// delete all log files except the last one
for
(
String
fileName
:
list
)
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_LOG_FILE
))
{
if
(!
lastLogFile
.
equals
(
fileName
))
{
File
file
=
new
File
(
fileName
);
file
.
delete
();
}
}
}
}
private
void
testReadOnlyConnect
()
throws
SQLException
{
deleteDb
(
"readonly"
);
Connection
conn
=
getConnection
(
"readonly;OPEN_NEW=TRUE"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestDataPage.java
浏览文件 @
75e1a835
...
...
@@ -13,7 +13,6 @@ import java.sql.Time;
import
java.sql.Timestamp
;
import
org.h2.store.Data
;
import
org.h2.store.DataHandler
;
import
org.h2.store.DataPage
;
import
org.h2.store.FileStore
;
import
org.h2.test.TestBase
;
import
org.h2.util.SmallLRUCache
;
...
...
@@ -210,13 +209,14 @@ public class TestDataPage extends TestBase implements DataHandler {
private
void
testAll
()
throws
SQLException
{
Data
Page
page
=
DataPage
.
create
(
this
,
128
);
Data
page
=
Data
.
create
(
this
,
128
);
char
[]
data
=
new
char
[
0x10000
];
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
data
[
i
]
=
(
char
)
i
;
}
String
s
=
new
String
(
data
);
page
.
checkCapacity
(
s
.
length
()
*
4
);
page
.
writeString
(
s
);
int
len
=
page
.
length
();
assertEquals
(
len
,
page
.
getStringLen
(
s
));
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestDateIso8601.java
浏览文件 @
75e1a835
...
...
@@ -12,7 +12,7 @@ import java.text.SimpleDateFormat;
import
java.util.Date
;
import
org.h2.test.TestBase
;
import
org.h2.util.DateTime
Iso8601
Utils
;
import
org.h2.util.DateTimeUtils
;
/**
* Test cases for DateTimeIso8601Utils.
...
...
@@ -53,7 +53,7 @@ public class TestDateIso8601 extends TestBase {
}
private
static
int
getIsoDayOfWeek
(
Date
date
)
{
return
DateTime
Iso8601
Utils
.
getIsoDayOfWeek
(
date
);
return
DateTimeUtils
.
getIsoDayOfWeek
(
date
);
}
/**
...
...
@@ -71,7 +71,7 @@ public class TestDateIso8601 extends TestBase {
private
static
int
getIsoWeek
(
Date
date
)
{
Timestamp
ts
=
new
Timestamp
(
date
.
getTime
());
return
DateTime
Iso8601
Utils
.
getIsoWeek
(
ts
);
return
DateTimeUtils
.
getIsoWeek
(
ts
);
}
/**
...
...
@@ -155,7 +155,7 @@ public class TestDateIso8601 extends TestBase {
private
static
int
getIsoYear
(
Date
date
)
{
Timestamp
ts
=
new
Timestamp
(
date
.
getTime
());
return
DateTime
Iso8601
Utils
.
getIsoYear
(
ts
);
return
DateTimeUtils
.
getIsoYear
(
ts
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestOverflow.java
浏览文件 @
75e1a835
...
...
@@ -10,8 +10,6 @@ import java.math.BigInteger;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.Random
;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestBase
;
import
org.h2.util.New
;
import
org.h2.value.Value
;
...
...
@@ -78,7 +76,7 @@ public class TestOverflow extends TestBase {
}
private
void
onSuccess
()
{
if
(!
successExpected
&&
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
if
(!
successExpected
)
{
fail
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestPageStore.java
浏览文件 @
75e1a835
...
...
@@ -42,7 +42,6 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
testReverseIndex
();
testLargeUpdates
();
testLargeInserts
();
testAutoConvert
();
testLargeDatabaseFastOpen
();
testUniqueIndexReopen
();
testExistingOld
();
...
...
@@ -203,54 +202,6 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
conn
.
close
();
}
private
void
testAutoConvert
()
throws
SQLException
{
if
(
true
)
{
// can't currently create a database in non-pageStore format
return
;
}
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"pageStore"
);
Connection
conn
;
conn
=
getConnection
(
"pageStore"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, data clob)"
);
stat
.
execute
(
"insert into test select x, space(10000) from system_range(1, 2)"
);
stat
.
execute
(
"checkpoint"
);
stat
.
execute
(
"set write_delay 0"
);
stat
.
execute
(
"insert into test select x, 'empty' from system_range(10, 20)"
);
stat
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
// ignore
}
// a database that was not closed normally can't be converted
try
{
getConnection
(
"pageStore"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
// now open and close the database normally
conn
=
getConnection
(
"pageStore"
);
conn
.
close
();
// convert it
conn
=
getConnection
(
"pageStore"
);
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test order by id"
);
while
(
rs
.
next
())
{
rs
.
getString
(
1
);
rs
.
getString
(
2
);
}
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testLargeDatabaseFastOpen
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
75e1a835
...
...
@@ -22,7 +22,6 @@ import java.sql.Types;
import
java.util.ArrayList
;
import
java.util.Random
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.store.FileLister
;
import
org.h2.test.TestBase
;
import
org.h2.test.trace.Player
;
...
...
@@ -36,6 +35,7 @@ import org.h2.tools.RunScript;
import
org.h2.tools.Script
;
import
org.h2.tools.Server
;
import
org.h2.util.FileUtils
;
import
org.h2.util.JdbcUtils
;
/**
* Tests the database tools.
...
...
@@ -58,6 +58,7 @@ public class TestTools extends TestBase {
return
;
}
org
.
h2
.
Driver
.
load
();
testJdbcDriverUtils
();
testWrongServer
();
deleteDb
(
"utils"
);
testDeleteFiles
();
...
...
@@ -75,6 +76,12 @@ public class TestTools extends TestBase {
deleteDb
(
"utils"
);
}
private
void
testJdbcDriverUtils
()
{
assertEquals
(
"org.h2.Driver"
,
JdbcUtils
.
getDriver
(
"jdbc:h2:~/test"
));
assertEquals
(
"org.postgresql.Driver"
,
JdbcUtils
.
getDriver
(
"jdbc:postgresql:test"
));
assertEquals
(
null
,
JdbcUtils
.
getDriver
(
"jdbc:unknown:test"
));
}
private
void
testWrongServer
()
throws
Exception
{
final
ServerSocket
serverSocket
=
new
ServerSocket
(
9001
);
Thread
thread
=
new
Thread
()
{
...
...
@@ -283,12 +290,6 @@ public class TestTools extends TestBase {
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"insert into test values(1, 'Hello')"
);
conn
.
close
();
ArrayList
<
String
>
list
=
FileLister
.
getDatabaseFiles
(
baseDir
,
"toolsRemove"
,
true
);
for
(
String
fileName
:
list
)
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_LOG_FILE
))
{
FileUtils
.
delete
(
fileName
);
}
}
Recover
.
main
(
"-dir"
,
baseDir
,
"-db"
,
"toolsRemove"
,
"-removePassword"
);
conn
=
DriverManager
.
getConnection
(
url
,
"sa"
,
""
);
stat
=
conn
.
createStatement
();
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论