Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d261c4f8
提交
d261c4f8
authored
7月 02, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Local temporary tables can now be created without having to commit a transaction.
上级
f2578a29
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
49 行增加
和
11 行删除
+49
-11
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+3
-1
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+10
-6
DefineCommand.java
h2/src/main/org/h2/command/ddl/DefineCommand.java
+10
-4
Table.java
h2/src/main/org/h2/table/Table.java
+4
-0
TestTempTables.java
h2/src/test/org/h2/test/db/TestTempTables.java
+22
-0
没有找到文件。
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
d261c4f8
...
@@ -96,7 +96,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
...
@@ -96,7 +96,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
* @return the update count
* @return the update count
*/
*/
public
int
tryUpdate
()
{
public
int
tryUpdate
()
{
if
(!
transactional
)
{
session
.
commit
(
true
);
session
.
commit
(
true
);
}
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
if
(
getSchema
().
findConstraint
(
session
,
constraintName
)
!=
null
)
{
if
(
getSchema
().
findConstraint
(
session
,
constraintName
)
!=
null
)
{
...
...
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
d261c4f8
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
package
org
.
h2
.
command
.
ddl
;
package
org
.
h2
.
command
.
ddl
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.h2.command.Prepared
;
import
org.h2.command.dml.Insert
;
import
org.h2.command.dml.Insert
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.Query
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
...
@@ -30,7 +29,7 @@ import org.h2.value.DataType;
...
@@ -30,7 +29,7 @@ import org.h2.value.DataType;
public
class
CreateTable
extends
SchemaCommand
{
public
class
CreateTable
extends
SchemaCommand
{
private
CreateTableData
data
=
new
CreateTableData
();
private
CreateTableData
data
=
new
CreateTableData
();
private
ArrayList
<
Prepare
d
>
constraintCommands
=
New
.
arrayList
();
private
ArrayList
<
DefineComman
d
>
constraintCommands
=
New
.
arrayList
();
private
IndexColumn
[]
pkColumns
;
private
IndexColumn
[]
pkColumns
;
private
boolean
ifNotExists
;
private
boolean
ifNotExists
;
private
boolean
onCommitDrop
;
private
boolean
onCommitDrop
;
...
@@ -72,7 +71,7 @@ public class CreateTable extends SchemaCommand {
...
@@ -72,7 +71,7 @@ public class CreateTable extends SchemaCommand {
*
*
* @param command the statement to add
* @param command the statement to add
*/
*/
public
void
addConstraintCommand
(
Prepare
d
command
)
{
public
void
addConstraintCommand
(
DefineComman
d
command
)
{
if
(
command
instanceof
CreateIndex
)
{
if
(
command
instanceof
CreateIndex
)
{
constraintCommands
.
add
(
command
);
constraintCommands
.
add
(
command
);
}
else
{
}
else
{
...
@@ -94,7 +93,9 @@ public class CreateTable extends SchemaCommand {
...
@@ -94,7 +93,9 @@ public class CreateTable extends SchemaCommand {
}
}
public
int
update
()
{
public
int
update
()
{
if
(!
transactional
)
{
session
.
commit
(
true
);
session
.
commit
(
true
);
}
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
if
(!
db
.
isPersistent
())
{
if
(!
db
.
isPersistent
())
{
data
.
persistIndexes
=
false
;
data
.
persistIndexes
=
false
;
...
@@ -156,7 +157,8 @@ public class CreateTable extends SchemaCommand {
...
@@ -156,7 +157,8 @@ public class CreateTable extends SchemaCommand {
for
(
Sequence
sequence
:
sequences
)
{
for
(
Sequence
sequence
:
sequences
)
{
table
.
addSequence
(
sequence
);
table
.
addSequence
(
sequence
);
}
}
for
(
Prepared
command
:
constraintCommands
)
{
for
(
DefineCommand
command
:
constraintCommands
)
{
command
.
setTransactional
(
transactional
);
command
.
update
();
command
.
update
();
}
}
if
(
asQuery
!=
null
)
{
if
(
asQuery
!=
null
)
{
...
@@ -177,7 +179,9 @@ public class CreateTable extends SchemaCommand {
...
@@ -177,7 +179,9 @@ public class CreateTable extends SchemaCommand {
}
catch
(
DbException
e
)
{
}
catch
(
DbException
e
)
{
db
.
checkPowerOff
();
db
.
checkPowerOff
();
db
.
removeSchemaObject
(
session
,
table
);
db
.
removeSchemaObject
(
session
,
table
);
if
(!
transactional
)
{
session
.
commit
(
true
);
session
.
commit
(
true
);
}
throw
e
;
throw
e
;
}
}
return
0
;
return
0
;
...
...
h2/src/main/org/h2/command/ddl/DefineCommand.java
浏览文件 @
d261c4f8
...
@@ -16,6 +16,8 @@ import org.h2.result.ResultInterface;
...
@@ -16,6 +16,8 @@ import org.h2.result.ResultInterface;
*/
*/
public
abstract
class
DefineCommand
extends
Prepared
{
public
abstract
class
DefineCommand
extends
Prepared
{
protected
boolean
transactional
;
/**
/**
* Create a new command for the given session.
* Create a new command for the given session.
*
*
...
@@ -25,10 +27,6 @@ public abstract class DefineCommand extends Prepared {
...
@@ -25,10 +27,6 @@ public abstract class DefineCommand extends Prepared {
super
(
session
);
super
(
session
);
}
}
public
boolean
isTransactional
()
{
return
false
;
}
public
boolean
isReadOnly
()
{
public
boolean
isReadOnly
()
{
return
false
;
return
false
;
}
}
...
@@ -37,4 +35,12 @@ public abstract class DefineCommand extends Prepared {
...
@@ -37,4 +35,12 @@ public abstract class DefineCommand extends Prepared {
return
null
;
return
null
;
}
}
public
void
setTransactional
(
boolean
transactional
)
{
this
.
transactional
=
transactional
;
}
public
boolean
isTransactional
()
{
return
transactional
;
}
}
}
h2/src/main/org/h2/table/Table.java
浏览文件 @
d261c4f8
...
@@ -421,6 +421,10 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -421,6 +421,10 @@ public abstract class Table extends SchemaObjectBase {
}
}
}
}
public
ArrayList
<
TableView
>
getViews
()
{
return
views
;
}
public
void
removeChildrenAndResources
(
Session
session
)
{
public
void
removeChildrenAndResources
(
Session
session
)
{
while
(
views
!=
null
&&
views
.
size
()
>
0
)
{
while
(
views
!=
null
&&
views
.
size
()
>
0
)
{
TableView
view
=
views
.
get
(
0
);
TableView
view
=
views
.
get
(
0
);
...
...
h2/src/test/org/h2/test/db/TestTempTables.java
浏览文件 @
d261c4f8
...
@@ -30,6 +30,7 @@ public class TestTempTables extends TestBase {
...
@@ -30,6 +30,7 @@ public class TestTempTables extends TestBase {
public
void
test
()
throws
SQLException
{
public
void
test
()
throws
SQLException
{
deleteDb
(
"tempTables"
);
deleteDb
(
"tempTables"
);
testTransactionalTemp
();
testDeleteGlobalTempTableWhenClosing
();
testDeleteGlobalTempTableWhenClosing
();
Connection
c1
=
getConnection
(
"tempTables"
);
Connection
c1
=
getConnection
(
"tempTables"
);
testAlter
(
c1
);
testAlter
(
c1
);
...
@@ -42,6 +43,27 @@ public class TestTempTables extends TestBase {
...
@@ -42,6 +43,27 @@ public class TestTempTables extends TestBase {
deleteDb
(
"tempTables"
);
deleteDb
(
"tempTables"
);
}
}
private
void
testTransactionalTemp
()
throws
SQLException
{
deleteDb
(
"tempTables"
);
Connection
conn
=
getConnection
(
"tempTables"
);
conn
.
setAutoCommit
(
false
);
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"insert into test values(1)"
);
stat
.
execute
(
"commit"
);
stat
.
execute
(
"insert into test values(2)"
);
stat
.
execute
(
"create local temporary table temp(id int primary key) transactional"
);
stat
.
execute
(
"insert into temp values(3)"
);
stat
.
execute
(
"rollback"
);
rs
=
stat
.
executeQuery
(
"select * from test"
);
assertTrue
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"drop table temp"
);
conn
.
close
();
}
private
void
testDeleteGlobalTempTableWhenClosing
()
throws
SQLException
{
private
void
testDeleteGlobalTempTableWhenClosing
()
throws
SQLException
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论