Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Transaction Properties
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Transactions > Transaction Properties

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

You can control the behavior of the transactions in your OpenAccess ORM applications by setting various transaction properties. The properties are always set for a specific transaction, and they are valid until the IObjectScope instance is disposed of. Transaction properties can be changed only if the transaction is not active.

The previous sections showed some transaction properties. In the following code example, the RetainValues property is set to true:

C# Copy Code
// prepare transaction properties

scope.TransactionProperties.RetainValues = true;

scope.Transaction.Begin();

...

ConsoleWriteLine(
"RetainValues is "

                 
+ scope.Transaction.Properties.RetainValues );

scope.Transaction.Commit();

// Properties are still valid

scope.Transaction.Begin();

...
VB.NET Copy Code
' prepare transaction properties
scope.TransactionProperties.RetainValues = True
scope.Transaction.Begin()
'...

ConsoleWriteLine("RetainValues is " + scope.Transaction.Properties.RetainValues)
scope.Transaction.Commit()
' Properties are still valid
scope.Transaction.Begin()

Following is a list of the transaction properties, their allowed and default values, and a brief description.

RetainValues
 

This property controls whether persistent class instances retain their values after commit of the transaction and if read access is allowed. By default it is set to true. However, regardless of this setting, objects are refreshed from the data store the next time the object is accessed within an active transaction.

RestoreValues
 

This property controls whether the values of objects are restored to their original values when a transaction (or one particular nesting level) is rolled back. By default it is set to false.

No Automatic Refreshes
 

As described earlier in this chapter, OpenAccess ORM uses optimistic concurrency control by default (refer to Concurrency Control Algorithms for more information about the various concurrency control mechanisms). This means that OpenAccess ORM does not validate read (but unmodified) objects at commit time, and therefore it is possible that if an object is read inside a transaction, it might be changed in the database, while the transaction is running.

So, in order to avoid long-living stale objects, OpenAccess ORM will refresh such objects if they are accessed in a subsequent transaction. This happens on the first access to such objects. Thus, only short-living stale objects are possible, at the cost of an SQL call for refreshing the object in a subsequent transaction.

It is possible to have more control over this refreshing behavior, by disabling the automatic refresh function, which can be done as shown below:

Copy Code
scope.TransactionProperties.RefreshReadObjectsInNewTransaction = false;

The advantage of using this is that objects can keep their data for a long time, without the need for executing an SQL Statement again.

However, if you enable "no automatic refreshes" then you are responsible for avoiding stale data, i.e. you will need to call Refresh() or Evict() at appropriate times.

Therefore, please use this with care, since read (but not modified) objects, will not be refreshed automatic`ally in new transactions of the same ObjectScope, i.e., if an object is fetched from the database in the first transaction and is subsequently never explicitly refreshed, evicted or modified in subsequent transactions, it will still have the values from the first transaction.

Concurrency
 

This property determines the concurrency settings of a transaction. The default is TransactionMode.OPTIMISTIC|TransactionMode.NO_LOST_UPDATES.

AutomaticBegin
 

This property allows the user to specify that every Commit()/Rollback() of a transaction will start a new transaction immediately. Therefore, the user does not need to call Begin(), and one can work with just Commit() and Rollback() calls. In other words, there is always a started transaction. This is regardless of a failure of a Commit() [the next transaction will yet be started].

This is especially useful for multithreaded applications, i.e., working with multiple threads in one object scope by setting the <option.Multithreaded> to "true", since this allows an automatic synchronized Commit() + Begin().

FailFast
 

This property determines whether a transaction commit or flush, should fail at the first failure. When this property is set to true (default value), the transaction will fail on the occurrence of the first OptimisticVerificationException. When this property is set to false the IObjectScope will collect all the failures, i.e., the commit or flush will continue and collect all the OptimisticVerificationExceptions that occur. It might be time consuming to collect all the failures, therefore this property is set to true by default.

This property should be set to false only when the information about failing objects is necessary, since it might be very time consuming to collect all the failures.