Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
32e14584
提交
32e14584
authored
8月 08, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JaQu: the order of the fields in the database no longer needs to match the order in the database.
上级
07063c2c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
70 行增加
和
12 行删除
+70
-12
SamplesTest.java
h2/src/test/org/h2/test/jaqu/SamplesTest.java
+30
-6
Db.java
h2/src/tools/org/h2/jaqu/Db.java
+14
-2
Query.java
h2/src/tools/org/h2/jaqu/Query.java
+7
-3
TableDefinition.java
h2/src/tools/org/h2/jaqu/TableDefinition.java
+19
-1
没有找到文件。
h2/src/test/org/h2/test/jaqu/SamplesTest.java
浏览文件 @
32e14584
...
...
@@ -6,14 +6,14 @@
*/
package
org
.
h2
.
test
.
jaqu
;
import
static
org
.
h2
.
jaqu
.
Function
.
count
;
import
static
org
.
h2
.
jaqu
.
Function
.
isNull
;
import
static
org
.
h2
.
jaqu
.
Function
.
length
;
import
static
org
.
h2
.
jaqu
.
Function
.*;
import
java.math.BigDecimal
;
//## Java 1.5 begin ##
import
java.util.List
;
import
org.h2.jaqu.Db
;
import
org.h2.jaqu.Filter
;
import
static
org
.
h2
.
jaqu
.
Function
.*;
//## Java 1.5 end ##
import
org.h2.test.TestBase
;
/**
...
...
@@ -52,8 +52,8 @@ public class SamplesTest extends TestBase {
db
.
insertAll
(
Order
.
getList
());
db
.
insertAll
(
ComplexObject
.
getList
());
// TODO support JavaBeans specification
// TODO support all relevant data types (byte[],...)
// TODO nested AND/OR, >, <,...
// TODO support all relevant data types (byte[],
...)
// TODO nested AND/OR, >, <,
...
// TODO NOT
// TODO +, -, *, /, ||, nested operations
// TODO LIKE ESCAPE...
...
...
@@ -77,10 +77,34 @@ public class SamplesTest extends TestBase {
testAnonymousTypes3
();
testWhereSimple2
();
testWhereSimple3
();
testReverseColumns
();
db
.
close
();
//## Java 1.5 end ##
}
/**
* A simple test table. The columns are in a different order than in the
* database.
*/
public
static
class
TestReverse
{
public
String
name
;
public
Integer
id
;
}
//## Java 1.5 begin ##
private
void
testReverseColumns
()
{
db
.
executeUpdate
(
"create table TestReverse(id int, name varchar)"
);
TestReverse
t
=
new
TestReverse
();
t
.
id
=
10
;
t
.
name
=
"Hello"
;
db
.
insert
(
t
);
TestReverse
check
=
db
.
from
(
new
TestReverse
()).
selectFirst
();
assertEquals
(
t
.
name
,
check
.
name
);
assertEquals
(
t
.
id
,
check
.
id
);
}
//## Java 1.5 end ##
//## Java 1.5 begin ##
private
void
testWhereSimple2
()
{
...
...
h2/src/tools/org/h2/jaqu/Db.java
浏览文件 @
32e14584
...
...
@@ -140,7 +140,13 @@ public class Db {
return
(
TableDefinition
<
T
>)
classMap
.
get
(
clazz
);
}
ResultSet
executeQuery
(
String
sql
)
{
/**
* Run a SQL query directly against the database.
*
* @param sql the SQL statement
* @return the result set
*/
public
ResultSet
executeQuery
(
String
sql
)
{
try
{
return
conn
.
createStatement
().
executeQuery
(
sql
);
}
catch
(
SQLException
e
)
{
...
...
@@ -148,7 +154,13 @@ public class Db {
}
}
int
executeUpdate
(
String
sql
)
{
/**
* Run a SQL statement directly against the database.
*
* @param sql the SQL statement
* @return the update count
*/
public
int
executeUpdate
(
String
sql
)
{
try
{
return
conn
.
createStatement
().
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
...
...
h2/src/tools/org/h2/jaqu/Query.java
浏览文件 @
32e14584
...
...
@@ -63,6 +63,10 @@ public class Query<T> {
return
select
(
false
);
}
public
T
selectFirst
()
{
return
select
(
false
).
get
(
0
);
}
public
List
<
T
>
selectDistinct
()
{
return
select
(
true
);
}
...
...
@@ -81,8 +85,8 @@ public class Query<T> {
private
List
<
T
>
select
(
boolean
distinct
)
{
List
<
T
>
result
=
Utils
.
newArrayList
();
SQLStatement
selectList
=
new
SQLStatement
(
db
);
selectList
.
setSQL
(
"*"
);
TableDefinition
<
T
>
def
=
from
.
getAliasDefinition
(
);
SQLStatement
selectList
=
def
.
getSelectList
(
db
);
ResultSet
rs
=
prepare
(
selectList
,
distinct
).
executeQuery
();
try
{
while
(
rs
.
next
())
{
...
...
@@ -123,10 +127,10 @@ public class Query<T> {
}
private
<
X
>
List
<
X
>
select
(
Class
<
X
>
clazz
,
X
x
,
boolean
distinct
)
{
List
<
X
>
result
=
Utils
.
newArrayList
();
TableDefinition
<
X
>
def
=
db
.
define
(
clazz
);
SQLStatement
selectList
=
def
.
getSelectList
(
this
,
x
);
ResultSet
rs
=
prepare
(
selectList
,
distinct
).
executeQuery
();
List
<
X
>
result
=
Utils
.
newArrayList
();
try
{
while
(
rs
.
next
())
{
X
row
=
Utils
.
newObject
(
clazz
);
...
...
h2/src/tools/org/h2/jaqu/TableDefinition.java
浏览文件 @
32e14584
...
...
@@ -168,7 +168,13 @@ class TableDefinition<T> {
void
insert
(
Db
db
,
Object
obj
)
{
SQLStatement
stat
=
new
SQLStatement
(
db
);
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
buff
.
append
(
tableName
).
append
(
" VALUES("
);
buff
.
append
(
tableName
).
append
(
'('
);
for
(
FieldDefinition
field
:
fields
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
field
.
columnName
);
}
buff
.
append
(
") VALUES("
);
buff
.
resetCount
();
for
(
FieldDefinition
field
:
fields
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
'?'
);
...
...
@@ -236,6 +242,18 @@ class TableDefinition<T> {
}
}
SQLStatement
getSelectList
(
Db
db
)
{
SQLStatement
selectList
=
new
SQLStatement
(
db
);
for
(
int
i
=
0
;
i
<
fields
.
size
();
i
++)
{
if
(
i
>
0
)
{
selectList
.
appendSQL
(
", "
);
}
FieldDefinition
def
=
fields
.
get
(
i
);
selectList
.
appendSQL
(
def
.
columnName
);
}
return
selectList
;
}
<
Y
,
X
>
SQLStatement
getSelectList
(
Query
<
Y
>
query
,
X
x
)
{
SQLStatement
selectList
=
new
SQLStatement
(
query
.
getDb
());
for
(
int
i
=
0
;
i
<
fields
.
size
();
i
++)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论