Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ad601a53
提交
ad601a53
authored
14 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The database upgrade (to upgrade from H2 version 1.1.x) has been simplified.
上级
32b28f61
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
27 行增加
和
15 行删除
+27
-15
Driver.java
h2/src/main/org/h2/Driver.java
+6
-2
ConnectionInfo.java
h2/src/main/org/h2/engine/ConnectionInfo.java
+1
-1
Engine.java
h2/src/main/org/h2/engine/Engine.java
+1
-0
JdbcDataSource.java
h2/src/main/org/h2/jdbcx/JdbcDataSource.java
+4
-2
DbUpgrade.java
h2/src/main/org/h2/upgrade/DbUpgrade.java
+14
-6
TestUpgrade.java
h2/src/test/org/h2/test/db/TestUpgrade.java
+1
-4
没有找到文件。
h2/src/main/org/h2/Driver.java
浏览文件 @
ad601a53
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
*/
*/
package
org
.
h2
;
package
org
.
h2
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.DriverPropertyInfo
;
import
java.sql.DriverPropertyInfo
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
...
@@ -46,7 +47,7 @@ public class Driver implements java.sql.Driver {
...
@@ -46,7 +47,7 @@ public class Driver implements java.sql.Driver {
* @param info the connection properties
* @param info the connection properties
* @return the new connection or null if the URL is not supported
* @return the new connection or null if the URL is not supported
*/
*/
public
Jdbc
Connection
connect
(
String
url
,
Properties
info
)
throws
SQLException
{
public
Connection
connect
(
String
url
,
Properties
info
)
throws
SQLException
{
try
{
try
{
if
(
info
==
null
)
{
if
(
info
==
null
)
{
info
=
new
Properties
();
info
=
new
Properties
();
...
@@ -54,7 +55,10 @@ public class Driver implements java.sql.Driver {
...
@@ -54,7 +55,10 @@ public class Driver implements java.sql.Driver {
if
(!
acceptsURL
(
url
))
{
if
(!
acceptsURL
(
url
))
{
return
null
;
return
null
;
}
}
DbUpgrade
.
upgradeIfRequired
(
url
,
info
);
Connection
c
=
DbUpgrade
.
connctOrUpgrade
(
url
,
info
);
if
(
c
!=
null
)
{
return
c
;
}
return
new
JdbcConnection
(
url
,
info
);
return
new
JdbcConnection
(
url
,
info
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
DbException
.
toSQLException
(
e
);
throw
DbException
.
toSQLException
(
e
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/ConnectionInfo.java
浏览文件 @
ad601a53
...
@@ -83,7 +83,7 @@ public class ConnectionInfo implements Cloneable {
...
@@ -83,7 +83,7 @@ public class ConnectionInfo implements Cloneable {
set
.
addAll
(
list
);
set
.
addAll
(
list
);
String
[]
connectionTime
=
{
"ACCESS_MODE_DATA"
,
"AUTOCOMMIT"
,
"CIPHER"
,
String
[]
connectionTime
=
{
"ACCESS_MODE_DATA"
,
"AUTOCOMMIT"
,
"CIPHER"
,
"CREATE"
,
"CACHE_TYPE"
,
"FILE_LOCK"
,
"IGNORE_UNKNOWN_SETTINGS"
,
"IFEXISTS"
,
"CREATE"
,
"CACHE_TYPE"
,
"FILE_LOCK"
,
"IGNORE_UNKNOWN_SETTINGS"
,
"IFEXISTS"
,
"INIT"
,
"PASSWORD"
,
"RECOVER"
,
"USER"
,
"AUTO_SERVER"
,
"INIT"
,
"PASSWORD"
,
"RECOVER"
,
"USER"
,
"AUTO_SERVER"
,
"NO_UPGRADE"
,
"AUTO_RECONNECT"
,
"OPEN_NEW"
,
"PAGE_SIZE"
,
"PASSWORD_HASH"
,
"JMX"
};
"AUTO_RECONNECT"
,
"OPEN_NEW"
,
"PAGE_SIZE"
,
"PASSWORD_HASH"
,
"JMX"
};
for
(
String
key
:
connectionTime
)
{
for
(
String
key
:
connectionTime
)
{
if
(
SysProperties
.
CHECK
&&
set
.
contains
(
key
))
{
if
(
SysProperties
.
CHECK
&&
set
.
contains
(
key
))
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Engine.java
浏览文件 @
ad601a53
...
@@ -40,6 +40,7 @@ public class Engine implements SessionFactory {
...
@@ -40,6 +40,7 @@ public class Engine implements SessionFactory {
private
Session
openSession
(
ConnectionInfo
ci
,
boolean
ifExists
,
String
cipher
)
{
private
Session
openSession
(
ConnectionInfo
ci
,
boolean
ifExists
,
String
cipher
)
{
String
name
=
ci
.
getName
();
String
name
=
ci
.
getName
();
Database
database
;
Database
database
;
ci
.
removeProperty
(
"NO_UPGRADE"
,
false
);
boolean
openNew
=
ci
.
getProperty
(
"OPEN_NEW"
,
false
);
boolean
openNew
=
ci
.
getProperty
(
"OPEN_NEW"
,
false
);
if
(
openNew
||
ci
.
isUnnamedInMemory
())
{
if
(
openNew
||
ci
.
isUnnamedInMemory
())
{
database
=
null
;
database
=
null
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbcx/JdbcDataSource.java
浏览文件 @
ad601a53
...
@@ -177,11 +177,13 @@ implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Ref
...
@@ -177,11 +177,13 @@ implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Ref
Properties
info
=
new
Properties
();
Properties
info
=
new
Properties
();
info
.
setProperty
(
"user"
,
user
);
info
.
setProperty
(
"user"
,
user
);
info
.
put
(
"password"
,
password
);
info
.
put
(
"password"
,
password
);
Jdbc
Connection
conn
=
Driver
.
load
().
connect
(
url
,
info
);
Connection
conn
=
Driver
.
load
().
connect
(
url
,
info
);
if
(
conn
==
null
)
{
if
(
conn
==
null
)
{
throw
new
SQLException
(
"No suitable driver found for "
+
url
,
"08001"
,
8001
);
throw
new
SQLException
(
"No suitable driver found for "
+
url
,
"08001"
,
8001
);
}
else
if
(!(
conn
instanceof
JdbcConnection
))
{
throw
new
SQLException
(
"Connecting with old version is not supported: "
+
url
,
"08001"
,
8001
);
}
}
return
conn
;
return
(
JdbcConnection
)
conn
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/upgrade/DbUpgrade.java
浏览文件 @
ad601a53
...
@@ -45,9 +45,9 @@ public class DbUpgrade {
...
@@ -45,9 +45,9 @@ public class DbUpgrade {
* @param url the database URL
* @param url the database URL
* @param info the properties
* @param info the properties
*/
*/
public
static
void
upgradeIfRequired
(
String
url
,
Properties
info
)
throws
SQLException
{
public
static
Connection
connctOrUpgrade
(
String
url
,
Properties
info
)
throws
SQLException
{
if
(!
upgradeClassesPresent
)
{
if
(!
upgradeClassesPresent
)
{
return
;
return
null
;
}
}
Properties
i2
=
new
Properties
();
Properties
i2
=
new
Properties
();
i2
.
putAll
(
info
);
i2
.
putAll
(
info
);
...
@@ -59,18 +59,21 @@ public class DbUpgrade {
...
@@ -59,18 +59,21 @@ public class DbUpgrade {
info
=
i2
;
info
=
i2
;
ConnectionInfo
ci
=
new
ConnectionInfo
(
url
,
info
);
ConnectionInfo
ci
=
new
ConnectionInfo
(
url
,
info
);
if
(
ci
.
isRemote
()
||
!
ci
.
isPersistent
())
{
if
(
ci
.
isRemote
()
||
!
ci
.
isPersistent
())
{
return
;
return
null
;
}
}
String
name
=
ci
.
getName
();
String
name
=
ci
.
getName
();
if
(
Database
.
exists
(
name
))
{
if
(
Database
.
exists
(
name
))
{
return
;
return
null
;
}
}
if
(!
IOUtils
.
exists
(
name
+
".data.db"
))
{
if
(!
IOUtils
.
exists
(
name
+
".data.db"
))
{
return
;
return
null
;
}
if
(
ci
.
removeProperty
(
"NO_UPGRADE"
,
false
))
{
return
connectWithOldVersion
(
url
,
info
);
}
}
synchronized
(
DbUpgrade
.
class
)
{
synchronized
(
DbUpgrade
.
class
)
{
upgrade
(
ci
,
info
);
upgrade
(
ci
,
info
);
return
;
return
null
;
}
}
}
}
...
@@ -97,6 +100,11 @@ public class DbUpgrade {
...
@@ -97,6 +100,11 @@ public class DbUpgrade {
DbUpgrade
.
deleteOldDb
=
deleteOldDb
;
DbUpgrade
.
deleteOldDb
=
deleteOldDb
;
}
}
private
static
Connection
connectWithOldVersion
(
String
url
,
Properties
info
)
throws
SQLException
{
url
=
"jdbc:h2v1_1:"
+
url
.
substring
(
"jdbc:h2:"
.
length
())
+
";IGNORE_UNKNOWN_SETTINGS=TRUE"
;
return
DriverManager
.
getConnection
(
url
,
info
);
}
private
static
void
upgrade
(
ConnectionInfo
ci
,
Properties
info
)
throws
SQLException
{
private
static
void
upgrade
(
ConnectionInfo
ci
,
Properties
info
)
throws
SQLException
{
String
name
=
ci
.
getName
();
String
name
=
ci
.
getName
();
String
data
=
name
+
".data.db"
;
String
data
=
name
+
".data.db"
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestUpgrade.java
浏览文件 @
ad601a53
...
@@ -93,10 +93,7 @@ public class TestUpgrade extends TestBase {
...
@@ -93,10 +93,7 @@ public class TestUpgrade extends TestBase {
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/upgrade.h2.db"
));
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/upgrade.h2.db"
));
deleteDb
(
"upgrade"
);
deleteDb
(
"upgrade"
);
conn
=
getConnection
(
"jdbc:h2v1_1:"
+
getBaseDir
()
+
"/upgrade"
);
conn
=
getConnection
(
"upgrade;NO_UPGRADE=TRUE"
);
conn
.
close
();
conn
=
getConnection
(
"upgrade"
);
conn
.
close
();
conn
.
close
();
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/upgrade.h2.db"
));
assertTrue
(
IOUtils
.
exists
(
getBaseDir
()
+
"/upgrade.h2.db"
));
deleteDb
(
"upgrade"
);
deleteDb
(
"upgrade"
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论