Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e126424c
提交
e126424c
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use generics
上级
bfcce888
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
121 个修改的文件
包含
904 行增加
和
1275 行删除
+904
-1275
Bnf.java
h2/src/main/org/h2/bnf/Bnf.java
+1
-3
RuleList.java
h2/src/main/org/h2/bnf/RuleList.java
+10
-13
Parser.java
h2/src/main/org/h2/command/Parser.java
+8
-10
Prepared.java
h2/src/main/org/h2/command/Prepared.java
+15
-26
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+2
-2
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+1
-1
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+1
-1
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+14
-20
Merge.java
h2/src/main/org/h2/command/dml/Merge.java
+30
-43
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+1
-1
Select.java
h2/src/main/org/h2/command/dml/Select.java
+32
-50
SelectOrderBy.java
h2/src/main/org/h2/command/dml/SelectOrderBy.java
+1
-2
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+1
-1
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+64
-105
ConstraintUnique.java
h2/src/main/org/h2/constraint/ConstraintUnique.java
+9
-17
FunctionAlias.java
h2/src/main/org/h2/engine/FunctionAlias.java
+7
-14
User.java
h2/src/main/org/h2/engine/User.java
+1
-1
Aggregate.java
h2/src/main/org/h2/expression/Aggregate.java
+14
-25
AggregateData.java
h2/src/main/org/h2/expression/AggregateData.java
+2
-3
CompareLike.java
h2/src/main/org/h2/expression/CompareLike.java
+2
-2
ConditionExists.java
h2/src/main/org/h2/expression/ConditionExists.java
+2
-5
ConditionIn.java
h2/src/main/org/h2/expression/ConditionIn.java
+12
-22
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+2
-4
ExpressionList.java
h2/src/main/org/h2/expression/ExpressionList.java
+16
-19
Function.java
h2/src/main/org/h2/expression/Function.java
+26
-37
JavaAggregate.java
h2/src/main/org/h2/expression/JavaAggregate.java
+11
-16
JavaFunction.java
h2/src/main/org/h2/expression/JavaFunction.java
+13
-20
TableFunction.java
h2/src/main/org/h2/expression/TableFunction.java
+7
-12
FullText.java
h2/src/main/org/h2/fulltext/FullText.java
+6
-10
FullTextLucene.java
h2/src/main/org/h2/fulltext/FullTextLucene.java
+13
-22
FullTextSettings.java
h2/src/main/org/h2/fulltext/FullTextSettings.java
+1
-3
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+15
-29
HashIndex.java
h2/src/main/org/h2/index/HashIndex.java
+2
-6
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+20
-35
PageBtreeIndex.java
h2/src/main/org/h2/index/PageBtreeIndex.java
+7
-6
PageBtreeNode.java
h2/src/main/org/h2/index/PageBtreeNode.java
+5
-6
PageDataNode.java
h2/src/main/org/h2/index/PageDataNode.java
+5
-6
JdbcArray.java
h2/src/main/org/h2/jdbc/JdbcArray.java
+1
-3
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+9
-13
JdbcPreparedStatement.java
h2/src/main/org/h2/jdbc/JdbcPreparedStatement.java
+1
-1
JdbcResultSet.java
h2/src/main/org/h2/jdbc/JdbcResultSet.java
+4
-5
JdbcConnectionPool.java
h2/src/main/org/h2/jdbcx/JdbcConnectionPool.java
+2
-2
LogFile.java
h2/src/main/org/h2/log/LogFile.java
+1
-2
LogSystem.java
h2/src/main/org/h2/log/LogSystem.java
+2
-4
TraceObject.java
h2/src/main/org/h2/message/TraceObject.java
+9
-15
ResultDiskBuffer.java
h2/src/main/org/h2/result/ResultDiskBuffer.java
+5
-11
ResultRemote.java
h2/src/main/org/h2/result/ResultRemote.java
+1
-2
ResultTempTable.java
h2/src/main/org/h2/result/ResultTempTable.java
+1
-2
Row.java
h2/src/main/org/h2/result/Row.java
+6
-11
SimpleRow.java
h2/src/main/org/h2/result/SimpleRow.java
+5
-9
SortOrder.java
h2/src/main/org/h2/result/SortOrder.java
+7
-9
UpdatableRow.java
h2/src/main/org/h2/result/UpdatableRow.java
+17
-25
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+18
-24
DataPage.java
h2/src/main/org/h2/store/DataPage.java
+4
-4
DiskFile.java
h2/src/main/org/h2/store/DiskFile.java
+1
-2
Column.java
h2/src/main/org/h2/table/Column.java
+9
-22
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+10
-20
Plan.java
h2/src/main/org/h2/table/Plan.java
+2
-2
TableData.java
h2/src/main/org/h2/table/TableData.java
+7
-11
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+9
-15
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+2
-2
TableView.java
h2/src/main/org/h2/table/TableView.java
+12
-19
ChangeFileEncryption.java
h2/src/main/org/h2/tools/ChangeFileEncryption.java
+2
-2
MultiDimension.java
h2/src/main/org/h2/tools/MultiDimension.java
+27
-22
Recover.java
h2/src/main/org/h2/tools/Recover.java
+6
-10
Shell.java
h2/src/main/org/h2/tools/Shell.java
+0
-1
CacheSecondLevel.java
h2/src/main/org/h2/util/CacheSecondLevel.java
+2
-2
ObjectUtils.java
h2/src/main/org/h2/util/ObjectUtils.java
+0
-109
SmallMap.java
h2/src/main/org/h2/util/SmallMap.java
+3
-3
StatementBuilder.java
h2/src/main/org/h2/util/StatementBuilder.java
+119
-0
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+13
-24
DataType.java
h2/src/main/org/h2/value/DataType.java
+7
-7
ValueArray.java
h2/src/main/org/h2/value/ValueArray.java
+17
-27
ValueByte.java
h2/src/main/org/h2/value/ValueByte.java
+1
-3
ValueDouble.java
h2/src/main/org/h2/value/ValueDouble.java
+1
-3
ValueFloat.java
h2/src/main/org/h2/value/ValueFloat.java
+1
-3
ValueInt.java
h2/src/main/org/h2/value/ValueInt.java
+1
-3
ValueLong.java
h2/src/main/org/h2/value/ValueLong.java
+1
-3
ValueResultSet.java
h2/src/main/org/h2/value/ValueResultSet.java
+5
-7
ValueShort.java
h2/src/main/org/h2/value/ValueShort.java
+1
-3
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+10
-1
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+3
-4
Coverage.java
h2/src/test/org/h2/test/coverage/Coverage.java
+4
-5
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+2
-4
TestLinkedTable.java
h2/src/test/org/h2/test/db/TestLinkedTable.java
+2
-2
TestLogFile.java
h2/src/test/org/h2/test/db/TestLogFile.java
+2
-5
TestPowerOff.java
h2/src/test/org/h2/test/db/TestPowerOff.java
+1
-4
TestReadOnly.java
h2/src/test/org/h2/test/db/TestReadOnly.java
+2
-4
TestTwoPhaseCommit.java
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
+1
-2
TestBatchUpdates.java
h2/src/test/org/h2/test/jdbc/TestBatchUpdates.java
+2
-3
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+1
-2
TestResultSet.java
h2/src/test/org/h2/test/jdbc/TestResultSet.java
+2
-3
Test.java
h2/src/test/org/h2/test/poweroff/Test.java
+2
-2
TestRecover.java
h2/src/test/org/h2/test/poweroff/TestRecover.java
+4
-8
TestCrashAPI.java
h2/src/test/org/h2/test/synth/TestCrashAPI.java
+4
-10
Command.java
h2/src/test/org/h2/test/synth/sql/Command.java
+10
-11
Result.java
h2/src/test/org/h2/test/synth/sql/Result.java
+2
-4
Row.java
h2/src/test/org/h2/test/synth/sql/Row.java
+1
-2
Table.java
h2/src/test/org/h2/test/synth/sql/Table.java
+6
-6
Value.java
h2/src/test/org/h2/test/synth/sql/Value.java
+2
-2
Player.java
h2/src/test/org/h2/test/trace/Player.java
+2
-2
TestClearReferences.java
h2/src/test/org/h2/test/unit/TestClearReferences.java
+6
-11
TestCompress.java
h2/src/test/org/h2/test/unit/TestCompress.java
+2
-3
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+4
-7
TestOverflow.java
h2/src/test/org/h2/test/unit/TestOverflow.java
+2
-4
TestValueMemory.java
h2/src/test/org/h2/test/unit/TestValueMemory.java
+2
-2
BuildBase.java
h2/src/tools/org/h2/build/BuildBase.java
+4
-4
Doclet.java
h2/src/tools/org/h2/build/doclet/Doclet.java
+1
-3
FtpClient.java
h2/src/tools/org/h2/dev/ftp/FtpClient.java
+3
-4
Condition.java
h2/src/tools/org/h2/jaqu/Condition.java
+1
-1
ConditionAndOr.java
h2/src/tools/org/h2/jaqu/ConditionAndOr.java
+1
-1
Function.java
h2/src/tools/org/h2/jaqu/Function.java
+20
-18
OrderExpression.java
h2/src/tools/org/h2/jaqu/OrderExpression.java
+1
-1
Query.java
h2/src/tools/org/h2/jaqu/Query.java
+16
-16
QueryWhere.java
h2/src/tools/org/h2/jaqu/QueryWhere.java
+1
-1
SQLStatement.java
h2/src/tools/org/h2/jaqu/SQLStatement.java
+15
-7
SelectColumn.java
h2/src/tools/org/h2/jaqu/SelectColumn.java
+1
-1
SelectTable.java
h2/src/tools/org/h2/jaqu/SelectTable.java
+2
-2
TableDefinition.java
h2/src/tools/org/h2/jaqu/TableDefinition.java
+19
-31
TestCondition.java
h2/src/tools/org/h2/jaqu/TestCondition.java
+6
-6
Token.java
h2/src/tools/org/h2/jaqu/Token.java
+1
-1
没有找到文件。
h2/src/main/org/h2/bnf/Bnf.java
浏览文件 @
e126424c
...
...
@@ -15,7 +15,6 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Random
;
import
java.util.StringTokenizer
;
...
...
@@ -301,8 +300,7 @@ public class Bnf {
* This method is called after updating the topics.
*/
public
void
linkStatements
()
{
for
(
Iterator
<
RuleHead
>
it
=
ruleMap
.
values
().
iterator
();
it
.
hasNext
();)
{
RuleHead
r
=
it
.
next
();
for
(
RuleHead
r
:
ruleMap
.
values
())
{
r
.
getRule
().
setLinks
(
ruleMap
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/bnf/RuleList.java
浏览文件 @
e126424c
...
...
@@ -9,6 +9,7 @@ package org.h2.bnf;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
/**
* Represents a sequence of BNF rules, or a list of alternative rules.
...
...
@@ -35,22 +36,18 @@ public class RuleList implements Rule {
}
public
String
toString
()
{
St
ringBuffer
buff
=
new
StringBuff
er
();
St
atementBuilder
buff
=
new
StatementBuild
er
();
if
(
or
)
{
buff
.
append
(
"{"
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
"|"
);
}
buff
.
append
(
list
.
get
(
i
).
toString
());
buff
.
append
(
'{'
);
for
(
Rule
r
:
list
)
{
buff
.
appendExceptFirst
(
"|"
);
buff
.
append
(
r
.
toString
());
}
buff
.
append
(
"}"
);
buff
.
append
(
'}'
);
}
else
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" "
);
}
buff
.
append
(
list
.
get
(
i
).
toString
());
for
(
Rule
r
:
list
)
{
buff
.
appendExceptFirst
(
" "
);
buff
.
append
(
r
.
toString
());
}
}
return
buff
.
toString
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e126424c
...
...
@@ -129,6 +129,7 @@ import org.h2.util.ByteUtils;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringCache
;
import
org.h2.util.StringUtils
;
import
org.h2.value.CompareMode
;
...
...
@@ -467,12 +468,10 @@ public class Parser {
if
(
expectedList
==
null
||
expectedList
.
size
()
==
0
)
{
return
Message
.
getSyntaxError
(
sqlCommand
,
parseIndex
);
}
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
expectedList
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
expectedList
.
get
(
i
));
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
String
e
:
expectedList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
);
}
return
Message
.
getSyntaxError
(
sqlCommand
,
parseIndex
,
buff
.
toString
());
}
...
...
@@ -1247,10 +1246,9 @@ public class Parser {
String
tableSchema
=
last
.
getTable
().
getSchema
().
getName
();
String
joinSchema
=
join
.
getTable
().
getSchema
().
getName
();
Expression
on
=
null
;
for
(
int
t
=
0
;
t
<
tableCols
.
length
;
t
++)
{
String
tableColumnName
=
tableCols
[
t
].
getName
();
for
(
int
j
=
0
;
j
<
joinCols
.
length
;
j
++)
{
Column
c
=
joinCols
[
j
];
for
(
Column
tc
:
tableCols
)
{
String
tableColumnName
=
tc
.
getName
();
for
(
Column
c
:
joinCols
)
{
String
joinColumnName
=
c
.
getName
();
if
(
tableColumnName
.
equals
(
joinColumnName
))
{
join
.
addNaturalJoinColumn
(
c
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Prepared.java
浏览文件 @
e126424c
...
...
@@ -19,6 +19,7 @@ import org.h2.jdbc.JdbcSQLException;
import
org.h2.message.Message
;
import
org.h2.result.LocalResult
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
/**
...
...
@@ -312,20 +313,14 @@ public abstract class Prepared {
long
time
=
System
.
currentTimeMillis
()
-
startTime
;
String
params
;
if
(
parameters
.
size
()
>
0
)
{
StringBuffer
buff
=
new
StringBuffer
(
parameters
.
size
()
*
10
);
buff
.
append
(
" {"
);
for
(
int
i
=
0
;
i
<
parameters
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
i
+
1
);
buff
.
append
(
": "
);
Expression
e
=
parameters
.
get
(
i
);
StatementBuilder
buff
=
new
StatementBuilder
(
" {"
);
int
i
=
0
;
for
(
Expression
e
:
parameters
)
{
buff
.
appendExceptFirst
(
", "
);
Value
v
=
e
.
getValue
(
session
);
buff
.
append
(
v
.
getTraceSQL
());
buff
.
append
(
++
i
).
append
(
": "
).
append
(
v
.
getTraceSQL
());
}
buff
.
append
(
"}"
);
params
=
buff
.
toString
();
params
=
buff
.
append
(
'}'
).
toString
();
}
else
{
params
=
""
;
}
...
...
@@ -377,12 +372,9 @@ public abstract class Prepared {
* @return the SQL snippet
*/
protected
String
getSQL
(
Value
[]
values
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Value
v
=
values
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
Value
v
:
values
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
v
!=
null
)
{
buff
.
append
(
v
.
getSQL
());
}
...
...
@@ -397,12 +389,9 @@ public abstract class Prepared {
* @return the SQL snippet
*/
protected
String
getSQL
(
Expression
[]
list
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
e
=
list
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
Expression
e
:
list
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
e
!=
null
)
{
buff
.
append
(
e
.
getSQL
());
}
...
...
@@ -427,9 +416,9 @@ public abstract class Prepared {
}
buff
.
append
(
" -- "
);
if
(
rowId
>
0
)
{
buff
.
append
(
"row #"
).
append
(
rowId
+
1
).
append
(
" "
);
buff
.
append
(
"row #"
).
append
(
rowId
+
1
).
append
(
' '
);
}
buff
.
append
(
"("
).
append
(
values
).
append
(
")"
);
buff
.
append
(
'('
).
append
(
values
).
append
(
')'
);
e
.
setSQL
(
buff
.
toString
());
}
return
ex
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
e126424c
...
...
@@ -335,12 +335,12 @@ public class AlterTableAddConstraint extends SchemaCommand {
if
(
indexCols
.
length
<
cols
.
length
)
{
return
false
;
}
for
(
int
j
=
0
;
j
<
cols
.
length
;
j
++
)
{
for
(
IndexColumn
col
:
cols
)
{
// all columns of the list must be part of the index,
// but not all columns of the index need to be part of the list
// holes are not allowed (index=a,b,c & list=a,b is ok; but list=a,c
// is not)
int
idx
=
existingIndex
.
getColumnIndex
(
col
s
[
j
]
.
column
);
int
idx
=
existingIndex
.
getColumnIndex
(
col
.
column
);
if
(
idx
<
0
||
idx
>=
cols
.
length
)
{
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
e126424c
...
...
@@ -256,7 +256,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
buff
.
append
(
" AS SELECT "
);
if
(
columnList
.
length
()
==
0
)
{
// special case insert into test select * from test
buff
.
append
(
"*"
);
buff
.
append
(
'*'
);
}
else
{
buff
.
append
(
columnList
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
e126424c
...
...
@@ -46,7 +46,7 @@ public class Analyze extends DefineCommand {
}
buff
.
append
(
"SELECTIVITY("
);
buff
.
append
(
columns
[
j
].
getSQL
());
buff
.
append
(
")"
);
buff
.
append
(
')'
);
}
buff
.
append
(
" FROM "
);
buff
.
append
(
table
.
getSQL
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
e126424c
...
...
@@ -22,6 +22,7 @@ import org.h2.result.Row;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
/**
...
...
@@ -137,30 +138,24 @@ public class Insert extends Prepared {
}
public
String
getPlanSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"INSERT INTO "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
buff
.
append
(
table
.
getSQL
()).
append
(
'('
);
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
")\n"
);
if
(
list
.
size
()
>
0
)
{
buff
.
append
(
"VALUES "
);
for
(
int
x
=
0
;
x
<
list
.
size
();
x
++)
{
Expression
[]
expr
=
list
.
get
(
x
);
if
(
x
>
0
)
{
int
row
=
0
;
for
(
Expression
[]
expr
:
list
)
{
if
(
row
++
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
"("
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
e
=
expr
[
i
];
buff
.
append
(
'('
);
buff
.
resetCount
();
for
(
Expression
e
:
expr
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
e
==
null
)
{
buff
.
append
(
"DEFAULT"
);
}
else
{
...
...
@@ -185,8 +180,7 @@ public class Insert extends Prepared {
}
}
if
(
list
.
size
()
>
0
)
{
for
(
int
x
=
0
;
x
<
list
.
size
();
x
++)
{
Expression
[]
expr
=
list
.
get
(
x
);
for
(
Expression
[]
expr
:
list
)
{
if
(
expr
.
length
!=
columns
.
length
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Merge.java
浏览文件 @
e126424c
...
...
@@ -23,6 +23,7 @@ import org.h2.result.Row;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
...
...
@@ -86,23 +87,17 @@ public class Merge extends Prepared {
}
keys
=
idx
.
getColumns
();
}
StringBuffer
buff
=
new
StringBuffer
(
"UPDATE "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
" SET "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
buff
.
append
(
"=?"
);
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
buff
.
append
(
table
.
getSQL
()).
append
(
" SET "
);
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
}
buff
.
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" AND "
);
}
buff
.
append
(
keys
[
i
].
getSQL
());
buff
.
append
(
"=?"
);
buff
.
resetCount
();
for
(
Column
c
:
keys
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
c
.
getSQL
()).
append
(
"=?"
);
}
String
sql
=
buff
.
toString
();
update
=
session
.
prepare
(
sql
);
...
...
@@ -121,7 +116,7 @@ public class Merge extends Prepared {
if
(
e
!=
null
)
{
// e can be null (DEFAULT)
try
{
Value
v
=
e
xpr
[
i
]
.
getValue
(
session
).
convertTo
(
c
.
getType
());
Value
v
=
e
.
getValue
(
session
).
convertTo
(
c
.
getType
());
newRow
.
setValue
(
index
,
v
);
}
catch
(
SQLException
ex
)
{
throw
setRow
(
ex
,
count
,
getSQL
(
expr
));
...
...
@@ -193,41 +188,34 @@ public class Merge extends Prepared {
}
public
String
getPlanSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"MERGE INTO "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
buff
.
append
(
table
.
getSQL
()).
append
(
'('
);
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
if
(
keys
!=
null
)
{
buff
.
append
(
" KEY("
);
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
keys
[
i
].
getSQL
());
buff
.
resetCount
();
for
(
Column
c
:
keys
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
}
buff
.
append
(
'\n'
);
if
(
list
.
size
()
>
0
)
{
buff
.
append
(
"VALUES "
);
for
(
int
x
=
0
;
x
<
list
.
size
();
x
++)
{
Expression
[]
expr
=
list
.
get
(
x
);
if
(
x
>
0
)
{
int
row
=
0
;
for
(
Expression
[]
expr
:
list
)
{
if
(
row
++
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
"("
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
e
=
expr
[
i
];
buff
.
append
(
'('
);
buff
.
resetCount
();
for
(
Expression
e
:
expr
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
e
==
null
)
{
buff
.
append
(
"DEFAULT"
);
}
else
{
...
...
@@ -252,8 +240,7 @@ public class Merge extends Prepared {
}
}
if
(
list
.
size
()
>
0
)
{
for
(
int
x
=
0
;
x
<
list
.
size
();
x
++)
{
Expression
[]
expr
=
list
.
get
(
x
);
for
(
Expression
[]
expr
:
list
)
{
if
(
expr
.
length
!=
columns
.
length
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
e126424c
...
...
@@ -259,7 +259,7 @@ public class ScriptCommand extends ScriptBase {
buff
.
append
(
v
.
getSQL
());
}
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
if
(
simple
||
buff
.
length
()
>
Constants
.
IO_BUFFER_SIZE
)
{
add
(
buff
.
toString
(),
true
);
buff
=
null
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
e126424c
...
...
@@ -38,6 +38,7 @@ import org.h2.table.TableFilter;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.Value
;
...
...
@@ -580,16 +581,14 @@ public class Select extends Query {
if
(
tableAlias
==
null
)
{
int
temp
=
i
;
expressions
.
remove
(
i
);
for
(
int
j
=
0
;
j
<
filters
.
size
();
j
++)
{
TableFilter
filter
=
filters
.
get
(
j
);
for
(
TableFilter
filter
:
filters
)
{
Wildcard
c2
=
new
Wildcard
(
filter
.
getTable
().
getSchema
().
getName
(),
filter
.
getTableAlias
());
expressions
.
add
(
i
++,
c2
);
}
i
=
temp
-
1
;
}
else
{
TableFilter
filter
=
null
;
for
(
int
j
=
0
;
j
<
filters
.
size
();
j
++)
{
TableFilter
f
=
filters
.
get
(
j
);
for
(
TableFilter
f
:
filters
)
{
if
(
tableAlias
.
equals
(
f
.
getTableAlias
()))
{
if
(
schemaName
==
null
||
schemaName
.
equals
(
f
.
getSchemaName
()))
{
filter
=
f
;
...
...
@@ -604,8 +603,7 @@ public class Select extends Query {
String
alias
=
filter
.
getTableAlias
();
expressions
.
remove
(
i
);
Column
[]
columns
=
t
.
getColumns
();
for
(
int
j
=
0
;
j
<
columns
.
length
;
j
++)
{
Column
c
=
columns
[
j
];
for
(
Column
c
:
columns
)
{
if
(
filter
.
isNaturalJoinColumn
(
c
))
{
continue
;
}
...
...
@@ -726,8 +724,7 @@ public class Select extends Query {
if
(
SysProperties
.
optimizeInJoin
)
{
condition
=
condition
.
optimizeInJoin
(
session
,
this
);
}
for
(
int
j
=
0
;
j
<
filters
.
size
();
j
++)
{
TableFilter
f
=
filters
.
get
(
j
);
for
(
TableFilter
f
:
filters
)
{
condition
.
createIndexConditions
(
session
,
f
);
}
}
...
...
@@ -852,62 +849,52 @@ public class Select extends Query {
// can not use the field sqlStatement because the parameter
// indexes may be incorrect: ? may be in fact ?2 for a subquery
// but indexes may be set manually as well
StringBuffer
buff
=
new
StringBuffer
();
Expression
[]
exprList
=
new
Expression
[
expressions
.
size
()];
expressions
.
toArray
(
exprList
);
buff
.
append
(
"SELECT "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT "
);
if
(
distinct
)
{
buff
.
append
(
"DISTINCT "
);
}
for
(
int
i
=
0
;
i
<
visibleColumnCount
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
expr
=
exprList
[
i
];
buff
.
append
(
expr
.
getSQL
());
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
exprList
[
i
].
getSQL
());
}
buff
.
append
(
"\nFROM "
);
TableFilter
filter
=
topTableFilter
;
if
(
filter
!=
null
)
{
buff
.
resetCount
();
int
i
=
0
;
do
{
if
(
i
>
0
)
{
buff
.
append
(
"\n"
);
}
buff
.
append
(
filter
.
getPlanSQL
(
i
>
0
));
i
++;
buff
.
appendExceptFirst
(
"\n"
);
buff
.
append
(
filter
.
getPlanSQL
(
i
++
>
0
));
filter
=
filter
.
getJoin
();
}
while
(
filter
!=
null
);
}
else
{
for
(
int
i
=
0
;
i
<
filters
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
"\n"
);
}
filter
=
filters
.
get
(
i
);
buff
.
append
(
filter
.
getPlanSQL
(
i
>
0
));
buff
.
resetCount
();
int
i
=
0
;
for
(
TableFilter
f
:
filters
)
{
buff
.
appendExceptFirst
(
"\n"
);
buff
.
append
(
f
.
getPlanSQL
(
i
++
>
0
));
}
}
if
(
condition
!=
null
)
{
buff
.
append
(
"\nWHERE "
+
StringUtils
.
unEnclose
(
condition
.
getSQL
()));
buff
.
append
(
"\nWHERE "
).
append
(
StringUtils
.
unEnclose
(
condition
.
getSQL
()));
}
if
(
groupIndex
!=
null
)
{
buff
.
append
(
"\nGROUP BY "
);
for
(
int
i
=
0
;
i
<
groupIndex
.
length
;
i
++)
{
Expression
g
=
exprList
[
groupIndex
[
i
]];
buff
.
resetCount
();
for
(
int
gi
:
groupIndex
)
{
Expression
g
=
exprList
[
gi
];
g
=
g
.
getNonAliasExpression
();
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
StringUtils
.
unEnclose
(
g
.
getSQL
()));
}
}
if
(
group
!=
null
)
{
buff
.
append
(
"\nGROUP BY "
);
for
(
int
i
=
0
;
i
<
group
.
size
();
i
++)
{
Expression
g
=
group
.
get
(
i
);
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
resetCount
();
for
(
Expression
g
:
group
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
StringUtils
.
unEnclose
(
g
.
getSQL
()));
}
}
...
...
@@ -916,31 +903,26 @@ public class Select extends Query {
// in this case the query is not run directly, just getPlanSQL is
// called
Expression
h
=
having
;
buff
.
append
(
"\nHAVING "
+
StringUtils
.
unEnclose
(
h
.
getSQL
()));
buff
.
append
(
"\nHAVING "
).
append
(
StringUtils
.
unEnclose
(
h
.
getSQL
()));
}
else
if
(
havingIndex
>=
0
)
{
Expression
h
=
exprList
[
havingIndex
];
buff
.
append
(
"\nHAVING "
+
StringUtils
.
unEnclose
(
h
.
getSQL
()));
buff
.
append
(
"\nHAVING "
).
append
(
StringUtils
.
unEnclose
(
h
.
getSQL
()));
}
if
(
sort
!=
null
)
{
buff
.
append
(
"\nORDER BY "
);
buff
.
append
(
sort
.
getSQL
(
exprList
,
visibleColumnCount
));
buff
.
append
(
"\nORDER BY "
).
append
(
sort
.
getSQL
(
exprList
,
visibleColumnCount
));
}
if
(
orderList
!=
null
)
{
buff
.
append
(
"\nORDER BY "
);
for
(
int
i
=
0
;
i
<
orderList
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
SelectOrderBy
o
=
orderList
.
get
(
i
);
buff
.
resetCount
();
for
(
SelectOrderBy
o
:
orderList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
StringUtils
.
unEnclose
(
o
.
getSQL
()));
}
}
if
(
limitExpr
!=
null
)
{
buff
.
append
(
"\nLIMIT "
);
buff
.
append
(
StringUtils
.
unEnclose
(
limitExpr
.
getSQL
()));
buff
.
append
(
"\nLIMIT "
).
append
(
StringUtils
.
unEnclose
(
limitExpr
.
getSQL
()));
if
(
offsetExpr
!=
null
)
{
buff
.
append
(
" OFFSET "
);
buff
.
append
(
StringUtils
.
unEnclose
(
offsetExpr
.
getSQL
()));
buff
.
append
(
" OFFSET "
).
append
(
StringUtils
.
unEnclose
(
offsetExpr
.
getSQL
()));
}
}
if
(
isForUpdate
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/SelectOrderBy.java
浏览文件 @
e126424c
...
...
@@ -43,8 +43,7 @@ public class SelectOrderBy {
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
if
(
expression
!=
null
)
{
buff
.
append
(
"="
);
buff
.
append
(
expression
.
getSQL
());
buff
.
append
(
'='
).
append
(
expression
.
getSQL
());
}
else
{
buff
.
append
(
columnIndexExpr
.
getSQL
());
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
e126424c
...
...
@@ -131,7 +131,7 @@ public class ConstraintCheck extends Constraint {
buff
.
append
(
filter
.
getTable
().
getSQL
());
buff
.
append
(
" WHERE NOT("
);
buff
.
append
(
expr
.
getSQL
());
buff
.
append
(
")"
);
buff
.
append
(
')'
);
String
sql
=
buff
.
toString
();
LocalResult
r
=
session
.
prepare
(
sql
).
query
(
1
);
if
(
r
.
next
())
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
e126424c
...
...
@@ -25,6 +25,7 @@ import org.h2.table.Column;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -74,7 +75,7 @@ public class ConstraintReferential extends Constraint {
return
Constraint
.
REFERENTIAL
;
}
private
void
appendAction
(
St
ringBuff
er
buff
,
int
action
)
{
private
void
appendAction
(
St
atementBuild
er
buff
,
int
action
)
{
switch
(
action
)
{
case
CASCADE:
buff
.
append
(
"CASCADE"
);
...
...
@@ -111,29 +112,22 @@ public class ConstraintReferential extends Constraint {
* @return the SQL statement
*/
public
String
getCreateSQLForCopy
(
Table
forTable
,
Table
forRefTable
,
String
quotedName
,
boolean
internalIndex
)
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"ALTER TABLE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
String
mainTable
=
forTable
.
getSQL
();
buff
.
append
(
mainTable
);
buff
.
append
(
" ADD CONSTRAINT "
);
buff
.
append
(
quotedName
);
buff
.
append
(
mainTable
).
append
(
" ADD CONSTRAINT "
).
append
(
quotedName
);
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
IndexColumn
[]
cols
=
columns
;
IndexColumn
[]
refCols
=
refColumns
;
buff
.
append
(
" FOREIGN KEY("
);
for
(
int
i
=
0
;
i
<
cols
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
cols
[
i
].
getSQL
());
for
(
IndexColumn
c
:
cols
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
if
(
internalIndex
&&
indexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
);
buff
.
append
(
index
.
getSQL
());
buff
.
append
(
" INDEX "
).
append
(
index
.
getSQL
());
}
buff
.
append
(
" REFERENCES "
);
String
quotedRefTable
;
...
...
@@ -143,18 +137,15 @@ public class ConstraintReferential extends Constraint {
}
else
{
quotedRefTable
=
forRefTable
.
getSQL
();
}
buff
.
append
(
quotedRefTable
);
buff
.
append
(
"("
);
for
(
int
i
=
0
;
i
<
refCols
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
refCols
[
i
].
getSQL
());
buff
.
append
(
quotedRefTable
).
append
(
'('
);
buff
.
resetCount
();
for
(
IndexColumn
r
:
refCols
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
r
.
getSQL
());
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
if
(
internalIndex
&&
refIndexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
);
buff
.
append
(
refIndex
.
getSQL
());
buff
.
append
(
" INDEX "
).
append
(
refIndex
.
getSQL
());
}
if
(
deleteAction
!=
RESTRICT
)
{
buff
.
append
(
" ON DELETE "
);
...
...
@@ -164,8 +155,7 @@ public class ConstraintReferential extends Constraint {
buff
.
append
(
" ON UPDATE "
);
appendAction
(
buff
,
updateAction
);
}
buff
.
append
(
" NOCHECK"
);
return
buff
.
toString
();
return
buff
.
append
(
" NOCHECK"
).
toString
();
}
...
...
@@ -176,29 +166,19 @@ public class ConstraintReferential extends Constraint {
* @return the description
*/
public
String
getShortDescription
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
getName
());
buff
.
append
(
": "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
" FOREIGN KEY("
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
StatementBuilder
buff
=
new
StatementBuilder
(
getName
());
buff
.
append
(
": "
).
append
(
table
.
getSQL
()).
append
(
" FOREIGN KEY("
);
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
")"
);
buff
.
append
(
" REFERENCES "
);
buff
.
append
(
refTable
.
getSQL
());
buff
.
append
(
"("
);
for
(
int
i
=
0
;
i
<
refColumns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
refColumns
[
i
].
getSQL
());
buff
.
append
(
") REFERENCES "
).
append
(
refTable
.
getSQL
()).
append
(
'('
);
buff
.
resetCount
();
for
(
IndexColumn
r
:
refColumns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
r
.
getSQL
());
}
buff
.
append
(
")"
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
String
getCreateSQLWithoutIndexes
()
{
...
...
@@ -484,10 +464,9 @@ public class ConstraintReferential extends Constraint {
if
(
deleteAction
==
RESTRICT
)
{
return
;
}
St
ringBuffer
buff
=
new
StringBuff
er
();
St
atementBuilder
buff
=
new
StatementBuild
er
();
if
(
deleteAction
==
CASCADE
)
{
buff
.
append
(
"DELETE FROM "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
"DELETE FROM "
).
append
(
table
.
getSQL
());
}
else
{
appendUpdate
(
buff
);
}
...
...
@@ -527,7 +506,7 @@ public class ConstraintReferential extends Constraint {
if
(
updateAction
==
RESTRICT
)
{
return
;
}
St
ringBuffer
buff
=
new
StringBuff
er
();
St
atementBuilder
buff
=
new
StatementBuild
er
();
appendUpdate
(
buff
);
appendWhere
(
buff
);
updateSQL
=
buff
.
toString
();
...
...
@@ -561,29 +540,21 @@ public class ConstraintReferential extends Constraint {
return
command
;
}
private
void
appendUpdate
(
StringBuffer
buff
)
{
buff
.
append
(
"UPDATE "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
" SET "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" , "
);
}
Column
column
=
columns
[
i
].
column
;
buff
.
append
(
Parser
.
quoteIdentifier
(
column
.
getName
()));
buff
.
append
(
"=?"
);
private
void
appendUpdate
(
StatementBuilder
buff
)
{
buff
.
append
(
"UPDATE "
).
append
(
table
.
getSQL
()).
append
(
" SET "
);
buff
.
resetCount
();
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
" , "
);
buff
.
append
(
Parser
.
quoteIdentifier
(
c
.
column
.
getName
())).
append
(
"=?"
);
}
}
private
void
appendWhere
(
St
ringBuff
er
buff
)
{
private
void
appendWhere
(
St
atementBuild
er
buff
)
{
buff
.
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" AND "
);
}
Column
column
=
columns
[
i
].
column
;
buff
.
append
(
Parser
.
quoteIdentifier
(
column
.
getName
()));
buff
.
append
(
"=?"
);
buff
.
resetCount
();
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
Parser
.
quoteIdentifier
(
c
.
column
.
getName
())).
append
(
"=?"
);
}
}
...
...
@@ -628,45 +599,33 @@ public class ConstraintReferential extends Constraint {
// don't check at startup
return
;
}
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"SELECT 1 FROM (SELECT "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT 1 FROM (SELECT "
);
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
" FROM "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" AND "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
buff
.
append
(
" IS NOT NULL "
);
buff
.
append
(
" FROM "
).
append
(
table
.
getSQL
()).
append
(
" WHERE "
);
buff
.
resetCount
();
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
c
.
getSQL
()).
append
(
" IS NOT NULL "
);
}
buff
.
append
(
" ORDER BY "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
buff
.
resetCount
();
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
") C WHERE NOT EXISTS(SELECT 1 FROM "
);
buff
.
append
(
refTable
.
getSQL
());
buff
.
append
(
" P WHERE "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" AND "
);
}
buff
.
append
(
"C."
);
buff
.
append
(
columns
[
i
].
getSQL
());
buff
.
append
(
"="
);
buff
.
append
(
"P."
);
buff
.
append
(
refColumns
[
i
].
getSQL
());
buff
.
append
(
refTable
.
getSQL
()).
append
(
" P WHERE "
);
buff
.
resetCount
();
int
i
=
0
;
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
"C."
).
append
(
c
.
getSQL
()).
append
(
'='
);
buff
.
append
(
"P."
).
append
(
refColumns
[
i
++].
getSQL
());
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
String
sql
=
buff
.
toString
();
LocalResult
r
=
session
.
prepare
(
sql
).
query
(
1
);
if
(
r
.
next
())
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constraint/ConstraintUnique.java
浏览文件 @
e126424c
...
...
@@ -16,6 +16,7 @@ import org.h2.schema.Schema;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -42,28 +43,19 @@ public class ConstraintUnique extends Constraint {
}
private
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
,
boolean
internalIndex
)
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"ALTER TABLE "
);
buff
.
append
(
forTable
.
getSQL
());
buff
.
append
(
" ADD CONSTRAINT "
);
buff
.
append
(
quotedName
);
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
buff
.
append
(
forTable
.
getSQL
()).
append
(
" ADD CONSTRAINT "
).
append
(
quotedName
);
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
buff
.
append
(
' '
);
buff
.
append
(
getTypeName
());
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
Parser
.
quoteIdentifier
(
columns
[
i
].
column
.
getName
()));
buff
.
append
(
' '
).
append
(
getTypeName
()).
append
(
'('
);
for
(
IndexColumn
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
Parser
.
quoteIdentifier
(
c
.
column
.
getName
()));
}
buff
.
append
(
')'
);
if
(
internalIndex
&&
indexOwner
&&
forTable
==
this
.
table
)
{
buff
.
append
(
" INDEX "
);
buff
.
append
(
index
.
getSQL
());
buff
.
append
(
" INDEX "
).
append
(
index
.
getSQL
());
}
return
buff
.
toString
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/FunctionAlias.java
浏览文件 @
e126424c
...
...
@@ -21,6 +21,7 @@ import org.h2.message.Trace;
import
org.h2.table.Table
;
import
org.h2.util.ClassUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -72,8 +73,7 @@ public class FunctionAlias extends DbObjectBase {
}
if
(
m
.
getName
().
equals
(
methodName
)
||
getMethodSignature
(
m
).
equals
(
methodName
))
{
JavaMethod
javaMethod
=
new
JavaMethod
(
m
,
i
);
for
(
int
j
=
0
;
j
<
list
.
size
();
j
++)
{
JavaMethod
old
=
list
.
get
(
j
);
for
(
JavaMethod
old
:
list
)
{
if
(
old
.
getParameterCount
()
==
javaMethod
.
getParameterCount
())
{
throw
Message
.
getSQLException
(
ErrorCode
.
METHODS_MUST_HAVE_DIFFERENT_PARAMETER_COUNTS_2
,
new
String
[]
{
...
...
@@ -99,24 +99,17 @@ public class FunctionAlias extends DbObjectBase {
}
private
String
getMethodSignature
(
Method
m
)
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
m
.
getName
());
StatementBuilder
buff
=
new
StatementBuilder
(
m
.
getName
());
buff
.
append
(
'('
);
Class
<
?
>[]
params
=
m
.
getParameterTypes
();
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Class
<
?
>
p
=
params
[
i
];
for
(
Class
<
?
>
p
:
m
.
getParameterTypes
())
{
buff
.
appendExceptFirst
(
", "
);
if
(
p
.
isArray
())
{
buff
.
append
(
p
.
getComponentType
().
getName
());
buff
.
append
(
"[]"
);
buff
.
append
(
p
.
getComponentType
().
getName
()).
append
(
"[]"
);
}
else
{
buff
.
append
(
p
.
getName
());
}
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/User.java
浏览文件 @
e126424c
...
...
@@ -149,7 +149,7 @@ public class User extends RightOwner {
buff
.
append
(
ByteUtils
.
convertBytesToString
(
salt
));
buff
.
append
(
"' HASH '"
);
buff
.
append
(
ByteUtils
.
convertBytesToString
(
passwordHash
));
buff
.
append
(
"'"
);
buff
.
append
(
'\''
);
}
else
{
buff
.
append
(
" PASSWORD ''"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/Aggregate.java
浏览文件 @
e126424c
...
...
@@ -9,7 +9,6 @@ package org.h2.expression;
import
java.sql.SQLException
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
org.h2.command.dml.Select
;
import
org.h2.command.dml.SelectOrderBy
;
import
org.h2.constant.ErrorCode
;
...
...
@@ -26,7 +25,7 @@ import org.h2.table.Table;
import
org.h2.table.TableFilter
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.
ObjectUtils
;
import
org.h2.util.
StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
...
...
@@ -169,7 +168,7 @@ public class Aggregate extends Expression {
}
private
static
void
addAggregate
(
String
name
,
int
type
)
{
AGGREGATES
.
put
(
name
,
ObjectUtils
.
getInteger
(
type
)
);
AGGREGATES
.
put
(
name
,
type
);
}
/**
...
...
@@ -314,10 +313,9 @@ public class Aggregate extends Expression {
throw
Message
.
convert
(
e
);
}
}
St
ringBuffer
buff
=
new
StringBuff
er
();
St
atementBuilder
buff
=
new
StatementBuild
er
();
String
sep
=
separator
==
null
?
","
:
separator
.
getValue
(
session
).
getString
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Value
val
=
list
.
get
(
i
);
for
(
Value
val
:
list
)
{
String
s
;
if
(
val
.
getType
()
==
Value
.
ARRAY
)
{
s
=
((
ValueArray
)
val
).
getList
()[
0
].
getString
();
...
...
@@ -327,8 +325,8 @@ public class Aggregate extends Expression {
if
(
s
==
null
)
{
continue
;
}
if
(
i
>
0
&&
sep
!=
null
)
{
buff
.
append
(
sep
);
if
(
sep
!=
null
)
{
buff
.
append
ExceptFirst
(
sep
);
}
buff
.
append
(
s
);
}
...
...
@@ -346,8 +344,7 @@ public class Aggregate extends Expression {
on
.
mapColumns
(
resolver
,
level
);
}
if
(
orderList
!=
null
)
{
for
(
int
i
=
0
;
i
<
orderList
.
size
();
i
++)
{
SelectOrderBy
o
=
orderList
.
get
(
i
);
for
(
SelectOrderBy
o
:
orderList
)
{
o
.
expression
.
mapColumns
(
resolver
,
level
);
}
}
...
...
@@ -365,8 +362,7 @@ public class Aggregate extends Expression {
displaySize
=
on
.
getDisplaySize
();
}
if
(
orderList
!=
null
)
{
for
(
int
i
=
0
;
i
<
orderList
.
size
();
i
++)
{
SelectOrderBy
o
=
orderList
.
get
(
i
);
for
(
SelectOrderBy
o
:
orderList
)
{
o
.
expression
=
o
.
expression
.
optimize
(
session
);
}
sort
=
initOrder
(
session
);
...
...
@@ -435,8 +431,7 @@ public class Aggregate extends Expression {
on
.
setEvaluatable
(
tableFilter
,
b
);
}
if
(
orderList
!=
null
)
{
for
(
int
i
=
0
;
i
<
orderList
.
size
();
i
++)
{
SelectOrderBy
o
=
orderList
.
get
(
i
);
for
(
SelectOrderBy
o
:
orderList
)
{
o
.
expression
.
setEvaluatable
(
tableFilter
,
b
);
}
}
...
...
@@ -458,16 +453,12 @@ public class Aggregate extends Expression {
}
private
String
getSQLGroupConcat
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"GROUP_CONCAT("
);
StatementBuilder
buff
=
new
StatementBuilder
(
"GROUP_CONCAT("
);
buff
.
append
(
on
.
getSQL
());
if
(
orderList
!=
null
)
{
buff
.
append
(
" ORDER BY "
);
for
(
int
i
=
0
;
i
<
orderList
.
size
();
i
++)
{
SelectOrderBy
o
=
orderList
.
get
(
i
);
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
for
(
SelectOrderBy
o
:
orderList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
o
.
expression
.
getSQL
());
if
(
o
.
descending
)
{
buff
.
append
(
" DESC"
);
...
...
@@ -475,11 +466,9 @@ public class Aggregate extends Expression {
}
}
if
(
separator
!=
null
)
{
buff
.
append
(
" SEPARATOR "
);
buff
.
append
(
separator
.
getSQL
());
buff
.
append
(
" SEPARATOR "
).
append
(
separator
.
getSQL
());
}
buff
.
append
(
")"
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
String
getSQL
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/AggregateData.java
浏览文件 @
e126424c
...
...
@@ -246,9 +246,8 @@ class AggregateData {
count
=
distinctValues
.
size
();
}
else
{
count
=
0
;
ObjectArray
<
Value
>
l2
=
distinctValues
.
keys
();
for
(
int
i
=
0
;
i
<
l2
.
size
();
i
++)
{
add
(
database
,
false
,
l2
.
get
(
i
));
for
(
Value
v
:
distinctValues
.
keys
())
{
add
(
database
,
false
,
v
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/CompareLike.java
浏览文件 @
e126424c
...
...
@@ -339,8 +339,8 @@ public class CompareLike extends Condition {
if
(
types
==
null
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
types
.
length
;
i
++
)
{
if
(
type
s
[
i
]
!=
MATCH
)
{
for
(
int
type
:
types
)
{
if
(
type
!=
MATCH
)
{
return
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/ConditionExists.java
浏览文件 @
e126424c
...
...
@@ -41,11 +41,8 @@ public class ConditionExists extends Condition {
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"EXISTS("
);
buff
.
append
(
query
.
getPlanSQL
());
buff
.
append
(
")"
);
return
buff
.
toString
();
StringBuffer
buff
=
new
StringBuffer
(
"EXISTS("
);
return
buff
.
append
(
query
.
getPlanSQL
()).
append
(
')'
).
toString
();
}
public
void
updateAggregate
(
Session
session
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/ConditionIn.java
浏览文件 @
e126424c
...
...
@@ -21,6 +21,7 @@ import org.h2.table.ColumnResolver;
import
org.h2.table.FunctionTable
;
import
org.h2.table.TableFilter
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.CompareMode
;
import
org.h2.value.Value
;
import
org.h2.value.ValueBoolean
;
...
...
@@ -53,8 +54,7 @@ public class ConditionIn extends Condition {
}
boolean
result
=
false
;
boolean
hasNull
=
false
;
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Expression
e
=
values
.
get
(
i
);
for
(
Expression
e
:
values
)
{
Value
r
=
e
.
getValue
(
session
);
if
(
r
==
ValueNull
.
INSTANCE
)
{
hasNull
=
true
;
...
...
@@ -73,8 +73,7 @@ public class ConditionIn extends Condition {
public
void
mapColumns
(
ColumnResolver
resolver
,
int
queryLevel
)
throws
SQLException
{
left
.
mapColumns
(
resolver
,
queryLevel
);
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Expression
e
=
values
.
get
(
i
);
for
(
Expression
e
:
values
)
{
e
.
mapColumns
(
resolver
,
queryLevel
);
}
this
.
queryLevel
=
Math
.
max
(
queryLevel
,
this
.
queryLevel
);
...
...
@@ -157,31 +156,24 @@ public class ConditionIn extends Condition {
public
void
setEvaluatable
(
TableFilter
tableFilter
,
boolean
b
)
{
left
.
setEvaluatable
(
tableFilter
,
b
);
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Expression
e
=
values
.
get
(
i
);
for
(
Expression
e
:
values
)
{
e
.
setEvaluatable
(
tableFilter
,
b
);
}
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
(
"("
);
buff
.
append
(
left
.
getSQL
());
buff
.
append
(
" IN("
);
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
e
=
values
.
get
(
i
);
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
buff
.
append
(
left
.
getSQL
()).
append
(
" IN("
);
for
(
Expression
e
:
values
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
}
buff
.
append
(
"))"
);
return
buff
.
toString
();
return
buff
.
append
(
"))"
).
toString
();
}
public
void
updateAggregate
(
Session
session
)
throws
SQLException
{
left
.
updateAggregate
(
session
);
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Expression
e
=
values
.
get
(
i
);
for
(
Expression
e
:
values
)
{
e
.
updateAggregate
(
session
);
}
}
...
...
@@ -194,8 +186,7 @@ public class ConditionIn extends Condition {
}
private
boolean
areAllValues
(
ExpressionVisitor
visitor
)
{
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Expression
e
=
values
.
get
(
i
);
for
(
Expression
e
:
values
)
{
if
(!
e
.
isEverything
(
visitor
))
{
return
false
;
}
...
...
@@ -205,8 +196,7 @@ public class ConditionIn extends Condition {
public
int
getCost
()
{
int
cost
=
left
.
getCost
();
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Expression
e
=
values
.
get
(
i
);
for
(
Expression
e
:
values
)
{
cost
+=
e
.
getCost
();
}
return
cost
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
e126424c
...
...
@@ -78,15 +78,13 @@ public class ExpressionColumn extends Expression {
if
(
schemaName
!=
null
&&
!
schemaName
.
equals
(
resolver
.
getSchemaName
()))
{
return
;
}
Column
[]
columns
=
resolver
.
getColumns
();
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
Column
col
=
columns
[
i
];
for
(
Column
col
:
resolver
.
getColumns
())
{
if
(
columnName
.
equals
(
col
.
getName
()))
{
mapColumn
(
resolver
,
col
,
level
);
return
;
}
}
columns
=
resolver
.
getSystemColumns
();
Column
[]
columns
=
resolver
.
getSystemColumns
();
for
(
int
i
=
0
;
columns
!=
null
&&
i
<
columns
.
length
;
i
++)
{
Column
col
=
columns
[
i
];
if
(
columnName
.
equals
(
col
.
getName
()))
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/ExpressionList.java
浏览文件 @
e126424c
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
org.h2.engine.Session
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -39,8 +40,8 @@ public class ExpressionList extends Expression {
}
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++
)
{
list
[
i
]
.
mapColumns
(
resolver
,
level
);
for
(
Expression
e
:
list
)
{
e
.
mapColumns
(
resolver
,
level
);
}
}
...
...
@@ -60,8 +61,8 @@ public class ExpressionList extends Expression {
}
public
void
setEvaluatable
(
TableFilter
tableFilter
,
boolean
b
)
{
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++
)
{
list
[
i
]
.
setEvaluatable
(
tableFilter
,
b
);
for
(
Expression
e
:
list
)
{
e
.
setEvaluatable
(
tableFilter
,
b
);
}
}
...
...
@@ -78,27 +79,23 @@ public class ExpressionList extends Expression {
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
list
[
i
].
getSQL
());
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
for
(
Expression
e:
list
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
void
updateAggregate
(
Session
session
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++
)
{
list
[
i
]
.
updateAggregate
(
session
);
for
(
Expression
e
:
list
)
{
e
.
updateAggregate
(
session
);
}
}
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++
)
{
if
(!
list
[
i
]
.
isEverything
(
visitor
))
{
for
(
Expression
e
:
list
)
{
if
(!
e
.
isEverything
(
visitor
))
{
return
false
;
}
}
...
...
@@ -107,8 +104,8 @@ public class ExpressionList extends Expression {
public
int
getCost
()
{
int
cost
=
1
;
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++
)
{
cost
+=
list
[
i
]
.
getCost
();
for
(
Expression
e
:
list
)
{
cost
+=
e
.
getCost
();
}
return
cost
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/Function.java
浏览文件 @
e126424c
...
...
@@ -50,6 +50,7 @@ import org.h2.util.MemoryUtils;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
...
...
@@ -538,8 +539,8 @@ public class Function extends Expression implements FunctionCall {
break
;
case
CONCAT:
{
result
=
ValueNull
.
INSTANCE
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
Value
v
=
args
[
i
]
.
getValue
(
session
);
for
(
Expression
e
:
args
)
{
Value
v
=
e
.
getValue
(
session
);
if
(
v
==
ValueNull
.
INSTANCE
)
{
continue
;
}
...
...
@@ -830,8 +831,7 @@ public class Function extends Expression implements FunctionCall {
private
boolean
cancelStatement
(
Session
session
,
int
targetSessionId
)
throws
SQLException
{
session
.
getUser
().
checkAdmin
();
Session
[]
sessions
=
session
.
getDatabase
().
getSessions
(
false
);
for
(
int
i
=
0
;
i
<
sessions
.
length
;
i
++)
{
Session
s
=
sessions
[
i
];
for
(
Session
s
:
sessions
)
{
if
(
s
.
getId
()
==
targetSessionId
)
{
Command
c
=
s
.
getCurrentCommand
();
if
(
c
==
null
)
{
...
...
@@ -1488,8 +1488,8 @@ public class Function extends Expression implements FunctionCall {
}
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
args
[
i
]
.
mapColumns
(
resolver
,
level
);
for
(
Expression
e
:
args
)
{
e
.
mapColumns
(
resolver
,
level
);
}
}
...
...
@@ -1626,8 +1626,7 @@ public class Function extends Expression implements FunctionCall {
s
=
0
;
p
=
0
;
d
=
0
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
ValueExpression
.
getNull
()
&&
e
.
getType
()
!=
Value
.
UNKNOWN
)
{
t
=
Value
.
getHigherOrder
(
t
,
e
.
getType
());
s
=
Math
.
max
(
s
,
e
.
getScale
());
...
...
@@ -1732,8 +1731,7 @@ public class Function extends Expression implements FunctionCall {
}
public
void
setEvaluatable
(
TableFilter
tableFilter
,
boolean
b
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
)
{
e
.
setEvaluatable
(
tableFilter
,
b
);
}
...
...
@@ -1776,9 +1774,9 @@ public class Function extends Expression implements FunctionCall {
case
CONCAT:
precision
=
0
;
displaySize
=
0
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
precision
+=
args
[
i
]
.
getPrecision
();
displaySize
=
MathUtils
.
convertLongToInt
((
long
)
displaySize
+
args
[
i
]
.
getDisplaySize
());
for
(
Expression
e
:
args
)
{
precision
+=
e
.
getPrecision
();
displaySize
=
MathUtils
.
convertLongToInt
((
long
)
displaySize
+
e
.
getDisplaySize
());
if
(
precision
<
0
)
{
precision
=
Long
.
MAX_VALUE
;
}
...
...
@@ -1823,46 +1821,38 @@ public class Function extends Expression implements FunctionCall {
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
info
.
name
);
StatementBuilder
buff
=
new
StatementBuilder
(
info
.
name
);
buff
.
append
(
'('
);
switch
(
info
.
type
)
{
case
CAST:
{
buff
.
append
(
args
[
0
].
getSQL
())
;
buff
.
append
(
" AS "
);
buff
.
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
());
buff
.
append
(
args
[
0
].
getSQL
())
.
append
(
" AS "
).
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
());
break
;
}
case
CONVERT:
{
buff
.
append
(
args
[
0
].
getSQL
())
;
buff
.
append
(
","
);
buff
.
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
());
buff
.
append
(
args
[
0
].
getSQL
())
.
append
(
","
).
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
());
break
;
}
case
EXTRACT:
{
ValueString
v
=
(
ValueString
)
((
ValueExpression
)
args
[
0
]).
getValue
(
null
);
buff
.
append
(
v
.
getString
());
buff
.
append
(
" FROM "
);
buff
.
append
(
args
[
1
].
getSQL
());
buff
.
append
(
v
.
getString
()).
append
(
" FROM "
).
append
(
args
[
1
].
getSQL
());
break
;
}
default
:
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
}
}
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
void
updateAggregate
(
Session
session
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
)
{
e
.
updateAggregate
(
session
);
}
...
...
@@ -1933,8 +1923,7 @@ public class Function extends Expression implements FunctionCall {
if
(
visitor
.
getType
()
==
ExpressionVisitor
.
DETERMINISTIC
&&
!
info
.
deterministic
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
&&
!
e
.
isEverything
(
visitor
))
{
return
false
;
}
...
...
@@ -1944,8 +1933,8 @@ public class Function extends Expression implements FunctionCall {
public
int
getCost
()
{
int
cost
=
3
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
cost
+=
args
[
i
]
.
getCost
();
for
(
Expression
e
:
args
)
{
cost
+=
e
.
getCost
();
}
return
cost
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/JavaAggregate.java
浏览文件 @
e126424c
...
...
@@ -19,6 +19,7 @@ import org.h2.engine.UserAggregate;
import
org.h2.message.Message
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -45,8 +46,8 @@ public class JavaAggregate extends Expression {
public
int
getCost
()
{
int
cost
=
5
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
cost
+=
args
[
i
]
.
getCost
();
for
(
Expression
e
:
args
)
{
cost
+=
e
.
getCost
();
}
return
cost
;
}
...
...
@@ -64,18 +65,13 @@ public class JavaAggregate extends Expression {
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
Parser
.
quoteIdentifier
(
userAggregate
.
getName
()));
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
e
=
args
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
buff
.
append
(
Parser
.
quoteIdentifier
(
userAggregate
.
getName
())).
append
(
'('
);
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
int
getType
()
{
...
...
@@ -96,8 +92,7 @@ public class JavaAggregate extends Expression {
return
false
;
default
:
}
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
&&
!
e
.
isEverything
(
visitor
))
{
return
false
;
}
...
...
@@ -128,8 +123,8 @@ public class JavaAggregate extends Expression {
}
public
void
setEvaluatable
(
TableFilter
tableFilter
,
boolean
b
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
args
[
i
]
.
setEvaluatable
(
tableFilter
,
b
);
for
(
Expression
e
:
args
)
{
e
.
setEvaluatable
(
tableFilter
,
b
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/JavaFunction.java
浏览文件 @
e126424c
...
...
@@ -13,6 +13,7 @@ import org.h2.engine.FunctionAlias;
import
org.h2.engine.Session
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -42,8 +43,8 @@ public class JavaFunction extends Expression implements FunctionCall {
}
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
args
[
i
]
.
mapColumns
(
resolver
,
level
);
for
(
Expression
e
:
args
)
{
e
.
mapColumns
(
resolver
,
level
);
}
}
...
...
@@ -61,8 +62,7 @@ public class JavaFunction extends Expression implements FunctionCall {
}
public
void
setEvaluatable
(
TableFilter
tableFilter
,
boolean
b
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
)
{
e
.
setEvaluatable
(
tableFilter
,
b
);
}
...
...
@@ -82,23 +82,17 @@ public class JavaFunction extends Expression implements FunctionCall {
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getName
()));
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Expression
e
=
args
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
buff
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getName
())).
append
(
'('
);
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
void
updateAggregate
(
Session
session
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
)
{
e
.
updateAggregate
(
session
);
}
...
...
@@ -135,8 +129,7 @@ public class JavaFunction extends Expression implements FunctionCall {
break
;
default
:
}
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
];
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
&&
!
e
.
isEverything
(
visitor
))
{
return
false
;
}
...
...
@@ -146,8 +139,8 @@ public class JavaFunction extends Expression implements FunctionCall {
public
int
getCost
()
{
int
cost
=
javaMethod
.
hasConnectionParam
()
?
25
:
5
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++
)
{
cost
+=
args
[
i
]
.
getCost
();
for
(
Expression
e
:
args
)
{
cost
+=
e
.
getCost
();
}
return
cost
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/TableFunction.java
浏览文件 @
e126424c
...
...
@@ -17,6 +17,7 @@ import org.h2.table.Column;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.MathUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -49,20 +50,14 @@ public class TableFunction extends Function {
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
getName
());
StatementBuilder
buff
=
new
StatementBuilder
(
getName
());
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columnList
[
i
].
getCreateSQL
());
buff
.
append
(
"="
);
Expression
e
=
args
[
i
];
buff
.
append
(
e
.
getSQL
());
int
i
=
0
;
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
columnList
[
i
++].
getCreateSQL
()).
append
(
"="
).
append
(
e
.
getSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/fulltext/FullText.java
浏览文件 @
e126424c
...
...
@@ -39,6 +39,7 @@ import org.h2.util.ByteUtils;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
...
...
@@ -871,23 +872,18 @@ public class FullText {
}
private
String
getKey
(
Object
[]
row
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
index
.
keys
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" AND "
);
}
int
columnIndex
=
index
.
keys
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
int
columnIndex
:
index
.
keys
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
StringUtils
.
quoteIdentifier
(
index
.
columns
[
columnIndex
]));
Object
o
=
row
[
columnIndex
];
if
(
o
==
null
)
{
buff
.
append
(
" IS NULL"
);
}
else
{
buff
.
append
(
"="
);
buff
.
append
(
quoteSQL
(
o
,
columnTypes
[
columnIndex
]));
buff
.
append
(
'='
).
append
(
quoteSQL
(
o
,
columnTypes
[
columnIndex
]));
}
}
String
key
=
buff
.
toString
();
return
key
;
return
buff
.
toString
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/fulltext/FullTextLucene.java
浏览文件 @
e126424c
...
...
@@ -40,6 +40,7 @@ import org.h2.store.fs.FileSystem;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
//## Java 1.4 end ##
...
...
@@ -498,19 +499,16 @@ public class FullTextLucene extends FullText {
doc
.
add
(
new
Field
(
FIELD_QUERY
,
query
,
Field
.
Store
.
YES
,
Field
.
Index
.
UN_TOKENIZED
));
long
time
=
System
.
currentTimeMillis
();
doc
.
add
(
new
Field
(
"modified"
,
DateTools
.
timeToString
(
time
,
DateTools
.
Resolution
.
SECOND
),
Field
.
Store
.
YES
,
Field
.
Index
.
UN_TOKENIZED
));
StringBuffer
allData
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
indexColumns
.
length
;
i
++)
{
int
index
=
indexColumns
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
int
index
:
indexColumns
)
{
String
columnName
=
columns
[
index
];
String
data
=
asString
(
row
[
index
],
columnTypes
[
index
]);
doc
.
add
(
new
Field
(
FIELD_COLUMN_PREFIX
+
columnName
,
data
,
Field
.
Store
.
NO
,
Field
.
Index
.
TOKENIZED
));
if
(
i
>
0
)
{
allData
.
append
(
" "
);
}
allData
.
append
(
data
);
buff
.
appendExceptFirst
(
" "
);
buff
.
append
(
data
);
}
Field
.
Store
storeText
=
STORE_DOCUMENT_TEXT_IN_INDEX
?
Field
.
Store
.
YES
:
Field
.
Store
.
NO
;
doc
.
add
(
new
Field
(
FIELD_DATA
,
allData
.
toString
(),
storeText
,
doc
.
add
(
new
Field
(
FIELD_DATA
,
buff
.
toString
(),
storeText
,
Field
.
Index
.
TOKENIZED
));
try
{
indexModifier
.
addDocument
(
doc
);
...
...
@@ -530,29 +528,22 @@ public class FullTextLucene extends FullText {
}
private
String
getQuery
(
Object
[]
row
)
throws
SQLException
{
St
ringBuffer
buff
=
new
StringBuff
er
();
St
atementBuilder
buff
=
new
StatementBuild
er
();
if
(
schema
!=
null
)
{
buff
.
append
(
StringUtils
.
quoteIdentifier
(
schema
));
buff
.
append
(
"."
);
buff
.
append
(
StringUtils
.
quoteIdentifier
(
schema
)).
append
(
"."
);
}
buff
.
append
(
StringUtils
.
quoteIdentifier
(
table
));
buff
.
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" AND "
);
}
int
columnIndex
=
keys
[
i
];
buff
.
append
(
StringUtils
.
quoteIdentifier
(
table
)).
append
(
" WHERE "
);
for
(
int
columnIndex
:
keys
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
StringUtils
.
quoteIdentifier
(
columns
[
columnIndex
]));
Object
o
=
row
[
columnIndex
];
if
(
o
==
null
)
{
buff
.
append
(
" IS NULL"
);
}
else
{
buff
.
append
(
"="
);
buff
.
append
(
FullText
.
quoteSQL
(
o
,
columnTypes
[
columnIndex
]));
buff
.
append
(
'='
).
append
(
FullText
.
quoteSQL
(
o
,
columnTypes
[
columnIndex
]));
}
}
String
key
=
buff
.
toString
();
return
key
;
return
buff
.
toString
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/fulltext/FullTextSettings.java
浏览文件 @
e126424c
...
...
@@ -13,9 +13,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
org.h2.util.New
;
import
org.h2.util.ObjectUtils
;
/**
* The global settings of a full text search.
...
...
@@ -134,7 +132,7 @@ class FullTextSettings {
* @param index the index to remove
*/
void
removeIndexInfo
(
IndexInfo
index
)
{
indexes
.
remove
(
ObjectUtils
.
getLong
(
index
.
id
)
);
indexes
.
remove
(
index
.
id
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
e126424c
...
...
@@ -22,6 +22,7 @@ import org.h2.schema.SchemaObjectBase;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -149,14 +150,9 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
public
SQLException
getDuplicateKeyException
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
getName
());
buff
.
append
(
" "
);
buff
.
append
(
" ON "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
"("
);
buff
.
append
(
getColumnListSQL
());
buff
.
append
(
")"
);
StringBuffer
buff
=
new
StringBuffer
(
getName
());
buff
.
append
(
" ON "
).
append
(
table
.
getSQL
()).
append
(
'('
);
buff
.
append
(
getColumnListSQL
()).
append
(
')'
);
return
Message
.
getSQLException
(
ErrorCode
.
DUPLICATE_KEY_1
,
buff
.
toString
());
}
...
...
@@ -258,8 +254,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
if
(
mode
.
uniqueIndexSingleNull
)
{
return
false
;
}
else
if
(
mode
.
uniqueIndexSingleNullExceptAllColumnsAreNull
)
{
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
int
index
=
columnIds
[
i
];
for
(
int
index
:
columnIds
)
{
Value
v
=
newRow
.
getValue
(
index
);
if
(
v
!=
ValueNull
.
INSTANCE
)
{
return
false
;
...
...
@@ -267,8 +262,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
return
true
;
}
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
int
index
=
columnIds
[
i
];
for
(
int
index
:
columnIds
)
{
Value
v
=
newRow
.
getValue
(
index
);
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
true
;
...
...
@@ -316,33 +310,25 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
public
String
getColumnListSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
indexColumns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
indexColumns
[
i
].
getSQL
());
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
IndexColumn
c
:
indexColumns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
return
buff
.
toString
();
}
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"CREATE "
);
StringBuffer
buff
=
new
StringBuffer
(
"CREATE "
);
buff
.
append
(
indexType
.
getSQL
());
if
(!
indexType
.
getPrimaryKey
())
{
buff
.
append
(
' '
);
buff
.
append
(
quotedName
);
buff
.
append
(
' '
).
append
(
quotedName
);
}
buff
.
append
(
" ON "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
" ON "
).
append
(
table
.
getSQL
());
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
buff
.
append
(
"("
);
buff
.
append
(
getColumnListSQL
());
buff
.
append
(
")"
);
buff
.
append
(
'('
).
append
(
getColumnListSQL
()).
append
(
")"
);
return
buff
.
toString
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/HashIndex.java
浏览文件 @
e126424c
...
...
@@ -7,7 +7,6 @@
package
org
.
h2
.
index
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.message.Message
;
import
org.h2.result.Row
;
...
...
@@ -16,7 +15,6 @@ import org.h2.table.Column;
import
org.h2.table.IndexColumn
;
import
org.h2.table.TableData
;
import
org.h2.util.IntIntHashMap
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -68,8 +66,7 @@ public class HashIndex extends BaseIndex {
// TODO index duplicate key for hash indexes: is this allowed?
throw
getDuplicateKeyException
();
}
Integer
pos
=
ObjectUtils
.
getInteger
(
row
.
getPos
());
rows
.
put
(
getKey
(
row
),
pos
);
rows
.
put
(
getKey
(
row
),
row
.
getPos
());
}
rowCount
++;
}
...
...
@@ -126,8 +123,7 @@ public class HashIndex extends BaseIndex {
}
public
double
getCost
(
Session
session
,
int
[]
masks
)
{
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
Column
column
=
columns
[
i
];
for
(
Column
column
:
columns
)
{
int
index
=
column
.
getColumnId
();
int
mask
=
masks
[
index
];
if
((
mask
&
IndexCondition
.
EQUALITY
)
!=
IndexCondition
.
EQUALITY
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
e126424c
...
...
@@ -18,6 +18,7 @@ import org.h2.result.SearchRow;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.TableLink
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -86,35 +87,28 @@ public class LinkedIndex extends BaseIndex {
}
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
();
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT * FROM "
);
buff
.
append
(
targetTableName
).
append
(
" T"
);
for
(
int
i
=
0
;
first
!=
null
&&
i
<
first
.
getColumnCount
();
i
++)
{
Value
v
=
first
.
getValue
(
i
);
if
(
v
!=
null
)
{
if
(
buff
.
length
()
!=
0
)
{
buff
.
append
(
" AND "
);
}
buff
.
appendOnlyFirst
(
" WHERE "
);
buff
.
appendExceptFirst
(
" AND "
);
Column
col
=
table
.
getColumn
(
i
);
buff
.
append
(
col
.
getSQL
());
buff
.
append
(
">="
);
buff
.
append
(
col
.
getSQL
()).
append
(
">="
);
addParameter
(
buff
,
col
);
}
}
for
(
int
i
=
0
;
last
!=
null
&&
i
<
last
.
getColumnCount
();
i
++)
{
Value
v
=
last
.
getValue
(
i
);
if
(
v
!=
null
)
{
if
(
buff
.
length
()
!=
0
)
{
buff
.
append
(
" AND "
);
}
buff
.
appendOnlyFirst
(
" WHERE "
);
buff
.
appendExceptFirst
(
" AND "
);
Column
col
=
table
.
getColumn
(
i
);
buff
.
append
(
col
.
getSQL
());
buff
.
append
(
"<="
);
buff
.
append
(
col
.
getSQL
()).
append
(
"<="
);
addParameter
(
buff
,
col
);
}
}
if
(
buff
.
length
()
>
0
)
{
buff
.
insert
(
0
,
" WHERE "
);
}
buff
.
insert
(
0
,
"SELECT * FROM "
+
targetTableName
+
" T"
);
String
sql
=
buff
.
toString
();
synchronized
(
link
.
getConnection
())
{
try
{
...
...
@@ -142,17 +136,15 @@ public class LinkedIndex extends BaseIndex {
}
}
private
void
addParameter
(
St
ringBuff
er
buff
,
Column
col
)
{
private
void
addParameter
(
St
atementBuild
er
buff
,
Column
col
)
{
if
(
col
.
getType
()
==
Value
.
STRING_FIXED
&&
link
.
isOracle
())
{
// workaround for Oracle
// create table test(id int primary key, name char(15));
// insert into test values(1, 'Hello')
// select * from test where name = ? -- where ? = "Hello" > no rows
buff
.
append
(
"CAST(? AS CHAR("
);
buff
.
append
(
col
.
getPrecision
());
buff
.
append
(
"))"
);
buff
.
append
(
"CAST(? AS CHAR("
).
append
(
col
.
getPrecision
()).
append
(
"))"
);
}
else
{
buff
.
append
(
"?"
);
buff
.
append
(
'?'
);
}
}
...
...
@@ -187,13 +179,10 @@ public class LinkedIndex extends BaseIndex {
}
public
void
remove
(
Session
session
,
Row
row
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
(
"DELETE FROM "
);
buff
.
append
(
targetTableName
);
buff
.
append
(
" WHERE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"DELETE FROM "
);
buff
.
append
(
targetTableName
).
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
"AND "
);
}
buff
.
appendExceptFirst
(
"AND "
);
Column
col
=
table
.
getColumn
(
i
);
buff
.
append
(
col
.
getSQL
());
Value
v
=
row
.
getValue
(
i
);
...
...
@@ -232,28 +221,24 @@ public class LinkedIndex extends BaseIndex {
* @param newRow the new data
*/
public
void
update
(
Row
oldRow
,
Row
newRow
)
throws
SQLException
{
St
ringBuffer
buff
=
new
StringBuff
er
(
"UPDATE "
);
St
atementBuilder
buff
=
new
StatementBuild
er
(
"UPDATE "
);
buff
.
append
(
targetTableName
).
append
(
" SET "
);
for
(
int
i
=
0
;
i
<
newRow
.
getColumnCount
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
table
.
getColumn
(
i
).
getSQL
()).
append
(
"=?"
);
}
buff
.
append
(
" WHERE "
);
buff
.
resetCount
();
for
(
int
i
=
0
;
i
<
oldRow
.
getColumnCount
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
"AND "
);
}
Column
col
=
table
.
getColumn
(
i
);
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
col
.
getSQL
());
Value
v
=
oldRow
.
getValue
(
i
);
if
(
isNull
(
v
))
{
buff
.
append
(
" IS NULL
"
);
buff
.
append
(
" IS NULL"
);
}
else
{
buff
.
append
(
'='
);
addParameter
(
buff
,
col
);
buff
.
append
(
' '
);
}
}
String
sql
=
buff
.
toString
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/PageBtreeIndex.java
浏览文件 @
e126424c
...
...
@@ -17,6 +17,7 @@ import org.h2.result.SearchRow;
import
org.h2.store.DataPage
;
import
org.h2.store.PageStore
;
import
org.h2.store.Record
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.TableData
;
import
org.h2.value.Value
;
...
...
@@ -291,8 +292,8 @@ public class PageBtreeIndex extends BaseIndex {
data
.
setPos
(
offset
);
SearchRow
row
=
table
.
getTemplateSimpleRow
(
columns
.
length
==
1
);
row
.
setPos
(
data
.
readInt
());
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++
)
{
int
idx
=
col
umns
[
i
]
.
getColumnId
();
for
(
Column
col
:
columns
)
{
int
idx
=
col
.
getColumnId
();
row
.
setValue
(
idx
,
data
.
readValue
());
}
return
row
;
...
...
@@ -308,8 +309,8 @@ public class PageBtreeIndex extends BaseIndex {
void
writeRow
(
DataPage
data
,
int
offset
,
SearchRow
row
)
throws
SQLException
{
data
.
setPos
(
offset
);
data
.
writeInt
(
row
.
getPos
());
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++
)
{
int
idx
=
col
umns
[
i
]
.
getColumnId
();
for
(
Column
col
:
columns
)
{
int
idx
=
col
.
getColumnId
();
data
.
writeValue
(
row
.
getValue
(
idx
));
}
}
...
...
@@ -323,8 +324,8 @@ public class PageBtreeIndex extends BaseIndex {
*/
int
getRowSize
(
DataPage
dummy
,
SearchRow
row
)
throws
SQLException
{
int
rowsize
=
DataPage
.
LENGTH_INT
;
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++
)
{
Value
v
=
row
.
getValue
(
col
umns
[
i
]
.
getColumnId
());
for
(
Column
col
:
columns
)
{
Value
v
=
row
.
getValue
(
col
.
getColumnId
());
rowsize
+=
dummy
.
getValueLen
(
v
);
}
return
rowsize
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/PageBtreeNode.java
浏览文件 @
e126424c
...
...
@@ -153,8 +153,7 @@ class PageBtreeNode extends PageBtree {
}
protected
void
remapChildren
()
throws
SQLException
{
for
(
int
i
=
0
;
i
<
childPageIds
.
length
;
i
++)
{
int
child
=
childPageIds
[
i
];
for
(
int
child
:
childPageIds
)
{
PageBtree
p
=
index
.
getPage
(
child
);
p
.
setParentPageId
(
getPos
());
index
.
getPageStore
().
updateRecord
(
p
,
true
,
p
.
data
);
...
...
@@ -222,8 +221,8 @@ class PageBtreeNode extends PageBtree {
int
getRowCount
()
throws
SQLException
{
if
(
rowCount
==
UNKNOWN_ROWCOUNT
)
{
int
count
=
0
;
for
(
int
i
=
0
;
i
<
childPageIds
.
length
;
i
++
)
{
PageBtree
page
=
index
.
getPage
(
child
PageIds
[
i
]
);
for
(
int
child
:
childPageIds
)
{
PageBtree
page
=
index
.
getPage
(
child
);
count
+=
page
.
getRowCount
();
}
rowCount
=
count
;
...
...
@@ -240,8 +239,8 @@ class PageBtreeNode extends PageBtree {
}
private
void
check
()
{
for
(
int
i
=
0
;
i
<
childPageIds
.
length
;
i
++
)
{
if
(
child
PageIds
[
i
]
==
0
)
{
for
(
int
child
:
childPageIds
)
{
if
(
child
==
0
)
{
Message
.
throwInternalError
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/PageDataNode.java
浏览文件 @
e126424c
...
...
@@ -133,8 +133,7 @@ class PageDataNode extends PageData {
}
protected
void
remapChildren
()
throws
SQLException
{
for
(
int
i
=
0
;
i
<
childPageIds
.
length
;
i
++)
{
int
child
=
childPageIds
[
i
];
for
(
int
child
:
childPageIds
)
{
PageData
p
=
index
.
getPage
(
child
);
p
.
setParentPageId
(
getPos
());
index
.
getPageStore
().
updateRecord
(
p
,
true
,
p
.
data
);
...
...
@@ -215,8 +214,8 @@ class PageDataNode extends PageData {
int
getRowCount
()
throws
SQLException
{
if
(
rowCount
==
UNKNOWN_ROWCOUNT
)
{
int
count
=
0
;
for
(
int
i
=
0
;
i
<
childPageIds
.
length
;
i
++
)
{
PageData
page
=
index
.
getPage
(
child
PageIds
[
i
]
);
for
(
int
child
:
childPageIds
)
{
PageData
page
=
index
.
getPage
(
child
);
if
(
getPos
()
==
page
.
getPos
())
{
throw
Message
.
throwInternalError
(
"Page it its own child: "
+
getPageId
());
}
...
...
@@ -236,8 +235,8 @@ class PageDataNode extends PageData {
}
private
void
check
()
{
for
(
int
i
=
0
;
i
<
childPageIds
.
length
;
i
++
)
{
if
(
child
PageIds
[
i
]
==
0
)
{
for
(
int
child
:
childPageIds
)
{
if
(
child
==
0
)
{
Message
.
throwInternalError
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcArray.java
浏览文件 @
e126424c
...
...
@@ -11,12 +11,10 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Types
;
import
java.util.Map
;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.Message
;
import
org.h2.message.TraceObject
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.ObjectUtils
;
import
org.h2.value.Value
;
/**
...
...
@@ -245,7 +243,7 @@ public class JdbcArray extends TraceObject implements Array {
rs
.
addColumn
(
"VALUE"
,
Types
.
NULL
,
0
,
0
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
Object
[]
row
=
new
Object
[
2
];
row
[
0
]
=
ObjectUtils
.
getLong
(
offset
+
i
+
1
);
row
[
0
]
=
Long
.
valueOf
(
offset
+
i
+
1
);
row
[
1
]
=
array
[
i
];
rs
.
addRow
(
row
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
e126424c
...
...
@@ -20,6 +20,7 @@ import org.h2.engine.Constants;
import
org.h2.message.Message
;
import
org.h2.message.Trace
;
import
org.h2.message.TraceObject
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -127,15 +128,12 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
checkClosed
();
String
tableType
;
if
(
types
!=
null
&&
types
.
length
>
0
)
{
St
ringBuffer
buff
=
new
StringBuff
er
(
"TABLE_TYPE IN("
);
St
atementBuilder
buff
=
new
StatementBuild
er
(
"TABLE_TYPE IN("
);
for
(
int
i
=
0
;
i
<
types
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
"?"
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
'?'
);
}
buff
.
append
(
")"
);
tableType
=
buff
.
toString
();
tableType
=
buff
.
append
(
')'
).
toString
();
}
else
{
tableType
=
"TRUE"
;
}
...
...
@@ -1363,20 +1361,18 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
private
String
getFunctions
(
String
section
)
throws
SQLException
{
try
{
StringBuffer
buff
=
new
StringBuffer
();
checkClosed
();
PreparedStatement
prep
=
conn
.
prepareAutoCloseStatement
(
"SELECT TOPIC "
+
"FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?"
);
prep
.
setString
(
1
,
section
);
ResultSet
rs
=
prep
.
executeQuery
();
StatementBuilder
buff
=
new
StatementBuilder
();
while
(
rs
.
next
())
{
String
s
=
rs
.
getString
(
1
).
trim
();
String
[]
array
=
StringUtils
.
arraySplit
(
s
,
','
,
true
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
buff
.
length
()
>
0
)
{
buff
.
append
(
","
);
}
String
f
=
array
[
i
].
trim
();
for
(
String
a
:
array
)
{
buff
.
appendExceptFirst
(
","
);
String
f
=
a
.
trim
();
if
(
f
.
indexOf
(
' '
)
>=
0
)
{
// remove 'Function' from 'INSERT Function'
f
=
f
.
substring
(
0
,
f
.
indexOf
(
' '
)).
trim
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcPreparedStatement.java
浏览文件 @
e126424c
...
...
@@ -1039,8 +1039,8 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
boolean
error
=
false
;
SQLException
next
=
null
;
for
(
int
i
=
0
;
i
<
batchParameters
.
size
();
i
++)
{
ObjectArray
<
?
extends
ParameterInterface
>
parameters
=
command
.
getParameters
();
Value
[]
set
=
batchParameters
.
get
(
i
);
ObjectArray
<
?
extends
ParameterInterface
>
parameters
=
command
.
getParameters
();
for
(
int
j
=
0
;
j
<
set
.
length
;
j
++)
{
Value
value
=
set
[
j
];
ParameterInterface
param
=
parameters
.
get
(
j
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcResultSet.java
浏览文件 @
e126424c
...
...
@@ -42,7 +42,6 @@ import org.h2.util.DateTimeUtils;
import
org.h2.util.IOUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
...
...
@@ -2930,11 +2929,11 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
String
colName
=
result
.
getColumnName
(
i
);
if
(
colName
!=
null
)
{
colName
=
StringUtils
.
toUpperEnglish
(
colName
);
map
.
put
(
colName
,
ObjectUtils
.
getInteger
(
i
)
);
map
.
put
(
colName
,
i
);
String
tabName
=
result
.
getTableName
(
i
);
if
(
tabName
!=
null
)
{
colName
=
StringUtils
.
toUpperEnglish
(
tabName
)
+
"."
+
colName
;
map
.
put
(
colName
,
ObjectUtils
.
getInteger
(
i
)
);
map
.
put
(
colName
,
i
);
}
}
}
...
...
@@ -2942,7 +2941,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
// column names with the same name are replaced
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
c
=
StringUtils
.
toUpperEnglish
(
result
.
getAlias
(
i
));
map
.
put
(
c
,
ObjectUtils
.
getInteger
(
i
)
);
map
.
put
(
c
,
i
);
}
// assign at the end so concurrent access is supported
columnLabelMap
=
map
;
...
...
@@ -3522,7 +3521,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
if
(
patchedRows
==
null
)
{
patchedRows
=
New
.
hashMap
();
}
Integer
rowId
=
ObjectUtils
.
getInteger
(
result
.
getRowId
()
);
Integer
rowId
=
result
.
getRowId
(
);
if
(!
changed
)
{
patchedRows
.
remove
(
rowId
);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbcx/JdbcConnectionPool.java
浏览文件 @
e126424c
...
...
@@ -48,9 +48,9 @@ import org.h2.message.Message;
* public static void main(String[] args) throws Exception {
* JdbcConnectionPool cp = JdbcConnectionPool.create(
* "jdbc:h2:~/test", "sa", "sa");
* for (
int i = 0; i < args.length; i++
) {
* for (
String sql : args
) {
* Connection conn = cp.getConnection();
* conn.createStatement().execute(
args[i]
);
* conn.createStatement().execute(
sql
);
* conn.close();
* }
* cp.dispose();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/log/LogFile.java
浏览文件 @
e126424c
...
...
@@ -425,8 +425,7 @@ public class LogFile {
}
file
.
write
(
buffer
,
0
,
bufferPos
);
pos
=
getBlock
();
for
(
int
i
=
0
;
i
<
unwritten
.
size
();
i
++)
{
Record
r
=
unwritten
.
get
(
i
);
for
(
Record
r
:
unwritten
)
{
r
.
setLogWritten
(
id
,
pos
);
}
unwritten
.
clear
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/log/LogSystem.java
浏览文件 @
e126424c
...
...
@@ -9,7 +9,6 @@ package org.h2.log;
import
java.sql.SQLException
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
...
...
@@ -24,7 +23,6 @@ import org.h2.store.Storage;
import
org.h2.util.FileUtils
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ObjectUtils
;
/**
* The transaction log system is responsible for the write ahead log mechanism
...
...
@@ -271,7 +269,7 @@ public class LogSystem {
for
(
int
i
=
undo
.
size
()
-
1
;
i
>=
0
&&
sessionStates
.
size
()
>
0
;
i
--)
{
database
.
setProgress
(
DatabaseEventListener
.
STATE_RECOVER
,
null
,
undo
.
size
()
-
1
-
i
,
undo
.
size
());
LogRecord
record
=
undo
.
get
(
i
);
if
(
sessionStates
.
get
(
ObjectUtils
.
getInteger
(
record
.
sessionId
)
)
!=
null
)
{
if
(
sessionStates
.
get
(
record
.
sessionId
)
!=
null
)
{
// undo only if the session is not yet committed
record
.
log
.
undo
(
record
.
logRecordId
);
database
.
getDataFile
().
flushRedoLog
();
...
...
@@ -438,7 +436,7 @@ public class LogSystem {
* @param sessionId the session id
*/
void
removeSession
(
int
sessionId
)
{
sessionStates
.
remove
(
ObjectUtils
.
getInteger
(
sessionId
)
);
sessionStates
.
remove
(
sessionId
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/message/TraceObject.java
浏览文件 @
e126424c
...
...
@@ -18,6 +18,7 @@ import org.h2.util.ByteUtils;
import
org.h2.util.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -414,29 +415,22 @@ public class TraceObject {
* INTERNAL
*/
public
static
String
toString
(
String
sql
,
ObjectArray
<
?
extends
ParameterInterface
>
params
)
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
sql
);
StatementBuilder
buff
=
new
StatementBuilder
(
sql
);
if
(
params
!=
null
&&
params
.
size
()
>
0
)
{
buff
.
append
(
" {"
);
for
(
int
i
=
0
;
i
<
params
.
size
();
i
++)
{
int
i
=
0
;
for
(
ParameterInterface
p
:
params
)
{
i
++;
try
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
i
+
1
);
buff
.
append
(
": "
);
ParameterInterface
p
=
params
.
get
(
i
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
i
).
append
(
": "
);
if
(
p
==
null
||
p
.
getParamValue
()
==
null
)
{
buff
.
append
(
"-"
);
buff
.
append
(
'-'
);
}
else
{
buff
.
append
(
p
.
getParamValue
().
getSQL
());
}
}
catch
(
SQLException
e
)
{
buff
.
append
(
"/* "
);
buff
.
append
(
i
+
1
);
buff
.
append
(
": "
);
buff
.
append
(
e
.
toString
());
buff
.
append
(
"*/ "
);
buff
.
append
(
"/* "
).
append
(
i
).
append
(
": "
).
append
(
e
.
toString
()).
append
(
"*/ "
);
}
}
buff
.
append
(
"};"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/ResultDiskBuffer.java
浏览文件 @
e126424c
...
...
@@ -86,10 +86,9 @@ class ResultDiskBuffer implements ResultExternal {
ByteArrayOutputStream
buffer
=
new
ByteArrayOutputStream
();
int
bufferLen
=
0
;
int
maxBufferSize
=
SysProperties
.
LARGE_RESULT_BUFFER_SIZE
;
for
(
int
i
=
0
;
i
<
rows
.
size
();
i
++
)
{
for
(
Value
[]
row
:
rows
)
{
buff
.
reset
();
buff
.
writeInt
(
0
);
Value
[]
row
=
rows
.
get
(
i
);
for
(
int
j
=
0
;
j
<
columnCount
;
j
++)
{
buff
.
writeValue
(
row
[
j
]);
}
...
...
@@ -131,8 +130,7 @@ class ResultDiskBuffer implements ResultExternal {
public
void
reset
()
{
if
(
sort
!=
null
)
{
for
(
int
i
=
0
;
i
<
tapes
.
size
();
i
++)
{
ResultDiskTape
tape
=
getTape
(
i
);
for
(
ResultDiskTape
tape
:
tapes
)
{
tape
.
pos
=
tape
.
start
;
tape
.
buffer
=
ObjectArray
.
newInstance
();
}
...
...
@@ -180,7 +178,7 @@ class ResultDiskBuffer implements ResultExternal {
private
Value
[]
nextSorted
()
throws
SQLException
{
int
next
=
-
1
;
for
(
int
i
=
0
;
i
<
tapes
.
size
();
i
++)
{
ResultDiskTape
tape
=
getTape
(
i
);
ResultDiskTape
tape
=
tapes
.
get
(
i
);
if
(
tape
.
buffer
.
size
()
==
0
&&
tape
.
pos
<
tape
.
end
)
{
file
.
seek
(
tape
.
pos
);
for
(
int
j
=
0
;
tape
.
pos
<
tape
.
end
&&
j
<
READ_AHEAD
;
j
++)
{
...
...
@@ -190,21 +188,17 @@ class ResultDiskBuffer implements ResultExternal {
if
(
tape
.
buffer
.
size
()
>
0
)
{
if
(
next
==
-
1
)
{
next
=
i
;
}
else
if
(
compareTapes
(
tape
,
getTape
(
next
))
<
0
)
{
}
else
if
(
compareTapes
(
tape
,
tapes
.
get
(
next
))
<
0
)
{
next
=
i
;
}
}
}
ResultDiskTape
t
=
getTape
(
next
);
ResultDiskTape
t
=
tapes
.
get
(
next
);
Value
[]
row
=
t
.
buffer
.
get
(
0
);
t
.
buffer
.
remove
(
0
);
return
row
;
}
private
ResultDiskTape
getTape
(
int
i
)
{
return
tapes
.
get
(
i
);
}
private
int
compareTapes
(
ResultDiskTape
a
,
ResultDiskTape
b
)
throws
SQLException
{
Value
[]
va
=
a
.
buffer
.
get
(
0
);
Value
[]
vb
=
b
.
buffer
.
get
(
0
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/ResultRemote.java
浏览文件 @
e126424c
...
...
@@ -165,8 +165,7 @@ public class ResultRemote implements ResultInterface {
Trace
trace
=
session
.
getTrace
();
sendClose
();
if
(
lobValues
!=
null
)
{
for
(
int
i
=
0
;
i
<
lobValues
.
size
();
i
++)
{
Value
v
=
lobValues
.
get
(
i
);
for
(
Value
v
:
lobValues
)
{
try
{
v
.
close
();
}
catch
(
SQLException
e
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/ResultTempTable.java
浏览文件 @
e126424c
...
...
@@ -89,8 +89,7 @@ public class ResultTempTable implements ResultExternal {
if
(
sort
!=
null
)
{
sort
.
sort
(
rows
);
}
for
(
int
i
=
0
;
i
<
rows
.
size
();
i
++)
{
Value
[]
values
=
rows
.
get
(
i
);
for
(
Value
[]
values
:
rows
)
{
addRow
(
values
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/Row.java
浏览文件 @
e126424c
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
org.h2.store.DataPage
;
import
org.h2.store.DiskFile
;
import
org.h2.store.Record
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
/**
...
...
@@ -46,8 +47,7 @@ public class Row extends Record implements SearchRow {
public
void
write
(
DataPage
buff
)
throws
SQLException
{
buff
.
writeInt
(
data
.
length
);
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
Value
v
=
data
[
i
];
for
(
Value
v
:
data
)
{
buff
.
writeValue
(
v
);
}
}
...
...
@@ -86,8 +86,7 @@ public class Row extends Record implements SearchRow {
}
public
String
toString
()
{
StringBuffer
buff
=
new
StringBuffer
(
data
.
length
*
5
);
buff
.
append
(
"( /* pos:"
);
StatementBuilder
buff
=
new
StatementBuilder
(
"( /* pos:"
);
buff
.
append
(
getPos
());
if
(
version
!=
0
)
{
buff
.
append
(
" v:"
+
version
);
...
...
@@ -96,15 +95,11 @@ public class Row extends Record implements SearchRow {
buff
.
append
(
" deleted"
);
}
buff
.
append
(
" */ "
);
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Value
v
=
data
[
i
];
for
(
Value
v
:
data
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
v
==
null
?
"null"
:
v
.
getTraceSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/SimpleRow.java
浏览文件 @
e126424c
...
...
@@ -6,6 +6,7 @@
*/
package
org
.
h2
.
result
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
/**
...
...
@@ -51,22 +52,17 @@ public class SimpleRow implements SearchRow {
}
public
String
toString
()
{
StringBuffer
buff
=
new
StringBuffer
(
data
.
length
*
5
);
buff
.
append
(
"( /* pos:"
);
StatementBuilder
buff
=
new
StatementBuilder
(
"( /* pos:"
);
buff
.
append
(
getPos
());
if
(
version
!=
0
)
{
buff
.
append
(
" v:"
+
version
);
}
buff
.
append
(
" */ "
);
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
Value
v
=
data
[
i
];
for
(
Value
v
:
data
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
v
==
null
?
"null"
:
v
.
getTraceSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/SortOrder.java
浏览文件 @
e126424c
...
...
@@ -13,6 +13,7 @@ import org.h2.engine.Database;
import
org.h2.expression.Expression
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -77,19 +78,16 @@ public class SortOrder {
* @return the SQL snippet
*/
public
String
getSQL
(
Expression
[]
list
,
int
visible
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
int
idx
=
indexes
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
int
i
=
0
;
for
(
int
idx
:
indexes
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
idx
<
visible
)
{
buff
.
append
(
idx
+
1
);
}
else
{
buff
.
append
(
"="
);
buff
.
append
(
StringUtils
.
unEnclose
(
list
[
idx
].
getSQL
()));
buff
.
append
(
'='
).
append
(
StringUtils
.
unEnclose
(
list
[
idx
].
getSQL
()));
}
int
type
=
sortTypes
[
i
];
int
type
=
sortTypes
[
i
++
];
if
((
type
&
DESCENDING
)
!=
0
)
{
buff
.
append
(
" DESC"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/UpdatableRow.java
浏览文件 @
e126424c
...
...
@@ -16,6 +16,7 @@ import org.h2.jdbc.JdbcConnection;
import
org.h2.message.Message
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
...
...
@@ -113,11 +114,10 @@ public class UpdatableRow {
throw
Message
.
getSQLException
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
columnName
);
}
private
void
appendColumnList
(
StringBuffer
buff
,
boolean
set
)
{
private
void
appendColumnList
(
StatementBuilder
buff
,
boolean
set
)
{
buff
.
resetCount
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
','
);
}
buff
.
appendExceptFirst
(
","
);
String
col
=
result
.
getColumnName
(
i
);
buff
.
append
(
StringUtils
.
quoteIdentifier
(
col
));
if
(
set
)
{
...
...
@@ -126,14 +126,12 @@ public class UpdatableRow {
}
}
private
void
appendKeyCondition
(
St
ringBuff
er
buff
)
{
private
void
appendKeyCondition
(
St
atementBuild
er
buff
)
{
buff
.
append
(
" WHERE "
);
for
(
int
i
=
0
;
i
<
key
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" AND "
);
}
buff
.
append
(
StringUtils
.
quoteIdentifier
(
key
.
get
(
i
)));
buff
.
append
(
"=?"
);
buff
.
resetCount
();
for
(
String
k
:
key
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
StringUtils
.
quoteIdentifier
(
k
)).
append
(
"=?"
);
}
}
...
...
@@ -163,10 +161,9 @@ public class UpdatableRow {
// return rs.getInt(1) == 0;
// }
private
void
appendTableName
(
St
ringBuff
er
buff
)
{
private
void
appendTableName
(
St
atementBuild
er
buff
)
{
if
(
schemaName
!=
null
&&
schemaName
.
length
()
>
0
)
{
buff
.
append
(
StringUtils
.
quoteIdentifier
(
schemaName
));
buff
.
append
(
'.'
);
buff
.
append
(
StringUtils
.
quoteIdentifier
(
schemaName
)).
append
(
'.'
);
}
buff
.
append
(
StringUtils
.
quoteIdentifier
(
tableName
));
}
...
...
@@ -178,8 +175,7 @@ public class UpdatableRow {
* @return the row
*/
public
Value
[]
readRow
(
Value
[]
row
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"SELECT "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT "
);
appendColumnList
(
buff
,
false
);
buff
.
append
(
" FROM "
);
appendTableName
(
buff
);
...
...
@@ -205,8 +201,7 @@ public class UpdatableRow {
* @throws SQLException if this row has already been deleted
*/
public
void
deleteRow
(
Value
[]
current
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"DELETE FROM "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"DELETE FROM "
);
appendTableName
(
buff
);
appendKeyCondition
(
buff
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
buff
.
toString
());
...
...
@@ -226,8 +221,7 @@ public class UpdatableRow {
* @throws SQLException if the row has been deleted
*/
public
void
updateRow
(
Value
[]
current
,
Value
[]
updateRow
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"UPDATE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
appendTableName
(
buff
);
buff
.
append
(
" SET "
);
appendColumnList
(
buff
,
true
);
...
...
@@ -259,16 +253,14 @@ public class UpdatableRow {
* @throws SQLException if the row could not be inserted
*/
public
void
insertRow
(
Value
[]
row
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"INSERT INTO "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
appendTableName
(
buff
);
buff
.
append
(
'('
);
appendColumnList
(
buff
,
false
);
buff
.
append
(
")VALUES("
);
buff
.
resetCount
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
','
);
}
buff
.
appendExceptFirst
(
","
);
buff
.
append
(
'?'
);
}
buff
.
append
(
')'
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
e126424c
...
...
@@ -72,6 +72,7 @@ import org.h2.util.New;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ScriptReader
;
import
org.h2.util.SortedProperties
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Tool
;
...
...
@@ -293,7 +294,7 @@ class WebThread extends Thread implements DatabaseEventListener {
if
(
value
.
equals
(
selected
))
{
buff
.
append
(
" selected"
);
}
buff
.
append
(
">"
);
buff
.
append
(
'>'
);
buff
.
append
(
PageParser
.
escapeHtml
(
value
));
buff
.
append
(
"</option>"
);
}
...
...
@@ -309,7 +310,7 @@ class WebThread extends Thread implements DatabaseEventListener {
if
(
n
[
0
].
equals
(
selected
))
{
buff
.
append
(
" selected"
);
}
buff
.
append
(
">"
);
buff
.
append
(
'>'
);
buff
.
append
(
PageParser
.
escapeHtml
(
n
[
1
]));
buff
.
append
(
"</option>"
);
}
...
...
@@ -533,15 +534,13 @@ class WebThread extends Thread implements DatabaseEventListener {
list
.
add
(
type
+
"#"
+
key
+
"#"
+
value
);
}
Collections
.
sort
(
list
);
StringBuffer
buff
=
new
StringBuffer
();
if
(
query
.
endsWith
(
"\n"
)
||
query
.
trim
().
endsWith
(
";"
))
{
list
.
add
(
0
,
"1#(Newline)#\n"
);
}
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
'|'
);
}
buff
.
append
(
list
.
get
(
i
));
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
String
s
:
list
)
{
buff
.
appendExceptFirst
(
"|"
);
buff
.
append
(
s
);
}
result
=
buff
.
toString
();
}
...
...
@@ -1776,9 +1775,8 @@ class WebThread extends Thread implements DatabaseEventListener {
Statement
stat
=
conn
.
createStatement
();
for
(
int
i
=
0
;
!
stop
&&
i
<
count
;
i
++)
{
String
s
=
sql
;
for
(
int
j
=
0
;
j
<
params
.
size
();
j
++
)
{
for
(
Integer
type
:
params
)
{
idx
=
s
.
indexOf
(
'?'
);
Integer
type
=
params
.
get
(
j
);
if
(
type
.
intValue
()
==
1
)
{
s
=
s
.
substring
(
0
,
idx
)
+
random
.
nextInt
(
count
)
+
s
.
substring
(
idx
+
1
);
}
else
{
...
...
@@ -1823,23 +1821,19 @@ class WebThread extends Thread implements DatabaseEventListener {
}
}
time
=
System
.
currentTimeMillis
()
-
time
;
String
result
=
time
+
" ms: "
+
count
+
" * "
;
StatementBuilder
buff
=
new
StatementBuilder
();
buff
.
append
(
time
).
append
(
" ms: "
).
append
(
count
).
append
(
" * "
);
if
(
prepared
)
{
result
+=
"(Prepared) "
;
buff
.
append
(
"(Prepared) "
)
;
}
else
{
result
+=
"(Statement) "
;
buff
.
append
(
"(Statement) "
)
;
}
result
+=
"("
;
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
params
.
size
();
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
params
.
get
(
i
)
==
0
?
"i"
:
"rnd"
);
buff
.
append
(
'('
);
for
(
int
p
:
params
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
p
==
0
?
"i"
:
"rnd"
);
}
result
+=
buff
.
toString
();
result
+=
") "
+
sql
;
return
result
;
return
buff
.
append
(
") "
).
append
(
sql
).
toString
();
}
private
String
getHistoryString
()
{
...
...
@@ -2032,7 +2026,7 @@ class WebThread extends Thread implements DatabaseEventListener {
}
else
if
(
rows
==
1
)
{
buff
.
append
(
"(${text.result.1row}"
);
}
else
{
buff
.
append
(
"("
);
buff
.
append
(
'('
);
buff
.
append
(
rows
);
buff
.
append
(
" ${text.result.rows}"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/DataPage.java
浏览文件 @
e126424c
...
...
@@ -485,8 +485,8 @@ public class DataPage {
case
Value
.
ARRAY
:
{
Value
[]
list
=
((
ValueArray
)
v
).
getList
();
writeInt
(
list
.
length
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++
)
{
writeValue
(
list
[
i
]
);
for
(
Value
x
:
list
)
{
writeValue
(
x
);
}
break
;
}
...
...
@@ -561,8 +561,8 @@ public class DataPage {
case
Value
.
ARRAY
:
{
Value
[]
list
=
((
ValueArray
)
v
).
getList
();
int
len
=
1
+
LENGTH_INT
;
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++
)
{
len
+=
getValueLen
(
list
[
i
]
);
for
(
Value
x
:
list
)
{
len
+=
getValueLen
(
x
);
}
return
len
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/DiskFile.java
浏览文件 @
e126424c
...
...
@@ -37,7 +37,6 @@ import org.h2.util.IntArray;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ObjectUtils
;
/**
* This class represents a file that is usually written to disk. The two main
...
...
@@ -795,7 +794,7 @@ public class DiskFile implements CacheWriter {
if
(
storageId
>=
0
)
{
database
.
getStorage
(
storageId
,
this
).
addPage
(
page
);
if
(
SysProperties
.
REUSE_SPACE_QUICKLY
)
{
potentiallyFreePages
.
remove
(
ObjectUtils
.
getInteger
(
page
)
);
potentiallyFreePages
.
remove
(
page
);
}
}
else
{
firstFreePage
=
Math
.
min
(
firstFreePage
,
page
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Column.java
浏览文件 @
e126424c
...
...
@@ -381,8 +381,7 @@ public class Column {
public
String
getCreateSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
if
(
name
!=
null
)
{
buff
.
append
(
Parser
.
quoteIdentifier
(
name
));
buff
.
append
(
' '
);
buff
.
append
(
Parser
.
quoteIdentifier
(
name
)).
append
(
' '
);
}
if
(
originalSQL
!=
null
)
{
buff
.
append
(
originalSQL
);
...
...
@@ -390,20 +389,14 @@ public class Column {
buff
.
append
(
DataType
.
getDataType
(
type
).
name
);
switch
(
type
)
{
case
Value
.
DECIMAL
:
buff
.
append
(
"("
);
buff
.
append
(
precision
);
buff
.
append
(
", "
);
buff
.
append
(
scale
);
buff
.
append
(
")"
);
buff
.
append
(
'('
).
append
(
precision
).
append
(
", "
).
append
(
scale
).
append
(
')'
);
break
;
case
Value
.
BYTES
:
case
Value
.
STRING
:
case
Value
.
STRING_IGNORECASE
:
case
Value
.
STRING_FIXED
:
if
(
precision
<
Integer
.
MAX_VALUE
)
{
buff
.
append
(
"("
);
buff
.
append
(
precision
);
buff
.
append
(
")"
);
buff
.
append
(
'('
).
append
(
precision
).
append
(
")"
);
}
break
;
default
:
...
...
@@ -413,11 +406,9 @@ public class Column {
String
sql
=
defaultExpression
.
getSQL
();
if
(
sql
!=
null
)
{
if
(
isComputed
)
{
buff
.
append
(
" AS "
);
buff
.
append
(
sql
);
buff
.
append
(
" AS "
).
append
(
sql
);
}
else
if
(
defaultExpression
!=
null
)
{
buff
.
append
(
" DEFAULT "
);
buff
.
append
(
sql
);
buff
.
append
(
" DEFAULT "
).
append
(
sql
);
}
}
}
...
...
@@ -428,20 +419,16 @@ public class Column {
buff
.
append
(
" NULL_TO_DEFAULT"
);
}
if
(
sequence
!=
null
)
{
buff
.
append
(
" SEQUENCE "
);
buff
.
append
(
sequence
.
getSQL
());
buff
.
append
(
" SEQUENCE "
).
append
(
sequence
.
getSQL
());
}
if
(
selectivity
!=
0
)
{
buff
.
append
(
" SELECTIVITY "
);
buff
.
append
(
selectivity
);
buff
.
append
(
" SELECTIVITY "
).
append
(
selectivity
);
}
if
(
checkConstraint
!=
null
)
{
buff
.
append
(
" CHECK "
);
buff
.
append
(
checkConstraintSQL
);
buff
.
append
(
" CHECK "
).
append
(
checkConstraintSQL
);
}
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
return
buff
.
toString
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
e126424c
...
...
@@ -53,6 +53,7 @@ import org.h2.store.DiskFile;
import
org.h2.tools.Csv
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.Resources
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.CompareMode
;
import
org.h2.value.DataType
;
...
...
@@ -1047,9 +1048,7 @@ public class MetaTable extends Table {
}
case
FUNCTION_ALIASES:
{
for
(
FunctionAlias
alias
:
database
.
getAllFunctionAliases
())
{
FunctionAlias
.
JavaMethod
[]
methods
=
alias
.
getJavaMethods
();
for
(
int
j
=
0
;
j
<
methods
.
length
;
j
++)
{
FunctionAlias
.
JavaMethod
method
=
methods
[
j
];
for
(
FunctionAlias
.
JavaMethod
method
:
alias
.
getJavaMethods
())
{
int
returnsResult
=
method
.
getDataType
()
==
Value
.
NULL
?
DatabaseMetaData
.
procedureNoResult
:
DatabaseMetaData
.
procedureReturnsResult
;
add
(
rows
,
new
String
[]
{
...
...
@@ -1105,9 +1104,7 @@ public class MetaTable extends Table {
}
case
FUNCTION_COLUMNS:
{
for
(
FunctionAlias
alias
:
database
.
getAllFunctionAliases
())
{
FunctionAlias
.
JavaMethod
[]
methods
=
alias
.
getJavaMethods
();
for
(
int
j
=
0
;
j
<
methods
.
length
;
j
++)
{
FunctionAlias
.
JavaMethod
method
=
methods
[
j
];
for
(
FunctionAlias
.
JavaMethod
method
:
alias
.
getJavaMethods
())
{
Class
<
?
>[]
columns
=
method
.
getColumnClasses
();
for
(
int
k
=
0
;
k
<
columns
.
length
;
k
++)
{
Class
<
?
>
clazz
=
columns
[
k
];
...
...
@@ -1204,10 +1201,8 @@ public class MetaTable extends Table {
}
DbObject
grantee
=
r
.
getGrantee
();
int
mask
=
r
.
getRightMask
();
Column
[]
columns
=
table
.
getColumns
();
for
(
int
j
=
0
;
j
<
columns
.
length
;
j
++)
{
String
column
=
columns
[
j
].
getName
();
addPrivileges
(
rows
,
grantee
,
catalog
,
table
,
column
,
mask
);
for
(
Column
column
:
table
.
getColumns
())
{
addPrivileges
(
rows
,
grantee
,
catalog
,
table
,
column
.
getName
(),
mask
);
}
}
break
;
...
...
@@ -1507,9 +1502,7 @@ public class MetaTable extends Table {
boolean
admin
=
session
.
getUser
().
getAdmin
();
for
(
Session
s
:
database
.
getSessions
(
false
))
{
if
(
admin
||
s
==
session
)
{
Table
[]
locks
=
s
.
getLocks
();
for
(
int
j
=
0
;
j
<
locks
.
length
;
j
++)
{
Table
table
=
locks
[
j
];
for
(
Table
table
:
s
.
getLocks
())
{
add
(
rows
,
new
String
[]
{
// TABLE_SCHEMA
table
.
getSchema
().
getName
(),
...
...
@@ -1545,13 +1538,10 @@ public class MetaTable extends Table {
}
String
[]
path
=
session
.
getSchemaSearchPath
();
if
(
path
!=
null
&&
path
.
length
>
0
)
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"SET SCHEMA_SEARCH_PATH "
);
for
(
int
i
=
0
;
i
<
path
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
StringUtils
.
quoteIdentifier
(
path
[
i
]));
StatementBuilder
buff
=
new
StatementBuilder
(
"SET SCHEMA_SEARCH_PATH "
);
for
(
String
p
:
path
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
StringUtils
.
quoteIdentifier
(
p
));
}
add
(
rows
,
new
String
[]
{
// KEY
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Plan.java
浏览文件 @
e126424c
...
...
@@ -128,8 +128,8 @@ public class Plan {
}
private
void
setEvaluatable
(
TableFilter
filter
,
boolean
b
)
{
for
(
int
j
=
0
;
j
<
allConditions
.
length
;
j
++
)
{
allConditions
[
j
]
.
setEvaluatable
(
filter
,
b
);
for
(
Expression
e
:
allConditions
)
{
e
.
setEvaluatable
(
filter
,
b
);
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableData.java
浏览文件 @
e126424c
...
...
@@ -41,6 +41,7 @@ import org.h2.store.RecordReader;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
...
...
@@ -167,8 +168,8 @@ public class TableData extends Table implements RecordReader {
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
indexComment
)
throws
SQLException
{
if
(
indexType
.
getPrimaryKey
())
{
for
(
int
i
=
0
;
i
<
cols
.
length
;
i
++
)
{
Column
column
=
c
ols
[
i
]
.
column
;
for
(
IndexColumn
c
:
cols
)
{
Column
column
=
c
.
column
;
if
(
column
.
getNullable
())
{
throw
Message
.
getSQLException
(
ErrorCode
.
COLUMN_MUST_NOT_BE_NULLABLE_1
,
column
.
getName
());
}
...
...
@@ -539,8 +540,7 @@ public class TableData extends Table implements RecordReader {
}
public
String
getCreateSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"CREATE "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"CREATE "
);
if
(
getTemporary
())
{
if
(
globalTemporary
)
{
buff
.
append
(
"GLOBAL "
);
...
...
@@ -556,15 +556,11 @@ public class TableData extends Table implements RecordReader {
buff
.
append
(
"TABLE "
);
buff
.
append
(
getSQL
());
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
buff
.
append
(
"(\n "
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
Column
column
=
columns
[
i
];
if
(
i
>
0
)
{
buff
.
append
(
",\n "
);
}
for
(
Column
column
:
columns
)
{
buff
.
appendExceptFirst
(
",\n "
);
buff
.
append
(
column
.
getCreateSQL
());
}
buff
.
append
(
"\n)"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
e126424c
...
...
@@ -24,6 +24,7 @@ import org.h2.result.Row;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
...
...
@@ -503,7 +504,7 @@ public class TableFilter implements ColumnResolver {
* @return the SQL statement snippet
*/
public
String
getPlanSQL
(
boolean
join
)
{
StringBu
ffer
buff
=
new
StringBuff
er
();
StringBu
ilder
buff
=
new
StringBuild
er
();
if
(
join
)
{
if
(
outerJoin
)
{
buff
.
append
(
"LEFT OUTER JOIN "
);
...
...
@@ -513,27 +514,21 @@ public class TableFilter implements ColumnResolver {
}
buff
.
append
(
table
.
getSQL
());
if
(
alias
!=
null
)
{
buff
.
append
(
' '
);
buff
.
append
(
Parser
.
quoteIdentifier
(
alias
));
buff
.
append
(
' '
).
append
(
Parser
.
quoteIdentifier
(
alias
));
}
if
(
index
!=
null
)
{
buff
.
append
(
" /* "
);
St
ringBuffer
planBuff
=
new
StringBuff
er
();
St
atementBuilder
planBuff
=
new
StatementBuild
er
();
planBuff
.
append
(
index
.
getPlanSQL
());
if
(
indexConditions
.
size
()
>
0
)
{
planBuff
.
append
(
": "
);
for
(
int
i
=
0
;
i
<
indexConditions
.
size
();
i
++)
{
IndexCondition
condition
=
indexConditions
.
get
(
i
);
if
(
i
>
0
)
{
planBuff
.
append
(
" AND "
);
}
for
(
IndexCondition
condition
:
indexConditions
)
{
planBuff
.
appendExceptFirst
(
" AND "
);
planBuff
.
append
(
condition
.
getSQL
());
}
}
String
plan
=
planBuff
.
toString
();
plan
=
StringUtils
.
quoteRemarkSQL
(
plan
);
buff
.
append
(
plan
);
buff
.
append
(
" */"
);
String
plan
=
StringUtils
.
quoteRemarkSQL
(
planBuff
.
toString
());
buff
.
append
(
plan
).
append
(
" */"
);
}
if
(
join
)
{
buff
.
append
(
" ON "
);
...
...
@@ -548,8 +543,7 @@ public class TableFilter implements ColumnResolver {
buff
.
append
(
" /* WHERE "
);
String
condition
=
StringUtils
.
unEnclose
(
filterCondition
.
getSQL
());
condition
=
StringUtils
.
quoteRemarkSQL
(
condition
);
buff
.
append
(
condition
);
buff
.
append
(
" */"
);
buff
.
append
(
condition
).
append
(
" */"
);
}
return
buff
.
toString
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
e126424c
...
...
@@ -310,7 +310,7 @@ public class TableLink extends Table {
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
buff
.
append
(
"("
);
buff
.
append
(
'('
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
driver
));
buff
.
append
(
", "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
url
));
...
...
@@ -320,7 +320,7 @@ public class TableLink extends Table {
buff
.
append
(
StringUtils
.
quoteStringSQL
(
password
));
buff
.
append
(
", "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
originalTable
));
buff
.
append
(
")"
);
buff
.
append
(
')'
);
if
(
emitUpdates
)
{
buff
.
append
(
" EMIT UPDATES"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableView.java
浏览文件 @
e126424c
...
...
@@ -24,6 +24,7 @@ import org.h2.schema.Schema;
import
org.h2.util.IntArray
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
...
...
@@ -153,35 +154,27 @@ public class TableView extends Table {
}
public
String
getCreateSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"CREATE FORCE VIEW "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"CREATE FORCE VIEW "
);
buff
.
append
(
getSQL
());
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
if
(
columns
.
length
>
0
)
{
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
for
(
Column
c
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
}
else
if
(
columnNames
!=
null
)
{
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
columnNames
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columnNames
[
i
]);
for
(
String
n
:
columnNames
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
n
);
}
buff
.
append
(
")"
);
buff
.
append
(
')'
);
}
buff
.
append
(
" AS\n"
);
buff
.
append
(
querySQL
);
return
buff
.
toString
();
return
buff
.
append
(
" AS\n"
).
append
(
querySQL
).
toString
();
}
public
void
checkRename
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/ChangeFileEncryption.java
浏览文件 @
e126424c
...
...
@@ -124,8 +124,8 @@ public class ChangeFileEncryption extends Tool {
private
void
process
(
String
dir
,
String
db
,
String
cipher
,
char
[]
decryptPassword
,
char
[]
encryptPassword
,
boolean
quiet
)
throws
SQLException
{
ChangeFileEncryption
change
=
new
ChangeFileEncryption
();
if
(
encryptPassword
!=
null
)
{
for
(
int
i
=
0
;
i
<
encryptPassword
.
length
;
i
++
)
{
if
(
encryptPassword
[
i
]
==
' '
)
{
for
(
char
c
:
encryptPassword
)
{
if
(
c
==
' '
)
{
throw
new
SQLException
(
"The file password may not contain spaces"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/MultiDimension.java
浏览文件 @
e126424c
...
...
@@ -12,9 +12,8 @@ import java.sql.SQLException;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
org.h2.util.New
;
import
org.h2.util.
ObjectUtils
;
import
org.h2.util.
StatementBuilder
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -136,8 +135,8 @@ public class MultiDimension {
Long
[]
from
=
new
Long
[
len
];
Long
[]
to
=
new
Long
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
from
[
i
]
=
ObjectUtils
.
getLong
(
ranges
[
i
][
0
]);
to
[
i
]
=
ObjectUtils
.
getLong
(
ranges
[
i
][
1
]);
from
[
i
]
=
Long
.
valueOf
(
ranges
[
i
][
0
]);
to
[
i
]
=
Long
.
valueOf
(
ranges
[
i
][
1
]);
}
prep
.
setObject
(
1
,
from
);
prep
.
setObject
(
2
,
to
);
...
...
@@ -163,24 +162,31 @@ public class MultiDimension {
*/
public
String
generateQuery
(
String
table
,
String
scalarColumn
,
String
[]
columns
,
int
[]
min
,
int
[]
max
)
{
long
[][]
ranges
=
getMortonRanges
(
min
,
max
);
StringBuffer
buff
=
new
StringBuffer
(
"SELECT * FROM ("
);
for
(
int
i
=
0
;
i
<
ranges
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
" UNION ALL "
);
}
long
minScalar
=
ranges
[
i
][
0
];
long
maxScalar
=
ranges
[
i
][
1
];
buff
.
append
(
"SELECT * FROM "
).
append
(
table
).
append
(
" WHERE "
);
buff
.
append
(
scalarColumn
).
append
(
" BETWEEN "
);
buff
.
append
(
minScalar
).
append
(
" AND "
).
append
(
maxScalar
);
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT * FROM ("
);
for
(
long
[]
range
:
ranges
)
{
long
minScalar
=
range
[
0
];
long
maxScalar
=
range
[
1
];
buff
.
appendExceptFirst
(
" UNION ALL "
);
buff
.
append
(
"SELECT * FROM "
).
append
(
table
).
append
(
" WHERE "
).
append
(
scalarColumn
).
append
(
" BETWEEN "
).
append
(
minScalar
).
append
(
" AND "
).
append
(
maxScalar
);
}
buff
.
append
(
") WHERE "
);
for
(
int
j
=
0
;
j
<
columns
.
length
;
j
++)
{
if
(
j
>
0
)
{
buff
.
append
(
" AND "
);
}
buff
.
append
(
columns
[
j
]).
append
(
" BETWEEN "
);
buff
.
append
(
min
[
j
]).
append
(
" AND "
).
append
(
max
[
j
]);
int
i
=
0
;
buff
.
resetCount
();
for
(
String
col
:
columns
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
col
).
append
(
" BETWEEN "
).
append
(
min
[
i
]).
append
(
" AND "
).
append
(
max
[
i
]);
i
++;
}
return
buff
.
toString
();
}
...
...
@@ -251,8 +257,7 @@ public class MultiDimension {
}
}
int
searched
=
0
;
for
(
int
j
=
0
;
j
<
list
.
size
();
j
++)
{
long
[]
range
=
list
.
get
(
j
);
for
(
long
[]
range
:
list
)
{
searched
+=
range
[
1
]
-
range
[
0
]
+
1
;
}
if
(
searched
>
2
*
total
||
list
.
size
()
<
3
/* || minGap > total */
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
e126424c
...
...
@@ -49,6 +49,7 @@ import org.h2.util.New;
import
org.h2.util.ObjectArray
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.TempFileDeleter
;
import
org.h2.util.Tool
;
import
org.h2.value.Value
;
...
...
@@ -1225,18 +1226,13 @@ public class Recover extends Tool implements DataHandler {
private
void
createTemporaryTable
(
PrintWriter
writer
)
{
if
(!
objectIdSet
.
contains
(
storageId
))
{
objectIdSet
.
add
(
storageId
);
St
ringBuffer
sb
=
new
StringBuffer
(
);
sb
.
append
(
"CREATE TABLE O_"
+
storageName
+
"("
);
St
atementBuilder
buff
=
new
StatementBuilder
(
"CREATE TABLE O_"
);
buff
.
append
(
storageName
).
append
(
'('
);
for
(
int
i
=
0
;
i
<
recordLength
;
i
++)
{
if
(
i
>
0
)
{
sb
.
append
(
", "
);
}
sb
.
append
(
"C"
);
sb
.
append
(
i
);
sb
.
append
(
" VARCHAR"
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
'C'
).
append
(
i
).
append
(
" VARCHAR"
);
}
sb
.
append
(
");"
);
writer
.
println
(
sb
.
toString
());
writer
.
println
(
buff
.
append
(
");"
).
toString
());
writer
.
flush
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Shell.java
浏览文件 @
e126424c
...
...
@@ -20,7 +20,6 @@ import java.sql.ResultSetMetaData;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
org.h2.engine.Constants
;
import
org.h2.server.web.ConnectionInfo
;
import
org.h2.util.ClassUtils
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/CacheSecondLevel.java
浏览文件 @
e126424c
...
...
@@ -69,7 +69,7 @@ class CacheSecondLevel implements Cache {
public
void
remove
(
int
pos
)
{
baseCache
.
remove
(
pos
);
map
.
remove
(
ObjectUtils
.
getInteger
(
pos
)
);
map
.
remove
(
pos
);
}
public
void
setMaxSize
(
int
size
)
throws
SQLException
{
...
...
@@ -78,7 +78,7 @@ class CacheSecondLevel implements Cache {
public
CacheObject
update
(
int
pos
,
CacheObject
record
)
throws
SQLException
{
CacheObject
oldRec
=
baseCache
.
update
(
pos
,
record
);
map
.
put
(
ObjectUtils
.
getInteger
(
pos
)
,
record
);
map
.
put
(
pos
,
record
);
return
oldRec
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/ObjectUtils.java
浏览文件 @
e126424c
...
...
@@ -32,115 +32,6 @@ public class ObjectUtils {
// utility class
}
/**
* Create a new object or get a cached object for the given value.
*
* @param x the value
* @return the object
*/
public
static
Integer
getInteger
(
int
x
)
{
//## Java 1.5 begin ##
if
(
true
)
{
return
Integer
.
valueOf
(
x
);
}
//## Java 1.5 end ##
// NOPMD
return
new
Integer
(
x
);
}
/**
* Create a new object or get a cached object for the given value.
*
* @param x the value
* @return the object
*/
public
static
Character
getCharacter
(
char
x
)
{
//## Java 1.5 begin ##
if
(
true
)
{
return
Character
.
valueOf
(
x
);
}
//## Java 1.5 end ##
return
new
Character
(
x
);
}
/**
* Create a new object or get a cached object for the given value.
*
* @param x the value
* @return the object
*/
public
static
Long
getLong
(
long
x
)
{
//## Java 1.5 begin ##
if
(
true
)
{
return
Long
.
valueOf
(
x
);
}
//## Java 1.5 end ##
// NOPMD
return
new
Long
(
x
);
}
/**
* Create a new object or get a cached object for the given value.
*
* @param x the value
* @return the object
*/
public
static
Short
getShort
(
short
x
)
{
//## Java 1.5 begin ##
if
(
true
)
{
return
Short
.
valueOf
(
x
);
}
//## Java 1.5 end ##
// NOPMD
return
new
Short
(
x
);
}
/**
* Create a new object or get a cached object for the given value.
*
* @param x the value
* @return the object
*/
public
static
Byte
getByte
(
byte
x
)
{
//## Java 1.5 begin ##
if
(
true
)
{
return
Byte
.
valueOf
(
x
);
}
//## Java 1.5 end ##
// NOPMD
return
new
Byte
(
x
);
}
/**
* Create a new object or get a cached object for the given value.
*
* @param x the value
* @return the object
*/
public
static
Float
getFloat
(
float
x
)
{
//## Java 1.5 begin ##
if
(
true
)
{
return
Float
.
valueOf
(
x
);
}
//## Java 1.5 end ##
return
new
Float
(
x
);
}
/**
* Create a new object or get a cached object for the given value.
*
* @param x the value
* @return the object
*/
public
static
Double
getDouble
(
double
x
)
{
//## Java 1.5 begin ##
if
(
true
)
{
return
Double
.
valueOf
(
x
);
}
//## Java 1.5 end ##
return
new
Double
(
x
);
}
/**
* Serialize the object to a byte array.
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/SmallMap.java
浏览文件 @
e126424c
...
...
@@ -53,7 +53,7 @@ public class SmallMap {
if
(
id
>
lastId
)
{
lastId
=
id
;
}
map
.
put
(
ObjectUtils
.
getInteger
(
id
)
,
o
);
map
.
put
(
id
,
o
);
cacheId
=
id
;
cache
=
o
;
return
id
;
...
...
@@ -69,7 +69,7 @@ public class SmallMap {
cacheId
=
-
1
;
cache
=
null
;
}
map
.
remove
(
ObjectUtils
.
getInteger
(
id
)
);
map
.
remove
(
id
);
}
/**
...
...
@@ -85,7 +85,7 @@ public class SmallMap {
if
(
id
==
cacheId
)
{
return
cache
;
}
Object
obj
=
map
.
get
(
ObjectUtils
.
getInteger
(
id
)
);
Object
obj
=
map
.
get
(
id
);
if
(
obj
==
null
&&
!
ifAvailable
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
OBJECT_CLOSED
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/StatementBuilder.java
0 → 100644
浏览文件 @
e126424c
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
util
;
/**
* A utility class to build a statement. In addition to the methods supported by StringBuilder,
* it allows to add a text only in the second iteration. This simplified constructs such as:
* <pre>
* StringBuilder buff = new StringBuilder();
* for (int i = 0; i < args.length; i++) {
* if (i > 0) {
* buff.append(", ");
* }
* buff.append(args[i]);
* }
* </pre>
* to
* <pre>
* StatementBuilder buff = new StatementBuilder();
* for (String s : args) {
* buff.appendExceptFirst(", ");
* buff.append(a);
* }
*</pre>
*/
public
class
StatementBuilder
{
private
StringBuilder
builder
=
new
StringBuilder
();
private
int
index
;
/**
* Create a new builder.
*/
public
StatementBuilder
()
{
}
/**
* Create a new builder.
*
* @param string the initial string
*/
public
StatementBuilder
(
String
string
)
{
builder
.
append
(
string
);
}
/**
* Append a text.
*
* @param s the text to append
* @return itself
*/
public
StatementBuilder
append
(
String
s
)
{
builder
.
append
(
s
);
return
this
;
}
/**
* Append a character.
*
* @param c the character to append
* @return itself
*/
public
StatementBuilder
append
(
char
c
)
{
builder
.
append
(
c
);
return
this
;
}
/**
* Append a number.
*
* @param x the number to append
* @return itself
*/
public
StatementBuilder
append
(
long
x
)
{
builder
.
append
(
x
);
return
this
;
}
/**
* Reset the loop counter.
*
* @return itself
*/
public
StatementBuilder
resetCount
()
{
index
=
0
;
return
this
;
}
/**
* Append a text, but only if appendExceptFirst was never called.
*
* @param s the text to append
* @return itself
*/
public
void
appendOnlyFirst
(
String
s
)
{
if
(
index
==
0
)
{
builder
.
append
(
s
);
}
}
/**
* Append a text, except when this method is called the first time.
*
* @param s the text to append
*/
public
void
appendExceptFirst
(
String
s
)
{
if
(
index
++
>
0
)
{
builder
.
append
(
s
);
}
}
public
String
toString
()
{
return
builder
.
toString
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
e126424c
...
...
@@ -326,16 +326,12 @@ public class StringUtils {
if
(
array
==
null
)
{
return
"null"
;
}
StringBuffer
buff
=
new
StringBuffer
(
5
*
array
.
length
);
buff
.
append
(
"new String[]{"
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
quoteJavaString
(
array
[
i
]));
StatementBuilder
buff
=
new
StatementBuilder
(
"new String[]{"
);
for
(
String
a
:
array
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
quoteJavaString
(
a
));
}
buff
.
append
(
"}"
);
return
buff
.
toString
();
return
buff
.
append
(
"}"
).
toString
();
}
/**
...
...
@@ -349,16 +345,12 @@ public class StringUtils {
if
(
array
==
null
)
{
return
"null"
;
}
StringBuffer
buff
=
new
StringBuffer
(
2
*
array
.
length
);
buff
.
append
(
"new int[]{"
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
array
[
i
]);
StatementBuilder
buff
=
new
StatementBuilder
(
"new int[]{"
);
for
(
int
a
:
array
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
a
);
}
buff
.
append
(
"}"
);
return
buff
.
toString
();
return
buff
.
append
(
"}"
).
toString
();
}
/**
...
...
@@ -490,12 +482,9 @@ public class StringUtils {
* @return the combined string
*/
public
static
String
arrayCombine
(
String
[]
list
,
char
separatorChar
)
{
StringBuffer
buff
=
new
StringBuffer
(
5
*
list
.
length
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
separatorChar
);
}
String
s
=
list
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
String
s
:
list
)
{
buff
.
appendExceptFirst
(
String
.
valueOf
(
separatorChar
));
if
(
s
==
null
)
{
s
=
""
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/DataType.java
浏览文件 @
e126424c
...
...
@@ -957,19 +957,19 @@ public class DataType {
if
(
clazz
==
Boolean
.
TYPE
)
{
return
Boolean
.
FALSE
;
}
else
if
(
clazz
==
Byte
.
TYPE
)
{
return
ObjectUtils
.
getByte
((
byte
)
0
);
return
Byte
.
valueOf
((
byte
)
0
);
}
else
if
(
clazz
==
Character
.
TYPE
)
{
return
ObjectUtils
.
getCharacter
((
char
)
0
);
return
Character
.
valueOf
((
char
)
0
);
}
else
if
(
clazz
==
Short
.
TYPE
)
{
return
ObjectUtils
.
getShort
((
short
)
0
);
return
Short
.
valueOf
((
short
)
0
);
}
else
if
(
clazz
==
Integer
.
TYPE
)
{
return
ObjectUtils
.
getInteger
(
0
);
return
Integer
.
valueOf
(
0
);
}
else
if
(
clazz
==
Long
.
TYPE
)
{
return
ObjectUtils
.
getLong
(
0
);
return
Long
.
valueOf
(
0
);
}
else
if
(
clazz
==
Float
.
TYPE
)
{
return
ObjectUtils
.
getFloat
(
0
);
return
Float
.
valueOf
(
0
);
}
else
if
(
clazz
==
Double
.
TYPE
)
{
return
ObjectUtils
.
getDouble
(
0
);
return
Double
.
valueOf
(
0
);
}
throw
Message
.
throwInternalError
(
"primitive="
+
clazz
.
toString
());
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueArray.java
浏览文件 @
e126424c
...
...
@@ -9,6 +9,7 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StatementBuilder
;
/**
* Implementation of the ARRAY data type.
...
...
@@ -57,16 +58,12 @@ public class ValueArray extends Value {
}
public
String
getString
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
values
[
i
].
getString
());
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
for
(
Value
v
:
values
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
v
.
getString
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
throws
SQLException
{
...
...
@@ -101,30 +98,23 @@ public class ValueArray extends Value {
}
public
String
getSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
values
[
i
].
getSQL
());
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
for
(
Value
v
:
values
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
v
.
getSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
String
getTraceSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
values
[
i
].
getTraceSQL
());
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
for
(
Value
v
:
values
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
v
.
getTraceSQL
());
}
buff
.
append
(
')'
);
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
public
int
getDisplaySize
()
{
long
size
=
0
;
for
(
Value
v
:
values
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueByte.java
浏览文件 @
e126424c
...
...
@@ -8,11 +8,9 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.ObjectUtils
;
/**
* Implementation of the BYTE data type.
...
...
@@ -119,7 +117,7 @@ public class ValueByte extends Value {
}
public
Object
getObject
()
{
return
ObjectUtils
.
getByte
(
value
);
return
Byte
.
valueOf
(
value
);
}
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueDouble.java
浏览文件 @
e126424c
...
...
@@ -8,10 +8,8 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.Message
;
import
org.h2.util.ObjectUtils
;
/**
* Implementation of the DOUBLE data type.
...
...
@@ -115,7 +113,7 @@ public class ValueDouble extends Value {
}
public
Object
getObject
()
{
return
ObjectUtils
.
getDouble
(
value
);
return
Double
.
valueOf
(
value
);
}
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueFloat.java
浏览文件 @
e126424c
...
...
@@ -8,10 +8,8 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.Message
;
import
org.h2.util.ObjectUtils
;
/**
* Implementation of the REAL data type.
...
...
@@ -114,7 +112,7 @@ public class ValueFloat extends Value {
}
public
Object
getObject
()
{
return
ObjectUtils
.
getFloat
(
value
);
return
Float
.
valueOf
(
value
);
}
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueInt.java
浏览文件 @
e126424c
...
...
@@ -8,11 +8,9 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.ObjectUtils
;
/**
* Implementation of the INT data type.
...
...
@@ -149,7 +147,7 @@ public class ValueInt extends Value {
}
public
Object
getObject
()
{
return
ObjectUtils
.
getInteger
(
value
)
;
return
value
;
}
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueLong.java
浏览文件 @
e126424c
...
...
@@ -9,11 +9,9 @@ package org.h2.value;
import
java.math.BigInteger
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.ObjectUtils
;
/**
* Implementation of the BIGINT data type.
...
...
@@ -173,7 +171,7 @@ public class ValueLong extends Value {
}
public
Object
getObject
()
{
return
ObjectUtils
.
getLong
(
value
)
;
return
value
;
}
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueResultSet.java
浏览文件 @
e126424c
...
...
@@ -13,6 +13,7 @@ import java.sql.SQLException;
import
org.h2.message.Message
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.StatementBuilder
;
/**
* Implementation of the RESULT_SET data type.
...
...
@@ -83,8 +84,7 @@ public class ValueResultSet extends Value {
public
String
getString
()
{
try
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"("
);
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
result
.
beforeFirst
();
ResultSetMetaData
meta
=
result
.
getMetaData
();
int
columnCount
=
meta
.
getColumnCount
();
...
...
@@ -93,19 +93,17 @@ public class ValueResultSet extends Value {
buff
.
append
(
", "
);
}
buff
.
append
(
'('
);
buff
.
resetCount
();
for
(
int
j
=
0
;
j
<
columnCount
;
j
++)
{
if
(
j
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
appendExceptFirst
(
", "
);
int
t
=
DataType
.
convertSQLTypeToValueType
(
meta
.
getColumnType
(
j
+
1
));
Value
v
=
DataType
.
readValue
(
null
,
result
,
j
+
1
,
t
);
buff
.
append
(
v
.
getString
());
}
buff
.
append
(
')'
);
}
buff
.
append
(
")"
);
result
.
beforeFirst
();
return
buff
.
toString
();
return
buff
.
append
(
')'
).
toString
();
}
catch
(
SQLException
e
)
{
throw
Message
.
convertToInternal
(
e
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueShort.java
浏览文件 @
e126424c
...
...
@@ -8,11 +8,9 @@ package org.h2.value;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.ObjectUtils
;
/**
* Implementation of the SMALLINT data type.
...
...
@@ -119,7 +117,7 @@ public class ValueShort extends Value {
}
public
Object
getObject
()
{
return
ObjectUtils
.
getShort
(
value
);
return
Short
.
valueOf
(
value
);
}
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
e126424c
...
...
@@ -292,6 +292,15 @@ java org.h2.test.TestAll timer
/*
recover tool: move
alter table add constraint behind insert into select
i > 0 -> StatementBuidler
StringBuffer > StringBuilder
buff.append... chain
SqlStatement.appendExceptFirst
append(".") > append('.')
BaseIndex or TableData should have its own compareMode
(default is: Database.compareMode when created).
standard: COLLATE for each column (MySQL, SQL Server)
...
...
@@ -464,7 +473,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
beforeTest
();
// db
//
new TestScriptSimple().runTest(this);
new
TestScriptSimple
().
runTest
(
this
);
new
TestScript
().
runTest
(
this
);
new
TestAlter
().
runTest
(
this
);
new
TestAutoRecompile
().
runTest
(
this
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
e126424c
...
...
@@ -906,8 +906,8 @@ public abstract class TestBase {
private
String
formatRow
(
String
[]
row
)
{
String
sb
=
""
;
for
(
int
i
=
0
;
i
<
row
.
length
;
i
++
)
{
sb
+=
"{"
+
r
ow
[
i
]
+
"}"
;
for
(
String
r
:
row
)
{
sb
+=
"{"
+
r
+
"}"
;
}
return
"{"
+
sb
+
"}"
;
}
...
...
@@ -1020,8 +1020,7 @@ public abstract class TestBase {
String
s2
=
rs2
.
getString
(
1
);
list2
.
add
(
s2
);
}
for
(
int
i
=
0
;
i
<
list1
.
size
();
i
++)
{
String
s
=
list1
.
get
(
i
);
for
(
String
s
:
list1
)
{
if
(!
list2
.
remove
(
s
))
{
fail
(
"only found in first: "
+
s
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/coverage/Coverage.java
浏览文件 @
e126424c
...
...
@@ -97,8 +97,8 @@ public class Coverage {
}
private
boolean
isExcluded
(
String
s
)
{
for
(
int
i
=
0
;
i
<
exclude
.
size
();
i
++
)
{
if
(
s
.
startsWith
(
e
xclude
.
get
(
i
).
toString
()
))
{
for
(
String
e
:
exclude
)
{
if
(
s
.
startsWith
(
e
))
{
return
true
;
}
}
...
...
@@ -112,9 +112,8 @@ public class Coverage {
files
.
add
(
path
);
}
}
else
if
(
f
.
isDirectory
()
&&
recurse
>
0
)
{
String
[]
list
=
f
.
list
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
addDir
(
path
+
"/"
+
list
[
i
],
recurse
-
1
);
for
(
String
name
:
f
.
list
())
{
addDir
(
path
+
"/"
+
name
,
recurse
-
1
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
e126424c
...
...
@@ -76,8 +76,7 @@ public class TestCompatibility extends TestBase {
columnAlias
=
"MySQL,Regular"
;
}
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
for
(
int
i
=
0
;
i
<
modes
.
length
;
i
++)
{
String
mode
=
modes
[
i
];
for
(
String
mode
:
modes
)
{
stat
.
execute
(
"SET MODE "
+
mode
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT ID I FROM TEST"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
...
...
@@ -98,8 +97,7 @@ public class TestCompatibility extends TestBase {
Statement
stat
=
conn
.
createStatement
();
String
[]
modes
=
new
String
[]
{
"PostgreSQL"
,
"MySQL"
,
"HSQLDB"
,
"MSSQLServer"
,
"Derby"
,
"Oracle"
,
"Regular"
};
String
multiNull
=
"PostgreSQL,MySQL,Oracle,Regular"
;
for
(
int
i
=
0
;
i
<
modes
.
length
;
i
++)
{
String
mode
=
modes
[
i
];
for
(
String
mode
:
modes
)
{
stat
.
execute
(
"SET MODE "
+
mode
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"CREATE UNIQUE INDEX IDX_ID_U ON TEST(ID)"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestLinkedTable.java
浏览文件 @
e126424c
...
...
@@ -150,9 +150,9 @@ public class TestLinkedTable extends TestBase {
sb
.
execute
(
sql
);
sb
.
executeQuery
(
"SELECT * FROM T"
);
String
[]
update
=
new
String
[]{
"DELETE FROM T"
,
"INSERT INTO T VALUES(2)"
,
"UPDATE T SET ID = 3"
};
for
(
int
j
=
0
;
j
<
update
.
length
;
j
++
)
{
for
(
String
u
:
update
)
{
try
{
sb
.
execute
(
u
pdate
[
j
]
);
sb
.
execute
(
u
);
if
(
i
==
1
)
{
fail
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestLogFile.java
浏览文件 @
e126424c
...
...
@@ -41,8 +41,7 @@ public class TestLogFile extends TestBase {
long
length
=
0
;
ArrayList
<
String
>
files
=
FileLister
.
getDatabaseFiles
(
baseDir
,
"logfile"
,
false
);
assertSmaller
(
files
.
size
(),
maxFiles
+
2
);
for
(
int
i
=
0
;
i
<
files
.
size
();
i
++)
{
String
fileName
=
files
.
get
(
i
);
for
(
String
fileName
:
files
)
{
long
len
=
new
File
(
fileName
).
length
();
length
+=
len
;
}
...
...
@@ -77,9 +76,7 @@ public class TestLogFile extends TestBase {
}
private
void
checkLogSize
()
{
String
[]
files
=
new
File
(
"."
).
list
();
for
(
int
j
=
0
;
j
<
files
.
length
;
j
++)
{
String
name
=
files
[
j
];
for
(
String
name
:
new
File
(
getTestDir
(
""
)).
list
())
{
if
(
name
.
startsWith
(
"logfile"
)
&&
name
.
endsWith
(
".log.db"
))
{
long
length
=
new
File
(
name
).
length
();
assertSmaller
(
length
,
MAX_LOG_SIZE
*
1024
*
1024
*
2
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestPowerOff.java
浏览文件 @
e126424c
...
...
@@ -11,7 +11,6 @@ import java.sql.DatabaseMetaData;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Random
;
import
org.h2.constant.SysProperties
;
...
...
@@ -180,9 +179,7 @@ public class TestPowerOff extends TestBase {
assertKnownException
(
e
);
}
boolean
deleted
=
false
;
ArrayList
<
String
>
files
=
FileLister
.
getDatabaseFiles
(
dir
,
dbName
,
false
);
for
(
int
i
=
0
;
i
<
files
.
size
();
i
++)
{
String
fileName
=
files
.
get
(
i
);
for
(
String
fileName
:
FileLister
.
getDatabaseFiles
(
dir
,
dbName
,
false
))
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_INDEX_FILE
))
{
FileUtils
.
delete
(
fileName
);
deleted
=
true
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestReadOnly.java
浏览文件 @
e126424c
...
...
@@ -132,8 +132,7 @@ public class TestReadOnly extends TestBase {
private
void
setReadOnly
()
throws
SQLException
{
String
lastLogFile
=
null
;
ArrayList
<
String
>
list
=
FileLister
.
getDatabaseFiles
(
TestBase
.
baseDir
,
"readonly"
,
true
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
fileName
=
list
.
get
(
i
);
for
(
String
fileName
:
list
)
{
File
file
=
new
File
(
fileName
);
file
.
setReadOnly
();
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_LOG_FILE
))
{
...
...
@@ -143,8 +142,7 @@ public class TestReadOnly extends TestBase {
}
}
// delete all log files except the last one
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
fileName
=
list
.
get
(
i
);
for
(
String
fileName
:
list
)
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_LOG_FILE
))
{
if
(!
lastLogFile
.
equals
(
fileName
))
{
File
file
=
new
File
(
fileName
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
浏览文件 @
e126424c
...
...
@@ -71,8 +71,7 @@ public class TestTwoPhaseCommit extends TestBase {
while
(
rs
.
next
())
{
list
.
add
(
rs
.
getString
(
"TRANSACTION"
));
}
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
s
=
list
.
get
(
i
);
for
(
String
s
:
list
)
{
if
(
rollback
)
{
stat
.
execute
(
"ROLLBACK TRANSACTION "
+
s
);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestBatchUpdates.java
浏览文件 @
e126424c
...
...
@@ -439,9 +439,8 @@ public class TestBatchUpdates extends TestBase {
stat
.
executeBatch
();
}
catch
(
BatchUpdateException
b
)
{
batchExceptionFlag
=
true
;
int
[]
updCounts
=
b
.
getUpdateCounts
();
for
(
int
i
=
0
;
i
<
updCounts
.
length
;
i
++)
{
trace
(
"Update counts:"
+
updCounts
[
i
]);
for
(
int
uc
:
b
.
getUpdateCounts
())
{
trace
(
"Update counts:"
+
uc
);
}
}
if
(
batchExceptionFlag
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
e126424c
...
...
@@ -948,8 +948,7 @@ public class TestPreparedStatement extends TestBase {
}
private
void
checkBigDecimal
(
ResultSet
rs
,
String
[]
value
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++)
{
String
v
=
value
[
i
];
for
(
String
v
:
value
)
{
assertTrue
(
rs
.
next
());
java
.
math
.
BigDecimal
x
=
rs
.
getBigDecimal
(
1
);
trace
(
"v="
+
v
+
" x="
+
x
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestResultSet.java
浏览文件 @
e126424c
...
...
@@ -785,10 +785,9 @@ public class TestResultSet extends TestBase {
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?, ?, ?)"
);
Calendar
regular
=
Calendar
.
getInstance
();
Calendar
other
=
null
;
String
[]
timeZones
=
TimeZone
.
getAvailableIDs
();
// search a locale that has a _different_ raw offset
for
(
int
i
=
0
;
i
<
timeZones
.
length
;
i
++
)
{
TimeZone
zone
=
TimeZone
.
getTimeZone
(
timeZones
[
i
]
);
for
(
String
s
:
TimeZone
.
getAvailableIDs
()
)
{
TimeZone
zone
=
TimeZone
.
getTimeZone
(
s
);
if
(
regular
.
getTimeZone
().
getRawOffset
()
!=
zone
.
getRawOffset
())
{
other
=
Calendar
.
getInstance
(
zone
);
break
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/poweroff/Test.java
浏览文件 @
e126424c
...
...
@@ -154,8 +154,8 @@ public class Test {
new
Test
(
"org.h2.Driver"
,
"jdbc:h2:test5"
,
"sa"
,
""
,
true
),
new
Test
(
"org.h2.Driver"
,
"jdbc:h2:test6"
,
"sa"
,
""
,
false
),
};
for
(
int
i
=
0
;;
i
++)
{
for
(
int
j
=
0
;
j
<
dbs
.
length
;
j
++
)
{
dbs
[
j
]
.
insert
(
i
);
for
(
Test
t
:
dbs
)
{
t
.
insert
(
i
);
}
out
.
writeInt
(
i
);
out
.
flush
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/poweroff/TestRecover.java
浏览文件 @
e126424c
...
...
@@ -88,11 +88,9 @@ public class TestRecover {
root
.
mkdirs
();
}
while
(
true
)
{
File
[]
list
=
root
.
listFiles
();
File
oldest
=
null
;
int
count
=
0
;
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
File
f
=
list
[
i
];
for
(
File
f
:
root
.
listFiles
())
{
String
name
=
f
.
getName
();
if
(
f
.
isFile
()
&&
name
.
startsWith
(
"backup"
)
&&
name
.
endsWith
(
".zip"
))
{
count
++;
...
...
@@ -121,8 +119,7 @@ public class TestRecover {
out
=
new
FileOutputStream
(
zipFile
);
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
out
);
String
baseName
=
base
.
getAbsolutePath
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
File
f
=
list
.
get
(
i
);
for
(
File
f
:
list
)
{
String
fileName
=
f
.
getAbsolutePath
();
String
entryName
=
fileName
;
if
(
fileName
.
startsWith
(
baseName
))
{
...
...
@@ -168,9 +165,8 @@ public class TestRecover {
private
static
void
deleteRecursive
(
File
file
)
throws
IOException
{
if
(
file
.
isDirectory
())
{
File
[]
list
=
file
.
listFiles
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
deleteRecursive
(
list
[
i
]);
for
(
File
f
:
file
.
listFiles
())
{
deleteRecursive
(
f
);
}
}
if
(
file
.
exists
()
&&
!
file
.
delete
())
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/TestCrashAPI.java
浏览文件 @
e126424c
...
...
@@ -371,9 +371,7 @@ public class TestCrashAPI extends TestBase {
}
private
Class
<
?
>
getJdbcInterface
(
Object
o
)
{
Class
<
?
>[]
list
=
o
.
getClass
().
getInterfaces
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
Class
<
?
>
in
=
list
[
i
];
for
(
Class
<
?
>
in
:
o
.
getClass
().
getInterfaces
())
{
if
(
classMethods
.
get
(
in
)
!=
null
)
{
return
in
;
}
...
...
@@ -382,16 +380,12 @@ public class TestCrashAPI extends TestBase {
}
private
void
initMethods
()
{
for
(
int
i
=
0
;
i
<
INTERFACES
.
length
;
i
++)
{
Class
<
?
>
inter
=
INTERFACES
[
i
];
for
(
Class
<
?
>
inter
:
INTERFACES
)
{
classMethods
.
put
(
inter
,
new
ArrayList
<
Method
>());
}
for
(
int
i
=
0
;
i
<
INTERFACES
.
length
;
i
++)
{
Class
<
?
>
inter
=
INTERFACES
[
i
];
for
(
Class
<
?
>
inter
:
INTERFACES
)
{
ArrayList
<
Method
>
list
=
classMethods
.
get
(
inter
);
Method
[]
methods
=
inter
.
getMethods
();
for
(
int
j
=
0
;
j
<
methods
.
length
;
j
++)
{
Method
m
=
methods
[
j
];
for
(
Method
m
:
inter
.
getMethods
())
{
list
.
add
(
m
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/sql/Command.java
浏览文件 @
e126424c
...
...
@@ -9,6 +9,7 @@ package org.h2.test.synth.sql;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
/**
* Represents a statement.
...
...
@@ -287,22 +288,20 @@ class Command {
}
private
Result
select
(
DbInterface
db
)
throws
SQLException
{
String
sql
=
"SELECT "
;
for
(
int
i
=
0
;
i
<
selectList
.
length
;
i
++)
{
if
(
i
>
0
)
{
sql
+=
", "
;
}
sql
+=
selectList
[
i
];
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT "
);
for
(
String
s
:
selectList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
s
);
}
sql
+=
" FROM "
+
table
.
getName
()
+
" M"
;
sql
+=
" "
+
join
;
buff
.
append
(
" FROM "
).
append
(
table
.
getName
()).
append
(
" M"
).
append
(
' '
).
append
(
join
)
;
if
(
condition
!=
null
)
{
sql
+=
" WHERE "
+
condition
;
buff
.
append
(
" WHERE "
).
append
(
condition
)
;
}
if
(
order
.
trim
().
length
()
>
0
)
{
sql
+=
" ORDER BY "
+
order
;
buff
.
append
(
" ORDER BY "
).
append
(
order
)
;
}
return
db
.
select
(
sql
);
return
db
.
select
(
buff
.
toString
()
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/sql/Result.java
浏览文件 @
e126424c
...
...
@@ -94,13 +94,11 @@ class Result implements Comparable<Result> {
}
case
RESULT_SET:
String
result
=
"ResultSet { // size="
+
rows
.
size
()
+
"\r\n "
;
for
(
int
i
=
0
;
i
<
header
.
size
();
i
++)
{
Column
column
=
header
.
get
(
i
);
for
(
Column
column
:
header
)
{
result
+=
column
.
toString
()
+
"; "
;
}
result
+=
"} = {\r\n"
;
for
(
int
i
=
0
;
i
<
rows
.
size
();
i
++)
{
Row
row
=
rows
.
get
(
i
);
for
(
Row
row
:
rows
)
{
result
+=
" { "
+
row
.
toString
()
+
"};\r\n"
;
}
return
result
+
"}"
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/sql/Row.java
浏览文件 @
e126424c
...
...
@@ -24,8 +24,7 @@ class Row implements Comparable<Row> {
public
String
toString
()
{
String
s
=
""
;
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
Object
o
=
data
[
i
];
for
(
Object
o
:
data
)
{
s
+=
o
==
null
?
"NULL"
:
o
.
toString
();
s
+=
"; "
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/sql/Table.java
浏览文件 @
e126424c
...
...
@@ -179,9 +179,9 @@ class Table {
*/
Column
getRandomConditionColumn
()
{
ArrayList
<
Column
>
list
=
New
.
arrayList
();
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++
)
{
if
(
Column
.
isConditionType
(
config
,
col
umns
[
i
]
.
getType
()))
{
list
.
add
(
col
umns
[
i
]
);
for
(
Column
col
:
columns
)
{
if
(
Column
.
isConditionType
(
config
,
col
.
getType
()))
{
list
.
add
(
col
);
}
}
if
(
list
.
size
()
==
0
)
{
...
...
@@ -206,9 +206,9 @@ class Table {
*/
Column
getRandomColumnOfType
(
int
type
)
{
ArrayList
<
Column
>
list
=
New
.
arrayList
();
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++
)
{
if
(
col
umns
[
i
]
.
getType
()
==
type
)
{
list
.
add
(
col
umns
[
i
]
);
for
(
Column
col
:
columns
)
{
if
(
col
.
getType
()
==
type
)
{
list
.
add
(
col
);
}
}
if
(
list
.
size
()
==
0
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/sql/Value.java
浏览文件 @
e126424c
...
...
@@ -122,8 +122,8 @@ public class Value {
byte
[]
bytes
=
(
byte
[])
data
;
// StringBuffer buff = new StringBuffer("X'");
StringBuffer
buff
=
new
StringBuffer
(
"'"
);
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++
)
{
int
c
=
b
ytes
[
i
]
&
0xff
;
for
(
byte
b
:
bytes
)
{
int
c
=
b
&
0xff
;
buff
.
append
(
Integer
.
toHexString
(
c
>>
4
&
0xf
));
buff
.
append
(
Integer
.
toHexString
(
c
&
0xf
));
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/trace/Player.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestClearReferences.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestCompress.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestOverflow.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestValueMemory.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/build/BuildBase.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/build/doclet/Doclet.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/dev/ftp/FtpClient.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/Condition.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/ConditionAndOr.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/Function.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/OrderExpression.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/Query.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/QueryWhere.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/S
ql
Statement.java
→
h2/src/tools/org/h2/jaqu/S
QL
Statement.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/SelectColumn.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/SelectTable.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/TableDefinition.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/TestCondition.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
h2/src/tools/org/h2/jaqu/Token.java
浏览文件 @
e126424c
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论