com.jenkov.mrpersister.scope
Interface IScopeFactory

All Known Implementing Classes:
ScopeFactory

public interface IScopeFactory

A factory capable of creating IScopeBoundary objects. IScopeBoundary objects can be either ConnectionScope or TransactionScope objects.

The default implementation of this IScopeFactory interface is the ScopeFactory class.

Author:
Jakob Jenkov - Copyright 2005 Jenkov Development

Method Summary
 IScopeBoundary createConnectionScope()
          Creates a connection scope object.
 java.lang.Object createConnectionScope(java.lang.Object scopeTarget)
          Creates a connection scope object that wraps a connection scope around methods of the scopeTarget object.
 IScopeBoundary createTransactionScope()
          Creates a transaction scope object.
 java.lang.Object createTransactionScope(java.lang.Object scopeTarget)
          Creates a transaction scope object that wraps a transaction scope around methods of the scopeTarget object.
 ScopingDataSource getScopingDataSource()
          Returns the ScopingDataSource used by this IScopeFactory.
 

Method Detail

getScopingDataSource

ScopingDataSource getScopingDataSource()
Returns the ScopingDataSource used by this IScopeFactory.

Returns:
The ScopingDataSource used by this IScopeFactory.

createConnectionScope

IScopeBoundary createConnectionScope()
Creates a connection scope object.

Returns:
A new connection scope object.

createConnectionScope

java.lang.Object createConnectionScope(java.lang.Object scopeTarget)
Creates a connection scope object that wraps a connection scope around methods of the scopeTarget object. Only methods that are implementations of interface methods will be wrapped.

The returned object implements the same interfaces as the scopeTarget. You can therefore cast the returned object to any of those interfaces. Whenever you call one of the methods on the returned object, which are part of one of the implemented interfaces, a connection scope will be wrapped around the method call. In other words, any opened connections inside the interface method will be reused, and the connection automatically closed afterwards. This will only work if the scopeTarget object obtains it's connections from the ScopingDatasource referenced by this ScopeFactory instance.

Parameters:
scopeTarget -
Returns:
An object implementing the same interfaces as the scopeTarget, and has all interface methods wrapped in a connection scope.

createTransactionScope

IScopeBoundary createTransactionScope()
Creates a transaction scope object.

Returns:
A new transaction scope object.

createTransactionScope

java.lang.Object createTransactionScope(java.lang.Object scopeTarget)
Creates a transaction scope object that wraps a transaction scope around methods of the scopeTarget object. Only methods that are implementations of interface methods will be wrapped.

The returned object implements the same interfaces as the scopeTarget. You can therefore cast the returned object to any of those interfaces. Whenever you call one of the methods on the returned object, which are part of one of the implemented interfaces, a transaction scope will be wrapped around the method call. In other words, any opened connections inside the interface method will be reused, and the transaction automatically committed/rolled back, and connection automatically closed afterwards. This will only work if the scopeTarget object obtains it's connections from the ScopingDatasource referenced by this ScopeFactory instance.

Parameters:
scopeTarget -
Returns:
An object implementing the same interfaces as the scopeTarget, and has all interface methods wrapped in a connection scope.