Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2c903f83
提交
2c903f83
authored
3月 29, 2017
作者:
Max Englander
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enum-support: in Transfer, use base ValueEnumBase when reading
上级
cf06d6ec
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
138 行增加
和
120 行删除
+138
-120
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+5
-17
ValueEnum.java
h2/src/main/org/h2/value/ValueEnum.java
+3
-103
ValueEnumBase.java
h2/src/main/org/h2/value/ValueEnumBase.java
+130
-0
没有找到文件。
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
2c903f83
...
@@ -495,17 +495,8 @@ public class Transfer {
...
@@ -495,17 +495,8 @@ public class Transfer {
break
;
break
;
}
}
case
Value
.
ENUM
:
{
case
Value
.
ENUM
:
{
ValueEnum
ve
=
(
ValueEnum
)
v
;
writeInt
(
v
.
getInt
());
String
[]
enumerators
=
ve
.
getEnumerators
();
writeString
(
v
.
getString
());
writeInt
(
enumerators
.
length
);
for
(
String
member
:
enumerators
)
{
writeString
(
member
);
}
writeInt
(
ve
.
getInt
());
break
;
break
;
}
}
case
Value
.
RESULT_SET
:
{
case
Value
.
RESULT_SET
:
{
...
@@ -609,12 +600,9 @@ public class Transfer {
...
@@ -609,12 +600,9 @@ public class Transfer {
case
Value
.
FLOAT
:
case
Value
.
FLOAT
:
return
ValueFloat
.
get
(
readFloat
());
return
ValueFloat
.
get
(
readFloat
());
case
Value
.
ENUM
:
{
case
Value
.
ENUM
:
{
int
len
=
readInt
();
final
int
ordinal
=
readInt
();
String
[]
enumerators
=
new
String
[
len
];
final
String
label
=
readString
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
return
ValueEnumBase
.
get
(
label
,
ordinal
);
enumerators
[
i
]
=
readString
();
}
return
ValueEnum
.
get
(
enumerators
,
readInt
());
}
}
case
Value
.
INT
:
case
Value
.
INT
:
return
ValueInt
.
get
(
readInt
());
return
ValueInt
.
get
(
readInt
());
...
...
h2/src/main/org/h2/value/ValueEnum.java
浏览文件 @
2c903f83
package
org
.
h2
.
value
;
package
org
.
h2
.
value
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
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
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
public
class
ValueEnum
extends
Value
{
public
class
ValueEnum
extends
ValueEnumBase
{
public
static
final
int
PRECISION
=
10
;
public
static
final
int
DISPLAY_SIZE
=
11
;
private
static
enum
Validation
{
private
static
enum
Validation
{
DUPLICATE
,
DUPLICATE
,
EMPTY
,
EMPTY
,
...
@@ -20,19 +14,10 @@ public class ValueEnum extends Value {
...
@@ -20,19 +14,10 @@ public class ValueEnum extends Value {
}
}
private
final
String
[]
enumerators
;
private
final
String
[]
enumerators
;
private
final
String
label
;
private
final
int
ordinal
;
private
ValueEnum
(
final
String
[]
enumerators
,
final
int
ordinal
)
{
private
ValueEnum
(
final
String
[]
enumerators
,
final
int
ordinal
)
{
this
.
label
=
enumerators
[
ordinal
]
;
super
(
enumerators
[
ordinal
],
ordinal
)
;
this
.
enumerators
=
enumerators
;
this
.
enumerators
=
enumerators
;
this
.
ordinal
=
ordinal
;
}
@Override
public
Value
add
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
add
(
iv
);
}
}
public
static
final
void
check
(
final
String
[]
enumerators
)
{
public
static
final
void
check
(
final
String
[]
enumerators
)
{
...
@@ -92,18 +77,6 @@ public class ValueEnum extends Value {
...
@@ -92,18 +77,6 @@ public class ValueEnum extends Value {
return
MathUtils
.
compareInt
(
ordinal
(),
ev
.
ordinal
());
return
MathUtils
.
compareInt
(
ordinal
(),
ev
.
ordinal
());
}
}
@Override
public
Value
divide
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
divide
(
iv
);
}
@Override
public
boolean
equals
(
final
Object
other
)
{
return
other
instanceof
ValueEnum
&&
ordinal
()
==
((
ValueEnum
)
other
).
ordinal
();
}
public
static
ValueEnum
get
(
final
String
[]
enumerators
,
final
String
label
)
{
public
static
ValueEnum
get
(
final
String
[]
enumerators
,
final
String
label
)
{
check
(
enumerators
,
label
);
check
(
enumerators
,
label
);
...
@@ -130,58 +103,13 @@ public class ValueEnum extends Value {
...
@@ -130,58 +103,13 @@ public class ValueEnum extends Value {
}
}
}
}
@Override
public
int
getDisplaySize
()
{
return
DISPLAY_SIZE
;
}
public
String
[]
getEnumerators
()
{
public
String
[]
getEnumerators
()
{
return
enumerators
;
return
enumerators
;
}
}
@Override
public
int
getInt
()
{
return
ordinal
;
}
@Override
public
long
getLong
()
{
return
ordinal
;
}
@Override
public
Object
getObject
()
{
return
ordinal
;
}
@Override
public
long
getPrecision
()
{
return
PRECISION
;
}
@Override
public
int
getSignum
()
{
return
Integer
.
signum
(
ordinal
);
}
@Override
public
String
getSQL
()
{
return
getString
();
}
@Override
public
String
getString
()
{
return
label
;
}
@Override
public
int
getType
()
{
return
Value
.
ENUM
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
enumerators
.
hashCode
()
+
ordinal
;
return
enumerators
.
hashCode
()
+
ordinal
()
;
}
}
public
static
boolean
isValid
(
final
String
enumerators
[],
final
String
label
)
{
public
static
boolean
isValid
(
final
String
enumerators
[],
final
String
label
)
{
...
@@ -196,34 +124,6 @@ public class ValueEnum extends Value {
...
@@ -196,34 +124,6 @@ public class ValueEnum extends Value {
return
validate
(
enumerators
,
value
).
equals
(
Validation
.
VALID
);
return
validate
(
enumerators
,
value
).
equals
(
Validation
.
VALID
);
}
}
protected
int
ordinal
()
{
return
ordinal
;
}
@Override
public
Value
modulus
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
modulus
(
iv
);
}
@Override
public
Value
multiply
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
multiply
(
iv
);
}
@Override
public
void
set
(
final
PreparedStatement
prep
,
final
int
parameterIndex
)
throws
SQLException
{
prep
.
setInt
(
parameterIndex
,
ordinal
);
}
@Override
public
Value
subtract
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
subtract
(
iv
);
}
private
static
String
toString
(
final
String
[]
enumerators
)
{
private
static
String
toString
(
final
String
[]
enumerators
)
{
String
result
=
"("
;
String
result
=
"("
;
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
...
...
h2/src/main/org/h2/value/ValueEnumBase.java
0 → 100644
浏览文件 @
2c903f83
package
org
.
h2
.
value
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.message.DbException
;
import
org.h2.util.MathUtils
;
public
class
ValueEnumBase
extends
Value
{
public
static
final
int
PRECISION
=
10
;
public
static
final
int
DISPLAY_SIZE
=
11
;
private
final
String
label
;
private
final
int
ordinal
;
protected
ValueEnumBase
(
final
String
label
,
final
int
ordinal
)
{
this
.
label
=
label
;
this
.
ordinal
=
ordinal
;
}
@Override
public
Value
add
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
add
(
iv
);
}
@Override
protected
int
compareSecure
(
final
Value
v
,
final
CompareMode
mode
)
{
return
MathUtils
.
compareInt
(
ordinal
(),
v
.
getInt
());
}
@Override
public
Value
divide
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
divide
(
iv
);
}
@Override
public
boolean
equals
(
final
Object
other
)
{
return
other
instanceof
ValueEnumBase
&&
ordinal
()
==
((
ValueEnumBase
)
other
).
ordinal
()
&&
getString
()
==
((
ValueEnumBase
)
other
).
getString
();
}
public
static
ValueEnumBase
get
(
final
String
label
,
final
int
ordinal
)
{
return
new
ValueEnumBase
(
label
,
ordinal
);
}
@Override
public
int
getDisplaySize
()
{
return
DISPLAY_SIZE
;
}
@Override
public
int
getInt
()
{
return
ordinal
;
}
@Override
public
long
getLong
()
{
return
ordinal
;
}
@Override
public
Object
getObject
()
{
return
ordinal
;
}
@Override
public
long
getPrecision
()
{
return
PRECISION
;
}
@Override
public
int
getSignum
()
{
return
Integer
.
signum
(
ordinal
);
}
@Override
public
String
getSQL
()
{
return
getString
();
}
@Override
public
String
getString
()
{
return
label
;
}
@Override
public
int
getType
()
{
return
Value
.
ENUM
;
}
@Override
public
int
hashCode
()
{
int
results
=
31
;
results
+=
getString
().
hashCode
();
results
+=
ordinal
();
return
results
;
}
@Override
public
Value
modulus
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
modulus
(
iv
);
}
@Override
public
Value
multiply
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
multiply
(
iv
);
}
protected
int
ordinal
()
{
return
ordinal
;
}
@Override
public
void
set
(
final
PreparedStatement
prep
,
final
int
parameterIndex
)
throws
SQLException
{
prep
.
setInt
(
parameterIndex
,
ordinal
);
}
@Override
public
Value
subtract
(
final
Value
v
)
{
final
Value
iv
=
v
.
convertTo
(
Value
.
INT
);
return
convertTo
(
Value
.
INT
).
subtract
(
iv
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论