Side of Software
Persistence Library 2.0

sos.db
Class DefaultTransactionPolicy

java.lang.Object
  extended by sos.db.AbstractTransactionPolicy
      extended by sos.db.DefaultTransactionPolicy
All Implemented Interfaces:
java.io.Serializable, TransactionPolicy

public class DefaultTransactionPolicy
extends AbstractTransactionPolicy
implements TransactionPolicy

A transaction policy that uses a single database lock to ensure that transactions appear to execute sequentially. For any transaction to make progress it must hold the single database lock. An instance of this class should not be shared among databases.

With this policy, there is no chance for deadlock. If the transaction holding the lock never commits or aborts, however, then another transaction would wait forever and no progress would be made. To avoid this starvation, a timeout interval is used. A transaction will wait for a lock the number of milliseconds specified in the constructor.

This policy allows no concurrency in transactions. To allow operations on different objects to execute concurrently, consider using DefaultReadWriteTransactionPolicy instead of this class.

This policy is adequate for applications in which all transactions execute on the same thread or for applications in which there is high transaction contention.

Since:
1.0
See Also:
DefaultReadWriteTransactionPolicy

Constructor Summary
DefaultTransactionPolicy()
          Creates an instance of DefaultTransactionPolicy with a default lock timeout of Long.MAX_VALUE milliseconds.
DefaultTransactionPolicy(long timeout)
          Creates an instance of DefaultTransactionPolicy with the specified lock timeout.
 
Method Summary
protected  void logLockAcquired(java.lang.String databaseName)
          Records that the database lock has been acquired.
protected  void logLockReleased(java.lang.String databaseName)
          Records that the database lock has been released.
 void startTransaction(TransactionSupport support)
          Notifies this policy that a top-level transaction is starting for the executing thread.
 
Methods inherited from class sos.db.AbstractTransactionPolicy
getMethodStatus, invoke, logMethodInvocation, prepareForReadOnlyInvocation, prepareForWriteInvocation, registerObject, unregisterObjects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sos.db.TransactionPolicy
invoke, registerObject, unregisterObjects
 

Constructor Detail

DefaultTransactionPolicy

public DefaultTransactionPolicy()
Creates an instance of DefaultTransactionPolicy with a default lock timeout of Long.MAX_VALUE milliseconds.

See Also:
DefaultTransactionPolicy(long)

DefaultTransactionPolicy

public DefaultTransactionPolicy(long timeout)
Creates an instance of DefaultTransactionPolicy with the specified lock timeout.

Parameters:
timeout - maximum time to wait (in milliseconds) for the database lock
Method Detail

logLockAcquired

protected void logLockAcquired(java.lang.String databaseName)
Records that the database lock has been acquired.

This implementation uses the localized message for key "logLockAcquired". The message takes two parameters: the database name and the transaction thread.

Parameters:
databaseName - name of the database
Since:
2.0

logLockReleased

protected void logLockReleased(java.lang.String databaseName)
Records that the database lock has been released.

This implementation uses the localized message for key "logLockReleased". The message takes two parameters: the database name and the transaction thread.

Parameters:
databaseName - name of the database
Since:
2.0

startTransaction

public void startTransaction(TransactionSupport support)
                      throws java.io.IOException
Description copied from interface: TransactionPolicy
Notifies this policy that a top-level transaction is starting for the executing thread. The database calls this method when a top-level transaction is starting.

Specified by:
startTransaction in interface TransactionPolicy
Overrides:
startTransaction in class AbstractTransactionPolicy
Parameters:
support - object to assist in transaction management
Throws:
java.io.IOException - if an I/O error occurs

Side of Software
Persistence Library 2.0

Copyright 2004-08 Side of Software (SOS). All rights reserved.