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.
50 lines
910 B
50 lines
910 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace FLocal.Core.DB {
|
|
|
|
abstract public class Transaction : IDisposable {
|
|
|
|
protected Transaction() {
|
|
this.finalized = false;
|
|
}
|
|
|
|
abstract protected void do_Commit();
|
|
|
|
abstract protected void do_Rollback();
|
|
|
|
public bool finalized {
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public void Commit() {
|
|
lock(this) {
|
|
if(this.finalized) throw new CriticalException("Already finalized");
|
|
this.do_Commit();
|
|
this.finalized = true;
|
|
}
|
|
}
|
|
|
|
public void Rollback() {
|
|
lock(this) {
|
|
if(this.finalized) throw new CriticalException("Already finalized");
|
|
this.do_Rollback();
|
|
this.finalized = true;
|
|
}
|
|
}
|
|
|
|
public void Dispose() {
|
|
lock(this) {
|
|
if(!this.finalized) {
|
|
this.do_Rollback();
|
|
this.finalized = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|