Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
24e903c6
提交
24e903c6
authored
10月 12, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup of MergeUsing useless stuff copied from Merge
上级
2ac7c44d
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
72 行删除
+19
-72
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+19
-72
没有找到文件。
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
24e903c6
...
...
@@ -19,7 +19,6 @@ import org.h2.engine.Session;
import
org.h2.expression.ConditionAndOr
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.expression.Parameter
;
import
org.h2.message.DbException
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
...
...
@@ -44,7 +43,6 @@ public class MergeUsing extends Prepared {
private
Column
[]
keys
;
private
final
ArrayList
<
Expression
[]>
valuesExpressionList
=
New
.
arrayList
();
private
Query
query
;
private
Prepared
update
;
// MergeUsing fields
private
TableFilter
sourceTableFilter
;
...
...
@@ -68,6 +66,8 @@ public class MergeUsing extends Prepared {
@Override
public
int
update
()
{
// clear list of source table keys we have processed already
sourceKeysRemembered
.
clear
();
if
(
targetTableFilter
!=
null
){
...
...
@@ -93,7 +93,6 @@ public class MergeUsing extends Prepared {
countInputRows
++;
Value
[]
sourceRowValues
=
rows
.
currentRow
();
Row
sourceRow
=
new
RowImpl
(
sourceRowValues
,
0
);
Row
newTargetRow
=
targetTable
.
getTemplateRow
();
ArrayList
<
Value
>
sourceKeyValuesList
=
new
ArrayList
<
Value
>();
setCurrentRowNumber
(
countInputRows
);
...
...
@@ -120,19 +119,7 @@ public class MergeUsing extends Prepared {
sourceKeysRemembered
.
put
(
sourceKeyValuesList
,
countInputRows
);
}
// compute the new target row columns values
for
(
int
j
=
0
;
j
<
columns
.
length
;
j
++)
{
Column
c
=
columns
[
j
];
int
index
=
c
.
getColumnId
();
try
{
Value
v
=
c
.
convert
(
sourceRowValues
[
j
]);
newTargetRow
.
setValue
(
index
,
v
);
}
catch
(
DbException
ex
)
{
throw
setRow
(
ex
,
countInputRows
,
getSQL
(
sourceRowValues
));
}
}
merge
(
sourceRow
,
sourceRowValues
,
newTargetRow
);
merge
(
sourceRow
,
sourceRowValues
);
}
rows
.
close
();
targetTable
.
fire
(
session
,
evaluateTriggerMasks
(),
false
);
...
...
@@ -164,11 +151,13 @@ public class MergeUsing extends Prepared {
if
(
deleteCommand
!=
null
){
session
.
getUser
().
checkRight
(
targetTable
,
Right
.
DELETE
);
}
}
protected
void
merge
(
Row
sourceRow
,
Value
[]
sourceRowValues
,
Row
newTargetRow
)
{
configPreparedParameters
(
newTargetRow
,
update
);
// check the underlying tables
session
.
getUser
().
checkRight
(
targetTable
,
Right
.
SELECT
);
session
.
getUser
().
checkRight
(
sourceTableFilter
.
getTable
(),
Right
.
SELECT
);
}
protected
void
merge
(
Row
sourceRow
,
Value
[]
sourceRowValues
)
{
// put the column values into the table filter
sourceTableFilter
.
set
(
sourceRow
);
...
...
@@ -191,36 +180,16 @@ public class MergeUsing extends Prepared {
// if either updates do nothing, try an insert
if
(
rowUpdateCount
==
0
)
{
rowUpdateCount
+=
addRowByCommandInsert
(
session
,
newTargetRow
);
rowUpdateCount
+=
addRowByCommandInsert
(
session
);
}
else
if
(
rowUpdateCount
!=
1
)
{
throw
DbException
.
get
(
ErrorCode
.
DUPLICATE_KEY_1
,
"Duplicate key updated "
+
rowUpdateCount
+
" rows at once, only 1 expected:"
+
targetTable
.
getSQL
());
}
countUpdatedRows
+=
rowUpdateCount
;
}
private
void
configPreparedParameters
(
Row
newTargetRow
,
Prepared
updatePrepared
)
{
ArrayList
<
Parameter
>
k
=
updatePrepared
.
getParameters
();
// set each parameter in the updatePrepared with the real value from the source column
// 0 to columns.length-1
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
Column
col
=
columns
[
i
];
Value
v
=
newTargetRow
.
getValue
(
col
.
getColumnId
());
Parameter
p
=
k
.
get
(
i
);
p
.
setValue
(
v
);
}
// columns.length to columns.length+keys.length-1
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
Column
col
=
keys
[
i
];
Value
v
=
newTargetRow
.
getValue
(
col
.
getColumnId
());
if
(
v
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
COLUMN_CONTAINS_NULL_VALUES_1
,
col
.
getSQL
());
}
Parameter
p
=
k
.
get
(
columns
.
length
+
i
);
p
.
setValue
(
v
);
}
}
private
int
addRowByCommandInsert
(
Session
session
,
Row
newTargetRow
)
{
private
int
addRowByCommandInsert
(
Session
session
/*, Row newTargetRow*/
)
{
int
localCount
=
0
;
if
(
insertCommand
!=
null
){
localCount
+=
insertCommand
.
update
();
...
...
@@ -228,6 +197,7 @@ public class MergeUsing extends Prepared {
return
localCount
;
}
// Use the regular merge syntax as our plan SQL
@Override
public
String
getPlanSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
...
...
@@ -276,10 +246,10 @@ public class MergeUsing extends Prepared {
public
void
prepare
()
{
onCondition
.
addFilterConditions
(
sourceTableFilter
,
true
);
onCondition
.
addFilterConditions
(
targetTableFilter
,
true
);
onCondition
.
mapColumns
(
sourceTableFilter
,
2
);
onCondition
.
mapColumns
(
targetTableFilter
,
1
);
if
(
keys
==
null
)
{
HashSet
<
Column
>
targetColumns
=
buildColumnListFromOnCondition
(
targetTableFilter
);
keys
=
targetColumns
.
toArray
(
new
Column
[
0
]);
...
...
@@ -329,10 +299,7 @@ public class MergeUsing extends Prepared {
}
}
String
sql
=
buildPreparedSQL
();
update
=
session
.
prepare
(
sql
);
// Not sure how these sub-prepares will work...
// Prepare each of the sub-commands ready to aid in the MERGE collaboration
if
(
updateCommand
!=
null
){
updateCommand
.
setSourceTableFilter
(
sourceTableFilter
);
updateCommand
.
setCondition
(
appendOnCondition
(
updateCommand
));
...
...
@@ -376,27 +343,6 @@ public class MergeUsing extends Prepared {
return
new
ConditionAndOr
(
ConditionAndOr
.
AND
,
deleteCommand
.
getCondition
(),
onCondition
);
}
private
String
buildPreparedSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
buff
.
append
(
targetTable
.
getSQL
());
if
(
targetTableFilter
.
getTableAlias
()!=
null
){
buff
.
append
(
" AS "
+
targetTableFilter
.
getTableAlias
()+
" "
);
}
buff
.
append
(
" SET "
);
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
}
buff
.
append
(
" WHERE "
);
buff
.
resetCount
();
for
(
Column
c
:
keys
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
}
String
sql
=
buff
.
toString
();
return
sql
;
}
public
void
setSourceTableFilter
(
TableFilter
sourceTableFilter
)
{
this
.
sourceTableFilter
=
sourceTableFilter
;
}
...
...
@@ -458,7 +404,8 @@ public class MergeUsing extends Prepared {
public
void
setTargetTable
(
Table
targetTable
)
{
this
.
targetTable
=
targetTable
;
}
// Prepared interface
// Prepared interface implementations
@Override
public
boolean
isTransactional
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论