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 {
* @return the update count
*/
public
int
tryUpdate
()
{
if
(!
transactional
)
{
session
.
commit
(
true
);
}
Database
db
=
session
.
getDatabase
();
Table
table
=
getSchema
().
getTableOrView
(
session
,
tableName
);
if
(
getSchema
().
findConstraint
(
session
,
constraintName
)
!=
null
)
{
...
...
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
d261c4f8
...
...
@@ -7,7 +7,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.util.ArrayList
;
import
org.h2.command.Prepared
;
import
org.h2.command.dml.Insert
;
import
org.h2.command.dml.Query
;
import
org.h2.constant.ErrorCode
;
...
...
@@ -30,7 +29,7 @@ import org.h2.value.DataType;
public
class
CreateTable
extends
SchemaCommand
{
private
CreateTableData
data
=
new
CreateTableData
();
private
ArrayList
<
Prepare
d
>
constraintCommands
=
New
.
arrayList
();
private
ArrayList
<
DefineComman
d
>
constraintCommands
=
New
.
arrayList
();
private
IndexColumn
[]
pkColumns
;
private
boolean
ifNotExists
;
private
boolean
onCommitDrop
;
...
...
@@ -72,7 +71,7 @@ public class CreateTable extends SchemaCommand {
*
* @param command the statement to add
*/
public
void
addConstraintCommand
(
Prepare
d
command
)
{
public
void
addConstraintCommand
(
DefineComman
d
command
)
{
if
(
command
instanceof
CreateIndex
)
{
constraintCommands
.
add
(
command
);
}
else
{
...
...
@@ -94,7 +93,9 @@ public class CreateTable extends SchemaCommand {
}
public
int
update
()
{
if
(!
transactional
)
{
session
.
commit
(
true
);
}
Database
db
=
session
.
getDatabase
();
if
(!
db
.
isPersistent
())
{
data
.
persistIndexes
=
false
;
...
...
@@ -156,7 +157,8 @@ public class CreateTable extends SchemaCommand {
for
(
Sequence
sequence
:
sequences
)
{
table
.
addSequence
(
sequence
);
}
for
(
Prepared
command
:
constraintCommands
)
{
for
(
DefineCommand
command
:
constraintCommands
)
{
command
.
setTransactional
(
transactional
);
command
.
update
();
}
if
(
asQuery
!=
null
)
{
...
...
@@ -177,7 +179,9 @@ public class CreateTable extends SchemaCommand {
}
catch
(
DbException
e
)
{
db
.
checkPowerOff
();
db
.
removeSchemaObject
(
session
,
table
);
if
(!
transactional
)
{
session
.
commit
(
true
);
}
throw
e
;
}
return
0
;
...
...
h2/src/main/org/h2/command/ddl/DefineCommand.java
浏览文件 @
d261c4f8
...
...
@@ -16,6 +16,8 @@ import org.h2.result.ResultInterface;
*/
public
abstract
class
DefineCommand
extends
Prepared
{
protected
boolean
transactional
;
/**
* Create a new command for the given session.
*
...
...
@@ -25,10 +27,6 @@ public abstract class DefineCommand extends Prepared {
super
(
session
);
}
public
boolean
isTransactional
()
{
return
false
;
}
public
boolean
isReadOnly
()
{
return
false
;
}
...
...
@@ -37,4 +35,12 @@ public abstract class DefineCommand extends Prepared {
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 {
}
}
public
ArrayList
<
TableView
>
getViews
()
{
return
views
;
}
public
void
removeChildrenAndResources
(
Session
session
)
{
while
(
views
!=
null
&&
views
.
size
()
>
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 {
public
void
test
()
throws
SQLException
{
deleteDb
(
"tempTables"
);
testTransactionalTemp
();
testDeleteGlobalTempTableWhenClosing
();
Connection
c1
=
getConnection
(
"tempTables"
);
testAlter
(
c1
);
...
...
@@ -42,6 +43,27 @@ public class TestTempTables extends TestBase {
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
{
if
(
config
.
memory
)
{
return
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论