Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e8d00a2c
提交
e8d00a2c
authored
3月 30, 2017
作者:
Max Englander
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enum-support: use toUpperCase(ENGLISH) instead of toLowerCase()
上级
2c903f83
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
61 行增加
和
94 行删除
+61
-94
Parser.java
h2/src/main/org/h2/command/Parser.java
+5
-7
Column.java
h2/src/main/org/h2/table/Column.java
+1
-1
DataType.java
h2/src/main/org/h2/value/DataType.java
+1
-1
ValueEnum.java
h2/src/main/org/h2/value/ValueEnum.java
+52
-83
ValueEnumBase.java
h2/src/main/org/h2/value/ValueEnumBase.java
+2
-2
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e8d00a2c
...
@@ -4128,7 +4128,6 @@ public class Parser {
...
@@ -4128,7 +4128,6 @@ public class Parser {
}
}
long
precision
=
-
1
;
long
precision
=
-
1
;
int
displaySize
=
-
1
;
int
displaySize
=
-
1
;
java
.
util
.
List
<
String
>
enumeratorList
=
null
;
String
[]
enumerators
=
null
;
String
[]
enumerators
=
null
;
int
scale
=
-
1
;
int
scale
=
-
1
;
String
comment
=
null
;
String
comment
=
null
;
...
@@ -4205,22 +4204,21 @@ public class Parser {
...
@@ -4205,22 +4204,21 @@ public class Parser {
}
}
}
else
if
(
dataType
.
enumerated
)
{
}
else
if
(
dataType
.
enumerated
)
{
if
(
readIf
(
"("
))
{
if
(
readIf
(
"("
))
{
enumeratorList
=
new
ArrayList
<
String
>();
java
.
util
.
List
<
String
>
enumeratorList
=
new
ArrayList
<
String
>();
original
+=
'('
;
original
+=
'('
;
String
enumerator0
=
readString
();
String
enumerator0
=
readString
();
enumeratorList
.
add
(
enumerator0
.
toLowerCase
().
trim
()
);
enumeratorList
.
add
(
enumerator0
);
original
+=
"'"
+
enumerator0
+
"'"
;
original
+=
"'"
+
enumerator0
+
"'"
;
while
(
readIf
(
","
))
{
while
(
readIf
(
","
))
{
original
+=
','
;
original
+=
','
;
String
enumeratorN
=
readString
();
String
enumeratorN
=
readString
();
original
+=
"'"
+
enumeratorN
+
"'"
;
original
+=
"'"
+
enumeratorN
+
"'"
;
enumeratorList
.
add
(
enumeratorN
.
toLowerCase
().
trim
()
);
enumeratorList
.
add
(
enumeratorN
);
}
}
read
(
")"
);
read
(
")"
);
original
+=
')'
;
original
+=
')'
;
enumerators
=
enumeratorList
.
toArray
(
new
String
[
enumeratorList
.
size
()]);
}
}
enumerators
=
enumeratorList
.
toArray
(
new
String
[
enumeratorList
.
size
()]);
try
{
try
{
ValueEnum
.
check
(
enumerators
);
ValueEnum
.
check
(
enumerators
);
}
catch
(
DbException
e
)
{
}
catch
(
DbException
e
)
{
...
@@ -4249,7 +4247,7 @@ public class Parser {
...
@@ -4249,7 +4247,7 @@ public class Parser {
Column
column
=
new
Column
(
columnName
,
type
,
precision
,
scale
,
Column
column
=
new
Column
(
columnName
,
type
,
precision
,
scale
,
displaySize
,
enumerators
==
null
?
null
:
enumerators
);
displaySize
,
enumerators
);
if
(
templateColumn
!=
null
)
{
if
(
templateColumn
!=
null
)
{
column
.
setNullable
(
templateColumn
.
isNullable
());
column
.
setNullable
(
templateColumn
.
isNullable
());
column
.
setDefaultExpression
(
session
,
column
.
setDefaultExpression
(
session
,
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
e8d00a2c
...
@@ -147,7 +147,7 @@ public class Column {
...
@@ -147,7 +147,7 @@ public class Column {
}
}
public
boolean
isEnumerated
()
{
public
boolean
isEnumerated
()
{
return
enumerators
!=
null
&&
enumerators
.
length
>
0
;
return
type
==
Value
.
ENUM
;
}
}
public
Column
getClone
()
{
public
Column
getClone
()
{
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
e8d00a2c
...
@@ -141,7 +141,7 @@ public class DataType {
...
@@ -141,7 +141,7 @@ public class DataType {
public
boolean
caseSensitive
;
public
boolean
caseSensitive
;
/**
/**
* If
permitted values are supports
.
* If
enumerated values are supported
.
*/
*/
public
boolean
enumerated
;
public
boolean
enumerated
;
...
...
h2/src/main/org/h2/value/ValueEnum.java
浏览文件 @
e8d00a2c
package
org
.
h2
.
value
;
package
org
.
h2
.
value
;
import
java.util.Locale
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
...
@@ -35,30 +37,6 @@ public class ValueEnum extends ValueEnumBase {
...
@@ -35,30 +37,6 @@ public class ValueEnum extends ValueEnumBase {
}
}
}
}
private
static
final
void
check
(
final
String
[]
enumerators
,
final
String
label
)
{
check
(
enumerators
);
switch
(
validate
(
enumerators
,
label
))
{
case
VALID:
return
;
default
:
throw
DbException
.
get
(
ErrorCode
.
ENUM_VALUE_NOT_PERMITTED_2
,
toString
(
enumerators
),
"'"
+
label
+
"'"
);
}
}
private
static
final
void
check
(
final
String
[]
enumerators
,
final
int
ordinal
)
{
check
(
enumerators
);
switch
(
validate
(
enumerators
,
ordinal
))
{
case
VALID:
return
;
default
:
throw
DbException
.
get
(
ErrorCode
.
ENUM_VALUE_NOT_PERMITTED_2
,
toString
(
enumerators
),
Integer
.
toString
(
ordinal
));
}
}
private
static
final
void
check
(
final
String
[]
enumerators
,
final
Value
value
)
{
private
static
final
void
check
(
final
String
[]
enumerators
,
final
Value
value
)
{
check
(
enumerators
);
check
(
enumerators
);
...
@@ -77,29 +55,20 @@ public class ValueEnum extends ValueEnumBase {
...
@@ -77,29 +55,20 @@ public class ValueEnum extends ValueEnumBase {
return
MathUtils
.
compareInt
(
ordinal
(),
ev
.
ordinal
());
return
MathUtils
.
compareInt
(
ordinal
(),
ev
.
ordinal
());
}
}
public
static
ValueEnum
get
(
final
String
[]
enumerators
,
final
String
label
)
{
check
(
enumerators
,
label
);
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
if
(
label
.
equals
(
enumerators
[
i
]))
return
new
ValueEnum
(
enumerators
,
i
);
}
throw
DbException
.
get
(
ErrorCode
.
GENERAL_ERROR_1
,
"Unexpected error"
);
}
public
static
ValueEnum
get
(
final
String
[]
enumerators
,
final
int
ordinal
)
{
check
(
enumerators
,
ordinal
);
return
new
ValueEnum
(
enumerators
,
ordinal
);
}
public
static
ValueEnum
get
(
final
String
[]
enumerators
,
final
Value
value
)
{
public
static
ValueEnum
get
(
final
String
[]
enumerators
,
final
Value
value
)
{
check
(
enumerators
,
value
);
check
(
enumerators
,
value
);
if
(
DataType
.
isStringType
(
value
.
getType
()))
{
if
(
DataType
.
isStringType
(
value
.
getType
()))
{
return
get
(
enumerators
,
value
.
getString
());
final
String
cleanLabel
=
sanitize
(
value
.
getString
());
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
if
(
cleanLabel
.
equals
(
sanitize
(
enumerators
[
i
])))
return
new
ValueEnum
(
enumerators
,
i
);
}
throw
DbException
.
get
(
ErrorCode
.
GENERAL_ERROR_1
,
"Unexpected error"
);
}
else
{
}
else
{
return
get
(
enumerators
,
value
.
getInt
());
return
new
ValueEnum
(
enumerators
,
value
.
getInt
());
}
}
}
}
...
@@ -107,21 +76,24 @@ public class ValueEnum extends ValueEnumBase {
...
@@ -107,21 +76,24 @@ public class ValueEnum extends ValueEnumBase {
return
enumerators
;
return
enumerators
;
}
}
@Override
public
static
boolean
isValid
(
final
String
enumerators
[],
final
Value
value
)
{
public
int
hashCode
()
{
return
validate
(
enumerators
,
value
).
equals
(
Validation
.
VALID
);
return
enumerators
.
hashCode
()
+
ordinal
();
}
}
p
ublic
static
boolean
isValid
(
final
String
enumerators
[],
final
String
label
)
{
p
rivate
static
String
sanitize
(
final
String
label
)
{
return
validate
(
enumerators
,
label
).
equals
(
Validation
.
VALID
);
return
label
==
null
?
null
:
label
.
trim
().
toUpperCase
(
Locale
.
ENGLISH
);
}
}
public
static
boolean
isValid
(
final
String
enumerators
[],
final
int
ordinal
)
{
public
static
String
[]
sanitize
(
final
String
[]
enumerators
)
{
return
validate
(
enumerators
,
ordinal
).
equals
(
Validation
.
VALID
);
if
(
enumerators
==
null
||
enumerators
.
length
==
0
)
return
null
;
}
public
static
boolean
isValid
(
final
String
enumerators
[],
final
Value
value
)
{
final
String
[]
clean
=
new
String
[
enumerators
.
length
];
return
validate
(
enumerators
,
value
).
equals
(
Validation
.
VALID
);
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
clean
[
i
]
=
sanitize
(
enumerators
[
i
]);
}
return
clean
;
}
}
private
static
String
toString
(
final
String
[]
enumerators
)
{
private
static
String
toString
(
final
String
[]
enumerators
)
{
...
@@ -136,33 +108,21 @@ public class ValueEnum extends ValueEnumBase {
...
@@ -136,33 +108,21 @@ public class ValueEnum extends ValueEnumBase {
return
result
;
return
result
;
}
}
private
static
Validation
validate
(
final
String
[]
enumerators
,
final
String
label
)
{
check
(
enumerators
);
final
String
cleanLabel
=
label
.
trim
().
toLowerCase
();
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
if
(
cleanLabel
.
equals
(
enumerators
[
i
]))
{
return
Validation
.
VALID
;
}
}
return
Validation
.
INVALID
;
}
private
static
Validation
validate
(
final
String
[]
enumerators
)
{
private
static
Validation
validate
(
final
String
[]
enumerators
)
{
if
(
enumerators
==
null
||
enumerators
.
length
==
0
)
{
final
String
[]
cleaned
=
sanitize
(
enumerators
);
if
(
cleaned
==
null
||
cleaned
.
length
==
0
)
{
return
Validation
.
EMPTY
;
return
Validation
.
EMPTY
;
}
}
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
cleaned
.
length
;
i
++)
{
if
(
enumerators
[
i
]
==
null
||
enumerators
[
i
].
trim
()
.
equals
(
""
))
{
if
(
cleaned
[
i
]
==
null
||
cleaned
[
i
]
.
equals
(
""
))
{
return
Validation
.
EMPTY
;
return
Validation
.
EMPTY
;
}
}
if
(
i
<
enumerators
.
length
-
1
)
{
if
(
i
<
cleaned
.
length
-
1
)
{
for
(
int
j
=
i
+
1
;
j
<
enumerators
.
length
;
j
++)
{
for
(
int
j
=
i
+
1
;
j
<
cleaned
.
length
;
j
++)
{
if
(
enumerators
[
i
].
equals
(
enumerators
[
j
]))
{
if
(
cleaned
[
i
].
equals
(
cleaned
[
j
]))
{
return
Validation
.
DUPLICATE
;
return
Validation
.
DUPLICATE
;
}
}
}
}
...
@@ -172,21 +132,30 @@ public class ValueEnum extends ValueEnumBase {
...
@@ -172,21 +132,30 @@ public class ValueEnum extends ValueEnumBase {
return
Validation
.
VALID
;
return
Validation
.
VALID
;
}
}
private
static
Validation
validate
(
final
String
[]
enumerators
,
final
int
ordinal
)
{
private
static
Validation
validate
(
final
String
[]
enumerators
,
final
Value
value
)
{
check
(
enumerators
);
final
Validation
validation
=
validate
(
enumerators
);
if
(!
validation
.
equals
(
Validation
.
VALID
))
{
if
(
ordinal
<
0
||
ordinal
>=
enumerators
.
length
)
{
return
validation
;
return
Validation
.
INVALID
;
}
}
return
Validation
.
VALID
;
}
private
static
Validation
validate
(
final
String
[]
enumerators
,
final
Value
value
)
{
if
(
DataType
.
isStringType
(
value
.
getType
()))
{
if
(
DataType
.
isStringType
(
value
.
getType
()))
{
return
validate
(
enumerators
,
value
.
getString
());
final
String
cleanLabel
=
sanitize
(
value
.
getString
());
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
if
(
cleanLabel
.
equals
(
sanitize
(
enumerators
[
i
])))
{
return
Validation
.
VALID
;
}
}
return
Validation
.
INVALID
;
}
else
{
}
else
{
return
validate
(
enumerators
,
value
.
getInt
());
final
int
ordinal
=
value
.
getInt
();
if
(
ordinal
<
0
||
ordinal
>=
enumerators
.
length
)
{
return
Validation
.
INVALID
;
}
return
Validation
.
VALID
;
}
}
}
}
}
}
h2/src/main/org/h2/value/ValueEnumBase.java
浏览文件 @
e8d00a2c
...
@@ -2,6 +2,7 @@ package org.h2.value;
...
@@ -2,6 +2,7 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Locale
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
...
@@ -38,8 +39,7 @@ public class ValueEnumBase extends Value {
...
@@ -38,8 +39,7 @@ public class ValueEnumBase extends Value {
@Override
@Override
public
boolean
equals
(
final
Object
other
)
{
public
boolean
equals
(
final
Object
other
)
{
return
other
instanceof
ValueEnumBase
&&
return
other
instanceof
ValueEnumBase
&&
ordinal
()
==
((
ValueEnumBase
)
other
).
ordinal
()
&&
ordinal
()
==
((
ValueEnumBase
)
other
).
ordinal
();
getString
()
==
((
ValueEnumBase
)
other
).
getString
();
}
}
public
static
ValueEnumBase
get
(
final
String
label
,
final
int
ordinal
)
{
public
static
ValueEnumBase
get
(
final
String
label
,
final
int
ordinal
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论