Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6b39b12a
提交
6b39b12a
authored
2月 24, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle first and last arguments of FunctionIndex.find()
上级
47e92b90
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
131 行增加
和
62 行删除
+131
-62
AbstractFunctionCursor.java
h2/src/main/org/h2/index/AbstractFunctionCursor.java
+91
-0
FunctionCursor.java
h2/src/main/org/h2/index/FunctionCursor.java
+4
-31
FunctionCursorResultSet.java
h2/src/main/org/h2/index/FunctionCursorResultSet.java
+4
-29
FunctionIndex.java
h2/src/main/org/h2/index/FunctionIndex.java
+2
-2
TestIndex.java
h2/src/test/org/h2/test/db/TestIndex.java
+30
-0
没有找到文件。
h2/src/main/org/h2/index/AbstractFunctionCursor.java
0 → 100644
浏览文件 @
6b39b12a
/*
* 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
.
index
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.value.Value
;
/**
* Abstract function cursor.
*/
abstract
class
AbstractFunctionCursor
implements
Cursor
{
private
final
FunctionIndex
index
;
private
final
SearchRow
first
;
private
final
SearchRow
last
;
final
Session
session
;
Value
[]
values
;
Row
row
;
/**
* @param index
* index
* @param first
* first row
* @param last
* last row
* @param session
* session
*/
AbstractFunctionCursor
(
FunctionIndex
index
,
SearchRow
first
,
SearchRow
last
,
Session
session
)
{
this
.
index
=
index
;
this
.
first
=
first
;
this
.
last
=
last
;
this
.
session
=
session
;
}
@Override
public
Row
get
()
{
if
(
values
==
null
)
{
return
null
;
}
if
(
row
==
null
)
{
row
=
session
.
createRow
(
values
,
1
);
}
return
row
;
}
@Override
public
SearchRow
getSearchRow
()
{
return
get
();
}
@Override
public
boolean
next
()
{
while
(
nextImpl
())
{
Row
current
=
get
();
if
(
first
!=
null
)
{
int
comp
=
index
.
compareRows
(
current
,
first
);
if
(
comp
<
0
)
{
continue
;
}
}
if
(
last
!=
null
)
{
int
comp
=
index
.
compareRows
(
current
,
last
);
if
(
comp
>
0
)
{
continue
;
}
}
return
true
;
}
return
false
;
}
abstract
boolean
nextImpl
();
@Override
public
boolean
previous
()
{
throw
DbException
.
throwInternalError
(
toString
());
}
}
\ No newline at end of file
h2/src/main/org/h2/index/FunctionCursor.java
浏览文件 @
6b39b12a
...
...
@@ -6,45 +6,23 @@
package
org
.
h2
.
index
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.value.Value
;
/**
* A cursor for a function that returns a result.
*/
public
class
FunctionCursor
implements
Cursor
{
public
class
FunctionCursor
extends
AbstractFunction
Cursor
{
private
final
Session
session
;
private
final
ResultInterface
result
;
private
Value
[]
values
;
private
Row
row
;
FunctionCursor
(
Session
session
,
ResultInterface
result
)
{
this
.
session
=
session
;
FunctionCursor
(
FunctionIndex
index
,
SearchRow
first
,
SearchRow
last
,
Session
session
,
ResultInterface
result
)
{
super
(
index
,
first
,
last
,
session
)
;
this
.
result
=
result
;
}
@Override
public
Row
get
()
{
if
(
values
==
null
)
{
return
null
;
}
if
(
row
==
null
)
{
row
=
session
.
createRow
(
values
,
1
);
}
return
row
;
}
@Override
public
SearchRow
getSearchRow
()
{
return
get
();
}
@Override
public
boolean
next
()
{
boolean
nextImpl
()
{
row
=
null
;
if
(
result
!=
null
&&
result
.
next
())
{
values
=
result
.
currentRow
();
...
...
@@ -54,9 +32,4 @@ public class FunctionCursor implements Cursor {
return
values
!=
null
;
}
@Override
public
boolean
previous
()
{
throw
DbException
.
throwInternalError
(
toString
());
}
}
h2/src/main/org/h2/index/FunctionCursorResultSet.java
浏览文件 @
6b39b12a
...
...
@@ -10,7 +10,6 @@ import java.sql.ResultSetMetaData;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
...
...
@@ -18,16 +17,13 @@ import org.h2.value.Value;
/**
* A cursor for a function that returns a JDBC result set.
*/
public
class
FunctionCursorResultSet
implements
Cursor
{
public
class
FunctionCursorResultSet
extends
AbstractFunction
Cursor
{
private
final
Session
session
;
private
final
ResultSet
result
;
private
final
ResultSetMetaData
meta
;
private
Value
[]
values
;
private
Row
row
;
FunctionCursorResultSet
(
Session
session
,
ResultSet
result
)
{
this
.
session
=
session
;
FunctionCursorResultSet
(
FunctionIndex
index
,
SearchRow
first
,
SearchRow
last
,
Session
session
,
ResultSet
result
)
{
super
(
index
,
first
,
last
,
session
)
;
this
.
result
=
result
;
try
{
this
.
meta
=
result
.
getMetaData
();
...
...
@@ -37,23 +33,7 @@ public class FunctionCursorResultSet implements Cursor {
}
@Override
public
Row
get
()
{
if
(
values
==
null
)
{
return
null
;
}
if
(
row
==
null
)
{
row
=
session
.
createRow
(
values
,
1
);
}
return
row
;
}
@Override
public
SearchRow
getSearchRow
()
{
return
get
();
}
@Override
public
boolean
next
()
{
boolean
nextImpl
()
{
row
=
null
;
try
{
if
(
result
!=
null
&&
result
.
next
())
{
...
...
@@ -72,9 +52,4 @@ public class FunctionCursorResultSet implements Cursor {
return
values
!=
null
;
}
@Override
public
boolean
previous
()
{
throw
DbException
.
throwInternalError
(
toString
());
}
}
\ No newline at end of file
h2/src/main/org/h2/index/FunctionIndex.java
浏览文件 @
6b39b12a
...
...
@@ -47,9 +47,9 @@ public class FunctionIndex extends BaseIndex {
@Override
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
{
if
(
functionTable
.
isBufferResultSetToLocalTemp
())
{
return
new
FunctionCursor
(
session
,
functionTable
.
getResult
(
session
));
return
new
FunctionCursor
(
this
,
first
,
last
,
session
,
functionTable
.
getResult
(
session
));
}
return
new
FunctionCursorResultSet
(
session
,
return
new
FunctionCursorResultSet
(
this
,
first
,
last
,
session
,
functionTable
.
getResultSet
(
session
));
}
...
...
h2/src/test/org/h2/test/db/TestIndex.java
浏览文件 @
6b39b12a
...
...
@@ -10,6 +10,7 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Types
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Random
;
...
...
@@ -17,6 +18,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import
org.h2.api.ErrorCode
;
import
org.h2.result.SortOrder
;
import
org.h2.test.TestBase
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.value.ValueInt
;
/**
* Index tests.
...
...
@@ -89,6 +92,8 @@ public class TestIndex extends TestBase {
testMultiColumnHashIndex
();
testFunctionIndex
();
conn
.
close
();
deleteDb
(
"index"
);
}
...
...
@@ -702,4 +707,29 @@ public class TestIndex extends TestBase {
trace
(
"---done---"
);
}
public
static
ResultSet
testFunctionIndexFunction
()
{
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"ID"
,
Types
.
INTEGER
,
ValueInt
.
PRECISION
,
0
);
rs
.
addColumn
(
"VALUE"
,
Types
.
INTEGER
,
ValueInt
.
PRECISION
,
0
);
rs
.
addRow
(
1
,
10
);
rs
.
addRow
(
2
,
20
);
rs
.
addRow
(
3
,
30
);
return
rs
;
}
private
void
testFunctionIndex
()
throws
SQLException
{
stat
.
execute
(
"CREATE ALIAS TEST_INDEX FOR \""
+
TestIndex
.
class
.
getName
()
+
".testFunctionIndexFunction\""
);
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST_INDEX() WHERE ID = 1 OR ID = 3"
))
{
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
10
,
rs
.
getInt
(
2
));
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertEquals
(
30
,
rs
.
getInt
(
2
));
assertFalse
(
rs
.
next
());
}
finally
{
stat
.
execute
(
"DROP ALIAS TEST_INDEX"
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论