An alternative to UBB.threads
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FLocal/MySQLConnector/Transaction.cs

54 lines
1.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Core;
using System.Data.Common;
namespace FLocal.MySQLConnector {
class Transaction : Core.DB.Transaction {
internal DbConnection sqlconnection;
internal DbTransaction sqltransaction;
public bool finalizedImpl {
get;
private set;
}
public Transaction(Connection connection, System.Data.IsolationLevel iso) : base() {
this.sqlconnection = connection.createConnection();
try {
//for some reason, call to BeginTransaction with IsolationLevel set fails somewhere deep in mysql library
this.sqltransaction = this.sqlconnection.BeginTransaction();
} catch(Exception e) {
this.close();
throw e;
}
}
protected override void do_Commit() {
lock(this) {
if(this.finalizedImpl) throw new CriticalException("Already finalized");
this.sqltransaction.Commit();
this.close();
}
}
protected override void do_Rollback() {
lock(this) {
if(this.finalizedImpl) throw new CriticalException("Already finalized");
this.sqltransaction.Rollback();
this.close();
}
}
private void close() {
this.sqlconnection.Close();
this.sqlconnection.Dispose();
this.finalizedImpl = true;
}
}
}