Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added transaction handling and corrected DateTime quoting format string for Jet #320

Closed
wants to merge 4 commits into from

3 participants

@dabide

Added transaction handling to Jet (the mdb file was locked after running the migrations the way it was, because the connection was never closed). Also added a finally { ... } clause to MigrationRunner to ensure closing of the connection, because VersionLoader.LoadVersionInfo() reopens it after the transaction has been committed.

JetQuoter.cs contained a wrong format string for DateTime, resulting in the insert into VersionInfo failing. Has this ever worked? Probably noone uses Access. Good for them! :-)

@daniellee
Collaborator

Thanks for having a look at the Jet code. I suppose I'd better starting testing Jet :-) At the moment I test everything except Oracle, Jet and Sql Server 2000. Are any of the other core committers testing Jet?

@tommarien
Collaborator

This seems like a non obtrusive pull, the only thing I don't like is the sealed change you did for the processor, @dabide you mind correcting this ? The last commit seems the most changing one, mmm, need to investigate ...

@dabide

The reason I made it sealed, is that it now contains a call to a virtual method in the constructor. That is probably the reason that SqlServerProcessor and SqlServer2000Processor also are sealed. Probably, it would be better only to seal the BeginTransaction method. What do you think?
http://stackoverflow.com/questions/119506/virtual-member-call-in-a-constructor

@tommarien
Collaborator

@dabide in fact now that you mention it the processorbase begintransaction should be abstract etc, but in this case you can ignore the warning, or just keep it sealed like you did.

@tommarien
Collaborator

@dabide there are some tests that fail, see IfDatabaseExpressionRootTests, you mind fixing those ?

@dabide

Closing this pull request. Added a newer, much simpler one.

@dabide dabide closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2012
  1. @dabide
Commits on Oct 24, 2012
  1. @dabide
  2. @dabide

    Added code to ensure connection being closed by MigrationRunner

    dabide authored
    (VersionLoader.LoadVersionInfo() reopened it)
Commits on Oct 31, 2012
  1. @dabide

    Merge tag '1.0.4'

    dabide authored
