Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
847cf627
提交
847cf627
authored
1月 29, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The information schema tables are only initialized when needed.
上级
8308f5c8
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
41 行增加
和
22 行删除
+41
-22
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+1
-1
DropDatabase.java
h2/src/main/org/h2/command/ddl/DropDatabase.java
+1
-1
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+1
-1
Database.java
h2/src/main/org/h2/engine/Database.java
+35
-17
User.java
h2/src/main/org/h2/engine/User.java
+2
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+1
-1
没有找到文件。
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
847cf627
...
@@ -34,7 +34,7 @@ public class Analyze extends DefineCommand {
...
@@ -34,7 +34,7 @@ public class Analyze extends DefineCommand {
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
session
.
getUser
().
checkAdmin
();
session
.
getUser
().
checkAdmin
();
// TODO do we need to lock the table?
// TODO do we need to lock the table?
for
(
Table
table
:
db
.
getAllTablesAndViews
())
{
for
(
Table
table
:
db
.
getAllTablesAndViews
(
false
))
{
if
(!(
table
instanceof
TableData
))
{
if
(!(
table
instanceof
TableData
))
{
continue
;
continue
;
}
}
...
...
h2/src/main/org/h2/command/ddl/DropDatabase.java
浏览文件 @
847cf627
...
@@ -50,7 +50,7 @@ public class DropDatabase extends DefineCommand {
...
@@ -50,7 +50,7 @@ public class DropDatabase extends DefineCommand {
db
.
removeDatabaseObject
(
session
,
schema
);
db
.
removeDatabaseObject
(
session
,
schema
);
}
}
}
}
ObjectArray
<
Table
>
tables
=
db
.
getAllTablesAndViews
();
ObjectArray
<
Table
>
tables
=
db
.
getAllTablesAndViews
(
false
);
for
(
Table
t
:
tables
)
{
for
(
Table
t
:
tables
)
{
if
(
t
.
getName
()
!=
null
&&
Table
.
VIEW
.
equals
(
t
.
getTableType
()))
{
if
(
t
.
getName
()
!=
null
&&
Table
.
VIEW
.
equals
(
t
.
getTableType
()))
{
db
.
removeSchemaObject
(
session
,
t
);
db
.
removeSchemaObject
(
session
,
t
);
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
847cf627
...
@@ -171,7 +171,7 @@ public class ScriptCommand extends ScriptBase {
...
@@ -171,7 +171,7 @@ public class ScriptCommand extends ScriptBase {
}
}
add
(
agg
.
getCreateSQL
(),
false
);
add
(
agg
.
getCreateSQL
(),
false
);
}
}
ObjectArray
<
Table
>
tables
=
db
.
getAllTablesAndViews
();
ObjectArray
<
Table
>
tables
=
db
.
getAllTablesAndViews
(
false
);
// sort by id, so that views are after tables and views on views
// sort by id, so that views are after tables and views on views
// after the base views
// after the base views
tables
.
sort
(
new
Comparator
<
Table
>()
{
tables
.
sort
(
new
Comparator
<
Table
>()
{
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
847cf627
...
@@ -45,7 +45,7 @@ import org.h2.store.PageStore;
...
@@ -45,7 +45,7 @@ import org.h2.store.PageStore;
import
org.h2.store.RecordReader
;
import
org.h2.store.RecordReader
;
import
org.h2.store.Storage
;
import
org.h2.store.Storage
;
import
org.h2.store.WriterThread
;
import
org.h2.store.WriterThread
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.store.fs.FileSystem
Memory
;
import
org.h2.table.Column
;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.MetaTable
;
import
org.h2.table.MetaTable
;
...
@@ -175,6 +175,7 @@ public class Database implements DataHandler {
...
@@ -175,6 +175,7 @@ public class Database implements DataHandler {
private
int
cacheSize
;
private
int
cacheSize
;
private
boolean
compactFully
;
private
boolean
compactFully
;
private
SourceCompiler
compiler
;
private
SourceCompiler
compiler
;
private
boolean
metaTablesInitialized
;
public
Database
(
String
name
,
ConnectionInfo
ci
,
String
cipher
)
throws
SQLException
{
public
Database
(
String
name
,
ConnectionInfo
ci
,
String
cipher
)
throws
SQLException
{
this
.
compareMode
=
CompareMode
.
getInstance
(
null
,
0
);
this
.
compareMode
=
CompareMode
.
getInstance
(
null
,
0
);
...
@@ -693,10 +694,6 @@ public class Database implements DataHandler {
...
@@ -693,10 +694,6 @@ public class Database implements DataHandler {
metaIdIndex
=
meta
.
addIndex
(
systemSession
,
"SYS_ID"
,
0
,
pkCols
,
IndexType
.
createPrimaryKey
(
metaIdIndex
=
meta
.
addIndex
(
systemSession
,
"SYS_ID"
,
0
,
pkCols
,
IndexType
.
createPrimaryKey
(
false
,
false
),
Index
.
EMPTY_HEAD
,
null
);
false
,
false
),
Index
.
EMPTY_HEAD
,
null
);
objectIds
.
set
(
0
);
objectIds
.
set
(
0
);
// there could be views on system tables, so they must be added first
for
(
int
i
=
0
;
i
<
MetaTable
.
getMetaTableTypeCount
();
i
++)
{
addMetaData
(
i
);
}
starting
=
true
;
starting
=
true
;
Cursor
cursor
=
metaIdIndex
.
find
(
systemSession
,
null
,
null
);
Cursor
cursor
=
metaIdIndex
.
find
(
systemSession
,
null
,
null
);
// first, create all function aliases and sequences because
// first, create all function aliases and sequences because
...
@@ -758,7 +755,7 @@ public class Database implements DataHandler {
...
@@ -758,7 +755,7 @@ public class Database implements DataHandler {
boolean
recompileSuccessful
;
boolean
recompileSuccessful
;
do
{
do
{
recompileSuccessful
=
false
;
recompileSuccessful
=
false
;
for
(
Table
obj
:
getAllTablesAndViews
())
{
for
(
Table
obj
:
getAllTablesAndViews
(
false
))
{
if
(
obj
instanceof
TableView
)
{
if
(
obj
instanceof
TableView
)
{
TableView
view
=
(
TableView
)
obj
;
TableView
view
=
(
TableView
)
obj
;
if
(
view
.
isInvalid
())
{
if
(
view
.
isInvalid
())
{
...
@@ -777,7 +774,7 @@ public class Database implements DataHandler {
...
@@ -777,7 +774,7 @@ public class Database implements DataHandler {
// when opening a database, views are initialized before indexes,
// when opening a database, views are initialized before indexes,
// so they may not have the optimal plan yet
// so they may not have the optimal plan yet
// this is not a problem, it is just nice to see the newest plan
// this is not a problem, it is just nice to see the newest plan
for
(
Table
obj
:
getAllTablesAndViews
())
{
for
(
Table
obj
:
getAllTablesAndViews
(
false
))
{
if
(
obj
instanceof
TableView
)
{
if
(
obj
instanceof
TableView
)
{
TableView
view
=
(
TableView
)
obj
;
TableView
view
=
(
TableView
)
obj
;
if
(!
view
.
isInvalid
())
{
if
(!
view
.
isInvalid
())
{
...
@@ -855,9 +852,19 @@ public class Database implements DataHandler {
...
@@ -855,9 +852,19 @@ public class Database implements DataHandler {
return
storage
;
return
storage
;
}
}
private
void
addMetaData
(
int
type
)
throws
SQLException
{
private
void
initMetaTables
()
{
if
(
metaTablesInitialized
)
{
return
;
}
for
(
int
type
=
0
;
type
<
MetaTable
.
getMetaTableTypeCount
();
type
++)
{
try
{
MetaTable
m
=
new
MetaTable
(
infoSchema
,
-
1
-
type
,
type
);
MetaTable
m
=
new
MetaTable
(
infoSchema
,
-
1
-
type
,
type
);
infoSchema
.
add
(
m
);
infoSchema
.
add
(
m
);
}
catch
(
SQLException
e
)
{
throw
Message
.
convertToInternal
(
e
);
}
}
metaTablesInitialized
=
true
;
}
}
private
synchronized
void
addMeta
(
Session
session
,
DbObject
obj
)
throws
SQLException
{
private
synchronized
void
addMeta
(
Session
session
,
DbObject
obj
)
throws
SQLException
{
...
@@ -1034,7 +1041,11 @@ public class Database implements DataHandler {
...
@@ -1034,7 +1041,11 @@ public class Database implements DataHandler {
* @return the schema or null
* @return the schema or null
*/
*/
public
Schema
findSchema
(
String
schemaName
)
{
public
Schema
findSchema
(
String
schemaName
)
{
return
schemas
.
get
(
schemaName
);
Schema
schema
=
schemas
.
get
(
schemaName
);
if
(
schema
==
infoSchema
)
{
initMetaTables
();
}
return
schema
;
}
}
/**
/**
...
@@ -1201,7 +1212,7 @@ public class Database implements DataHandler {
...
@@ -1201,7 +1212,7 @@ public class Database implements DataHandler {
try
{
try
{
if
(
systemSession
!=
null
)
{
if
(
systemSession
!=
null
)
{
if
(
powerOffCount
!=
-
1
)
{
if
(
powerOffCount
!=
-
1
)
{
for
(
Table
table
:
getAllTablesAndViews
())
{
for
(
Table
table
:
getAllTablesAndViews
(
false
))
{
table
.
close
(
systemSession
);
table
.
close
(
systemSession
);
}
}
for
(
SchemaObject
obj
:
getAllSchemaObjects
(
DbObject
.
SEQUENCE
))
{
for
(
SchemaObject
obj
:
getAllSchemaObjects
(
DbObject
.
SEQUENCE
))
{
...
@@ -1426,6 +1437,9 @@ public class Database implements DataHandler {
...
@@ -1426,6 +1437,9 @@ public class Database implements DataHandler {
* @return all objects of that type
* @return all objects of that type
*/
*/
public
ObjectArray
<
SchemaObject
>
getAllSchemaObjects
(
int
type
)
{
public
ObjectArray
<
SchemaObject
>
getAllSchemaObjects
(
int
type
)
{
if
(
type
==
DbObject
.
TABLE_OR_VIEW
)
{
initMetaTables
();
}
ObjectArray
<
SchemaObject
>
list
=
ObjectArray
.
newInstance
();
ObjectArray
<
SchemaObject
>
list
=
ObjectArray
.
newInstance
();
for
(
Schema
schema
:
schemas
.
values
())
{
for
(
Schema
schema
:
schemas
.
values
())
{
list
.
addAll
(
schema
.
getAll
(
type
));
list
.
addAll
(
schema
.
getAll
(
type
));
...
@@ -1438,7 +1452,10 @@ public class Database implements DataHandler {
...
@@ -1438,7 +1452,10 @@ public class Database implements DataHandler {
*
*
* @return all objects of that type
* @return all objects of that type
*/
*/
public
ObjectArray
<
Table
>
getAllTablesAndViews
()
{
public
ObjectArray
<
Table
>
getAllTablesAndViews
(
boolean
includeMeta
)
{
if
(
includeMeta
)
{
initMetaTables
();
}
ObjectArray
<
Table
>
list
=
ObjectArray
.
newInstance
();
ObjectArray
<
Table
>
list
=
ObjectArray
.
newInstance
();
for
(
Schema
schema
:
schemas
.
values
())
{
for
(
Schema
schema
:
schemas
.
values
())
{
list
.
addAll
(
schema
.
getAllTablesAndViews
());
list
.
addAll
(
schema
.
getAllTablesAndViews
());
...
@@ -1447,6 +1464,7 @@ public class Database implements DataHandler {
...
@@ -1447,6 +1464,7 @@ public class Database implements DataHandler {
}
}
public
ObjectArray
<
Schema
>
getAllSchemas
()
{
public
ObjectArray
<
Schema
>
getAllSchemas
()
{
initMetaTables
();
return
ObjectArray
.
newInstance
(
schemas
.
values
());
return
ObjectArray
.
newInstance
(
schemas
.
values
());
}
}
...
@@ -1603,7 +1621,7 @@ public class Database implements DataHandler {
...
@@ -1603,7 +1621,7 @@ public class Database implements DataHandler {
boolean
inTempDir
=
readOnly
;
boolean
inTempDir
=
readOnly
;
String
name
=
databaseName
;
String
name
=
databaseName
;
if
(!
persistent
)
{
if
(!
persistent
)
{
name
=
FileSystem
.
PREFIX_MEMORY
+
name
;
name
=
FileSystem
Memory
.
PREFIX
+
name
;
}
}
return
FileUtils
.
createTempFile
(
name
,
Constants
.
SUFFIX_TEMP_FILE
,
true
,
inTempDir
);
return
FileUtils
.
createTempFile
(
name
,
Constants
.
SUFFIX_TEMP_FILE
,
true
,
inTempDir
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -1719,7 +1737,7 @@ public class Database implements DataHandler {
...
@@ -1719,7 +1737,7 @@ public class Database implements DataHandler {
default
:
default
:
}
}
HashSet
<
DbObject
>
set
=
New
.
hashSet
();
HashSet
<
DbObject
>
set
=
New
.
hashSet
();
for
(
Table
t
:
getAllTablesAndViews
())
{
for
(
Table
t
:
getAllTablesAndViews
(
false
))
{
if
(
except
==
t
)
{
if
(
except
==
t
)
{
continue
;
continue
;
}
}
...
@@ -1735,7 +1753,7 @@ public class Database implements DataHandler {
...
@@ -1735,7 +1753,7 @@ public class Database implements DataHandler {
private
String
getFirstInvalidTable
(
Session
session
)
{
private
String
getFirstInvalidTable
(
Session
session
)
{
String
conflict
=
null
;
String
conflict
=
null
;
try
{
try
{
for
(
Table
t
:
getAllTablesAndViews
())
{
for
(
Table
t
:
getAllTablesAndViews
(
false
))
{
conflict
=
t
.
getSQL
();
conflict
=
t
.
getSQL
();
session
.
prepare
(
t
.
getCreateSQL
());
session
.
prepare
(
t
.
getCreateSQL
());
}
}
...
@@ -2327,7 +2345,7 @@ public class Database implements DataHandler {
...
@@ -2327,7 +2345,7 @@ public class Database implements DataHandler {
* @return the table or null if no table is defined
* @return the table or null if no table is defined
*/
*/
public
Table
getFirstUserTable
()
{
public
Table
getFirstUserTable
()
{
for
(
Table
table
:
getAllTablesAndViews
())
{
for
(
Table
table
:
getAllTablesAndViews
(
false
))
{
if
(
table
.
getCreateSQL
()
!=
null
)
{
if
(
table
.
getCreateSQL
()
!=
null
)
{
return
table
;
return
table
;
}
}
...
...
h2/src/main/org/h2/engine/User.java
浏览文件 @
847cf627
...
@@ -64,7 +64,8 @@ public class User extends RightOwner {
...
@@ -64,7 +64,8 @@ public class User extends RightOwner {
*/
*/
public
void
setUserPasswordHash
(
byte
[]
userPasswordHash
)
{
public
void
setUserPasswordHash
(
byte
[]
userPasswordHash
)
{
if
(
userPasswordHash
!=
null
)
{
if
(
userPasswordHash
!=
null
)
{
salt
=
RandomUtils
.
getSecureBytes
(
Constants
.
SALT_LEN
);
salt
=
new
byte
[
Constants
.
SALT_LEN
];
RandomUtils
.
nextBytes
(
salt
);
SHA256
sha
=
new
SHA256
();
SHA256
sha
=
new
SHA256
();
this
.
passwordHash
=
sha
.
getHashWithSalt
(
userPasswordHash
,
salt
);
this
.
passwordHash
=
sha
.
getHashWithSalt
(
userPasswordHash
,
salt
);
}
}
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
847cf627
...
@@ -565,7 +565,7 @@ public class MetaTable extends Table {
...
@@ -565,7 +565,7 @@ public class MetaTable extends Table {
}
}
private
ObjectArray
<
Table
>
getAllTables
(
Session
session
)
{
private
ObjectArray
<
Table
>
getAllTables
(
Session
session
)
{
ObjectArray
<
Table
>
tables
=
database
.
getAllTablesAndViews
();
ObjectArray
<
Table
>
tables
=
database
.
getAllTablesAndViews
(
true
);
ObjectArray
<
Table
>
tempTables
=
session
.
getLocalTempTables
();
ObjectArray
<
Table
>
tempTables
=
session
.
getLocalTempTables
();
tables
.
addAll
(
tempTables
);
tables
.
addAll
(
tempTables
);
return
tables
;
return
tables
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论