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;
import
org.h2.command.dml.SetTypes
;
import
org.h2.command.dml.TransactionCommand
;
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.Database
;
import
org.h2.engine.DbObject
;
...
...
@@ -1599,12 +1599,12 @@ public class Parser {
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
if
(
readIf
(
"CASCADE"
))
{
command
.
setDropAction
(
Constraint
Referential
.
CASCADE
);
command
.
setDropAction
(
Constraint
ActionType
.
CASCADE
);
readIf
(
"CONSTRAINTS"
);
}
else
if
(
readIf
(
"RESTRICT"
))
{
command
.
setDropAction
(
Constraint
Referential
.
RESTRICT
);
command
.
setDropAction
(
Constraint
ActionType
.
RESTRICT
);
}
else
if
(
readIf
(
"IGNORE"
))
{
command
.
setDropAction
(
Constraint
Referential
.
SET_DEFAULT
);
command
.
setDropAction
(
Constraint
ActionType
.
SET_DEFAULT
);
}
return
command
;
}
else
if
(
readIf
(
"INDEX"
))
{
...
...
@@ -1654,7 +1654,7 @@ public class Parser {
command
.
setViewName
(
viewName
);
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
Integer
dropAction
=
parseCascadeOrRestrict
();
ConstraintActionType
dropAction
=
parseCascadeOrRestrict
();
if
(
dropAction
!=
null
)
{
command
.
setDropAction
(
dropAction
);
}
...
...
@@ -1964,21 +1964,21 @@ public class Parser {
if
(
readIf
(
"UNION"
))
{
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
if
(
readIf
(
"ALL"
))
{
union
.
setUnionType
(
SelectUnion
.
UNION_ALL
);
union
.
setUnionType
(
SelectUnion
.
U
nionType
.
U
NION_ALL
);
}
else
{
readIf
(
"DISTINCT"
);
union
.
setUnionType
(
SelectUnion
.
UNION
);
union
.
setUnionType
(
SelectUnion
.
U
nionType
.
U
NION
);
}
union
.
setRight
(
parseSelectSub
());
command
=
union
;
}
else
if
(
readIf
(
"MINUS"
)
||
readIf
(
"EXCEPT"
))
{
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
union
.
setUnionType
(
SelectUnion
.
EXCEPT
);
union
.
setUnionType
(
SelectUnion
.
UnionType
.
EXCEPT
);
union
.
setRight
(
parseSelectSub
());
command
=
union
;
}
else
if
(
readIf
(
"INTERSECT"
))
{
SelectUnion
union
=
new
SelectUnion
(
session
,
command
);
union
.
setUnionType
(
SelectUnion
.
INTERSECT
);
union
.
setUnionType
(
SelectUnion
.
UnionType
.
INTERSECT
);
union
.
setRight
(
parseSelectSub
());
command
=
union
;
}
else
{
...
...
@@ -6382,28 +6382,28 @@ public class Parser {
return
command
;
}
private
int
parseAction
()
{
Integer
result
=
parseCascadeOrRestrict
();
private
ConstraintActionType
parseAction
()
{
ConstraintActionType
result
=
parseCascadeOrRestrict
();
if
(
result
!=
null
)
{
return
result
;
}
if
(
readIf
(
"NO"
))
{
read
(
"ACTION"
);
return
Constraint
Referential
.
RESTRICT
;
return
Constraint
ActionType
.
RESTRICT
;
}
read
(
"SET"
);
if
(
readIf
(
"NULL"
))
{
return
Constraint
Referential
.
SET_NULL
;
return
Constraint
ActionType
.
SET_NULL
;
}
read
(
"DEFAULT"
);
return
Constraint
Referential
.
SET_DEFAULT
;
return
Constraint
ActionType
.
SET_DEFAULT
;
}
private
Integer
parseCascadeOrRestrict
()
{
private
ConstraintActionType
parseCascadeOrRestrict
()
{
if
(
readIf
(
"CASCADE"
))
{
return
Constraint
Referential
.
CASCADE
;
return
Constraint
ActionType
.
CASCADE
;
}
else
if
(
readIf
(
"RESTRICT"
))
{
return
Constraint
Referential
.
RESTRICT
;
return
Constraint
ActionType
.
RESTRICT
;
}
else
{
return
null
;
}
...
...
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
426737dd
...
...
@@ -10,6 +10,7 @@ import java.util.HashSet;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintActionType
;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintUnique
;
...
...
@@ -38,8 +39,8 @@ public class AlterTableAddConstraint extends SchemaCommand {
private
String
constraintName
;
private
String
tableName
;
private
IndexColumn
[]
indexColumns
;
private
int
deleteAction
;
private
int
updateAction
;
private
ConstraintActionType
deleteAction
;
private
ConstraintActionType
updateAction
;
private
Schema
refSchema
;
private
String
refTableName
;
private
IndexColumn
[]
refIndexColumns
;
...
...
@@ -298,11 +299,11 @@ public class AlterTableAddConstraint extends SchemaCommand {
}
}
public
void
setDeleteAction
(
int
action
)
{
public
void
setDeleteAction
(
ConstraintActionType
action
)
{
this
.
deleteAction
=
action
;
}
public
void
setUpdateAction
(
int
action
)
{
public
void
setUpdateAction
(
ConstraintActionType
action
)
{
this
.
updateAction
=
action
;
}
...
...
h2/src/main/org/h2/command/ddl/DropTable.java
浏览文件 @
426737dd
...
...
@@ -7,11 +7,10 @@ package org.h2.command.ddl;
import
java.util.List
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
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.Right
;
import
org.h2.engine.Session
;
...
...
@@ -31,13 +30,13 @@ public class DropTable extends SchemaCommand {
private
String
tableName
;
private
Table
table
;
private
DropTable
next
;
private
int
dropAction
;
private
ConstraintActionType
dropAction
;
public
DropTable
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
dropAction
=
session
.
getDatabase
().
getSettings
().
dropRestrict
?
Constraint
Referential
.
RESTRICT
:
ConstraintReferential
.
CASCADE
;
Constraint
ActionType
.
RESTRICT
:
ConstraintActionType
.
CASCADE
;
}
/**
...
...
@@ -75,7 +74,7 @@ public class DropTable extends SchemaCommand {
if
(!
table
.
canDrop
())
{
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_TABLE_1
,
tableName
);
}
if
(
dropAction
==
Constraint
Referential
.
RESTRICT
)
{
if
(
dropAction
==
Constraint
ActionType
.
RESTRICT
)
{
StatementBuilder
buff
=
new
StatementBuilder
();
CopyOnWriteArrayList
<
TableView
>
dependentViews
=
table
.
getDependentViews
();
if
(
dependentViews
!=
null
&&
dependentViews
.
size
()
>
0
)
{
...
...
@@ -131,7 +130,7 @@ public class DropTable extends SchemaCommand {
return
0
;
}
public
void
setDropAction
(
int
dropAction
)
{
public
void
setDropAction
(
ConstraintActionType
dropAction
)
{
this
.
dropAction
=
dropAction
;
if
(
next
!=
null
)
{
next
.
setDropAction
(
dropAction
);
...
...
h2/src/main/org/h2/command/ddl/DropView.java
浏览文件 @
426737dd
...
...
@@ -8,7 +8,7 @@ package org.h2.command.ddl;
import
java.util.ArrayList
;
import
org.h2.api.ErrorCode
;
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.Right
;
import
org.h2.engine.Session
;
...
...
@@ -26,20 +26,20 @@ public class DropView extends SchemaCommand {
private
String
viewName
;
private
boolean
ifExists
;
private
int
dropAction
;
private
ConstraintActionType
dropAction
;
public
DropView
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
dropAction
=
session
.
getDatabase
().
getSettings
().
dropRestrict
?
Constraint
Referential
.
RESTRICT
:
Constraint
Referential
.
CASCADE
;
Constraint
ActionType
.
RESTRICT
:
Constraint
ActionType
.
CASCADE
;
}
public
void
setIfExists
(
boolean
b
)
{
ifExists
=
b
;
}
public
void
setDropAction
(
int
dropAction
)
{
public
void
setDropAction
(
ConstraintActionType
dropAction
)
{
this
.
dropAction
=
dropAction
;
}
...
...
@@ -61,7 +61,7 @@ public class DropView extends SchemaCommand {
}
session
.
getUser
().
checkRight
(
view
,
Right
.
ALL
);
if
(
dropAction
==
Constraint
Referential
.
RESTRICT
)
{
if
(
dropAction
==
Constraint
ActionType
.
RESTRICT
)
{
for
(
DbObject
child
:
view
.
getChildren
())
{
if
(
child
instanceof
TableView
)
{
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;
*/
public
class
SelectUnion
extends
Query
{
/**
* The type of a UNION statement.
*/
public
static
final
int
UNION
=
0
;
public
enum
UnionType
{
/**
* The type of a UNION statement.
*/
UNION
,
/**
* The type of a UNION ALL statement.
*/
public
static
final
int
UNION_ALL
=
1
;
/**
* The type of a UNION ALL statement.
*/
UNION_ALL
,
/**
* The type of an EXCEPT statement.
*/
public
static
final
int
EXCEPT
=
2
;
/**
* The type of an EXCEPT statement.
*/
EXCEPT
,
/**
* The type of an INTERSECT statement.
*/
public
static
final
int
INTERSECT
=
3
;
/**
* The type of an INTERSECT statement.
*/
INTERSECT
}
private
int
unionType
;
private
UnionType
unionType
;
/**
* The left hand side of the union (the first subquery).
...
...
@@ -93,11 +95,11 @@ public class SelectUnion extends Query {
right
.
prepareJoinBatch
();
}
public
void
setUnionType
(
int
type
)
{
public
void
setUnionType
(
UnionType
type
)
{
this
.
unionType
=
type
;
}
public
int
getUnionType
()
{
public
UnionType
getUnionType
()
{
return
unionType
;
}
...
...
@@ -178,7 +180,7 @@ public class SelectUnion extends Query {
limitExpr
=
ValueExpression
.
get
(
ValueInt
.
get
(
l
));
}
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
&&
offsetExpr
==
null
&&
limitExpr
==
null
)
{
left
.
query
(
0
,
target
);
...
...
@@ -188,7 +190,7 @@ public class SelectUnion extends Query {
}
}
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
&&
offsetExpr
==
null
&&
isReadOnly
())
{
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;
*/
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
[]
refColumns
;
private
int
deleteAction
;
private
int
updateAction
;
private
ConstraintActionType
deleteAction
;
private
ConstraintActionType
updateAction
;
private
Table
refTable
;
private
Index
index
;
private
Index
refIndex
;
...
...
@@ -74,7 +54,7 @@ public class ConstraintReferential extends Constraint {
return
Constraint
.
REFERENTIAL
;
}
private
static
void
appendAction
(
StatementBuilder
buff
,
int
action
)
{
private
static
void
appendAction
(
StatementBuilder
buff
,
ConstraintActionType
action
)
{
switch
(
action
)
{
case
CASCADE:
buff
.
append
(
"CASCADE"
);
...
...
@@ -154,11 +134,11 @@ public class ConstraintReferential extends Constraint {
if
(
internalIndex
&&
refIndexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
).
append
(
refIndex
.
getSQL
());
}
if
(
deleteAction
!=
RESTRICT
)
{
if
(
deleteAction
!=
ConstraintActionType
.
RESTRICT
)
{
buff
.
append
(
" ON DELETE "
);
appendAction
(
buff
,
deleteAction
);
}
if
(
updateAction
!=
RESTRICT
)
{
if
(
updateAction
!=
ConstraintActionType
.
RESTRICT
)
{
buff
.
append
(
" ON UPDATE "
);
appendAction
(
buff
,
updateAction
);
}
...
...
@@ -437,21 +417,21 @@ public class ConstraintReferential extends Constraint {
}
if
(
newRow
==
null
)
{
// this is a delete
if
(
deleteAction
==
RESTRICT
)
{
if
(
deleteAction
==
ConstraintActionType
.
RESTRICT
)
{
checkRow
(
session
,
oldRow
);
}
else
{
int
i
=
deleteAction
==
CASCADE
?
0
:
columns
.
length
;
int
i
=
deleteAction
==
C
onstraintActionType
.
C
ASCADE
?
0
:
columns
.
length
;
Prepared
deleteCommand
=
getDelete
(
session
);
setWhere
(
deleteCommand
,
i
,
oldRow
);
updateWithSkipCheck
(
deleteCommand
);
}
}
else
{
// this is an update
if
(
updateAction
==
RESTRICT
)
{
if
(
updateAction
==
ConstraintActionType
.
RESTRICT
)
{
checkRow
(
session
,
oldRow
);
}
else
{
Prepared
updateCommand
=
getUpdate
(
session
);
if
(
updateAction
==
CASCADE
)
{
if
(
updateAction
==
C
onstraintActionType
.
C
ASCADE
)
{
ArrayList
<
Parameter
>
params
=
updateCommand
.
getParameters
();
for
(
int
i
=
0
,
len
=
columns
.
length
;
i
<
len
;
i
++)
{
Parameter
param
=
params
.
get
(
i
);
...
...
@@ -488,7 +468,7 @@ public class ConstraintReferential extends Constraint {
}
}
public
int
getDeleteAction
()
{
public
ConstraintActionType
getDeleteAction
()
{
return
deleteAction
;
}
...
...
@@ -497,11 +477,11 @@ public class ConstraintReferential extends Constraint {
*
* @param action the action
*/
public
void
setDeleteAction
(
int
action
)
{
public
void
setDeleteAction
(
ConstraintActionType
action
)
{
if
(
action
==
deleteAction
&&
deleteSQL
==
null
)
{
return
;
}
if
(
deleteAction
!=
RESTRICT
)
{
if
(
deleteAction
!=
ConstraintActionType
.
RESTRICT
)
{
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
"ON DELETE"
);
}
this
.
deleteAction
=
action
;
...
...
@@ -509,11 +489,11 @@ public class ConstraintReferential extends Constraint {
}
private
void
buildDeleteSQL
()
{
if
(
deleteAction
==
RESTRICT
)
{
if
(
deleteAction
==
ConstraintActionType
.
RESTRICT
)
{
return
;
}
StatementBuilder
buff
=
new
StatementBuilder
();
if
(
deleteAction
==
CASCADE
)
{
if
(
deleteAction
==
C
onstraintActionType
.
C
ASCADE
)
{
buff
.
append
(
"DELETE FROM "
).
append
(
table
.
getSQL
());
}
else
{
appendUpdate
(
buff
);
...
...
@@ -530,7 +510,7 @@ public class ConstraintReferential extends Constraint {
return
prepare
(
session
,
deleteSQL
,
deleteAction
);
}
public
int
getUpdateAction
()
{
public
ConstraintActionType
getUpdateAction
()
{
return
updateAction
;
}
...
...
@@ -539,11 +519,11 @@ public class ConstraintReferential extends Constraint {
*
* @param action the action
*/
public
void
setUpdateAction
(
int
action
)
{
public
void
setUpdateAction
(
ConstraintActionType
action
)
{
if
(
action
==
updateAction
&&
updateSQL
==
null
)
{
return
;
}
if
(
updateAction
!=
RESTRICT
)
{
if
(
updateAction
!=
ConstraintActionType
.
RESTRICT
)
{
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
"ON UPDATE"
);
}
this
.
updateAction
=
action
;
...
...
@@ -551,7 +531,7 @@ public class ConstraintReferential extends Constraint {
}
private
void
buildUpdateSQL
()
{
if
(
updateAction
==
RESTRICT
)
{
if
(
updateAction
==
ConstraintActionType
.
RESTRICT
)
{
return
;
}
StatementBuilder
buff
=
new
StatementBuilder
();
...
...
@@ -566,15 +546,15 @@ public class ConstraintReferential extends Constraint {
buildDeleteSQL
();
}
private
Prepared
prepare
(
Session
session
,
String
sql
,
int
action
)
{
private
Prepared
prepare
(
Session
session
,
String
sql
,
ConstraintActionType
action
)
{
Prepared
command
=
session
.
prepare
(
sql
);
if
(
action
!=
CASCADE
)
{
if
(
action
!=
C
onstraintActionType
.
C
ASCADE
)
{
ArrayList
<
Parameter
>
params
=
command
.
getParameters
();
for
(
int
i
=
0
,
len
=
columns
.
length
;
i
<
len
;
i
++)
{
Column
column
=
columns
[
i
].
column
;
Parameter
param
=
params
.
get
(
i
);
Value
value
;
if
(
action
==
SET_NULL
)
{
if
(
action
==
ConstraintActionType
.
SET_NULL
)
{
value
=
ValueNull
.
INSTANCE
;
}
else
{
Expression
expr
=
column
.
getDefaultExpression
();
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
426737dd
...
...
@@ -19,6 +19,7 @@ import java.util.HashMap;
import
java.util.Locale
;
import
org.h2.command.Command
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintActionType
;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintUnique
;
...
...
@@ -1913,15 +1914,15 @@ public class MetaTable extends Table {
return
rows
;
}
private
static
int
getRefAction
(
int
action
)
{
private
static
int
getRefAction
(
ConstraintActionType
action
)
{
switch
(
action
)
{
case
C
onstraintReferential
.
C
ASCADE
:
case
CASCADE:
return
DatabaseMetaData
.
importedKeyCascade
;
case
ConstraintReferential
.
RESTRICT
:
case
RESTRICT:
return
DatabaseMetaData
.
importedKeyRestrict
;
case
ConstraintReferential
.
SET_DEFAULT
:
case
SET_DEFAULT:
return
DatabaseMetaData
.
importedKeySetDefault
;
case
ConstraintReferential
.
SET_NULL
:
case
SET_NULL:
return
DatabaseMetaData
.
importedKeySetNull
;
default
:
throw
DbException
.
throwInternalError
(
"action="
+
action
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论