Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f4ee562c
提交
f4ee562c
authored
11月 12, 2015
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/h2database/h2database
上级
46983c43
84fd6dae
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
37 个修改的文件
包含
1322 行增加
和
143 行删除
+1322
-143
CommandContainer.java
h2/src/main/org/h2/command/CommandContainer.java
+1
-1
Delete.java
h2/src/main/org/h2/command/dml/Delete.java
+1
-1
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+1
-1
Update.java
h2/src/main/org/h2/command/dml/Update.java
+1
-1
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+8
-13
FunctionIndex.java
h2/src/main/org/h2/index/FunctionIndex.java
+2
-2
HashIndex.java
h2/src/main/org/h2/index/HashIndex.java
+2
-2
Index.java
h2/src/main/org/h2/index/Index.java
+8
-23
IndexCondition.java
h2/src/main/org/h2/index/IndexCondition.java
+27
-0
IndexLookupBatch.java
h2/src/main/org/h2/index/IndexLookupBatch.java
+50
-0
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+3
-3
MetaIndex.java
h2/src/main/org/h2/index/MetaIndex.java
+3
-3
MultiVersionIndex.java
h2/src/main/org/h2/index/MultiVersionIndex.java
+6
-10
NonUniqueHashIndex.java
h2/src/main/org/h2/index/NonUniqueHashIndex.java
+2
-2
PageBtreeIndex.java
h2/src/main/org/h2/index/PageBtreeIndex.java
+3
-3
PageDataIndex.java
h2/src/main/org/h2/index/PageDataIndex.java
+2
-3
PageDelegateIndex.java
h2/src/main/org/h2/index/PageDelegateIndex.java
+3
-3
RangeIndex.java
h2/src/main/org/h2/index/RangeIndex.java
+2
-2
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+2
-2
SpatialTreeIndex.java
h2/src/main/org/h2/index/SpatialTreeIndex.java
+4
-4
TreeIndex.java
h2/src/main/org/h2/index/TreeIndex.java
+2
-2
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+1
-1
MVDelegateIndex.java
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
+4
-5
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+2
-3
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+4
-5
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+4
-6
Plan.java
h2/src/main/org/h2/table/Plan.java
+3
-3
PlanItem.java
h2/src/main/org/h2/table/PlanItem.java
+9
-0
Table.java
h2/src/main/org/h2/table/Table.java
+5
-4
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+651
-10
TableView.java
h2/src/main/org/h2/table/TableView.java
+3
-3
DoneFuture.java
h2/src/main/org/h2/util/DoneFuture.java
+55
-0
SourceCompiler.java
h2/src/main/org/h2/util/SourceCompiler.java
+18
-3
javax.annotation.processing.Processor
...t/META-INF/services/javax.annotation.processing.Processor
+1
-0
TestAnnotationProcessor.java
h2/src/test/org/h2/test/ap/TestAnnotationProcessor.java
+65
-0
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+81
-1
TestTableEngines.java
h2/src/test/org/h2/test/db/TestTableEngines.java
+283
-18
没有找到文件。
h2/src/main/org/h2/command/CommandContainer.java
浏览文件 @
f4ee562c
...
@@ -17,7 +17,7 @@ import org.h2.value.ValueNull;
...
@@ -17,7 +17,7 @@ import org.h2.value.ValueNull;
* Represents a single SQL statements.
* Represents a single SQL statements.
* It wraps a prepared statement.
* It wraps a prepared statement.
*/
*/
class
CommandContainer
extends
Command
{
public
class
CommandContainer
extends
Command
{
private
Prepared
prepared
;
private
Prepared
prepared
;
private
boolean
readOnlyKnown
;
private
boolean
readOnlyKnown
;
...
...
h2/src/main/org/h2/command/dml/Delete.java
浏览文件 @
f4ee562c
...
@@ -130,7 +130,7 @@ public class Delete extends Prepared {
...
@@ -130,7 +130,7 @@ public class Delete extends Prepared {
condition
=
condition
.
optimize
(
session
);
condition
=
condition
.
optimize
(
session
);
condition
.
createIndexConditions
(
session
,
tableFilter
);
condition
.
createIndexConditions
(
session
,
tableFilter
);
}
}
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
1
);
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
new
TableFilter
[]{
tableFilter
},
0
);
tableFilter
.
setPlanItem
(
item
);
tableFilter
.
setPlanItem
(
item
);
tableFilter
.
prepare
();
tableFilter
.
prepare
();
}
}
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
f4ee562c
...
@@ -389,7 +389,7 @@ public class ScriptCommand extends ScriptBase {
...
@@ -389,7 +389,7 @@ public class ScriptCommand extends ScriptBase {
}
}
private
int
generateInsertValues
(
int
count
,
Table
table
)
throws
IOException
{
private
int
generateInsertValues
(
int
count
,
Table
table
)
throws
IOException
{
PlanItem
plan
=
table
.
getBestPlanItem
(
session
,
null
,
null
,
null
);
PlanItem
plan
=
table
.
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
);
Index
index
=
plan
.
getIndex
();
Index
index
=
plan
.
getIndex
();
Cursor
cursor
=
index
.
find
(
session
,
null
,
null
);
Cursor
cursor
=
index
.
find
(
session
,
null
,
null
);
Column
[]
columns
=
table
.
getColumns
();
Column
[]
columns
=
table
.
getColumns
();
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
f4ee562c
...
@@ -187,7 +187,7 @@ public class Update extends Prepared {
...
@@ -187,7 +187,7 @@ public class Update extends Prepared {
e
.
mapColumns
(
tableFilter
,
0
);
e
.
mapColumns
(
tableFilter
,
0
);
expressionMap
.
put
(
c
,
e
.
optimize
(
session
));
expressionMap
.
put
(
c
,
e
.
optimize
(
session
));
}
}
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
1
);
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
new
TableFilter
[]
{
tableFilter
},
0
);
tableFilter
.
setPlanItem
(
item
);
tableFilter
.
setPlanItem
(
item
);
tableFilter
.
prepare
();
tableFilter
.
prepare
();
}
}
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
f4ee562c
...
@@ -5,8 +5,6 @@
...
@@ -5,8 +5,6 @@
*/
*/
package
org
.
h2
.
index
;
package
org
.
h2
.
index
;
import
java.util.List
;
import
java.util.concurrent.Future
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.DbObject
;
...
@@ -152,12 +150,13 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -152,12 +150,13 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
*
*
* @param masks the search mask
* @param masks the search mask
* @param rowCount the number of rows in the index
* @param rowCount the number of rows in the index
* @param filter the table filter
* @param filters all joined table filters
* @param filter the current table filter index
* @param sortOrder the sort order
* @param sortOrder the sort order
* @return the estimated cost
* @return the estimated cost
*/
*/
protected
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
protected
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
rowCount
+=
Constants
.
COST_ROW_OFFSET
;
rowCount
+=
Constants
.
COST_ROW_OFFSET
;
long
cost
=
rowCount
;
long
cost
=
rowCount
;
long
rows
=
rowCount
;
long
rows
=
rowCount
;
...
@@ -201,6 +200,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -201,6 +200,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
boolean
sortOrderMatches
=
true
;
boolean
sortOrderMatches
=
true
;
int
coveringCount
=
0
;
int
coveringCount
=
0
;
int
[]
sortTypes
=
sortOrder
.
getSortTypes
();
int
[]
sortTypes
=
sortOrder
.
getSortTypes
();
TableFilter
tableFilter
=
filters
==
null
?
null
:
filters
[
filter
];
for
(
int
i
=
0
,
len
=
sortTypes
.
length
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
,
len
=
sortTypes
.
length
;
i
<
len
;
i
++)
{
if
(
i
>=
indexColumns
.
length
)
{
if
(
i
>=
indexColumns
.
length
)
{
// we can still use this index if we are sorting by more
// we can still use this index if we are sorting by more
...
@@ -209,7 +209,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -209,7 +209,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
// more of the order by columns
// more of the order by columns
break
;
break
;
}
}
Column
col
=
sortOrder
.
getColumn
(
i
,
f
ilter
);
Column
col
=
sortOrder
.
getColumn
(
i
,
tableF
ilter
);
if
(
col
==
null
)
{
if
(
col
==
null
)
{
sortOrderMatches
=
false
;
sortOrderMatches
=
false
;
break
;
break
;
...
@@ -427,13 +427,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -427,13 +427,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
}
@Override
@Override
public
int
getPreferedLookupBatchSize
()
{
public
IndexLookupBatch
createLookupBatch
(
TableFilter
filter
)
{
// No batched lookups supported by default.
// Lookup batching is not supported.
return
0
;
return
null
;
}
@Override
public
List
<
Future
<
Cursor
>>
findBatched
(
TableFilter
filter
,
List
<
SearchRow
>
firstLastPairs
)
{
throw
DbException
.
throwInternalError
(
"Must not be called if getPreferedLookupBatchSize() is 0."
);
}
}
}
}
h2/src/main/org/h2/index/FunctionIndex.java
浏览文件 @
f4ee562c
...
@@ -52,8 +52,8 @@ public class FunctionIndex extends BaseIndex {
...
@@ -52,8 +52,8 @@ public class FunctionIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
masks
!=
null
)
{
if
(
masks
!=
null
)
{
throw
DbException
.
getUnsupportedException
(
"ALIAS"
);
throw
DbException
.
getUnsupportedException
(
"ALIAS"
);
}
}
...
...
h2/src/main/org/h2/index/HashIndex.java
浏览文件 @
f4ee562c
...
@@ -113,8 +113,8 @@ public class HashIndex extends BaseIndex {
...
@@ -113,8 +113,8 @@ public class HashIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
for
(
Column
column
:
columns
)
{
for
(
Column
column
:
columns
)
{
int
index
=
column
.
getColumnId
();
int
index
=
column
.
getColumnId
();
int
mask
=
masks
[
index
];
int
mask
=
masks
[
index
];
...
...
h2/src/main/org/h2/index/Index.java
浏览文件 @
f4ee562c
...
@@ -83,11 +83,12 @@ public interface Index extends SchemaObject {
...
@@ -83,11 +83,12 @@ public interface Index extends SchemaObject {
* @param session the session
* @param session the session
* @param masks per-column comparison bit masks, null means 'always false',
* @param masks per-column comparison bit masks, null means 'always false',
* see constants in IndexCondition
* see constants in IndexCondition
* @param filter the table filter
* @param filters all joined table filters
* @param filter the current table filter index
* @param sortOrder the sort order
* @param sortOrder the sort order
* @return the estimated cost
* @return the estimated cost
*/
*/
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
);
SortOrder
sortOrder
);
/**
/**
...
@@ -259,27 +260,11 @@ public interface Index extends SchemaObject {
...
@@ -259,27 +260,11 @@ public interface Index extends SchemaObject {
void
setSortedInsertMode
(
boolean
sortedInsertMode
);
void
setSortedInsertMode
(
boolean
sortedInsertMode
);
/**
/**
*
If this index can do batched lookups, it may return it's preferred batch size,
*
Creates new lookup batch. Note that returned {@link IndexLookupBatch} instance
*
otherwise it must return 0
.
*
can be used multiple times
.
*
*
* @
return preferred batch size or 0 if lookup batching is not supported
* @
param filter Table filter.
* @
see #findBatched(TableFilter, Collection)
* @
return Created batch or {@code null} if batched lookup is not supported by this index.
*/
*/
int
getPreferedLookupBatchSize
();
IndexLookupBatch
createLookupBatch
(
TableFilter
filter
);
/**
* Do batched lookup over the given collection of {@link SearchRow} pairs as in
* {@link #find(TableFilter, SearchRow, SearchRow)}.
* <br/><br/>
* Correct implementation must always return number of future cursors equal to
* {@code firstLastPairs.size() / 2}. Instead of {@link Future} containing empty
* {@link Cursor} it is possible to put {@code null} in result list.
*
* @param filter the table filter
* @param firstLastPairs List of batched search row pairs as in
* {@link #find(TableFilter, SearchRow, SearchRow)}, the collection will be reused by H2,
* thus it makes sense to defensively copy contents if needed.
* @return batched cursors for respective search row pairs in the same order
*/
List
<
Future
<
Cursor
>>
findBatched
(
TableFilter
filter
,
List
<
SearchRow
>
firstLastPairs
);
}
}
h2/src/main/org/h2/index/IndexCondition.java
浏览文件 @
f4ee562c
...
@@ -347,6 +347,33 @@ public class IndexCondition {
...
@@ -347,6 +347,33 @@ public class IndexCondition {
return
column
;
return
column
;
}
}
/**
* Get expression.
*
* @return Expression.
*/
public
Expression
getExpression
()
{
return
expression
;
}
/**
* Get expression list.
*
* @return Expression list.
*/
public
List
<
Expression
>
getExpressionList
()
{
return
expressionList
;
}
/**
* Get expression query.
*
* @return Expression query.
*/
public
Query
getExpressionQuery
()
{
return
expressionQuery
;
}
/**
/**
* Check if the expression can be evaluated.
* Check if the expression can be evaluated.
*
*
...
...
h2/src/main/org/h2/index/IndexLookupBatch.java
0 → 100644
浏览文件 @
f4ee562c
/*
* Copyright 2004-2014 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
java.util.List
;
import
java.util.concurrent.Future
;
import
org.h2.result.SearchRow
;
/**
* Support for asynchronous batched lookups in indexes. The flow is the following:
* H2 engine will be calling {@link #addSearchRows(SearchRow, SearchRow)} until
* method {@link #isBatchFull()}} will return {@code true} or there are no more
* search rows to add. Then method {@link #find()} will be called to execute batched lookup.
* Note that a single instance of {@link IndexLookupBatch} can be reused for multiple
* sequential batched lookups.
*
* @see Index#createLookupBatch(TableFilter)
* @author Sergi Vladykin
*/
public
interface
IndexLookupBatch
{
/**
* Add search row pair to the batch.
*
* @param first the first row, or null for no limit
* @param last the last row, or null for no limit
* @see Index#find(TableFilter, SearchRow, SearchRow)
*/
void
addSearchRows
(
SearchRow
first
,
SearchRow
last
);
/**
* Check if this batch is full.
*
* @return {@code true} If batch is full, will not accept any
* more rows and {@link #find()} can be executed.
*/
boolean
isBatchFull
();
/**
* Execute batched lookup and return future cursor for each provided
* search row pair. Note that this method must return exactly the same number
* of future cursors in result list as number of {@link #addSearchRows(SearchRow, SearchRow)}
* calls has been done before {@link #find()} call exactly in the same order.
*
* @return List of future cursors for collected search rows.
*/
List
<
Future
<
Cursor
>>
find
();
}
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
f4ee562c
...
@@ -141,10 +141,10 @@ public class LinkedIndex extends BaseIndex {
...
@@ -141,10 +141,10 @@ public class LinkedIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
100
+
getCostRangeIndex
(
masks
,
rowCount
+
return
100
+
getCostRangeIndex
(
masks
,
rowCount
+
Constants
.
COST_ROW_OFFSET
,
filter
,
sortOrder
);
Constants
.
COST_ROW_OFFSET
,
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/MetaIndex.java
浏览文件 @
f4ee562c
...
@@ -52,13 +52,13 @@ public class MetaIndex extends BaseIndex {
...
@@ -52,13 +52,13 @@ public class MetaIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
scan
)
{
if
(
scan
)
{
return
10
*
MetaTable
.
ROW_COUNT_APPROXIMATION
;
return
10
*
MetaTable
.
ROW_COUNT_APPROXIMATION
;
}
}
return
getCostRangeIndex
(
masks
,
MetaTable
.
ROW_COUNT_APPROXIMATION
,
return
getCostRangeIndex
(
masks
,
MetaTable
.
ROW_COUNT_APPROXIMATION
,
filter
,
sortOrder
);
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/MultiVersionIndex.java
浏览文件 @
f4ee562c
...
@@ -142,9 +142,9 @@ public class MultiVersionIndex implements Index {
...
@@ -142,9 +142,9 @@ public class MultiVersionIndex implements Index {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
base
.
getCost
(
session
,
masks
,
filter
,
sortOrder
);
return
base
.
getCost
(
session
,
masks
,
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
@@ -389,12 +389,8 @@ public class MultiVersionIndex implements Index {
...
@@ -389,12 +389,8 @@ public class MultiVersionIndex implements Index {
}
}
@Override
@Override
public
int
getPreferedLookupBatchSize
()
{
public
IndexLookupBatch
createLookupBatch
(
TableFilter
filter
)
{
return
0
;
// Lookup batching is not supported.
}
return
null
;
@Override
public
List
<
Future
<
Cursor
>>
findBatched
(
TableFilter
filter
,
List
<
SearchRow
>
firstLastPairs
)
{
throw
DbException
.
throwInternalError
(
"Must never be called."
);
}
}
}
}
h2/src/main/org/h2/index/NonUniqueHashIndex.java
浏览文件 @
f4ee562c
...
@@ -130,8 +130,8 @@ public class NonUniqueHashIndex extends BaseIndex {
...
@@ -130,8 +130,8 @@ public class NonUniqueHashIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
for
(
Column
column
:
columns
)
{
for
(
Column
column
:
columns
)
{
int
index
=
column
.
getColumnId
();
int
index
=
column
.
getColumnId
();
int
mask
=
masks
[
index
];
int
mask
=
masks
[
index
];
...
...
h2/src/main/org/h2/index/PageBtreeIndex.java
浏览文件 @
f4ee562c
...
@@ -217,10 +217,10 @@ public class PageBtreeIndex extends PageIndex {
...
@@ -217,10 +217,10 @@ public class PageBtreeIndex extends PageIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
10
*
getCostRangeIndex
(
masks
,
tableData
.
getRowCount
(
session
),
return
10
*
getCostRangeIndex
(
masks
,
tableData
.
getRowCount
(
session
),
filter
,
sortOrder
);
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/PageDataIndex.java
浏览文件 @
f4ee562c
...
@@ -10,7 +10,6 @@ import java.util.HashMap;
...
@@ -10,7 +10,6 @@ import java.util.HashMap;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -310,8 +309,8 @@ public class PageDataIndex extends PageIndex {
...
@@ -310,8 +309,8 @@ public class PageDataIndex extends PageIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
long
cost
=
10
*
(
tableData
.
getRowCountApproximation
()
+
long
cost
=
10
*
(
tableData
.
getRowCountApproximation
()
+
Constants
.
COST_ROW_OFFSET
);
Constants
.
COST_ROW_OFFSET
);
return
cost
;
return
cost
;
...
...
h2/src/main/org/h2/index/PageDelegateIndex.java
浏览文件 @
f4ee562c
...
@@ -96,10 +96,10 @@ public class PageDelegateIndex extends PageIndex {
...
@@ -96,10 +96,10 @@ public class PageDelegateIndex extends PageIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
10
*
getCostRangeIndex
(
masks
,
mainIndex
.
getRowCount
(
session
),
return
10
*
getCostRangeIndex
(
masks
,
mainIndex
.
getRowCount
(
session
),
filter
,
sortOrder
);
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/RangeIndex.java
浏览文件 @
f4ee562c
...
@@ -62,8 +62,8 @@ public class RangeIndex extends BaseIndex {
...
@@ -62,8 +62,8 @@ public class RangeIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
1
;
return
1
;
}
}
...
...
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
f4ee562c
...
@@ -174,8 +174,8 @@ public class ScanIndex extends BaseIndex {
...
@@ -174,8 +174,8 @@ public class ScanIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
tableData
.
getRowCountApproximation
()
+
Constants
.
COST_ROW_OFFSET
;
return
tableData
.
getRowCountApproximation
()
+
Constants
.
COST_ROW_OFFSET
;
}
}
...
...
h2/src/main/org/h2/index/SpatialTreeIndex.java
浏览文件 @
f4ee562c
...
@@ -180,7 +180,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
...
@@ -180,7 +180,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
@Override
@Override
protected
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
protected
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
rowCount
,
columns
);
return
getCostRangeIndex
(
masks
,
rowCount
,
columns
);
}
}
...
@@ -208,10 +208,10 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
...
@@ -208,10 +208,10 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
table
.
getRowCountApproximation
(),
return
getCostRangeIndex
(
masks
,
table
.
getRowCountApproximation
(),
filter
,
sortOrder
);
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/TreeIndex.java
浏览文件 @
f4ee562c
...
@@ -318,10 +318,10 @@ public class TreeIndex extends BaseIndex {
...
@@ -318,10 +318,10 @@ public class TreeIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
tableData
.
getRowCountApproximation
(),
return
getCostRangeIndex
(
masks
,
tableData
.
getRowCountApproximation
(),
filter
,
sortOrder
);
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
f4ee562c
...
@@ -115,7 +115,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -115,7 +115,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
@Override
@Override
public
synchronized
double
getCost
(
Session
session
,
int
[]
masks
,
public
synchronized
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
recursive
)
{
if
(
recursive
)
{
return
1000
;
return
1000
;
}
}
...
...
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
浏览文件 @
f4ee562c
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
package
org
.
h2
.
mvstore
.
db
;
package
org
.
h2
.
mvstore
.
db
;
import
java.util.List
;
import
java.util.List
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.index.BaseIndex
;
import
org.h2.index.BaseIndex
;
import
org.h2.index.Cursor
;
import
org.h2.index.Cursor
;
...
@@ -89,10 +88,10 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
...
@@ -89,10 +88,10 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
10
*
getCostRangeIndex
(
masks
,
return
10
*
getCostRangeIndex
(
masks
,
mainIndex
.
getRowCountApproximation
(),
mainIndex
.
getRowCountApproximation
()
,
filter
,
sortOrder
);
filters
,
filter
,
sortOrder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
f4ee562c
...
@@ -10,7 +10,6 @@ import java.util.Collections;
...
@@ -10,7 +10,6 @@ import java.util.Collections;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
...
@@ -217,8 +216,8 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -217,8 +216,8 @@ public class MVPrimaryIndex extends BaseIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
try
{
try
{
long
cost
=
10
*
(
dataMap
.
sizeAsLongMax
()
+
Constants
.
COST_ROW_OFFSET
);
long
cost
=
10
*
(
dataMap
.
sizeAsLongMax
()
+
Constants
.
COST_ROW_OFFSET
);
return
cost
;
return
cost
;
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
f4ee562c
...
@@ -10,7 +10,6 @@ import java.util.Collections;
...
@@ -10,7 +10,6 @@ import java.util.Collections;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.TreeSet
;
import
java.util.TreeSet
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -352,11 +351,11 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
...
@@ -352,11 +351,11 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
try
{
try
{
return
10
*
getCostRangeIndex
(
masks
,
return
10
*
getCostRangeIndex
(
masks
,
dataMap
.
sizeAsLongMax
(),
dataMap
.
sizeAsLongMax
()
,
filter
,
sortOrder
);
filters
,
filter
,
sortOrder
);
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
throw
DbException
.
get
(
ErrorCode
.
OBJECT_CLOSED
,
e
);
throw
DbException
.
get
(
ErrorCode
.
OBJECT_CLOSED
,
e
);
}
}
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
f4ee562c
...
@@ -7,7 +7,6 @@ package org.h2.mvstore.db;
...
@@ -7,7 +7,6 @@ package org.h2.mvstore.db;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -33,7 +32,6 @@ import org.h2.value.Value;
...
@@ -33,7 +32,6 @@ import org.h2.value.Value;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
import
com.vividsolutions.jts.geom.Envelope
;
import
com.vividsolutions.jts.geom.Envelope
;
import
com.vividsolutions.jts.geom.Geometry
;
import
com.vividsolutions.jts.geom.Geometry
;
...
@@ -239,15 +237,15 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -239,15 +237,15 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
}
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
table
.
getRowCountApproximation
(),
return
getCostRangeIndex
(
masks
,
table
.
getRowCountApproximation
(),
filter
,
sortOrder
);
filter
s
,
filter
,
sortOrder
);
}
}
@Override
@Override
protected
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
protected
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
SpatialTreeIndex
.
getCostRangeIndex
(
masks
,
rowCount
,
columns
);
return
SpatialTreeIndex
.
getCostRangeIndex
(
masks
,
rowCount
,
columns
);
}
}
...
...
h2/src/main/org/h2/table/Plan.java
浏览文件 @
f4ee562c
...
@@ -106,9 +106,9 @@ public class Plan {
...
@@ -106,9 +106,9 @@ public class Plan {
public
double
calculateCost
(
Session
session
)
{
public
double
calculateCost
(
Session
session
)
{
double
cost
=
1
;
double
cost
=
1
;
boolean
invalidPlan
=
false
;
boolean
invalidPlan
=
false
;
int
level
=
1
;
for
(
int
i
=
0
;
i
<
allFilters
.
length
;
i
++)
{
for
(
TableFilter
tableFilter
:
allFilters
)
{
TableFilter
tableFilter
=
allFilters
[
i
];
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
level
++
);
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
allFilters
,
i
);
planItems
.
put
(
tableFilter
,
item
);
planItems
.
put
(
tableFilter
,
item
);
cost
+=
cost
*
item
.
cost
;
cost
+=
cost
*
item
.
cost
;
setEvaluatable
(
tableFilter
,
true
);
setEvaluatable
(
tableFilter
,
true
);
...
...
h2/src/main/org/h2/table/PlanItem.java
浏览文件 @
f4ee562c
...
@@ -18,10 +18,19 @@ public class PlanItem {
...
@@ -18,10 +18,19 @@ public class PlanItem {
*/
*/
double
cost
;
double
cost
;
private
int
[]
masks
;
private
Index
index
;
private
Index
index
;
private
PlanItem
joinPlan
;
private
PlanItem
joinPlan
;
private
PlanItem
nestedJoinPlan
;
private
PlanItem
nestedJoinPlan
;
void
setMasks
(
int
[]
masks
)
{
this
.
masks
=
masks
;
}
int
[]
getMasks
()
{
return
masks
;
}
void
setIndex
(
Index
index
)
{
void
setIndex
(
Index
index
)
{
this
.
index
=
index
;
this
.
index
=
index
;
}
}
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
f4ee562c
...
@@ -678,20 +678,21 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -678,20 +678,21 @@ public abstract class Table extends SchemaObjectBase {
* @param session the session
* @param session the session
* @param masks per-column comparison bit masks, null means 'always false',
* @param masks per-column comparison bit masks, null means 'always false',
* see constants in IndexCondition
* see constants in IndexCondition
* @param filter the table filter
* @param filters all joined table filters
* @param filter the current table filter index
* @param sortOrder the sort order
* @param sortOrder the sort order
* @return the plan item
* @return the plan item
*/
*/
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
PlanItem
item
=
new
PlanItem
();
PlanItem
item
=
new
PlanItem
();
item
.
setIndex
(
getScanIndex
(
session
));
item
.
setIndex
(
getScanIndex
(
session
));
item
.
cost
=
item
.
getIndex
().
getCost
(
session
,
null
,
null
,
null
);
item
.
cost
=
item
.
getIndex
().
getCost
(
session
,
null
,
filters
,
filter
,
null
);
ArrayList
<
Index
>
indexes
=
getIndexes
();
ArrayList
<
Index
>
indexes
=
getIndexes
();
if
(
indexes
!=
null
&&
masks
!=
null
)
{
if
(
indexes
!=
null
&&
masks
!=
null
)
{
for
(
int
i
=
1
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
for
(
int
i
=
1
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
Index
index
=
indexes
.
get
(
i
);
Index
index
=
indexes
.
get
(
i
);
double
cost
=
index
.
getCost
(
session
,
masks
,
filter
,
sortOrder
);
double
cost
=
index
.
getCost
(
session
,
masks
,
filter
s
,
filter
,
sortOrder
);
if
(
cost
<
item
.
cost
)
{
if
(
cost
<
item
.
cost
)
{
item
.
cost
=
cost
;
item
.
cost
=
cost
;
item
.
setIndex
(
index
);
item
.
setIndex
(
index
);
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
f4ee562c
差异被折叠。
点击展开。
h2/src/main/org/h2/table/TableView.java
浏览文件 @
f4ee562c
...
@@ -225,9 +225,9 @@ public class TableView extends Table {
...
@@ -225,9 +225,9 @@ public class TableView extends Table {
@Override
@Override
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
PlanItem
item
=
new
PlanItem
();
PlanItem
item
=
new
PlanItem
();
item
.
cost
=
index
.
getCost
(
session
,
masks
,
filter
,
sortOrder
);
item
.
cost
=
index
.
getCost
(
session
,
masks
,
filter
s
,
filter
,
sortOrder
);
final
CacheKey
cacheKey
=
new
CacheKey
(
masks
,
session
);
final
CacheKey
cacheKey
=
new
CacheKey
(
masks
,
session
);
synchronized
(
this
)
{
synchronized
(
this
)
{
...
@@ -434,7 +434,7 @@ public class TableView extends Table {
...
@@ -434,7 +434,7 @@ public class TableView extends Table {
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
createException
,
getSQL
(),
msg
);
createException
,
getSQL
(),
msg
);
}
}
PlanItem
item
=
getBestPlanItem
(
session
,
null
,
null
,
null
);
PlanItem
item
=
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
);
return
item
.
getIndex
();
return
item
.
getIndex
();
}
}
...
...
h2/src/main/org/h2/util/DoneFuture.java
0 → 100644
浏览文件 @
f4ee562c
/*
* Copyright 2004-2014 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
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
/**
* Future which is already done.
*
* @param <T> Result value.
* @author Sergi Vladykin
*/
public
class
DoneFuture
<
T
>
implements
Future
<
T
>
{
final
T
x
;
public
DoneFuture
(
T
x
)
{
this
.
x
=
x
;
}
@Override
public
T
get
()
throws
InterruptedException
,
ExecutionException
{
return
x
;
}
@Override
public
T
get
(
long
timeout
,
TimeUnit
unit
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
return
x
;
}
@Override
public
boolean
isDone
()
{
return
true
;
}
@Override
public
boolean
cancel
(
boolean
mayInterruptIfRunning
)
{
return
false
;
}
@Override
public
boolean
isCancelled
()
{
return
false
;
}
@Override
public
String
toString
()
{
return
"DoneFuture->"
+
x
;
}
}
h2/src/main/org/h2/util/SourceCompiler.java
浏览文件 @
f4ee562c
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataInputStream
;
import
java.io.File
;
import
java.io.File
;
...
@@ -13,6 +14,7 @@ import java.io.IOException;
...
@@ -13,6 +14,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.io.PrintStream
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.io.Writer
;
import
java.io.Writer
;
import
java.lang.reflect.Array
;
import
java.lang.reflect.Array
;
...
@@ -361,9 +363,22 @@ public class SourceCompiler {
...
@@ -361,9 +363,22 @@ public class SourceCompiler {
}
}
private
static
void
handleSyntaxError
(
String
output
)
{
private
static
void
handleSyntaxError
(
String
output
)
{
if
(
output
.
startsWith
(
"Note:"
)
||
output
.
startsWith
(
"warning:"
))
{
boolean
syntaxError
=
false
;
// just a warning (e.g. unchecked or unsafe operations)
final
BufferedReader
reader
=
new
BufferedReader
(
new
StringReader
(
output
));
}
else
if
(
output
.
length
()
>
0
)
{
try
{
for
(
String
line
;
(
line
=
reader
.
readLine
())
!=
null
;
)
{
if
(
line
.
startsWith
(
"Note:"
)
||
line
.
startsWith
(
"warning:"
))
{
// just a warning (e.g. unchecked or unsafe operations)
}
else
{
syntaxError
=
true
;
break
;
}
}
}
catch
(
IOException
ignored
)
{
// exception ignored
}
if
(
syntaxError
)
{
output
=
StringUtils
.
replaceAll
(
output
,
COMPILE_DIR
,
""
);
output
=
StringUtils
.
replaceAll
(
output
,
COMPILE_DIR
,
""
);
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
output
);
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
output
);
}
}
...
...
h2/src/test/META-INF/services/javax.annotation.processing.Processor
0 → 100644
浏览文件 @
f4ee562c
org.h2.test.ap.TestAnnotationProcessor
\ No newline at end of file
h2/src/test/org/h2/test/ap/TestAnnotationProcessor.java
0 → 100644
浏览文件 @
f4ee562c
package
org
.
h2
.
test
.
ap
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
import
javax.annotation.processing.AbstractProcessor
;
import
javax.annotation.processing.RoundEnvironment
;
import
javax.lang.model.SourceVersion
;
import
javax.lang.model.element.TypeElement
;
import
javax.tools.Diagnostic
;
public
class
TestAnnotationProcessor
extends
AbstractProcessor
{
public
static
final
String
MESSAGES_KEY
=
TestAnnotationProcessor
.
class
.
getName
()
+
"-messages"
;
public
Set
<
String
>
getSupportedAnnotationTypes
()
{
for
(
OutputMessage
outputMessage
:
findMessages
())
{
processingEnv
.
getMessager
().
printMessage
(
outputMessage
.
kind
,
outputMessage
.
message
);
}
return
Collections
.
emptySet
();
}
private
List
<
OutputMessage
>
findMessages
()
{
final
String
messagesStr
=
System
.
getProperty
(
MESSAGES_KEY
);
if
(
messagesStr
==
null
||
messagesStr
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
else
{
final
List
<
OutputMessage
>
outputMessages
=
new
ArrayList
<
OutputMessage
>();
for
(
String
msg
:
messagesStr
.
split
(
"\\|"
))
{
final
String
[]
split
=
msg
.
split
(
","
);
if
(
split
.
length
==
2
)
{
outputMessages
.
add
(
new
OutputMessage
(
Diagnostic
.
Kind
.
valueOf
(
split
[
0
]),
split
[
1
]));
}
else
{
throw
new
IllegalStateException
(
"Unable to parse messages definition for: '"
+
messagesStr
+
"'"
);
}
}
return
outputMessages
;
}
}
public
SourceVersion
getSupportedSourceVersion
()
{
return
SourceVersion
.
RELEASE_6
;
}
@Override
public
boolean
process
(
Set
<?
extends
TypeElement
>
annotations
,
RoundEnvironment
roundEnv
)
{
return
false
;
}
private
static
class
OutputMessage
{
public
final
Diagnostic
.
Kind
kind
;
public
final
String
message
;
private
OutputMessage
(
Diagnostic
.
Kind
kind
,
String
message
)
{
this
.
kind
=
kind
;
this
.
message
=
message
;
}
}
}
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
f4ee562c
...
@@ -41,8 +41,10 @@ import org.h2.api.Aggregate;
...
@@ -41,8 +41,10 @@ import org.h2.api.Aggregate;
import
org.h2.api.AggregateFunction
;
import
org.h2.api.AggregateFunction
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.test.ap.TestAnnotationProcessor
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.IOUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.New
;
import
org.h2.util.New
;
...
@@ -103,6 +105,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -103,6 +105,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testTranslate
();
testTranslate
();
testGenerateSeries
();
testGenerateSeries
();
testFileWrite
();
testFileWrite
();
testAnnotationProcessorsOutput
();
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
}
}
...
@@ -1163,7 +1166,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1163,7 +1166,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
call
.
execute
();
call
.
execute
();
assertEquals
(
Integer
[].
class
.
getName
(),
call
.
getArray
(
1
).
getArray
()
assertEquals
(
Integer
[].
class
.
getName
(),
call
.
getArray
(
1
).
getArray
()
.
getClass
().
getName
());
.
getClass
().
getName
());
assertEquals
(
new
Integer
[]
{
2
,
1
},
(
Integer
[])
call
.
getObject
(
1
));
assertEquals
(
new
Integer
[]
{
2
,
1
},
(
Integer
[])
call
.
getObject
(
1
));
stat
.
execute
(
"drop alias array_test"
);
stat
.
execute
(
"drop alias array_test"
);
...
@@ -1778,6 +1781,83 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1778,6 +1781,83 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
conn
.
close
();
}
}
private
void
testAnnotationProcessorsOutput
()
throws
SQLException
{
testAnnotationProcessorsOutput_emptyKey
();
testAnnotationProcessorsOutput_invalidKey
();
testAnnotationProcessorsOutput_oneInvalidKey
();
testAnnotationProcessorsOutput_warnAndError
();
}
private
void
testAnnotationProcessorsOutput_emptyKey
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
""
);
callCompiledFunction
(
"test_atp_empty_key"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
testAnnotationProcessorsOutput_invalidKey
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
"invalid"
);
callCompiledFunction
(
"test_atp_invalid_key"
);
fail
();
}
catch
(
JdbcSQLException
e
)
{
assertEquals
(
ErrorCode
.
SYNTAX_ERROR_1
,
e
.
getErrorCode
());
assertContains
(
e
.
getMessage
(),
"'invalid'"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
testAnnotationProcessorsOutput_oneInvalidKey
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
"invalid,foo"
);
callCompiledFunction
(
"test_atp_one_invalid_key"
);
fail
();
}
catch
(
JdbcSQLException
e
)
{
assertEquals
(
ErrorCode
.
SYNTAX_ERROR_1
,
e
.
getErrorCode
());
assertContains
(
e
.
getMessage
(),
"enum"
);
assertContains
(
e
.
getMessage
(),
"Kind.invalid"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
testAnnotationProcessorsOutput_warnAndError
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
"WARNING,foo1|ERROR,foo2"
);
callCompiledFunction
(
"test_atp_warn_and_error"
);
fail
();
}
catch
(
JdbcSQLException
e
)
{
assertEquals
(
ErrorCode
.
SYNTAX_ERROR_1
,
e
.
getErrorCode
());
assertContains
(
e
.
getMessage
(),
"foo1"
);
assertContains
(
e
.
getMessage
(),
"foo2"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
callCompiledFunction
(
String
functionName
)
throws
SQLException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
stat
.
execute
(
"create alias "
+
functionName
+
" AS "
+
"$$ boolean "
+
functionName
+
"() "
+
"{ return true; } $$;"
);
PreparedStatement
stmt
=
conn
.
prepareStatement
(
"select "
+
functionName
+
"() from dual"
);
rs
=
stmt
.
executeQuery
();
rs
.
next
();
assertEquals
(
Boolean
.
class
.
getName
(),
rs
.
getObject
(
1
).
getClass
().
getName
());
stat
.
execute
(
"drop alias "
+
functionName
+
""
);
conn
.
close
();
}
private
void
assertCallResult
(
String
expected
,
Statement
stat
,
String
sql
)
private
void
assertCallResult
(
String
expected
,
Statement
stat
,
String
sql
)
throws
SQLException
{
throws
SQLException
{
ResultSet
rs
=
stat
.
executeQuery
(
"CALL "
+
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
"CALL "
+
sql
);
...
...
h2/src/test/org/h2/test/db/TestTableEngines.java
浏览文件 @
f4ee562c
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论