Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8644cb48
提交
8644cb48
authored
7 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use shared SimpleColumnInfo in SimpleResultSet and MergedResultSet
上级
8aced489
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
96 行增加
和
107 行删除
+96
-107
SimpleResultSet.java
h2/src/main/org/h2/tools/SimpleResultSet.java
+7
-43
MergedResultSet.java
h2/src/main/org/h2/util/MergedResultSet.java
+9
-64
SimpleColumnInfo.java
h2/src/main/org/h2/util/SimpleColumnInfo.java
+80
-0
没有找到文件。
h2/src/main/org/h2/tools/SimpleResultSet.java
浏览文件 @
8644cb48
...
...
@@ -38,6 +38,7 @@ import org.h2.util.Bits;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.SimpleColumnInfo
;
import
org.h2.util.Utils
;
import
org.h2.value.DataType
;
...
...
@@ -67,7 +68,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
private
int
rowId
=
-
1
;
private
boolean
wasNull
;
private
SimpleRowSource
source
;
private
ArrayList
<
Column
>
columns
=
New
.
arrayList
();
private
ArrayList
<
SimpleColumnInfo
>
columns
=
New
.
arrayList
();
private
boolean
autoClose
=
true
;
/**
...
...
@@ -123,13 +124,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
if
(
name
==
null
)
{
name
=
"C"
+
(
columns
.
size
()
+
1
);
}
Column
column
=
new
Column
();
column
.
name
=
name
;
column
.
sqlType
=
sqlType
;
column
.
precision
=
precision
;
column
.
scale
=
scale
;
column
.
sqlTypeName
=
sqlTypeName
;
columns
.
add
(
column
);
columns
.
add
(
new
SimpleColumnInfo
(
name
,
sqlType
,
sqlTypeName
,
precision
,
scale
));
}
/**
...
...
@@ -1012,7 +1007,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
if
(
o
==
null
)
{
return
null
;
}
switch
(
columns
.
get
(
columnIndex
-
1
).
sqlT
ype
)
{
switch
(
columns
.
get
(
columnIndex
-
1
).
t
ype
)
{
case
Types
.
CLOB
:
Clob
c
=
(
Clob
)
o
;
return
c
.
getSubString
(
1
,
MathUtils
.
convertLongToInt
(
c
.
length
()));
...
...
@@ -1868,7 +1863,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
*/
@Override
public
int
getColumnType
(
int
columnIndex
)
throws
SQLException
{
return
getColumn
(
columnIndex
-
1
).
sqlT
ype
;
return
getColumn
(
columnIndex
-
1
).
t
ype
;
}
/**
...
...
@@ -2045,7 +2040,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
*/
@Override
public
String
getColumnTypeName
(
int
columnIndex
)
throws
SQLException
{
return
getColumn
(
columnIndex
-
1
).
sqlT
ypeName
;
return
getColumn
(
columnIndex
-
1
).
t
ypeName
;
}
/**
...
...
@@ -2295,7 +2290,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
return
o
;
}
private
Column
getColumn
(
int
i
)
throws
SQLException
{
private
SimpleColumnInfo
getColumn
(
int
i
)
throws
SQLException
{
checkColumnIndex
(
i
+
1
);
return
columns
.
get
(
i
);
}
...
...
@@ -2355,37 +2350,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
return
autoClose
;
}
/**
* This class holds the data of a result column.
*/
static
class
Column
{
/**
* The column label.
*/
String
name
;
/**
* The column type Name
*/
String
sqlTypeName
;
/**
* The SQL type.
*/
int
sqlType
;
/**
* The precision.
*/
int
precision
;
/**
* The scale.
*/
int
scale
;
}
/**
* A simple array implementation,
* backed by an object array
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/MergedResultSet.java
浏览文件 @
8644cb48
...
...
@@ -24,64 +24,9 @@ import org.h2.tools.SimpleResultSet;
* that have {@code NAME} column should also define it with the same type.
*/
public
final
class
MergedResultSet
{
/**
* Metadata of a column.
*/
private
static
final
class
ColumnInfo
{
final
String
name
;
final
int
type
;
final
String
typeName
;
final
int
precision
;
final
int
scale
;
/**
* Creates metadata.
*
* @param name
* name of the column
* @param type
* type of the column, see {@link java.sql.Types}
* @param typeName
* type name of the column
* @param precision
* precision of the column
* @param scale
* scale of the column
*/
ColumnInfo
(
String
name
,
int
type
,
String
typeName
,
int
precision
,
int
scale
)
{
this
.
name
=
name
;
this
.
type
=
type
;
this
.
typeName
=
typeName
;
this
.
precision
=
precision
;
this
.
scale
=
scale
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
||
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
ColumnInfo
other
=
(
ColumnInfo
)
obj
;
return
name
.
equals
(
other
.
name
);
}
@Override
public
int
hashCode
()
{
return
name
.
hashCode
();
}
}
private
final
ArrayList
<
Map
<
ColumnInfo
,
Object
>>
data
=
New
.
arrayList
();
private
final
ArrayList
<
Map
<
SimpleColumnInfo
,
Object
>>
data
=
New
.
arrayList
();
private
final
ArrayList
<
ColumnInfo
>
columns
=
New
.
arrayList
();
private
final
ArrayList
<
Simple
ColumnInfo
>
columns
=
New
.
arrayList
();
/**
* Appends a result set.
...
...
@@ -97,9 +42,9 @@ public final class MergedResultSet {
if
(
cols
==
0
)
{
return
;
}
ColumnInfo
[]
info
=
new
ColumnInfo
[
cols
];
SimpleColumnInfo
[]
info
=
new
Simple
ColumnInfo
[
cols
];
for
(
int
i
=
1
;
i
<=
cols
;
i
++)
{
ColumnInfo
ci
=
new
ColumnInfo
(
meta
.
getColumnName
(
i
),
meta
.
getColumnType
(
i
),
meta
.
getColumnTypeName
(
i
),
SimpleColumnInfo
ci
=
new
Simple
ColumnInfo
(
meta
.
getColumnName
(
i
),
meta
.
getColumnType
(
i
),
meta
.
getColumnTypeName
(
i
),
meta
.
getPrecision
(
i
),
meta
.
getScale
(
i
));
info
[
i
-
1
]
=
ci
;
if
(!
columns
.
contains
(
ci
))
{
...
...
@@ -110,9 +55,9 @@ public final class MergedResultSet {
if
(
cols
==
1
)
{
data
.
add
(
Collections
.
singletonMap
(
info
[
0
],
rs
.
getObject
(
1
)));
}
else
{
HashMap
<
ColumnInfo
,
Object
>
map
=
new
HashMap
<>();
HashMap
<
Simple
ColumnInfo
,
Object
>
map
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
cols
;
i
++)
{
ColumnInfo
ci
=
info
[
i
-
1
];
Simple
ColumnInfo
ci
=
info
[
i
-
1
];
map
.
put
(
ci
,
rs
.
getObject
(
i
));
}
data
.
add
(
map
);
...
...
@@ -127,12 +72,12 @@ public final class MergedResultSet {
*/
public
SimpleResultSet
getResult
()
{
SimpleResultSet
rs
=
new
SimpleResultSet
();
for
(
ColumnInfo
ci
:
columns
)
{
for
(
Simple
ColumnInfo
ci
:
columns
)
{
rs
.
addColumn
(
ci
.
name
,
ci
.
type
,
ci
.
typeName
,
ci
.
precision
,
ci
.
scale
);
}
for
(
Map
<
ColumnInfo
,
Object
>
map
:
data
)
{
for
(
Map
<
Simple
ColumnInfo
,
Object
>
map
:
data
)
{
Object
[]
row
=
new
Object
[
columns
.
size
()];
for
(
Map
.
Entry
<
ColumnInfo
,
Object
>
entry
:
map
.
entrySet
())
{
for
(
Map
.
Entry
<
Simple
ColumnInfo
,
Object
>
entry
:
map
.
entrySet
())
{
row
[
columns
.
indexOf
(
entry
.
getKey
())]
=
entry
.
getValue
();
}
rs
.
addRow
(
row
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/SimpleColumnInfo.java
0 → 100644
浏览文件 @
8644cb48
/*
* 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
.
util
;
/**
* Metadata of a column.
*
* <p>
* Notice: {@linkplain #equals(Object)} and {@linkplain #hashCode()} use only
* {@linkplain #name} field.
* </p>
*/
public
final
class
SimpleColumnInfo
{
/**
* Name of the column.
*/
public
final
String
name
;
/**
* Type of the column, see {@link java.sql.Types}.
*/
public
final
int
type
;
/**
* Type name of the column.
*/
public
final
String
typeName
;
/**
* Precision of the column
*/
public
final
int
precision
;
/**
* Scale of the column.
*/
public
final
int
scale
;
/**
* Creates metadata.
*
* @param name
* name of the column
* @param type
* type of the column, see {@link java.sql.Types}
* @param typeName
* type name of the column
* @param precision
* precision of the column
* @param scale
* scale of the column
*/
public
SimpleColumnInfo
(
String
name
,
int
type
,
String
typeName
,
int
precision
,
int
scale
)
{
this
.
name
=
name
;
this
.
type
=
type
;
this
.
typeName
=
typeName
;
this
.
precision
=
precision
;
this
.
scale
=
scale
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
||
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
SimpleColumnInfo
other
=
(
SimpleColumnInfo
)
obj
;
return
name
.
equals
(
other
.
name
);
}
@Override
public
int
hashCode
()
{
return
name
.
hashCode
();
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论