This page is out of date. Refresh to see the latest.
View
4 FluentMigrator (2010).sln.DotSettings
@@ -15,4 +15,6 @@ See the License for the specific language governing permissions and
limitations under the License.</s:String>
<s:String x:Key="/Default/Environment/UserInterface/ShortcutSchemeName/@EntryValue">None</s:String>
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/FormatStatementOnSemicolon/@EntryValue">False</s:Boolean>
- <s:Boolean x:Key="/Default/CodeEditing/TypingAssist/FormatBlockOnRBrace/@EntryValue">False</s:Boolean></wpf:ResourceDictionary>
+ <s:Boolean x:Key="/Default/CodeEditing/TypingAssist/FormatBlockOnRBrace/@EntryValue">False</s:Boolean>
+ <s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
+ <s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String></wpf:ResourceDictionary>
View
2  src/FluentMigrator.Runner/Generators/Jet/JetColumn.cs
@@ -30,7 +30,7 @@ protected override string FormatType(ColumnDefinition column)
protected override string FormatIdentity(ColumnDefinition column)
{
- //Indentity type is handled by FormartType
+ //Identity type is handled by FormatType
return string.Empty;
}
View
10 src/FluentMigrator.Runner/Generators/Jet/JetGenerator.cs
@@ -14,27 +14,27 @@ public JetGenerator()
public override string Generate(RenameTableExpression expression)
{
- return compatabilityMode.HandleCompatabilty("Renaming of tables is not supporteed for MySql");
+ return compatabilityMode.HandleCompatabilty("Renaming of tables is not supported for Jet");
}
public override string Generate(RenameColumnExpression expression)
{
- return compatabilityMode.HandleCompatabilty("Renaming of columns is not supporteed for MySql");
+ return compatabilityMode.HandleCompatabilty("Renaming of columns is not supported for Jet");
}
public override string Generate(AlterDefaultConstraintExpression expression)
{
- return compatabilityMode.HandleCompatabilty("Altering of default constraints is not supporteed for MySql");
+ return compatabilityMode.HandleCompatabilty("Altering of default constraints is not supported for Jet");
}
public override string Generate(CreateSequenceExpression expression)
{
- return compatabilityMode.HandleCompatabilty("Sequences is not supporteed for MySql");
+ return compatabilityMode.HandleCompatabilty("Sequences are not supported for Jet");
}
public override string Generate(DeleteSequenceExpression expression)
{
- return compatabilityMode.HandleCompatabilty("Sequences is not supporteed for MySql");
+ return compatabilityMode.HandleCompatabilty("Sequences are not supported for Jet");
}
public override string Generate(DeleteDefaultConstraintExpression expression)
View
3  src/FluentMigrator.Runner/Generators/Jet/JetQuoter.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using FluentMigrator.Runner.Generators.Generic;
namespace FluentMigrator.Runner.Generators.Jet
@@ -15,7 +16,7 @@ public class JetQuoter : GenericQuoter
public override string FormatDateTime(DateTime value)
{
- return ValueQuote + (value).ToString("YYYY-MM-DD HH:mm:ss") + ValueQuote;
+ return string.Format(CultureInfo.InvariantCulture, "{0}{1:yyyy-MM-dd HH:mm:ss}{0}", ValueQuote, (value));
}
}
}
View
22 src/FluentMigrator.Runner/MigrationRunner.cs
@@ -95,6 +95,10 @@ public void MigrateUp(bool useAutomaticTransactionManagement)
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
public void MigrateUp(long targetVersion)
@@ -113,11 +117,15 @@ public void MigrateUp(long targetVersion, bool useAutomaticTransactionManagement
if (useAutomaticTransactionManagement) { Processor.CommitTransaction(); }
VersionLoader.LoadVersionInfo();
}
- catch (Exception ex)
+ catch (Exception)
{
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
private IEnumerable<long> GetUpMigrationsToApply(long version)
@@ -158,6 +166,10 @@ public void MigrateDown(long targetVersion, bool useAutomaticTransactionManageme
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
private IEnumerable<long> GetDownMigrationsToApply(long targetVersion)
@@ -237,6 +249,10 @@ public void Rollback(int steps, bool useAutomaticTransactionManagement)
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
public void RollbackToVersion(long version)
@@ -271,6 +287,10 @@ public void RollbackToVersion(long version, bool useAutomaticTransactionManageme
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
public Assembly MigrationAssembly
View
12 src/FluentMigrator.Runner/Processors/Firebird/FirebirdProcessor.cs
@@ -145,10 +145,7 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
ClearLocks();
}
@@ -177,11 +174,16 @@ public override void RollbackTransaction()
}
}
+ CloseConnection();
+ ClearLocks();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
}
- ClearLocks();
}
public virtual void CommitRetaining()
View
39 src/FluentMigrator.Runner/Processors/Jet/JetProcessor.cs
@@ -5,9 +5,10 @@
namespace FluentMigrator.Runner.Processors.Jet
{
- public class JetProcessor : ProcessorBase
+ public sealed class JetProcessor : ProcessorBase
{
private OleDbConnection Connection { get; set; }
+ public OleDbTransaction Transaction { get; private set; }
public override string DatabaseType
{
@@ -18,8 +19,40 @@ public JetProcessor(OleDbConnection connection, IMigrationGenerator generator, I
: base(generator, announcer, options)
{
Connection = connection;
+ connection.Open();
+ BeginTransaction();
}
+ public override void BeginTransaction()
+ {
+ Announcer.Say("Beginning Transaction");
+ Transaction = Connection.BeginTransaction();
+ }
+
+ public override void CommitTransaction()
+ {
+ Announcer.Say("Committing Transaction");
+ Transaction.Commit();
+ WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void RollbackTransaction()
+ {
+ Announcer.Say("Rolling back transaction");
+ Transaction.Rollback();
+ WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
+ if (Connection.State != ConnectionState.Closed)
+ {
+ Connection.Close();
+ }
+ }
+
public override void Process(PerformDBOperationExpression expression)
{
Announcer.Say("Performing DB Operation");
@@ -43,7 +76,7 @@ protected override void Process(string sql)
if (Connection.State != ConnectionState.Open)
Connection.Open();
- using (var command = new OleDbCommand(sql, Connection))
+ using (var command = new OleDbCommand(sql, Connection, Transaction))
{
try
{
@@ -66,7 +99,7 @@ public override DataSet Read(string template, params object[] args)
if (Connection.State != ConnectionState.Open) Connection.Open();
var ds = new DataSet();
- using (var command = new OleDbCommand(String.Format(template, args), Connection))
+ using (var command = new OleDbCommand(String.Format(template, args), Connection, Transaction))
using (var adapter = new OleDbDataAdapter(command))
{
adapter.Fill(ds);
View
10 src/FluentMigrator.Runner/Processors/Postgres/PostgresProcessor.cs
@@ -100,10 +100,7 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
@@ -111,6 +108,11 @@ public override void RollbackTransaction()
Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
View
4 src/FluentMigrator.Runner/Processors/ProcessorBase.cs
@@ -172,6 +172,10 @@ public virtual void RollbackTransaction()
{
}
+ public virtual void CloseConnection()
+ {
+ }
+
public abstract System.Data.DataSet ReadTableData(string schemaName, string tableName);
public abstract System.Data.DataSet Read(string template, params object[] args);
public abstract bool Exists(string template, params object[] args);
View
10 src/FluentMigrator.Runner/Processors/SqlServer/SqlServer2000Processor.cs
@@ -100,10 +100,7 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
@@ -111,6 +108,11 @@ public override void RollbackTransaction()
Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
View
10 src/FluentMigrator.Runner/Processors/SqlServer/SqlServerCeProcessor.cs
@@ -120,10 +120,7 @@ public override void CommitTransaction()
transaction = null;
}
- if (connection.State != ConnectionState.Closed)
- {
- connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
@@ -138,6 +135,11 @@ public override void RollbackTransaction()
transaction.Rollback();
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (connection.State != ConnectionState.Closed)
{
connection.Close();
View
10 src/FluentMigrator.Runner/Processors/SqlServer/SqlServerProcessor.cs
@@ -128,10 +128,7 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
@@ -139,6 +136,11 @@ public override void RollbackTransaction()
Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
View
1  src/FluentMigrator/IMigrationProcessor.cs
@@ -34,6 +34,7 @@ public interface IMigrationProcessor : IQuerySchema
void BeginTransaction();
void CommitTransaction();
void RollbackTransaction();
+ void CloseConnection();
void Process(CreateSchemaExpression expression);
void Process(DeleteSchemaExpression expression);
Something went wrong with that request. Please try again.