Skip to content

Commit 0899043

Browse files
committed
Merge branch 'NH-3588'
2 parents cb2e260 + 941e733 commit 0899043

File tree

4 files changed

+93
-16
lines changed

4 files changed

+93
-16
lines changed

src/NHibernate/Dialect/FirebirdDialect.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,30 @@ public override SqlString GetLimitString(SqlString queryString, SqlString offset
128128
return queryString.Insert(insertIndex, limitFragment.ToSqlString());
129129
}
130130

131+
#region Temporaray Table Support
132+
133+
public override bool SupportsTemporaryTables
134+
{
135+
get { return true; }
136+
}
137+
138+
public override string CreateTemporaryTableString
139+
{
140+
get { return "create global temporary table"; }
141+
}
142+
143+
public override bool? PerformTemporaryTableDDLInIsolation()
144+
{
145+
return true;
146+
}
147+
148+
public override bool DropTemporaryTableAfterUse()
149+
{
150+
return true;
151+
}
152+
153+
#endregion
154+
131155
private static int GetAfterSelectInsertPoint(SqlString text)
132156
{
133157
if (text.StartsWithCaseInsensitive("select"))

src/NHibernate/Hql/Ast/ANTLR/Exec/AbstractStatementExecutor.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
using System;
22
using System.Data;
3+
using Antlr.Runtime;
34
using Antlr.Runtime.Tree;
45
using NHibernate.Action;
6+
using NHibernate.AdoNet.Util;
57
using NHibernate.Engine;
68
using NHibernate.Engine.Transaction;
79
using NHibernate.Event;
810
using NHibernate.Hql.Ast.ANTLR.Tree;
911
using NHibernate.Persister.Entity;
1012
using NHibernate.SqlCommand;
11-
12-
using Antlr.Runtime;
1313
using NHibernate.SqlTypes;
14+
using NHibernate.Transaction;
1415
using NHibernate.Util;
15-
using NHibernate.AdoNet.Util;
1616

1717
namespace NHibernate.Hql.Ast.ANTLR.Exec
1818
{
@@ -142,8 +142,11 @@ protected virtual void CreateTemporaryTableIfNecessary(IQueryable persister, ISe
142142
}
143143
else
144144
{
145-
work.DoWork(session.ConnectionManager.GetConnection(), null);
146-
session.ConnectionManager.AfterStatement();
145+
using (var dummyCommand = session.ConnectionManager.CreateCommand())
146+
{
147+
work.DoWork(dummyCommand.Connection, dummyCommand.Transaction);
148+
session.ConnectionManager.AfterStatement();
149+
}
147150
}
148151
}
149152

@@ -165,19 +168,25 @@ protected virtual void DropTemporaryTableIfNecessary(IQueryable persister, ISess
165168

166169
if (ShouldIsolateTemporaryTableDDL())
167170
{
168-
if (Factory.Settings.IsDataDefinitionInTransactionSupported)
169-
{
170-
Isolater.DoIsolatedWork(work, session);
171-
}
172-
else
171+
session.ConnectionManager.Transaction.RegisterSynchronization(new AfterTransactionCompletes((success) =>
173172
{
174-
Isolater.DoNonTransactedWork(work, session);
175-
}
173+
if (Factory.Settings.IsDataDefinitionInTransactionSupported)
174+
{
175+
Isolater.DoIsolatedWork(work, session);
176+
}
177+
else
178+
{
179+
Isolater.DoNonTransactedWork(work, session);
180+
}
181+
}));
176182
}
177183
else
178184
{
179-
work.DoWork(session.ConnectionManager.GetConnection(), null);
180-
session.ConnectionManager.AfterStatement();
185+
using (var dummyCommand = session.ConnectionManager.CreateCommand())
186+
{
187+
work.DoWork(dummyCommand.Connection, dummyCommand.Transaction);
188+
session.ConnectionManager.AfterStatement();
189+
}
181190
}
182191
}
183192
else
@@ -229,7 +238,8 @@ public void DoWork(IDbConnection connection, IDbTransaction transaction)
229238
IDbCommand stmnt = null;
230239
try
231240
{
232-
stmnt = session.ConnectionManager.CreateCommand();
241+
stmnt = connection.CreateCommand();
242+
stmnt.Transaction = transaction;
233243
stmnt.CommandText = persister.TemporaryIdTableDDL;
234244
stmnt.ExecuteNonQuery();
235245
session.Factory.Settings.SqlStatementLogger.LogCommand(stmnt, FormatStyle.Ddl);
@@ -273,7 +283,8 @@ public void DoWork(IDbConnection connection, IDbTransaction transaction)
273283
IDbCommand stmnt = null;
274284
try
275285
{
276-
stmnt = session.ConnectionManager.CreateCommand();
286+
stmnt = connection.CreateCommand();
287+
stmnt.Transaction = transaction;
277288
stmnt.CommandText = "drop table " + persister.TemporaryIdTableName;
278289
stmnt.ExecuteNonQuery();
279290
session.Factory.Settings.SqlStatementLogger.LogCommand(stmnt, FormatStyle.Ddl);

src/NHibernate/NHibernate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@
643643
<Compile Include="TransactionException.cs" />
644644
<Compile Include="Transaction\AdoNetWithDistributedTransactionFactory.cs" />
645645
<Compile Include="Transaction\AdoTransaction.cs" />
646+
<Compile Include="Transaction\AfterTransactionCompletes.cs" />
646647
<Compile Include="Transaction\ITransactionFactory.cs" />
647648
<Compile Include="Transform\AliasToEntityMapResultTransformer.cs" />
648649
<Compile Include="Transform\DistinctRootEntityResultTransformer.cs" />
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
3+
namespace NHibernate.Transaction
4+
{
5+
public class AfterTransactionCompletes : ISynchronization
6+
{
7+
#region Fields
8+
9+
private readonly Action<bool> _whenCompleted;
10+
11+
#endregion
12+
13+
#region Constructors/Destructors
14+
15+
/// <summary>
16+
/// Create an AfterTransactionCompletes that will execute the given delegate
17+
/// when the transaction is completed. The action delegate will receive
18+
/// the value 'true' if the transaction was completed successfully.
19+
/// </summary>
20+
/// <param name="whenCompleted"></param>
21+
public AfterTransactionCompletes(Action<bool> whenCompleted)
22+
{
23+
_whenCompleted = whenCompleted;
24+
}
25+
26+
#endregion
27+
28+
#region ISynchronization Members
29+
30+
public void BeforeCompletion()
31+
{
32+
}
33+
34+
public void AfterCompletion(bool success)
35+
{
36+
_whenCompleted(success);
37+
}
38+
39+
#endregion
40+
}
41+
}

0 commit comments

Comments
 (0)