C# Class Tiraggo.Interfaces.tgTransactionScope

This is the EntitySpaces ADO.NET connection based transaction class that mimics the System.Transactions.TransactionScope class.
EntitySpaces supports two transactions models, connection based via this class (tgTransactionScope) and the new System.Transactions.TransactionScope. Some databases such as Microsoft Access don't support the new System.Transactions.TransactionScope class. And still there are other cases where the System.Transactions.TransactionScope class cannot be used as is the case with a lot of hosting companies. Thus EntitySpaces provides a very nice ADO.NET connection based transaction handler. The Syntax should be as follows: using (tgTransactionScope scope = new tgTransactionScope()) { // Logic here ... scope.Complete(); // last line of using statement } Note that if an exception is thrown scope.Complete will not be called, and the transaction upon leaving the using statement will be rolled back. You indicate whether you want the provider to use the tgTransactionScope or the System.Transactions.TransactionScope class in your .config file. Notice in the config file setting below that providerClass="DataProvider". This indicates that you want to use the tgTransactionScope class, use providerClass="DataProviderEnterprise" to use System.Transactions.TransactionScope. <add name="SQL" providerMetadataKey="esDefault" sqlAccessType="DynamicSQL" provider="Tiraggo.SqlClientProvider" providerClass="DataProvider" connectionString="User ID=sa;Password=griffinski;Initial Catalog=Northwind;Data Source=localhost" databaseVersion="2005"/>
Inheritance: IDisposable
Exibir arquivo Open project: BrewDawg/Tiraggo Class Usage Examples

Public Methods

Method Description
AddForCommit ( ICommittable commit ) : bool

You should never call this directly, EntitySpaces calls this internally.

Complete ( ) : void

You must call Complete to commit the transaction. Calls and transactions can be nested, only the final outer call to Complete will commit the transaction.

DeEnlist ( IDbCommand cmd ) : void

You should never call this directly, the providers call this method.

Enlist ( IDbCommand cmd, string connectionString, CreateIDbConnectionDelegate creator ) : void

You should never call this directly, the providers call this method.

GetCurrentTransactionScopeOption ( ) : tgTransactionScopeOption

This can be used to get the tgTransactionScopeOption from the current tgTransactionScope (remember transactions can be nested). If there is no on-going transaction then tgTransactionScopeOption.None is returned.

tgTransactionScope ( ) : System

The default constructor, this transactions tgTransactionScopeOption will be set to Required. The IsolationLevel is set to Unspecified. using (tgTransactionScope scope = new tgTransactionScope()) { // Do your work here scope.Complete(); }

tgTransactionScope ( tgTransactionScopeOption option ) : System

Use this constructor to control the tgTransactionScopeOption as it applies to this transaction. using (tgTransactionScope scope = new tgTransactionScope(tgTransactionScopeOption.RequiresNew)) { // Do your work here scope.Complete(); }

tgTransactionScope ( tgTransactionScopeOption option, IsolationLevel level ) : System

Use this constructor to control the tgTransactionScopeOption as it applies to this transaction. using (tgTransactionScope scope = new tgTransactionScope(tgTransactionScopeOption.RequiresNew, IsolationLevel.ReadCommitted)) { // Do your work here scope.Complete(); }

Protected Methods

Method Description
CommonInit ( tgTransactionScope tx ) : void

This is the common constructor logic, tx is "this" from the constructor

Private Methods

Method Description
GetCurrentTx ( ) : tgTransactionScope

Internal method.

IDisposable ( ) : void

Internal. Called when the "using" statement is exited.

Rollback ( ) : void

Internal method, called if the "using" statement is left without calling scope.Complete()

Method Details

AddForCommit() public static method

You should never call this directly, EntitySpaces calls this internally.
public static AddForCommit ( ICommittable commit ) : bool
commit ICommittable Any class that implements ICommittable
return bool

CommonInit() protected static method

This is the common constructor logic, tx is "this" from the constructor
protected static CommonInit ( tgTransactionScope tx ) : void
tx tgTransactionScope
return void

Complete() public method

You must call Complete to commit the transaction. Calls and transactions can be nested, only the final outer call to Complete will commit the transaction.
public Complete ( ) : void
return void

DeEnlist() public static method

You should never call this directly, the providers call this method.
public static DeEnlist ( IDbCommand cmd ) : void
cmd IDbCommand The command to enlist into a transaction
return void

Enlist() public static method

You should never call this directly, the providers call this method.
public static Enlist ( IDbCommand cmd, string connectionString, CreateIDbConnectionDelegate creator ) : void
cmd IDbCommand The command to enlist into a transaction
connectionString string The connection string passed to the CreateIDbConnectionDelegate delegate
creator CreateIDbConnectionDelegate The delegate previously registered by the provider
return void

GetCurrentTransactionScopeOption() public static method

This can be used to get the tgTransactionScopeOption from the current tgTransactionScope (remember transactions can be nested). If there is no on-going transaction then tgTransactionScopeOption.None is returned.
public static GetCurrentTransactionScopeOption ( ) : tgTransactionScopeOption
return tgTransactionScopeOption

tgTransactionScope() public method

The default constructor, this transactions tgTransactionScopeOption will be set to Required. The IsolationLevel is set to Unspecified. using (tgTransactionScope scope = new tgTransactionScope()) { // Do your work here scope.Complete(); }
public tgTransactionScope ( ) : System
return System

tgTransactionScope() public method

Use this constructor to control the tgTransactionScopeOption as it applies to this transaction. using (tgTransactionScope scope = new tgTransactionScope(tgTransactionScopeOption.RequiresNew)) { // Do your work here scope.Complete(); }
public tgTransactionScope ( tgTransactionScopeOption option ) : System
option tgTransactionScopeOption See
return System

tgTransactionScope() public method

Use this constructor to control the tgTransactionScopeOption as it applies to this transaction. using (tgTransactionScope scope = new tgTransactionScope(tgTransactionScopeOption.RequiresNew, IsolationLevel.ReadCommitted)) { // Do your work here scope.Complete(); }
public tgTransactionScope ( tgTransactionScopeOption option, IsolationLevel level ) : System
option tgTransactionScopeOption See
level IsolationLevel See IsolationLevel in the System.Data namespace
return System