Local Transactions in NDO

Local NDO transactions are always bound to a persistence manager. The optimistic or pessimistic mode can be selected with the property TransactionMode. The enum value TransactionMode.Optimistic enables the optimistic and TransactionMode.Pessimistic the pessimistic mode.

Here is an example:

PersistenceManager pm = new PersistenceManager();

pm.TransactionMode = TransactionMode.Optimistic;

Employee e = ....;

pm.MakePersistent(e); 

pm.Save();

This starts a transaction that last only for the call of pm.Save. TransactionMode.Pessimistic would cause the start the transaction to begin at the first data access and to end when the call to pm.Save() has ended.

Isolation Level

The enumeration System.Data.IsolationLevel is used for defining the Isolation Level. This enumeration has six different values. Their meaning can be found in the MSDN documentation. Per Default NDO uses the value ReadCommitted. That means, data rows cannot be read if they were changed in another currently running transaction. But after data is read it can be changed in another transaction. This level is compatible with optimistic transactions.

For pessimistic transactions the levels Serializable or RepeatableRead could be used. They prevent other users from changing data that has been queried in another transaction. Beyond that, Serializable prevents the creation of phantom rows. Here the reading of a data row is impossible if this data row is part of a record set read by another concurrent transaction. Note that not all database products implement all Isolation Levels defined in the IsolationLevel enumeration.