Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
194fbc5c
提交
194fbc5c
authored
7月 03, 2010
作者:
christian.peter.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Automatic database upgrade from non page store is now possible
上级
001f9d04
全部展开
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
4757 行增加
和
4029 行删除
+4757
-4029
advanced.html
h2/src/docsrc/html/advanced.html
+26
-1
changelog.html
h2/src/docsrc/html/changelog.html
+6
-2
download.html
h2/src/docsrc/html/download.html
+5
-0
tutorial.html
h2/src/docsrc/html/tutorial.html
+3
-3
_docs_en.utf8.txt
h2/src/docsrc/text/_docs_en.utf8.txt
+1426
-1336
_docs_ja.utf8.txt
h2/src/docsrc/text/_docs_ja.utf8.txt
+1434
-1344
_docs_en.properties
h2/src/docsrc/textbase/_docs_en.properties
+1368
-1338
Driver.java
h2/src/main/org/h2/Driver.java
+4
-0
help.csv
h2/src/main/org/h2/res/help.csv
+4
-4
DbUpgrade.java
h2/src/main/org/h2/upgrade/DbUpgrade.java
+61
-0
DbUpgradeNonPageStoreToCurrent.java
...c/main/org/h2/upgrade/DbUpgradeNonPageStoreToCurrent.java
+198
-0
package.html
h2/src/main/org/h2/upgrade/package.html
+15
-0
Utils.java
h2/src/main/org/h2/util/Utils.java
+205
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+2
-1
没有找到文件。
h2/src/docsrc/html/advanced.html
浏览文件 @
194fbc5c
...
@@ -68,6 +68,8 @@ Advanced
...
@@ -68,6 +68,8 @@ Advanced
Setting the Server Bind Address
</a><br
/>
Setting the Server Bind Address
</a><br
/>
<a
href=
"#file_system"
>
<a
href=
"#file_system"
>
Pluggable File System
</a><br
/>
Pluggable File System
</a><br
/>
<a
href=
"#database_upgrade"
>
Database Upgrade
</a><br
/>
<a
href=
"#limits_limitations"
>
<a
href=
"#limits_limitations"
>
Limits and Limitations
</a><br
/>
Limits and Limitations
</a><br
/>
<a
href=
"#glossary_links"
>
<a
href=
"#glossary_links"
>
...
@@ -1221,6 +1223,29 @@ To register a new file system, extend the classes <code>org.h2.store.fs.FileSyst
...
@@ -1221,6 +1223,29 @@ To register a new file system, extend the classes <code>org.h2.store.fs.FileSyst
and call the method
<code>
FileSystem.register
</code>
before using it.
and call the method
<code>
FileSystem.register
</code>
before using it.
</p>
</p>
<h2
id=
"database_upgrade"
>
Database Upgrade
</h2>
<p>
In version 1.2, H2 introduced a new file store implementation which is incompatible to the one used in versions
<
1.2.
To automatically convert databases to the new file store, it is necessary to include an additional jar file.
The file can be found at
<a
href=
"http://h2database.com/h2mig_pagestore_addon.jar"
>
http://h2database.com/h2mig_pagestore_addon.jar
</a>
.
If this file is in the classpath, every connect to an older database will result in a conversion process.
</p>
<p>
The conversion itself is done via 'script to' and 'runscript from'. After the conversion process, the files will be
renamed from
<ul>
<li>
dbName.data.db to dbName.data.db.backup
</li><li>
dbName.index.db to dbName.index.db.backup
</li></ul>
by default. Also, the temporary script will be written to the database directory instead of a temporary directory.
Both defaults can be customized via
<ul>
<li>
org.h2.upgrade.DbUpgradeNonPageStoreToCurrent.setDeleteOldDb(boolean)
</li><li>
org.h2.upgrade.DbUpgradeNonPageStoreToCurrent.setScriptInTmpDir(boolean)
</li></ul>
prior opening a database connection.
</p>
<h2
id=
"limits_limitations"
>
Limits and Limitations
</h2>
<h2
id=
"limits_limitations"
>
Limits and Limitations
</h2>
<p>
<p>
This database has the following known limitations:
This database has the following known limitations:
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
194fbc5c
...
@@ -18,7 +18,11 @@ Change Log
...
@@ -18,7 +18,11 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The MultiDimension tools was extended with a few helper methods.
<ul><li>
Automatic database upgrade from non page store is now possible. If the file
h2mig_pagestore_addon.jar is found, the database will be converted to the current
page store format automatically. The file can be found in this zip:
<a
href=
"http://h2database.com/h2mig_pagestore_addon.jar"
>
http://h2database.com/h2mig_pagestore_addon.jar
</a>
</li><li>
The MultiDimension tools was extended with a few helper methods.
The API was unified a bit.
The API was unified a bit.
</li><li>
ODBC: additional connection settings can now be added to the database name.
</li><li>
ODBC: additional connection settings can now be added to the database name.
Example: ~/test;cipher=xtea. Therefore, encrypted databases are supported.
Example: ~/test;cipher=xtea. Therefore, encrypted databases are supported.
...
...
h2/src/docsrc/html/download.html
浏览文件 @
194fbc5c
...
@@ -43,6 +43,11 @@ Downloads
...
@@ -43,6 +43,11 @@ Downloads
<a
href=
"http://www.h2database.com/automated/h2-latest.jar"
>
Latest Automated Build (not released)
</a>
<a
href=
"http://www.h2database.com/automated/h2-latest.jar"
>
Latest Automated Build (not released)
</a>
</p>
</p>
<h3>
Database Upgrade Helper Files
</h3>
<p>
<a
href=
"http://h2database.com/h2mig_pagestore_addon.jar"
>
Upgrade database from 1.1 to the current version
</a>
</p>
<h3>
Subversion Source Repository
</h3>
<h3>
Subversion Source Repository
</h3>
<p>
<p>
<a
href=
"http://code.google.com/p/h2database/source"
>
Google Code
</a>
<a
href=
"http://code.google.com/p/h2database/source"
>
Google Code
</a>
...
...
h2/src/docsrc/html/tutorial.html
浏览文件 @
194fbc5c
h2/src/docsrc/text/_docs_en.utf8.txt
浏览文件 @
194fbc5c
差异被折叠。
点击展开。
h2/src/docsrc/text/_docs_ja.utf8.txt
浏览文件 @
194fbc5c
差异被折叠。
点击展开。
h2/src/docsrc/textbase/_docs_en.properties
浏览文件 @
194fbc5c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
h2/src/main/org/h2/Driver.java
浏览文件 @
194fbc5c
...
@@ -16,6 +16,7 @@ import org.h2.engine.Constants;
...
@@ -16,6 +16,7 @@ import org.h2.engine.Constants;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.message.TraceSystem
;
import
org.h2.message.TraceSystem
;
import
org.h2.upgrade.DbUpgrade
;
/**
/**
* The database driver. An application should not use this class directly. The
* The database driver. An application should not use this class directly. The
...
@@ -55,6 +56,9 @@ public class Driver implements java.sql.Driver {
...
@@ -55,6 +56,9 @@ public class Driver implements java.sql.Driver {
if
(!
acceptsURL
(
url
))
{
if
(!
acceptsURL
(
url
))
{
return
null
;
return
null
;
}
}
// Upgrade the database if needed and conversion classes are found
DbUpgrade
.
upgrade
(
url
,
info
);
return
new
JdbcConnection
(
url
,
info
);
return
new
JdbcConnection
(
url
,
info
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
DbException
.
toSQLException
(
e
);
throw
DbException
.
toSQLException
(
e
);
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
194fbc5c
...
@@ -184,7 +184,7 @@ CREATE [ CACHED | MEMORY ] [ TEMP | [ GLOBAL | LOCAL ] TEMPORARY ]
...
@@ -184,7 +184,7 @@ CREATE [ CACHED | MEMORY ] [ TEMP | [ GLOBAL | LOCAL ] TEMPORARY ]
TABLE [ IF NOT EXISTS ] name
TABLE [ IF NOT EXISTS ] name
{ { ( { columnDefinition | constraint } [,...] ) [ AS select ] }
{ { ( { columnDefinition | constraint } [,...] ) [ AS select ] }
| { AS select } }
| { AS select } }
[ ENGINE tableEngineName ] [ NOT PERSISTENT ]
[ ENGINE tableEngineName ] [
TRANSACTIONAL ] [
NOT PERSISTENT ]
","
","
Creates a new table."
Creates a new table."
"Commands (DDL)","CREATE TRIGGER","
"Commands (DDL)","CREATE TRIGGER","
...
@@ -241,9 +241,9 @@ DROP SEQUENCE [ IF EXISTS ] sequenceName
...
@@ -241,9 +241,9 @@ DROP SEQUENCE [ IF EXISTS ] sequenceName
","
","
Drops a sequence."
Drops a sequence."
"Commands (DDL)","DROP TABLE","
"Commands (DDL)","DROP TABLE","
DROP TABLE [ IF EXISTS ] tableName [,...]
DROP TABLE [ IF EXISTS ] tableName [,...]
[ CASCADE | RESTRICT ]
","
","
Drops an existing table, or a list of
existing
tables."
Drops an existing table, or a list of tables."
"Commands (DDL)","DROP TRIGGER","
"Commands (DDL)","DROP TRIGGER","
DROP TRIGGER [ IF EXISTS ] triggerName
DROP TRIGGER [ IF EXISTS ] triggerName
","
","
...
@@ -255,7 +255,7 @@ Drops a user."
...
@@ -255,7 +255,7 @@ Drops a user."
"Commands (DDL)","DROP VIEW","
"Commands (DDL)","DROP VIEW","
DROP VIEW [ IF EXISTS ] viewName [ RESTRICT | CASCADE ]
DROP VIEW [ IF EXISTS ] viewName [ RESTRICT | CASCADE ]
","
","
Drops a
view, and all dependent views if the CASCADE clause is used
."
Drops a
n existing view
."
"Commands (DDL)","TRUNCATE TABLE","
"Commands (DDL)","TRUNCATE TABLE","
TRUNCATE TABLE tableName
TRUNCATE TABLE tableName
","
","
...
...
h2/src/main/org/h2/upgrade/DbUpgrade.java
0 → 100644
浏览文件 @
194fbc5c
/*
* 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
.
upgrade
;
import
java.sql.SQLException
;
import
java.util.Collections
;
import
java.util.Hashtable
;
import
java.util.Map
;
import
java.util.Properties
;
import
org.h2.util.Utils
;
/**
* This class starts the conversion from older database versions to the current
* version if the respective classes are found.
*/
public
class
DbUpgrade
{
private
static
boolean
nonPageStoreToCurrentEnabled
;
private
static
Map
<
String
,
DbUpgradeNonPageStoreToCurrent
>
runningConversions
;
static
{
// static initialize block
nonPageStoreToCurrentEnabled
=
Utils
.
isClassPresent
(
"org.h2.upgrade.v1_1_to_v1_2.Driver"
);
runningConversions
=
Collections
.
synchronizedMap
(
new
Hashtable
<
String
,
DbUpgradeNonPageStoreToCurrent
>(
1
));
}
/**
* Starts the conversion if the respective classes are found. Is automatically
* called on connect.
*
* @param url The connection string
* @param info The connection Properties
* @throws SQLException
*/
public
synchronized
static
void
upgrade
(
String
url
,
Properties
info
)
throws
SQLException
{
if
(
nonPageStoreToCurrentEnabled
)
{
upgradeFromNonPageStore
(
url
,
info
);
}
}
private
static
void
upgradeFromNonPageStore
(
String
url
,
Properties
info
)
throws
SQLException
{
if
(
runningConversions
.
containsKey
(
url
))
{
// do not migrate, because we are currently migrating, and this is
// the connection where "runscript from" will be executed
return
;
}
try
{
DbUpgradeNonPageStoreToCurrent
instance
=
new
DbUpgradeNonPageStoreToCurrent
(
url
,
info
);
runningConversions
.
put
(
url
,
instance
);
instance
.
upgrade
(
url
,
info
);
}
finally
{
runningConversions
.
remove
(
url
);
}
}
}
h2/src/main/org/h2/upgrade/DbUpgradeNonPageStoreToCurrent.java
0 → 100644
浏览文件 @
194fbc5c
/*
* 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
.
upgrade
;
import
java.io.File
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
org.h2.message.DbException
;
import
org.h2.util.Utils
;
/**
* Class to convert a 1.1 DB (non page store) to a 1.2 DB (page store) format.
* Conversion is done via "script to" and "runscript from".
*/
public
class
DbUpgradeNonPageStoreToCurrent
{
private
static
boolean
scriptInTmpDir
=
false
;
private
static
boolean
deleteOldDb
=
false
;
private
String
url
;
private
Properties
info
;
private
boolean
mustBeConverted
;
private
String
newName
;
private
String
oldUrl
;
private
File
oldDataFile
;
private
File
oldIndexFile
;
private
File
newFile
;
private
File
backupDataFile
;
private
File
backupIndexFile
;
private
boolean
successful
;
/**
* Converts a database from a 1.1 DB (non page store) to a 1.2 DB
* (page store) format.
*
* @param url The connection string
* @param info The connection properties
* @throws SQLException if an exception occurred
*/
public
DbUpgradeNonPageStoreToCurrent
(
String
url
,
Properties
info
)
throws
SQLException
{
this
.
url
=
url
;
this
.
info
=
info
;
init
();
}
private
void
init
()
throws
SQLException
{
try
{
String
oldStartUrlPrefix
=
(
String
)
Utils
.
getStaticField
(
"org.h2.upgrade.v1_1_to_v1_2.engine.Constants.START_URL"
);
oldUrl
=
url
;
oldUrl
=
oldUrl
.
replaceAll
(
org
.
h2
.
engine
.
Constants
.
START_URL
,
oldStartUrlPrefix
);
oldUrl
=
oldUrl
.
replaceAll
(
";IGNORE_UNKNOWN_SETTINGS=TRUE"
,
""
);
oldUrl
=
oldUrl
.
replaceAll
(
";IGNORE_UNKNOWN_SETTINGS=FALSE"
,
""
);
oldUrl
=
oldUrl
.
replaceAll
(
";IFEXISTS=TRUE"
,
""
);
oldUrl
=
oldUrl
.
replaceAll
(
";IFEXISTS=FALSE"
,
""
);
oldUrl
+=
";IGNORE_UNKNOWN_SETTINGS=TRUE"
;
Object
ci
=
Utils
.
newInstance
(
"org.h2.upgrade.v1_1_to_v1_2.engine.ConnectionInfo"
,
oldUrl
,
info
);
boolean
isRemote
=
(
Boolean
)
Utils
.
callMethod
(
"isRemote"
,
ci
);
boolean
isPersistent
=
(
Boolean
)
Utils
.
callMethod
(
"isPersistent"
,
ci
);
String
dbName
=
(
String
)
Utils
.
callMethod
(
"getName"
,
ci
);
if
(!
isRemote
&&
isPersistent
)
{
String
oldDataName
=
dbName
+
".data.db"
;
String
oldIndexName
=
dbName
+
".index.db"
;
newName
=
dbName
+
".h2.db"
;
oldDataFile
=
new
File
(
oldDataName
).
getAbsoluteFile
();
oldIndexFile
=
new
File
(
oldIndexName
).
getAbsoluteFile
();
newFile
=
new
File
(
newName
).
getAbsoluteFile
();
backupDataFile
=
new
File
(
oldDataFile
.
getAbsolutePath
()
+
".backup"
);
backupIndexFile
=
new
File
(
oldIndexFile
.
getAbsolutePath
()
+
".backup"
);
mustBeConverted
=
oldDataFile
.
exists
()
&&
!
newFile
.
exists
();
}
}
catch
(
Exception
e
)
{
DbException
.
toSQLException
(
e
);
}
}
/**
* Returns if a database must be converted by this class.
*
* @param url The connection string
* @param info The connection properties
* @return if the conversion classes were found and the database must be
* converted
* @throws SQLException
*/
public
boolean
mustBeConverted
(
String
url
,
Properties
info
)
throws
SQLException
{
return
mustBeConverted
;
}
/**
* Converts the database from 1.1 (non page store) to current (page store).
*
* @param url The connection string
* @param info The connection properties
* @throws SQLException
*/
public
void
upgrade
(
String
url
,
Properties
info
)
throws
SQLException
{
successful
=
true
;
if
(!
mustBeConverted
)
{
return
;
}
File
scriptFile
=
null
;
try
{
if
(
scriptInTmpDir
)
{
scriptFile
=
File
.
createTempFile
(
"h2dbmigration"
,
"backup.sql"
);
}
else
{
scriptFile
=
new
File
(
oldDataFile
.
getAbsolutePath
()
+
"_script.sql"
);
}
// outputStream.println("H2 Migrating '" + oldFile.getPath() +
// "' to '" + newFile.getPath() + "' via '" + scriptFile.getPath()
// + "'");
Utils
.
callStaticMethod
(
"org.h2.upgrade.v1_1_to_v1_2.Driver.load"
);
Connection
connection
=
DriverManager
.
getConnection
(
oldUrl
,
info
);
Statement
stmt
=
connection
.
createStatement
();
stmt
.
execute
(
"script to '"
+
scriptFile
+
"'"
);
stmt
.
close
();
connection
.
close
();
oldDataFile
.
renameTo
(
backupDataFile
);
oldIndexFile
.
renameTo
(
backupIndexFile
);
connection
=
DriverManager
.
getConnection
(
url
,
info
);
stmt
=
connection
.
createStatement
();
stmt
.
execute
(
"runscript from '"
+
scriptFile
+
"'"
);
stmt
.
close
();
connection
.
close
();
if
(
deleteOldDb
)
{
backupDataFile
.
delete
();
backupIndexFile
.
delete
();
}
// outputStream.println("H2 Migration of '" + oldFile.getPath() +
// "' finished successfully");
}
catch
(
Exception
e
)
{
successful
=
false
;
if
(
backupDataFile
.
exists
())
{
backupDataFile
.
renameTo
(
oldDataFile
);
}
if
(
backupIndexFile
.
exists
())
{
backupIndexFile
.
renameTo
(
oldIndexFile
);
}
newFile
.
delete
();
// errorStream.println("H2 Migration of '" + oldFile.getPath() +
// "' finished with error: " + e.getMessage());
throw
DbException
.
toSQLException
(
e
);
}
finally
{
if
(
scriptFile
!=
null
)
{
scriptFile
.
delete
();
}
}
}
/**
* Returns if the database upgrade was successful.
*
* @return if the database upgrade was successful
*/
public
boolean
wasSuccessful
()
{
return
successful
;
}
/**
* The conversion script file will per default be created in the db
* directory. Use this method to change the directory to the temp
* directory.
*
* @param scriptInTmpDir true if the conversion script should be
* located in the temp directory.
*/
public
static
void
setScriptInTmpDir
(
boolean
scriptInTmpDir
)
{
DbUpgradeNonPageStoreToCurrent
.
scriptInTmpDir
=
scriptInTmpDir
;
}
/**
* Old files will be renamed to .backup after a successful conversion. To
* delete them after the conversion, use this method with the parameter
* 'true'.
*
* @param deleteOldDb if true, the old db files will be deleted.
*/
public
static
void
setDeleteOldDb
(
boolean
deleteOldDb
)
{
DbUpgradeNonPageStoreToCurrent
.
deleteOldDb
=
deleteOldDb
;
}
}
h2/src/main/org/h2/upgrade/package.html
0 → 100644
浏览文件 @
194fbc5c
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
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
-->
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"en"
xml:lang=
"en"
>
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
Implementation of the database upgrade mechanism.
</body></html>
\ No newline at end of file
h2/src/main/org/h2/util/Utils.java
浏览文件 @
194fbc5c
...
@@ -12,6 +12,10 @@ import java.io.IOException;
...
@@ -12,6 +12,10 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.ObjectOutputStream
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
...
@@ -543,4 +547,205 @@ public class Utils {
...
@@ -543,4 +547,205 @@ public class Utils {
}
}
}
}
/**
* Calls a static method via reflection. The order in which the method is
* searched:
* - With object arguments, eg. doSomething(Integer)
* - With primitive arguments, eg. doSomething(int)
*
* @param classAndMethod a string with the entire class and method name,
* eg. "java.lang.System.gc"
* @param params the method parameters
* @throws ClassNotFoundException if the class was not found
* @throws NoSuchMethodException if the class doesn't contain the method
* @throws InvocationTargetException if an exception occurred in the called
* method
* @throws IllegalAccessException if the reflection call is not allowed
* @throws IllegalArgumentException if the reflection call arguments are
* wrong
* @return Return value from this call
*/
public
static
Object
callStaticMethod
(
String
classAndMethod
,
Object
...
params
)
throws
ClassNotFoundException
,
NoSuchMethodException
,
IllegalArgumentException
,
IllegalAccessException
,
InvocationTargetException
{
int
lastDot
=
classAndMethod
.
lastIndexOf
(
'.'
);
String
className
=
classAndMethod
.
substring
(
0
,
lastDot
);
String
methodName
=
classAndMethod
.
substring
(
lastDot
+
1
);
Class
<
?
>[]
paramTypes
=
getParameterTypesObjects
(
params
);
Class
<
?
>
c
=
Class
.
forName
(
className
);
Method
m
;
try
{
m
=
c
.
getMethod
(
methodName
,
paramTypes
);
}
catch
(
NoSuchMethodException
e
)
{
paramTypes
=
getParameterTypesPrimitives
(
params
);
m
=
c
.
getMethod
(
methodName
,
paramTypes
);
}
return
m
.
invoke
(
null
,
params
);
}
/**
* Calls an instance method via reflection. The order in which the method is
* searched:
* - With object arguments, eg. doSomething(Integer)
* - With primitive arguments, eg. doSomething(int)
*
* @param methodName a string with the method name
* @param instance the instance on which the call is done
* @param params the method parameters
* @throws ClassNotFoundException if the class was not found
* @throws NoSuchMethodException if the class doesn't contain the method
* @throws IllegalArgumentException if the reflection call arguments are
* wrong
* @throws IllegalAccessException if the reflection call is not allowed
* @throws InvocationTargetException if an exception occurred in the called
* method
* @return Return value from this call
*/
public
static
Object
callMethod
(
String
methodName
,
Object
instance
,
Object
...
params
)
throws
ClassNotFoundException
,
NoSuchMethodException
,
IllegalArgumentException
,
IllegalAccessException
,
InvocationTargetException
{
Class
<
?
>[]
paramTypes
=
getParameterTypesObjects
(
params
);
Class
<
?
>
c
=
instance
.
getClass
();
Method
m
;
try
{
m
=
c
.
getMethod
(
methodName
,
paramTypes
);
}
catch
(
NoSuchMethodException
e
)
{
paramTypes
=
getParameterTypesPrimitives
(
params
);
m
=
c
.
getMethod
(
methodName
,
paramTypes
);
}
return
m
.
invoke
(
instance
,
params
);
}
/**
* Creates a new instance. The order in which the constructor is searched:
* - With object arguments, eg. SomeClass(Integer)
* - With primitive arguments, eg. SomeClass(int)
*
* @param className a string with the entire class, eg. "java.lang.Integer"
* @param params the constructor parameters
* @throws ClassNotFoundException if the class was not found
* @throws NoSuchMethodException if the class doesn't contain the
* constructor
* @throws IllegalArgumentException if the reflection call arguments are
* wrong
* @throws InstantiationException if it is not possible to instantiate the
* object
* @throws IllegalAccessException if the reflection call is not allowed
* @throws InvocationTargetException if an exception occurred in the called
* method
* @return the newly created object
*/
public
static
Object
newInstance
(
String
className
,
Object
...
params
)
throws
ClassNotFoundException
,
NoSuchMethodException
,
IllegalArgumentException
,
InstantiationException
,
IllegalAccessException
,
InvocationTargetException
{
Class
<
?
>
c
=
Class
.
forName
(
className
);
Class
<
?
>[]
paramTypes
=
getParameterTypesObjects
(
params
);
Constructor
<
?
>
constructor
;
try
{
constructor
=
c
.
getConstructor
(
paramTypes
);
}
catch
(
NoSuchMethodException
e
)
{
paramTypes
=
getParameterTypesPrimitives
(
params
);
constructor
=
c
.
getConstructor
(
paramTypes
);
}
return
constructor
.
newInstance
(
params
);
}
/**
* Returns a static field.
*
* @param classAndField a string with the entire class and field name
* @return the field value
* @throws ClassNotFoundException if the class was not found
* @throws IllegalAccessException if it is not allowed to access the class
* @throws NoSuchFieldException if the field was not found
*/
public
static
Object
getStaticField
(
String
classAndField
)
throws
ClassNotFoundException
,
IllegalAccessException
,
NoSuchFieldException
{
int
lastDot
=
classAndField
.
lastIndexOf
(
'.'
);
String
className
=
classAndField
.
substring
(
0
,
lastDot
);
String
fieldName
=
classAndField
.
substring
(
lastDot
+
1
);
Class
<
?
>
c
=
Class
.
forName
(
className
);
Field
f
=
c
.
getField
(
fieldName
);
return
f
.
get
(
null
);
}
/**
* Returns a static field.
*
* @param instance the instance on which the call is done
* @param fieldName the field name
* @return the field value
* @throws ClassNotFoundException if the class was not found
* @throws IllegalAccessException if it is not allowed to access the class
* @throws NoSuchFieldException if the field was not found
*/
public
static
Object
getField
(
Object
instance
,
String
fieldName
)
throws
ClassNotFoundException
,
IllegalAccessException
,
NoSuchFieldException
{
Class
<
?
>
c
=
instance
.
getClass
();
Field
f
=
c
.
getField
(
fieldName
);
return
f
.
get
(
instance
);
}
/**
* Returns true if the class is present in the current vm
*
* @param fullyQualifiedClassName a string with the entire class name, eg.
* "java.lang.System"
* @return true if the class is present in the current vm
*/
public
static
boolean
isClassPresent
(
String
fullyQualifiedClassName
)
{
try
{
Class
.
forName
(
fullyQualifiedClassName
);
return
true
;
}
catch
(
ClassNotFoundException
e
)
{
return
false
;
}
}
private
static
Class
<
?
>[]
getParameterTypesObjects
(
Object
...
params
)
{
Class
<
?
>[]
paramTypes
=
new
Class
[
params
.
length
];
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
paramTypes
[
i
]
=
params
[
i
].
getClass
();
}
return
paramTypes
;
}
private
static
Class
<
?
>[]
getParameterTypesPrimitives
(
Object
...
params
)
{
Class
<
?
>[]
paramTypes
=
new
Class
[
params
.
length
];
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
paramTypes
[
i
]
=
getPrimitiveIfPossible
(
params
[
i
].
getClass
());
}
return
paramTypes
;
}
private
static
Class
<
?
>
getPrimitiveIfPossible
(
Class
<
?
>
clazz
)
{
if
(
clazz
==
Boolean
.
class
)
{
return
boolean
.
class
;
}
if
(
clazz
==
Byte
.
class
)
{
return
byte
.
class
;
}
if
(
clazz
==
Character
.
class
)
{
return
char
.
class
;
}
if
(
clazz
==
Double
.
class
)
{
return
double
.
class
;
}
if
(
clazz
==
Float
.
class
)
{
return
float
.
class
;
}
if
(
clazz
==
Integer
.
class
)
{
return
int
.
class
;
}
if
(
clazz
==
Long
.
class
)
{
return
long
.
class
;
}
if
(
clazz
==
Short
.
class
)
{
return
short
.
class
;
}
if
(
clazz
==
Void
.
class
)
{
return
void
.
class
;
}
return
clazz
;
}
}
}
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
194fbc5c
...
@@ -647,4 +647,5 @@ recorder grajciar recording slovensky uninitialized arriving lubomir unchanged
...
@@ -647,4 +647,5 @@ recorder grajciar recording slovensky uninitialized arriving lubomir unchanged
erik dick calculations lutin cite bom evaluating telegard excel bbs deprecation
erik dick calculations lutin cite bom evaluating telegard excel bbs deprecation
importing cumulative fired convenient sums judged anybody vacuum encountered
importing cumulative fired convenient sums judged anybody vacuum encountered
corresponds cnf informatique ilm boundaries shao crossed retroweaver usr pico
corresponds cnf informatique ilm boundaries shao crossed retroweaver usr pico
pengxiang china timestampadd picked histogram transact locker activemq
pengxiang china timestampadd picked releasing autoboxing conversions
\ No newline at end of file
pagestore addon defaults introduced customized histogram transact locker activemq
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论