Skip to content

Commit

Permalink
Added transaction handling to Jet, and corrected some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
dabide committed Feb 18, 2013
1 parent 3d1790d commit 6627de5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
4 changes: 3 additions & 1 deletion FluentMigrator (2010).sln.DotSettings
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion src/FluentMigrator.Runner/Generators/Jet/JetColumn.cs
Expand Up @@ -30,7 +30,7 @@ protected override string FormatType(ColumnDefinition column)

protected override string FormatIdentity(ColumnDefinition column)
{
//Indentity type is handled by FormartType
//Indentity type is handled by FormatType
return string.Empty;
}

Expand Down
10 changes: 5 additions & 5 deletions src/FluentMigrator.Runner/Generators/Jet/JetGenerator.cs
Expand Up @@ -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 supporteed 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 supporteed 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 supporteed for Jet");
}

public override string Generate(CreateSequenceExpression expression)
{
return compatabilityMode.HandleCompatabilty("Sequences is not supporteed for MySql");
return compatabilityMode.HandleCompatabilty("Sequences is not supporteed for Jet");
}

public override string Generate(DeleteSequenceExpression expression)
{
return compatabilityMode.HandleCompatabilty("Sequences is not supporteed for MySql");
return compatabilityMode.HandleCompatabilty("Sequences is not supporteed for Jet");
}

public override string Generate(DeleteDefaultConstraintExpression expression)
Expand Down
51 changes: 45 additions & 6 deletions src/FluentMigrator.Runner/Processors/Jet/JetProcessor.cs
Expand Up @@ -8,6 +8,7 @@ namespace FluentMigrator.Runner.Processors.Jet
public class JetProcessor : ProcessorBase
{
private OleDbConnection Connection { get; set; }
public OleDbTransaction Transaction { get; protected set; }

public override string DatabaseType
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public override void Process(PerformDBOperationExpression expression)

if (Options.PreviewOnly)
return;

EnsureConnectionIsOpen();

if (expression.Operation != null)
Expand All @@ -54,7 +55,7 @@ protected override void Process(string sql)

EnsureConnectionIsOpen();

using (var command = new OleDbCommand(sql, Connection))
using (var command = new OleDbCommand(sql, Connection, Transaction))
{
try
{
Expand All @@ -77,7 +78,7 @@ public override DataSet Read(string template, params object[] args)
EnsureConnectionIsOpen();

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);
Expand All @@ -89,7 +90,7 @@ public override bool Exists(string template, params object[] args)
{
EnsureConnectionIsOpen();

using (var command = new OleDbCommand(String.Format(template, args), Connection))
using (var command = new OleDbCommand(String.Format(template, args), Connection, Transaction))
using (var reader = command.ExecuteReader())
{
return reader.Read();
Expand Down Expand Up @@ -118,7 +119,8 @@ public override bool TableExists(string schemaName, string tableName)
var restrict = new object[] { null, null, tableName, "TABLE" };
using (var tables = Connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, restrict))
{
for (int i = 0; i < tables.Rows.Count; i++) {
for (int i = 0; i < tables.Rows.Count; i++)
{
var name = tables.Rows[i].ItemArray[2].ToString();
if (name == tableName)
{
Expand All @@ -136,7 +138,8 @@ public override bool ColumnExists(string schemaName, string tableName, string co
var restrict = new[] { null, null, tableName, null };
using (var columns = Connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, restrict))
{
for (int i = 0; i < columns.Rows.Count; i++) {
for (int i = 0; i < columns.Rows.Count; i++)
{
var name = columns.Rows[i].ItemArray[3].ToString();
if (name == columnName)
{
Expand Down Expand Up @@ -169,8 +172,44 @@ public override bool IndexExists(string schemaName, string tableName, string ind
}
}

public bool SupportsTransactions
{
get { return true; }
}

public override void BeginTransaction()
{
if (!SupportsTransactions || Transaction != null) return;

EnsureConnectionIsOpen();

Announcer.Say("Beginning Transaction");
Transaction = Connection.BeginTransaction();
}

public override void RollbackTransaction()
{
if (Transaction == null) return;

Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
Transaction = null;
}

public override void CommitTransaction()
{
if (Transaction == null) return;

Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
Transaction = null;
}

protected override void Dispose(bool isDisposing)
{
RollbackTransaction();
EnsureConnectionIsClosed();
}
}
Expand Down

0 comments on commit 6627de5

Please sign in to comment.