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 {
...
@@ -60,11 +60,13 @@ public class LinkedIndex extends BaseIndex {
@Override
@Override
public
void
add
(
Session
session
,
Row
row
)
{
public
void
add
(
Session
session
,
Row
row
)
{
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
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("
);
buff
.
append
(
targetTableName
).
append
(
" VALUES("
);
for
(
int
i
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
for
(
int
i
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
Value
v
=
row
.
getValue
(
i
);
Value
v
=
row
.
getValue
(
i
);
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
if
(
v
==
null
)
{
if
(
v
==
null
)
{
buff
.
append
(
"DEFAULT"
);
buff
.
append
(
"DEFAULT"
);
}
else
if
(
isNull
(
v
))
{
}
else
if
(
isNull
(
v
))
{
...
@@ -100,7 +102,7 @@ public class LinkedIndex extends BaseIndex {
...
@@ -100,7 +102,7 @@ public class LinkedIndex extends BaseIndex {
buff
.
append
(
" IS NULL"
);
buff
.
append
(
" IS NULL"
);
}
else
{
}
else
{
buff
.
append
(
">="
);
buff
.
append
(
">="
);
addParameter
(
buff
,
col
);
addParameter
(
buff
.
builder
()
,
col
);
params
.
add
(
v
);
params
.
add
(
v
);
}
}
}
}
...
@@ -116,7 +118,7 @@ public class LinkedIndex extends BaseIndex {
...
@@ -116,7 +118,7 @@ public class LinkedIndex extends BaseIndex {
buff
.
append
(
" IS NULL"
);
buff
.
append
(
" IS NULL"
);
}
else
{
}
else
{
buff
.
append
(
"<="
);
buff
.
append
(
"<="
);
addParameter
(
buff
,
col
);
addParameter
(
buff
.
builder
()
,
col
);
params
.
add
(
v
);
params
.
add
(
v
);
}
}
}
}
...
@@ -131,16 +133,16 @@ public class LinkedIndex extends BaseIndex {
...
@@ -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
();
TypeInfo
type
=
col
.
getType
();
if
(
type
.
getValueType
()
==
Value
.
STRING_FIXED
&&
link
.
isOracle
())
{
if
(
type
.
getValueType
()
==
Value
.
STRING_FIXED
&&
link
.
isOracle
())
{
// workaround for Oracle
// workaround for Oracle
// create table test(id int primary key, name char(15));
// create table test(id int primary key, name char(15));
// insert into test values(1, 'Hello')
// insert into test values(1, 'Hello')
// select * from test where name = ? -- where ? = "Hello" > no rows
// 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
{
}
else
{
bu
ff
.
append
(
'?'
);
bu
ilder
.
append
(
'?'
);
}
}
}
}
...
@@ -187,23 +189,24 @@ public class LinkedIndex extends BaseIndex {
...
@@ -187,23 +189,24 @@ public class LinkedIndex extends BaseIndex {
@Override
@Override
public
void
remove
(
Session
session
,
Row
row
)
{
public
void
remove
(
Session
session
,
Row
row
)
{
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
StatementBuilder
buff
=
new
StatementBuilder
(
"DELETE FROM "
);
StringBuilder
builder
=
new
StringBuilder
(
"DELETE FROM "
).
append
(
targetTableName
).
append
(
" WHERE "
);
buff
.
append
(
targetTableName
).
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
for
(
int
i
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
buff
.
appendExceptFirst
(
"AND "
);
if
(
i
>
0
)
{
builder
.
append
(
"AND "
);
}
Column
col
=
table
.
getColumn
(
i
);
Column
col
=
table
.
getColumn
(
i
);
col
.
getSQL
(
bu
ff
.
builder
()
);
col
.
getSQL
(
bu
ilder
);
Value
v
=
row
.
getValue
(
i
);
Value
v
=
row
.
getValue
(
i
);
if
(
isNull
(
v
))
{
if
(
isNull
(
v
))
{
bu
ff
.
append
(
" IS NULL "
);
bu
ilder
.
append
(
" IS NULL "
);
}
else
{
}
else
{
bu
ff
.
append
(
'='
);
bu
ilder
.
append
(
'='
);
addParameter
(
bu
ff
,
col
);
addParameter
(
bu
ilder
,
col
);
params
.
add
(
v
);
params
.
add
(
v
);
bu
ff
.
append
(
' '
);
bu
ilder
.
append
(
' '
);
}
}
}
}
String
sql
=
bu
ff
.
toString
();
String
sql
=
bu
ilder
.
toString
();
try
{
try
{
PreparedStatement
prep
=
link
.
execute
(
sql
,
params
,
false
);
PreparedStatement
prep
=
link
.
execute
(
sql
,
params
,
false
);
int
count
=
prep
.
executeUpdate
();
int
count
=
prep
.
executeUpdate
();
...
@@ -223,35 +226,37 @@ public class LinkedIndex extends BaseIndex {
...
@@ -223,35 +226,37 @@ public class LinkedIndex extends BaseIndex {
*/
*/
public
void
update
(
Row
oldRow
,
Row
newRow
)
{
public
void
update
(
Row
oldRow
,
Row
newRow
)
{
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
ArrayList
<
Value
>
params
=
Utils
.
newSmallArrayList
();
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
StringBuilder
builder
=
new
StringBuilder
(
"UPDATE "
).
append
(
targetTableName
).
append
(
" SET "
);
buff
.
append
(
targetTableName
).
append
(
" SET "
);
for
(
int
i
=
0
;
i
<
newRow
.
getColumnCount
();
i
++)
{
for
(
int
i
=
0
;
i
<
newRow
.
getColumnCount
();
i
++)
{
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
table
.
getColumn
(
i
).
getSQL
(
buff
.
builder
()).
append
(
'='
);
builder
.
append
(
", "
);
}
table
.
getColumn
(
i
).
getSQL
(
builder
).
append
(
'='
);
Value
v
=
newRow
.
getValue
(
i
);
Value
v
=
newRow
.
getValue
(
i
);
if
(
v
==
null
)
{
if
(
v
==
null
)
{
bu
ff
.
append
(
"DEFAULT"
);
bu
ilder
.
append
(
"DEFAULT"
);
}
else
{
}
else
{
bu
ff
.
append
(
'?'
);
bu
ilder
.
append
(
'?'
);
params
.
add
(
v
);
params
.
add
(
v
);
}
}
}
}
buff
.
append
(
" WHERE "
);
builder
.
append
(
" WHERE "
);
buff
.
resetCount
();
for
(
int
i
=
0
;
i
<
oldRow
.
getColumnCount
();
i
++)
{
for
(
int
i
=
0
;
i
<
oldRow
.
getColumnCount
();
i
++)
{
Column
col
=
table
.
getColumn
(
i
);
Column
col
=
table
.
getColumn
(
i
);
buff
.
appendExceptFirst
(
" AND "
);
if
(
i
>
0
)
{
col
.
getSQL
(
buff
.
builder
());
builder
.
append
(
" AND "
);
}
col
.
getSQL
(
builder
);
Value
v
=
oldRow
.
getValue
(
i
);
Value
v
=
oldRow
.
getValue
(
i
);
if
(
isNull
(
v
))
{
if
(
isNull
(
v
))
{
bu
ff
.
append
(
" IS NULL"
);
bu
ilder
.
append
(
" IS NULL"
);
}
else
{
}
else
{
bu
ff
.
append
(
'='
);
bu
ilder
.
append
(
'='
);
params
.
add
(
v
);
params
.
add
(
v
);
addParameter
(
bu
ff
,
col
);
addParameter
(
bu
ilder
,
col
);
}
}
}
}
String
sql
=
bu
ff
.
toString
();
String
sql
=
bu
ilder
.
toString
();
try
{
try
{
link
.
execute
(
sql
,
params
,
true
);
link
.
execute
(
sql
,
params
,
true
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
h2/src/main/org/h2/table/TableBase.java
浏览文件 @
130a9f2d
...
@@ -14,7 +14,6 @@ import org.h2.index.IndexType;
...
@@ -14,7 +14,6 @@ import org.h2.index.IndexType;
import
org.h2.mvstore.db.MVTableEngine
;
import
org.h2.mvstore.db.MVTableEngine
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.result.SortOrder
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
...
@@ -91,7 +90,7 @@ public abstract class TableBase extends Table {
...
@@ -91,7 +90,7 @@ public abstract class TableBase extends Table {
// closed
// closed
return
null
;
return
null
;
}
}
St
atementBuilder
buff
=
new
Statement
Builder
(
"CREATE "
);
St
ringBuilder
buff
=
new
String
Builder
(
"CREATE "
);
if
(
isTemporary
())
{
if
(
isTemporary
())
{
if
(
isGlobalTemporary
())
{
if
(
isGlobalTemporary
())
{
buff
.
append
(
"GLOBAL "
);
buff
.
append
(
"GLOBAL "
);
...
@@ -108,15 +107,17 @@ public abstract class TableBase extends Table {
...
@@ -108,15 +107,17 @@ public abstract class TableBase extends Table {
if
(
isHidden
)
{
if
(
isHidden
)
{
buff
.
append
(
"IF NOT EXISTS "
);
buff
.
append
(
"IF NOT EXISTS "
);
}
}
getSQL
(
buff
.
builder
()
);
getSQL
(
buff
);
if
(
comment
!=
null
)
{
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
" COMMENT "
);
StringUtils
.
quoteStringSQL
(
buff
.
builder
()
,
comment
);
StringUtils
.
quoteStringSQL
(
buff
,
comment
);
}
}
buff
.
append
(
"(\n "
);
buff
.
append
(
"(\n "
);
for
(
Column
column
:
columns
)
{
for
(
int
i
=
0
,
l
=
columns
.
length
;
i
<
l
;
i
++)
{
buff
.
appendExceptFirst
(
",\n "
);
if
(
i
>
0
)
{
buff
.
append
(
column
.
getCreateSQL
());
buff
.
append
(
",\n "
);
}
buff
.
append
(
columns
[
i
].
getCreateSQL
());
}
}
buff
.
append
(
"\n)"
);
buff
.
append
(
"\n)"
);
if
(
tableEngine
!=
null
)
{
if
(
tableEngine
!=
null
)
{
...
@@ -127,15 +128,16 @@ public abstract class TableBase extends Table {
...
@@ -127,15 +128,16 @@ public abstract class TableBase extends Table {
}
}
if
(
d
==
null
||
!
tableEngine
.
endsWith
(
d
))
{
if
(
d
==
null
||
!
tableEngine
.
endsWith
(
d
))
{
buff
.
append
(
"\nENGINE "
);
buff
.
append
(
"\nENGINE "
);
StringUtils
.
quoteIdentifier
(
buff
.
builder
()
,
tableEngine
);
StringUtils
.
quoteIdentifier
(
buff
,
tableEngine
);
}
}
}
}
if
(!
tableEngineParams
.
isEmpty
())
{
if
(!
tableEngineParams
.
isEmpty
())
{
buff
.
append
(
"\nWITH "
);
buff
.
append
(
"\nWITH "
);
buff
.
resetCount
();
for
(
int
i
=
0
,
l
=
tableEngineParams
.
size
();
i
<
l
;
i
++)
{
for
(
String
parameter
:
tableEngineParams
)
{
if
(
i
>
0
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
", "
);
StringUtils
.
quoteIdentifier
(
buff
.
builder
(),
parameter
);
}
StringUtils
.
quoteIdentifier
(
buff
,
tableEngineParams
.
get
(
i
));
}
}
}
}
if
(!
isPersistIndexes
()
&&
!
isPersistData
())
{
if
(!
isPersistIndexes
()
&&
!
isPersistData
())
{
...
...
h2/src/tools/org/h2/build/doclet/Doclet.java
浏览文件 @
130a9f2d
...
@@ -14,7 +14,6 @@ import java.util.ArrayList;
...
@@ -14,7 +14,6 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.Comparator
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
com.sun.javadoc.ClassDoc
;
import
com.sun.javadoc.ClassDoc
;
import
com.sun.javadoc.ConstructorDoc
;
import
com.sun.javadoc.ConstructorDoc
;
...
@@ -311,31 +310,34 @@ public class Doclet {
...
@@ -311,31 +310,34 @@ public class Doclet {
return
;
return
;
}
}
Parameter
[]
params
=
method
.
parameters
();
Parameter
[]
params
=
method
.
parameters
();
StatementBuilder
buff
=
new
StatementBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
buff
.
append
(
'('
);
builder
.
append
(
'('
);
int
i
=
0
;
for
(
int
i
=
0
,
l
=
params
.
length
;
i
<
l
;
i
++)
{
for
(
Parameter
p
:
params
)
{
if
(
i
>
0
)
{
boolean
isVarArgs
=
method
.
isVarArgs
()
&&
i
++
==
params
.
length
-
1
;
builder
.
append
(
", "
);
buff
.
appendExceptFirst
(
", "
);
}
buff
.
append
(
getTypeName
(
false
,
isVarArgs
,
p
.
type
()));
boolean
isVarArgs
=
method
.
isVarArgs
()
&&
i
==
params
.
length
-
1
;
buff
.
append
(
' '
);
Parameter
p
=
params
[
i
];
buff
.
append
(
p
.
name
());
builder
.
append
(
getTypeName
(
false
,
isVarArgs
,
p
.
type
()));
}
builder
.
append
(
' '
);
buff
.
append
(
')'
);
builder
.
append
(
p
.
name
());
}
builder
.
append
(
')'
);
ClassDoc
[]
exceptions
=
method
.
thrownExceptions
();
ClassDoc
[]
exceptions
=
method
.
thrownExceptions
();
if
(
exceptions
.
length
>
0
)
{
if
(
exceptions
.
length
>
0
)
{
buff
.
append
(
" throws "
);
builder
.
append
(
" throws "
);
buff
.
resetCount
();
for
(
int
i
=
0
,
l
=
exceptions
.
length
;
i
<
l
;
i
++)
{
for
(
ClassDoc
ex
:
exceptions
)
{
if
(
i
>
0
)
{
buff
.
appendExceptFirst
(
", "
);
builder
.
append
(
", "
);
buff
.
append
(
ex
.
typeName
());
}
builder
.
append
(
exceptions
[
i
].
typeName
());
}
}
}
}
if
(
isDeprecated
(
method
))
{
if
(
isDeprecated
(
method
))
{
name
=
"<span class=\"deprecated\">"
+
name
+
"</span>"
;
name
=
"<span class=\"deprecated\">"
+
name
+
"</span>"
;
}
}
writer
.
println
(
"<a id=\""
+
signature
+
"\" href=\"#"
+
signature
+
"\">"
+
writer
.
println
(
"<a id=\""
+
signature
+
"\" href=\"#"
+
signature
+
"\">"
+
name
+
"</a>"
+
bu
ff
.
toString
());
name
+
"</a>"
+
bu
ilder
.
toString
());
boolean
hasComment
=
method
.
commentText
()
!=
null
&&
boolean
hasComment
=
method
.
commentText
()
!=
null
&&
method
.
commentText
().
trim
().
length
()
!=
0
;
method
.
commentText
().
trim
().
length
()
!=
0
;
writer
.
println
(
"<div class=\"methodText\">"
+
writer
.
println
(
"<div class=\"methodText\">"
+
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论