Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e2893192
提交
e2893192
authored
2月 04, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused code.
上级
75e1a835
隐藏空白字符变更
内嵌
并排
正在显示
47 个修改的文件
包含
367 行增加
和
404 行删除
+367
-404
changelog.html
h2/src/docsrc/html/changelog.html
+4
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+5
-2
ScriptBase.java
h2/src/main/org/h2/command/dml/ScriptBase.java
+8
-3
Constants.java
h2/src/main/org/h2/engine/Constants.java
+3
-129
Database.java
h2/src/main/org/h2/engine/Database.java
+14
-8
MetaRecord.java
h2/src/main/org/h2/engine/MetaRecord.java
+16
-21
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+1
-1
JdbcBlob.java
h2/src/main/org/h2/jdbc/JdbcBlob.java
+2
-2
JdbcClob.java
h2/src/main/org/h2/jdbc/JdbcClob.java
+2
-2
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+6
-4
JdbcConnectionPool.java
h2/src/main/org/h2/jdbcx/JdbcConnectionPool.java
+15
-16
UndoLog.java
h2/src/main/org/h2/log/UndoLog.java
+1
-2
ResultDiskBuffer.java
h2/src/main/org/h2/result/ResultDiskBuffer.java
+1
-1
RowList.java
h2/src/main/org/h2/result/RowList.java
+1
-1
TcpServer.java
h2/src/main/org/h2/server/TcpServer.java
+9
-9
ConnectionInfo.java
h2/src/main/org/h2/server/web/ConnectionInfo.java
+6
-1
WebApp.java
h2/src/main/org/h2/server/web/WebApp.java
+1
-1
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+8
-10
Data.java
h2/src/main/org/h2/store/Data.java
+0
-1
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+44
-47
FileStore.java
h2/src/main/org/h2/store/FileStore.java
+7
-8
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+4
-2
Backup.java
h2/src/main/org/h2/tools/Backup.java
+2
-2
ChangeFileEncryption.java
h2/src/main/org/h2/tools/ChangeFileEncryption.java
+2
-2
Console.java
h2/src/main/org/h2/tools/Console.java
+89
-23
ConvertTraceFile.java
h2/src/main/org/h2/tools/ConvertTraceFile.java
+2
-2
CreateCluster.java
h2/src/main/org/h2/tools/CreateCluster.java
+2
-2
DeleteDbFiles.java
h2/src/main/org/h2/tools/DeleteDbFiles.java
+2
-2
MultiDimension.java
h2/src/main/org/h2/tools/MultiDimension.java
+6
-6
Recover.java
h2/src/main/org/h2/tools/Recover.java
+6
-6
Restore.java
h2/src/main/org/h2/tools/Restore.java
+2
-2
RunScript.java
h2/src/main/org/h2/tools/RunScript.java
+2
-2
Script.java
h2/src/main/org/h2/tools/Script.java
+2
-2
Server.java
h2/src/main/org/h2/tools/Server.java
+11
-16
Shell.java
h2/src/main/org/h2/tools/Shell.java
+26
-25
MathUtils.java
h2/src/main/org/h2/util/MathUtils.java
+7
-3
Profiler.java
h2/src/main/org/h2/util/Profiler.java
+30
-19
RandomUtils.java
h2/src/main/org/h2/util/RandomUtils.java
+1
-0
SortedProperties.java
h2/src/main/org/h2/util/SortedProperties.java
+6
-8
Tool.java
h2/src/main/org/h2/util/Tool.java
+1
-1
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+1
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-1
TestShell.java
h2/src/test/org/h2/test/unit/TestShell.java
+1
-1
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+1
-1
FtpServer.java
h2/src/tools/org/h2/dev/ftp/server/FtpServer.java
+2
-2
FileViewer.java
h2/src/tools/org/h2/dev/util/FileViewer.java
+2
-2
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
e2893192
...
@@ -18,7 +18,10 @@ Change Log
...
@@ -18,7 +18,10 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The database URL option ACCESS_MODE_LOG is no longer supported.
<ul><li>
Tools: the method run(String... args) has been renamed to runTool(String... args)
so it can't be confused with run().
</li><li>
Server.startWebServer(Connection) was not working as expected.
</li><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>
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>
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.overflowExceptions" is no longer supported.
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e2893192
...
@@ -3510,7 +3510,7 @@ public class Parser {
...
@@ -3510,7 +3510,7 @@ public class Parser {
}
else
if
(
readIf
(
"TABLE"
))
{
}
else
if
(
readIf
(
"TABLE"
))
{
int
defaultMode
;
int
defaultMode
;
Setting
setting
=
database
.
findSetting
(
SetTypes
.
getTypeName
(
SetTypes
.
DEFAULT_TABLE_TYPE
));
Setting
setting
=
database
.
findSetting
(
SetTypes
.
getTypeName
(
SetTypes
.
DEFAULT_TABLE_TYPE
));
defaultMode
=
setting
==
null
?
Constants
.
DEFAULT_TABLE_TYPE
:
setting
.
getIntValue
();
defaultMode
=
setting
==
null
?
Table
.
TYPE_CACHED
:
setting
.
getIntValue
();
return
parseCreateTable
(
false
,
false
,
defaultMode
==
Table
.
TYPE_CACHED
);
return
parseCreateTable
(
false
,
false
,
defaultMode
==
Table
.
TYPE_CACHED
);
}
else
if
(
readIf
(
"VIEW"
))
{
}
else
if
(
readIf
(
"VIEW"
))
{
return
parseCreateView
(
force
);
return
parseCreateView
(
force
);
...
...
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
e2893192
...
@@ -8,7 +8,6 @@ package org.h2.command.ddl;
...
@@ -8,7 +8,6 @@ package org.h2.command.ddl;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultInterface
;
...
@@ -23,7 +22,11 @@ import org.h2.util.StatementBuilder;
...
@@ -23,7 +22,11 @@ import org.h2.util.StatementBuilder;
*/
*/
public
class
Analyze
extends
DefineCommand
{
public
class
Analyze
extends
DefineCommand
{
private
int
sampleRows
=
Constants
.
SELECTIVITY_ANALYZE_SAMPLE_ROWS
;
/**
* The sample size.
* The default value is also in the documentation.
*/
private
int
sampleRows
=
10000
;
public
Analyze
(
Session
session
)
{
public
Analyze
(
Session
session
)
{
super
(
session
);
super
(
session
);
...
...
h2/src/main/org/h2/command/dml/ScriptBase.java
浏览文件 @
e2893192
...
@@ -38,6 +38,11 @@ import org.h2.value.Value;
...
@@ -38,6 +38,11 @@ import org.h2.value.Value;
*/
*/
public
abstract
class
ScriptBase
extends
Prepared
implements
DataHandler
{
public
abstract
class
ScriptBase
extends
Prepared
implements
DataHandler
{
/**
* The default name of the script file if .zip compression is used.
*/
private
static
final
String
SCRIPT_SQL
=
"script.sql"
;
/**
/**
* The output stream.
* The output stream.
*/
*/
...
@@ -130,7 +135,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
...
@@ -130,7 +135,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
}
else
{
}
else
{
OutputStream
o
=
FileUtils
.
openFileOutputStream
(
file
,
false
);
OutputStream
o
=
FileUtils
.
openFileOutputStream
(
file
,
false
);
out
=
new
BufferedOutputStream
(
o
,
Constants
.
IO_BUFFER_SIZE
);
out
=
new
BufferedOutputStream
(
o
,
Constants
.
IO_BUFFER_SIZE
);
out
=
CompressTool
.
wrapOutputStream
(
out
,
compressionAlgorithm
,
Constants
.
SCRIPT_SQL
);
out
=
CompressTool
.
wrapOutputStream
(
out
,
compressionAlgorithm
,
SCRIPT_SQL
);
}
}
}
}
...
@@ -153,9 +158,9 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
...
@@ -153,9 +158,9 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
throw
Message
.
convertIOException
(
e
,
file
);
throw
Message
.
convertIOException
(
e
,
file
);
}
}
in
=
new
BufferedInputStream
(
inStream
,
Constants
.
IO_BUFFER_SIZE
);
in
=
new
BufferedInputStream
(
inStream
,
Constants
.
IO_BUFFER_SIZE
);
in
=
CompressTool
.
wrapInputStream
(
in
,
compressionAlgorithm
,
Constants
.
SCRIPT_SQL
);
in
=
CompressTool
.
wrapInputStream
(
in
,
compressionAlgorithm
,
SCRIPT_SQL
);
if
(
in
==
null
)
{
if
(
in
==
null
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_NOT_FOUND_1
,
Constants
.
SCRIPT_SQL
+
" in "
+
file
);
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_NOT_FOUND_1
,
SCRIPT_SQL
+
" in "
+
file
);
}
}
}
}
}
}
...
...
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
e2893192
...
@@ -55,11 +55,6 @@ public class Constants {
...
@@ -55,11 +55,6 @@ public class Constants {
*/
*/
public
static
final
int
VERSION_MINOR
=
2
;
public
static
final
int
VERSION_MINOR
=
2
;
/**
* The version number (major.minor) of this database.
*/
public
static
final
double
VERSION
=
VERSION_MAJOR
+
VERSION_MINOR
/
10
.;
/**
/**
* Constant meaning both numbers and text is allowed in SQL statements.
* Constant meaning both numbers and text is allowed in SQL statements.
*/
*/
...
@@ -76,27 +71,11 @@ public class Constants {
...
@@ -76,27 +71,11 @@ public class Constants {
*/
*/
public
static
final
int
ALLOW_LITERALS_NUMBERS
=
1
;
public
static
final
int
ALLOW_LITERALS_NUMBERS
=
1
;
/**
* Automatically convert large LOB objects to files even if they have been
* set using setBytes.
*/
public
static
final
boolean
AUTO_CONVERT_LOB_TO_FILES
=
true
;
/**
* The maximum scale of a BigDecimal value.
*/
public
static
final
int
BIG_DECIMAL_SCALE_MAX
=
100000
;
/**
/**
* The minimum number of entries to keep in the cache.
* The minimum number of entries to keep in the cache.
*/
*/
public
static
final
int
CACHE_MIN_RECORDS
=
16
;
public
static
final
int
CACHE_MIN_RECORDS
=
16
;
/**
* The name of the character set used in this database.
*/
public
static
final
String
CHARACTER_SET_NAME
=
"Unicode"
;
/**
/**
* The value of the cluster setting if clustering is disabled.
* The value of the cluster setting if clustering is disabled.
*/
*/
...
@@ -121,45 +100,18 @@ public class Constants {
...
@@ -121,45 +100,18 @@ public class Constants {
*/
*/
public
static
final
int
COST_ROW_OFFSET
=
1000
;
public
static
final
int
COST_ROW_OFFSET
=
1000
;
/**
* The default name of the system user. This name is only used as long as
* there is no administrator user registered.
*/
public
static
final
String
DBA_NAME
=
"DBA"
;
/**
/**
* The number of milliseconds after which to check for a deadlock if locking
* The number of milliseconds after which to check for a deadlock if locking
* is not successful.
* is not successful.
*/
*/
public
static
final
int
DEADLOCK_CHECK
=
100
;
public
static
final
int
DEADLOCK_CHECK
=
100
;
/**
* The default value of the ALLOW_LITERALS setting
*/
public
static
final
int
DEFAULT_ALLOW_LITERALS
=
ALLOW_LITERALS_ALL
;
/**
* The default data page size.
*/
public
static
final
int
DEFAULT_DATA_PAGE_SIZE
=
512
;
/**
* If the HTTP server should allow connections from other computers by
* default.
*/
public
static
final
boolean
DEFAULT_HTTP_ALLOW_OTHERS
=
false
;
/**
/**
* The default port number of the HTTP server (for the H2 Console).
* The default port number of the HTTP server (for the H2 Console).
* This value is also in the documentation and in the Server javadoc.
* This value is also in the documentation and in the Server javadoc.
*/
*/
public
static
final
int
DEFAULT_HTTP_PORT
=
8082
;
public
static
final
int
DEFAULT_HTTP_PORT
=
8082
;
/**
* The default SSL setting for the HTTP server.
*/
public
static
final
boolean
DEFAULT_HTTP_SSL
=
false
;
/**
/**
* The default value for the maximum log file size.
* The default value for the maximum log file size.
*/
*/
...
@@ -178,25 +130,15 @@ public class Constants {
...
@@ -178,25 +130,15 @@ public class Constants {
/**
/**
* The default port of the TCP server.
* The default port of the TCP server.
* This port is also used in the documentation.
* This port is also used in the documentation
and in the Server javadoc
.
*/
*/
public
static
final
int
DEFAULT_SERVER_PORT
=
9092
;
public
static
final
int
DEFAULT_TCP_PORT
=
9092
;
/**
* The default table type when creating new tables.
*/
public
static
final
int
DEFAULT_TABLE_TYPE
=
0
;
/**
/**
* The default delay in milliseconds before the log file is written.
* The default delay in milliseconds before the log file is written.
*/
*/
public
static
final
int
DEFAULT_WRITE_DELAY
=
500
;
public
static
final
int
DEFAULT_WRITE_DELAY
=
500
;
/**
* The name of the JDBC driver.
*/
public
static
final
String
DRIVER_NAME
=
"H2 JDBC Driver"
;
/**
/**
* The password is hashed this many times
* The password is hashed this many times
* to slow down dictionary attacks.
* to slow down dictionary attacks.
...
@@ -204,25 +146,10 @@ public class Constants {
...
@@ -204,25 +146,10 @@ public class Constants {
public
static
final
int
ENCRYPTION_KEY_HASH_ITERATIONS
=
1024
;
public
static
final
int
ENCRYPTION_KEY_HASH_ITERATIONS
=
1024
;
/**
/**
* The
'word size' of a file (the minimum allocation size)
.
* The
block of a file. It is also the encryption block size
.
*/
*/
public
static
final
int
FILE_BLOCK_SIZE
=
16
;
public
static
final
int
FILE_BLOCK_SIZE
=
16
;
/**
* The maximum number of bytes a file should be expanded in one step.
*/
public
static
final
int
FILE_MAX_INCREMENT
=
32
*
1024
*
1024
;
/**
* The minimum file size in bytes.
*/
public
static
final
int
FILE_MIN_SIZE
=
128
*
1024
;
/**
* The page size of a file.
*/
public
static
final
int
FILE_PAGE_SIZE
=
8
*
1024
;
/**
/**
* For testing, the lock timeout is smaller than for interactive use cases.
* For testing, the lock timeout is smaller than for interactive use cases.
* This value could be increased to about 5 or 10 seconds.
* This value could be increased to about 5 or 10 seconds.
...
@@ -269,28 +196,6 @@ public class Constants {
...
@@ -269,28 +196,6 @@ public class Constants {
*/
*/
public
static
final
int
LOCK_SLEEP
=
1000
;
public
static
final
int
LOCK_SLEEP
=
1000
;
/**
* The file header used for binary files.
*/
public
static
final
String
MAGIC_FILE_HEADER
=
"-- H2 0.5/B -- "
.
substring
(
0
,
FILE_BLOCK_SIZE
-
1
)
+
"\n"
;
/**
* If old text file headers should be supported. This setting can be removed
* in future versions (required for compatibility with version 1.1.103).
*/
public
static
final
boolean
MAGIC_FILE_HEADER_SUPPORT_TEXT
=
true
;
/**
* The name of the in-memory management database used by the TCP server
* to keep the active sessions.
*/
public
static
final
String
MANAGEMENT_DB_PREFIX
=
"management_db_"
;
/**
* The user name of the management database.
*/
public
static
final
String
MANAGEMENT_DB_USER
=
"sa"
;
/**
/**
* The highest possible parameter index.
* The highest possible parameter index.
*/
*/
...
@@ -317,37 +222,16 @@ public class Constants {
...
@@ -317,37 +222,16 @@ public class Constants {
*/
*/
public
static
final
String
PREFIX_PRIMARY_KEY
=
"PRIMARY_KEY_"
;
public
static
final
String
PREFIX_PRIMARY_KEY
=
"PRIMARY_KEY_"
;
/**
* The product name. This value must stay like that, see
* http://opensource.atlassian.com/projects/hibernate/browse/HHH-2682
*/
public
static
final
String
PRODUCT_NAME
=
"H2"
;
/**
/**
* Every user belongs to this role.
* Every user belongs to this role.
*/
*/
public
static
final
String
PUBLIC_ROLE_NAME
=
"PUBLIC"
;
public
static
final
String
PUBLIC_ROLE_NAME
=
"PUBLIC"
;
/**
* The name of the schema that contains the information schema tables.
*/
public
static
final
String
SCHEMA_INFORMATION
=
"INFORMATION_SCHEMA"
;
/**
/**
* The name of the default schema.
* The name of the default schema.
*/
*/
public
static
final
String
SCHEMA_MAIN
=
"PUBLIC"
;
public
static
final
String
SCHEMA_MAIN
=
"PUBLIC"
;
/**
* The default name of the script file if .zip compression is used.
*/
public
static
final
String
SCRIPT_SQL
=
"script.sql"
;
/**
* The default sample size for the ANALYZE statement.
*/
public
static
final
int
SELECTIVITY_ANALYZE_SAMPLE_ROWS
=
10000
;
/**
/**
* The default selectivity (used if the selectivity is not calculated).
* The default selectivity (used if the selectivity is not calculated).
*/
*/
...
@@ -363,11 +247,6 @@ public class Constants {
...
@@ -363,11 +247,6 @@ public class Constants {
*/
*/
public
static
final
String
SERVER_PROPERTIES_FILE
=
".h2.server.properties"
;
public
static
final
String
SERVER_PROPERTIES_FILE
=
".h2.server.properties"
;
/**
* The title of the server properties file.
*/
public
static
final
String
SERVER_PROPERTIES_TITLE
=
"H2 Server Properties"
;
/**
/**
* Queries that take longer than this number of milliseconds are written to
* Queries that take longer than this number of milliseconds are written to
* the trace file with the level info.
* the trace file with the level info.
...
@@ -411,11 +290,6 @@ public class Constants {
...
@@ -411,11 +290,6 @@ public class Constants {
*/
*/
public
static
final
String
SUFFIX_TRACE_FILE
=
".trace.db"
;
public
static
final
String
SUFFIX_TRACE_FILE
=
".trace.db"
;
/**
* The table name suffix used to create internal temporary tables.
*/
public
static
final
String
TEMP_TABLE_PREFIX
=
"TEMP_TABLE_"
;
/**
/**
* The delay that is to be used if throttle has been enabled.
* The delay that is to be used if throttle has been enabled.
*/
*/
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
e2893192
...
@@ -78,6 +78,12 @@ public class Database implements DataHandler {
...
@@ -78,6 +78,12 @@ public class Database implements DataHandler {
private
static
int
initialPowerOffCount
;
private
static
int
initialPowerOffCount
;
/**
* The default name of the system user. This name is only used as long as
* there is no administrator user registered.
*/
private
static
final
String
SYSTEM_USER_NAME
=
"DBA"
;
private
final
boolean
persistent
;
private
final
boolean
persistent
;
private
final
String
databaseName
;
private
final
String
databaseName
;
private
final
String
databaseShortName
;
private
final
String
databaseShortName
;
...
@@ -127,7 +133,7 @@ public class Database implements DataHandler {
...
@@ -127,7 +133,7 @@ public class Database implements DataHandler {
private
int
maxMemoryUndo
=
SysProperties
.
DEFAULT_MAX_MEMORY_UNDO
;
private
int
maxMemoryUndo
=
SysProperties
.
DEFAULT_MAX_MEMORY_UNDO
;
private
int
lockMode
=
SysProperties
.
DEFAULT_LOCK_MODE
;
private
int
lockMode
=
SysProperties
.
DEFAULT_LOCK_MODE
;
private
int
maxLengthInplaceLob
=
SysProperties
.
DEFAULT_MAX_LENGTH_INPLACE_LOB
;
private
int
maxLengthInplaceLob
=
SysProperties
.
DEFAULT_MAX_LENGTH_INPLACE_LOB
;
private
int
allowLiterals
=
Constants
.
DEFAULT_ALLOW_LITERALS
;
private
int
allowLiterals
=
Constants
.
ALLOW_LITERALS_ALL
;
private
int
powerOffCount
=
initialPowerOffCount
;
private
int
powerOffCount
=
initialPowerOffCount
;
private
int
closeDelay
;
private
int
closeDelay
;
...
@@ -544,9 +550,9 @@ public class Database implements DataHandler {
...
@@ -544,9 +550,9 @@ public class Database implements DataHandler {
traceSystem
=
new
TraceSystem
(
null
);
traceSystem
=
new
TraceSystem
(
null
);
log
=
new
LogSystem
(
null
,
false
,
null
);
log
=
new
LogSystem
(
null
,
false
,
null
);
}
}
systemUser
=
new
User
(
this
,
0
,
Constants
.
DBA
_NAME
,
true
);
systemUser
=
new
User
(
this
,
0
,
SYSTEM_USER
_NAME
,
true
);
mainSchema
=
new
Schema
(
this
,
0
,
Constants
.
SCHEMA_MAIN
,
systemUser
,
true
);
mainSchema
=
new
Schema
(
this
,
0
,
Constants
.
SCHEMA_MAIN
,
systemUser
,
true
);
infoSchema
=
new
Schema
(
this
,
-
1
,
Constants
.
SCHEMA_INFORMATION
,
systemUser
,
true
);
infoSchema
=
new
Schema
(
this
,
-
1
,
"INFORMATION_SCHEMA"
,
systemUser
,
true
);
schemas
.
put
(
mainSchema
.
getName
(),
mainSchema
);
schemas
.
put
(
mainSchema
.
getName
(),
mainSchema
);
schemas
.
put
(
infoSchema
.
getName
(),
infoSchema
);
schemas
.
put
(
infoSchema
.
getName
(),
infoSchema
);
publicRole
=
new
Role
(
this
,
0
,
Constants
.
PUBLIC_ROLE_NAME
,
true
);
publicRole
=
new
Role
(
this
,
0
,
Constants
.
PUBLIC_ROLE_NAME
,
true
);
...
@@ -581,13 +587,13 @@ public class Database implements DataHandler {
...
@@ -581,13 +587,13 @@ public class Database implements DataHandler {
Cursor
cursor
=
metaIdIndex
.
find
(
systemSession
,
null
,
null
);
Cursor
cursor
=
metaIdIndex
.
find
(
systemSession
,
null
,
null
);
// first, create all function aliases and sequences because
// first, create all function aliases and sequences because
// they might be used in create table / view / constraints and so on
// they might be used in create table / view / constraints and so on
ObjectArray
<
MetaRecord
>
records
=
ObjectArray
.
newInstance
();
ArrayList
<
MetaRecord
>
records
=
New
.
arrayList
();
while
(
cursor
.
next
())
{
while
(
cursor
.
next
())
{
MetaRecord
rec
=
new
MetaRecord
(
cursor
.
get
());
MetaRecord
rec
=
new
MetaRecord
(
cursor
.
get
());
objectIds
.
set
(
rec
.
getId
());
objectIds
.
set
(
rec
.
getId
());
records
.
add
(
rec
);
records
.
add
(
rec
);
}
}
MetaRecord
.
sort
(
records
);
Collections
.
sort
(
records
);
for
(
MetaRecord
rec
:
records
)
{
for
(
MetaRecord
rec
:
records
)
{
rec
.
execute
(
this
,
systemSession
,
eventListener
);
rec
.
execute
(
this
,
systemSession
,
eventListener
);
}
}
...
@@ -595,7 +601,7 @@ public class Database implements DataHandler {
...
@@ -595,7 +601,7 @@ public class Database implements DataHandler {
recompileInvalidViews
(
systemSession
);
recompileInvalidViews
(
systemSession
);
starting
=
false
;
starting
=
false
;
addDefaultSetting
(
systemSession
,
SetTypes
.
DEFAULT_LOCK_TIMEOUT
,
null
,
Constants
.
INITIAL_LOCK_TIMEOUT
);
addDefaultSetting
(
systemSession
,
SetTypes
.
DEFAULT_LOCK_TIMEOUT
,
null
,
Constants
.
INITIAL_LOCK_TIMEOUT
);
addDefaultSetting
(
systemSession
,
SetTypes
.
DEFAULT_TABLE_TYPE
,
null
,
Constants
.
DEFAULT_TABLE_TYPE
);
addDefaultSetting
(
systemSession
,
SetTypes
.
DEFAULT_TABLE_TYPE
,
null
,
Table
.
TYPE_CACHED
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CACHE_SIZE
,
null
,
SysProperties
.
CACHE_SIZE_DEFAULT
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CACHE_SIZE
,
null
,
SysProperties
.
CACHE_SIZE_DEFAULT
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CLUSTER
,
Constants
.
CLUSTERING_DISABLED
,
0
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CLUSTER
,
Constants
.
CLUSTERING_DISABLED
,
0
);
addDefaultSetting
(
systemSession
,
SetTypes
.
WRITE_DELAY
,
null
,
Constants
.
DEFAULT_WRITE_DELAY
);
addDefaultSetting
(
systemSession
,
SetTypes
.
WRITE_DELAY
,
null
,
Constants
.
DEFAULT_WRITE_DELAY
);
...
@@ -805,7 +811,7 @@ public class Database implements DataHandler {
...
@@ -805,7 +811,7 @@ public class Database implements DataHandler {
HashMap
<
String
,
DbObject
>
map
=
getMap
(
obj
.
getType
());
HashMap
<
String
,
DbObject
>
map
=
getMap
(
obj
.
getType
());
if
(
obj
.
getType
()
==
DbObject
.
USER
)
{
if
(
obj
.
getType
()
==
DbObject
.
USER
)
{
User
user
=
(
User
)
obj
;
User
user
=
(
User
)
obj
;
if
(
user
.
isAdmin
()
&&
systemUser
.
getName
().
equals
(
Constants
.
DBA
_NAME
))
{
if
(
user
.
isAdmin
()
&&
systemUser
.
getName
().
equals
(
SYSTEM_USER
_NAME
))
{
systemUser
.
rename
(
user
.
getName
());
systemUser
.
rename
(
user
.
getName
());
}
}
}
}
...
@@ -1595,7 +1601,7 @@ public class Database implements DataHandler {
...
@@ -1595,7 +1601,7 @@ public class Database implements DataHandler {
public
synchronized
String
getTempTableName
(
Session
session
)
{
public
synchronized
String
getTempTableName
(
Session
session
)
{
String
tempName
;
String
tempName
;
do
{
do
{
tempName
=
Constants
.
TEMP_TABLE_PREFIX
+
session
.
getId
()
+
"_"
+
nextTempTableId
++;
tempName
=
"TEMP_TABLE_"
+
session
.
getId
()
+
"_"
+
nextTempTableId
++;
}
while
(
mainSchema
.
findTableOrView
(
session
,
tempName
)
!=
null
);
}
while
(
mainSchema
.
findTableOrView
(
session
,
tempName
)
!=
null
);
return
tempName
;
return
tempName
;
}
}
...
...
h2/src/main/org/h2/engine/MetaRecord.java
浏览文件 @
e2893192
...
@@ -7,13 +7,11 @@
...
@@ -7,13 +7,11 @@
package
org
.
h2
.
engine
;
package
org
.
h2
.
engine
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Comparator
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.message.Trace
;
import
org.h2.message.Trace
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SearchRow
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueString
;
import
org.h2.value.ValueString
;
...
@@ -21,7 +19,7 @@ import org.h2.value.ValueString;
...
@@ -21,7 +19,7 @@ import org.h2.value.ValueString;
* A record in the system table of the database.
* A record in the system table of the database.
* It contains the SQL statement to create the database object.
* It contains the SQL statement to create the database object.
*/
*/
public
class
MetaRecord
{
public
class
MetaRecord
implements
Comparable
<
MetaRecord
>
{
private
int
id
;
private
int
id
;
private
int
objectType
;
private
int
objectType
;
...
@@ -39,24 +37,6 @@ public class MetaRecord {
...
@@ -39,24 +37,6 @@ public class MetaRecord {
sql
=
obj
.
getCreateSQL
();
sql
=
obj
.
getCreateSQL
();
}
}
/**
* Sort the list of meta records by 'create order'.
*
* @param records the list of meta records
*/
public
static
void
sort
(
ObjectArray
<
MetaRecord
>
records
)
{
records
.
sort
(
new
Comparator
<
MetaRecord
>()
{
public
int
compare
(
MetaRecord
m1
,
MetaRecord
m2
)
{
int
c1
=
DbObjectBase
.
getCreateOrder
(
m1
.
getObjectType
());
int
c2
=
DbObjectBase
.
getCreateOrder
(
m2
.
getObjectType
());
if
(
c1
!=
c2
)
{
return
c1
-
c2
;
}
return
m1
.
getId
()
-
m2
.
getId
();
}
});
}
void
setRecord
(
SearchRow
r
)
{
void
setRecord
(
SearchRow
r
)
{
r
.
setValue
(
0
,
ValueInt
.
get
(
id
));
r
.
setValue
(
0
,
ValueInt
.
get
(
id
));
r
.
setValue
(
1
,
ValueInt
.
get
(
0
));
r
.
setValue
(
1
,
ValueInt
.
get
(
0
));
...
@@ -101,4 +81,19 @@ public class MetaRecord {
...
@@ -101,4 +81,19 @@ public class MetaRecord {
return
sql
;
return
sql
;
}
}
/**
* Sort the list of meta records by 'create order'.
*
* @param other the other record
* @return -1, 0, or 1
*/
public
int
compareTo
(
MetaRecord
other
)
{
int
c1
=
DbObjectBase
.
getCreateOrder
(
getObjectType
());
int
c2
=
DbObjectBase
.
getCreateOrder
(
other
.
getObjectType
());
if
(
c1
!=
c2
)
{
return
c1
-
c2
;
}
return
getId
()
-
other
.
getId
();
}
}
}
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
e2893192
...
@@ -91,7 +91,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
...
@@ -91,7 +91,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
}
}
private
Transfer
initTransfer
(
ConnectionInfo
ci
,
String
db
,
String
server
)
throws
IOException
,
SQLException
{
private
Transfer
initTransfer
(
ConnectionInfo
ci
,
String
db
,
String
server
)
throws
IOException
,
SQLException
{
Socket
socket
=
NetUtils
.
createSocket
(
server
,
Constants
.
DEFAULT_
SERVER
_PORT
,
ci
.
isSSL
());
Socket
socket
=
NetUtils
.
createSocket
(
server
,
Constants
.
DEFAULT_
TCP
_PORT
,
ci
.
isSSL
());
Transfer
trans
=
new
Transfer
(
this
);
Transfer
trans
=
new
Transfer
(
this
);
trans
.
setSocket
(
socket
);
trans
.
setSocket
(
socket
);
trans
.
setSSL
(
ci
.
isSSL
());
trans
.
setSSL
(
ci
.
isSSL
());
...
...
h2/src/main/org/h2/jdbc/JdbcBlob.java
浏览文件 @
e2893192
...
@@ -56,9 +56,9 @@ public class JdbcBlob extends TraceObject implements Blob {
...
@@ -56,9 +56,9 @@ public class JdbcBlob extends TraceObject implements Blob {
long
size
=
0
;
long
size
=
0
;
InputStream
in
=
value
.
getInputStream
();
InputStream
in
=
value
.
getInputStream
();
try
{
try
{
byte
[]
buff
=
new
byte
[
Constants
.
FILE_BLOCK
_SIZE
];
byte
[]
buff
=
new
byte
[
Constants
.
IO_BUFFER
_SIZE
];
while
(
true
)
{
while
(
true
)
{
int
len
=
in
.
read
(
buff
,
0
,
Constants
.
FILE_BLOCK
_SIZE
);
int
len
=
in
.
read
(
buff
,
0
,
Constants
.
IO_BUFFER
_SIZE
);
if
(
len
<=
0
)
{
if
(
len
<=
0
)
{
break
;
break
;
}
}
...
...
h2/src/main/org/h2/jdbc/JdbcClob.java
浏览文件 @
e2893192
...
@@ -63,9 +63,9 @@ public class JdbcClob extends TraceObject implements Clob
...
@@ -63,9 +63,9 @@ public class JdbcClob extends TraceObject implements Clob
Reader
in
=
value
.
getReader
();
Reader
in
=
value
.
getReader
();
try
{
try
{
long
size
=
0
;
long
size
=
0
;
char
[]
buff
=
new
char
[
Constants
.
FILE_BLOCK
_SIZE
];
char
[]
buff
=
new
char
[
Constants
.
IO_BUFFER
_SIZE
];
while
(
true
)
{
while
(
true
)
{
int
len
=
in
.
read
(
buff
,
0
,
Constants
.
FILE_BLOCK
_SIZE
);
int
len
=
in
.
read
(
buff
,
0
,
Constants
.
IO_BUFFER
_SIZE
);
if
(
len
<=
0
)
{
if
(
len
<=
0
)
{
break
;
break
;
}
}
...
...
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
e2893192
...
@@ -58,11 +58,13 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
...
@@ -58,11 +58,13 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
/**
/**
* Gets the database product name.
* Gets the database product name.
*
*
* @return the product name
* @return the product name
("H2")
*/
*/
public
String
getDatabaseProductName
()
{
public
String
getDatabaseProductName
()
{
debugCodeCall
(
"getDatabaseProductName"
);
debugCodeCall
(
"getDatabaseProductName"
);
return
Constants
.
PRODUCT_NAME
;
// This value must stay like that, see
// http://opensource.atlassian.com/projects/hibernate/browse/HHH-2682
return
"H2"
;
}
}
/**
/**
...
@@ -78,11 +80,11 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
...
@@ -78,11 +80,11 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
/**
/**
* Gets the name of the JDBC driver.
* Gets the name of the JDBC driver.
*
*
* @return the driver name
* @return the driver name
("H2 JDBC Driver")
*/
*/
public
String
getDriverName
()
{
public
String
getDriverName
()
{
debugCodeCall
(
"getDriverName"
);
debugCodeCall
(
"getDriverName"
);
return
Constants
.
DRIVER_NAME
;
return
"H2 JDBC Driver"
;
}
}
/**
/**
...
...
h2/src/main/org/h2/jdbcx/JdbcConnectionPool.java
浏览文件 @
e2893192
...
@@ -62,13 +62,12 @@ import org.h2.message.Message;
...
@@ -62,13 +62,12 @@ import org.h2.message.Message;
* (<a href="http://www.source-code.biz">www.source-code.biz</a>)
* (<a href="http://www.source-code.biz">www.source-code.biz</a>)
* @author Thomas Mueller (ported to Java 1.4, some changes)
* @author Thomas Mueller (ported to Java 1.4, some changes)
*/
*/
public
class
JdbcConnectionPool
implements
DataSource
{
public
class
JdbcConnectionPool
implements
DataSource
,
ConnectionEventListener
{
private
static
final
int
DEFAULT_TIMEOUT
=
5
*
60
;
private
static
final
int
DEFAULT_TIMEOUT
=
5
*
60
;
private
final
ConnectionPoolDataSource
dataSource
;
private
final
ConnectionPoolDataSource
dataSource
;
private
final
Stack
<
PooledConnection
>
recycledConnections
=
new
Stack
<
PooledConnection
>();
private
final
Stack
<
PooledConnection
>
recycledConnections
=
new
Stack
<
PooledConnection
>();
private
final
PoolConnectionEventListener
poolConnectionEventListener
=
new
PoolConnectionEventListener
();
private
PrintWriter
logWriter
;
private
PrintWriter
logWriter
;
private
int
maxConnections
=
10
;
private
int
maxConnections
=
10
;
private
int
timeout
=
DEFAULT_TIMEOUT
;
private
int
timeout
=
DEFAULT_TIMEOUT
;
...
@@ -224,7 +223,7 @@ public class JdbcConnectionPool implements DataSource {
...
@@ -224,7 +223,7 @@ public class JdbcConnectionPool implements DataSource {
}
}
Connection
conn
=
pc
.
getConnection
();
Connection
conn
=
pc
.
getConnection
();
activeConnections
++;
activeConnections
++;
pc
.
addConnectionEventListener
(
poolConnectionEventListener
);
pc
.
addConnectionEventListener
(
this
);
return
conn
;
return
conn
;
}
}
...
@@ -288,21 +287,21 @@ public class JdbcConnectionPool implements DataSource {
...
@@ -288,21 +287,21 @@ public class JdbcConnectionPool implements DataSource {
}
}
/**
/**
* This event listener informs the connection pool that about closed and
* INTERNAL
* broken connections.
*/
*/
class
PoolConnectionEventListener
implements
ConnectionEventListener
{
public
void
connectionClosed
(
ConnectionEvent
event
)
{
public
void
connectionClosed
(
ConnectionEvent
event
)
{
PooledConnection
pc
=
(
PooledConnection
)
event
.
getSource
();
PooledConnection
pc
=
(
PooledConnection
)
event
.
getSource
();
pc
.
removeConnectionEventListener
(
this
);
pc
.
removeConnectionEventListener
(
this
);
recycleConnection
(
pc
);
recycleConnection
(
pc
);
}
}
public
void
connectionErrorOccurred
(
ConnectionEvent
event
)
{
/**
PooledConnection
pc
=
(
PooledConnection
)
event
.
getSource
();
* INTERNAL
pc
.
removeConnectionEventListener
(
this
);
*/
disposeConnection
(
pc
);
public
void
connectionErrorOccurred
(
ConnectionEvent
event
)
{
}
PooledConnection
pc
=
(
PooledConnection
)
event
.
getSource
();
pc
.
removeConnectionEventListener
(
this
);
disposeConnection
(
pc
);
}
}
/**
/**
...
...
h2/src/main/org/h2/log/UndoLog.java
浏览文件 @
e2893192
...
@@ -8,7 +8,6 @@ package org.h2.log;
...
@@ -8,7 +8,6 @@ package org.h2.log;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
...
@@ -124,7 +123,7 @@ public class UndoLog {
...
@@ -124,7 +123,7 @@ public class UndoLog {
String
fileName
=
database
.
createTempFile
();
String
fileName
=
database
.
createTempFile
();
file
=
database
.
openFile
(
fileName
,
"rw"
,
false
);
file
=
database
.
openFile
(
fileName
,
"rw"
,
false
);
file
.
seek
(
FileStore
.
HEADER_LENGTH
);
file
.
seek
(
FileStore
.
HEADER_LENGTH
);
rowBuff
=
Data
.
create
(
database
,
Constants
.
DEFAULT_DATA_
PAGE_SIZE
);
rowBuff
=
Data
.
create
(
database
,
SysProperties
.
PAGE_SIZE
);
Data
buff
=
rowBuff
;
Data
buff
=
rowBuff
;
for
(
int
i
=
0
;
i
<
records
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
records
.
size
();
i
++)
{
UndoLogRecord
r
=
records
.
get
(
i
);
UndoLogRecord
r
=
records
.
get
(
i
);
...
...
h2/src/main/org/h2/result/ResultDiskBuffer.java
浏览文件 @
e2893192
...
@@ -64,7 +64,7 @@ class ResultDiskBuffer implements ResultExternal {
...
@@ -64,7 +64,7 @@ class ResultDiskBuffer implements ResultExternal {
this
.
sort
=
sort
;
this
.
sort
=
sort
;
this
.
columnCount
=
columnCount
;
this
.
columnCount
=
columnCount
;
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
rowBuff
=
Data
.
create
(
db
,
Constants
.
DEFAULT_DATA_
PAGE_SIZE
);
rowBuff
=
Data
.
create
(
db
,
SysProperties
.
PAGE_SIZE
);
String
fileName
=
session
.
getDatabase
().
createTempFile
();
String
fileName
=
session
.
getDatabase
().
createTempFile
();
file
=
session
.
getDatabase
().
openFile
(
fileName
,
"rw"
,
false
);
file
=
session
.
getDatabase
().
openFile
(
fileName
,
"rw"
,
false
);
file
.
setCheckedWriting
(
false
);
file
.
setCheckedWriting
(
false
);
...
...
h2/src/main/org/h2/result/RowList.java
浏览文件 @
e2893192
...
@@ -90,7 +90,7 @@ public class RowList {
...
@@ -90,7 +90,7 @@ public class RowList {
String
fileName
=
db
.
createTempFile
();
String
fileName
=
db
.
createTempFile
();
file
=
db
.
openFile
(
fileName
,
"rw"
,
false
);
file
=
db
.
openFile
(
fileName
,
"rw"
,
false
);
file
.
seek
(
FileStore
.
HEADER_LENGTH
);
file
.
seek
(
FileStore
.
HEADER_LENGTH
);
rowBuff
=
Data
.
create
(
db
,
Constants
.
DEFAULT_DATA_
PAGE_SIZE
);
rowBuff
=
Data
.
create
(
db
,
SysProperties
.
PAGE_SIZE
);
file
.
seek
(
FileStore
.
HEADER_LENGTH
);
file
.
seek
(
FileStore
.
HEADER_LENGTH
);
}
}
Data
buff
=
rowBuff
;
Data
buff
=
rowBuff
;
...
...
h2/src/main/org/h2/server/TcpServer.java
浏览文件 @
e2893192
...
@@ -41,15 +41,15 @@ import org.h2.util.New;
...
@@ -41,15 +41,15 @@ import org.h2.util.New;
*/
*/
public
class
TcpServer
implements
Service
{
public
class
TcpServer
implements
Service
{
/**
* The default port to use for the TCP server.
* This value is also in the documentation and in the Server javadoc.
*/
public
static
final
int
DEFAULT_PORT
=
9092
;
private
static
final
int
SHUTDOWN_NORMAL
=
0
;
private
static
final
int
SHUTDOWN_NORMAL
=
0
;
private
static
final
int
SHUTDOWN_FORCE
=
1
;
private
static
final
int
SHUTDOWN_FORCE
=
1
;
/**
* The name of the in-memory management database used by the TCP server
* to keep the active sessions.
*/
private
static
final
String
MANAGEMENT_DB_PREFIX
=
"management_db_"
;
private
static
final
Map
<
Integer
,
TcpServer
>
SERVERS
=
Collections
.
synchronizedMap
(
new
HashMap
<
Integer
,
TcpServer
>());
private
static
final
Map
<
Integer
,
TcpServer
>
SERVERS
=
Collections
.
synchronizedMap
(
new
HashMap
<
Integer
,
TcpServer
>());
private
int
port
;
private
int
port
;
...
@@ -77,7 +77,7 @@ public class TcpServer implements Service {
...
@@ -77,7 +77,7 @@ public class TcpServer implements Service {
* @return the database name (usually starting with mem:)
* @return the database name (usually starting with mem:)
*/
*/
public
static
String
getManagementDbName
(
int
port
)
{
public
static
String
getManagementDbName
(
int
port
)
{
return
"mem:"
+
Constants
.
MANAGEMENT_DB_PREFIX
+
port
;
return
"mem:"
+
MANAGEMENT_DB_PREFIX
+
port
;
}
}
private
void
initManagementDb
()
throws
SQLException
{
private
void
initManagementDb
()
throws
SQLException
{
...
@@ -144,7 +144,7 @@ public class TcpServer implements Service {
...
@@ -144,7 +144,7 @@ public class TcpServer implements Service {
}
}
public
void
init
(
String
...
args
)
{
public
void
init
(
String
...
args
)
{
port
=
DEFAULT
_PORT
;
port
=
Constants
.
DEFAULT_TCP
_PORT
;
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
String
a
=
args
[
i
];
String
a
=
args
[
i
];
if
(
"-trace"
.
equals
(
a
))
{
if
(
"-trace"
.
equals
(
a
))
{
...
@@ -373,7 +373,7 @@ public class TcpServer implements Service {
...
@@ -373,7 +373,7 @@ public class TcpServer implements Service {
* @param force if the server should be stopped immediately
* @param force if the server should be stopped immediately
*/
*/
public
static
synchronized
void
shutdown
(
String
url
,
String
password
,
boolean
force
)
throws
SQLException
{
public
static
synchronized
void
shutdown
(
String
url
,
String
password
,
boolean
force
)
throws
SQLException
{
int
port
=
Constants
.
DEFAULT_
SERVER
_PORT
;
int
port
=
Constants
.
DEFAULT_
TCP
_PORT
;
int
idx
=
url
.
indexOf
(
':'
,
"jdbc:h2:"
.
length
());
int
idx
=
url
.
indexOf
(
':'
,
"jdbc:h2:"
.
length
());
if
(
idx
>=
0
)
{
if
(
idx
>=
0
)
{
String
p
=
url
.
substring
(
idx
+
1
);
String
p
=
url
.
substring
(
idx
+
1
);
...
...
h2/src/main/org/h2/server/web/ConnectionInfo.java
浏览文件 @
e2893192
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
*/
*/
package
org
.
h2
.
server
.
web
;
package
org
.
h2
.
server
.
web
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
/**
/**
...
@@ -13,7 +14,7 @@ import org.h2.util.StringUtils;
...
@@ -13,7 +14,7 @@ import org.h2.util.StringUtils;
* such as the database URL, user name and password.
* such as the database URL, user name and password.
* This class is used by the H2 Console.
* This class is used by the H2 Console.
*/
*/
public
class
ConnectionInfo
{
public
class
ConnectionInfo
implements
Comparable
<
ConnectionInfo
>
{
/**
/**
* The driver class name.
* The driver class name.
*/
*/
...
@@ -59,4 +60,8 @@ public class ConnectionInfo {
...
@@ -59,4 +60,8 @@ public class ConnectionInfo {
return
StringUtils
.
arrayCombine
(
new
String
[]
{
name
,
driver
,
url
,
user
},
'|'
);
return
StringUtils
.
arrayCombine
(
new
String
[]
{
name
,
driver
,
url
,
user
},
'|'
);
}
}
public
int
compareTo
(
ConnectionInfo
o
)
{
return
MathUtils
.
compare
(
lastAccess
,
o
.
lastAccess
);
}
}
}
h2/src/main/org/h2/server/web/WebApp.java
浏览文件 @
e2893192
...
@@ -358,7 +358,7 @@ public class WebApp implements DatabaseEventListener {
...
@@ -358,7 +358,7 @@ public class WebApp implements DatabaseEventListener {
PrintStream
out
=
new
PrintStream
(
outBuff
,
false
,
"UTF-8"
);
PrintStream
out
=
new
PrintStream
(
outBuff
,
false
,
"UTF-8"
);
tool
.
setOut
(
out
);
tool
.
setOut
(
out
);
try
{
try
{
tool
.
run
(
argList
);
tool
.
run
Tool
(
argList
);
out
.
flush
();
out
.
flush
();
String
o
=
new
String
(
outBuff
.
toByteArray
(),
"UTF-8"
);
String
o
=
new
String
(
outBuff
.
toByteArray
(),
"UTF-8"
);
String
result
=
PageParser
.
escapeHtml
(
o
);
String
result
=
PageParser
.
escapeHtml
(
o
);
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
e2893192
...
@@ -17,7 +17,6 @@ import java.sql.SQLException;
...
@@ -17,7 +17,6 @@ import java.sql.SQLException;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
...
@@ -221,8 +220,8 @@ public class WebServer implements Service {
...
@@ -221,8 +220,8 @@ public class WebServer implements Service {
// TODO web: support using a different properties file
// TODO web: support using a different properties file
Properties
prop
=
loadProperties
();
Properties
prop
=
loadProperties
();
port
=
SortedProperties
.
getIntProperty
(
prop
,
"webPort"
,
Constants
.
DEFAULT_HTTP_PORT
);
port
=
SortedProperties
.
getIntProperty
(
prop
,
"webPort"
,
Constants
.
DEFAULT_HTTP_PORT
);
ssl
=
SortedProperties
.
getBooleanProperty
(
prop
,
"webSSL"
,
Constants
.
DEFAULT_HTTP_SSL
);
ssl
=
SortedProperties
.
getBooleanProperty
(
prop
,
"webSSL"
,
false
);
allowOthers
=
SortedProperties
.
getBooleanProperty
(
prop
,
"webAllowOthers"
,
Constants
.
DEFAULT_HTTP_ALLOW_OTHERS
);
allowOthers
=
SortedProperties
.
getBooleanProperty
(
prop
,
"webAllowOthers"
,
false
);
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
String
a
=
args
[
i
];
String
a
=
args
[
i
];
if
(
"-webPort"
.
equals
(
a
))
{
if
(
"-webPort"
.
equals
(
a
))
{
...
@@ -307,6 +306,10 @@ public class WebServer implements Service {
...
@@ -307,6 +306,10 @@ public class WebServer implements Service {
}
}
}
}
public
boolean
isStopped
()
{
return
serverSocket
==
null
;
}
public
void
stop
()
{
public
void
stop
()
{
if
(
serverSocket
!=
null
)
{
if
(
serverSocket
!=
null
)
{
try
{
try
{
...
@@ -527,12 +530,7 @@ public class WebServer implements Service {
...
@@ -527,12 +530,7 @@ public class WebServer implements Service {
}
else
{
}
else
{
settings
.
addAll
(
connInfoMap
.
values
());
settings
.
addAll
(
connInfoMap
.
values
());
}
}
Collections
.
sort
(
settings
,
new
Comparator
<
ConnectionInfo
>()
{
Collections
.
sort
(
settings
);
public
int
compare
(
ConnectionInfo
o1
,
ConnectionInfo
o2
)
{
return
MathUtils
.
compare
(
o2
.
lastAccess
,
o1
.
lastAccess
);
}
}
);
return
settings
;
return
settings
;
}
}
...
@@ -559,7 +557,7 @@ public class WebServer implements Service {
...
@@ -559,7 +557,7 @@ public class WebServer implements Service {
}
}
}
}
OutputStream
out
=
FileUtils
.
openFileOutputStream
(
getPropertiesFileName
(),
false
);
OutputStream
out
=
FileUtils
.
openFileOutputStream
(
getPropertiesFileName
(),
false
);
prop
.
store
(
out
,
Constants
.
SERVER_PROPERTIES_TITLE
);
prop
.
store
(
out
,
"H2 Server Properties"
);
out
.
close
();
out
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
TraceSystem
.
traceThrowable
(
e
);
TraceSystem
.
traceThrowable
(
e
);
...
...
h2/src/main/org/h2/store/Data.java
浏览文件 @
e2893192
...
@@ -1027,7 +1027,6 @@ public class Data {
...
@@ -1027,7 +1027,6 @@ public class Data {
* until the size is a multiple of Constants.FILE_BLOCK_SIZE.
* until the size is a multiple of Constants.FILE_BLOCK_SIZE.
*/
*/
public
void
fillAligned
()
{
public
void
fillAligned
()
{
// TODO datapage: fillAligned should not use a fixed constant '2'
// 0..6 > 8, 7..14 > 16, 15..22 > 24, ...
// 0..6 > 8, 7..14 > 16, 15..22 > 24, ...
fill
(
MathUtils
.
roundUp
(
pos
+
2
,
Constants
.
FILE_BLOCK_SIZE
));
fill
(
MathUtils
.
roundUp
(
pos
+
2
,
Constants
.
FILE_BLOCK_SIZE
));
}
}
...
...
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
e2893192
...
@@ -35,7 +35,7 @@ import org.h2.value.Transfer;
...
@@ -35,7 +35,7 @@ import org.h2.value.Transfer;
* to it. It uses a cooperative locking protocol. Usually a .lock.db file is
* to it. It uses a cooperative locking protocol. Usually a .lock.db file is
* used, but locking by creating a socket is supported as well.
* used, but locking by creating a socket is supported as well.
*/
*/
public
class
FileLock
{
public
class
FileLock
implements
Runnable
{
/**
/**
* This locking method means no locking is used at all.
* This locking method means no locking is used at all.
...
@@ -68,32 +68,32 @@ public class FileLock {
...
@@ -68,32 +68,32 @@ public class FileLock {
/**
/**
* The lock file name.
* The lock file name.
*/
*/
volatile
String
fileName
;
private
volatile
String
fileName
;
/**
/**
* The server socket (only used when using the SOCKET mode).
* The server socket (only used when using the SOCKET mode).
*/
*/
volatile
ServerSocket
serverSocket
;
private
volatile
ServerSocket
serverSocket
;
/**
/**
* The file system.
* The file system.
*/
*/
FileSystem
fs
;
private
FileSystem
fs
;
/**
/**
* The number of milliseconds to sleep after checking a file.
* The number of milliseconds to sleep after checking a file.
*/
*/
int
sleep
;
private
int
sleep
;
/**
/**
* The trace object.
* The trace object.
*/
*/
Trace
trace
;
private
Trace
trace
;
/**
/**
* The last time the lock file was written.
* The last time the lock file was written.
*/
*/
long
lastWrite
;
private
long
lastWrite
;
private
String
method
,
ipAddress
;
private
String
method
,
ipAddress
;
private
Properties
properties
;
private
Properties
properties
;
...
@@ -220,7 +220,7 @@ public class FileLock {
...
@@ -220,7 +220,7 @@ public class FileLock {
boolean
running
=
false
;
boolean
running
=
false
;
String
id
=
prop
.
getProperty
(
"id"
);
String
id
=
prop
.
getProperty
(
"id"
);
try
{
try
{
Socket
socket
=
NetUtils
.
createSocket
(
server
,
Constants
.
DEFAULT_
SERVER
_PORT
,
false
);
Socket
socket
=
NetUtils
.
createSocket
(
server
,
Constants
.
DEFAULT_
TCP
_PORT
,
false
);
Transfer
transfer
=
new
Transfer
(
null
);
Transfer
transfer
=
new
Transfer
(
null
);
transfer
.
setSocket
(
socket
);
transfer
.
setSocket
(
socket
);
transfer
.
init
();
transfer
.
init
();
...
@@ -343,31 +343,7 @@ public class FileLock {
...
@@ -343,31 +343,7 @@ public class FileLock {
fileName
=
null
;
fileName
=
null
;
throw
getExceptionFatal
(
"Concurrent update"
,
null
);
throw
getExceptionFatal
(
"Concurrent update"
,
null
);
}
}
watchdog
=
new
Thread
(
new
Runnable
()
{
watchdog
=
new
Thread
(
this
);
public
void
run
()
{
try
{
while
(
fileName
!=
null
)
{
// trace.debug("watchdog check");
try
{
if
(!
fs
.
exists
(
fileName
)
||
fs
.
getLastModified
(
fileName
)
!=
lastWrite
)
{
save
();
}
Thread
.
sleep
(
sleep
);
}
catch
(
OutOfMemoryError
e
)
{
// ignore
}
catch
(
InterruptedException
e
)
{
// ignore
}
catch
(
NullPointerException
e
)
{
// ignore
}
catch
(
Exception
e
)
{
trace
.
debug
(
"watchdog"
,
e
);
}
}
}
catch
(
Exception
e
)
{
trace
.
debug
(
"watchdog"
,
e
);
}
}
});
watchdog
.
setName
(
"H2 File Lock Watchdog "
+
fileName
);
watchdog
.
setName
(
"H2 File Lock Watchdog "
+
fileName
);
watchdog
.
setDaemon
(
true
);
watchdog
.
setDaemon
(
true
);
watchdog
.
setPriority
(
Thread
.
MAX_PRIORITY
-
1
);
watchdog
.
setPriority
(
Thread
.
MAX_PRIORITY
-
1
);
...
@@ -439,20 +415,7 @@ public class FileLock {
...
@@ -439,20 +415,7 @@ public class FileLock {
return
;
return
;
}
}
save
();
save
();
watchdog
=
new
Thread
(
new
Runnable
()
{
watchdog
=
new
Thread
(
this
);
public
void
run
()
{
while
(
serverSocket
!=
null
)
{
try
{
trace
.
debug
(
"watchdog accept"
);
Socket
s
=
serverSocket
.
accept
();
s
.
close
();
}
catch
(
Exception
e
)
{
trace
.
debug
(
"watchdog"
,
e
);
}
}
trace
.
debug
(
"watchdog end"
);
}
});
watchdog
.
setDaemon
(
true
);
watchdog
.
setDaemon
(
true
);
watchdog
.
setName
(
"H2 File Lock Watchdog (Socket) "
+
fileName
);
watchdog
.
setName
(
"H2 File Lock Watchdog (Socket) "
+
fileName
);
watchdog
.
start
();
watchdog
.
start
();
...
@@ -510,4 +473,38 @@ public class FileLock {
...
@@ -510,4 +473,38 @@ public class FileLock {
return
uniqueId
;
return
uniqueId
;
}
}
public
void
run
()
{
try
{
while
(
fileName
!=
null
)
{
// trace.debug("watchdog check");
try
{
if
(!
fs
.
exists
(
fileName
)
||
fs
.
getLastModified
(
fileName
)
!=
lastWrite
)
{
save
();
}
Thread
.
sleep
(
sleep
);
}
catch
(
OutOfMemoryError
e
)
{
// ignore
}
catch
(
InterruptedException
e
)
{
// ignore
}
catch
(
NullPointerException
e
)
{
// ignore
}
catch
(
Exception
e
)
{
trace
.
debug
(
"watchdog"
,
e
);
}
}
while
(
serverSocket
!=
null
)
{
try
{
trace
.
debug
(
"watchdog accept"
);
Socket
s
=
serverSocket
.
accept
();
s
.
close
();
}
catch
(
Exception
e
)
{
trace
.
debug
(
"watchdog"
,
e
);
}
}
}
catch
(
Exception
e
)
{
trace
.
debug
(
"watchdog"
,
e
);
}
trace
.
debug
(
"watchdog end"
);
}
}
}
h2/src/main/org/h2/store/FileStore.java
浏览文件 @
e2893192
...
@@ -38,6 +38,11 @@ public class FileStore {
...
@@ -38,6 +38,11 @@ public class FileStore {
*/
*/
protected
static
final
byte
[]
EMPTY
=
new
byte
[
16
*
1024
];
protected
static
final
byte
[]
EMPTY
=
new
byte
[
16
*
1024
];
/**
* The magic file header.
*/
private
static
final
String
HEADER
=
"-- H2 0.5/B -- "
.
substring
(
0
,
Constants
.
FILE_BLOCK_SIZE
-
1
)
+
"\n"
;
/**
/**
* The file name.
* The file name.
*/
*/
...
@@ -144,7 +149,7 @@ public class FileStore {
...
@@ -144,7 +149,7 @@ public class FileStore {
* @return the random salt or the magic
* @return the random salt or the magic
*/
*/
protected
byte
[]
generateSalt
()
{
protected
byte
[]
generateSalt
()
{
return
Constants
.
MAGIC_FILE_
HEADER
.
getBytes
();
return
HEADER
.
getBytes
();
}
}
/**
/**
...
@@ -179,7 +184,7 @@ public class FileStore {
...
@@ -179,7 +184,7 @@ public class FileStore {
public
void
init
()
throws
SQLException
{
public
void
init
()
throws
SQLException
{
int
len
=
Constants
.
FILE_BLOCK_SIZE
;
int
len
=
Constants
.
FILE_BLOCK_SIZE
;
byte
[]
salt
;
byte
[]
salt
;
byte
[]
magic
=
Constants
.
MAGIC_FILE_
HEADER
.
getBytes
();
byte
[]
magic
=
HEADER
.
getBytes
();
if
(
length
()
<
HEADER_LENGTH
)
{
if
(
length
()
<
HEADER_LENGTH
)
{
// write unencrypted
// write unencrypted
checkedWriting
=
false
;
checkedWriting
=
false
;
...
@@ -195,12 +200,6 @@ public class FileStore {
...
@@ -195,12 +200,6 @@ public class FileStore {
seek
(
0
);
seek
(
0
);
byte
[]
buff
=
new
byte
[
len
];
byte
[]
buff
=
new
byte
[
len
];
readFullyDirect
(
buff
,
0
,
len
);
readFullyDirect
(
buff
,
0
,
len
);
if
(
Constants
.
MAGIC_FILE_HEADER_SUPPORT_TEXT
)
{
if
(
buff
[
10
]
==
'T'
)
{
buff
[
10
]
=
'B'
;
textMode
=
true
;
}
}
if
(
ByteUtils
.
compareNotNull
(
buff
,
magic
)
!=
0
)
{
if
(
ByteUtils
.
compareNotNull
(
buff
,
magic
)
!=
0
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_VERSION_ERROR_1
,
name
);
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_VERSION_ERROR_1
,
name
);
}
}
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
e2893192
...
@@ -71,6 +71,8 @@ public class MetaTable extends Table {
...
@@ -71,6 +71,8 @@ public class MetaTable extends Table {
*/
*/
public
static
final
long
ROW_COUNT_APPROXIMATION
=
1000
;
public
static
final
long
ROW_COUNT_APPROXIMATION
=
1000
;
private
static
final
String
CHARACTER_SET_NAME
=
"Unicode"
;
private
static
final
int
TABLES
=
0
;
private
static
final
int
TABLES
=
0
;
private
static
final
int
COLUMNS
=
1
;
private
static
final
int
COLUMNS
=
1
;
private
static
final
int
INDEXES
=
2
;
private
static
final
int
INDEXES
=
2
;
...
@@ -693,7 +695,7 @@ public class MetaTable extends Table {
...
@@ -693,7 +695,7 @@ public class MetaTable extends Table {
// NUMERIC_SCALE
// NUMERIC_SCALE
""
+
c
.
getScale
(),
""
+
c
.
getScale
(),
// CHARACTER_SET_NAME
// CHARACTER_SET_NAME
C
onstants
.
C
HARACTER_SET_NAME
,
CHARACTER_SET_NAME
,
// COLLATION_NAME
// COLLATION_NAME
collation
,
collation
,
// TYPE_NAME
// TYPE_NAME
...
@@ -1159,7 +1161,7 @@ public class MetaTable extends Table {
...
@@ -1159,7 +1161,7 @@ public class MetaTable extends Table {
// SCHEMA_OWNER
// SCHEMA_OWNER
identifier
(
schema
.
getOwner
().
getName
()),
identifier
(
schema
.
getOwner
().
getName
()),
// DEFAULT_CHARACTER_SET_NAME
// DEFAULT_CHARACTER_SET_NAME
C
onstants
.
C
HARACTER_SET_NAME
,
CHARACTER_SET_NAME
,
// DEFAULT_COLLATION_NAME
// DEFAULT_COLLATION_NAME
collation
,
collation
,
// IS_DEFAULT
// IS_DEFAULT
...
...
h2/src/main/org/h2/tools/Backup.java
浏览文件 @
e2893192
...
@@ -55,10 +55,10 @@ public class Backup extends Tool {
...
@@ -55,10 +55,10 @@ public class Backup extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
Backup
().
run
(
args
);
new
Backup
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
zipFileName
=
"backup.zip"
;
String
zipFileName
=
"backup.zip"
;
String
dir
=
"."
;
String
dir
=
"."
;
String
db
=
null
;
String
db
=
null
;
...
...
h2/src/main/org/h2/tools/ChangeFileEncryption.java
浏览文件 @
e2893192
...
@@ -53,10 +53,10 @@ public class ChangeFileEncryption extends Tool {
...
@@ -53,10 +53,10 @@ public class ChangeFileEncryption extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
ChangeFileEncryption
().
run
(
args
);
new
ChangeFileEncryption
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
dir
=
"."
;
String
dir
=
"."
;
String
cipher
=
null
;
String
cipher
=
null
;
char
[]
decryptPassword
=
null
;
char
[]
decryptPassword
=
null
;
...
...
h2/src/main/org/h2/tools/Console.java
浏览文件 @
e2893192
...
@@ -27,15 +27,15 @@ import java.awt.event.ActionEvent;
...
@@ -27,15 +27,15 @@ import java.awt.event.ActionEvent;
import
java.awt.event.ActionListener
;
import
java.awt.event.ActionListener
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseListener
;
import
java.awt.event.WindowAdapter
;
import
java.awt.event.WindowEvent
;
import
java.awt.event.WindowEvent
;
import
java.awt.event.WindowListener
;
//## AWT end ##
import
org.h2.server.ShutdownHandler
;
import
org.h2.util.Resources
;
import
org.h2.util.Resources
;
import
org.h2.util.Tool
;
import
org.h2.util.Tool
;
import
java.io.IOException
;
import
java.io.IOException
;
//## AWT end ##
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.server.ShutdownHandler
;
import
org.h2.util.StartBrowser
;
import
org.h2.util.StartBrowser
;
/**
/**
...
@@ -46,12 +46,13 @@ import org.h2.util.StartBrowser;
...
@@ -46,12 +46,13 @@ import org.h2.util.StartBrowser;
*/
*/
public
class
Console
extends
Tool
implements
public
class
Console
extends
Tool
implements
//## AWT begin ##
//## AWT begin ##
ActionListener
,
MouseListener
,
ActionListener
,
MouseListener
,
WindowListener
,
//## AWT end ##
//## AWT end ##
ShutdownHandler
{
ShutdownHandler
{
//## AWT begin ##
//## AWT begin ##
Frame
frame
;
private
Frame
frame
;
private
boolean
trayIcon
;
private
Font
font
;
private
Font
font
;
private
Button
startBrowser
;
private
Button
startBrowser
;
//## AWT end ##
//## AWT end ##
...
@@ -85,7 +86,7 @@ ShutdownHandler {
...
@@ -85,7 +86,7 @@ ShutdownHandler {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
Console
().
run
(
args
);
new
Console
().
run
Tool
(
args
);
}
}
/**
/**
...
@@ -95,7 +96,7 @@ ShutdownHandler {
...
@@ -95,7 +96,7 @@ ShutdownHandler {
*
*
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
isWindows
=
SysProperties
.
getStringSetting
(
"os.name"
,
""
).
startsWith
(
"Windows"
);
isWindows
=
SysProperties
.
getStringSetting
(
"os.name"
,
""
).
startsWith
(
"Windows"
);
boolean
tcpStart
=
false
,
pgStart
=
false
,
webStart
=
false
,
toolStart
=
false
;
boolean
tcpStart
=
false
,
pgStart
=
false
,
webStart
=
false
,
toolStart
=
false
;
boolean
browserStart
=
false
;
boolean
browserStart
=
false
;
...
@@ -153,7 +154,7 @@ ShutdownHandler {
...
@@ -153,7 +154,7 @@ ShutdownHandler {
loadFont
();
loadFont
();
try
{
try
{
if
(!
createTrayIcon
())
{
if
(!
createTrayIcon
())
{
showWindow
(
true
);
showWindow
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -303,19 +304,21 @@ ShutdownHandler {
...
@@ -303,19 +304,21 @@ ShutdownHandler {
}
}
Image
icon
=
loadImage
(
iconFile
);
Image
icon
=
loadImage
(
iconFile
);
// TrayIcon icon = new TrayIcon(image, "H2 Database Engine", menuConsole);
// TrayIcon icon = new TrayIcon(image, "H2 Database Engine", menuConsole);
Object
t
rayIcon
=
Class
.
forName
(
"java.awt.TrayIcon"
).
Object
t
i
=
Class
.
forName
(
"java.awt.TrayIcon"
).
getConstructor
(
Image
.
class
,
String
.
class
,
PopupMenu
.
class
).
getConstructor
(
Image
.
class
,
String
.
class
,
PopupMenu
.
class
).
newInstance
(
icon
,
"H2 Database Engine"
,
menuConsole
);
newInstance
(
icon
,
"H2 Database Engine"
,
menuConsole
);
// trayIcon.addMouseListener(this);
// trayIcon.addMouseListener(this);
t
rayIcon
.
getClass
().
t
i
.
getClass
().
getMethod
(
"addMouseListener"
,
MouseListener
.
class
).
getMethod
(
"addMouseListener"
,
MouseListener
.
class
).
invoke
(
t
rayIcon
,
this
);
invoke
(
t
i
,
this
);
// tray.add(icon);
// tray.add(icon);
tray
.
getClass
().
tray
.
getClass
().
getMethod
(
"add"
,
Class
.
forName
(
"java.awt.TrayIcon"
)).
getMethod
(
"add"
,
Class
.
forName
(
"java.awt.TrayIcon"
)).
invoke
(
tray
,
trayIcon
);
invoke
(
tray
,
ti
);
this
.
trayIcon
=
true
;
return
true
;
return
true
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -323,17 +326,12 @@ ShutdownHandler {
...
@@ -323,17 +326,12 @@ ShutdownHandler {
}
}
}
}
private
void
showWindow
(
final
boolean
exit
)
{
private
void
showWindow
()
{
if
(
frame
!=
null
)
{
return
;
}
frame
=
new
Frame
(
"H2 Console"
);
frame
=
new
Frame
(
"H2 Console"
);
frame
.
addWindowListener
(
new
WindowAdapter
()
{
frame
.
addWindowListener
(
this
);
public
void
windowClosing
(
WindowEvent
we
)
{
if
(
exit
)
{
stopAll
();
}
else
{
frame
.
dispose
();
}
}
});
Image
image
=
loadImage
(
"/org/h2/res/h2.png"
);
Image
image
=
loadImage
(
"/org/h2/res/h2.png"
);
if
(
image
!=
null
)
{
if
(
image
!=
null
)
{
frame
.
setIconImage
(
image
);
frame
.
setIconImage
(
image
);
...
@@ -425,7 +423,7 @@ ShutdownHandler {
...
@@ -425,7 +423,7 @@ ShutdownHandler {
}
else
if
(
"console"
.
equals
(
command
))
{
}
else
if
(
"console"
.
equals
(
command
))
{
startBrowser
();
startBrowser
();
}
else
if
(
"status"
.
equals
(
command
))
{
}
else
if
(
"status"
.
equals
(
command
))
{
showWindow
(
false
);
showWindow
();
}
else
if
(
startBrowser
==
e
.
getSource
())
{
}
else
if
(
startBrowser
==
e
.
getSource
())
{
// for some reason, IKVM ignores setActionCommand
// for some reason, IKVM ignores setActionCommand
startBrowser
();
startBrowser
();
...
@@ -480,4 +478,72 @@ ShutdownHandler {
...
@@ -480,4 +478,72 @@ ShutdownHandler {
}
}
//## AWT end ##
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public
void
windowClosing
(
WindowEvent
e
)
{
if
(
trayIcon
)
{
frame
.
dispose
();
frame
=
null
;
}
else
{
stopAll
();
}
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public
void
windowActivated
(
WindowEvent
e
)
{
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public
void
windowClosed
(
WindowEvent
e
)
{
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public
void
windowDeactivated
(
WindowEvent
e
)
{
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public
void
windowDeiconified
(
WindowEvent
e
)
{
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public
void
windowIconified
(
WindowEvent
e
)
{
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public
void
windowOpened
(
WindowEvent
e
)
{
// nothing to do
}
//## AWT end ##
}
}
h2/src/main/org/h2/tools/ConvertTraceFile.java
浏览文件 @
e2893192
...
@@ -74,10 +74,10 @@ public class ConvertTraceFile extends Tool {
...
@@ -74,10 +74,10 @@ public class ConvertTraceFile extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
ConvertTraceFile
().
run
(
args
);
new
ConvertTraceFile
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
traceFile
=
"test.trace.db"
;
String
traceFile
=
"test.trace.db"
;
String
javaClass
=
"Test"
;
String
javaClass
=
"Test"
;
String
script
=
"test.sql"
;
String
script
=
"test.sql"
;
...
...
h2/src/main/org/h2/tools/CreateCluster.java
浏览文件 @
e2893192
...
@@ -44,10 +44,10 @@ public class CreateCluster extends Tool {
...
@@ -44,10 +44,10 @@ public class CreateCluster extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
CreateCluster
().
run
(
args
);
new
CreateCluster
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
urlSource
=
null
;
String
urlSource
=
null
;
String
urlTarget
=
null
;
String
urlTarget
=
null
;
String
user
=
"sa"
;
String
user
=
"sa"
;
...
...
h2/src/main/org/h2/tools/DeleteDbFiles.java
浏览文件 @
e2893192
...
@@ -39,10 +39,10 @@ public class DeleteDbFiles extends Tool {
...
@@ -39,10 +39,10 @@ public class DeleteDbFiles extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
DeleteDbFiles
().
run
(
args
);
new
DeleteDbFiles
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
dir
=
"."
;
String
dir
=
"."
;
String
db
=
null
;
String
db
=
null
;
boolean
quiet
=
false
;
boolean
quiet
=
false
;
...
...
h2/src/main/org/h2/tools/MultiDimension.java
浏览文件 @
e2893192
...
@@ -21,7 +21,7 @@ import org.h2.util.StringUtils;
...
@@ -21,7 +21,7 @@ import org.h2.util.StringUtils;
* The algorithm used is database independent, the only requirement
* The algorithm used is database independent, the only requirement
* is that the engine supports a range index (for example b-tree).
* is that the engine supports a range index (for example b-tree).
*/
*/
public
class
MultiDimension
{
public
class
MultiDimension
implements
Comparator
<
long
[]>
{
private
static
final
MultiDimension
INSTANCE
=
new
MultiDimension
();
private
static
final
MultiDimension
INSTANCE
=
new
MultiDimension
();
...
@@ -239,11 +239,7 @@ public class MultiDimension {
...
@@ -239,11 +239,7 @@ public class MultiDimension {
}
}
private
void
optimize
(
ArrayList
<
long
[]>
list
,
int
total
)
{
private
void
optimize
(
ArrayList
<
long
[]>
list
,
int
total
)
{
Collections
.
sort
(
list
,
new
Comparator
<
long
[]>()
{
Collections
.
sort
(
list
,
this
);
public
int
compare
(
long
[]
a
,
long
[]
b
)
{
return
a
[
0
]
>
b
[
0
]
?
1
:
-
1
;
}
});
for
(
int
minGap
=
10
;;
minGap
+=
minGap
/
2
)
{
for
(
int
minGap
=
10
;;
minGap
+=
minGap
/
2
)
{
for
(
int
i
=
0
;
i
<
list
.
size
()
-
1
;
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
size
()
-
1
;
i
++)
{
long
[]
current
=
list
.
get
(
i
);
long
[]
current
=
list
.
get
(
i
);
...
@@ -264,6 +260,10 @@ public class MultiDimension {
...
@@ -264,6 +260,10 @@ public class MultiDimension {
}
}
}
}
public
int
compare
(
long
[]
a
,
long
[]
b
)
{
return
a
[
0
]
>
b
[
0
]
?
1
:
-
1
;
}
private
void
addMortonRanges
(
ArrayList
<
long
[]>
list
,
int
[]
min
,
int
[]
max
,
int
len
,
int
level
)
{
private
void
addMortonRanges
(
ArrayList
<
long
[]>
list
,
int
[]
min
,
int
[]
max
,
int
len
,
int
level
)
{
if
(
level
>
100
)
{
if
(
level
>
100
)
{
throw
new
IllegalArgumentException
(
"Stop"
);
throw
new
IllegalArgumentException
(
"Stop"
);
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
e2893192
...
@@ -17,6 +17,7 @@ import java.io.PrintWriter;
...
@@ -17,6 +17,7 @@ import java.io.PrintWriter;
import
java.io.Reader
;
import
java.io.Reader
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -46,7 +47,6 @@ import org.h2.util.FileUtils;
...
@@ -46,7 +47,6 @@ import org.h2.util.FileUtils;
import
org.h2.util.IOUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.IntArray
;
import
org.h2.util.IntArray
;
import
org.h2.util.New
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StatementBuilder
;
...
@@ -69,7 +69,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -69,7 +69,7 @@ public class Recover extends Tool implements DataHandler {
private
int
recordLength
;
private
int
recordLength
;
private
int
valueId
;
private
int
valueId
;
private
boolean
trace
;
private
boolean
trace
;
private
ObjectArray
<
MetaRecord
>
schema
;
private
ArrayList
<
MetaRecord
>
schema
;
private
HashSet
<
Integer
>
objectIdSet
;
private
HashSet
<
Integer
>
objectIdSet
;
private
HashMap
<
Integer
,
String
>
tableMap
;
private
HashMap
<
Integer
,
String
>
tableMap
;
private
boolean
remove
;
private
boolean
remove
;
...
@@ -99,7 +99,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -99,7 +99,7 @@ public class Recover extends Tool implements DataHandler {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
Recover
().
run
(
args
);
new
Recover
().
run
Tool
(
args
);
}
}
/**
/**
...
@@ -113,7 +113,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -113,7 +113,7 @@ public class Recover extends Tool implements DataHandler {
*
*
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
dir
=
"."
;
String
dir
=
"."
;
String
db
=
null
;
String
db
=
null
;
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
...
@@ -1014,14 +1014,14 @@ public class Recover extends Tool implements DataHandler {
...
@@ -1014,14 +1014,14 @@ public class Recover extends Tool implements DataHandler {
}
}
private
void
resetSchema
()
{
private
void
resetSchema
()
{
schema
=
ObjectArray
.
newInstance
();
schema
=
New
.
arrayList
();
objectIdSet
=
New
.
hashSet
();
objectIdSet
=
New
.
hashSet
();
tableMap
=
New
.
hashMap
();
tableMap
=
New
.
hashMap
();
}
}
private
void
writeSchema
(
PrintWriter
writer
)
{
private
void
writeSchema
(
PrintWriter
writer
)
{
writer
.
println
(
"---- Schema ----------"
);
writer
.
println
(
"---- Schema ----------"
);
MetaRecord
.
sort
(
schema
);
Collections
.
sort
(
schema
);
for
(
MetaRecord
m
:
schema
)
{
for
(
MetaRecord
m
:
schema
)
{
String
sql
=
m
.
getSQL
();
String
sql
=
m
.
getSQL
();
// create, but not referential integrity constraints and so on
// create, but not referential integrity constraints and so on
...
...
h2/src/main/org/h2/tools/Restore.java
浏览文件 @
e2893192
...
@@ -45,10 +45,10 @@ public class Restore extends Tool {
...
@@ -45,10 +45,10 @@ public class Restore extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
Restore
().
run
(
args
);
new
Restore
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
zipFileName
=
"backup.zip"
;
String
zipFileName
=
"backup.zip"
;
String
dir
=
"."
;
String
dir
=
"."
;
String
db
=
null
;
String
db
=
null
;
...
...
h2/src/main/org/h2/tools/RunScript.java
浏览文件 @
e2893192
...
@@ -65,7 +65,7 @@ public class RunScript extends Tool {
...
@@ -65,7 +65,7 @@ public class RunScript extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
RunScript
().
run
(
args
);
new
RunScript
().
run
Tool
(
args
);
}
}
/**
/**
...
@@ -86,7 +86,7 @@ public class RunScript extends Tool {
...
@@ -86,7 +86,7 @@ public class RunScript extends Tool {
*
*
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
url
=
null
;
String
url
=
null
;
String
user
=
"sa"
;
String
user
=
"sa"
;
String
password
=
""
;
String
password
=
""
;
...
...
h2/src/main/org/h2/tools/Script.java
浏览文件 @
e2893192
...
@@ -48,10 +48,10 @@ public class Script extends Tool {
...
@@ -48,10 +48,10 @@ public class Script extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
Script
().
run
(
args
);
new
Script
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
url
=
null
;
String
url
=
null
;
String
user
=
"sa"
;
String
user
=
"sa"
;
String
password
=
""
;
String
password
=
""
;
...
...
h2/src/main/org/h2/tools/Server.java
浏览文件 @
e2893192
...
@@ -100,10 +100,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
...
@@ -100,10 +100,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
Server
().
run
(
args
);
new
Server
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
boolean
tcpStart
=
false
,
pgStart
=
false
,
webStart
=
false
;
boolean
tcpStart
=
false
,
pgStart
=
false
,
webStart
=
false
;
boolean
browserStart
=
false
;
boolean
browserStart
=
false
;
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
...
@@ -441,32 +441,27 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
...
@@ -441,32 +441,27 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
/**
/**
* Start a web server and a browser that uses the given connection. The
* Start a web server and a browser that uses the given connection. The
* current transaction is preserved. This is specially useful to manually
* current transaction is preserved. This is specially useful to manually
* inspect the database when debugging.
* inspect the database when debugging. This method return as soon as the
* user has disconnected.
*
*
* @param conn the database connection (the database must be open)
* @param conn the database connection (the database must be open)
*/
*/
public
static
void
startWebServer
(
Connection
conn
)
throws
SQLException
{
public
static
void
startWebServer
(
Connection
conn
)
throws
SQLException
{
final
Object
waitUntilDisconnected
=
new
Object
();
WebServer
webServer
=
new
WebServer
();
WebServer
webServer
=
new
WebServer
();
Server
server
=
new
Server
(
webServer
,
new
String
[]
{
"-webPort"
,
"0"
});
Server
web
=
new
Server
(
webServer
,
new
String
[]
{
"-webPort"
,
"0"
});
webServer
.
setShutdownHandler
(
new
ShutdownHandler
()
{
web
.
start
();
public
void
shutdown
()
{
Server
server
=
new
Server
();
synchronized
(
waitUntilDisconnected
)
{
server
.
web
=
web
;
waitUntilDisconnected
.
notifyAll
();
webServer
.
setShutdownHandler
(
server
);
}
}
});
server
.
start
();
String
url
=
webServer
.
addSession
(
conn
);
String
url
=
webServer
.
addSession
(
conn
);
StartBrowser
.
openURL
(
url
);
StartBrowser
.
openURL
(
url
);
synchronized
(
waitUntilDisconnected
)
{
while
(!
webServer
.
isStopped
()
)
{
try
{
try
{
waitUntilDisconnected
.
wait
(
);
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
// ignore
// ignore
}
}
}
}
webServer
.
stop
();
}
}
}
}
h2/src/main/org/h2/tools/Shell.java
浏览文件 @
e2893192
...
@@ -34,7 +34,7 @@ import org.h2.util.Tool;
...
@@ -34,7 +34,7 @@ import org.h2.util.Tool;
* Interactive command line tool to access a database using JDBC.
* Interactive command line tool to access a database using JDBC.
* @h2.resource
* @h2.resource
*/
*/
public
class
Shell
extends
Tool
{
public
class
Shell
extends
Tool
implements
Runnable
{
private
static
final
int
HISTORY_COUNT
=
20
;
private
static
final
int
HISTORY_COUNT
=
20
;
...
@@ -48,6 +48,7 @@ public class Shell extends Tool {
...
@@ -48,6 +48,7 @@ public class Shell extends Tool {
// Windows: '\u00b3';
// Windows: '\u00b3';
private
char
boxVertical
=
'|'
;
private
char
boxVertical
=
'|'
;
private
ArrayList
<
String
>
history
=
New
.
arrayList
();
private
ArrayList
<
String
>
history
=
New
.
arrayList
();
private
boolean
stopHide
;
/**
/**
* Options are case sensitive. Supported options are:
* Options are case sensitive. Supported options are:
...
@@ -70,7 +71,7 @@ public class Shell extends Tool {
...
@@ -70,7 +71,7 @@ public class Shell extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
Shell
().
run
(
args
);
new
Shell
().
run
Tool
(
args
);
}
}
/**
/**
...
@@ -105,7 +106,7 @@ public class Shell extends Tool {
...
@@ -105,7 +106,7 @@ public class Shell extends Tool {
*
*
* @param args the command line settings
* @param args the command line settings
*/
*/
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
url
=
null
;
String
url
=
null
;
String
user
=
""
;
String
user
=
""
;
String
password
=
""
;
String
password
=
""
;
...
@@ -401,31 +402,14 @@ public class Shell extends Tool {
...
@@ -401,31 +402,14 @@ public class Shell extends Tool {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// ignore, use the default solution
// ignore, use the default solution
}
}
Thread
passwordHider
=
new
Thread
(
this
);
/**
stopHide
=
false
;
* This thread hides the password by repeatedly printing
passwordHider
.
start
();
* backspace, backspace, >, <.
*/
class
PasswordHider
extends
Thread
{
volatile
boolean
stop
;
public
void
run
()
{
while
(!
stop
)
{
print
(
"\b\b><"
);
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
}
}
}
PasswordHider
thread
=
new
PasswordHider
();
thread
.
start
();
print
(
"Password > "
);
print
(
"Password > "
);
String
p
=
readLine
();
String
p
=
readLine
();
thread
.
stop
=
true
;
stopHide
=
true
;
try
{
try
{
thread
.
join
();
passwordHider
.
join
();
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
// ignore
// ignore
}
}
...
@@ -433,6 +417,23 @@ public class Shell extends Tool {
...
@@ -433,6 +417,23 @@ public class Shell extends Tool {
return
p
;
return
p
;
}
}
/**
* INTERNAL.
* Hides the password by repeatedly printing
* backspace, backspace, >, <.
*/
public
void
run
()
{
while
(!
stopHide
)
{
print
(
"\b\b><"
);
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
}
}
private
String
readLine
(
String
defaultValue
)
throws
IOException
{
private
String
readLine
(
String
defaultValue
)
throws
IOException
{
String
s
=
readLine
();
String
s
=
readLine
();
return
s
.
length
()
==
0
?
defaultValue
:
s
;
return
s
.
length
()
==
0
?
defaultValue
:
s
;
...
...
h2/src/main/org/h2/util/MathUtils.java
浏览文件 @
e2893192
...
@@ -9,7 +9,6 @@ package org.h2.util;
...
@@ -9,7 +9,6 @@ package org.h2.util;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.engine.Constants
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
/**
/**
...
@@ -17,6 +16,11 @@ import org.h2.message.Message;
...
@@ -17,6 +16,11 @@ import org.h2.message.Message;
*/
*/
public
class
MathUtils
{
public
class
MathUtils
{
/**
* The maximum scale of a BigDecimal value.
*/
private
static
final
int
BIG_DECIMAL_SCALE_MAX
=
100000
;
private
MathUtils
()
{
private
MathUtils
()
{
// utility class
// utility class
}
}
...
@@ -84,9 +88,9 @@ public class MathUtils {
...
@@ -84,9 +88,9 @@ public class MathUtils {
* @return the scaled value
* @return the scaled value
*/
*/
public
static
BigDecimal
setScale
(
BigDecimal
bd
,
int
scale
)
throws
SQLException
{
public
static
BigDecimal
setScale
(
BigDecimal
bd
,
int
scale
)
throws
SQLException
{
if
(
scale
>
Constants
.
BIG_DECIMAL_SCALE_MAX
)
{
if
(
scale
>
BIG_DECIMAL_SCALE_MAX
)
{
throw
Message
.
getInvalidValueException
(
""
+
scale
,
"scale"
);
throw
Message
.
getInvalidValueException
(
""
+
scale
,
"scale"
);
}
else
if
(
scale
<
-
Constants
.
BIG_DECIMAL_SCALE_MAX
)
{
}
else
if
(
scale
<
-
BIG_DECIMAL_SCALE_MAX
)
{
throw
Message
.
getInvalidValueException
(
""
+
scale
,
"scale"
);
throw
Message
.
getInvalidValueException
(
""
+
scale
,
"scale"
);
}
}
return
bd
.
setScale
(
scale
,
BigDecimal
.
ROUND_HALF_UP
);
return
bd
.
setScale
(
scale
,
BigDecimal
.
ROUND_HALF_UP
);
...
...
h2/src/main/org/h2/util/Profiler.java
浏览文件 @
e2893192
...
@@ -6,10 +6,9 @@
...
@@ -6,10 +6,9 @@
*/
*/
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
...
@@ -148,34 +147,46 @@ public class Profiler implements Runnable {
...
@@ -148,34 +147,46 @@ public class Profiler implements Runnable {
}
}
}
}
public
static
void
main
(
String
...
args
)
{
Profiler
p
=
new
Profiler
();
p
.
startCollecting
();
org
.
h2
.
Driver
.
load
();
Locale
.
getAvailableLocales
();
p
.
stopCollecting
();
System
.
out
.
println
(
p
.
getTop
(
10
));
}
/**
/**
* Get the top stack traces.
* Get the top stack traces.
*
*
* @param
max the maximum number of result
s
* @param
count the maximum number of stack trace
s
* @return the stack traces.
* @return the stack traces.
*/
*/
public
String
getTop
(
int
max
)
{
public
String
getTop
(
int
count
)
{
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"Profiler: top "
).
append
(
max
).
append
(
" stack trace(s) of "
).
append
(
time
).
buff
.
append
(
"Profiler: top "
).
append
(
count
).
append
(
" stack trace(s) of "
).
append
(
time
).
append
(
" ms [build-"
).
append
(
Constants
.
BUILD_ID
).
append
(
"]\n"
);
append
(
" ms [build-"
).
append
(
Constants
.
BUILD_ID
).
append
(
"]\n"
);
@SuppressWarnings
(
"unchecked"
)
for
(
int
x
=
0
,
min
=
0
;;)
{
Map
.
Entry
<
String
,
Integer
>[]
array
=
new
Map
.
Entry
[
counts
.
size
()];
int
highest
=
0
;
counts
.
entrySet
().
toArray
(
array
);
Map
.
Entry
<
String
,
Integer
>
best
=
null
;
Arrays
.
sort
(
array
,
new
Comparator
<
Map
.
Entry
<
String
,
Integer
>>()
{
for
(
Map
.
Entry
<
String
,
Integer
>
el
:
counts
.
entrySet
())
{
public
int
compare
(
Map
.
Entry
<
String
,
Integer
>
a
,
Map
.
Entry
<
String
,
Integer
>
b
)
{
if
(
el
.
getValue
()
>
highest
)
{
return
b
.
getValue
()
-
a
.
getValue
();
best
=
el
;
highest
=
el
.
getValue
();
}
}
if
(
best
==
null
)
{
break
;
}
}
});
counts
.
remove
(
best
.
getKey
());
int
x
=
0
,
min
=
0
;
if
(++
x
>=
count
)
{
for
(
Map
.
Entry
<
String
,
Integer
>
el
:
array
)
{
if
(
best
.
getValue
()
<
min
)
{
if
(++
x
>=
max
)
{
if
(
el
.
getValue
()
<
min
)
{
break
;
break
;
}
}
min
=
el
.
getValue
();
min
=
best
.
getValue
();
}
}
buff
.
append
(
el
.
getValue
()).
append
(
'/'
).
append
(
total
).
buff
.
append
(
best
.
getValue
()).
append
(
'/'
).
append
(
total
).
append
(
'\n'
).
append
(
el
.
getKey
());
append
(
'\n'
).
append
(
best
.
getKey
());
}
}
buff
.
append
(
'.'
);
buff
.
append
(
'.'
);
return
buff
.
toString
();
return
buff
.
toString
();
...
...
h2/src/main/org/h2/util/RandomUtils.java
浏览文件 @
e2893192
...
@@ -64,6 +64,7 @@ public class RandomUtils {
...
@@ -64,6 +64,7 @@ public class RandomUtils {
}
}
}
}
};
};
try
{
try
{
Thread
t
=
new
Thread
(
runnable
);
Thread
t
=
new
Thread
(
runnable
);
// let the process terminate even if generating the seed is really slow
// let the process terminate even if generating the seed is really slow
...
...
h2/src/main/org/h2/util/SortedProperties.java
浏览文件 @
e2893192
...
@@ -18,7 +18,6 @@ import java.io.PrintWriter;
...
@@ -18,7 +18,6 @@ import java.io.PrintWriter;
import
java.io.Writer
;
import
java.io.Writer
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.TreeMap
;
import
java.util.TreeMap
;
...
@@ -36,13 +35,12 @@ public class SortedProperties extends Properties {
...
@@ -36,13 +35,12 @@ public class SortedProperties extends Properties {
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
public
synchronized
Enumeration
<
Object
>
keys
()
{
public
synchronized
Enumeration
<
Object
>
keys
()
{
Vector
<
Object
>
v
=
new
Vector
<
Object
>(
keySet
());
Vector
<
String
>
v
=
new
Vector
<
String
>();
Collections
.
sort
(
v
,
new
Comparator
<
Object
>()
{
for
(
Object
o
:
keySet
())
{
public
int
compare
(
Object
o1
,
Object
o2
)
{
v
.
add
(
o
.
toString
());
return
o1
.
toString
().
compareTo
(
o2
.
toString
());
}
}
Collections
.
sort
(
v
);
});
return
new
Vector
<
Object
>(
v
).
elements
();
return
v
.
elements
();
}
}
/**
/**
...
...
h2/src/main/org/h2/util/Tool.java
浏览文件 @
e2893192
...
@@ -39,7 +39,7 @@ public abstract class Tool {
...
@@ -39,7 +39,7 @@ public abstract class Tool {
*
*
* @param args the argument list
* @param args the argument list
*/
*/
public
abstract
void
run
(
String
...
args
)
throws
SQLException
;
public
abstract
void
run
Tool
(
String
...
args
)
throws
SQLException
;
/**
/**
* Throw a SQLException saying this command line option is not supported.
* Throw a SQLException saying this command line option is not supported.
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
e2893192
...
@@ -709,7 +709,7 @@ public class ValueLob extends Value {
...
@@ -709,7 +709,7 @@ public class ValueLob extends Value {
* @param h the data handler
* @param h the data handler
*/
*/
public
void
convertToFileIfRequired
(
DataHandler
h
)
throws
SQLException
{
public
void
convertToFileIfRequired
(
DataHandler
h
)
throws
SQLException
{
if
(
Constants
.
AUTO_CONVERT_LOB_TO_FILES
&&
small
!=
null
&&
small
.
length
>
h
.
getMaxLengthInplaceLob
())
{
if
(
small
!=
null
&&
small
.
length
>
h
.
getMaxLengthInplaceLob
())
{
boolean
compress
=
h
.
getLobCompressionAlgorithm
(
type
)
!=
null
;
boolean
compress
=
h
.
getLobCompressionAlgorithm
(
type
)
!=
null
;
int
len
=
getBufferSize
(
h
,
compress
,
Long
.
MAX_VALUE
);
int
len
=
getBufferSize
(
h
,
compress
,
Long
.
MAX_VALUE
);
int
tabId
=
tableId
;
int
tabId
=
tableId
;
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
e2893192
...
@@ -286,7 +286,8 @@ java org.h2.test.TestAll timer
...
@@ -286,7 +286,8 @@ java org.h2.test.TestAll timer
System
.
setProperty
(
"h2.check2"
,
"true"
);
System
.
setProperty
(
"h2.check2"
,
"true"
);
/*
/*
check client jar file size
remove ObjectArray
Constants.FILE_BLOCK_SIZE and others
Constants.FILE_BLOCK_SIZE and others
simplify SysProperties
simplify SysProperties
combine small classes (StringCache / utils...)
combine small classes (StringCache / utils...)
...
...
h2/src/test/org/h2/test/unit/TestShell.java
浏览文件 @
e2893192
...
@@ -60,7 +60,7 @@ public class TestShell extends TestBase {
...
@@ -60,7 +60,7 @@ public class TestShell extends TestBase {
shell
.
setIn
(
toolIn
);
shell
.
setIn
(
toolIn
);
shell
.
setOut
(
toolOut
);
shell
.
setOut
(
toolOut
);
shell
.
setErr
(
toolOut
);
shell
.
setErr
(
toolOut
);
shell
.
run
();
shell
.
run
Tool
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
e2893192
...
@@ -198,7 +198,7 @@ public class TestTools extends TestBase {
...
@@ -198,7 +198,7 @@ public class TestTools extends TestBase {
server
.
setOut
(
ps
);
server
.
setOut
(
ps
);
int
result
=
0
;
int
result
=
0
;
try
{
try
{
server
.
run
(
args
);
server
.
run
Tool
(
args
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
result
=
1
;
result
=
1
;
e
.
printStackTrace
(
ps
);
e
.
printStackTrace
(
ps
);
...
...
h2/src/tools/org/h2/dev/ftp/server/FtpServer.java
浏览文件 @
e2893192
...
@@ -148,10 +148,10 @@ public class FtpServer extends Tool implements Service {
...
@@ -148,10 +148,10 @@ public class FtpServer extends Tool implements Service {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
FtpServer
().
run
(
args
);
new
FtpServer
().
run
Tool
(
args
);
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
String
arg
=
args
[
i
];
String
arg
=
args
[
i
];
if
(
arg
==
null
)
{
if
(
arg
==
null
)
{
...
...
h2/src/tools/org/h2/dev/util/FileViewer.java
浏览文件 @
e2893192
...
@@ -27,7 +27,7 @@ public class FileViewer extends Tool {
...
@@ -27,7 +27,7 @@ public class FileViewer extends Tool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
SQLException
{
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
FileViewer
().
run
(
args
);
new
FileViewer
().
run
Tool
(
args
);
}
}
protected
void
showUsage
()
{
protected
void
showUsage
()
{
...
@@ -44,7 +44,7 @@ public class FileViewer extends Tool {
...
@@ -44,7 +44,7 @@ public class FileViewer extends Tool {
// getClass().getName().replace('.', '/') + ".html");
// getClass().getName().replace('.', '/') + ".html");
}
}
public
void
run
(
String
...
args
)
throws
SQLException
{
public
void
run
Tool
(
String
...
args
)
throws
SQLException
{
String
file
=
null
;
String
file
=
null
;
String
find
=
null
;
String
find
=
null
;
boolean
head
=
false
,
tail
=
false
;
boolean
head
=
false
,
tail
=
false
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论