Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e857a250
提交
e857a250
authored
2月 20, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup:
- Let it compile with JDK 5
上级
dd7cdf0d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
35 行增加
和
36 行删除
+35
-36
Db.java
h2/src/tools/org/h2/jaqu/Db.java
+24
-17
GenerateModels.java
h2/src/tools/org/h2/jaqu/util/GenerateModels.java
+11
-13
Utils.java
h2/src/tools/org/h2/jaqu/util/Utils.java
+0
-6
没有找到文件。
h2/src/tools/org/h2/jaqu/Db.java
浏览文件 @
e857a250
...
...
@@ -14,6 +14,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
...
...
@@ -27,6 +28,7 @@ import org.h2.jaqu.util.JdbcUtils;
import
org.h2.jaqu.util.StringUtils
;
import
org.h2.jaqu.util.Utils
;
import
org.h2.jaqu.util.WeakIdentityHashMap
;
//## Java 1.5 end ##
/**
* This class represents a connection to a database.
...
...
@@ -48,14 +50,17 @@ public class Db {
Utils
.
newHashMap
();
private
final
SQLDialect
dialect
;
private
DbUpgrader
dbUpgrader
=
new
DefaultDbUpgrader
();
private
final
Set
<
Class
<?>>
upgradeChecked
=
Utils
.
newConcurrentHashSet
();
private
final
Set
<
Class
<?>>
upgradeChecked
=
Collections
.
synchronizedSet
(
new
HashSet
<
Class
<?>>());
private
int
todoDocumentNewFeaturesInHtmlFile
;
public
Db
(
Connection
conn
)
{
this
.
conn
=
conn
;
dialect
=
getDialect
(
conn
.
getClass
().
getCanonicalName
());
}
SQLDialect
getDialect
(
String
clazz
)
{
int
todo
;
// TODO add special cases here
return
new
DefaultSQLDialect
();
}
...
...
@@ -119,6 +124,7 @@ public class Db {
public
<
T
>
void
insert
(
T
t
)
{
Class
<?>
clazz
=
t
.
getClass
();
int
upgradeDbSoundsWrongHere
;
upgradeDb
().
define
(
clazz
).
createTableIfRequired
(
this
).
insert
(
this
,
t
,
false
);
}
...
...
@@ -141,13 +147,13 @@ public class Db {
Class
<?>
clazz
=
t
.
getClass
();
upgradeDb
().
define
(
clazz
).
createTableIfRequired
(
this
).
delete
(
this
,
t
);
}
public
<
T
extends
Object
>
Query
<
T
>
from
(
T
alias
)
{
Class
<?>
clazz
=
alias
.
getClass
();
upgradeDb
().
define
(
clazz
).
createTableIfRequired
(
this
);
return
Query
.
from
(
this
,
alias
);
}
Db
upgradeDb
()
{
if
(!
upgradeChecked
.
contains
(
dbUpgrader
.
getClass
()))
{
// Flag as checked immediately because calls are nested.
...
...
@@ -156,7 +162,7 @@ public class Db {
JQDatabase
model
=
dbUpgrader
.
getClass
().
getAnnotation
(
JQDatabase
.
class
);
if
(
model
.
version
()
>
0
)
{
DbVersion
v
=
new
DbVersion
();
DbVersion
dbVersion
=
DbVersion
dbVersion
=
// (SCHEMA="" && TABLE="") == DATABASE
from
(
v
).
where
(
v
.
schema
).
is
(
""
).
and
(
v
.
table
).
is
(
""
).
selectFirst
();
if
(
dbVersion
==
null
)
{
...
...
@@ -167,7 +173,7 @@ public class Db {
}
else
{
// Database has a version registration,
// check to see if upgrade is required.
if
((
model
.
version
()
>
dbVersion
.
version
)
if
((
model
.
version
()
>
dbVersion
.
version
)
&&
(
dbUpgrader
!=
null
))
{
// Database is an older version than model.
boolean
success
=
dbUpgrader
.
upgradeDatabase
(
this
,
...
...
@@ -182,7 +188,7 @@ public class Db {
}
return
this
;
}
<
T
>
void
upgradeTable
(
TableDefinition
<
T
>
model
)
{
if
(!
upgradeChecked
.
contains
(
model
.
getModelClass
()))
{
// Flag as checked immediately because calls are nested.
...
...
@@ -192,7 +198,7 @@ public class Db {
// Table is using JaQu version tracking.
DbVersion
v
=
new
DbVersion
();
String
schema
=
StringUtils
.
isNullOrEmpty
(
model
.
schemaName
)
?
""
:
model
.
schemaName
;
DbVersion
dbVersion
=
DbVersion
dbVersion
=
from
(
v
).
where
(
v
.
schema
).
like
(
schema
).
and
(
v
.
table
)
.
like
(
model
.
tableName
).
selectFirst
();
if
(
dbVersion
==
null
)
{
...
...
@@ -205,7 +211,7 @@ public class Db {
}
else
{
// Table has a version registration.
// Check to see if upgrade is required.
if
((
model
.
tableVersion
>
dbVersion
.
version
)
if
((
model
.
tableVersion
>
dbVersion
.
version
)
&&
(
dbUpgrader
!=
null
))
{
// Table is an older version than model.
boolean
success
=
dbUpgrader
.
upgradeTable
(
this
,
schema
,
...
...
@@ -233,12 +239,12 @@ public class Db {
}
else
if
(
clazz
.
isAnnotationPresent
(
JQTable
.
class
))
{
// Annotated Class skips Define().define() static initializer
T
t
=
instance
(
clazz
);
def
.
mapObject
(
t
);
def
.
mapObject
(
t
);
}
}
return
def
;
}
public
synchronized
void
setDbUpgrader
(
DbUpgrader
upgrader
)
{
if
(
upgrader
==
null
)
throw
new
RuntimeException
(
"DbUpgrader may not be NULL!"
);
...
...
@@ -248,11 +254,11 @@ public class Db {
this
.
dbUpgrader
=
upgrader
;
upgradeChecked
.
clear
();
}
SQLDialect
getDialect
()
{
return
dialect
;
}
public
Connection
getConnection
()
{
return
conn
;
}
...
...
@@ -295,10 +301,11 @@ public class Db {
}
}
PreparedStatement
prepare
(
String
sql
,
boolean
return
Key
)
{
PreparedStatement
prepare
(
String
sql
,
boolean
return
GeneratedKeys
)
{
try
{
if
(
returnKey
)
return
conn
.
prepareStatement
(
sql
,
PreparedStatement
.
RETURN_GENERATED_KEYS
);
if
(
returnGeneratedKeys
)
{
return
conn
.
prepareStatement
(
sql
,
Statement
.
RETURN_GENERATED_KEYS
);
}
return
conn
.
prepareStatement
(
sql
);
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
...
...
h2/src/tools/org/h2/jaqu/util/GenerateModels.java
浏览文件 @
e857a250
...
...
@@ -21,10 +21,10 @@ import java.util.regex.Matcher;
import
java.util.regex.Pattern
;
import
org.h2.jaqu.Db
;
import
org.h2.jaqu.DbInspector
;
import
org.h2.message.DbException
;
/**
* Generates JaQu models.
*
*/
public
class
GenerateModels
{
...
...
@@ -32,7 +32,7 @@ public class GenerateModels {
* The output stream where this tool writes to.
*/
protected
PrintStream
out
=
System
.
out
;
public
static
void
main
(
String
...
args
)
throws
SQLException
{
new
GenerateModels
().
runTool
(
args
);
}
...
...
@@ -82,13 +82,13 @@ public class GenerateModels {
if
(
url
==
null
)
{
throw
new
SQLException
(
"URL not set"
);
}
execute
(
url
,
user
,
password
,
schema
,
table
,
packageName
,
folder
,
execute
(
url
,
user
,
password
,
schema
,
table
,
packageName
,
folder
,
annotateSchema
,
trimStrings
);
}
/**
* Generates models from the database.
*
*
* @param url the database URL
* @param user the user name
* @param password the password
...
...
@@ -99,8 +99,8 @@ public class GenerateModels {
* @param annotateSchema includes the schema in the table model annotations
* @param trimStrings automatically trim strings that exceed maxLength
*/
public
static
void
execute
(
String
url
,
String
user
,
String
password
,
String
schema
,
String
table
,
String
packageName
,
String
folder
,
public
static
void
execute
(
String
url
,
String
user
,
String
password
,
String
schema
,
String
table
,
String
packageName
,
String
folder
,
boolean
annotateSchema
,
boolean
trimStrings
)
throws
SQLException
{
Connection
conn
=
null
;
...
...
@@ -109,7 +109,7 @@ public class GenerateModels {
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
Db
db
=
Db
.
open
(
url
,
user
,
password
.
toCharArray
());
DbInspector
inspector
=
new
DbInspector
(
db
);
List
<
String
>
models
=
inspector
.
generateModel
(
schema
,
table
,
List
<
String
>
models
=
inspector
.
generateModel
(
schema
,
table
,
packageName
,
annotateSchema
,
trimStrings
);
File
parentFile
;
if
(
StringUtils
.
isNullOrEmpty
(
folder
))
...
...
@@ -130,15 +130,13 @@ public class GenerateModels {
System
.
out
.
println
(
"Generated "
+
classFile
.
getAbsolutePath
());
}
}
}
catch
(
SQLException
s
)
{
throw
s
;
}
catch
(
IOException
i
)
{
throw
new
SQLException
(
i
);
}
catch
(
IOException
io
)
{
throw
DbException
.
convertIOException
(
io
,
"could not generate model"
).
getSQLException
();
}
finally
{
JdbcUtils
.
closeSilently
(
conn
);
}
}
/**
* Throw a SQLException saying this command line option is not supported.
*
...
...
@@ -149,7 +147,7 @@ public class GenerateModels {
showUsage
();
throw
new
SQLException
(
"Unsupported option: "
+
option
);
}
protected
void
showUsage
()
{
out
.
println
(
"GenerateModels"
);
out
.
println
(
"Usage: java "
+
getClass
().
getName
());
...
...
h2/src/tools/org/h2/jaqu/util/Utils.java
浏览文件 @
e857a250
...
...
@@ -22,8 +22,6 @@ import java.util.HashSet;
import
java.util.IdentityHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.atomic.AtomicLong
;
//## Java 1.5 end ##
...
...
@@ -55,10 +53,6 @@ public class Utils {
return
new
HashSet
<
T
>(
list
);
}
public
static
<
T
>
Set
<
T
>
newConcurrentHashSet
()
{
return
Collections
.
newSetFromMap
(
new
ConcurrentHashMap
<
T
,
Boolean
>());
}
public
static
<
A
,
B
>
HashMap
<
A
,
B
>
newHashMap
()
{
return
new
HashMap
<
A
,
B
>();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论