Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
78cc4925
提交
78cc4925
authored
7月 16, 2017
作者:
Niklas Mehner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor synonym support: Remove AbstractTable
上级
cbf6b4c8
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
70 个修改的文件
包含
455 行增加
和
453 行删除
+455
-453
Parser.java
h2/src/main/org/h2/command/Parser.java
+39
-40
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+3
-4
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+6
-7
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+2
-3
CreateIndex.java
h2/src/main/org/h2/command/ddl/CreateIndex.java
+0
-1
CreateLinkedTable.java
h2/src/main/org/h2/command/ddl/CreateLinkedTable.java
+1
-1
CreateSynonym.java
h2/src/main/org/h2/command/ddl/CreateSynonym.java
+11
-6
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+1
-1
CreateTrigger.java
h2/src/main/org/h2/command/ddl/CreateTrigger.java
+3
-3
CreateUserDataType.java
h2/src/main/org/h2/command/ddl/CreateUserDataType.java
+2
-2
CreateView.java
h2/src/main/org/h2/command/ddl/CreateView.java
+2
-2
DropDatabase.java
h2/src/main/org/h2/command/ddl/DropDatabase.java
+8
-8
DropSynonym.java
h2/src/main/org/h2/command/ddl/DropSynonym.java
+5
-7
DropTrigger.java
h2/src/main/org/h2/command/ddl/DropTrigger.java
+2
-2
DropView.java
h2/src/main/org/h2/command/ddl/DropView.java
+0
-1
GrantRevoke.java
h2/src/main/org/h2/command/ddl/GrantRevoke.java
+5
-5
TruncateTable.java
h2/src/main/org/h2/command/ddl/TruncateTable.java
+0
-1
AlterSequence.java
h2/src/main/org/h2/command/dml/AlterSequence.java
+2
-2
AlterTableSet.java
h2/src/main/org/h2/command/dml/AlterTableSet.java
+0
-1
Delete.java
h2/src/main/org/h2/command/dml/Delete.java
+2
-3
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+0
-1
Merge.java
h2/src/main/org/h2/command/dml/Merge.java
+0
-1
Query.java
h2/src/main/org/h2/command/dml/Query.java
+2
-2
Replace.java
h2/src/main/org/h2/command/dml/Replace.java
+0
-1
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+18
-19
Select.java
h2/src/main/org/h2/command/dml/Select.java
+20
-20
SelectUnion.java
h2/src/main/org/h2/command/dml/SelectUnion.java
+3
-3
Set.java
h2/src/main/org/h2/command/dml/Set.java
+4
-4
Update.java
h2/src/main/org/h2/command/dml/Update.java
+2
-3
Constraint.java
h2/src/main/org/h2/constraint/Constraint.java
+4
-5
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+3
-4
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+5
-6
ConstraintUnique.java
h2/src/main/org/h2/constraint/ConstraintUnique.java
+4
-5
Comment.java
h2/src/main/org/h2/engine/Comment.java
+2
-2
Database.java
h2/src/main/org/h2/engine/Database.java
+35
-22
DbObject.java
h2/src/main/org/h2/engine/DbObject.java
+7
-3
FunctionAlias.java
h2/src/main/org/h2/engine/FunctionAlias.java
+2
-2
MetaRecord.java
h2/src/main/org/h2/engine/MetaRecord.java
+6
-4
Right.java
h2/src/main/org/h2/engine/Right.java
+1
-2
RightOwner.java
h2/src/main/org/h2/engine/RightOwner.java
+2
-2
Role.java
h2/src/main/org/h2/engine/Role.java
+2
-2
Session.java
h2/src/main/org/h2/engine/Session.java
+5
-6
Setting.java
h2/src/main/org/h2/engine/Setting.java
+2
-2
UndoLog.java
h2/src/main/org/h2/engine/UndoLog.java
+4
-4
UndoLogRecord.java
h2/src/main/org/h2/engine/UndoLogRecord.java
+10
-10
User.java
h2/src/main/org/h2/engine/User.java
+7
-7
UserAggregate.java
h2/src/main/org/h2/engine/UserAggregate.java
+2
-2
UserDataType.java
h2/src/main/org/h2/engine/UserDataType.java
+2
-2
Aggregate.java
h2/src/main/org/h2/expression/Aggregate.java
+7
-7
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+1
-1
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+4
-4
ExpressionVisitor.java
h2/src/main/org/h2/expression/ExpressionVisitor.java
+5
-5
Function.java
h2/src/main/org/h2/expression/Function.java
+3
-3
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+1
-2
MultiVersionIndex.java
h2/src/main/org/h2/index/MultiVersionIndex.java
+1
-2
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+45
-4
Constant.java
h2/src/main/org/h2/schema/Constant.java
+2
-2
Schema.java
h2/src/main/org/h2/schema/Schema.java
+51
-23
Sequence.java
h2/src/main/org/h2/schema/Sequence.java
+2
-2
TriggerObject.java
h2/src/main/org/h2/schema/TriggerObject.java
+6
-6
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+5
-6
AbstractTable.java
h2/src/main/org/h2/table/AbstractTable.java
+0
-44
Column.java
h2/src/main/org/h2/table/Column.java
+3
-3
IndexColumn.java
h2/src/main/org/h2/table/IndexColumn.java
+2
-2
JoinBatch.java
h2/src/main/org/h2/table/JoinBatch.java
+1
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+28
-30
Table.java
h2/src/main/org/h2/table/Table.java
+3
-12
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+15
-15
TableSynonym.java
h2/src/main/org/h2/table/TableSynonym.java
+12
-23
TableView.java
h2/src/main/org/h2/table/TableView.java
+10
-10
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
78cc4925
差异被折叠。
点击展开。
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
78cc4925
...
...
@@ -22,7 +22,6 @@ import org.h2.index.Index;
import
org.h2.index.IndexType
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
...
...
@@ -63,7 +62,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
ifTableExists
=
b
;
}
private
String
generateConstraintName
(
Abstract
Table
table
)
{
private
String
generateConstraintName
(
Table
table
)
{
if
(
constraintName
==
null
)
{
constraintName
=
getSchema
().
getUniqueConstraintName
(
session
,
table
);
...
...
@@ -328,7 +327,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return
null
;
}
private
static
boolean
canUseUniqueIndex
(
Index
idx
,
Abstract
Table
table
,
private
static
boolean
canUseUniqueIndex
(
Index
idx
,
Table
table
,
IndexColumn
[]
cols
)
{
if
(
idx
.
getTable
()
!=
table
||
!
idx
.
getIndexType
().
isUnique
())
{
return
false
;
...
...
@@ -351,7 +350,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return
true
;
}
private
static
boolean
canUseIndex
(
Index
existingIndex
,
Abstract
Table
table
,
private
static
boolean
canUseIndex
(
Index
existingIndex
,
Table
table
,
IndexColumn
[]
cols
,
boolean
moreColumnsOk
)
{
if
(
existingIndex
.
getTable
()
!=
table
||
existingIndex
.
getCreateSQL
()
==
null
)
{
// can't use the scan index or index of another table
...
...
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
78cc4925
...
...
@@ -29,7 +29,6 @@ import org.h2.schema.Schema;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.TriggerObject
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.TableView
;
...
...
@@ -212,7 +211,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
return
0
;
}
private
static
void
checkDefaultReferencesTable
(
Abstract
Table
table
,
Expression
defaultExpression
)
{
private
static
void
checkDefaultReferencesTable
(
Table
table
,
Expression
defaultExpression
)
{
if
(
defaultExpression
==
null
)
{
return
;
}
...
...
@@ -235,7 +234,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private
void
convertAutoIncrementColumn
(
Abstract
Table
table
,
Column
c
)
{
private
void
convertAutoIncrementColumn
(
Table
table
,
Column
c
)
{
if
(
c
.
isAutoIncrement
())
{
if
(
c
.
isPrimaryKey
())
{
c
.
setOriginalSQL
(
"IDENTITY"
);
...
...
@@ -265,7 +264,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
String
tempName
=
db
.
getTempTableName
(
baseName
,
session
);
Column
[]
columns
=
table
.
getColumns
();
ArrayList
<
Column
>
newColumns
=
New
.
arrayList
();
Abstract
Table
newTable
=
cloneTableStructure
(
table
,
columns
,
db
,
tempName
,
newColumns
);
Table
newTable
=
cloneTableStructure
(
table
,
columns
,
db
,
tempName
,
newColumns
);
try
{
// check if a view would become invalid
// (because the column to drop is referenced or so)
...
...
@@ -315,7 +314,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private
Abstract
Table
cloneTableStructure
(
Table
table
,
Column
[]
columns
,
Database
db
,
private
Table
cloneTableStructure
(
Table
table
,
Column
[]
columns
,
Database
db
,
String
tempName
,
ArrayList
<
Column
>
newColumns
)
{
for
(
Column
col
:
columns
)
{
newColumns
.
add
(
col
.
getClone
());
...
...
@@ -369,7 +368,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
data
.
isHidden
=
table
.
isHidden
();
data
.
create
=
true
;
data
.
session
=
session
;
Abstract
Table
newTable
=
getSchema
().
createTable
(
data
);
Table
newTable
=
getSchema
().
createTable
(
data
);
newTable
.
setComment
(
table
.
getComment
());
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
newTable
.
getCreateSQL
());
...
...
@@ -518,7 +517,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private
void
checkNoNullValues
(
Abstract
Table
table
)
{
private
void
checkNoNullValues
(
Table
table
)
{
String
sql
=
"SELECT COUNT(*) FROM "
+
table
.
getSQL
()
+
" WHERE "
+
oldColumn
.
getSQL
()
+
" IS NULL"
;
...
...
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
78cc4925
...
...
@@ -13,7 +13,6 @@ import org.h2.engine.Right;
import
org.h2.engine.Session
;
import
org.h2.expression.Parameter
;
import
org.h2.result.ResultInterface
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.TableType
;
...
...
@@ -54,8 +53,8 @@ public class Analyze extends DefineCommand {
if
(
table
!=
null
)
{
analyzeTable
(
session
,
table
,
sampleRows
,
true
);
}
else
{
for
(
Abstract
Table
table
:
db
.
getAllTablesAndViews
(
false
))
{
analyzeTable
(
session
,
table
.
resolve
()
,
sampleRows
,
true
);
for
(
Table
table
:
db
.
getAllTablesAndViews
(
false
))
{
analyzeTable
(
session
,
table
,
sampleRows
,
true
);
}
}
return
0
;
...
...
h2/src/main/org/h2/command/ddl/CreateIndex.java
浏览文件 @
78cc4925
...
...
@@ -14,7 +14,6 @@ import org.h2.engine.Session;
import
org.h2.index.IndexType
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
...
...
h2/src/main/org/h2/command/ddl/CreateLinkedTable.java
浏览文件 @
78cc4925
...
...
@@ -66,7 +66,7 @@ public class CreateLinkedTable extends SchemaCommand {
session
.
commit
(
true
);
Database
db
=
session
.
getDatabase
();
session
.
getUser
().
checkAdmin
();
if
(
getSchema
().
findTableViewOrSynonym
(
session
,
tableName
)
!=
null
)
{
if
(
getSchema
().
resolveTableOrView
(
session
,
tableName
)
!=
null
)
{
if
(
ifNotExists
)
{
return
0
;
}
...
...
h2/src/main/org/h2/command/ddl/CreateSynonym.java
浏览文件 @
78cc4925
...
...
@@ -11,7 +11,6 @@ import org.h2.engine.Database;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.TableSynonym
;
/**
...
...
@@ -52,11 +51,16 @@ public class CreateSynonym extends SchemaCommand {
if
(!
transactional
)
{
session
.
commit
(
true
);
}
session
.
getUser
().
checkAdmin
();
Database
db
=
session
.
getDatabase
();
data
.
session
=
session
;
db
.
lockMeta
(
session
);
if
(
data
.
synonymForSchema
.
findTableViewOrSynonym
(
session
,
data
.
synonymFor
)
!=
null
)
{
if
(
data
.
synonymForSchema
.
findTableOrView
(
session
,
data
.
synonymName
)
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
,
data
.
synonymName
);
}
if
(
data
.
synonymForSchema
.
findTableOrView
(
session
,
data
.
synonymFor
)
!=
null
)
{
return
createTableSynonym
(
db
);
}
...
...
@@ -66,11 +70,12 @@ public class CreateSynonym extends SchemaCommand {
}
private
int
createTableSynonym
(
Database
db
)
{
AbstractTable
old
=
getSchema
().
findTableViewOrSynonym
(
session
,
data
.
synonymName
);
TableSynonym
old
=
getSchema
().
getSynonym
(
data
.
synonymName
);
if
(
old
!=
null
)
{
if
(
orReplace
&&
old
instanceof
TableSynonym
)
{
if
(
orReplace
)
{
// ok, we replacing the existing synonym
}
else
if
(
ifNotExists
&&
old
instanceof
TableSynonym
)
{
}
else
if
(
ifNotExists
)
{
return
0
;
}
else
{
throw
DbException
.
get
(
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
,
data
.
synonymName
);
...
...
@@ -79,7 +84,7 @@ public class CreateSynonym extends SchemaCommand {
TableSynonym
table
;
if
(
old
!=
null
)
{
table
=
(
TableSynonym
)
old
;
table
=
old
;
data
.
schema
=
table
.
getSchema
();
table
.
updateData
(
data
);
table
.
setComment
(
comment
);
...
...
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
78cc4925
...
...
@@ -110,7 +110,7 @@ public class CreateTable extends SchemaCommand {
if
(!
isSessionTemporary
)
{
db
.
lockMeta
(
session
);
}
if
(
getSchema
().
findTableViewOrSynonym
(
session
,
data
.
tableName
)
!=
null
)
{
if
(
getSchema
().
resolveTableOrView
(
session
,
data
.
tableName
)
!=
null
)
{
if
(
ifNotExists
)
{
return
0
;
}
...
...
h2/src/main/org/h2/command/ddl/CreateTrigger.java
浏览文件 @
78cc4925
...
...
@@ -13,7 +13,7 @@ import org.h2.engine.Session;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.schema.TriggerObject
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
/**
* This class represents the statement
...
...
@@ -102,7 +102,7 @@ public class CreateTrigger extends SchemaCommand {
triggerName
);
}
int
id
=
getObjectId
();
Abstract
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
TriggerObject
trigger
=
new
TriggerObject
(
getSchema
(),
id
,
triggerName
,
table
);
trigger
.
setInsteadOf
(
insteadOf
);
trigger
.
setBefore
(
before
);
...
...
@@ -117,7 +117,7 @@ public class CreateTrigger extends SchemaCommand {
trigger
.
setTriggerSource
(
triggerSource
,
force
);
}
db
.
addSchemaObject
(
session
,
trigger
);
table
.
resolve
().
addTrigger
(
trigger
);
table
.
addTrigger
(
trigger
);
return
0
;
}
...
...
h2/src/main/org/h2/command/ddl/CreateUserDataType.java
浏览文件 @
78cc4925
...
...
@@ -11,8 +11,8 @@ import org.h2.engine.Database;
import
org.h2.engine.Session
;
import
org.h2.engine.UserDataType
;
import
org.h2.message.DbException
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.value.DataType
;
/**
...
...
@@ -62,7 +62,7 @@ public class CreateUserDataType extends DefineCommand {
ErrorCode
.
USER_DATA_TYPE_ALREADY_EXISTS_1
,
typeName
);
}
Abstract
Table
table
=
session
.
getDatabase
().
getFirstUserTable
();
Table
table
=
session
.
getDatabase
().
getFirstUserTable
();
if
(
table
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
USER_DATA_TYPE_ALREADY_EXISTS_1
,
...
...
h2/src/main/org/h2/command/ddl/CreateView.java
浏览文件 @
78cc4925
...
...
@@ -15,8 +15,8 @@ import org.h2.engine.Session;
import
org.h2.expression.Parameter
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.TableType
;
import
org.h2.table.TableView
;
import
org.h2.value.Value
;
...
...
@@ -78,7 +78,7 @@ public class CreateView extends SchemaCommand {
session
.
getUser
().
checkAdmin
();
Database
db
=
session
.
getDatabase
();
TableView
view
=
null
;
AbstractTable
old
=
getSchema
().
findTableViewOrSynonym
(
session
,
viewName
);
Table
old
=
getSchema
().
findTableOrView
(
session
,
viewName
);
if
(
old
!=
null
)
{
if
(
ifNotExists
)
{
return
0
;
...
...
h2/src/main/org/h2/command/ddl/DropDatabase.java
浏览文件 @
78cc4925
...
...
@@ -15,7 +15,7 @@ import org.h2.engine.User;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.Sequence
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.table.TableType
;
import
org.h2.util.New
;
...
...
@@ -53,28 +53,28 @@ public class DropDatabase extends DefineCommand {
// so we might need to loop over them multiple times.
boolean
runLoopAgain
;
do
{
ArrayList
<
Abstract
Table
>
tables
=
db
.
getAllTablesAndViews
(
false
);
ArrayList
<
Abstract
Table
>
toRemove
=
New
.
arrayList
();
for
(
Abstract
Table
t
:
tables
)
{
ArrayList
<
Table
>
tables
=
db
.
getAllTablesAndViews
(
false
);
ArrayList
<
Table
>
toRemove
=
New
.
arrayList
();
for
(
Table
t
:
tables
)
{
if
(
t
.
getName
()
!=
null
&&
TableType
.
VIEW
==
t
.
getTableType
())
{
toRemove
.
add
(
t
);
}
}
for
(
Abstract
Table
t
:
tables
)
{
for
(
Table
t
:
tables
)
{
if
(
t
.
getName
()
!=
null
&&
TableType
.
TABLE_LINK
==
t
.
getTableType
())
{
toRemove
.
add
(
t
);
}
}
for
(
Abstract
Table
t
:
tables
)
{
for
(
Table
t
:
tables
)
{
if
(
t
.
getName
()
!=
null
&&
TableType
.
TABLE
==
t
.
getTableType
()
&&
!
t
.
isHidden
())
{
toRemove
.
add
(
t
);
}
}
for
(
Abstract
Table
t
:
tables
)
{
for
(
Table
t
:
tables
)
{
if
(
t
.
getName
()
!=
null
&&
TableType
.
EXTERNAL_TABLE_ENGINE
==
t
.
getTableType
()
&&
!
t
.
isHidden
())
{
...
...
@@ -82,7 +82,7 @@ public class DropDatabase extends DefineCommand {
}
}
runLoopAgain
=
false
;
for
(
Abstract
Table
t
:
toRemove
)
{
for
(
Table
t
:
toRemove
)
{
if
(
t
.
getName
()
==
null
)
{
// ignore, already dead
}
else
if
(
db
.
getDependentTable
(
t
,
t
)
==
null
)
{
...
...
h2/src/main/org/h2/command/ddl/DropSynonym.java
浏览文件 @
78cc4925
...
...
@@ -11,7 +11,8 @@ import org.h2.engine.Right;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Table
;
import
org.h2.table.TableSynonym
;
import
org.h2.table.TableType
;
/**
...
...
@@ -34,17 +35,14 @@ public class DropSynonym extends SchemaCommand {
@Override
public
int
update
()
{
session
.
commit
(
true
);
AbstractTable
synonym
=
getSchema
().
findTableViewOrSynonym
(
session
,
synonymName
);
session
.
getUser
().
checkAdmin
();
TableSynonym
synonym
=
getSchema
().
getSynonym
(
synonymName
);
if
(
synonym
==
null
)
{
if
(!
ifExists
)
{
throw
DbException
.
get
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
synonymName
);
}
}
else
{
if
(!
TableType
.
SYNONYM
.
equals
(
synonym
.
getTableType
()))
{
throw
DbException
.
get
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
synonymName
);
}
session
.
getUser
().
checkRight
(
synonym
,
Right
.
ALL
);
synonym
.
resolve
().
lock
(
session
,
true
,
true
);
session
.
getDatabase
().
removeSchemaObject
(
session
,
synonym
);
}
return
0
;
...
...
h2/src/main/org/h2/command/ddl/DropTrigger.java
浏览文件 @
78cc4925
...
...
@@ -13,7 +13,7 @@ import org.h2.engine.Session;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.schema.TriggerObject
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
/**
* This class represents the statement
...
...
@@ -46,7 +46,7 @@ public class DropTrigger extends SchemaCommand {
throw
DbException
.
get
(
ErrorCode
.
TRIGGER_NOT_FOUND_1
,
triggerName
);
}
}
else
{
Abstract
Table
table
=
trigger
.
getTable
();
Table
table
=
trigger
.
getTable
();
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
db
.
removeSchemaObject
(
session
,
trigger
);
}
...
...
h2/src/main/org/h2/command/ddl/DropView.java
浏览文件 @
78cc4925
...
...
@@ -13,7 +13,6 @@ import org.h2.engine.Right;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Table
;
import
org.h2.table.TableType
;
import
org.h2.table.TableView
;
...
...
h2/src/main/org/h2/command/ddl/GrantRevoke.java
浏览文件 @
78cc4925
...
...
@@ -17,7 +17,7 @@ import org.h2.engine.Role;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
/**
...
...
@@ -32,7 +32,7 @@ public class GrantRevoke extends DefineCommand {
private
ArrayList
<
String
>
roleNames
;
private
int
operationType
;
private
int
rightMask
;
private
final
ArrayList
<
Abstract
Table
>
tables
=
New
.
arrayList
();
private
final
ArrayList
<
Table
>
tables
=
New
.
arrayList
();
private
Schema
schema
;
private
RightOwner
grantee
;
...
...
@@ -111,7 +111,7 @@ public class GrantRevoke extends DefineCommand {
if
(
schema
!=
null
)
{
grantRight
(
schema
);
}
for
(
Abstract
Table
table
:
tables
)
{
for
(
Table
table
:
tables
)
{
grantRight
(
table
);
}
}
...
...
@@ -152,7 +152,7 @@ public class GrantRevoke extends DefineCommand {
if
(
schema
!=
null
)
{
revokeRight
(
schema
);
}
for
(
Abstract
Table
table
:
tables
)
{
for
(
Table
table
:
tables
)
{
revokeRight
(
table
);
}
}
...
...
@@ -193,7 +193,7 @@ public class GrantRevoke extends DefineCommand {
*
* @param table the table
*/
public
void
addTable
(
Abstract
Table
table
)
{
public
void
addTable
(
Table
table
)
{
tables
.
add
(
table
);
}
...
...
h2/src/main/org/h2/command/ddl/TruncateTable.java
浏览文件 @
78cc4925
...
...
@@ -10,7 +10,6 @@ import org.h2.command.CommandInterface;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Table
;
/**
...
...
h2/src/main/org/h2/command/dml/AlterSequence.java
浏览文件 @
78cc4925
...
...
@@ -15,8 +15,8 @@ import org.h2.expression.Expression;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Sequence
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
/**
* This class represents the statement
...
...
@@ -25,7 +25,7 @@ import org.h2.table.Column;
public
class
AlterSequence
extends
SchemaCommand
{
private
boolean
ifExists
;
private
Abstract
Table
table
;
private
Table
table
;
private
String
sequenceName
;
private
Sequence
sequence
;
private
Expression
start
;
...
...
h2/src/main/org/h2/command/dml/AlterTableSet.java
浏览文件 @
78cc4925
...
...
@@ -12,7 +12,6 @@ import org.h2.engine.Right;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Table
;
/**
...
...
h2/src/main/org/h2/command/dml/Delete.java
浏览文件 @
78cc4925
...
...
@@ -16,7 +16,6 @@ import org.h2.expression.ExpressionVisitor;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.result.RowList
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.PlanItem
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
...
...
@@ -54,9 +53,9 @@ public class Delete extends Prepared {
public
int
update
()
{
tableFilter
.
startQuery
(
session
);
tableFilter
.
reset
();
Abstract
Table
table
=
tableFilter
.
getTable
();
Table
table
=
tableFilter
.
getTable
();
session
.
getUser
().
checkRight
(
table
,
Right
.
DELETE
);
Table
resolvedTable
=
table
.
resolve
()
;
Table
resolvedTable
=
table
;
resolvedTable
.
fire
(
session
,
Trigger
.
DELETE
,
true
);
resolvedTable
.
lock
(
session
,
true
,
false
);
RowList
rows
=
new
RowList
(
session
);
...
...
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
78cc4925
...
...
@@ -26,7 +26,6 @@ import org.h2.mvstore.db.MVPrimaryIndex;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultTarget
;
import
org.h2.result.Row
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
...
...
h2/src/main/org/h2/command/dml/Merge.java
浏览文件 @
78cc4925
...
...
@@ -21,7 +21,6 @@ import org.h2.index.Index;
import
org.h2.message.DbException
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
...
...
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
78cc4925
...
...
@@ -22,8 +22,8 @@ import org.h2.message.DbException;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultTarget
;
import
org.h2.result.SortOrder
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.util.New
;
import
org.h2.value.Value
;
...
...
@@ -157,7 +157,7 @@ public abstract class Query extends Prepared {
*
* @return the set of tables
*/
public
abstract
HashSet
<
Abstract
Table
>
getTables
();
public
abstract
HashSet
<
Table
>
getTables
();
/**
* Set the order by list.
...
...
h2/src/main/org/h2/command/dml/Replace.java
浏览文件 @
78cc4925
...
...
@@ -19,7 +19,6 @@ import org.h2.index.Index;
import
org.h2.message.DbException
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
78cc4925
...
...
@@ -49,7 +49,6 @@ import org.h2.schema.Schema;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.TriggerObject
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.PlanItem
;
import
org.h2.table.Table
;
...
...
@@ -70,7 +69,7 @@ public class ScriptCommand extends ScriptBase {
private
Charset
charset
=
Constants
.
UTF8
;
private
Set
<
String
>
schemaNames
;
private
Collection
<
Abstract
Table
>
tables
;
private
Collection
<
Table
>
tables
;
private
boolean
passwords
;
// true if we're generating the INSERT..VALUES statements for row values
...
...
@@ -103,7 +102,7 @@ public class ScriptCommand extends ScriptBase {
this
.
schemaNames
=
schemaNames
;
}
public
void
setTables
(
Collection
<
Abstract
Table
>
tables
)
{
public
void
setTables
(
Collection
<
Table
>
tables
)
{
this
.
tables
=
tables
;
}
...
...
@@ -202,18 +201,18 @@ public class ScriptCommand extends ScriptBase {
add
(
constant
.
getCreateSQL
(),
false
);
}
final
ArrayList
<
Abstract
Table
>
tables
=
db
.
getAllTablesAndViews
(
false
);
final
ArrayList
<
Table
>
tables
=
db
.
getAllTablesAndViews
(
false
);
// sort by id, so that views are after tables and views on views
// after the base views
Collections
.
sort
(
tables
,
new
Comparator
<
Abstract
Table
>()
{
Collections
.
sort
(
tables
,
new
Comparator
<
Table
>()
{
@Override
public
int
compare
(
AbstractTable
t1
,
Abstract
Table
t2
)
{
public
int
compare
(
Table
t1
,
Table
t2
)
{
return
t1
.
getId
()
-
t2
.
getId
();
}
});
// Generate the DROP XXX ... IF EXISTS
for
(
Abstract
Table
table
:
tables
)
{
for
(
Table
table
:
tables
)
{
if
(
excludeSchema
(
table
.
getSchema
()))
{
continue
;
}
...
...
@@ -223,7 +222,7 @@ public class ScriptCommand extends ScriptBase {
if
(
table
.
isHidden
())
{
continue
;
}
table
.
resolve
().
lock
(
session
,
false
,
false
);
table
.
lock
(
session
,
false
,
false
);
String
sql
=
table
.
getCreateSQL
();
if
(
sql
==
null
)
{
// null for metadata tables
...
...
@@ -263,7 +262,7 @@ public class ScriptCommand extends ScriptBase {
// Generate CREATE TABLE and INSERT...VALUES
int
count
=
0
;
for
(
Abstract
Table
table
:
tables
)
{
for
(
Table
table
:
tables
)
{
if
(
excludeSchema
(
table
.
getSchema
()))
{
continue
;
}
...
...
@@ -273,7 +272,7 @@ public class ScriptCommand extends ScriptBase {
if
(
table
.
isHidden
())
{
continue
;
}
table
.
resolve
().
lock
(
session
,
false
,
false
);
table
.
lock
(
session
,
false
,
false
);
String
createTableSql
=
table
.
getCreateSQL
();
if
(
createTableSql
==
null
)
{
// null for metadata tables
...
...
@@ -281,7 +280,7 @@ public class ScriptCommand extends ScriptBase {
}
final
TableType
tableType
=
table
.
getTableType
();
add
(
createTableSql
,
false
);
final
ArrayList
<
Constraint
>
constraints
=
table
.
resolve
().
getConstraints
();
final
ArrayList
<
Constraint
>
constraints
=
table
.
getConstraints
();
if
(
constraints
!=
null
)
{
for
(
Constraint
constraint
:
constraints
)
{
if
(
Constraint
.
PRIMARY_KEY
.
equals
(
...
...
@@ -291,9 +290,9 @@ public class ScriptCommand extends ScriptBase {
}
}
if
(
TableType
.
TABLE
==
tableType
)
{
if
(
table
.
resolve
().
canGetRowCount
())
{
if
(
table
.
canGetRowCount
())
{
String
rowcount
=
"-- "
+
table
.
resolve
().
getRowCountApproximation
()
+
table
.
getRowCountApproximation
()
+
" +/- SELECT COUNT(*) FROM "
+
table
.
getSQL
();
add
(
rowcount
,
false
);
}
...
...
@@ -301,7 +300,7 @@ public class ScriptCommand extends ScriptBase {
count
=
generateInsertValues
(
count
,
table
);
}
}
final
ArrayList
<
Index
>
indexes
=
table
.
resolve
().
getIndexes
();
final
ArrayList
<
Index
>
indexes
=
table
.
getIndexes
();
for
(
int
j
=
0
;
indexes
!=
null
&&
j
<
indexes
.
size
();
j
++)
{
Index
index
=
indexes
.
get
(
j
);
if
(!
index
.
getIndexType
().
getBelongsToConstraint
())
{
...
...
@@ -389,11 +388,11 @@ public class ScriptCommand extends ScriptBase {
return
r
;
}
private
int
generateInsertValues
(
int
count
,
Abstract
Table
table
)
throws
IOException
{
PlanItem
plan
=
table
.
resolve
().
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
,
null
);
private
int
generateInsertValues
(
int
count
,
Table
table
)
throws
IOException
{
PlanItem
plan
=
table
.
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
,
null
);
Index
index
=
plan
.
getIndex
();
Cursor
cursor
=
index
.
find
(
session
,
null
,
null
);
Column
[]
columns
=
table
.
resolve
().
getColumns
();
Column
[]
columns
=
table
.
getColumns
();
StatementBuilder
buff
=
new
StatementBuilder
(
"INSERT INTO "
);
buff
.
append
(
table
.
getSQL
()).
append
(
'('
);
for
(
Column
col
:
columns
)
{
...
...
@@ -664,7 +663,7 @@ public class ScriptCommand extends ScriptBase {
}
if
(
tables
!=
null
)
{
// if filtering on specific tables, only include those schemas
for
(
Abstract
Table
table
:
schema
.
getAllTablesAndViews
())
{
for
(
Table
table
:
schema
.
getAllTablesAndViews
())
{
if
(
tables
.
contains
(
table
))
{
return
false
;
}
...
...
@@ -674,7 +673,7 @@ public class ScriptCommand extends ScriptBase {
return
false
;
}
private
boolean
excludeTable
(
Abstract
Table
table
)
{
private
boolean
excludeTable
(
Table
table
)
{
return
tables
!=
null
&&
!
tables
.
contains
(
table
);
}
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
78cc4925
...
...
@@ -33,11 +33,11 @@ import org.h2.result.ResultTarget;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.JoinBatch
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableView
;
import
org.h2.util.New
;
...
...
@@ -225,7 +225,7 @@ public class Select extends Query {
if
(
groupIndex
==
null
||
groupByExpression
==
null
)
{
return
null
;
}
ArrayList
<
Index
>
indexes
=
topTableFilter
.
getTable
().
resolve
().
getIndexes
();
ArrayList
<
Index
>
indexes
=
topTableFilter
.
getTable
().
getIndexes
();
if
(
indexes
!=
null
)
{
for
(
int
i
=
0
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
Index
index
=
indexes
.
get
(
i
);
...
...
@@ -406,9 +406,9 @@ public class Select extends Query {
int
[]
sortTypes
=
sort
.
getSortTypes
();
if
(
sortCols
.
length
==
0
)
{
// sort just on constants - can use scan index
return
topTableFilter
.
getTable
().
resolve
().
getScanIndex
(
session
);
return
topTableFilter
.
getTable
().
getScanIndex
(
session
);
}
ArrayList
<
Index
>
list
=
topTableFilter
.
getTable
().
resolve
().
getIndexes
();
ArrayList
<
Index
>
list
=
topTableFilter
.
getTable
().
getIndexes
();
if
(
list
!=
null
)
{
for
(
int
i
=
0
,
size
=
list
.
size
();
i
<
size
;
i
++)
{
Index
index
=
list
.
get
(
i
);
...
...
@@ -447,7 +447,7 @@ public class Select extends Query {
}
if
(
sortCols
.
length
==
1
&&
sortCols
[
0
].
getColumnId
()
==
-
1
)
{
// special case: order by _ROWID_
Index
index
=
topTableFilter
.
getTable
().
resolve
().
getScanIndex
(
session
);
Index
index
=
topTableFilter
.
getTable
().
getScanIndex
(
session
);
if
(
index
.
isRowIdIndex
())
{
return
index
;
}
...
...
@@ -480,7 +480,7 @@ public class Select extends Query {
SearchRow
found
=
cursor
.
getSearchRow
();
Value
value
=
found
.
getValue
(
columnIndex
);
if
(
first
==
null
)
{
first
=
topTableFilter
.
getTable
().
resolve
().
getTemplateSimpleRow
(
true
);
first
=
topTableFilter
.
getTable
().
getTemplateSimpleRow
(
true
);
}
first
.
setValue
(
columnIndex
,
value
);
Value
[]
row
=
{
value
};
...
...
@@ -710,9 +710,9 @@ public class Select extends Query {
}
private
int
expandColumnList
(
TableFilter
filter
,
int
index
)
{
Abstract
Table
t
=
filter
.
getTable
();
Table
t
=
filter
.
getTable
();
String
alias
=
filter
.
getTableAlias
();
Column
[]
columns
=
t
.
resolve
().
getColumns
();
Column
[]
columns
=
t
.
getColumns
();
for
(
Column
c
:
columns
)
{
if
(!
c
.
getVisible
())
{
continue
;
...
...
@@ -856,7 +856,7 @@ public class Select extends Query {
if
(
isGroupQuery
&&
groupIndex
==
null
&&
havingIndex
<
0
&&
filters
.
size
()
==
1
)
{
if
(
condition
==
null
)
{
Abstract
Table
t
=
filters
.
get
(
0
).
getTable
();
Table
t
=
filters
.
get
(
0
).
getTable
();
ExpressionVisitor
optimizable
=
ExpressionVisitor
.
getOptimizableVisitor
(
t
);
isQuickAggregateQuery
=
isEverything
(
optimizable
);
...
...
@@ -871,7 +871,7 @@ public class Select extends Query {
if
(
expr
instanceof
ExpressionColumn
)
{
Column
column
=
((
ExpressionColumn
)
expr
).
getColumn
();
int
selectivity
=
column
.
getSelectivity
();
Index
columnIndex
=
topTableFilter
.
getTable
().
resolve
().
Index
columnIndex
=
topTableFilter
.
getTable
().
getIndexForColumn
(
column
,
false
,
true
);
if
(
columnIndex
!=
null
&&
selectivity
!=
Constants
.
SELECTIVITY_DEFAULT
&&
...
...
@@ -975,8 +975,8 @@ public class Select extends Query {
}
@Override
public
HashSet
<
Abstract
Table
>
getTables
()
{
HashSet
<
Abstract
Table
>
set
=
New
.
hashSet
();
public
HashSet
<
Table
>
getTables
()
{
HashSet
<
Table
>
set
=
New
.
hashSet
();
for
(
TableFilter
filter
:
filters
)
{
set
.
add
(
filter
.
getTable
());
}
...
...
@@ -987,7 +987,7 @@ public class Select extends Query {
public
void
fireBeforeSelectTriggers
()
{
for
(
int
i
=
0
,
size
=
filters
.
size
();
i
<
size
;
i
++)
{
TableFilter
filter
=
filters
.
get
(
i
);
filter
.
getTable
().
resolve
().
fire
(
session
,
Trigger
.
SELECT
,
true
);
filter
.
getTable
().
fire
(
session
,
Trigger
.
SELECT
,
true
);
}
}
...
...
@@ -1072,11 +1072,11 @@ public class Select extends Query {
new
Expression
[
expressions
.
size
()]);
StatementBuilder
buff
=
new
StatementBuilder
();
for
(
TableFilter
f
:
topFilters
)
{
Abstract
Table
t
=
f
.
getTable
();
if
(
t
.
resolve
().
isView
()
&&
((
TableView
)
t
).
isRecursive
())
{
Table
t
=
f
.
getTable
();
if
(
t
.
isView
()
&&
((
TableView
)
t
).
isRecursive
())
{
buff
.
append
(
"WITH RECURSIVE "
).
append
(
t
.
getName
()).
append
(
'('
);
buff
.
resetCount
();
for
(
Column
c
:
t
.
resolve
().
getColumns
())
{
for
(
Column
c
:
t
.
getColumns
())
{
buff
.
appendExceptFirst
(
","
);
buff
.
append
(
c
.
getName
());
}
...
...
@@ -1321,7 +1321,7 @@ public class Select extends Query {
}
for
(
int
i
=
0
,
size
=
filters
.
size
();
i
<
size
;
i
++)
{
TableFilter
f
=
filters
.
get
(
i
);
if
(!
f
.
getTable
().
resolve
().
isDeterministic
())
{
if
(!
f
.
getTable
().
isDeterministic
())
{
return
false
;
}
}
...
...
@@ -1330,7 +1330,7 @@ public class Select extends Query {
case
ExpressionVisitor
.
SET_MAX_DATA_MODIFICATION_ID
:
{
for
(
int
i
=
0
,
size
=
filters
.
size
();
i
<
size
;
i
++)
{
TableFilter
f
=
filters
.
get
(
i
);
long
m
=
f
.
getTable
().
resolve
().
getMaxDataModificationId
();
long
m
=
f
.
getTable
().
getMaxDataModificationId
();
visitor
.
addDataModificationId
(
m
);
}
break
;
...
...
@@ -1344,9 +1344,9 @@ public class Select extends Query {
case
ExpressionVisitor
.
GET_DEPENDENCIES
:
{
for
(
int
i
=
0
,
size
=
filters
.
size
();
i
<
size
;
i
++)
{
TableFilter
f
=
filters
.
get
(
i
);
Abstract
Table
table
=
f
.
getTable
();
Table
table
=
f
.
getTable
();
visitor
.
addDependency
(
table
);
table
.
resolve
().
addDependencies
(
visitor
.
getDependencies
());
table
.
addDependencies
(
visitor
.
getDependencies
());
}
break
;
}
...
...
h2/src/main/org/h2/command/dml/SelectUnion.java
浏览文件 @
78cc4925
...
...
@@ -22,9 +22,9 @@ import org.h2.result.LocalResult;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultTarget
;
import
org.h2.result.SortOrder
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
...
...
@@ -355,8 +355,8 @@ public class SelectUnion extends Query {
}
@Override
public
HashSet
<
Abstract
Table
>
getTables
()
{
HashSet
<
Abstract
Table
>
set
=
left
.
getTables
();
public
HashSet
<
Table
>
getTables
()
{
HashSet
<
Table
>
set
=
left
.
getTables
();
set
.
addAll
(
right
.
getTables
());
return
set
;
}
...
...
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
78cc4925
...
...
@@ -21,7 +21,7 @@ import org.h2.message.DbException;
import
org.h2.result.ResultInterface
;
import
org.h2.result.RowFactory
;
import
org.h2.schema.Schema
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.tools.CompressTool
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.StringUtils
;
...
...
@@ -145,7 +145,7 @@ public class Set extends Prepared {
if
(
old
.
equals
(
compareMode
))
{
break
;
}
Abstract
Table
table
=
database
.
getFirstUserTable
();
Table
table
=
database
.
getFirstUserTable
();
if
(
table
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
COLLATION_CHANGE_WITH_DATA_TABLE_1
,
...
...
@@ -157,7 +157,7 @@ public class Set extends Prepared {
}
case
SetTypes
.
BINARY_COLLATION
:
{
session
.
getUser
().
checkAdmin
();
Abstract
Table
table
=
database
.
getFirstUserTable
();
Table
table
=
database
.
getFirstUserTable
();
if
(
table
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
COLLATION_CHANGE_WITH_DATA_TABLE_1
,
...
...
@@ -249,7 +249,7 @@ public class Set extends Prepared {
}
case
SetTypes
.
JAVA_OBJECT_SERIALIZER
:
{
session
.
getUser
().
checkAdmin
();
Abstract
Table
table
=
database
.
getFirstUserTable
();
Table
table
=
database
.
getFirstUserTable
();
if
(
table
!=
null
)
{
throw
DbException
.
get
(
ErrorCode
.
JAVA_OBJECT_SERIALIZER_CHANGE_WITH_DATA_TABLE
,
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
78cc4925
...
...
@@ -21,7 +21,6 @@ import org.h2.message.DbException;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.result.RowList
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.PlanItem
;
import
org.h2.table.Table
;
...
...
@@ -84,9 +83,9 @@ public class Update extends Prepared {
tableFilter
.
reset
();
RowList
rows
=
new
RowList
(
session
);
try
{
Abstract
Table
table
=
tableFilter
.
getTable
();
Table
table
=
tableFilter
.
getTable
();
session
.
getUser
().
checkRight
(
table
,
Right
.
UPDATE
);
Table
resolvedTable
=
table
.
resolve
()
;
Table
resolvedTable
=
table
;
resolvedTable
.
fire
(
session
,
Trigger
.
UPDATE
,
true
);
resolvedTable
.
lock
(
session
,
true
,
false
);
int
columnCount
=
resolvedTable
.
getColumns
().
length
;
...
...
h2/src/main/org/h2/constraint/Constraint.java
浏览文件 @
78cc4925
...
...
@@ -15,7 +15,6 @@ import org.h2.message.Trace;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObjectBase
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
...
...
@@ -72,7 +71,7 @@ public abstract class Constraint extends SchemaObjectBase implements
* @param oldRow the old row
* @param newRow the new row
*/
public
abstract
void
checkRow
(
Session
session
,
Abstract
Table
t
,
Row
oldRow
,
Row
newRow
);
public
abstract
void
checkRow
(
Session
session
,
Table
t
,
Row
oldRow
,
Row
newRow
);
/**
* Check if this constraint needs the specified index.
...
...
@@ -95,7 +94,7 @@ public abstract class Constraint extends SchemaObjectBase implements
* @param table the table
* @return the set of referenced columns
*/
public
abstract
HashSet
<
Column
>
getReferencedColumns
(
Abstract
Table
table
);
public
abstract
HashSet
<
Column
>
getReferencedColumns
(
Table
table
);
/**
* Get the SQL statement to create this constraint.
...
...
@@ -143,11 +142,11 @@ public abstract class Constraint extends SchemaObjectBase implements
return
DbObject
.
CONSTRAINT
;
}
public
Abstract
Table
getTable
()
{
public
Table
getTable
()
{
return
table
;
}
public
Abstract
Table
getRefTable
()
{
public
Table
getRefTable
()
{
return
table
;
}
...
...
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
78cc4925
...
...
@@ -16,7 +16,6 @@ import org.h2.message.DbException;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
...
...
@@ -49,7 +48,7 @@ public class ConstraintCheck extends Constraint {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
forTable
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
)
{
StringBuilder
buff
=
new
StringBuilder
(
"ALTER TABLE "
);
buff
.
append
(
forTable
.
getSQL
()).
append
(
" ADD CONSTRAINT "
);
if
(
forTable
.
isHidden
())
{
...
...
@@ -89,7 +88,7 @@ public class ConstraintCheck extends Constraint {
}
@Override
public
void
checkRow
(
Session
session
,
Abstract
Table
t
,
Row
oldRow
,
Row
newRow
)
{
public
void
checkRow
(
Session
session
,
Table
t
,
Row
oldRow
,
Row
newRow
)
{
if
(
newRow
==
null
)
{
return
;
}
...
...
@@ -119,7 +118,7 @@ public class ConstraintCheck extends Constraint {
}
@Override
public
HashSet
<
Column
>
getReferencedColumns
(
Abstract
Table
table
)
{
public
HashSet
<
Column
>
getReferencedColumns
(
Table
table
)
{
HashSet
<
Column
>
columns
=
New
.
hashSet
();
expr
.
isEverything
(
ExpressionVisitor
.
getColumnsVisitor
(
columns
));
for
(
Iterator
<
Column
>
it
=
columns
.
iterator
();
it
.
hasNext
();)
{
...
...
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
78cc4925
...
...
@@ -20,7 +20,6 @@ import org.h2.result.ResultInterface;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
...
...
@@ -101,7 +100,7 @@ public class ConstraintReferential extends Constraint {
* @return the SQL statement
*/
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
forTable
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
)
{
return
getCreateSQLForCopy
(
forTable
,
refTable
,
quotedName
,
true
);
}
...
...
@@ -115,7 +114,7 @@ public class ConstraintReferential extends Constraint {
* @param internalIndex add the index name to the statement
* @return the SQL statement
*/
public
String
getCreateSQLForCopy
(
AbstractTable
forTable
,
Abstract
Table
forRefTable
,
public
String
getCreateSQLForCopy
(
Table
forTable
,
Table
forRefTable
,
String
quotedName
,
boolean
internalIndex
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
String
mainTable
=
forTable
.
getSQL
();
...
...
@@ -225,7 +224,7 @@ public class ConstraintReferential extends Constraint {
}
@Override
public
HashSet
<
Column
>
getReferencedColumns
(
Abstract
Table
table
)
{
public
HashSet
<
Column
>
getReferencedColumns
(
Table
table
)
{
HashSet
<
Column
>
result
=
New
.
hashSet
();
if
(
table
==
this
.
table
)
{
for
(
IndexColumn
c
:
columns
)
{
...
...
@@ -301,7 +300,7 @@ public class ConstraintReferential extends Constraint {
}
@Override
public
void
checkRow
(
Session
session
,
Abstract
Table
t
,
Row
oldRow
,
Row
newRow
)
{
public
void
checkRow
(
Session
session
,
Table
t
,
Row
oldRow
,
Row
newRow
)
{
if
(!
database
.
getReferentialIntegrity
())
{
return
;
}
...
...
@@ -610,7 +609,7 @@ public class ConstraintReferential extends Constraint {
}
@Override
public
Abstract
Table
getRefTable
()
{
public
Table
getRefTable
()
{
return
refTable
;
}
...
...
h2/src/main/org/h2/constraint/ConstraintUnique.java
浏览文件 @
78cc4925
...
...
@@ -11,7 +11,6 @@ import org.h2.engine.Session;
import
org.h2.index.Index
;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
...
...
@@ -41,11 +40,11 @@ public class ConstraintUnique extends Constraint {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
forTable
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
)
{
return
getCreateSQLForCopy
(
forTable
,
quotedName
,
true
);
}
private
String
getCreateSQLForCopy
(
Abstract
Table
forTable
,
String
quotedName
,
private
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
,
boolean
internalIndex
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
"ALTER TABLE "
);
buff
.
append
(
forTable
.
getSQL
()).
append
(
" ADD CONSTRAINT "
);
...
...
@@ -119,7 +118,7 @@ public class ConstraintUnique extends Constraint {
}
@Override
public
void
checkRow
(
Session
session
,
Abstract
Table
t
,
Row
oldRow
,
Row
newRow
)
{
public
void
checkRow
(
Session
session
,
Table
t
,
Row
oldRow
,
Row
newRow
)
{
// unique index check is enough
}
...
...
@@ -134,7 +133,7 @@ public class ConstraintUnique extends Constraint {
}
@Override
public
HashSet
<
Column
>
getReferencedColumns
(
Abstract
Table
table
)
{
public
HashSet
<
Column
>
getReferencedColumns
(
Table
table
)
{
HashSet
<
Column
>
result
=
New
.
hashSet
();
for
(
IndexColumn
c
:
columns
)
{
result
.
add
(
c
.
column
);
...
...
h2/src/main/org/h2/engine/Comment.java
浏览文件 @
78cc4925
...
...
@@ -7,7 +7,7 @@ package org.h2.engine;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -26,7 +26,7 @@ public class Comment extends DbObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
78cc4925
...
...
@@ -50,12 +50,12 @@ import org.h2.store.LobStorageMap;
import
org.h2.store.PageStore
;
import
org.h2.store.WriterThread
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.MetaTable
;
import
org.h2.table.Table
;
import
org.h2.table.TableLinkConnection
;
import
org.h2.table.TableSynonym
;
import
org.h2.table.TableType
;
import
org.h2.table.TableView
;
import
org.h2.tools.DeleteDbFiles
;
...
...
@@ -834,7 +834,7 @@ public class Database implements DataHandler {
boolean
atLeastOneRecompiledSuccessfully
;
do
{
atLeastOneRecompiledSuccessfully
=
false
;
for
(
Abstract
Table
obj
:
getAllTablesAndViews
(
false
))
{
for
(
Table
obj
:
getAllTablesAndViews
(
false
))
{
if
(
obj
instanceof
TableView
)
{
TableView
view
=
(
TableView
)
obj
;
if
(
view
.
isInvalid
())
{
...
...
@@ -1264,11 +1264,11 @@ public class Database implements DataHandler {
try
{
if
(
systemSession
!=
null
)
{
if
(
powerOffCount
!=
-
1
)
{
for
(
Abstract
Table
table
:
getAllTablesAndViews
(
false
))
{
if
(
table
.
resolve
().
isGlobalTemporary
())
{
for
(
Table
table
:
getAllTablesAndViews
(
false
))
{
if
(
table
.
isGlobalTemporary
())
{
table
.
removeChildrenAndResources
(
systemSession
);
}
else
{
table
.
resolve
().
close
(
systemSession
);
table
.
close
(
systemSession
);
}
}
for
(
SchemaObject
obj
:
getAllSchemaObjects
(
...
...
@@ -1331,7 +1331,7 @@ public class Database implements DataHandler {
if
(!
persistent
)
{
return
;
}
boolean
lobStorageIsUsed
=
infoSchema
.
findTable
ViewOrSynonym
(
boolean
lobStorageIsUsed
=
infoSchema
.
findTable
OrView
(
systemSession
,
LobStorageBackend
.
LOB_DATA_TABLE
)
!=
null
;
lobStorageIsUsed
|=
mvStore
!=
null
;
if
(!
lobStorageIsUsed
)
{
...
...
@@ -1532,27 +1532,40 @@ public class Database implements DataHandler {
* tables are only included if they are already initialized)
* @return all objects of that type
*/
public
ArrayList
<
Abstract
Table
>
getAllTablesAndViews
(
boolean
includeMeta
)
{
public
ArrayList
<
Table
>
getAllTablesAndViews
(
boolean
includeMeta
)
{
if
(
includeMeta
)
{
initMetaTables
();
}
ArrayList
<
Abstract
Table
>
list
=
New
.
arrayList
();
ArrayList
<
Table
>
list
=
New
.
arrayList
();
for
(
Schema
schema
:
schemas
.
values
())
{
list
.
addAll
(
schema
.
getAllTablesAndViews
());
}
return
list
;
}
/**
* Get all synonyms.
*
* @return all objects of that type
*/
public
ArrayList
<
TableSynonym
>
getAllSynonyms
()
{
ArrayList
<
TableSynonym
>
list
=
New
.
arrayList
();
for
(
Schema
schema
:
schemas
.
values
())
{
list
.
addAll
(
schema
.
getAllSynonyms
());
}
return
list
;
}
/**
* Get the tables with the given name, if any.
*
* @param name the table name
* @return the list
*/
public
ArrayList
<
Abstract
Table
>
getTableOrViewByName
(
String
name
)
{
ArrayList
<
Abstract
Table
>
list
=
New
.
arrayList
();
public
ArrayList
<
Table
>
getTableOrViewByName
(
String
name
)
{
ArrayList
<
Table
>
list
=
New
.
arrayList
();
for
(
Schema
schema
:
schemas
.
values
())
{
Abstract
Table
table
=
schema
.
getTableOrViewByName
(
name
);
Table
table
=
schema
.
getTableOrViewByName
(
name
);
if
(
table
!=
null
)
{
list
.
add
(
table
);
}
...
...
@@ -1791,7 +1804,7 @@ public class Database implements DataHandler {
* @param except the table to exclude (or null)
* @return the first dependent table, or null
*/
public
AbstractTable
getDependentTable
(
SchemaObject
obj
,
Abstract
Table
except
)
{
public
Table
getDependentTable
(
SchemaObject
obj
,
Table
except
)
{
switch
(
obj
.
getType
())
{
case
DbObject
.
COMMENT
:
case
DbObject
.
CONSTRAINT
:
...
...
@@ -1803,14 +1816,14 @@ public class Database implements DataHandler {
default
:
}
HashSet
<
DbObject
>
set
=
New
.
hashSet
();
for
(
Abstract
Table
t
:
getAllTablesAndViews
(
false
))
{
for
(
Table
t
:
getAllTablesAndViews
(
false
))
{
if
(
except
==
t
)
{
continue
;
}
else
if
(
TableType
.
VIEW
==
t
.
getTableType
()
||
TableType
.
SYNONYM
==
t
.
getTableType
())
{
continue
;
}
set
.
clear
();
t
.
resolve
().
addDependencies
(
set
);
t
.
addDependencies
(
set
);
if
(
set
.
contains
(
obj
))
{
return
t
;
}
...
...
@@ -1828,8 +1841,8 @@ public class Database implements DataHandler {
SchemaObject
obj
)
{
int
type
=
obj
.
getType
();
if
(
type
==
DbObject
.
TABLE_OR_VIEW
)
{
AbstractTable
table
=
(
Abstract
Table
)
obj
;
if
(
table
.
isTemporary
()
&&
!
table
.
resolve
().
isGlobalTemporary
())
{
Table
table
=
(
Table
)
obj
;
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
())
{
session
.
removeLocalTempTable
(
table
);
return
;
}
...
...
@@ -1842,8 +1855,8 @@ public class Database implements DataHandler {
}
}
else
if
(
type
==
DbObject
.
CONSTRAINT
)
{
Constraint
constraint
=
(
Constraint
)
obj
;
Abstract
Table
table
=
constraint
.
getTable
();
if
(
table
.
isTemporary
()
&&
!
table
.
resolve
().
isGlobalTemporary
())
{
Table
table
=
constraint
.
getTable
();
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
())
{
session
.
removeLocalTempTableConstraint
(
constraint
);
return
;
}
...
...
@@ -1858,7 +1871,7 @@ public class Database implements DataHandler {
obj
.
getSchema
().
remove
(
obj
);
int
id
=
obj
.
getId
();
if
(!
starting
)
{
Abstract
Table
t
=
getDependentTable
(
obj
,
null
);
Table
t
=
getDependentTable
(
obj
,
null
);
if
(
t
!=
null
)
{
obj
.
getSchema
().
add
(
obj
);
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_2
,
obj
.
getSQL
(),
...
...
@@ -1919,7 +1932,7 @@ public class Database implements DataHandler {
do
{
tempName
=
baseName
+
"_COPY_"
+
session
.
getId
()
+
"_"
+
nextTempTableId
++;
}
while
(
mainSchema
.
findTable
ViewOrSynonym
(
session
,
tempName
)
!=
null
);
}
while
(
mainSchema
.
findTable
OrView
(
session
,
tempName
)
!=
null
);
return
tempName
;
}
...
...
@@ -2499,8 +2512,8 @@ public class Database implements DataHandler {
*
* @return the table or null if no table is defined
*/
public
Abstract
Table
getFirstUserTable
()
{
for
(
Abstract
Table
table
:
getAllTablesAndViews
(
false
))
{
public
Table
getFirstUserTable
()
{
for
(
Table
table
:
getAllTablesAndViews
(
false
))
{
if
(
table
.
getCreateSQL
()
!=
null
)
{
if
(
table
.
isHidden
())
{
// LOB tables
...
...
h2/src/main/org/h2/engine/DbObject.java
浏览文件 @
78cc4925
...
...
@@ -6,8 +6,7 @@
package
org
.
h2
.
engine
;
import
java.util.ArrayList
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Table
;
/**
* A database object such as a table, an index, or a user.
...
...
@@ -90,6 +89,11 @@ public interface DbObject {
*/
int
AGGREGATE
=
14
;
/**
* This object is a synonym.
*/
int
SYNONYM
=
15
;
/**
* Get the SQL name of this object (may be quoted).
*
...
...
@@ -134,7 +138,7 @@ public interface DbObject {
* @param quotedName the quoted name
* @return the SQL statement
*/
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
);
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
);
/**
* Construct the original CREATE ... SQL statement for this object.
...
...
h2/src/main/org/h2/engine/FunctionAlias.java
浏览文件 @
78cc4925
...
...
@@ -20,7 +20,7 @@ import org.h2.message.DbException;
import
org.h2.message.Trace
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObjectBase
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
import
org.h2.util.SourceCompiler
;
...
...
@@ -194,7 +194,7 @@ public class FunctionAlias extends SchemaObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/engine/MetaRecord.java
浏览文件 @
78cc4925
...
...
@@ -127,14 +127,16 @@ public class MetaRecord implements Comparable<MetaRecord> {
return
9
;
case
DbObject
.
TRIGGER
:
return
10
;
case
DbObject
.
ROLE
:
case
DbObject
.
SYNONYM
:
return
11
;
case
DbObject
.
R
IGHT
:
case
DbObject
.
R
OLE
:
return
12
;
case
DbObject
.
AGGREGATE
:
case
DbObject
.
RIGHT
:
return
13
;
case
DbObject
.
COMMENT
:
case
DbObject
.
AGGREGATE
:
return
14
;
case
DbObject
.
COMMENT
:
return
15
;
default
:
throw
DbException
.
throwInternalError
(
"type="
+
objectType
);
}
...
...
h2/src/main/org/h2/engine/Right.java
浏览文件 @
78cc4925
...
...
@@ -8,7 +8,6 @@ package org.h2.engine;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Table
;
/**
...
...
@@ -128,7 +127,7 @@ public class Right extends DbObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
return
getCreateSQLForCopy
(
table
);
}
...
...
h2/src/main/org/h2/engine/RightOwner.java
浏览文件 @
78cc4925
...
...
@@ -7,7 +7,7 @@ package org.h2.engine;
import
java.util.HashMap
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
/**
...
...
@@ -63,7 +63,7 @@ public abstract class RightOwner extends DbObjectBase {
* @param rightMask the right mask to check
* @return true if the right was already granted
*/
boolean
isRightGrantedRecursive
(
Abstract
Table
table
,
int
rightMask
)
{
boolean
isRightGrantedRecursive
(
Table
table
,
int
rightMask
)
{
Right
right
;
if
(
grantedRights
!=
null
)
{
if
(
table
!=
null
)
{
...
...
h2/src/main/org/h2/engine/Role.java
浏览文件 @
78cc4925
...
...
@@ -7,7 +7,7 @@ package org.h2.engine;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
/**
* Represents a role. Roles can be granted to users, and to other roles.
...
...
@@ -22,7 +22,7 @@ public class Role extends RightOwner {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
78cc4925
...
...
@@ -38,7 +38,6 @@ import org.h2.schema.Schema;
import
org.h2.store.DataHandler
;
import
org.h2.store.InDoubtTransaction
;
import
org.h2.store.LobStorageFrontend
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.SubQueryInfo
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
...
...
@@ -373,7 +372,7 @@ public class Session extends SessionWithState {
*
* @param table the table
*/
public
void
removeLocalTempTable
(
Abstract
Table
table
)
{
public
void
removeLocalTempTable
(
Table
table
)
{
modificationId
++;
localTempTables
.
remove
(
table
.
getName
());
synchronized
(
database
)
{
...
...
@@ -878,8 +877,8 @@ public class Session extends SessionWithState {
* @param operation the operation type (see {@link UndoLogRecord})
* @param row the row
*/
public
void
log
(
Abstract
Table
table
,
short
operation
,
Row
row
)
{
if
(
table
.
resolve
().
isMVStore
())
{
public
void
log
(
Table
table
,
short
operation
,
Row
row
)
{
if
(
table
.
isMVStore
())
{
return
;
}
if
(
undoLogEnabled
)
{
...
...
@@ -890,7 +889,7 @@ public class Session extends SessionWithState {
int
lockMode
=
database
.
getLockMode
();
if
(
lockMode
!=
Constants
.
LOCK_MODE_OFF
&&
!
database
.
isMultiVersion
())
{
TableType
tableType
=
log
.
getTable
().
resolve
().
getTableType
();
TableType
tableType
=
log
.
getTable
().
getTableType
();
if
(
locks
.
indexOf
(
log
.
getTable
())
<
0
&&
TableType
.
TABLE_LINK
!=
tableType
&&
TableType
.
EXTERNAL_TABLE_ENGINE
!=
tableType
)
{
...
...
@@ -902,7 +901,7 @@ public class Session extends SessionWithState {
}
else
{
if
(
database
.
isMultiVersion
())
{
// see also UndoLogRecord.commit
ArrayList
<
Index
>
indexes
=
table
.
resolve
().
getIndexes
();
ArrayList
<
Index
>
indexes
=
table
.
getIndexes
();
for
(
int
i
=
0
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
Index
index
=
indexes
.
get
(
i
);
index
.
commit
(
operation
,
row
);
...
...
h2/src/main/org/h2/engine/Setting.java
浏览文件 @
78cc4925
...
...
@@ -7,7 +7,7 @@ package org.h2.engine;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
/**
* A persistent database setting.
...
...
@@ -38,7 +38,7 @@ public class Setting extends DbObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/engine/UndoLog.java
浏览文件 @
78cc4925
...
...
@@ -10,7 +10,7 @@ import java.util.HashMap;
import
org.h2.message.DbException
;
import
org.h2.store.Data
;
import
org.h2.store.FileStore
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
/**
...
...
@@ -25,7 +25,7 @@ public class UndoLog {
private
Data
rowBuff
;
private
int
memoryUndo
;
private
int
storedEntries
;
private
HashMap
<
Integer
,
Abstract
Table
>
tables
;
private
HashMap
<
Integer
,
Table
>
tables
;
private
final
boolean
largeTransactions
;
/**
...
...
@@ -220,7 +220,7 @@ public class UndoLog {
* @param table the table
* @return the id
*/
int
getTableId
(
Abstract
Table
table
)
{
int
getTableId
(
Table
table
)
{
int
id
=
table
.
getId
();
if
(
tables
==
null
)
{
tables
=
New
.
hashMap
();
...
...
@@ -238,7 +238,7 @@ public class UndoLog {
* @param id the table id
* @return the table object
*/
Abstract
Table
getTable
(
int
id
)
{
Table
getTable
(
int
id
)
{
return
tables
.
get
(
id
);
}
...
...
h2/src/main/org/h2/engine/UndoLogRecord.java
浏览文件 @
78cc4925
...
...
@@ -10,7 +10,7 @@ import org.h2.message.DbException;
import
org.h2.result.Row
;
import
org.h2.store.Data
;
import
org.h2.store.FileStore
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.value.Value
;
/**
...
...
@@ -29,7 +29,7 @@ public class UndoLogRecord {
public
static
final
short
DELETE
=
1
;
private
static
final
int
IN_MEMORY
=
0
,
STORED
=
1
,
IN_MEMORY_INVALID
=
2
;
private
Abstract
Table
table
;
private
Table
table
;
private
Row
row
;
private
short
operation
;
private
short
state
;
...
...
@@ -42,7 +42,7 @@ public class UndoLogRecord {
* @param op the operation type
* @param row the row that was deleted or inserted
*/
UndoLogRecord
(
Abstract
Table
table
,
short
op
,
Row
row
)
{
UndoLogRecord
(
Table
table
,
short
op
,
Row
row
)
{
this
.
table
=
table
;
this
.
row
=
row
;
this
.
operation
=
op
;
...
...
@@ -66,7 +66,7 @@ public class UndoLogRecord {
*/
boolean
canStore
()
{
// if large transactions are enabled, this method is not called
if
(
table
.
resolve
().
getUniqueIndex
()
!=
null
)
{
if
(
table
.
getUniqueIndex
()
!=
null
)
{
return
true
;
}
return
false
;
...
...
@@ -93,8 +93,8 @@ public class UndoLogRecord {
}
try
{
row
.
setDeleted
(
false
);
table
.
re
solve
().
re
moveRow
(
session
,
row
);
table
.
resolve
().
fireAfterRow
(
session
,
row
,
null
,
true
);
table
.
removeRow
(
session
,
row
);
table
.
fireAfterRow
(
session
,
row
,
null
,
true
);
}
catch
(
DbException
e
)
{
if
(
session
.
getDatabase
().
getLockMode
()
==
Constants
.
LOCK_MODE_OFF
&&
e
.
getErrorCode
()
==
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
)
{
...
...
@@ -107,8 +107,8 @@ public class UndoLogRecord {
break
;
case
DELETE:
try
{
table
.
resolve
().
addRow
(
session
,
row
);
table
.
resolve
().
fireAfterRow
(
session
,
null
,
row
,
true
);
table
.
addRow
(
session
,
row
);
table
.
fireAfterRow
(
session
,
null
,
row
,
true
);
// reset session id, otherwise other sessions think
// that this row was inserted by this session
row
.
commit
();
...
...
@@ -233,7 +233,7 @@ public class UndoLogRecord {
*
* @return the table
*/
public
Abstract
Table
getTable
()
{
public
Table
getTable
()
{
return
table
;
}
...
...
@@ -251,7 +251,7 @@ public class UndoLogRecord {
* It commits the change to the indexes.
*/
void
commit
()
{
table
.
resolve
().
commit
(
operation
,
row
);
table
.
commit
(
operation
,
row
);
}
/**
...
...
h2/src/main/org/h2/engine/User.java
浏览文件 @
78cc4925
...
...
@@ -12,9 +12,9 @@ import org.h2.message.DbException;
import
org.h2.message.Trace
;
import
org.h2.schema.Schema
;
import
org.h2.security.SHA256
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.MetaTable
;
import
org.h2.table.RangeTable
;
import
org.h2.table.Table
;
import
org.h2.table.TableType
;
import
org.h2.table.TableView
;
import
org.h2.util.MathUtils
;
...
...
@@ -75,7 +75,7 @@ public class User extends RightOwner {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
@@ -96,7 +96,7 @@ public class User extends RightOwner {
* @param rightMask the rights required
* @throws DbException if this user does not have the required rights
*/
public
void
checkRight
(
Abstract
Table
table
,
int
rightMask
)
{
public
void
checkRight
(
Table
table
,
int
rightMask
)
{
if
(!
hasRight
(
table
,
rightMask
))
{
throw
DbException
.
get
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
table
.
getSQL
());
}
...
...
@@ -109,9 +109,9 @@ public class User extends RightOwner {
* @param rightMask the rights required
* @return true if the user has the rights
*/
public
boolean
hasRight
(
Abstract
Table
table
,
int
rightMask
)
{
public
boolean
hasRight
(
Table
table
,
int
rightMask
)
{
if
(
rightMask
!=
Right
.
SELECT
&&
!
systemUser
&&
table
!=
null
)
{
table
.
resolve
().
checkWritingAllowed
();
table
.
checkWritingAllowed
();
}
if
(
admin
)
{
return
true
;
...
...
@@ -128,7 +128,7 @@ public class User extends RightOwner {
if
(
hasRight
(
null
,
Right
.
ALTER_ANY_SCHEMA
))
{
return
true
;
}
TableType
tableType
=
table
.
resolve
().
getTableType
();
TableType
tableType
=
table
.
getTableType
();
if
(
TableType
.
VIEW
==
tableType
)
{
TableView
v
=
(
TableView
)
table
;
if
(
v
.
getOwner
()
==
this
)
{
...
...
@@ -140,7 +140,7 @@ public class User extends RightOwner {
// function table
return
true
;
}
if
(
table
.
isTemporary
()
&&
!
table
.
resolve
().
isGlobalTemporary
())
{
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
())
{
// the owner has all rights on local temporary tables
return
true
;
}
...
...
h2/src/main/org/h2/engine/UserAggregate.java
浏览文件 @
78cc4925
...
...
@@ -12,7 +12,7 @@ import org.h2.api.AggregateFunction;
import
org.h2.command.Parser
;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.util.JdbcUtils
;
import
org.h2.value.DataType
;
...
...
@@ -53,7 +53,7 @@ public class UserAggregate extends DbObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/engine/UserDataType.java
浏览文件 @
78cc4925
...
...
@@ -7,8 +7,8 @@ package org.h2.engine;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
/**
* Represents a domain (user-defined data type).
...
...
@@ -22,7 +22,7 @@ public class UserDataType extends DbObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/expression/Aggregate.java
浏览文件 @
78cc4925
...
...
@@ -18,9 +18,9 @@ import org.h2.index.Index;
import
org.h2.message.DbException
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
...
...
@@ -281,8 +281,8 @@ public class Aggregate extends Expression {
switch
(
type
)
{
case
COUNT:
case
COUNT_ALL:
Abstract
Table
table
=
select
.
getTopTableFilter
().
getTable
();
return
ValueLong
.
get
(
table
.
resolve
().
getRowCount
(
session
));
Table
table
=
select
.
getTopTableFilter
().
getTable
();
return
ValueLong
.
get
(
table
.
getRowCount
(
session
));
case
MIN:
case
MAX:
boolean
first
=
type
==
MIN
;
...
...
@@ -580,8 +580,8 @@ public class Aggregate extends Expression {
Column
column
=
col
.
getColumn
();
TableFilter
filter
=
col
.
getTableFilter
();
if
(
filter
!=
null
)
{
Abstract
Table
table
=
filter
.
getTable
();
Index
index
=
table
.
resolve
().
getIndexForColumn
(
column
,
true
,
false
);
Table
table
=
filter
.
getTable
();
Index
index
=
table
.
getIndexForColumn
(
column
,
true
,
false
);
return
index
;
}
}
...
...
@@ -594,11 +594,11 @@ public class Aggregate extends Expression {
switch
(
type
)
{
case
COUNT:
if
(!
distinct
&&
on
.
getNullable
()
==
Column
.
NOT_NULLABLE
)
{
return
visitor
.
getTable
().
resolve
().
canGetRowCount
();
return
visitor
.
getTable
().
canGetRowCount
();
}
return
false
;
case
COUNT_ALL:
return
visitor
.
getTable
().
resolve
().
canGetRowCount
();
return
visitor
.
getTable
().
canGetRowCount
();
case
MIN:
case
MAX:
Index
index
=
getMinMaxColumnIndex
();
...
...
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
78cc4925
...
...
@@ -373,7 +373,7 @@ public class Comparison extends Condition {
@Override
public
void
createIndexConditions
(
Session
session
,
TableFilter
filter
)
{
if
(!
filter
.
getTable
().
resolve
().
isQueryComparable
())
{
if
(!
filter
.
getTable
().
isQueryComparable
())
{
return
;
}
ExpressionColumn
l
=
null
;
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
78cc4925
...
...
@@ -16,9 +16,9 @@ import org.h2.index.IndexCondition;
import
org.h2.message.DbException
;
import
org.h2.schema.Constant
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.ValueBoolean
;
...
...
@@ -240,13 +240,13 @@ public class ExpressionColumn extends Expression {
@Override
public
String
getSchemaName
()
{
Abstract
Table
table
=
column
.
getTable
();
Table
table
=
column
.
getTable
();
return
table
==
null
?
null
:
table
.
getSchema
().
getName
();
}
@Override
public
String
getTableName
()
{
Abstract
Table
table
=
column
.
getTable
();
Table
table
=
column
.
getTable
();
return
table
==
null
?
null
:
table
.
getName
();
}
...
...
@@ -297,7 +297,7 @@ public class ExpressionColumn extends Expression {
}
return
evaluatable
||
visitor
.
getQueryLevel
()
<
this
.
queryLevel
;
case
ExpressionVisitor
.
SET_MAX_DATA_MODIFICATION_ID
:
visitor
.
addDataModificationId
(
column
.
getTable
().
resolve
().
getMaxDataModificationId
());
visitor
.
addDataModificationId
(
column
.
getTable
().
getMaxDataModificationId
());
return
true
;
case
ExpressionVisitor
.
NOT_FROM_RESOLVER
:
return
columnResolver
!=
visitor
.
getResolver
();
...
...
h2/src/main/org/h2/expression/ExpressionVisitor.java
浏览文件 @
78cc4925
...
...
@@ -7,9 +7,9 @@ package org.h2.expression;
import
java.util.HashSet
;
import
org.h2.engine.DbObject
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.util.New
;
...
...
@@ -111,14 +111,14 @@ public class ExpressionVisitor {
private
final
int
queryLevel
;
private
final
HashSet
<
DbObject
>
dependencies
;
private
final
HashSet
<
Column
>
columns
;
private
final
Abstract
Table
table
;
private
final
Table
table
;
private
final
long
[]
maxDataModificationId
;
private
final
ColumnResolver
resolver
;
private
ExpressionVisitor
(
int
type
,
int
queryLevel
,
HashSet
<
DbObject
>
dependencies
,
HashSet
<
Column
>
columns
,
Abstract
Table
table
,
ColumnResolver
resolver
,
HashSet
<
Column
>
columns
,
Table
table
,
ColumnResolver
resolver
,
long
[]
maxDataModificationId
)
{
this
.
type
=
type
;
this
.
queryLevel
=
queryLevel
;
...
...
@@ -157,7 +157,7 @@ public class ExpressionVisitor {
* @param table the table
* @return the new visitor
*/
public
static
ExpressionVisitor
getOptimizableVisitor
(
Abstract
Table
table
)
{
public
static
ExpressionVisitor
getOptimizableVisitor
(
Table
table
)
{
return
new
ExpressionVisitor
(
OPTIMIZABLE_MIN_MAX_COUNT_ALL
,
0
,
null
,
null
,
table
,
null
,
null
);
}
...
...
@@ -274,7 +274,7 @@ public class ExpressionVisitor {
*
* @return the table
*/
public
Abstract
Table
getTable
()
{
public
Table
getTable
()
{
return
table
;
}
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
78cc4925
...
...
@@ -37,10 +37,10 @@ import org.h2.security.BlockCipher;
import
org.h2.security.CipherFactory
;
import
org.h2.security.SHA256
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.LinkSchema
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.Csv
;
...
...
@@ -1160,8 +1160,8 @@ public class Function extends Expression implements FunctionCall {
private
static
long
getDiskSpaceUsed
(
Session
session
,
Value
v0
)
{
Parser
p
=
new
Parser
(
session
);
String
sql
=
v0
.
getString
();
Abstract
Table
table
=
p
.
parseTableName
(
sql
);
return
table
.
resolve
().
getDiskSpaceUsed
();
Table
table
=
p
.
parseTableName
(
sql
);
return
table
.
getDiskSpaceUsed
();
}
private
static
Value
getNullOrValue
(
Session
session
,
Expression
[]
args
,
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
78cc4925
...
...
@@ -17,7 +17,6 @@ import org.h2.result.Row;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.SchemaObjectBase
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
...
...
@@ -397,7 +396,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
targetTable
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
targetTable
,
String
quotedName
)
{
StringBuilder
buff
=
new
StringBuilder
(
"CREATE "
);
buff
.
append
(
indexType
.
getSQL
());
buff
.
append
(
' '
);
...
...
h2/src/main/org/h2/index/MultiVersionIndex.java
浏览文件 @
78cc4925
...
...
@@ -16,7 +16,6 @@ import org.h2.result.Row;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.Schema
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.RegularTable
;
...
...
@@ -252,7 +251,7 @@ public class MultiVersionIndex implements Index {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
forTable
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
forTable
,
String
quotedName
)
{
return
base
.
getCreateSQLForCopy
(
forTable
,
quotedName
);
}
...
...
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
78cc4925
...
...
@@ -12,6 +12,7 @@ import java.sql.ResultSet;
import
java.sql.RowIdLifetime
;
import
java.sql.SQLException
;
import
java.sql.Types
;
import
java.util.Arrays
;
import
java.util.Properties
;
import
org.h2.engine.Constants
;
import
org.h2.engine.SysProperties
;
...
...
@@ -153,7 +154,8 @@ public class JdbcDatabaseMetaData extends TraceObject implements
}
else
{
tableType
=
"TRUE"
;
}
PreparedStatement
prep
=
conn
.
prepareAutoCloseStatement
(
"SELECT "
String
tableSelect
=
"SELECT "
+
"TABLE_CATALOG TABLE_CAT, "
+
"TABLE_SCHEMA TABLE_SCHEM, "
+
"TABLE_NAME, "
...
...
@@ -169,16 +171,55 @@ public class JdbcDatabaseMetaData extends TraceObject implements
+
"WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+
"AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+
"AND TABLE_NAME LIKE ? ESCAPE ? "
+
"AND ("
+
tableType
+
") "
+
"ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME"
);
+
"AND ("
+
tableType
+
") "
;
boolean
includeSynonyms
=
types
==
null
||
Arrays
.
asList
(
types
).
contains
(
"SYNONYM"
);
String
synonymSelect
=
"SELECT "
+
"SYNONYM_CATALOG TABLE_CAT, "
+
"SYNONYM_SCHEMA TABLE_SCHEM, "
+
"SYNONYM_NAME as TABLE_NAME, "
+
"TYPE_NAME AS TABLE_TYPE, "
+
"REMARKS, "
+
"TYPE_NAME TYPE_CAT, "
+
"TYPE_NAME TYPE_SCHEM, "
+
"TYPE_NAME AS TYPE_NAME, "
+
"TYPE_NAME SELF_REFERENCING_COL_NAME, "
+
"TYPE_NAME REF_GENERATION, "
+
"NULL AS SQL "
+
"FROM INFORMATION_SCHEMA.SYNONYMS "
+
"WHERE SYNONYM_CATALOG LIKE ? ESCAPE ? "
+
"AND SYNONYM_SCHEMA LIKE ? ESCAPE ? "
+
"AND SYNONYM_NAME LIKE ? ESCAPE ? "
+
"AND ("
+
includeSynonyms
+
") "
;
PreparedStatement
prep
=
conn
.
prepareAutoCloseStatement
(
"SELECT "
+
"TABLE_CAT, "
+
"TABLE_SCHEM, "
+
"TABLE_NAME, "
+
"TABLE_TYPE, "
+
"REMARKS, "
+
"TYPE_CAT, "
+
"TYPE_SCHEM, "
+
"TYPE_NAME, "
+
"SELF_REFERENCING_COL_NAME, "
+
"REF_GENERATION, "
+
"SQL "
+
"FROM ("
+
synonymSelect
+
" UNION "
+
tableSelect
+
") "
+
"ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME"
);
prep
.
setString
(
1
,
getCatalogPattern
(
catalogPattern
));
prep
.
setString
(
2
,
"\\"
);
prep
.
setString
(
3
,
getSchemaPattern
(
schemaPattern
));
prep
.
setString
(
4
,
"\\"
);
prep
.
setString
(
5
,
getPattern
(
tableNamePattern
));
prep
.
setString
(
6
,
"\\"
);
prep
.
setString
(
7
,
getCatalogPattern
(
catalogPattern
));
prep
.
setString
(
8
,
"\\"
);
prep
.
setString
(
9
,
getSchemaPattern
(
schemaPattern
));
prep
.
setString
(
10
,
"\\"
);
prep
.
setString
(
11
,
getPattern
(
tableNamePattern
));
prep
.
setString
(
12
,
"\\"
);
for
(
int
i
=
0
;
types
!=
null
&&
i
<
types
.
length
;
i
++)
{
prep
.
setString
(
7
+
i
,
types
[
i
]);
prep
.
setString
(
13
+
i
,
types
[
i
]);
}
return
prep
.
executeQuery
();
}
catch
(
Exception
e
)
{
...
...
h2/src/main/org/h2/schema/Constant.java
浏览文件 @
78cc4925
...
...
@@ -10,7 +10,7 @@ import org.h2.engine.Session;
import
org.h2.expression.ValueExpression
;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.value.Value
;
/**
...
...
@@ -27,7 +27,7 @@ public class Constant extends SchemaObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
78cc4925
...
...
@@ -25,7 +25,6 @@ import org.h2.index.Index;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.mvstore.db.MVTableEngine
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.RegularTable
;
import
org.h2.table.Table
;
import
org.h2.table.TableLink
;
...
...
@@ -43,7 +42,8 @@ public class Schema extends DbObjectBase {
private
final
boolean
system
;
private
ArrayList
<
String
>
tableEngineParams
;
private
final
ConcurrentHashMap
<
String
,
AbstractTable
>
tablesAndViews
;
private
final
ConcurrentHashMap
<
String
,
Table
>
tablesAndViews
;
private
final
ConcurrentHashMap
<
String
,
TableSynonym
>
synonyms
;
private
final
ConcurrentHashMap
<
String
,
Index
>
indexes
;
private
final
ConcurrentHashMap
<
String
,
Sequence
>
sequences
;
private
final
ConcurrentHashMap
<
String
,
TriggerObject
>
triggers
;
...
...
@@ -71,6 +71,7 @@ public class Schema extends DbObjectBase {
public
Schema
(
Database
database
,
int
id
,
String
schemaName
,
User
owner
,
boolean
system
)
{
tablesAndViews
=
database
.
newConcurrentStringMap
();
synonyms
=
database
.
newConcurrentStringMap
();
indexes
=
database
.
newConcurrentStringMap
();
sequences
=
database
.
newConcurrentStringMap
();
triggers
=
database
.
newConcurrentStringMap
();
...
...
@@ -92,7 +93,7 @@ public class Schema extends DbObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
@@ -132,7 +133,7 @@ public class Schema extends DbObjectBase {
runLoopAgain
=
false
;
if
(
tablesAndViews
!=
null
)
{
// Loop over a copy because the map is modified underneath us.
for
(
Abstract
Table
obj
:
New
.
arrayList
(
tablesAndViews
.
values
()))
{
for
(
Table
obj
:
New
.
arrayList
(
tablesAndViews
.
values
()))
{
// Check for null because multiple tables might be deleted
// in one go underneath us.
if
(
obj
.
getName
()
!=
null
)
{
...
...
@@ -204,6 +205,9 @@ public class Schema extends DbObjectBase {
case
DbObject
.
TABLE_OR_VIEW
:
result
=
tablesAndViews
;
break
;
case
DbObject
.
SYNONYM
:
result
=
synonyms
;
break
;
case
DbObject
.
SEQUENCE
:
result
=
sequences
;
break
;
...
...
@@ -276,34 +280,51 @@ public class Schema extends DbObjectBase {
/**
* Try to find a table or view with this name. This method returns null if
* no object with this name exists. Local temporary tables are also
* returned.
* returned.
Synonyms are not returned or resolved.
*
* @param session the session
* @param name the object name
* @return the object or null
*/
public
AbstractTable
findTableViewOrSynonym
(
Session
session
,
String
name
)
{
Abstract
Table
table
=
tablesAndViews
.
get
(
name
);
public
Table
findTableOrView
(
Session
session
,
String
name
)
{
Table
table
=
tablesAndViews
.
get
(
name
);
if
(
table
==
null
&&
session
!=
null
)
{
table
=
session
.
findLocalTempTable
(
name
);
}
return
table
;
}
/**
* Try to find a table or view with this name. This method returns null if
* no object with this name exists. Local temporary tables are also
* returned. If a synonym with this name exists, the backing table of the
* synonym is returned
*
* @param session the session
* @param name the object name
* @return the object or null
*/
public
Table
resolveTableOrView
(
Session
session
,
String
name
)
{
AbstractTable
table
=
findTableViewOrSynonym
(
session
,
name
);
Table
table
=
findTableOrView
(
session
,
name
);
if
(
table
==
null
)
{
TableSynonym
synonym
=
synonyms
.
get
(
name
);
if
(
synonym
!=
null
)
{
return
synonym
.
getSynonymFor
();
}
return
null
;
}
return
table
.
resolve
()
;
return
table
;
}
public
Table
findTableOrView
(
Session
session
,
String
name
)
{
AbstractTable
table
=
findTableViewOrSynonym
(
session
,
name
);
if
(
table
==
null
)
{
return
null
;
}
return
table
.
asTable
();
/**
* Try to find a synonym with this name. This method returns null if
* no object with this name exists.
*
* @param name the object name
* @return the object or null
*/
public
TableSynonym
getSynonym
(
String
name
)
{
return
synonyms
.
get
(
name
);
}
/**
...
...
@@ -428,9 +449,9 @@ public class Schema extends DbObjectBase {
* @param table the constraint table
* @return the unique name
*/
public
String
getUniqueConstraintName
(
Session
session
,
Abstract
Table
table
)
{
public
String
getUniqueConstraintName
(
Session
session
,
Table
table
)
{
Map
<
String
,
Constraint
>
tableConstraints
;
if
(
table
.
isTemporary
()
&&
!
table
.
resolve
().
isGlobalTemporary
())
{
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
())
{
tableConstraints
=
session
.
getLocalTempTableConstraints
();
}
else
{
tableConstraints
=
constraints
;
...
...
@@ -446,9 +467,9 @@ public class Schema extends DbObjectBase {
* @param prefix the index name prefix
* @return the unique name
*/
public
String
getUniqueIndexName
(
Session
session
,
Abstract
Table
table
,
String
prefix
)
{
public
String
getUniqueIndexName
(
Session
session
,
Table
table
,
String
prefix
)
{
Map
<
String
,
Index
>
tableIndexes
;
if
(
table
.
isTemporary
()
&&
!
table
.
resolve
().
isGlobalTemporary
())
{
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
())
{
tableIndexes
=
session
.
getLocalTempTableIndexes
();
}
else
{
tableIndexes
=
indexes
;
...
...
@@ -465,8 +486,8 @@ public class Schema extends DbObjectBase {
* @return the table or view
* @throws DbException if no such object exists
*/
public
Abstract
Table
getTableOrView
(
Session
session
,
String
name
)
{
Abstract
Table
table
=
tablesAndViews
.
get
(
name
);
public
Table
getTableOrView
(
Session
session
,
String
name
)
{
Table
table
=
tablesAndViews
.
get
(
name
);
if
(
table
==
null
)
{
if
(
session
!=
null
)
{
table
=
session
.
findLocalTempTable
(
name
);
...
...
@@ -571,19 +592,26 @@ public class Schema extends DbObjectBase {
*
* @return a (possible empty) list of all objects
*/
public
ArrayList
<
Abstract
Table
>
getAllTablesAndViews
()
{
public
ArrayList
<
Table
>
getAllTablesAndViews
()
{
synchronized
(
database
)
{
return
New
.
arrayList
(
tablesAndViews
.
values
());
}
}
public
ArrayList
<
TableSynonym
>
getAllSynonyms
()
{
synchronized
(
database
)
{
return
New
.
arrayList
(
synonyms
.
values
());
}
}
/**
* Get the table with the given name, if any.
*
* @param name the table name
* @return the table or null if not found
*/
public
Abstract
Table
getTableOrViewByName
(
String
name
)
{
public
Table
getTableOrViewByName
(
String
name
)
{
synchronized
(
database
)
{
return
tablesAndViews
.
get
(
name
);
}
...
...
h2/src/main/org/h2/schema/Sequence.java
浏览文件 @
78cc4925
...
...
@@ -11,7 +11,7 @@ import org.h2.engine.DbObject;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
/**
* A sequence is created using the statement
...
...
@@ -206,7 +206,7 @@ public class Sequence extends SchemaObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/schema/TriggerObject.java
浏览文件 @
78cc4925
...
...
@@ -18,7 +18,7 @@ import org.h2.engine.Session;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.result.Row
;
import
org.h2.table.
Abstract
Table
;
import
org.h2.table.Table
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.SourceCompiler
;
import
org.h2.util.StatementBuilder
;
...
...
@@ -45,12 +45,12 @@ public class TriggerObject extends SchemaObjectBase {
// TODO trigger: support queue and noWait = false as well
private
int
queueSize
=
DEFAULT_QUEUE_SIZE
;
private
boolean
noWait
;
private
Abstract
Table
table
;
private
Table
table
;
private
String
triggerClassName
;
private
String
triggerSource
;
private
Trigger
triggerCallback
;
public
TriggerObject
(
Schema
schema
,
int
id
,
String
name
,
Abstract
Table
table
)
{
public
TriggerObject
(
Schema
schema
,
int
id
,
String
name
,
Table
table
)
{
initSchemaObjectBase
(
schema
,
id
,
name
,
Trace
.
TRIGGER
);
this
.
table
=
table
;
setTemporary
(
table
.
isTemporary
());
...
...
@@ -318,7 +318,7 @@ public class TriggerObject extends SchemaObjectBase {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
targetTable
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
targetTable
,
String
quotedName
)
{
StringBuilder
buff
=
new
StringBuilder
(
"CREATE FORCE TRIGGER "
);
buff
.
append
(
quotedName
);
if
(
insteadOf
)
{
...
...
@@ -383,7 +383,7 @@ public class TriggerObject extends SchemaObjectBase {
@Override
public
void
removeChildrenAndResources
(
Session
session
)
{
table
.
re
solve
().
re
moveTrigger
(
this
);
table
.
removeTrigger
(
this
);
database
.
removeMeta
(
session
,
getId
());
if
(
triggerCallback
!=
null
)
{
try
{
...
...
@@ -409,7 +409,7 @@ public class TriggerObject extends SchemaObjectBase {
*
* @return the table
*/
public
Abstract
Table
getTable
()
{
public
Table
getTable
()
{
return
table
;
}
...
...
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
78cc4925
...
...
@@ -37,7 +37,6 @@ import org.h2.message.Trace;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.table.AbstractTable
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.RegularTable
;
...
...
@@ -553,19 +552,19 @@ public class PageStore implements CacheWriter {
log
.
checkpoint
();
writeBack
();
cache
.
clear
();
ArrayList
<
Abstract
Table
>
tables
=
database
.
getAllTablesAndViews
(
false
);
ArrayList
<
Table
>
tables
=
database
.
getAllTablesAndViews
(
false
);
recordedPagesList
=
New
.
arrayList
();
recordedPagesIndex
=
new
IntIntHashMap
();
recordPageReads
=
true
;
Session
sysSession
=
database
.
getSystemSession
();
for
(
Abstract
Table
table
:
tables
)
{
if
(!
table
.
isTemporary
()
&&
TableType
.
TABLE
==
table
.
resolve
().
getTableType
())
{
Index
scanIndex
=
table
.
resolve
().
getScanIndex
(
sysSession
);
for
(
Table
table
:
tables
)
{
if
(!
table
.
isTemporary
()
&&
TableType
.
TABLE
==
table
.
getTableType
())
{
Index
scanIndex
=
table
.
getScanIndex
(
sysSession
);
Cursor
cursor
=
scanIndex
.
find
(
sysSession
,
null
,
null
);
while
(
cursor
.
next
())
{
cursor
.
get
();
}
for
(
Index
index
:
table
.
resolve
().
getIndexes
())
{
for
(
Index
index
:
table
.
getIndexes
())
{
if
(
index
!=
scanIndex
&&
index
.
canScan
())
{
cursor
=
index
.
find
(
sysSession
,
null
,
null
);
while
(
cursor
.
next
())
{
...
...
h2/src/main/org/h2/table/AbstractTable.java
deleted
100644 → 0
浏览文件 @
cbf6b4c8
package
org
.
h2
.
table
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.h2.command.Prepared
;
import
org.h2.constraint.Constraint
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Session
;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
import
org.h2.message.DbException
;
import
org.h2.result.Row
;
import
org.h2.result.RowList
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.SchemaObjectBase
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.TriggerObject
;
import
org.h2.value.CompareMode
;
import
org.h2.value.Value
;
/**
* Abstract base class for tables and table synonyms.
*/
public
abstract
class
AbstractTable
extends
SchemaObjectBase
{
/**
* Resolves the "real" table behind this abstract table. For table this is the table itself for
* a synonym this is the backing table of the synonym. This method should be used in places, where synonym support
* is desired.
*/
public
abstract
Table
resolve
();
/**
* Returns the current table or fails with an unsupported database exception for synonyms.
* This method should be used in places that do not support the usage of synonyms.
*/
public
abstract
Table
asTable
();
public
abstract
TableType
getTableType
();
}
h2/src/main/org/h2/table/Column.java
浏览文件 @
78cc4925
...
...
@@ -70,7 +70,7 @@ public class Column {
private
int
scale
;
private
String
[]
enumerators
;
private
int
displaySize
;
private
Abstract
Table
table
;
private
Table
table
;
private
String
name
;
private
int
columnId
;
private
boolean
nullable
=
true
;
...
...
@@ -224,12 +224,12 @@ public class Column {
* @param table the table
* @param columnId the column index
*/
public
void
setTable
(
Abstract
Table
table
,
int
columnId
)
{
public
void
setTable
(
Table
table
,
int
columnId
)
{
this
.
table
=
table
;
this
.
columnId
=
columnId
;
}
public
Abstract
Table
getTable
()
{
public
Table
getTable
()
{
return
table
;
}
...
...
h2/src/main/org/h2/table/IndexColumn.java
浏览文件 @
78cc4925
...
...
@@ -69,9 +69,9 @@ public class IndexColumn {
* @param indexColumns the column list with column names set
* @param table the table from where to map the column names to columns
*/
public
static
void
mapColumns
(
IndexColumn
[]
indexColumns
,
Abstract
Table
table
)
{
public
static
void
mapColumns
(
IndexColumn
[]
indexColumns
,
Table
table
)
{
for
(
IndexColumn
col
:
indexColumns
)
{
col
.
column
=
table
.
resolve
().
getColumn
(
col
.
columnName
);
col
.
column
=
table
.
getColumn
(
col
.
columnName
);
}
}
...
...
h2/src/main/org/h2/table/JoinBatch.java
浏览文件 @
78cc4925
...
...
@@ -469,7 +469,7 @@ public final class JoinBatch {
}
Row
getNullRow
()
{
return
filter
.
getTable
().
resolve
().
getNullRow
();
return
filter
.
getTable
().
getNullRow
();
}
boolean
isOuterJoin
()
{
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
78cc4925
...
...
@@ -546,6 +546,7 @@ public class MetaTable extends Table {
"SYNONYM_SCHEMA"
,
"SYNONYM_NAME"
,
"SYNONYM_FOR"
,
"TYPE_NAME"
,
"STATUS"
,
"REMARKS"
,
"ID INT"
...
...
@@ -624,18 +625,18 @@ public class MetaTable extends Table {
return
s
;
}
private
ArrayList
<
Abstract
Table
>
getAllTables
(
Session
session
)
{
ArrayList
<
Abstract
Table
>
tables
=
database
.
getAllTablesAndViews
(
true
);
private
ArrayList
<
Table
>
getAllTables
(
Session
session
)
{
ArrayList
<
Table
>
tables
=
database
.
getAllTablesAndViews
(
true
);
ArrayList
<
Table
>
tempTables
=
session
.
getLocalTempTables
();
tables
.
addAll
(
tempTables
);
return
tables
;
}
private
ArrayList
<
Abstract
Table
>
getTablesByName
(
Session
session
,
String
tableName
)
{
private
ArrayList
<
Table
>
getTablesByName
(
Session
session
,
String
tableName
)
{
if
(
database
.
getMode
().
lowerCaseIdentifiers
)
{
tableName
=
StringUtils
.
toUpperEnglish
(
tableName
);
}
ArrayList
<
Abstract
Table
>
tables
=
database
.
getTableOrViewByName
(
tableName
);
ArrayList
<
Table
>
tables
=
database
.
getTableOrViewByName
(
tableName
);
for
(
Table
temp
:
session
.
getLocalTempTables
())
{
if
(
temp
.
getName
().
equals
(
tableName
))
{
tables
.
add
(
temp
);
...
...
@@ -669,7 +670,7 @@ public class MetaTable extends Table {
return
s
==
null
?
""
:
s
;
}
private
boolean
hideTable
(
Abstract
Table
table
,
Session
session
)
{
private
boolean
hideTable
(
Table
table
,
Session
session
)
{
return
table
.
isHidden
()
&&
session
!=
database
.
getSystemSession
();
}
...
...
@@ -700,7 +701,7 @@ public class MetaTable extends Table {
boolean
admin
=
session
.
getUser
().
isAdmin
();
switch
(
type
)
{
case
TABLES:
{
for
(
Abstract
Table
table
:
getAllTables
(
session
))
{
for
(
Table
table
:
getAllTables
(
session
))
{
String
tableName
=
identifier
(
table
.
getName
());
if
(!
checkIndex
(
session
,
tableName
,
indexFrom
,
indexTo
))
{
continue
;
...
...
@@ -710,13 +711,13 @@ public class MetaTable extends Table {
}
String
storageType
;
if
(
table
.
isTemporary
())
{
if
(
table
.
resolve
().
isGlobalTemporary
())
{
if
(
table
.
isGlobalTemporary
())
{
storageType
=
"GLOBAL TEMPORARY"
;
}
else
{
storageType
=
"LOCAL TEMPORARY"
;
}
}
else
{
storageType
=
table
.
resolve
().
isPersistIndexes
()
?
storageType
=
table
.
isPersistIndexes
()
?
"CACHED"
:
"MEMORY"
;
}
String
sql
=
table
.
getCreateSQL
();
...
...
@@ -742,7 +743,7 @@ public class MetaTable extends Table {
// REMARKS
replaceNullWithEmpty
(
table
.
getComment
()),
// LAST_MODIFICATION
""
+
table
.
resolve
().
getMaxDataModificationId
(),
""
+
table
.
getMaxDataModificationId
(),
// ID
""
+
table
.
getId
(),
// TYPE_NAME
...
...
@@ -750,7 +751,7 @@ public class MetaTable extends Table {
// TABLE_CLASS
table
.
getClass
().
getName
(),
// ROW_COUNT_ESTIMATE
""
+
table
.
resolve
().
getRowCountApproximation
()
""
+
table
.
getRowCountApproximation
()
);
}
break
;
...
...
@@ -758,14 +759,14 @@ public class MetaTable extends Table {
case
COLUMNS:
{
// reduce the number of tables to scan - makes some metadata queries
// 10x faster
final
ArrayList
<
Abstract
Table
>
tablesToList
;
final
ArrayList
<
Table
>
tablesToList
;
if
(
indexFrom
!=
null
&&
indexTo
!=
null
&&
indexFrom
.
equals
(
indexTo
))
{
String
tableName
=
identifier
(
indexFrom
.
getString
());
tablesToList
=
getTablesByName
(
session
,
tableName
);
}
else
{
tablesToList
=
getAllTables
(
session
);
}
for
(
Abstract
Table
table
:
tablesToList
)
{
for
(
Table
table
:
tablesToList
)
{
String
tableName
=
identifier
(
table
.
getName
());
if
(!
checkIndex
(
session
,
tableName
,
indexFrom
,
indexTo
))
{
continue
;
...
...
@@ -773,7 +774,7 @@ public class MetaTable extends Table {
if
(
hideTable
(
table
,
session
))
{
continue
;
}
Column
[]
cols
=
table
.
resolve
().
getColumns
();
Column
[]
cols
=
table
.
getColumns
();
String
collation
=
database
.
getCompareMode
().
getName
();
for
(
int
j
=
0
;
j
<
cols
.
length
;
j
++)
{
Column
c
=
cols
[
j
];
...
...
@@ -835,14 +836,14 @@ public class MetaTable extends Table {
case
INDEXES:
{
// reduce the number of tables to scan - makes some metadata queries
// 10x faster
final
ArrayList
<
Abstract
Table
>
tablesToList
;
final
ArrayList
<
Table
>
tablesToList
;
if
(
indexFrom
!=
null
&&
indexTo
!=
null
&&
indexFrom
.
equals
(
indexTo
))
{
String
tableName
=
identifier
(
indexFrom
.
getString
());
tablesToList
=
getTablesByName
(
session
,
tableName
);
}
else
{
tablesToList
=
getAllTables
(
session
);
}
for
(
Abstract
Table
table
:
tablesToList
)
{
for
(
Table
table
:
tablesToList
)
{
String
tableName
=
identifier
(
table
.
getName
());
if
(!
checkIndex
(
session
,
tableName
,
indexFrom
,
indexTo
))
{
continue
;
...
...
@@ -850,8 +851,8 @@ public class MetaTable extends Table {
if
(
hideTable
(
table
,
session
))
{
continue
;
}
ArrayList
<
Index
>
indexes
=
table
.
resolve
().
getIndexes
();
ArrayList
<
Constraint
>
constraints
=
table
.
resolve
().
getConstraints
();
ArrayList
<
Index
>
indexes
=
table
.
getIndexes
();
ArrayList
<
Constraint
>
constraints
=
table
.
getConstraints
();
for
(
int
j
=
0
;
indexes
!=
null
&&
j
<
indexes
.
size
();
j
++)
{
Index
index
=
indexes
.
get
(
j
);
if
(
index
.
getCreateSQL
()
==
null
)
{
...
...
@@ -1488,7 +1489,7 @@ public class MetaTable extends Table {
break
;
}
case
VIEWS:
{
for
(
Abstract
Table
table
:
getAllTables
(
session
))
{
for
(
Table
table
:
getAllTables
(
session
))
{
if
(
table
.
getTableType
()
!=
TableType
.
VIEW
)
{
continue
;
}
...
...
@@ -1544,8 +1545,8 @@ public class MetaTable extends Table {
ConstraintReferential
ref
=
(
ConstraintReferential
)
constraint
;
IndexColumn
[]
cols
=
ref
.
getColumns
();
IndexColumn
[]
refCols
=
ref
.
getRefColumns
();
Abstract
Table
tab
=
ref
.
getTable
();
Abstract
Table
refTab
=
ref
.
getRefTable
();
Table
tab
=
ref
.
getTable
();
Table
refTab
=
ref
.
getRefTable
();
String
tableName
=
identifier
(
refTab
.
getName
());
if
(!
checkIndex
(
session
,
tableName
,
indexFrom
,
indexTo
))
{
continue
;
...
...
@@ -1594,7 +1595,7 @@ public class MetaTable extends Table {
String
constraintType
=
constraint
.
getConstraintType
();
String
checkExpression
=
null
;
IndexColumn
[]
indexColumns
=
null
;
Abstract
Table
table
=
constraint
.
getTable
();
Table
table
=
constraint
.
getTable
();
if
(
hideTable
(
table
,
session
))
{
continue
;
}
...
...
@@ -1719,7 +1720,7 @@ public class MetaTable extends Table {
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
TRIGGER
))
{
TriggerObject
trigger
=
(
TriggerObject
)
obj
;
Abstract
Table
table
=
trigger
.
getTable
();
Table
table
=
trigger
.
getTable
();
add
(
rows
,
// TRIGGER_CATALOG
catalog
,
...
...
@@ -1878,21 +1879,18 @@ public class MetaTable extends Table {
break
;
}
case
SYNONYMS:
{
for
(
AbstractTable
table
:
getAllTables
(
session
))
{
if
(!
table
.
getTableType
().
equals
(
TableType
.
SYNONYM
))
{
continue
;
}
String
synonymName
=
identifier
(
table
.
getName
());
TableSynonym
synonym
=
(
TableSynonym
)
table
;
for
(
TableSynonym
synonym
:
database
.
getAllSynonyms
())
{
add
(
rows
,
// SYNONYM_CATALOG
catalog
,
// SYNONYM_SCHEMA
identifier
(
table
.
getSchema
().
getName
()),
identifier
(
synonym
.
getSchema
().
getName
()),
// SYNONYM_NAME
synonymName
,
identifier
(
synonym
.
getName
())
,
// SYNONYM_FOR
synonym
.
getSynonymForName
(),
// TYPE NAME
"SYNONYM"
,
// STATUS
"VALID"
,
// REMARKS
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
78cc4925
...
...
@@ -31,6 +31,7 @@ import org.h2.result.SimpleRow;
import
org.h2.result.SimpleRowValue
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObjectBase
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.TriggerObject
;
import
org.h2.util.New
;
...
...
@@ -42,7 +43,7 @@ import org.h2.value.ValueNull;
* This is the base class for most tables.
* A table contains a list of columns and a list of rows.
*/
public
abstract
class
Table
extends
AbstractTabl
e
{
public
abstract
class
Table
extends
SchemaObjectBas
e
{
/**
* The table type that means this table is a regular persistent table.
...
...
@@ -106,16 +107,6 @@ public abstract class Table extends AbstractTable {
return
false
;
}
@Override
public
Table
resolve
()
{
return
this
;
}
@Override
public
Table
asTable
()
{
return
this
;
}
/**
* Lock the table for the given session.
* This method waits until the lock is granted.
...
...
@@ -348,7 +339,7 @@ public abstract class Table extends AbstractTable {
return
null
;
}
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
DbException
.
throwInternalError
(
toString
());
}
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
78cc4925
...
...
@@ -51,7 +51,7 @@ public class TableFilter implements ColumnResolver {
private
Session
session
;
private
final
Abstract
Table
table
;
private
final
Table
table
;
private
final
Select
select
;
private
String
alias
;
private
Index
index
;
...
...
@@ -128,7 +128,7 @@ public class TableFilter implements ColumnResolver {
* @param orderInFrom original order number (index) of this table filter in
* @param indexHints the index hints to be used by the query planner
*/
public
TableFilter
(
Session
session
,
Abstract
Table
table
,
String
alias
,
public
TableFilter
(
Session
session
,
Table
table
,
String
alias
,
boolean
rightsChecked
,
Select
select
,
int
orderInFrom
,
IndexHints
indexHints
)
{
this
.
session
=
session
;
this
.
table
=
table
;
...
...
@@ -162,7 +162,7 @@ public class TableFilter implements ColumnResolver {
return
select
;
}
public
Abstract
Table
getTable
()
{
public
Table
getTable
()
{
return
table
;
}
...
...
@@ -174,7 +174,7 @@ public class TableFilter implements ColumnResolver {
* @param forceLockEvenInMvcc lock even in the MVCC mode
*/
public
void
lock
(
Session
s
,
boolean
exclusive
,
boolean
forceLockEvenInMvcc
)
{
table
.
resolve
().
lock
(
s
,
exclusive
,
forceLockEvenInMvcc
);
table
.
lock
(
s
,
exclusive
,
forceLockEvenInMvcc
);
if
(
join
!=
null
)
{
join
.
lock
(
s
,
exclusive
,
forceLockEvenInMvcc
);
}
...
...
@@ -199,12 +199,12 @@ public class TableFilter implements ColumnResolver {
}
if
(
indexConditions
.
size
()
==
0
)
{
item1
=
new
PlanItem
();
item1
.
setIndex
(
table
.
resolve
().
getScanIndex
(
s
,
null
,
filters
,
filter
,
item1
.
setIndex
(
table
.
getScanIndex
(
s
,
null
,
filters
,
filter
,
sortOrder
,
allColumnsSet
));
item1
.
cost
=
item1
.
getIndex
().
getCost
(
s
,
null
,
filters
,
filter
,
sortOrder
,
allColumnsSet
);
}
int
len
=
table
.
resolve
().
getColumns
().
length
;
int
len
=
table
.
getColumns
().
length
;
int
[]
masks
=
new
int
[
len
];
for
(
IndexCondition
condition
:
indexConditions
)
{
if
(
condition
.
isEvaluatable
())
{
...
...
@@ -218,7 +218,7 @@ public class TableFilter implements ColumnResolver {
}
}
}
PlanItem
item
=
table
.
resolve
().
getBestPlanItem
(
s
,
masks
,
filters
,
filter
,
sortOrder
,
allColumnsSet
);
PlanItem
item
=
table
.
getBestPlanItem
(
s
,
masks
,
filters
,
filter
,
sortOrder
,
allColumnsSet
);
item
.
setMasks
(
masks
);
// The more index conditions, the earlier the table.
// This is to ensure joins without indexes run quickly:
...
...
@@ -397,7 +397,7 @@ public class TableFilter implements ColumnResolver {
assert
filters
[
filter
]
==
this
;
joinBatch
=
null
;
joinFilterId
=
-
1
;
if
(
getTable
().
resolve
().
isView
())
{
if
(
getTable
().
isView
())
{
session
.
pushSubQueryInfo
(
masks
,
filters
,
filter
,
select
.
getSortOrder
());
try
{
((
ViewIndex
)
index
).
getQuery
().
prepareJoinBatch
();
...
...
@@ -553,7 +553,7 @@ public class TableFilter implements ColumnResolver {
*/
protected
void
setNullRow
()
{
state
=
NULL_ROW
;
current
=
table
.
resolve
().
getNullRow
();
current
=
table
.
getNullRow
();
currentSearchRow
=
current
;
if
(
nestedJoin
!=
null
)
{
nestedJoin
.
visit
(
new
TableFilterVisitor
()
{
...
...
@@ -818,12 +818,12 @@ public class TableFilter implements ColumnResolver {
}
return
buff
.
toString
();
}
if
(
table
.
resolve
().
isView
()
&&
((
TableView
)
table
).
isRecursive
())
{
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isRecursive
())
{
buff
.
append
(
table
.
getName
());
}
else
{
buff
.
append
(
table
.
getSQL
());
}
if
(
table
.
resolve
().
isView
()
&&
((
TableView
)
table
).
isInvalid
())
{
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isInvalid
())
{
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
table
.
getName
(),
"not compiled"
);
}
if
(
alias
!=
null
)
{
...
...
@@ -1034,7 +1034,7 @@ public class TableFilter implements ColumnResolver {
@Override
public
Column
[]
getColumns
()
{
return
table
.
resolve
().
getColumns
();
return
table
.
getColumns
();
}
/**
...
...
@@ -1062,7 +1062,7 @@ public class TableFilter implements ColumnResolver {
@Override
public
Column
getRowIdColumn
()
{
if
(
session
.
getDatabase
().
getSettings
().
rowId
)
{
return
table
.
resolve
().
getRowIdColumn
();
return
table
.
getRowIdColumn
();
}
return
null
;
}
...
...
@@ -1172,9 +1172,9 @@ public class TableFilter implements ColumnResolver {
public
void
lockRows
(
ArrayList
<
Row
>
forUpdateRows
)
{
for
(
Row
row
:
forUpdateRows
)
{
Row
newRow
=
row
.
getCopy
();
table
.
re
solve
().
re
moveRow
(
session
,
row
);
table
.
removeRow
(
session
,
row
);
session
.
log
(
table
,
UndoLogRecord
.
DELETE
,
row
);
table
.
resolve
().
addRow
(
session
,
newRow
);
table
.
addRow
(
session
,
newRow
);
session
.
log
(
table
,
UndoLogRecord
.
INSERT
,
newRow
);
}
}
...
...
h2/src/main/org/h2/table/TableSynonym.java
浏览文件 @
78cc4925
...
...
@@ -4,12 +4,13 @@ import org.h2.command.ddl.CreateSynonymData;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.schema.SchemaObjectBase
;
/**
* Synonym for an existing table or view. All DML requests are forwarded to the backing table. Adding indices
* to a synonym or altering the table is not supported.
*/
public
class
TableSynonym
extends
AbstractTabl
e
{
public
class
TableSynonym
extends
SchemaObjectBas
e
{
private
CreateSynonymData
data
;
...
...
@@ -20,33 +21,28 @@ public class TableSynonym extends AbstractTable {
this
.
data
=
data
;
}
public
void
updateData
(
CreateSynonymData
data
)
{
this
.
data
=
data
;
public
Table
getSynonymFor
(
)
{
return
synonymFor
;
}
p
rivate
AbstractTable
getSynonymFor
(
)
{
return
synonymFor
;
p
ublic
void
updateData
(
CreateSynonymData
data
)
{
this
.
data
=
data
;
}
@Override
public
int
getType
()
{
return
TABLE_OR_VIEW
;
return
SYNONYM
;
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
return
getSynonymFor
()
.
getCreateSQLForCopy
(
table
,
quotedName
);
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
return
synonymFor
.
getCreateSQLForCopy
(
table
,
quotedName
);
}
@Override
public
void
rename
(
String
newName
)
{
throw
DbException
.
getUnsupportedException
(
"SYNONYM"
);
}
@Override
public
TableType
getTableType
()
{
return
TableType
.
SYNONYM
;
}
@Override
public
void
removeChildrenAndResources
(
Session
session
)
{
synonymFor
.
removeSynonym
(
this
);
...
...
@@ -73,7 +69,7 @@ public class TableSynonym extends AbstractTable {
}
public
boolean
isInvalid
()
{
return
data
.
synonymForSchema
.
findTableViewOrSynonym
(
data
.
session
,
data
.
synonymFor
)
==
null
;
return
synonymFor
.
isValid
()
;
}
...
...
@@ -81,15 +77,8 @@ public class TableSynonym extends AbstractTable {
if
(
synonymFor
!=
null
)
{
synonymFor
.
removeSynonym
(
this
);
}
synonymFor
=
data
.
synonymForSchema
.
getTableOrView
(
data
.
session
,
data
.
synonymFor
)
.
resolve
()
;
synonymFor
=
data
.
synonymForSchema
.
getTableOrView
(
data
.
session
,
data
.
synonymFor
);
synonymFor
.
addSynonym
(
this
);
}
@Override
public
Table
resolve
()
{
return
synonymFor
;
}
@Override
public
Table
asTable
()
{
throw
DbException
.
getUnsupportedException
(
"SYNONYM"
);
}
}
h2/src/main/org/h2/table/TableView.java
浏览文件 @
78cc4925
...
...
@@ -45,7 +45,7 @@ public class TableView extends Table {
private
static
final
long
ROW_COUNT_APPROXIMATION
=
100
;
private
String
querySQL
;
private
ArrayList
<
Abstract
Table
>
tables
;
private
ArrayList
<
Table
>
tables
;
private
Column
[]
columnTemplates
;
private
Query
viewQuery
;
private
ViewIndex
index
;
...
...
@@ -265,8 +265,8 @@ public class TableView extends Table {
if
(!
super
.
isQueryComparable
())
{
return
false
;
}
for
(
Abstract
Table
t
:
tables
)
{
if
(!
t
.
resolve
().
isQueryComparable
())
{
for
(
Table
t
:
tables
)
{
if
(!
t
.
isQueryComparable
())
{
return
false
;
}
}
...
...
@@ -287,7 +287,7 @@ public class TableView extends Table {
}
@Override
public
String
getCreateSQLForCopy
(
Abstract
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
return
getCreateSQL
(
false
,
true
,
quotedName
);
}
...
...
@@ -502,16 +502,16 @@ public class TableView extends Table {
private
void
removeViewFromTables
()
{
if
(
tables
!=
null
)
{
for
(
Abstract
Table
t
:
tables
)
{
t
.
re
solve
().
re
moveView
(
this
);
for
(
Table
t
:
tables
)
{
t
.
removeView
(
this
);
}
tables
.
clear
();
}
}
private
void
addViewToTables
()
{
for
(
Abstract
Table
t
:
tables
)
{
t
.
resolve
().
addView
(
this
);
for
(
Table
t
:
tables
)
{
t
.
addView
(
this
);
}
}
...
...
@@ -620,9 +620,9 @@ public class TableView extends Table {
public
void
addDependencies
(
HashSet
<
DbObject
>
dependencies
)
{
super
.
addDependencies
(
dependencies
);
if
(
tables
!=
null
)
{
for
(
Abstract
Table
t
:
tables
)
{
for
(
Table
t
:
tables
)
{
if
(
TableType
.
VIEW
!=
t
.
getTableType
())
{
t
.
resolve
().
addDependencies
(
dependencies
);
t
.
addDependencies
(
dependencies
);
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论