Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
77b6e4b1
Unverified
提交
77b6e4b1
authored
2月 10, 2018
作者:
Noel Grandin
提交者:
GitHub
2月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #862 from h2database/constraint_type_enum
Convert constraint type into enum
上级
bc763b82
3eba25f8
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
40 行增加
和
60 行删除
+40
-60
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+1
-1
DropIndex.java
h2/src/main/org/h2/command/ddl/DropIndex.java
+1
-1
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+2
-3
Constraint.java
h2/src/main/org/h2/constraint/Constraint.java
+20
-38
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+2
-2
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+2
-2
ConstraintUnique.java
h2/src/main/org/h2/constraint/ConstraintUnique.java
+2
-2
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+1
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+8
-9
RegularTable.java
h2/src/main/org/h2/table/RegularTable.java
+1
-1
没有找到文件。
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
77b6e4b1
...
...
@@ -120,7 +120,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
ArrayList
<
Constraint
>
constraints
=
table
.
getConstraints
();
for
(
int
i
=
0
;
constraints
!=
null
&&
i
<
constraints
.
size
();
i
++)
{
Constraint
c
=
constraints
.
get
(
i
);
if
(
Constraint
.
PRIMARY_KEY
.
equals
(
c
.
getConstraintType
()
))
{
if
(
Constraint
.
Type
.
PRIMARY_KEY
==
c
.
getConstraintType
(
))
{
throw
DbException
.
get
(
ErrorCode
.
SECOND_PRIMARY_KEY
);
}
}
...
...
h2/src/main/org/h2/command/ddl/DropIndex.java
浏览文件 @
77b6e4b1
...
...
@@ -57,7 +57,7 @@ public class DropIndex extends SchemaCommand {
Constraint
cons
=
constraints
.
get
(
i
);
if
(
cons
.
usesIndex
(
index
))
{
// can drop primary key index (for compatibility)
if
(
Constraint
.
PRIMARY_KEY
.
equals
(
cons
.
getConstraintType
()
))
{
if
(
Constraint
.
Type
.
PRIMARY_KEY
==
cons
.
getConstraintType
(
))
{
pkConstraint
=
cons
;
}
else
{
throw
DbException
.
get
(
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
77b6e4b1
...
...
@@ -284,8 +284,7 @@ public class ScriptCommand extends ScriptBase {
final
ArrayList
<
Constraint
>
constraints
=
table
.
getConstraints
();
if
(
constraints
!=
null
)
{
for
(
Constraint
constraint
:
constraints
)
{
if
(
Constraint
.
PRIMARY_KEY
.
equals
(
constraint
.
getConstraintType
()))
{
if
(
Constraint
.
Type
.
PRIMARY_KEY
==
constraint
.
getConstraintType
())
{
add
(
constraint
.
getCreateSQLWithoutIndexes
(),
false
);
}
}
...
...
@@ -336,7 +335,7 @@ public class ScriptCommand extends ScriptBase {
if
(
constraint
.
getTable
().
isHidden
())
{
continue
;
}
if
(
!
Constraint
.
PRIMARY_KEY
.
equals
(
constraint
.
getConstraintType
()
))
{
if
(
Constraint
.
Type
.
PRIMARY_KEY
!=
constraint
.
getConstraintType
(
))
{
add
(
constraint
.
getCreateSQLWithoutIndexes
(),
false
);
}
}
...
...
h2/src/main/org/h2/constraint/Constraint.java
浏览文件 @
77b6e4b1
...
...
@@ -24,25 +24,24 @@ import org.h2.table.Table;
public
abstract
class
Constraint
extends
SchemaObjectBase
implements
Comparable
<
Constraint
>
{
/**
* The constraint type name for check constraints.
*/
public
static
final
String
CHECK
=
"CHECK"
;
/**
* The constraint type name for referential constraints.
*/
public
static
final
String
REFERENTIAL
=
"REFERENTIAL"
;
/**
* The constraint type name for unique constraints.
*/
public
static
final
String
UNIQUE
=
"UNIQUE"
;
/**
* The constraint type name for primary key constraints.
*/
public
static
final
String
PRIMARY_KEY
=
"PRIMARY KEY"
;
public
enum
Type
{
/**
* The constraint type for check constraints.
*/
CHECK
,
/**
* The constraint type for primary key constraints.
*/
PRIMARY_KEY
,
/**
* The constraint type for unique constraints.
*/
UNIQUE
,
/**
* The constraint type for referential constraints.
*/
REFERENTIAL
}
/**
* The table for which this constraint is defined.
...
...
@@ -60,7 +59,7 @@ public abstract class Constraint extends SchemaObjectBase implements
*
* @return the name
*/
public
abstract
String
getConstraintType
();
public
abstract
Type
getConstraintType
();
/**
* Check if this row fulfils the constraint.
...
...
@@ -155,29 +154,12 @@ public abstract class Constraint extends SchemaObjectBase implements
return
null
;
}
private
int
getConstraintTypeOrder
()
{
String
constraintType
=
getConstraintType
();
if
(
CHECK
.
equals
(
constraintType
))
{
return
0
;
}
else
if
(
PRIMARY_KEY
.
equals
(
constraintType
))
{
return
1
;
}
else
if
(
UNIQUE
.
equals
(
constraintType
))
{
return
2
;
}
else
if
(
REFERENTIAL
.
equals
(
constraintType
))
{
return
3
;
}
else
{
throw
DbException
.
throwInternalError
(
"type: "
+
constraintType
);
}
}
@Override
public
int
compareTo
(
Constraint
other
)
{
if
(
this
==
other
)
{
return
0
;
}
int
thisType
=
getConstraintTypeOrder
();
int
otherType
=
other
.
getConstraintTypeOrder
();
return
thisType
-
otherType
;
return
Integer
.
compare
(
getConstraintType
().
ordinal
(),
other
.
getConstraintType
().
ordinal
());
}
@Override
...
...
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
77b6e4b1
...
...
@@ -36,8 +36,8 @@ public class ConstraintCheck extends Constraint {
}
@Override
public
String
getConstraintType
()
{
return
Constraint
.
CHECK
;
public
Type
getConstraintType
()
{
return
Constraint
.
Type
.
CHECK
;
}
public
void
setTableFilter
(
TableFilter
filter
)
{
...
...
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
77b6e4b1
...
...
@@ -50,8 +50,8 @@ public class ConstraintReferential extends Constraint {
}
@Override
public
String
getConstraintType
()
{
return
Constraint
.
REFERENTIAL
;
public
Type
getConstraintType
()
{
return
Constraint
.
Type
.
REFERENTIAL
;
}
private
static
void
appendAction
(
StatementBuilder
buff
,
ConstraintActionType
action
)
{
...
...
h2/src/main/org/h2/constraint/ConstraintUnique.java
浏览文件 @
77b6e4b1
...
...
@@ -34,8 +34,8 @@ public class ConstraintUnique extends Constraint {
}
@Override
public
String
getConstraintType
()
{
return
primaryKey
?
Constraint
.
PRIMARY_KEY
:
Constraint
.
UNIQUE
;
public
Type
getConstraintType
()
{
return
primaryKey
?
Constraint
.
Type
.
PRIMARY_KEY
:
Constraint
.
Type
.
UNIQUE
;
}
@Override
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
77b6e4b1
...
...
@@ -467,7 +467,7 @@ public class MVTable extends TableBase {
if
(
constraints
!=
null
)
{
for
(
int
i
=
0
,
size
=
constraints
.
size
();
i
<
size
;
i
++)
{
Constraint
c
=
constraints
.
get
(
i
);
if
(
!(
c
.
getConstraintType
().
equals
(
Constraint
.
REFERENTIAL
))
)
{
if
(
c
.
getConstraintType
()
!=
Constraint
.
Type
.
REFERENTIAL
)
{
continue
;
}
ConstraintReferential
ref
=
(
ConstraintReferential
)
c
;
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
77b6e4b1
...
...
@@ -868,8 +868,7 @@ public class MetaTable extends Table {
Constraint
constraint
=
constraints
.
get
(
k
);
if
(
constraint
.
usesIndex
(
index
))
{
if
(
index
.
getIndexType
().
isPrimaryKey
())
{
if
(
constraint
.
getConstraintType
().
equals
(
Constraint
.
PRIMARY_KEY
))
{
if
(
constraint
.
getConstraintType
()
==
Constraint
.
Type
.
PRIMARY_KEY
)
{
constraintName
=
constraint
.
getName
();
}
}
else
{
...
...
@@ -1544,7 +1543,7 @@ public class MetaTable extends Table {
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
))
{
Constraint
constraint
=
(
Constraint
)
obj
;
if
(
!(
constraint
.
getConstraintType
().
equals
(
Constraint
.
REFERENTIAL
))
)
{
if
(
constraint
.
getConstraintType
()
!=
Constraint
.
Type
.
REFERENTIAL
)
{
continue
;
}
ConstraintReferential
ref
=
(
ConstraintReferential
)
constraint
;
...
...
@@ -1597,7 +1596,7 @@ public class MetaTable extends Table {
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
))
{
Constraint
constraint
=
(
Constraint
)
obj
;
String
constraintType
=
constraint
.
getConstraintType
();
Constraint
.
Type
constraintType
=
constraint
.
getConstraintType
();
String
checkExpression
=
null
;
IndexColumn
[]
indexColumns
=
null
;
Table
table
=
constraint
.
getTable
();
...
...
@@ -1613,12 +1612,12 @@ public class MetaTable extends Table {
if
(!
checkIndex
(
session
,
tableName
,
indexFrom
,
indexTo
))
{
continue
;
}
if
(
constraintType
.
equals
(
Constraint
.
CHECK
)
)
{
if
(
constraintType
==
Constraint
.
Type
.
CHECK
)
{
checkExpression
=
((
ConstraintCheck
)
constraint
).
getExpression
().
getSQL
();
}
else
if
(
constraintType
.
equals
(
Constraint
.
UNIQUE
)
||
constraintType
.
equals
(
Constraint
.
PRIMARY_KEY
)
)
{
}
else
if
(
constraintType
==
Constraint
.
Type
.
UNIQUE
||
constraintType
==
Constraint
.
Type
.
PRIMARY_KEY
)
{
indexColumns
=
((
ConstraintUnique
)
constraint
).
getColumns
();
}
else
if
(
constraintType
.
equals
(
Constraint
.
REFERENTIAL
)
)
{
}
else
if
(
constraintType
==
Constraint
.
Type
.
REFERENTIAL
)
{
indexColumns
=
((
ConstraintReferential
)
constraint
).
getColumns
();
}
String
columnList
=
null
;
...
...
@@ -1638,7 +1637,7 @@ public class MetaTable extends Table {
// CONSTRAINT_NAME
identifier
(
constraint
.
getName
()),
// CONSTRAINT_TYPE
constraintType
,
constraintType
.
toString
()
,
// TABLE_CATALOG
catalog
,
// TABLE_SCHEMA
...
...
h2/src/main/org/h2/table/RegularTable.java
浏览文件 @
77b6e4b1
...
...
@@ -746,7 +746,7 @@ public class RegularTable extends TableBase {
if
(
constraints
!=
null
)
{
for
(
int
i
=
0
,
size
=
constraints
.
size
();
i
<
size
;
i
++)
{
Constraint
c
=
constraints
.
get
(
i
);
if
(
!(
c
.
getConstraintType
().
equals
(
Constraint
.
REFERENTIAL
))
)
{
if
(
c
.
getConstraintType
()
!=
Constraint
.
Type
.
REFERENTIAL
)
{
continue
;
}
ConstraintReferential
ref
=
(
ConstraintReferential
)
c
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论