Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f28d45c5
提交
f28d45c5
authored
9月 22, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unify CREATE and ALTER SEQUENCE options parsing
上级
061618f0
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
177 行增加
和
193 行删除
+177
-193
Parser.java
h2/src/main/org/h2/command/Parser.java
+49
-79
AlterSequence.java
h2/src/main/org/h2/command/ddl/AlterSequence.java
+18
-52
CreateSequence.java
h2/src/main/org/h2/command/ddl/CreateSequence.java
+10
-45
SequenceOptions.java
h2/src/main/org/h2/command/ddl/SequenceOptions.java
+84
-0
Column.java
h2/src/main/org/h2/table/Column.java
+16
-17
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
f28d45c5
...
@@ -65,6 +65,7 @@ import org.h2.api.IntervalQualifier;
...
@@ -65,6 +65,7 @@ import org.h2.api.IntervalQualifier;
import
org.h2.api.Trigger
;
import
org.h2.api.Trigger
;
import
org.h2.command.ddl.AlterIndexRename
;
import
org.h2.command.ddl.AlterIndexRename
;
import
org.h2.command.ddl.AlterSchemaRename
;
import
org.h2.command.ddl.AlterSchemaRename
;
import
org.h2.command.ddl.AlterSequence
;
import
org.h2.command.ddl.AlterTableAddConstraint
;
import
org.h2.command.ddl.AlterTableAddConstraint
;
import
org.h2.command.ddl.AlterTableAlterColumn
;
import
org.h2.command.ddl.AlterTableAlterColumn
;
import
org.h2.command.ddl.AlterTableDropConstraint
;
import
org.h2.command.ddl.AlterTableDropConstraint
;
...
@@ -108,9 +109,9 @@ import org.h2.command.ddl.DropView;
...
@@ -108,9 +109,9 @@ import org.h2.command.ddl.DropView;
import
org.h2.command.ddl.GrantRevoke
;
import
org.h2.command.ddl.GrantRevoke
;
import
org.h2.command.ddl.PrepareProcedure
;
import
org.h2.command.ddl.PrepareProcedure
;
import
org.h2.command.ddl.SchemaCommand
;
import
org.h2.command.ddl.SchemaCommand
;
import
org.h2.command.ddl.SequenceOptions
;
import
org.h2.command.ddl.SetComment
;
import
org.h2.command.ddl.SetComment
;
import
org.h2.command.ddl.TruncateTable
;
import
org.h2.command.ddl.TruncateTable
;
import
org.h2.command.dml.AlterSequence
;
import
org.h2.command.dml.AlterTableSet
;
import
org.h2.command.dml.AlterTableSet
;
import
org.h2.command.dml.BackupCommand
;
import
org.h2.command.dml.BackupCommand
;
import
org.h2.command.dml.Call
;
import
org.h2.command.dml.Call
;
...
@@ -171,10 +172,10 @@ import org.h2.expression.UnaryOperation;
...
@@ -171,10 +172,10 @@ import org.h2.expression.UnaryOperation;
import
org.h2.expression.ValueExpression
;
import
org.h2.expression.ValueExpression
;
import
org.h2.expression.Variable
;
import
org.h2.expression.Variable
;
import
org.h2.expression.Wildcard
;
import
org.h2.expression.Wildcard
;
import
org.h2.expression.aggregate.DataAnalysisOperation
;
import
org.h2.expression.aggregate.AbstractAggregate
;
import
org.h2.expression.aggregate.AbstractAggregate
;
import
org.h2.expression.aggregate.Aggregate
;
import
org.h2.expression.aggregate.Aggregate
;
import
org.h2.expression.aggregate.Aggregate.AggregateType
;
import
org.h2.expression.aggregate.Aggregate.AggregateType
;
import
org.h2.expression.aggregate.DataAnalysisOperation
;
import
org.h2.expression.aggregate.JavaAggregate
;
import
org.h2.expression.aggregate.JavaAggregate
;
import
org.h2.expression.aggregate.Window
;
import
org.h2.expression.aggregate.Window
;
import
org.h2.expression.aggregate.WindowFrame
;
import
org.h2.expression.aggregate.WindowFrame
;
...
@@ -4875,19 +4876,12 @@ public class Parser {
...
@@ -4875,19 +4876,12 @@ public class Parser {
}
}
read
(
"AS"
);
read
(
"AS"
);
read
(
"IDENTITY"
);
read
(
"IDENTITY"
);
long
start
=
1
,
increment
=
1
;
SequenceOptions
options
=
new
SequenceOptions
()
;
if
(
readIf
(
OPEN_PAREN
))
{
if
(
readIf
(
OPEN_PAREN
))
{
read
(
"START"
);
parseSequenceOptions
(
options
,
null
,
true
);
readIf
(
WITH
);
start
=
readLong
();
readIf
(
COMMA
);
if
(
readIf
(
"INCREMENT"
))
{
readIf
(
"BY"
);
increment
=
readLong
();
}
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
}
}
column
.
setAutoIncrement
(
true
,
start
,
increment
);
column
.
setAutoIncrement
Options
(
options
);
}
}
if
(
readIf
(
ON
))
{
if
(
readIf
(
ON
))
{
read
(
"UPDATE"
);
read
(
"UPDATE"
);
...
@@ -4924,15 +4918,15 @@ public class Parser {
...
@@ -4924,15 +4918,15 @@ public class Parser {
}
}
private
void
parseAutoIncrement
(
Column
column
)
{
private
void
parseAutoIncrement
(
Column
column
)
{
long
start
=
1
,
increment
=
1
;
SequenceOptions
options
=
new
SequenceOptions
()
;
if
(
readIf
(
OPEN_PAREN
))
{
if
(
readIf
(
OPEN_PAREN
))
{
start
=
readLong
(
);
options
.
setStartValue
(
ValueExpression
.
get
(
ValueLong
.
get
(
readLong
()))
);
if
(
readIf
(
COMMA
))
{
if
(
readIf
(
COMMA
))
{
increment
=
readLong
(
);
options
.
setIncrement
(
ValueExpression
.
get
(
ValueLong
.
get
(
readLong
()))
);
}
}
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
}
}
column
.
setAutoIncrement
(
true
,
start
,
increment
);
column
.
setAutoIncrement
Options
(
options
);
}
}
private
String
readCommentIf
()
{
private
String
readCommentIf
()
{
...
@@ -5665,49 +5659,9 @@ public class Parser {
...
@@ -5665,49 +5659,9 @@ public class Parser {
CreateSequence
command
=
new
CreateSequence
(
session
,
getSchema
());
CreateSequence
command
=
new
CreateSequence
(
session
,
getSchema
());
command
.
setIfNotExists
(
ifNotExists
);
command
.
setIfNotExists
(
ifNotExists
);
command
.
setSequenceName
(
sequenceName
);
command
.
setSequenceName
(
sequenceName
);
while
(
true
)
{
SequenceOptions
options
=
new
SequenceOptions
();
if
(
readIf
(
"START"
))
{
parseSequenceOptions
(
options
,
command
,
true
);
readIf
(
WITH
);
command
.
setOptions
(
options
);
command
.
setStartWith
(
readExpression
());
}
else
if
(
readIf
(
"INCREMENT"
))
{
readIf
(
"BY"
);
command
.
setIncrement
(
readExpression
());
}
else
if
(
readIf
(
"MINVALUE"
))
{
command
.
setMinValue
(
readExpression
());
}
else
if
(
readIf
(
"NOMINVALUE"
))
{
command
.
setMinValue
(
null
);
}
else
if
(
readIf
(
"MAXVALUE"
))
{
command
.
setMaxValue
(
readExpression
());
}
else
if
(
readIf
(
"NOMAXVALUE"
))
{
command
.
setMaxValue
(
null
);
}
else
if
(
readIf
(
"CYCLE"
))
{
command
.
setCycle
(
true
);
}
else
if
(
readIf
(
"NOCYCLE"
))
{
command
.
setCycle
(
false
);
}
else
if
(
readIf
(
"NO"
))
{
if
(
readIf
(
"MINVALUE"
))
{
command
.
setMinValue
(
null
);
}
else
if
(
readIf
(
"MAXVALUE"
))
{
command
.
setMaxValue
(
null
);
}
else
if
(
readIf
(
"CYCLE"
))
{
command
.
setCycle
(
false
);
}
else
if
(
readIf
(
"CACHE"
))
{
command
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
}
else
{
break
;
}
}
else
if
(
readIf
(
"CACHE"
))
{
command
.
setCacheSize
(
readExpression
());
}
else
if
(
readIf
(
"NOCACHE"
))
{
command
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
}
else
if
(
readIf
(
"BELONGS_TO_TABLE"
))
{
command
.
setBelongsToTable
(
true
);
}
else
if
(
readIf
(
ORDER
))
{
// Oracle compatibility
}
else
{
break
;
}
}
return
command
;
return
command
;
}
}
...
@@ -6230,46 +6184,60 @@ public class Parser {
...
@@ -6230,46 +6184,60 @@ public class Parser {
AlterSequence
command
=
new
AlterSequence
(
session
,
getSchema
());
AlterSequence
command
=
new
AlterSequence
(
session
,
getSchema
());
command
.
setSequenceName
(
sequenceName
);
command
.
setSequenceName
(
sequenceName
);
command
.
setIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
while
(
true
)
{
SequenceOptions
options
=
new
SequenceOptions
();
if
(
readIf
(
"RESTART"
))
{
parseSequenceOptions
(
options
,
null
,
false
);
read
(
WITH
);
command
.
setOptions
(
options
);
command
.
setStartWith
(
readExpression
());
return
command
;
}
private
void
parseSequenceOptions
(
SequenceOptions
options
,
CreateSequence
command
,
boolean
forCreate
)
{
for
(;;)
{
if
(
readIf
(
forCreate
?
"START"
:
"RESTART"
))
{
readIf
(
WITH
);
options
.
setStartValue
(
readExpression
());
}
else
if
(
readIf
(
"INCREMENT"
))
{
}
else
if
(
readIf
(
"INCREMENT"
))
{
read
(
"BY"
);
read
If
(
"BY"
);
command
.
setIncrement
(
readExpression
());
options
.
setIncrement
(
readExpression
());
}
else
if
(
readIf
(
"MINVALUE"
))
{
}
else
if
(
readIf
(
"MINVALUE"
))
{
command
.
setMinValue
(
readExpression
());
options
.
setMinValue
(
readExpression
());
}
else
if
(
readIf
(
"NOMINVALUE"
))
{
}
else
if
(
readIf
(
"NOMINVALUE"
))
{
command
.
setMinValue
(
null
);
options
.
setMinValue
(
null
);
}
else
if
(
readIf
(
"MAXVALUE"
))
{
}
else
if
(
readIf
(
"MAXVALUE"
))
{
command
.
setMaxValue
(
readExpression
());
options
.
setMaxValue
(
readExpression
());
}
else
if
(
readIf
(
"NOMAXVALUE"
))
{
}
else
if
(
readIf
(
"NOMAXVALUE"
))
{
command
.
setMaxValue
(
null
);
options
.
setMaxValue
(
null
);
}
else
if
(
readIf
(
"CYCLE"
))
{
}
else
if
(
readIf
(
"CYCLE"
))
{
command
.
setCycle
(
true
);
options
.
setCycle
(
true
);
}
else
if
(
readIf
(
"NOCYCLE"
))
{
}
else
if
(
readIf
(
"NOCYCLE"
))
{
command
.
setCycle
(
false
);
options
.
setCycle
(
false
);
}
else
if
(
readIf
(
"NO"
))
{
}
else
if
(
readIf
(
"NO"
))
{
if
(
readIf
(
"MINVALUE"
))
{
if
(
readIf
(
"MINVALUE"
))
{
command
.
setMinValue
(
null
);
options
.
setMinValue
(
null
);
}
else
if
(
readIf
(
"MAXVALUE"
))
{
}
else
if
(
readIf
(
"MAXVALUE"
))
{
command
.
setMaxValue
(
null
);
options
.
setMaxValue
(
null
);
}
else
if
(
readIf
(
"CYCLE"
))
{
}
else
if
(
readIf
(
"CYCLE"
))
{
command
.
setCycle
(
false
);
options
.
setCycle
(
false
);
}
else
if
(
readIf
(
"CACHE"
))
{
}
else
if
(
readIf
(
"CACHE"
))
{
command
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
options
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
}
else
{
}
else
{
break
;
break
;
}
}
}
else
if
(
readIf
(
"CACHE"
))
{
}
else
if
(
readIf
(
"CACHE"
))
{
command
.
setCacheSize
(
readExpression
());
options
.
setCacheSize
(
readExpression
());
}
else
if
(
readIf
(
"NOCACHE"
))
{
}
else
if
(
readIf
(
"NOCACHE"
))
{
command
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
options
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
}
else
if
(
command
!=
null
)
{
if
(
readIf
(
"BELONGS_TO_TABLE"
))
{
command
.
setBelongsToTable
(
true
);
}
else
if
(
readIf
(
ORDER
))
{
// Oracle compatibility
}
else
{
break
;
}
}
else
{
}
else
{
break
;
break
;
}
}
}
}
return
command
;
}
}
private
AlterUser
parseAlterUser
()
{
private
AlterUser
parseAlterUser
()
{
...
@@ -7039,7 +7007,9 @@ public class Parser {
...
@@ -7039,7 +7007,9 @@ public class Parser {
Expression
start
=
readExpression
();
Expression
start
=
readExpression
();
AlterSequence
command
=
new
AlterSequence
(
session
,
schema
);
AlterSequence
command
=
new
AlterSequence
(
session
,
schema
);
command
.
setColumn
(
column
);
command
.
setColumn
(
column
);
command
.
setStartWith
(
start
);
SequenceOptions
options
=
new
SequenceOptions
();
options
.
setStartValue
(
start
);
command
.
setOptions
(
options
);
return
commandIfTableExists
(
schema
,
tableName
,
ifTableExists
,
command
);
return
commandIfTableExists
(
schema
,
tableName
,
ifTableExists
,
command
);
}
else
if
(
readIf
(
"SELECTIVITY"
))
{
}
else
if
(
readIf
(
"SELECTIVITY"
))
{
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
...
...
h2/src/main/org/h2/command/d
m
l/AlterSequence.java
→
h2/src/main/org/h2/command/d
d
l/AlterSequence.java
浏览文件 @
f28d45c5
...
@@ -3,15 +3,13 @@
...
@@ -3,15 +3,13 @@
* and the EPL 1.0 (http://h2database.com/html/license.html).
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Initial Developer: H2 Group
*/
*/
package
org
.
h2
.
command
.
d
m
l
;
package
org
.
h2
.
command
.
d
d
l
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.ddl.SchemaCommand
;
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
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.Sequence
;
...
@@ -19,21 +17,19 @@ import org.h2.table.Column;
...
@@ -19,21 +17,19 @@ import org.h2.table.Column;
import
org.h2.table.Table
;
import
org.h2.table.Table
;
/**
/**
* This class represents the statement
* This class represents the statement ALTER SEQUENCE.
* ALTER SEQUENCE
*/
*/
public
class
AlterSequence
extends
SchemaCommand
{
public
class
AlterSequence
extends
SchemaCommand
{
private
boolean
ifExists
;
private
boolean
ifExists
;
private
Table
table
;
private
Table
table
;
private
String
sequenceName
;
private
String
sequenceName
;
private
Sequence
sequence
;
private
Sequence
sequence
;
private
Expression
start
;
private
Expression
increment
;
private
SequenceOptions
options
;
private
Boolean
cycle
;
private
Expression
minValue
;
private
Expression
maxValue
;
private
Expression
cacheSize
;
public
AlterSequence
(
Session
session
,
Schema
schema
)
{
public
AlterSequence
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
super
(
session
,
schema
);
...
@@ -47,6 +43,10 @@ public class AlterSequence extends SchemaCommand {
...
@@ -47,6 +43,10 @@ public class AlterSequence extends SchemaCommand {
this
.
sequenceName
=
sequenceName
;
this
.
sequenceName
=
sequenceName
;
}
}
public
void
setOptions
(
SequenceOptions
options
)
{
this
.
options
=
options
;
}
@Override
@Override
public
boolean
isTransactional
()
{
public
boolean
isTransactional
()
{
return
true
;
return
true
;
...
@@ -60,30 +60,6 @@ public class AlterSequence extends SchemaCommand {
...
@@ -60,30 +60,6 @@ public class AlterSequence extends SchemaCommand {
}
}
}
}
public
void
setStartWith
(
Expression
start
)
{
this
.
start
=
start
;
}
public
void
setIncrement
(
Expression
increment
)
{
this
.
increment
=
increment
;
}
public
void
setCycle
(
Boolean
cycle
)
{
this
.
cycle
=
cycle
;
}
public
void
setMinValue
(
Expression
minValue
)
{
this
.
minValue
=
minValue
;
}
public
void
setMaxValue
(
Expression
maxValue
)
{
this
.
maxValue
=
maxValue
;
}
public
void
setCacheSize
(
Expression
cacheSize
)
{
this
.
cacheSize
=
cacheSize
;
}
@Override
@Override
public
int
update
()
{
public
int
update
()
{
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
...
@@ -99,32 +75,22 @@ public class AlterSequence extends SchemaCommand {
...
@@ -99,32 +75,22 @@ public class AlterSequence extends SchemaCommand {
if
(
table
!=
null
)
{
if
(
table
!=
null
)
{
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
}
}
Boolean
cycle
=
options
.
getCycle
();
if
(
cycle
!=
null
)
{
if
(
cycle
!=
null
)
{
sequence
.
setCycle
(
cycle
);
sequence
.
setCycle
(
cycle
);
}
}
if
(
cacheSize
!=
null
)
{
Long
cache
=
options
.
getCacheSize
(
session
);
long
size
=
cacheSize
.
optimize
(
session
).
getValue
(
session
).
getLong
();
if
(
cache
!=
null
)
{
sequence
.
setCacheSize
(
siz
e
);
sequence
.
setCacheSize
(
cach
e
);
}
}
if
(
start
!=
null
||
minValue
!=
null
||
if
(
options
.
isRangeSet
())
{
maxValue
!=
null
||
increment
!=
null
)
{
sequence
.
modify
(
options
.
getStartValue
(
session
),
options
.
getMinValue
(
session
),
options
.
getMaxValue
(
session
),
Long
startValue
=
getLong
(
start
);
options
.
getIncrement
(
session
));
Long
min
=
getLong
(
minValue
);
Long
max
=
getLong
(
maxValue
);
Long
inc
=
getLong
(
increment
);
sequence
.
modify
(
startValue
,
min
,
max
,
inc
);
}
}
db
.
updateMeta
(
session
,
sequence
);
db
.
updateMeta
(
session
,
sequence
);
return
0
;
return
0
;
}
}
private
Long
getLong
(
Expression
expr
)
{
if
(
expr
==
null
)
{
return
null
;
}
return
expr
.
optimize
(
session
).
getValue
(
session
).
getLong
();
}
@Override
@Override
public
int
getType
()
{
public
int
getType
()
{
return
CommandInterface
.
ALTER_SEQUENCE
;
return
CommandInterface
.
ALTER_SEQUENCE
;
...
...
h2/src/main/org/h2/command/ddl/CreateSequence.java
浏览文件 @
f28d45c5
...
@@ -9,25 +9,21 @@ import org.h2.api.ErrorCode;
...
@@ -9,25 +9,21 @@ import org.h2.api.ErrorCode;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.Sequence
;
/**
/**
* This class represents the statement
* This class represents the statement CREATE SEQUENCE.
* CREATE SEQUENCE
*/
*/
public
class
CreateSequence
extends
SchemaCommand
{
public
class
CreateSequence
extends
SchemaCommand
{
private
String
sequenceName
;
private
String
sequenceName
;
private
boolean
ifNotExists
;
private
boolean
ifNotExists
;
private
boolean
cycle
;
private
Expression
minValue
;
private
SequenceOptions
options
;
private
Expression
maxValue
;
private
Expression
start
;
private
Expression
increment
;
private
Expression
cacheSize
;
private
boolean
belongsToTable
;
private
boolean
belongsToTable
;
public
CreateSequence
(
Session
session
,
Schema
schema
)
{
public
CreateSequence
(
Session
session
,
Schema
schema
)
{
...
@@ -42,8 +38,8 @@ public class CreateSequence extends SchemaCommand {
...
@@ -42,8 +38,8 @@ public class CreateSequence extends SchemaCommand {
this
.
ifNotExists
=
ifNotExists
;
this
.
ifNotExists
=
ifNotExists
;
}
}
public
void
set
Cycle
(
boolean
cycle
)
{
public
void
set
Options
(
SequenceOptions
options
)
{
this
.
cycle
=
cycle
;
this
.
options
=
options
;
}
}
@Override
@Override
...
@@ -57,48 +53,17 @@ public class CreateSequence extends SchemaCommand {
...
@@ -57,48 +53,17 @@ public class CreateSequence extends SchemaCommand {
throw
DbException
.
get
(
ErrorCode
.
SEQUENCE_ALREADY_EXISTS_1
,
sequenceName
);
throw
DbException
.
get
(
ErrorCode
.
SEQUENCE_ALREADY_EXISTS_1
,
sequenceName
);
}
}
int
id
=
getObjectId
();
int
id
=
getObjectId
();
Long
startValue
=
getLong
(
start
);
Sequence
sequence
=
new
Sequence
(
getSchema
(),
id
,
sequenceName
,
options
.
getStartValue
(
session
),
Long
inc
=
getLong
(
increment
);
options
.
getIncrement
(
session
),
options
.
getCacheSize
(
session
),
options
.
getMinValue
(
session
),
Long
cache
=
getLong
(
cacheSize
);
options
.
getMaxValue
(
session
),
Boolean
.
TRUE
.
equals
(
options
.
getCycle
()),
belongsToTable
);
Long
min
=
getLong
(
minValue
);
Long
max
=
getLong
(
maxValue
);
Sequence
sequence
=
new
Sequence
(
getSchema
(),
id
,
sequenceName
,
startValue
,
inc
,
cache
,
min
,
max
,
cycle
,
belongsToTable
);
db
.
addSchemaObject
(
session
,
sequence
);
db
.
addSchemaObject
(
session
,
sequence
);
return
0
;
return
0
;
}
}
private
Long
getLong
(
Expression
expr
)
{
if
(
expr
==
null
)
{
return
null
;
}
return
expr
.
optimize
(
session
).
getValue
(
session
).
getLong
();
}
public
void
setStartWith
(
Expression
start
)
{
this
.
start
=
start
;
}
public
void
setIncrement
(
Expression
increment
)
{
this
.
increment
=
increment
;
}
public
void
setMinValue
(
Expression
minValue
)
{
this
.
minValue
=
minValue
;
}
public
void
setMaxValue
(
Expression
maxValue
)
{
this
.
maxValue
=
maxValue
;
}
public
void
setBelongsToTable
(
boolean
belongsToTable
)
{
public
void
setBelongsToTable
(
boolean
belongsToTable
)
{
this
.
belongsToTable
=
belongsToTable
;
this
.
belongsToTable
=
belongsToTable
;
}
}
public
void
setCacheSize
(
Expression
cacheSize
)
{
this
.
cacheSize
=
cacheSize
;
}
@Override
@Override
public
int
getType
()
{
public
int
getType
()
{
return
CommandInterface
.
CREATE_SEQUENCE
;
return
CommandInterface
.
CREATE_SEQUENCE
;
...
...
h2/src/main/org/h2/command/ddl/SequenceOptions.java
0 → 100644
浏览文件 @
f28d45c5
/*
* 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
.
command
.
ddl
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
/**
* Sequence options.
*/
public
class
SequenceOptions
{
private
Expression
start
;
private
Expression
increment
;
private
Expression
maxValue
;
private
Expression
minValue
;
private
Boolean
cycle
;
private
Expression
cacheSize
;
private
static
Long
getLong
(
Session
session
,
Expression
expr
)
{
return
expr
!=
null
?
expr
.
optimize
(
session
).
getValue
(
session
).
getLong
()
:
null
;
}
public
Long
getStartValue
(
Session
session
)
{
return
getLong
(
session
,
start
);
}
public
void
setStartValue
(
Expression
start
)
{
this
.
start
=
start
;
}
public
Long
getIncrement
(
Session
session
)
{
return
getLong
(
session
,
increment
);
}
public
void
setIncrement
(
Expression
increment
)
{
this
.
increment
=
increment
;
}
public
Long
getMaxValue
(
Session
session
)
{
return
getLong
(
session
,
maxValue
);
}
public
void
setMaxValue
(
Expression
maxValue
)
{
this
.
maxValue
=
maxValue
;
}
public
Long
getMinValue
(
Session
session
)
{
return
getLong
(
session
,
minValue
);
}
public
void
setMinValue
(
Expression
minValue
)
{
this
.
minValue
=
minValue
;
}
public
Boolean
getCycle
()
{
return
cycle
;
}
public
void
setCycle
(
Boolean
cycle
)
{
this
.
cycle
=
cycle
;
}
public
Long
getCacheSize
(
Session
session
)
{
return
getLong
(
session
,
cacheSize
);
}
public
void
setCacheSize
(
Expression
cacheSize
)
{
this
.
cacheSize
=
cacheSize
;
}
protected
boolean
isRangeSet
()
{
return
start
!=
null
||
minValue
!=
null
||
maxValue
!=
null
||
increment
!=
null
;
}
}
h2/src/main/org/h2/table/Column.java
浏览文件 @
f28d45c5
...
@@ -10,6 +10,7 @@ import java.util.Objects;
...
@@ -10,6 +10,7 @@ import java.util.Objects;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
import
org.h2.command.ddl.SequenceOptions
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -77,9 +78,7 @@ public class Column {
...
@@ -77,9 +78,7 @@ public class Column {
private
Expression
checkConstraint
;
private
Expression
checkConstraint
;
private
String
checkConstraintSQL
;
private
String
checkConstraintSQL
;
private
String
originalSQL
;
private
String
originalSQL
;
private
boolean
autoIncrement
;
private
SequenceOptions
autoIncrementOptions
;
private
long
start
;
private
long
increment
;
private
boolean
convertNullToDefault
;
private
boolean
convertNullToDefault
;
private
Sequence
sequence
;
private
Sequence
sequence
;
private
boolean
isComputed
;
private
boolean
isComputed
;
...
@@ -440,7 +439,7 @@ public class Column {
...
@@ -440,7 +439,7 @@ public class Column {
*/
*/
public
void
convertAutoIncrementToSequence
(
Session
session
,
Schema
schema
,
public
void
convertAutoIncrementToSequence
(
Session
session
,
Schema
schema
,
int
id
,
boolean
temporary
)
{
int
id
,
boolean
temporary
)
{
if
(
!
autoIncrement
)
{
if
(
autoIncrementOptions
==
null
)
{
DbException
.
throwInternalError
();
DbException
.
throwInternalError
();
}
}
if
(
"IDENTITY"
.
equals
(
originalSQL
))
{
if
(
"IDENTITY"
.
equals
(
originalSQL
))
{
...
@@ -455,10 +454,13 @@ public class Column {
...
@@ -455,10 +454,13 @@ public class Column {
s
=
StringUtils
.
toUpperEnglish
(
s
.
replace
(
'-'
,
'_'
));
s
=
StringUtils
.
toUpperEnglish
(
s
.
replace
(
'-'
,
'_'
));
sequenceName
=
"SYSTEM_SEQUENCE_"
+
s
;
sequenceName
=
"SYSTEM_SEQUENCE_"
+
s
;
}
while
(
schema
.
findSequence
(
sequenceName
)
!=
null
);
}
while
(
schema
.
findSequence
(
sequenceName
)
!=
null
);
Sequence
seq
=
new
Sequence
(
schema
,
id
,
sequenceName
,
start
,
increment
);
Sequence
seq
=
new
Sequence
(
schema
,
id
,
sequenceName
,
autoIncrementOptions
.
getStartValue
(
session
),
autoIncrementOptions
.
getIncrement
(
session
),
autoIncrementOptions
.
getCacheSize
(
session
),
autoIncrementOptions
.
getMinValue
(
session
),
autoIncrementOptions
.
getMaxValue
(
session
),
Boolean
.
TRUE
.
equals
(
autoIncrementOptions
.
getCycle
()),
true
);
seq
.
setTemporary
(
temporary
);
seq
.
setTemporary
(
temporary
);
session
.
getDatabase
().
addSchemaObject
(
session
,
seq
);
session
.
getDatabase
().
addSchemaObject
(
session
,
seq
);
setAutoIncrement
(
false
,
0
,
0
);
setAutoIncrement
Options
(
null
);
SequenceValue
seqValue
=
new
SequenceValue
(
seq
);
SequenceValue
seqValue
=
new
SequenceValue
(
seq
);
setDefaultExpression
(
session
,
seqValue
);
setDefaultExpression
(
session
,
seqValue
);
setSequence
(
seq
);
setSequence
(
seq
);
...
@@ -603,22 +605,19 @@ public class Column {
...
@@ -603,22 +605,19 @@ public class Column {
}
}
public
boolean
isAutoIncrement
()
{
public
boolean
isAutoIncrement
()
{
return
autoIncrement
;
return
autoIncrement
Options
!=
null
;
}
}
/**
/**
* Set the autoincrement flag and related
propertie
s of this column.
* Set the autoincrement flag and related
option
s of this column.
*
*
* @param autoInc the new autoincrement flag
* @param sequenceOptions
* @param start the sequence start value
* sequence options, or {@code null} to reset the flag
* @param increment the sequence increment
*/
*/
public
void
setAutoIncrement
(
boolean
autoInc
,
long
start
,
long
increment
)
{
public
void
setAutoIncrementOptions
(
SequenceOptions
sequenceOptions
)
{
this
.
autoIncrement
=
autoInc
;
this
.
autoIncrementOptions
=
sequenceOptions
;
this
.
start
=
start
;
this
.
increment
=
increment
;
this
.
nullable
=
false
;
this
.
nullable
=
false
;
if
(
autoInc
)
{
if
(
sequenceOptions
!=
null
)
{
convertNullToDefault
=
true
;
convertNullToDefault
=
true
;
}
}
}
}
...
@@ -829,7 +828,7 @@ public class Column {
...
@@ -829,7 +828,7 @@ public class Column {
if
(
primaryKey
!=
newColumn
.
primaryKey
)
{
if
(
primaryKey
!=
newColumn
.
primaryKey
)
{
return
false
;
return
false
;
}
}
if
(
autoIncrement
||
newColumn
.
autoIncrement
)
{
if
(
autoIncrement
Options
!=
null
||
newColumn
.
autoIncrementOptions
!=
null
)
{
return
false
;
return
false
;
}
}
if
(
checkConstraint
!=
null
||
newColumn
.
checkConstraint
!=
null
)
{
if
(
checkConstraint
!=
null
||
newColumn
.
checkConstraint
!=
null
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论