Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
73c1cc8c
提交
73c1cc8c
authored
17 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
e756cf88
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
290 行增加
和
155 行删除
+290
-155
Parser.java
h2/src/main/org/h2/command/Parser.java
+19
-8
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+88
-15
CreateIndex.java
h2/src/main/org/h2/command/ddl/CreateIndex.java
+6
-31
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+18
-31
DropIndex.java
h2/src/main/org/h2/command/ddl/DropIndex.java
+13
-3
Constants.java
h2/src/main/org/h2/engine/Constants.java
+2
-1
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+5
-6
Schema.java
h2/src/main/org/h2/schema/Schema.java
+32
-8
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+46
-0
IndexColumn.java
h2/src/main/org/h2/table/IndexColumn.java
+0
-1
Table.java
h2/src/main/org/h2/table/Table.java
+1
-1
TableData.java
h2/src/main/org/h2/table/TableData.java
+1
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+17
-9
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+4
-4
TestCases.java
h2/src/test/org/h2/test/db/TestCases.java
+1
-1
TestMetaData.java
h2/src/test/org/h2/test/jdbc/TestMetaData.java
+7
-6
test.in.txt
h2/src/test/org/h2/test/test.in.txt
+30
-29
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
73c1cc8c
...
...
@@ -4174,16 +4174,20 @@ public class Parser {
}
if
(
readIf
(
"PRIMARY"
))
{
read
(
"KEY"
);
CreateIndex
command
=
new
CreateIndex
(
session
,
schema
);
AlterTableAddConstraint
command
=
new
AlterTableAddConstraint
(
session
,
schema
);
command
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
command
.
setComment
(
comment
);
command
.
setConstraintName
(
constraintName
);
command
.
setTableName
(
tableName
);
command
.
setPrimaryKey
(
true
);
if
(
readIf
(
"HASH"
))
{
command
.
setHash
(
true
);
command
.
set
PrimaryKey
Hash
(
true
);
}
read
(
"("
);
command
.
setIndexColumns
(
parseIndexColumnList
());
if
(
readIf
(
"INDEX"
))
{
String
indexName
=
readIdentifierWithSchema
();
command
.
setIndex
(
getSchema
().
findIndex
(
indexName
));
}
return
command
;
}
else
if
(
database
.
getMode
().
indexDefinitionInCreateTable
&&
(
readIf
(
"INDEX"
)
||
readIf
(
"KEY"
)))
{
// MySQL
...
...
@@ -4335,7 +4339,11 @@ public class Parser {
if
(
column
.
getAutoIncrement
())
{
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
cols
[
0
].
columnName
=
column
.
getName
();
command
.
setPrimaryKeyColumns
(
cols
);
AlterTableAddConstraint
pk
=
new
AlterTableAddConstraint
(
session
,
schema
);
pk
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
pk
.
setTableName
(
tableName
);
pk
.
setIndexColumns
(
cols
);
command
.
addConstraintCommand
(
pk
);
}
command
.
addColumn
(
column
);
String
constraintName
=
null
;
...
...
@@ -4344,12 +4352,15 @@ public class Parser {
}
if
(
readIf
(
"PRIMARY"
))
{
read
(
"KEY"
);
if
(
readIf
(
"HASH"
))
{
command
.
setHashPrimaryKey
(
true
);
}
boolean
hash
=
readIf
(
"HASH"
);
IndexColumn
[]
cols
=
new
IndexColumn
[]{
new
IndexColumn
()};
cols
[
0
].
columnName
=
column
.
getName
();
command
.
setPrimaryKeyColumns
(
cols
);
AlterTableAddConstraint
pk
=
new
AlterTableAddConstraint
(
session
,
schema
);
pk
.
setPrimaryKeyHash
(
hash
);
pk
.
setType
(
AlterTableAddConstraint
.
PRIMARY_KEY
);
pk
.
setTableName
(
tableName
);
pk
.
setIndexColumns
(
cols
);
command
.
addConstraintCommand
(
pk
);
}
else
if
(
readIf
(
"UNIQUE"
))
{
AlterTableAddConstraint
unique
=
new
AlterTableAddConstraint
(
session
,
schema
);
unique
.
setConstraintName
(
constraintName
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
73c1cc8c
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
org.h2.constant.ErrorCode
;
...
...
@@ -13,6 +12,7 @@ import org.h2.constraint.Constraint;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintUnique
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Right
;
...
...
@@ -48,6 +48,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
private
Index
index
,
refIndex
;
private
String
comment
;
private
boolean
checkExisting
;
private
boolean
primaryKeyKash
;
public
AlterTableAddConstraint
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
...
...
@@ -61,29 +62,64 @@ public class AlterTableAddConstraint extends SchemaCommand {
}
public
int
update
()
throws
SQLException
{
try
{
return
tryUpdate
();
}
finally
{
getSchema
().
freeUniqueName
(
constraintName
);
}
}
public
int
tryUpdate
()
throws
SQLException
{
session
.
commit
(
true
);
Database
db
=
session
.
getDatabase
();
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
if
(
getSchema
().
findConstraint
(
constraintName
)
!=
null
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
constraintName
);
}
Constraint
constraint
;
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
table
.
lock
(
session
,
true
,
true
);
Constraint
constraint
;
switch
(
type
)
{
case
CHECK:
{
int
id
=
getObjectId
(
true
,
true
);
String
name
=
generateConstraintName
(
table
,
id
);
ConstraintCheck
check
=
new
ConstraintCheck
(
getSchema
(),
id
,
name
,
table
);
TableFilter
filter
=
new
TableFilter
(
session
,
table
,
null
,
false
,
null
);
checkExpression
.
mapColumns
(
filter
,
0
);
checkExpression
=
checkExpression
.
optimize
(
session
);
check
.
setExpression
(
checkExpression
);
check
.
setTableFilter
(
filter
);
constraint
=
check
;
if
(
checkExisting
)
{
check
.
checkExistingData
(
session
);
case
PRIMARY_KEY:
{
IndexColumn
.
mapColumns
(
indexColumns
,
table
);
index
=
table
.
findPrimaryKey
();
ObjectArray
constraints
=
table
.
getConstraints
();
for
(
int
i
=
0
;
constraints
!=
null
&&
i
<
constraints
.
size
();
i
++)
{
Constraint
c
=
(
Constraint
)
constraints
.
get
(
i
);
if
(
Constraint
.
PRIMARY_KEY
.
equals
(
c
.
getConstraintType
()))
{
throw
Message
.
getSQLException
(
ErrorCode
.
SECOND_PRIMARY_KEY
);
}
}
if
(
index
!=
null
)
{
// if there is an index, it must match with the one declared
// we don't test ascending / descending
IndexColumn
[]
pkCols
=
index
.
getIndexColumns
();
if
(
pkCols
.
length
!=
indexColumns
.
length
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
SECOND_PRIMARY_KEY
);
}
for
(
int
i
=
0
;
i
<
pkCols
.
length
;
i
++)
{
if
(
pkCols
[
i
].
column
!=
indexColumns
[
i
].
column
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
SECOND_PRIMARY_KEY
);
}
}
}
if
(
index
==
null
)
{
IndexType
indexType
=
IndexType
.
createPrimaryKey
(
table
.
isPersistent
(),
primaryKeyKash
);
String
indexName
=
getSchema
().
getUniqueIndexName
(
table
,
Constants
.
PREFIX_PRIMARY_KEY
);
int
id
=
getObjectId
(
true
,
false
);
try
{
index
=
table
.
addIndex
(
session
,
indexName
,
id
,
indexColumns
,
indexType
,
Index
.
EMPTY_HEAD
,
null
);
}
finally
{
getSchema
().
freeUniqueName
(
indexName
);
}
}
index
.
getIndexType
().
setBelongsToConstraint
(
true
);
int
constraintId
=
getObjectId
(
true
,
true
);
String
name
=
generateConstraintName
(
table
,
constraintId
);
ConstraintUnique
pk
=
new
ConstraintUnique
(
getSchema
(),
constraintId
,
name
,
table
,
true
);
pk
.
setColumns
(
indexColumns
);
pk
.
setIndex
(
index
,
true
);
constraint
=
pk
;
break
;
}
case
UNIQUE:
{
...
...
@@ -107,6 +143,21 @@ public class AlterTableAddConstraint extends SchemaCommand {
constraint
=
unique
;
break
;
}
case
CHECK:
{
int
id
=
getObjectId
(
true
,
true
);
String
name
=
generateConstraintName
(
table
,
id
);
ConstraintCheck
check
=
new
ConstraintCheck
(
getSchema
(),
id
,
name
,
table
);
TableFilter
filter
=
new
TableFilter
(
session
,
table
,
null
,
false
,
null
);
checkExpression
.
mapColumns
(
filter
,
0
);
checkExpression
=
checkExpression
.
optimize
(
session
);
check
.
setExpression
(
checkExpression
);
check
.
setTableFilter
(
filter
);
constraint
=
check
;
if
(
checkExisting
)
{
check
.
checkExistingData
(
session
);
}
break
;
}
case
REFERENTIAL:
{
Table
refTable
=
refSchema
.
getTableOrView
(
session
,
refTableName
);
session
.
getUser
().
checkRight
(
refTable
,
Right
.
ALL
);
...
...
@@ -187,7 +238,13 @@ public class AlterTableAddConstraint extends SchemaCommand {
indexType
.
setBelongsToConstraint
(
true
);
String
prefix
=
constraintName
==
null
?
"CONSTRAINT"
:
constraintName
;
String
indexName
=
getSchema
().
getUniqueIndexName
(
t
,
prefix
+
"_INDEX_"
);
return
t
.
addIndex
(
session
,
indexName
,
indexId
,
cols
,
indexType
,
Index
.
EMPTY_HEAD
,
null
);
Index
idx
;
try
{
idx
=
t
.
addIndex
(
session
,
indexName
,
indexId
,
cols
,
indexType
,
Index
.
EMPTY_HEAD
,
null
);
}
finally
{
getSchema
().
freeUniqueName
(
indexName
);
}
return
idx
;
}
public
void
setDeleteAction
(
int
action
)
{
...
...
@@ -282,6 +339,10 @@ public class AlterTableAddConstraint extends SchemaCommand {
this
.
type
=
type
;
}
public
int
getType
()
{
return
type
;
}
public
void
setCheckExpression
(
Expression
expression
)
{
this
.
checkExpression
=
expression
;
}
...
...
@@ -294,6 +355,10 @@ public class AlterTableAddConstraint extends SchemaCommand {
this
.
indexColumns
=
indexColumns
;
}
public
IndexColumn
[]
getIndexColumns
()
{
return
indexColumns
;
}
public
void
setRefTableName
(
Schema
refSchema
,
String
ref
)
{
this
.
refSchema
=
refSchema
;
this
.
refTableName
=
ref
;
...
...
@@ -319,4 +384,12 @@ public class AlterTableAddConstraint extends SchemaCommand {
this
.
checkExisting
=
b
;
}
public
void
setPrimaryKeyHash
(
boolean
b
)
{
this
.
primaryKeyKash
=
b
;
}
public
boolean
getPrimaryKeyHash
()
{
return
primaryKeyKash
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/CreateIndex.java
浏览文件 @
73c1cc8c
...
...
@@ -7,12 +7,10 @@ package org.h2.command.ddl;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.
constraint.ConstraintUnique
;
import
org.h2.
engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
import
org.h2.message.Message
;
import
org.h2.schema.Schema
;
...
...
@@ -31,7 +29,6 @@ public class CreateIndex extends SchemaCommand {
private
boolean
primaryKey
,
unique
,
hash
;
private
boolean
ifNotExists
;
private
String
comment
;
private
String
constraintName
;
public
CreateIndex
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
...
...
@@ -61,13 +58,6 @@ public class CreateIndex extends SchemaCommand {
return
indexColumns
;
}
private
String
generateConstraintName
(
DbObject
obj
,
int
id
)
throws
SQLException
{
if
(
constraintName
==
null
)
{
constraintName
=
getSchema
().
getUniqueConstraintName
(
obj
);
}
return
constraintName
;
}
public
int
update
()
throws
SQLException
{
// TODO cancel: may support for index creation
session
.
commit
(
true
);
...
...
@@ -80,8 +70,10 @@ public class CreateIndex extends SchemaCommand {
persistent
=
false
;
}
int
id
=
getObjectId
(
true
,
false
);
if
(
indexName
==
null
)
{
indexName
=
getSchema
().
getUniqueIndexName
(
table
,
"INDEX_"
);
if
(
primaryKey
)
{
indexName
=
getSchema
().
getUniqueIndexName
(
table
,
Constants
.
PREFIX_PRIMARY_KEY
);
}
else
if
(
indexName
==
null
)
{
indexName
=
getSchema
().
getUniqueIndexName
(
table
,
Constants
.
PREFIX_INDEX
);
}
if
(
getSchema
().
findIndex
(
indexName
)
!=
null
)
{
if
(
ifNotExists
)
{
...
...
@@ -101,20 +93,7 @@ public class CreateIndex extends SchemaCommand {
indexType
=
IndexType
.
createNonUnique
(
persistent
);
}
IndexColumn
.
mapColumns
(
indexColumns
,
table
);
Index
index
=
table
.
addIndex
(
session
,
indexName
,
id
,
indexColumns
,
indexType
,
headPos
,
comment
);
int
todo
;
// if (primaryKey) {
// // TODO this code is a copy of CreateTable (primaryKey creation)
// // for primary keys, create a constraint as well
// String name = generateConstraintName(table, id);
// int constraintId = getObjectId(true, true);
// ConstraintUnique pk = new ConstraintUnique(getSchema(), constraintId, name, table, true);
// pk.setColumns(index.getIndexColumns());
// pk.setIndex(index, true);
// pk.setComment(comment);
// db.addSchemaObject(session, pk);
// table.addConstraint(pk);
// }
table
.
addIndex
(
session
,
indexName
,
id
,
indexColumns
,
indexType
,
headPos
,
comment
);
return
0
;
}
...
...
@@ -138,8 +117,4 @@ public class CreateIndex extends SchemaCommand {
this
.
comment
=
comment
;
}
public
void
setConstraintName
(
String
constraintName
)
{
this
.
constraintName
=
constraintName
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
73c1cc8c
...
...
@@ -10,12 +10,9 @@ import org.h2.command.Prepared;
import
org.h2.command.dml.Insert
;
import
org.h2.command.dml.Query
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constraint.ConstraintUnique
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
import
org.h2.message.Message
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Sequence
;
...
...
@@ -37,7 +34,6 @@ public class CreateTable extends SchemaCommand {
private
IndexColumn
[]
pkColumns
;
private
boolean
ifNotExists
;
private
boolean
persistent
=
true
;
private
boolean
hashPrimaryKey
;
private
boolean
temporary
;
private
boolean
globalTemporary
;
private
boolean
onCommitDrop
;
...
...
@@ -68,15 +64,18 @@ public class CreateTable extends SchemaCommand {
public
void
addConstraintCommand
(
Prepared
command
)
throws
SQLException
{
if
(
command
instanceof
CreateIndex
)
{
CreateIndex
create
=
(
CreateIndex
)
command
;
if
(
create
.
getPrimaryKey
())
{
setPrimaryKeyColumns
(
create
.
getIndexColumns
());
setHashPrimaryKey
(
create
.
getHash
());
constraintCommands
.
add
(
command
);
}
else
{
AlterTableAddConstraint
con
=
(
AlterTableAddConstraint
)
command
;
boolean
alreadySet
;
if
(
con
.
getType
()
==
AlterTableAddConstraint
.
PRIMARY_KEY
)
{
alreadySet
=
setPrimaryKeyColumns
(
con
.
getIndexColumns
());
}
else
{
alreadySet
=
false
;
}
if
(!
alreadySet
)
{
constraintCommands
.
add
(
command
);
}
}
else
{
constraintCommands
.
add
(
command
);
}
}
...
...
@@ -144,22 +143,6 @@ public class CreateTable extends SchemaCommand {
Column
c
=
(
Column
)
columns
.
get
(
i
);
c
.
prepareExpression
(
session
);
}
if
(
pkColumns
!=
null
)
{
IndexColumn
.
mapColumns
(
pkColumns
,
table
);
int
indexId
=
getObjectId
(
true
,
false
);
Index
index
=
table
.
addIndex
(
session
,
null
,
indexId
,
pkColumns
,
IndexType
.
createPrimaryKey
(
persistent
,
hashPrimaryKey
),
Index
.
EMPTY_HEAD
,
null
);
// TODO this code is a copy of CreateIndex (if primaryKey)
int
todo
;
// String name = getSchema().getUniqueConstraintName(table);
// int constraintId = getObjectId(true, true);
// ConstraintUnique pk = new ConstraintUnique(getSchema(), constraintId, name, table, true);
// pk.setColumns(index.getIndexColumns());
// pk.setIndex(index, true);
// pk.setComment(comment);
// db.addSchemaObject(session, pk);
// table.addConstraint(pk);
}
for
(
int
i
=
0
;
i
<
sequences
.
size
();
i
++)
{
Sequence
sequence
=
(
Sequence
)
sequences
.
get
(
i
);
table
.
addSequence
(
sequence
);
...
...
@@ -214,7 +197,13 @@ public class CreateTable extends SchemaCommand {
}
}
public
void
setPrimaryKeyColumns
(
IndexColumn
[]
columns
)
throws
SQLException
{
/**
* Sets the primary key columns, but also check if an primary key with different columns is already defined.
*
* @param columns the primary key columns
* @return true if the same primary key columns where already set
*/
private
boolean
setPrimaryKeyColumns
(
IndexColumn
[]
columns
)
throws
SQLException
{
if
(
pkColumns
!=
null
)
{
if
(
columns
.
length
!=
pkColumns
.
length
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
SECOND_PRIMARY_KEY
);
...
...
@@ -224,18 +213,16 @@ public class CreateTable extends SchemaCommand {
throw
Message
.
getSQLException
(
ErrorCode
.
SECOND_PRIMARY_KEY
);
}
}
return
true
;
}
this
.
pkColumns
=
columns
;
return
false
;
}
public
void
setPersistent
(
boolean
persistent
)
{
this
.
persistent
=
persistent
;
}
public
void
setHashPrimaryKey
(
boolean
b
)
{
this
.
hashPrimaryKey
=
b
;
}
public
void
setGlobalTemporary
(
boolean
globalTemporary
)
{
this
.
globalTemporary
=
globalTemporary
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/DropIndex.java
浏览文件 @
73c1cc8c
...
...
@@ -47,16 +47,26 @@ public class DropIndex extends SchemaCommand {
}
}
else
{
Table
table
=
index
.
getTable
();
session
.
getUser
().
checkRight
(
index
.
getTable
(),
Right
.
ALL
);
Constraint
pkConstraint
=
null
;
ObjectArray
constraints
=
table
.
getConstraints
();
for
(
int
i
=
0
;
constraints
!=
null
&&
i
<
constraints
.
size
();
i
++)
{
Constraint
cons
=
(
Constraint
)
constraints
.
get
(
i
);
if
(
cons
.
usesIndex
(
index
))
{
throw
Message
.
getSQLException
(
ErrorCode
.
INDEX_BELONGS_TO_CONSTRAINT_1
,
indexName
);
// can drop primary key index (for compatibility)
if
(
Constraint
.
PRIMARY_KEY
.
equals
(
cons
.
getConstraintType
()))
{
pkConstraint
=
cons
;
}
else
{
throw
Message
.
getSQLException
(
ErrorCode
.
INDEX_BELONGS_TO_CONSTRAINT_1
,
indexName
);
}
}
}
session
.
getUser
().
checkRight
(
index
.
getTable
(),
Right
.
ALL
);
index
.
getTable
().
setModified
();
db
.
removeSchemaObject
(
session
,
index
);
if
(
pkConstraint
!=
null
)
{
db
.
removeSchemaObject
(
session
,
pkConstraint
);
}
else
{
db
.
removeSchemaObject
(
session
,
index
);
}
}
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
73c1cc8c
...
...
@@ -116,7 +116,8 @@ public class Constants {
public
static
final
int
DEFAULT_MAX_LENGTH_CLIENTSIDE_LOB
=
65536
;
public
static
final
int
SALT_LEN
=
8
;
public
static
final
int
DEFAULT_DATA_PAGE_SIZE
=
512
;
public
static
final
String
PRIMARY_KEY_PREFIX
=
"PRIMARY_KEY_"
;
public
static
final
String
PREFIX_PRIMARY_KEY
=
"PRIMARY_KEY_"
;
public
static
final
String
PREFIX_INDEX
=
"INDEX_"
;
public
static
final
int
LOCK_SLEEP
=
1000
;
// TODO for testing, the lock timeout is smaller than for interactive use cases
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
73c1cc8c
...
...
@@ -2644,7 +2644,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
//#ifdef JDK16
/*
public <T> T unwrap(Class<T> iface) throws SQLException {
debugCodeCall("unwrap");
debugCodeCall("unwrap");
throw Message.getUnsupportedException();
}
*/
...
...
@@ -2656,7 +2656,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
//#ifdef JDK16
/*
public boolean isWrapperFor(Class< ? > iface) throws SQLException {
debugCodeCall("isWrapperFor");
debugCodeCall("isWrapperFor");
throw Message.getUnsupportedException();
}
*/
...
...
@@ -2666,7 +2666,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* [Not supported] Gets the list of function columns.
*/
public
ResultSet
getFunctionColumns
(
String
catalog
,
String
schemaPattern
,
String
functionNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
debugCodeCall
(
"getFunctionColumns"
);
debugCodeCall
(
"getFunctionColumns"
);
throw
Message
.
getUnsupportedException
();
}
...
...
@@ -2674,10 +2674,10 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* [Not supported] Gets the list of functions.
*/
public
ResultSet
getFunctions
(
String
arg0
,
String
arg1
,
String
arg2
)
throws
SQLException
{
debugCodeCall
(
"getFunctions"
);
debugCodeCall
(
"getFunctions"
);
throw
Message
.
getUnsupportedException
();
}
/**
* INTERNAL
*/
...
...
@@ -2686,4 +2686,3 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
73c1cc8c
...
...
@@ -6,6 +6,7 @@ package org.h2.schema;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
...
...
@@ -40,6 +41,13 @@ public class Schema extends DbObjectBase {
private
HashMap
constraints
=
new
HashMap
();
private
HashMap
constants
=
new
HashMap
();
/*
* Set of returned unique names that are not yet stored
* (to avoid returning the same unique name twice when multiple threads
* concurrently create objects).
*/
private
HashSet
temporaryUniqueNames
=
new
HashSet
();
public
Schema
(
Database
database
,
int
id
,
String
schemaName
,
User
owner
,
boolean
system
)
{
super
(
database
,
id
,
schemaName
,
Trace
.
SCHEMA
);
this
.
owner
=
owner
;
...
...
@@ -139,6 +147,7 @@ public class Schema extends DbObjectBase {
throw
Message
.
getInternalError
(
"object already exists"
);
}
map
.
put
(
name
,
obj
);
freeUniqueName
(
name
);
}
public
void
rename
(
SchemaObject
obj
,
String
newName
)
throws
SQLException
{
...
...
@@ -153,8 +162,10 @@ public class Schema extends DbObjectBase {
}
}
map
.
remove
(
obj
.
getName
());
freeUniqueName
(
obj
.
getName
());
obj
.
rename
(
newName
);
map
.
put
(
newName
,
obj
);
freeUniqueName
(
newName
);
}
public
Table
findTableOrView
(
Session
session
,
String
name
)
{
...
...
@@ -185,21 +196,33 @@ public class Schema extends DbObjectBase {
return
(
Constant
)
constants
.
get
(
constantName
);
}
public
void
freeUniqueName
(
String
name
)
{
if
(
name
!=
null
)
{
temporaryUniqueNames
.
remove
(
name
);
}
}
private
String
getUniqueName
(
DbObject
obj
,
HashMap
map
,
String
prefix
)
{
String
hash
=
Integer
.
toHexString
(
obj
.
getName
().
hashCode
()).
toUpperCase
();
String
name
=
null
;
for
(
int
i
=
1
;
i
<
hash
.
length
();
i
++)
{
String
name
=
prefix
+
hash
.
substring
(
0
,
i
);
if
(
map
.
get
(
name
)
==
null
)
{
return
name
;
name
=
prefix
+
hash
.
substring
(
0
,
i
);
if
(
!
map
.
containsKey
(
name
)
&&
!
temporaryUniqueNames
.
contains
(
name
)
)
{
break
;
}
name
=
null
;
}
prefix
=
prefix
+
hash
+
"_"
;
for
(
int
i
=
0
;;
i
++)
{
String
name
=
prefix
+
i
;
if
(
map
.
get
(
name
)
==
null
)
{
return
name
;
if
(
name
==
null
)
{
prefix
=
prefix
+
hash
+
"_"
;
for
(
int
i
=
0
;;
i
++)
{
name
=
prefix
+
i
;
if
(!
map
.
containsKey
(
name
)
&&
!
temporaryUniqueNames
.
contains
(
name
))
{
break
;
}
}
}
temporaryUniqueNames
.
add
(
name
);
return
name
;
}
public
String
getUniqueConstraintName
(
DbObject
obj
)
{
...
...
@@ -265,6 +288,7 @@ public class Schema extends DbObjectBase {
throw
Message
.
getInternalError
(
"not found: "
+
objName
);
}
map
.
remove
(
objName
);
freeUniqueName
(
objName
);
}
public
TableData
createTable
(
String
tempName
,
int
id
,
ObjectArray
newColumns
,
boolean
persistent
,
boolean
clustered
)
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
73c1cc8c
...
...
@@ -819,6 +819,9 @@ class WebThread extends Thread implements DatabaseEventListener {
e
.
printStackTrace
(
new
PrintWriter
(
writer
));
String
stackTrace
=
writer
.
toString
();
stackTrace
=
PageParser
.
escapeHtml
(
stackTrace
);
if
(
isH2
)
{
stackTrace
=
linkToSource
(
stackTrace
);
}
stackTrace
=
StringUtils
.
replaceAll
(
stackTrace
,
"\t"
,
" "
);
String
message
=
PageParser
.
escapeHtml
(
e
.
getMessage
());
String
error
=
"<a class=\"error\" href=\"#\" onclick=\"var x=document.getElementById('st"
+
id
...
...
@@ -837,6 +840,49 @@ class WebThread extends Thread implements DatabaseEventListener {
}
}
private
String
linkToSource
(
String
s
)
{
try
{
StringBuffer
result
=
new
StringBuffer
(
s
.
length
());
int
idx
=
s
.
indexOf
(
"<br />"
);
result
.
append
(
s
.
substring
(
0
,
idx
));
while
(
true
)
{
int
start
=
s
.
indexOf
(
"org.h2."
,
idx
);
if
(
start
<
0
)
{
result
.
append
(
s
.
substring
(
idx
));
break
;
}
result
.
append
(
s
.
substring
(
idx
,
start
));
int
end
=
s
.
indexOf
(
')'
,
start
);
if
(
end
<
0
)
{
result
.
append
(
s
.
substring
(
idx
));
break
;
}
String
element
=
s
.
substring
(
start
,
end
);
int
open
=
element
.
lastIndexOf
(
'('
);
int
dotMethod
=
element
.
lastIndexOf
(
'.'
,
open
-
1
);
int
dotClass
=
element
.
lastIndexOf
(
'.'
,
dotMethod
-
1
);
String
packageName
=
element
.
substring
(
0
,
dotClass
);
int
colon
=
element
.
lastIndexOf
(
':'
);
String
file
=
element
.
substring
(
open
+
1
,
colon
);
String
lineNumber
=
element
.
substring
(
colon
+
1
,
element
.
length
());
String
fullFileName
=
packageName
.
replace
(
'.'
,
'/'
)
+
"/"
+
file
;
result
.
append
(
"<a href=\"http://h2database.com/html/source.html?file="
);
result
.
append
(
fullFileName
);
result
.
append
(
"&line="
);
result
.
append
(
lineNumber
);
result
.
append
(
"&build="
);
result
.
append
(
Constants
.
BUILD_ID
);
result
.
append
(
"\">"
);
result
.
append
(
element
);
result
.
append
(
"</a>"
);
idx
=
end
;
}
return
result
.
toString
();
}
catch
(
Throwable
t
)
{
return
s
;
}
}
private
String
formatAsError
(
String
s
)
{
return
"<div class=\"error\">"
+
s
+
"</div>"
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/IndexColumn.java
浏览文件 @
73c1cc8c
...
...
@@ -31,7 +31,6 @@ public class IndexColumn {
}
public
static
IndexColumn
[]
wrap
(
Column
[]
columns
)
{
int
testDelete_
;
IndexColumn
[]
list
=
new
IndexColumn
[
columns
.
length
];
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
list
[
i
]
=
new
IndexColumn
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Table.java
浏览文件 @
73c1cc8c
...
...
@@ -447,7 +447,7 @@ public abstract class Table extends SchemaObjectBase {
if
(
index
!=
null
)
{
return
index
;
}
throw
Message
.
getSQLException
(
ErrorCode
.
INDEX_NOT_FOUND_1
,
Constants
.
PR
IMARY_KEY_PREFIX
);
throw
Message
.
getSQLException
(
ErrorCode
.
INDEX_NOT_FOUND_1
,
Constants
.
PR
EFIX_PRIMARY_KEY
);
}
public
void
validateConvertUpdateSequence
(
Session
session
,
Row
row
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableData.java
浏览文件 @
73c1cc8c
...
...
@@ -151,7 +151,6 @@ public class TableData extends Table implements RecordReader {
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
int
headPos
,
String
indexComment
)
throws
SQLException
{
if
(
indexType
.
isPrimaryKey
())
{
indexName
=
getSchema
().
getUniqueIndexName
(
this
,
Constants
.
PRIMARY_KEY_PREFIX
);
for
(
int
i
=
0
;
i
<
cols
.
length
;
i
++)
{
Column
column
=
cols
[
i
].
column
;
if
(
column
.
getNullable
())
{
...
...
@@ -202,6 +201,7 @@ public class TableData extends Table implements RecordReader {
throw
Message
.
getInternalError
(
"rowcount remaining="
+
remaining
+
" "
+
getName
());
}
}
catch
(
SQLException
e
)
{
getSchema
().
freeUniqueName
(
indexName
);
try
{
index
.
remove
(
session
);
}
catch
(
SQLException
e2
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
73c1cc8c
...
...
@@ -151,17 +151,23 @@ java org.h2.test.TestAll timer
/*
create table bla (id integer not null);
alter table bla add constraint pk primary key (id);
-- doesn't create a constraint!
alter table bla drop constraint pk;
alter table bla drop primary key;
drop table bla;
-- PostgreSQL, Derby, HSQLDB: works
-- MySQL: does not work
implement max_query_time and use it for TestCrashAPI
Value too long for column DESC. But which value?
org.h2.jdbc.JdbcSQLException: Value too long for column DESC
[90005-64]
at org.h2.message.Message.getSQLException(Message.java:89)
at org.h2.message.Message.getSQLException(Message.java:93)
at org.h2.message.Message.getSQLException(Message.java:71)
at org.h2.table.Column.validateConvertUpdateSequence(Column.java:226)
at org.h2.table.Table.validateConvertUpdateSequence(Table.java:331)
at org.h2.command.dml.Insert.update(Insert.java:111)
at org.h2.command.CommandContainer.update(CommandContainer.java:68)
CREATE {[UNIQUE [HASH]] INDEX [[IF NOT EXISTS] newIndexName]
| PRIMARY KEY [HASH]} ON (columnName [,...])
There is missing name of table
adjust cache memory usage
simple pure java config file (interpreted)
...
...
@@ -182,6 +188,8 @@ Roadmap:
Move Maven 2 repository from hsql.sf.net to h2database.sf.net
History:
Primary keys are now considered constraints and can have a constraint name.
H2 Console: stack traces are now links to the source code in the source repository (H2 database only)
Test Recovery with MAX_LOG_FILE_SIZE=1; test with various log file sizes
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
73c1cc8c
...
...
@@ -318,10 +318,10 @@ public abstract class TestBase {
error
(
"a: "
+
a
+
" is not smaller than b: "
+
b
);
}
}
protected
void
checkContains
(
String
result
,
String
contains
)
throws
Exception
{
if
(
result
.
indexOf
(
contains
)
<
0
)
{
error
(
result
+
" does not contain: "
+
contains
);
protected
void
checkContains
(
String
result
,
String
contains
)
throws
Exception
{
if
(
result
.
indexOf
(
contains
)
<
0
)
{
error
(
result
+
" does not contain: "
+
contains
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCases.java
浏览文件 @
73c1cc8c
...
...
@@ -495,7 +495,7 @@ public class TestCases extends TestBase {
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST_SEQ(ID INT IDENTITY, NAME VARCHAR(255))"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY)"
);
conn
.
createStatement
().
execute
(
"ALTER TABLE TEST RENAME TO TEST2"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME VARCHAR, UNIQUE(NAME))
;
"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME VARCHAR, UNIQUE(NAME))"
);
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST_SEQ(NAME) VALUES('Hi')"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
73c1cc8c
...
...
@@ -743,21 +743,21 @@ public class TestMetaData extends TestBase {
* null,
* null
*/
},
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"TX2"
,
"FALSE"
,
catalog
,
"PRIMARY_KEY_14
6
"
,
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"TX2"
,
"FALSE"
,
catalog
,
"PRIMARY_KEY_14"
,
""
+
DatabaseMetaData
.
tableIndexOther
,
"1"
,
"C"
,
"A"
/*
* ,
* null,
* null,
* null
*/
},
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"TX2"
,
"FALSE"
,
catalog
,
"PRIMARY_KEY_14
6
"
,
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"TX2"
,
"FALSE"
,
catalog
,
"PRIMARY_KEY_14"
,
""
+
DatabaseMetaData
.
tableIndexOther
,
"2"
,
"A"
,
"A"
/*
* ,
* null,
* null,
* null
*/
},
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"TX2"
,
"FALSE"
,
catalog
,
"PRIMARY_KEY_14
6
"
,
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"TX2"
,
"FALSE"
,
catalog
,
"PRIMARY_KEY_14"
,
""
+
DatabaseMetaData
.
tableIndexOther
,
"3"
,
"B"
,
"A"
/*
* ,
* null,
...
...
@@ -787,9 +787,10 @@ public class TestMetaData extends TestBase {
*/
},
});
trace
(
"getPrimaryKeys"
);
rs
=
meta
.
getPrimaryKeys
(
null
,
null
,
"T_2"
);
testResultSetOrdered
(
rs
,
new
String
[][]
{
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"T_2"
,
"A"
,
"2"
,
"PRIMARY_KEY_14"
},
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"T_2"
,
"B"
,
"3"
,
"PRIMARY_KEY_14"
},
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"T_2"
,
"C"
,
"1"
,
"PRIMARY_KEY_14"
},
});
testResultSetOrdered
(
rs
,
new
String
[][]
{
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"T_2"
,
"A"
,
"2"
,
"PRIMARY_KEY_1"
},
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"T_2"
,
"B"
,
"3"
,
"PRIMARY_KEY_1"
},
{
catalog
,
Constants
.
SCHEMA_MAIN
,
"T_2"
,
"C"
,
"1"
,
"PRIMARY_KEY_1"
},
});
stat
.
executeUpdate
(
"DROP TABLE TX2"
);
stat
.
executeUpdate
(
"DROP TABLE T_2"
);
stat
.
executeUpdate
(
"CREATE TABLE PARENT(ID INT PRIMARY KEY)"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/test.in.txt
浏览文件 @
73c1cc8c
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论