Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
426737dd
提交
426737dd
authored
1月 31, 2018
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
create enums for ConstraintActionType and UnionType
上级
cad0c35a
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
112 行增加
和
101 行删除
+112
-101
Parser.java
h2/src/main/org/h2/command/Parser.java
+17
-17
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+5
-4
DropTable.java
h2/src/main/org/h2/command/ddl/DropTable.java
+6
-7
DropView.java
h2/src/main/org/h2/command/ddl/DropView.java
+6
-6
SelectUnion.java
h2/src/main/org/h2/command/dml/SelectUnion.java
+23
-21
ConstraintActionType.java
h2/src/main/org/h2/constraint/ConstraintActionType.java
+28
-0
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+21
-41
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+6
-5
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
426737dd
...
@@ -90,7 +90,7 @@ import org.h2.command.dml.Set;
...
@@ -90,7 +90,7 @@ import org.h2.command.dml.Set;
import
org.h2.command.dml.SetTypes
;
import
org.h2.command.dml.SetTypes
;
import
org.h2.command.dml.TransactionCommand
;
import
org.h2.command.dml.TransactionCommand
;
import
org.h2.command.dml.Update
;
import
org.h2.command.dml.Update
;
import
org.h2.constraint.Constraint
Referential
;
import
org.h2.constraint.Constraint
ActionType
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.DbObject
;
...
@@ -1599,12 +1599,12 @@ public class Parser {
...
@@ -1599,12 +1599,12 @@ public class Parser {
ifExists
=
readIfExists
(
ifExists
);
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
if
(
readIf
(
"CASCADE"
))
{
if
(
readIf
(
"CASCADE"
))
{
command
.
setDropAction
(
Constraint
Referential
.
CASCADE
);
command
.
setDropAction
(
Constraint
ActionType
.
CASCADE
);
readIf
(
"CONSTRAINTS"
);
readIf
(
"CONSTRAINTS"
);
}
else
if
(
readIf
(
"RESTRICT"
))
{
}
else
if
(
readIf
(
"RESTRICT"
))
{
command
.
setDropAction
(
Constraint
Referential
.
RESTRICT
);
command
.
setDropAction
(
Constraint
ActionType
.
RESTRICT
);
}
else
if
(
readIf
(
"IGNORE"
))
{
}
else
if
(
readIf
(
"IGNORE"
))
{
command
.
setDropAction
(
Constraint
Referential
.
SET_DEFAULT
);
command
.
setDropAction
(
Constraint
ActionType
.
SET_DEFAULT
);
}
}
return
command
;
return
command
;
}
else
if
(
readIf
(
"INDEX"
))
{
}
else
if
(
readIf
(
"INDEX"
))
{
...
@@ -1654,7 +1654,7 @@ public class Parser {
...
@@ -1654,7 +1654,7 @@ public class Parser {
command
.
setViewName
(
viewName
);
command
.
setViewName
(
viewName
);
ifExists
=
readIfExists
(
ifExists
);
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
Integer
dropAction
=
parseCascadeOrRestrict
();
ConstraintActionType
dropAction
=
parseCascadeOrRestrict
();
if
(
dropAction
!=
null
)
{
if
(
dropAction
!=
null
)
{
command
.
setDropAction
(
dropAction
);
command
.
setDropAction
(
dropAction
);
}
}
...
@@ -1964,21 +1964,21 @@ public class Parser {
...
@@ -1964,21 +1964,21 @@ public class Parser {
if
(
readIf
(
"UNION"
))
{
if
(
readIf
(
"UNION"
))
{
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
if
(
readIf
(
"ALL"
))
{
if
(
readIf
(
"ALL"
))
{
union
.
setUnionType
(
SelectUnion
.
UNION_ALL
);
union
.
setUnionType
(
SelectUnion
.
U
nionType
.
U
NION_ALL
);
}
else
{
}
else
{
readIf
(
"DISTINCT"
);
readIf
(
"DISTINCT"
);
union
.
setUnionType
(
SelectUnion
.
UNION
);
union
.
setUnionType
(
SelectUnion
.
U
nionType
.
U
NION
);
}
}
union
.
setRight
(
parseSelectSub
());
union
.
setRight
(
parseSelectSub
());
command
=
union
;
command
=
union
;
}
else
if
(
readIf
(
"MINUS"
)
||
readIf
(
"EXCEPT"
))
{
}
else
if
(
readIf
(
"MINUS"
)
||
readIf
(
"EXCEPT"
))
{
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
union
.
setUnionType
(
SelectUnion
.
EXCEPT
);
union
.
setUnionType
(
SelectUnion
.
UnionType
.
EXCEPT
);
union
.
setRight
(
parseSelectSub
());
union
.
setRight
(
parseSelectSub
());
command
=
union
;
command
=
union
;
}
else
if
(
readIf
(
"INTERSECT"
))
{
}
else
if
(
readIf
(
"INTERSECT"
))
{
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
union
.
setUnionType
(
SelectUnion
.
INTERSECT
);
union
.
setUnionType
(
SelectUnion
.
UnionType
.
INTERSECT
);
union
.
setRight
(
parseSelectSub
());
union
.
setRight
(
parseSelectSub
());
command
=
union
;
command
=
union
;
}
else
{
}
else
{
...
@@ -6382,28 +6382,28 @@ public class Parser {
...
@@ -6382,28 +6382,28 @@ public class Parser {
return
command
;
return
command
;
}
}
private
int
parseAction
()
{
private
ConstraintActionType
parseAction
()
{
Integer
result
=
parseCascadeOrRestrict
();
ConstraintActionType
result
=
parseCascadeOrRestrict
();
if
(
result
!=
null
)
{
if
(
result
!=
null
)
{
return
result
;
return
result
;
}
}
if
(
readIf
(
"NO"
))
{
if
(
readIf
(
"NO"
))
{
read
(
"ACTION"
);
read
(
"ACTION"
);
return
Constraint
Referential
.
RESTRICT
;
return
Constraint
ActionType
.
RESTRICT
;
}
}
read
(
"SET"
);
read
(
"SET"
);
if
(
readIf
(
"NULL"
))
{
if
(
readIf
(
"NULL"
))
{
return
Constraint
Referential
.
SET_NULL
;
return
Constraint
ActionType
.
SET_NULL
;
}
}
read
(
"DEFAULT"
);
read
(
"DEFAULT"
);
return
Constraint
Referential
.
SET_DEFAULT
;
return
Constraint
ActionType
.
SET_DEFAULT
;
}
}
private
Integer
parseCascadeOrRestrict
()
{
private
ConstraintActionType
parseCascadeOrRestrict
()
{
if
(
readIf
(
"CASCADE"
))
{
if
(
readIf
(
"CASCADE"
))
{
return
Constraint
Referential
.
CASCADE
;
return
Constraint
ActionType
.
CASCADE
;
}
else
if
(
readIf
(
"RESTRICT"
))
{
}
else
if
(
readIf
(
"RESTRICT"
))
{
return
Constraint
Referential
.
RESTRICT
;
return
Constraint
ActionType
.
RESTRICT
;
}
else
{
}
else
{
return
null
;
return
null
;
}
}
...
...
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
426737dd
...
@@ -10,6 +10,7 @@ import java.util.HashSet;
...
@@ -10,6 +10,7 @@ import java.util.HashSet;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintActionType
;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintUnique
;
import
org.h2.constraint.ConstraintUnique
;
...
@@ -38,8 +39,8 @@ public class AlterTableAddConstraint extends SchemaCommand {
...
@@ -38,8 +39,8 @@ public class AlterTableAddConstraint extends SchemaCommand {
private
String
constraintName
;
private
String
constraintName
;
private
String
tableName
;
private
String
tableName
;
private
IndexColumn
[]
indexColumns
;
private
IndexColumn
[]
indexColumns
;
private
int
deleteAction
;
private
ConstraintActionType
deleteAction
;
private
int
updateAction
;
private
ConstraintActionType
updateAction
;
private
Schema
refSchema
;
private
Schema
refSchema
;
private
String
refTableName
;
private
String
refTableName
;
private
IndexColumn
[]
refIndexColumns
;
private
IndexColumn
[]
refIndexColumns
;
...
@@ -298,11 +299,11 @@ public class AlterTableAddConstraint extends SchemaCommand {
...
@@ -298,11 +299,11 @@ public class AlterTableAddConstraint extends SchemaCommand {
}
}
}
}
public
void
setDeleteAction
(
int
action
)
{
public
void
setDeleteAction
(
ConstraintActionType
action
)
{
this
.
deleteAction
=
action
;
this
.
deleteAction
=
action
;
}
}
public
void
setUpdateAction
(
int
action
)
{
public
void
setUpdateAction
(
ConstraintActionType
action
)
{
this
.
updateAction
=
action
;
this
.
updateAction
=
action
;
}
}
...
...
h2/src/main/org/h2/command/ddl/DropTable.java
浏览文件 @
426737dd
...
@@ -7,11 +7,10 @@ package org.h2.command.ddl;
...
@@ -7,11 +7,10 @@ package org.h2.command.ddl;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
Referential
;
import
org.h2.constraint.Constraint
ActionType
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Right
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -31,13 +30,13 @@ public class DropTable extends SchemaCommand {
...
@@ -31,13 +30,13 @@ public class DropTable extends SchemaCommand {
private
String
tableName
;
private
String
tableName
;
private
Table
table
;
private
Table
table
;
private
DropTable
next
;
private
DropTable
next
;
private
int
dropAction
;
private
ConstraintActionType
dropAction
;
public
DropTable
(
Session
session
,
Schema
schema
)
{
public
DropTable
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
super
(
session
,
schema
);
dropAction
=
session
.
getDatabase
().
getSettings
().
dropRestrict
?
dropAction
=
session
.
getDatabase
().
getSettings
().
dropRestrict
?
Constraint
Referential
.
RESTRICT
:
Constraint
ActionType
.
RESTRICT
:
ConstraintReferential
.
CASCADE
;
ConstraintActionType
.
CASCADE
;
}
}
/**
/**
...
@@ -75,7 +74,7 @@ public class DropTable extends SchemaCommand {
...
@@ -75,7 +74,7 @@ public class DropTable extends SchemaCommand {
if
(!
table
.
canDrop
())
{
if
(!
table
.
canDrop
())
{
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_TABLE_1
,
tableName
);
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_TABLE_1
,
tableName
);
}
}
if
(
dropAction
==
Constraint
Referential
.
RESTRICT
)
{
if
(
dropAction
==
Constraint
ActionType
.
RESTRICT
)
{
StatementBuilder
buff
=
new
StatementBuilder
();
StatementBuilder
buff
=
new
StatementBuilder
();
CopyOnWriteArrayList
<
TableView
>
dependentViews
=
table
.
getDependentViews
();
CopyOnWriteArrayList
<
TableView
>
dependentViews
=
table
.
getDependentViews
();
if
(
dependentViews
!=
null
&&
dependentViews
.
size
()
>
0
)
{
if
(
dependentViews
!=
null
&&
dependentViews
.
size
()
>
0
)
{
...
@@ -131,7 +130,7 @@ public class DropTable extends SchemaCommand {
...
@@ -131,7 +130,7 @@ public class DropTable extends SchemaCommand {
return
0
;
return
0
;
}
}
public
void
setDropAction
(
int
dropAction
)
{
public
void
setDropAction
(
ConstraintActionType
dropAction
)
{
this
.
dropAction
=
dropAction
;
this
.
dropAction
=
dropAction
;
if
(
next
!=
null
)
{
if
(
next
!=
null
)
{
next
.
setDropAction
(
dropAction
);
next
.
setDropAction
(
dropAction
);
...
...
h2/src/main/org/h2/command/ddl/DropView.java
浏览文件 @
426737dd
...
@@ -8,7 +8,7 @@ package org.h2.command.ddl;
...
@@ -8,7 +8,7 @@ package org.h2.command.ddl;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.constraint.Constraint
Referential
;
import
org.h2.constraint.Constraint
ActionType
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Right
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -26,20 +26,20 @@ public class DropView extends SchemaCommand {
...
@@ -26,20 +26,20 @@ public class DropView extends SchemaCommand {
private
String
viewName
;
private
String
viewName
;
private
boolean
ifExists
;
private
boolean
ifExists
;
private
int
dropAction
;
private
ConstraintActionType
dropAction
;
public
DropView
(
Session
session
,
Schema
schema
)
{
public
DropView
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
super
(
session
,
schema
);
dropAction
=
session
.
getDatabase
().
getSettings
().
dropRestrict
?
dropAction
=
session
.
getDatabase
().
getSettings
().
dropRestrict
?
Constraint
Referential
.
RESTRICT
:
Constraint
ActionType
.
RESTRICT
:
Constraint
Referential
.
CASCADE
;
Constraint
ActionType
.
CASCADE
;
}
}
public
void
setIfExists
(
boolean
b
)
{
public
void
setIfExists
(
boolean
b
)
{
ifExists
=
b
;
ifExists
=
b
;
}
}
public
void
setDropAction
(
int
dropAction
)
{
public
void
setDropAction
(
ConstraintActionType
dropAction
)
{
this
.
dropAction
=
dropAction
;
this
.
dropAction
=
dropAction
;
}
}
...
@@ -61,7 +61,7 @@ public class DropView extends SchemaCommand {
...
@@ -61,7 +61,7 @@ public class DropView extends SchemaCommand {
}
}
session
.
getUser
().
checkRight
(
view
,
Right
.
ALL
);
session
.
getUser
().
checkRight
(
view
,
Right
.
ALL
);
if
(
dropAction
==
Constraint
Referential
.
RESTRICT
)
{
if
(
dropAction
==
Constraint
ActionType
.
RESTRICT
)
{
for
(
DbObject
child
:
view
.
getChildren
())
{
for
(
DbObject
child
:
view
.
getChildren
())
{
if
(
child
instanceof
TableView
)
{
if
(
child
instanceof
TableView
)
{
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_2
,
viewName
,
child
.
getName
());
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_2
,
viewName
,
child
.
getName
());
...
...
h2/src/main/org/h2/command/dml/SelectUnion.java
浏览文件 @
426737dd
...
@@ -38,27 +38,29 @@ import org.h2.value.ValueNull;
...
@@ -38,27 +38,29 @@ import org.h2.value.ValueNull;
*/
*/
public
class
SelectUnion
extends
Query
{
public
class
SelectUnion
extends
Query
{
/**
public
enum
UnionType
{
* The type of a UNION statement.
/**
*/
* The type of a UNION statement.
public
static
final
int
UNION
=
0
;
*/
UNION
,
/**
/**
* The type of a UNION ALL statement.
* The type of a UNION ALL statement.
*/
*/
public
static
final
int
UNION_ALL
=
1
;
UNION_ALL
,
/**
/**
* The type of an EXCEPT statement.
* The type of an EXCEPT statement.
*/
*/
public
static
final
int
EXCEPT
=
2
;
EXCEPT
,
/**
/**
* The type of an INTERSECT statement.
* The type of an INTERSECT statement.
*/
*/
public
static
final
int
INTERSECT
=
3
;
INTERSECT
}
private
int
unionType
;
private
UnionType
unionType
;
/**
/**
* The left hand side of the union (the first subquery).
* The left hand side of the union (the first subquery).
...
@@ -93,11 +95,11 @@ public class SelectUnion extends Query {
...
@@ -93,11 +95,11 @@ public class SelectUnion extends Query {
right
.
prepareJoinBatch
();
right
.
prepareJoinBatch
();
}
}
public
void
setUnionType
(
int
type
)
{
public
void
setUnionType
(
UnionType
type
)
{
this
.
unionType
=
type
;
this
.
unionType
=
type
;
}
}
public
int
getUnionType
()
{
public
UnionType
getUnionType
()
{
return
unionType
;
return
unionType
;
}
}
...
@@ -178,7 +180,7 @@ public class SelectUnion extends Query {
...
@@ -178,7 +180,7 @@ public class SelectUnion extends Query {
limitExpr
=
ValueExpression
.
get
(
ValueInt
.
get
(
l
));
limitExpr
=
ValueExpression
.
get
(
ValueInt
.
get
(
l
));
}
}
if
(
session
.
getDatabase
().
getSettings
().
optimizeInsertFromSelect
)
{
if
(
session
.
getDatabase
().
getSettings
().
optimizeInsertFromSelect
)
{
if
(
unionType
==
UNION_ALL
&&
target
!=
null
)
{
if
(
unionType
==
U
nionType
.
U
NION_ALL
&&
target
!=
null
)
{
if
(
sort
==
null
&&
!
distinct
&&
maxRows
==
0
&&
if
(
sort
==
null
&&
!
distinct
&&
maxRows
==
0
&&
offsetExpr
==
null
&&
limitExpr
==
null
)
{
offsetExpr
==
null
&&
limitExpr
==
null
)
{
left
.
query
(
0
,
target
);
left
.
query
(
0
,
target
);
...
@@ -188,7 +190,7 @@ public class SelectUnion extends Query {
...
@@ -188,7 +190,7 @@ public class SelectUnion extends Query {
}
}
}
}
int
columnCount
=
left
.
getColumnCount
();
int
columnCount
=
left
.
getColumnCount
();
if
(
session
.
isLazyQueryExecution
()
&&
unionType
==
UNION_ALL
&&
!
distinct
&&
if
(
session
.
isLazyQueryExecution
()
&&
unionType
==
U
nionType
.
U
NION_ALL
&&
!
distinct
&&
sort
==
null
&&
!
randomAccessResult
&&
!
isForUpdate
&&
sort
==
null
&&
!
randomAccessResult
&&
!
isForUpdate
&&
offsetExpr
==
null
&&
isReadOnly
())
{
offsetExpr
==
null
&&
isReadOnly
())
{
int
limit
=
-
1
;
int
limit
=
-
1
;
...
...
h2/src/main/org/h2/constraint/ConstraintActionType.java
0 → 100644
浏览文件 @
426737dd
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
constraint
;
public
enum
ConstraintActionType
{
/**
* The action is to restrict the operation.
*/
RESTRICT
,
/**
* The action is to cascade the operation.
*/
CASCADE
,
/**
* The action is to set the value to the default value.
*/
SET_DEFAULT
,
/**
* The action is to set the value to NULL.
*/
SET_NULL
}
\ No newline at end of file
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
426737dd
...
@@ -33,30 +33,10 @@ import org.h2.value.ValueNull;
...
@@ -33,30 +33,10 @@ import org.h2.value.ValueNull;
*/
*/
public
class
ConstraintReferential
extends
Constraint
{
public
class
ConstraintReferential
extends
Constraint
{
/**
* The action is to restrict the operation.
*/
public
static
final
int
RESTRICT
=
0
;
/**
* The action is to cascade the operation.
*/
public
static
final
int
CASCADE
=
1
;
/**
* The action is to set the value to the default value.
*/
public
static
final
int
SET_DEFAULT
=
2
;
/**
* The action is to set the value to NULL.
*/
public
static
final
int
SET_NULL
=
3
;
private
IndexColumn
[]
columns
;
private
IndexColumn
[]
columns
;
private
IndexColumn
[]
refColumns
;
private
IndexColumn
[]
refColumns
;
private
int
deleteAction
;
private
ConstraintActionType
deleteAction
;
private
int
updateAction
;
private
ConstraintActionType
updateAction
;
private
Table
refTable
;
private
Table
refTable
;
private
Index
index
;
private
Index
index
;
private
Index
refIndex
;
private
Index
refIndex
;
...
@@ -74,7 +54,7 @@ public class ConstraintReferential extends Constraint {
...
@@ -74,7 +54,7 @@ public class ConstraintReferential extends Constraint {
return
Constraint
.
REFERENTIAL
;
return
Constraint
.
REFERENTIAL
;
}
}
private
static
void
appendAction
(
StatementBuilder
buff
,
int
action
)
{
private
static
void
appendAction
(
StatementBuilder
buff
,
ConstraintActionType
action
)
{
switch
(
action
)
{
switch
(
action
)
{
case
CASCADE:
case
CASCADE:
buff
.
append
(
"CASCADE"
);
buff
.
append
(
"CASCADE"
);
...
@@ -154,11 +134,11 @@ public class ConstraintReferential extends Constraint {
...
@@ -154,11 +134,11 @@ public class ConstraintReferential extends Constraint {
if
(
internalIndex
&&
refIndexOwner
&&
forTable
==
this
.
table
)
{
if
(
internalIndex
&&
refIndexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
).
append
(
refIndex
.
getSQL
());
buff
.
append
(
" INDEX "
).
append
(
refIndex
.
getSQL
());
}
}
if
(
deleteAction
!=
RESTRICT
)
{
if
(
deleteAction
!=
ConstraintActionType
.
RESTRICT
)
{
buff
.
append
(
" ON DELETE "
);
buff
.
append
(
" ON DELETE "
);
appendAction
(
buff
,
deleteAction
);
appendAction
(
buff
,
deleteAction
);
}
}
if
(
updateAction
!=
RESTRICT
)
{
if
(
updateAction
!=
ConstraintActionType
.
RESTRICT
)
{
buff
.
append
(
" ON UPDATE "
);
buff
.
append
(
" ON UPDATE "
);
appendAction
(
buff
,
updateAction
);
appendAction
(
buff
,
updateAction
);
}
}
...
@@ -437,21 +417,21 @@ public class ConstraintReferential extends Constraint {
...
@@ -437,21 +417,21 @@ public class ConstraintReferential extends Constraint {
}
}
if
(
newRow
==
null
)
{
if
(
newRow
==
null
)
{
// this is a delete
// this is a delete
if
(
deleteAction
==
RESTRICT
)
{
if
(
deleteAction
==
ConstraintActionType
.
RESTRICT
)
{
checkRow
(
session
,
oldRow
);
checkRow
(
session
,
oldRow
);
}
else
{
}
else
{
int
i
=
deleteAction
==
CASCADE
?
0
:
columns
.
length
;
int
i
=
deleteAction
==
C
onstraintActionType
.
C
ASCADE
?
0
:
columns
.
length
;
Prepared
deleteCommand
=
getDelete
(
session
);
Prepared
deleteCommand
=
getDelete
(
session
);
setWhere
(
deleteCommand
,
i
,
oldRow
);
setWhere
(
deleteCommand
,
i
,
oldRow
);
updateWithSkipCheck
(
deleteCommand
);
updateWithSkipCheck
(
deleteCommand
);
}
}
}
else
{
}
else
{
// this is an update
// this is an update
if
(
updateAction
==
RESTRICT
)
{
if
(
updateAction
==
ConstraintActionType
.
RESTRICT
)
{
checkRow
(
session
,
oldRow
);
checkRow
(
session
,
oldRow
);
}
else
{
}
else
{
Prepared
updateCommand
=
getUpdate
(
session
);
Prepared
updateCommand
=
getUpdate
(
session
);
if
(
updateAction
==
CASCADE
)
{
if
(
updateAction
==
C
onstraintActionType
.
C
ASCADE
)
{
ArrayList
<
Parameter
>
params
=
updateCommand
.
getParameters
();
ArrayList
<
Parameter
>
params
=
updateCommand
.
getParameters
();
for
(
int
i
=
0
,
len
=
columns
.
length
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
,
len
=
columns
.
length
;
i
<
len
;
i
++)
{
Parameter
param
=
params
.
get
(
i
);
Parameter
param
=
params
.
get
(
i
);
...
@@ -488,7 +468,7 @@ public class ConstraintReferential extends Constraint {
...
@@ -488,7 +468,7 @@ public class ConstraintReferential extends Constraint {
}
}
}
}
public
int
getDeleteAction
()
{
public
ConstraintActionType
getDeleteAction
()
{
return
deleteAction
;
return
deleteAction
;
}
}
...
@@ -497,11 +477,11 @@ public class ConstraintReferential extends Constraint {
...
@@ -497,11 +477,11 @@ public class ConstraintReferential extends Constraint {
*
*
* @param action the action
* @param action the action
*/
*/
public
void
setDeleteAction
(
int
action
)
{
public
void
setDeleteAction
(
ConstraintActionType
action
)
{
if
(
action
==
deleteAction
&&
deleteSQL
==
null
)
{
if
(
action
==
deleteAction
&&
deleteSQL
==
null
)
{
return
;
return
;
}
}
if
(
deleteAction
!=
RESTRICT
)
{
if
(
deleteAction
!=
ConstraintActionType
.
RESTRICT
)
{
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
"ON DELETE"
);
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
"ON DELETE"
);
}
}
this
.
deleteAction
=
action
;
this
.
deleteAction
=
action
;
...
@@ -509,11 +489,11 @@ public class ConstraintReferential extends Constraint {
...
@@ -509,11 +489,11 @@ public class ConstraintReferential extends Constraint {
}
}
private
void
buildDeleteSQL
()
{
private
void
buildDeleteSQL
()
{
if
(
deleteAction
==
RESTRICT
)
{
if
(
deleteAction
==
ConstraintActionType
.
RESTRICT
)
{
return
;
return
;
}
}
StatementBuilder
buff
=
new
StatementBuilder
();
StatementBuilder
buff
=
new
StatementBuilder
();
if
(
deleteAction
==
CASCADE
)
{
if
(
deleteAction
==
C
onstraintActionType
.
C
ASCADE
)
{
buff
.
append
(
"DELETE FROM "
).
append
(
table
.
getSQL
());
buff
.
append
(
"DELETE FROM "
).
append
(
table
.
getSQL
());
}
else
{
}
else
{
appendUpdate
(
buff
);
appendUpdate
(
buff
);
...
@@ -530,7 +510,7 @@ public class ConstraintReferential extends Constraint {
...
@@ -530,7 +510,7 @@ public class ConstraintReferential extends Constraint {
return
prepare
(
session
,
deleteSQL
,
deleteAction
);
return
prepare
(
session
,
deleteSQL
,
deleteAction
);
}
}
public
int
getUpdateAction
()
{
public
ConstraintActionType
getUpdateAction
()
{
return
updateAction
;
return
updateAction
;
}
}
...
@@ -539,11 +519,11 @@ public class ConstraintReferential extends Constraint {
...
@@ -539,11 +519,11 @@ public class ConstraintReferential extends Constraint {
*
*
* @param action the action
* @param action the action
*/
*/
public
void
setUpdateAction
(
int
action
)
{
public
void
setUpdateAction
(
ConstraintActionType
action
)
{
if
(
action
==
updateAction
&&
updateSQL
==
null
)
{
if
(
action
==
updateAction
&&
updateSQL
==
null
)
{
return
;
return
;
}
}
if
(
updateAction
!=
RESTRICT
)
{
if
(
updateAction
!=
ConstraintActionType
.
RESTRICT
)
{
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
"ON UPDATE"
);
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
"ON UPDATE"
);
}
}
this
.
updateAction
=
action
;
this
.
updateAction
=
action
;
...
@@ -551,7 +531,7 @@ public class ConstraintReferential extends Constraint {
...
@@ -551,7 +531,7 @@ public class ConstraintReferential extends Constraint {
}
}
private
void
buildUpdateSQL
()
{
private
void
buildUpdateSQL
()
{
if
(
updateAction
==
RESTRICT
)
{
if
(
updateAction
==
ConstraintActionType
.
RESTRICT
)
{
return
;
return
;
}
}
StatementBuilder
buff
=
new
StatementBuilder
();
StatementBuilder
buff
=
new
StatementBuilder
();
...
@@ -566,15 +546,15 @@ public class ConstraintReferential extends Constraint {
...
@@ -566,15 +546,15 @@ public class ConstraintReferential extends Constraint {
buildDeleteSQL
();
buildDeleteSQL
();
}
}
private
Prepared
prepare
(
Session
session
,
String
sql
,
int
action
)
{
private
Prepared
prepare
(
Session
session
,
String
sql
,
ConstraintActionType
action
)
{
Prepared
command
=
session
.
prepare
(
sql
);
Prepared
command
=
session
.
prepare
(
sql
);
if
(
action
!=
CASCADE
)
{
if
(
action
!=
C
onstraintActionType
.
C
ASCADE
)
{
ArrayList
<
Parameter
>
params
=
command
.
getParameters
();
ArrayList
<
Parameter
>
params
=
command
.
getParameters
();
for
(
int
i
=
0
,
len
=
columns
.
length
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
,
len
=
columns
.
length
;
i
<
len
;
i
++)
{
Column
column
=
columns
[
i
].
column
;
Column
column
=
columns
[
i
].
column
;
Parameter
param
=
params
.
get
(
i
);
Parameter
param
=
params
.
get
(
i
);
Value
value
;
Value
value
;
if
(
action
==
SET_NULL
)
{
if
(
action
==
ConstraintActionType
.
SET_NULL
)
{
value
=
ValueNull
.
INSTANCE
;
value
=
ValueNull
.
INSTANCE
;
}
else
{
}
else
{
Expression
expr
=
column
.
getDefaultExpression
();
Expression
expr
=
column
.
getDefaultExpression
();
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
426737dd
...
@@ -19,6 +19,7 @@ import java.util.HashMap;
...
@@ -19,6 +19,7 @@ import java.util.HashMap;
import
java.util.Locale
;
import
java.util.Locale
;
import
org.h2.command.Command
;
import
org.h2.command.Command
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintActionType
;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintUnique
;
import
org.h2.constraint.ConstraintUnique
;
...
@@ -1913,15 +1914,15 @@ public class MetaTable extends Table {
...
@@ -1913,15 +1914,15 @@ public class MetaTable extends Table {
return
rows
;
return
rows
;
}
}
private
static
int
getRefAction
(
int
action
)
{
private
static
int
getRefAction
(
ConstraintActionType
action
)
{
switch
(
action
)
{
switch
(
action
)
{
case
C
onstraintReferential
.
C
ASCADE
:
case
CASCADE:
return
DatabaseMetaData
.
importedKeyCascade
;
return
DatabaseMetaData
.
importedKeyCascade
;
case
ConstraintReferential
.
RESTRICT
:
case
RESTRICT:
return
DatabaseMetaData
.
importedKeyRestrict
;
return
DatabaseMetaData
.
importedKeyRestrict
;
case
ConstraintReferential
.
SET_DEFAULT
:
case
SET_DEFAULT:
return
DatabaseMetaData
.
importedKeySetDefault
;
return
DatabaseMetaData
.
importedKeySetDefault
;
case
ConstraintReferential
.
SET_NULL
:
case
SET_NULL:
return
DatabaseMetaData
.
importedKeySetNull
;
return
DatabaseMetaData
.
importedKeySetNull
;
default
:
default
:
throw
DbException
.
throwInternalError
(
"action="
+
action
);
throw
DbException
.
throwInternalError
(
"action="
+
action
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论