Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
130a9f2d
提交
130a9f2d
authored
2月 12, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid StatementBuilder where resetCount() is required
上级
2c0a1fd5
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
69 行增加
和
60 行删除
+69
-60
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+35
-30
TableBase.java
h2/src/main/org/h2/table/TableBase.java
+14
-12
Doclet.java
h2/src/tools/org/h2/build/doclet/Doclet.java
+20
-18
没有找到文件。
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
130a9f2d
...
...
@@ -60,11 +60,13 @@ public class LinkedIndex extends BaseIndex {
@Override
public
void
add
(
Session
session
,
Row
row
)
{
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
St
atementBuilder
buff
=
new
Statement
Builder
(
"INSERT INTO "
);
St
ringBuilder
buff
=
new
String
Builder
(
"INSERT INTO "
);
buff
.
append
(
targetTableName
).
append
(
" VALUES("
);
for
(
int
i
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
Value
v
=
row
.
getValue
(
i
);
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
if
(
v
==
null
)
{
buff
.
append
(
"DEFAULT"
);
}
else
if
(
isNull
(
v
))
{
...
...
@@ -100,7 +102,7 @@ public class LinkedIndex extends BaseIndex {
buff
.
append
(
" IS NULL"
);
}
else
{
buff
.
append
(
">="
);
addParameter
(
buff
,
col
);
addParameter
(
buff
.
builder
()
,
col
);
params
.
add
(
v
);
}
}
...
...
@@ -116,7 +118,7 @@ public class LinkedIndex extends BaseIndex {
buff
.
append
(
" IS NULL"
);
}
else
{
buff
.
append
(
"<="
);
addParameter
(
buff
,
col
);
addParameter
(
buff
.
builder
()
,
col
);
params
.
add
(
v
);
}
}
...
...
@@ -131,16 +133,16 @@ public class LinkedIndex extends BaseIndex {
}
}
private
void
addParameter
(
St
atementBuilder
buff
,
Column
col
)
{
private
void
addParameter
(
St
ringBuilder
builder
,
Column
col
)
{
TypeInfo
type
=
col
.
getType
();
if
(
type
.
getValueType
()
==
Value
.
STRING_FIXED
&&
link
.
isOracle
())
{
// workaround for Oracle
// create table test(id int primary key, name char(15));
// insert into test values(1, 'Hello')
// select * from test where name = ? -- where ? = "Hello" > no rows
bu
ff
.
append
(
"CAST(? AS CHAR("
).
append
(
type
.
getPrecision
()).
append
(
"))"
);
bu
ilder
.
append
(
"CAST(? AS CHAR("
).
append
(
type
.
getPrecision
()).
append
(
"))"
);
}
else
{
bu
ff
.
append
(
'?'
);
bu
ilder
.
append
(
'?'
);
}
}
...
...
@@ -187,23 +189,24 @@ public class LinkedIndex extends BaseIndex {
@Override
public
void
remove
(
Session
session
,
Row
row
)
{
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
StatementBuilder
buff
=
new
StatementBuilder
(
"DELETE FROM "
);
buff
.
append
(
targetTableName
).
append
(
" WHERE "
);
StringBuilder
builder
=
new
StringBuilder
(
"DELETE FROM "
).
append
(
targetTableName
).
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
buff
.
appendExceptFirst
(
"AND "
);
if
(
i
>
0
)
{
builder
.
append
(
"AND "
);
}
Column
col
=
table
.
getColumn
(
i
);
col
.
getSQL
(
bu
ff
.
builder
()
);
col
.
getSQL
(
bu
ilder
);
Value
v
=
row
.
getValue
(
i
);
if
(
isNull
(
v
))
{
bu
ff
.
append
(
" IS NULL "
);
bu
ilder
.
append
(
" IS NULL "
);
}
else
{
bu
ff
.
append
(
'='
);
addParameter
(
bu
ff
,
col
);
bu
ilder
.
append
(
'='
);
addParameter
(
bu
ilder
,
col
);
params
.
add
(
v
);
bu
ff
.
append
(
' '
);
bu
ilder
.
append
(
' '
);
}
}
String
sql
=
bu
ff
.
toString
();
String
sql
=
bu
ilder
.
toString
();
try
{
PreparedStatement
prep
=
link
.
execute
(
sql
,
params
,
false
);
int
count
=
prep
.
executeUpdate
();
...
...
@@ -223,35 +226,37 @@ public class LinkedIndex extends BaseIndex {
*/
public
void
update
(
Row
oldRow
,
Row
newRow
)
{
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
buff
.
append
(
targetTableName
).
append
(
" SET "
);
StringBuilder
builder
=
new
StringBuilder
(
"UPDATE "
).
append
(
targetTableName
).
append
(
" SET "
);
for
(
int
i
=
0
;
i
<
newRow
.
getColumnCount
();
i
++)
{
buff
.
appendExceptFirst
(
", "
);
table
.
getColumn
(
i
).
getSQL
(
buff
.
builder
()).
append
(
'='
);
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
table
.
getColumn
(
i
).
getSQL
(
builder
).
append
(
'='
);
Value
v
=
newRow
.
getValue
(
i
);
if
(
v
==
null
)
{
bu
ff
.
append
(
"DEFAULT"
);
bu
ilder
.
append
(
"DEFAULT"
);
}
else
{
bu
ff
.
append
(
'?'
);
bu
ilder
.
append
(
'?'
);
params
.
add
(
v
);
}
}
buff
.
append
(
" WHERE "
);
buff
.
resetCount
();
builder
.
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
oldRow
.
getColumnCount
();
i
++)
{
Column
col
=
table
.
getColumn
(
i
);
buff
.
appendExceptFirst
(
" AND "
);
col
.
getSQL
(
buff
.
builder
());
if
(
i
>
0
)
{
builder
.
append
(
" AND "
);
}
col
.
getSQL
(
builder
);
Value
v
=
oldRow
.
getValue
(
i
);
if
(
isNull
(
v
))
{
bu
ff
.
append
(
" IS NULL"
);
bu
ilder
.
append
(
" IS NULL"
);
}
else
{
bu
ff
.
append
(
'='
);
bu
ilder
.
append
(
'='
);
params
.
add
(
v
);
addParameter
(
bu
ff
,
col
);
addParameter
(
bu
ilder
,
col
);
}
}
String
sql
=
bu
ff
.
toString
();
String
sql
=
bu
ilder
.
toString
();
try
{
link
.
execute
(
sql
,
params
,
true
);
}
catch
(
Exception
e
)
{
...
...
h2/src/main/org/h2/table/TableBase.java
浏览文件 @
130a9f2d
...
...
@@ -14,7 +14,6 @@ import org.h2.index.IndexType;
import
org.h2.mvstore.db.MVTableEngine
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
...
...
@@ -91,7 +90,7 @@ public abstract class TableBase extends Table {
// closed
return
null
;
}
St
atementBuilder
buff
=
new
Statement
Builder
(
"CREATE "
);
St
ringBuilder
buff
=
new
String
Builder
(
"CREATE "
);
if
(
isTemporary
())
{
if
(
isGlobalTemporary
())
{
buff
.
append
(
"GLOBAL "
);
...
...
@@ -108,15 +107,17 @@ public abstract class TableBase extends Table {
if
(
isHidden
)
{
buff
.
append
(
"IF NOT EXISTS "
);
}
getSQL
(
buff
.
builder
()
);
getSQL
(
buff
);
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
StringUtils
.
quoteStringSQL
(
buff
.
builder
()
,
comment
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
}
buff
.
append
(
"(\n "
);
for
(
Column
column
:
columns
)
{
buff
.
appendExceptFirst
(
",\n "
);
buff
.
append
(
column
.
getCreateSQL
());
for
(
int
i
=
0
,
l
=
columns
.
length
;
i
<
l
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
",\n "
);
}
buff
.
append
(
columns
[
i
].
getCreateSQL
());
}
buff
.
append
(
"\n)"
);
if
(
tableEngine
!=
null
)
{
...
...
@@ -127,15 +128,16 @@ public abstract class TableBase extends Table {
}
if
(
d
==
null
||
!
tableEngine
.
endsWith
(
d
))
{
buff
.
append
(
"\nENGINE "
);
StringUtils
.
quoteIdentifier
(
buff
.
builder
()
,
tableEngine
);
StringUtils
.
quoteIdentifier
(
buff
,
tableEngine
);
}
}
if
(!
tableEngineParams
.
isEmpty
())
{
buff
.
append
(
"\nWITH "
);
buff
.
resetCount
();
for
(
String
parameter
:
tableEngineParams
)
{
buff
.
appendExceptFirst
(
", "
);
StringUtils
.
quoteIdentifier
(
buff
.
builder
(),
parameter
);
for
(
int
i
=
0
,
l
=
tableEngineParams
.
size
();
i
<
l
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
StringUtils
.
quoteIdentifier
(
buff
,
tableEngineParams
.
get
(
i
));
}
}
if
(!
isPersistIndexes
()
&&
!
isPersistData
())
{
...
...
h2/src/tools/org/h2/build/doclet/Doclet.java
浏览文件 @
130a9f2d
...
...
@@ -14,7 +14,6 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.HashSet
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
com.sun.javadoc.ClassDoc
;
import
com.sun.javadoc.ConstructorDoc
;
...
...
@@ -311,31 +310,34 @@ public class Doclet {
return
;
}
Parameter
[]
params
=
method
.
parameters
();
StatementBuilder
buff
=
new
StatementBuilder
();
buff
.
append
(
'('
);
int
i
=
0
;
for
(
Parameter
p
:
params
)
{
boolean
isVarArgs
=
method
.
isVarArgs
()
&&
i
++
==
params
.
length
-
1
;
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
getTypeName
(
false
,
isVarArgs
,
p
.
type
()));
buff
.
append
(
' '
);
buff
.
append
(
p
.
name
());
}
buff
.
append
(
')'
);
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
'('
);
for
(
int
i
=
0
,
l
=
params
.
length
;
i
<
l
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
boolean
isVarArgs
=
method
.
isVarArgs
()
&&
i
==
params
.
length
-
1
;
Parameter
p
=
params
[
i
];
builder
.
append
(
getTypeName
(
false
,
isVarArgs
,
p
.
type
()));
builder
.
append
(
' '
);
builder
.
append
(
p
.
name
());
}
builder
.
append
(
')'
);
ClassDoc
[]
exceptions
=
method
.
thrownExceptions
();
if
(
exceptions
.
length
>
0
)
{
buff
.
append
(
" throws "
);
buff
.
resetCount
();
for
(
ClassDoc
ex
:
exceptions
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
ex
.
typeName
());
builder
.
append
(
" throws "
);
for
(
int
i
=
0
,
l
=
exceptions
.
length
;
i
<
l
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
builder
.
append
(
exceptions
[
i
].
typeName
());
}
}
if
(
isDeprecated
(
method
))
{
name
=
"<span class=\"deprecated\">"
+
name
+
"</span>"
;
}
writer
.
println
(
"<a id=\""
+
signature
+
"\" href=\"#"
+
signature
+
"\">"
+
name
+
"</a>"
+
bu
ff
.
toString
());
name
+
"</a>"
+
bu
ilder
.
toString
());
boolean
hasComment
=
method
.
commentText
()
!=
null
&&
method
.
commentText
().
trim
().
length
()
!=
0
;
writer
.
println
(
"<div class=\"methodText\">"
+
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论