Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8b2aeaa4
提交
8b2aeaa4
authored
9月 05, 2018
作者:
tledkov-gridgain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#1405 Introduce LocalResult factory: simple refactoring
上级
12ec6d9d
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
826 行增加
和
563 行删除
+826
-563
Call.java
h2/src/main/org/h2/command/dml/Call.java
+5
-4
Explain.java
h2/src/main/org/h2/command/dml/Explain.java
+2
-1
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+2
-1
Select.java
h2/src/main/org/h2/command/dml/Select.java
+4
-3
SelectUnion.java
h2/src/main/org/h2/command/dml/SelectUnion.java
+5
-4
Set.java
h2/src/main/org/h2/command/dml/Set.java
+14
-0
SetTypes.java
h2/src/main/org/h2/command/dml/SetTypes.java
+7
-1
Database.java
h2/src/main/org/h2/engine/Database.java
+11
-0
GeneratedKeys.java
h2/src/main/org/h2/engine/GeneratedKeys.java
+7
-6
TableFunction.java
h2/src/main/org/h2/expression/TableFunction.java
+2
-1
LocalResult.java
h2/src/main/org/h2/result/LocalResult.java
+15
-541
LocalResultFactory.java
h2/src/main/org/h2/result/LocalResultFactory.java
+107
-0
LocalResultImpl.java
h2/src/main/org/h2/result/LocalResultImpl.java
+575
-0
FunctionTable.java
h2/src/main/org/h2/table/FunctionTable.java
+2
-1
TestLocalResultFactory.java
h2/src/test/org/h2/test/db/TestLocalResultFactory.java
+68
-0
没有找到文件。
h2/src/main/org/h2/command/dml/Call.java
浏览文件 @
8b2aeaa4
...
...
@@ -12,6 +12,7 @@ import org.h2.engine.Session;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.ResultInterface
;
import
org.h2.value.Value
;
...
...
@@ -34,9 +35,9 @@ public class Call extends Prepared {
LocalResult
result
;
if
(
isResultSet
)
{
Expression
[]
expr
=
expression
.
getExpressionColumns
(
session
);
result
=
new
LocalResult
(
session
,
expr
,
expr
.
length
);
result
=
LocalResultFactory
.
createRow
(
session
,
expr
,
expr
.
length
);
}
else
{
result
=
new
LocalResult
(
session
,
expressions
,
1
);
result
=
LocalResultFactory
.
createRow
(
session
,
expressions
,
1
);
}
result
.
done
();
return
result
;
...
...
@@ -66,9 +67,9 @@ public class Call extends Prepared {
if
(
isResultSet
)
{
v
=
v
.
convertTo
(
Value
.
RESULT_SET
);
ResultSet
rs
=
v
.
getResultSet
();
return
LocalResult
.
read
(
session
,
rs
,
maxrows
);
return
LocalResult
Factory
.
read
(
session
,
rs
,
maxrows
);
}
LocalResult
result
=
new
LocalResult
(
session
,
expressions
,
1
);
LocalResult
result
=
LocalResultFactory
.
createRow
(
session
,
expressions
,
1
);
Value
[]
row
=
{
v
};
result
.
addRow
(
row
);
result
.
done
();
...
...
h2/src/main/org/h2/command/dml/Explain.java
浏览文件 @
8b2aeaa4
...
...
@@ -16,6 +16,7 @@ import org.h2.expression.Expression;
import
org.h2.expression.ExpressionColumn
;
import
org.h2.mvstore.db.MVTableEngine.Store
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.ResultInterface
;
import
org.h2.store.PageStore
;
import
org.h2.table.Column
;
...
...
@@ -72,7 +73,7 @@ public class Explain extends Prepared {
Database
db
=
session
.
getDatabase
();
ExpressionColumn
expr
=
new
ExpressionColumn
(
db
,
column
);
Expression
[]
expressions
=
{
expr
};
result
=
new
LocalResult
(
session
,
expressions
,
1
);
result
=
LocalResultFactory
.
createRow
(
session
,
expressions
,
1
);
if
(
maxrows
>=
0
)
{
String
plan
;
if
(
executeCommand
)
{
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
8b2aeaa4
...
...
@@ -43,6 +43,7 @@ import org.h2.index.Cursor;
import
org.h2.index.Index
;
import
org.h2.message.DbException
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.schema.Constant
;
...
...
@@ -137,7 +138,7 @@ public class ScriptCommand extends ScriptBase {
private
LocalResult
createResult
()
{
Expression
[]
expressions
=
{
new
ExpressionColumn
(
session
.
getDatabase
(),
new
Column
(
"SCRIPT"
,
Value
.
STRING
))
};
return
new
LocalResult
(
session
,
expressions
,
1
);
return
LocalResultFactory
.
createRow
(
session
,
expressions
,
1
);
}
@Override
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
8b2aeaa4
...
...
@@ -32,6 +32,7 @@ import org.h2.index.IndexType;
import
org.h2.message.DbException
;
import
org.h2.result.LazyResult
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultTarget
;
import
org.h2.result.Row
;
...
...
@@ -687,7 +688,7 @@ public class Select extends Query {
@Override
public
ResultInterface
queryMeta
()
{
LocalResult
result
=
new
LocalResult
(
session
,
expressionArray
,
LocalResult
result
=
LocalResultFactory
.
createRow
(
session
,
expressionArray
,
visibleColumnCount
);
result
.
done
();
return
result
;
...
...
@@ -858,12 +859,12 @@ public class Select extends Query {
}
private
LocalResult
createLocalResult
(
LocalResult
old
)
{
return
old
!=
null
?
old
:
new
LocalResult
(
session
,
expressionArray
,
return
old
!=
null
?
old
:
LocalResultFactory
.
createRow
(
session
,
expressionArray
,
visibleColumnCount
);
}
private
LocalResult
convertToDistinct
(
ResultInterface
result
)
{
LocalResult
distinctResult
=
new
LocalResult
(
session
,
expressionArray
,
visibleColumnCount
);
LocalResult
distinctResult
=
LocalResultFactory
.
createRow
(
session
,
expressionArray
,
visibleColumnCount
);
distinctResult
.
setDistinct
();
result
.
reset
();
while
(
result
.
next
())
{
...
...
h2/src/main/org/h2/command/dml/SelectUnion.java
浏览文件 @
8b2aeaa4
...
...
@@ -20,6 +20,7 @@ import org.h2.expression.ValueExpression;
import
org.h2.message.DbException
;
import
org.h2.result.LazyResult
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultTarget
;
import
org.h2.table.Column
;
...
...
@@ -130,14 +131,14 @@ public class SelectUnion extends Query {
@Override
public
ResultInterface
queryMeta
()
{
int
columnCount
=
left
.
getColumnCount
();
LocalResult
result
=
new
LocalResult
(
session
,
expressionArray
,
columnCount
);
LocalResult
result
=
LocalResultFactory
.
createRow
(
session
,
expressionArray
,
columnCount
);
result
.
done
();
return
result
;
}
public
LocalResult
getEmptyResult
()
{
int
columnCount
=
left
.
getColumnCount
();
return
new
LocalResult
(
session
,
expressionArray
,
columnCount
);
return
LocalResultFactory
.
createRow
(
session
,
expressionArray
,
columnCount
);
}
@Override
...
...
@@ -189,7 +190,7 @@ public class SelectUnion extends Query {
return
lazyResult
;
}
}
LocalResult
result
=
new
LocalResult
(
session
,
expressionArray
,
columnCount
);
LocalResult
result
=
LocalResultFactory
.
createRow
(
session
,
expressionArray
,
columnCount
);
if
(
sort
!=
null
)
{
result
.
setSortOrder
(
sort
);
}
...
...
@@ -239,7 +240,7 @@ public class SelectUnion extends Query {
break
;
}
case
INTERSECT:
{
LocalResult
temp
=
new
LocalResult
(
session
,
expressionArray
,
columnCount
);
LocalResult
temp
=
LocalResultFactory
.
createRow
(
session
,
expressionArray
,
columnCount
);
temp
.
setDistinct
();
while
(
l
.
next
())
{
temp
.
addRow
(
convert
(
l
.
currentRow
(),
columnCount
));
...
...
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
8b2aeaa4
...
...
@@ -19,6 +19,7 @@ import org.h2.expression.Expression;
import
org.h2.expression.ValueExpression
;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.RowFactory
;
import
org.h2.schema.Schema
;
...
...
@@ -558,6 +559,19 @@ public class Set extends Prepared {
}
break
;
}
case
SetTypes
.
LOCAL_RESULT_FACTORY
:
{
session
.
getUser
().
checkAdmin
();
String
localResultFactoryName
=
expression
.
getColumnName
();
Class
<
LocalResultFactory
>
localResultFactoryClass
=
JdbcUtils
.
loadUserClass
(
localResultFactoryName
);
LocalResultFactory
localResultFactory
;
try
{
localResultFactory
=
localResultFactoryClass
.
getDeclaredConstructor
().
newInstance
();
database
.
setLocalResultFactory
(
localResultFactory
);
}
catch
(
Exception
e
)
{
throw
DbException
.
convert
(
e
);
}
break
;
}
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
}
...
...
h2/src/main/org/h2/command/dml/SetTypes.java
浏览文件 @
8b2aeaa4
...
...
@@ -252,7 +252,12 @@ public class SetTypes {
*/
public
static
final
int
AUTHENTICATOR
=
48
;
private
static
final
int
COUNT
=
AUTHENTICATOR
+
1
;
/**
* The type of a SET LOCAL_RESULT_FACTORY statement.
*/
public
static
final
int
LOCAL_RESULT_FACTORY
=
49
;
private
static
final
int
COUNT
=
LOCAL_RESULT_FACTORY
+
1
;
private
static
final
ArrayList
<
String
>
TYPES
;
...
...
@@ -311,6 +316,7 @@ public class SetTypes {
list
.
add
(
BUILTIN_ALIAS_OVERRIDE
,
"BUILTIN_ALIAS_OVERRIDE"
);
list
.
add
(
COLUMN_NAME_RULES
,
"COLUMN_NAME_RULES"
);
list
.
add
(
AUTHENTICATOR
,
"AUTHENTICATOR"
);
list
.
add
(
LOCAL_RESULT_FACTORY
,
"LOCAL_RESULT_FACTORY"
);
TYPES
=
list
;
}
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
8b2aeaa4
...
...
@@ -41,6 +41,8 @@ import org.h2.message.Trace;
import
org.h2.message.TraceSystem
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.db.MVTableEngine
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.Row
;
import
org.h2.result.RowFactory
;
import
org.h2.result.SearchRow
;
...
...
@@ -230,6 +232,7 @@ public class Database implements DataHandler {
private
int
queryStatisticsMaxEntries
=
Constants
.
QUERY_STATISTICS_MAX_ENTRIES
;
private
QueryStatisticsData
queryStatisticsData
;
private
RowFactory
rowFactory
=
RowFactory
.
DEFAULT
;
private
LocalResultFactory
resultFactory
=
LocalResultFactory
.
DEFAULT
;
private
Authenticator
authenticator
;
...
...
@@ -369,6 +372,14 @@ public class Database implements DataHandler {
this
.
rowFactory
=
rowFactory
;
}
public
LocalResultFactory
getLocalResultFactory
()
{
return
resultFactory
;
}
public
void
setLocalResultFactory
(
LocalResultFactory
resultFactory
)
{
this
.
resultFactory
=
resultFactory
;
}
public
static
void
setInitialPowerOffCount
(
int
count
)
{
initialPowerOffCount
=
count
;
}
...
...
h2/src/main/org/h2/engine/GeneratedKeys.java
浏览文件 @
8b2aeaa4
...
...
@@ -13,6 +13,7 @@ import java.util.Map;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionColumn
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.Row
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
...
...
@@ -128,7 +129,7 @@ public final class GeneratedKeys {
Database
db
=
session
==
null
?
null
:
session
.
getDatabase
();
if
(
Boolean
.
FALSE
.
equals
(
generatedKeysRequest
))
{
clear
(
null
);
return
new
LocalResult
(
);
return
LocalResultFactory
.
createRow
(
session
);
}
ArrayList
<
ExpressionColumn
>
expressionColumns
;
if
(
Boolean
.
TRUE
.
equals
(
generatedKeysRequest
))
{
...
...
@@ -152,7 +153,7 @@ public final class GeneratedKeys {
}
}
else
{
clear
(
null
);
return
new
LocalResult
(
);
return
LocalResultFactory
.
createRow
(
session
);
}
}
else
if
(
generatedKeysRequest
instanceof
String
[])
{
if
(
table
!=
null
)
{
...
...
@@ -182,18 +183,18 @@ public final class GeneratedKeys {
}
}
else
{
clear
(
null
);
return
new
LocalResult
(
);
return
LocalResultFactory
.
createRow
(
session
);
}
}
else
{
clear
(
null
);
return
new
LocalResult
(
);
return
LocalResultFactory
.
createRow
(
session
);
}
int
columnCount
=
expressionColumns
.
size
();
if
(
columnCount
==
0
)
{
clear
(
null
);
return
new
LocalResult
(
);
return
LocalResultFactory
.
createRow
(
session
);
}
LocalResult
result
=
new
LocalResult
(
session
,
expressionColumns
.
toArray
(
new
Expression
[
0
]),
columnCount
);
LocalResult
result
=
LocalResultFactory
.
createRow
(
session
,
expressionColumns
.
toArray
(
new
Expression
[
0
]),
columnCount
);
for
(
Map
<
Column
,
Value
>
map
:
data
)
{
Value
[]
row
=
new
Value
[
columnCount
];
for
(
Map
.
Entry
<
Column
,
Value
>
entry
:
map
.
entrySet
())
{
...
...
h2/src/main/org/h2/expression/TableFunction.java
浏览文件 @
8b2aeaa4
...
...
@@ -12,6 +12,7 @@ import org.h2.engine.Database;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.table.Column
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.MathUtils
;
...
...
@@ -86,7 +87,7 @@ public class TableFunction extends Function {
ExpressionColumn
col
=
new
ExpressionColumn
(
db
,
c
);
header
[
i
]
=
col
;
}
LocalResult
result
=
new
LocalResult
(
session
,
header
,
len
);
LocalResult
result
=
LocalResultFactory
.
createRow
(
session
,
header
,
len
);
if
(
distinctRows
)
{
result
.
setDistinct
();
}
...
...
h2/src/main/org/h2/result/LocalResult.java
浏览文件 @
8b2aeaa4
差异被折叠。
点击展开。
h2/src/main/org/h2/result/LocalResultFactory.java
0 → 100644
浏览文件 @
8b2aeaa4
/*
* 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
.
result
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
/**
* Creates local result.
*/
public
abstract
class
LocalResultFactory
{
/**
* Default implementation of local result factory.
*/
public
static
final
LocalResultFactory
DEFAULT
=
new
DefaultLocalResultFactory
();
/**
* Create a local result object.
*
* @param session the session
* @param expressions the expression array
* @param visibleColumnCount the number of visible columns
* @return object to collect local result.
*/
public
abstract
LocalResult
create
(
Session
session
,
Expression
[]
expressions
,
int
visibleColumnCount
);
/**
* Create a local result object.
* @return object to collect local result.
*/
public
abstract
LocalResult
create
();
/**
* Default implementation of local result factory.
*/
static
final
class
DefaultLocalResultFactory
extends
LocalResultFactory
{
@Override
public
LocalResult
create
(
Session
session
,
Expression
[]
expressions
,
int
visibleColumnCount
)
{
return
new
LocalResultImpl
(
session
,
expressions
,
visibleColumnCount
);
}
@Override
public
LocalResult
create
()
{
return
new
LocalResultImpl
();
}
}
/**
* Create a local result object by factory registered at the database.
*
* @param session the session
* @param expressions the expression array
* @param visibleColumnCount the number of visible columns
* @return objetc to collect local result.
*/
public
static
LocalResult
createRow
(
Session
session
,
Expression
[]
expressions
,
int
visibleColumnCount
)
{
return
session
.
getDatabase
().
getLocalResultFactory
().
create
(
session
,
expressions
,
visibleColumnCount
);
}
/**
* Create a local result object by factory registered at the database.
*
* @param session the session
* @return objetc to collect local result.
*/
public
static
LocalResult
createRow
(
Session
session
)
{
return
session
.
getDatabase
().
getLocalResultFactory
().
create
();
}
/**
* Construct a local result set by reading all data from a regular result
* set.
*
* @param session the session
* @param rs the result set
* @param maxrows the maximum number of rows to read (0 for no limit)
* @return the local result set
*/
public
static
LocalResult
read
(
Session
session
,
ResultSet
rs
,
int
maxrows
)
{
Expression
[]
cols
=
Expression
.
getExpressionColumns
(
session
,
rs
);
int
columnCount
=
cols
.
length
;
LocalResult
result
=
session
.
getDatabase
().
getLocalResultFactory
().
create
(
session
,
cols
,
columnCount
);
try
{
for
(
int
i
=
0
;
(
maxrows
==
0
||
i
<
maxrows
)
&&
rs
.
next
();
i
++)
{
Value
[]
list
=
new
Value
[
columnCount
];
for
(
int
j
=
0
;
j
<
columnCount
;
j
++)
{
int
type
=
result
.
getColumnType
(
j
);
list
[
j
]
=
DataType
.
readValue
(
session
,
rs
,
j
+
1
,
type
);
}
result
.
addRow
(
list
);
}
}
catch
(
SQLException
e
)
{
throw
DbException
.
convert
(
e
);
}
result
.
done
();
return
result
;
}
}
h2/src/main/org/h2/result/LocalResultImpl.java
0 → 100644
浏览文件 @
8b2aeaa4
差异被折叠。
点击展开。
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
8b2aeaa4
...
...
@@ -19,6 +19,7 @@ import org.h2.index.Index;
import
org.h2.index.IndexType
;
import
org.h2.message.DbException
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
...
...
@@ -194,7 +195,7 @@ public class FunctionTable extends Table {
cachedResult
.
reset
();
return
cachedResult
;
}
LocalResult
result
=
LocalResult
.
read
(
session
,
v
.
getResultSet
(),
0
);
LocalResult
result
=
LocalResult
Factory
.
read
(
session
,
v
.
getResultSet
(),
0
);
if
(
function
.
isDeterministic
())
{
cachedResult
=
result
;
cachedValue
=
v
;
...
...
h2/src/test/org/h2/test/db/TestLocalResultFactory.java
0 → 100644
浏览文件 @
8b2aeaa4
/*
* 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
.
test
.
db
;
import
java.sql.Connection
;
import
java.sql.Statement
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResultFactory
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestDb
;
/**
* Test {@link LocalResultFactory} setting.
*/
public
class
TestLocalResultFactory
extends
TestDb
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
Exception
{
deleteDb
(
"localResultFactory"
);
Connection
conn
=
getConnection
(
"localResultFactory;LOCAL_RESULT_FACTORY=\""
+
MyTestLocalResultFactory
.
class
.
getName
()
+
'"'
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table t1(id int, name varchar)"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
stat
.
execute
(
"insert into t1 values("
+
i
+
", 'name')"
);
}
assertEquals
(
MyTestLocalResultFactory
.
COUNTER
.
get
(),
0
);
stat
.
execute
(
"select * from t1"
);
assertEquals
(
MyTestLocalResultFactory
.
COUNTER
.
get
(),
1
);
conn
.
close
();
deleteDb
(
"localResultFactory"
);
}
/**
* Test local result factory.
*/
public
static
class
MyTestLocalResultFactory
extends
LocalResultFactory
{
static
final
AtomicInteger
COUNTER
=
new
AtomicInteger
();
@Override
public
LocalResult
create
(
Session
session
,
Expression
[]
expressions
,
int
visibleColumnCount
)
{
COUNTER
.
incrementAndGet
();
return
LocalResultFactory
.
DEFAULT
.
create
(
session
,
expressions
,
visibleColumnCount
);
}
@Override
public
LocalResult
create
()
{
COUNTER
.
incrementAndGet
();
return
LocalResultFactory
.
DEFAULT
.
create
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论