com.jenkov.mrpersister.scope
Class ScopeFactory

java.lang.Object
  extended by com.jenkov.mrpersister.scope.ScopeFactory
All Implemented Interfaces:
IScopeFactory

public class ScopeFactory
extends java.lang.Object
implements IScopeFactory

Author:
Jakob Jenkov - Copyright 2005 Jenkov Development

Field Summary
protected  ScopingDataSource scopingDataSource
           
 
Constructor Summary
ScopeFactory(javax.sql.DataSource dataSource)
          Creates a new ScopeFactory.
ScopeFactory(ScopingDataSource dataSource)
          Creates a new ScopeFactory.
 
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.
protected static java.lang.Class[] getInterfacesForObject(java.lang.Object object)
          Returns all interfaces implemented by this objects class.
 ScopingDataSource getScopingDataSource()
          Returns the ScopingDataSource used by this IScopeFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scopingDataSource

protected ScopingDataSource scopingDataSource
Constructor Detail

ScopeFactory

public ScopeFactory(javax.sql.DataSource dataSource)
Creates a new ScopeFactory. The given DataSource is wrapped internally in a ScopingDataSource instance. You can obtain the ScopingDataSource instance by calling the getScopingDataSource() method.

Parameters:
dataSource -

ScopeFactory

public ScopeFactory(ScopingDataSource dataSource)
Creates a new ScopeFactory. The given ScopingDataSource is used internally to implement scoping.

Parameters:
dataSource - The ScopingDataSource to use by this ScopeFactory.
Method Detail

getScopingDataSource

public ScopingDataSource getScopingDataSource()
Description copied from interface: IScopeFactory
Returns the ScopingDataSource used by this IScopeFactory.

Specified by:
getScopingDataSource in interface IScopeFactory
Returns:
The ScopingDataSource used by this IScopeFactory.

createConnectionScope

public IScopeBoundary createConnectionScope()
Description copied from interface: IScopeFactory
Creates a connection scope object.

Specified by:
createConnectionScope in interface IScopeFactory
Returns:
A new connection scope object.

createConnectionScope

public java.lang.Object createConnectionScope(java.lang.Object scopeTarget)
Description copied from interface: IScopeFactory
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.

Specified by:
createConnectionScope in interface IScopeFactory
Returns:
An object implementing the same interfaces as the scopeTarget, and has all interface methods wrapped in a connection scope.

createTransactionScope

public IScopeBoundary createTransactionScope()
Description copied from interface: IScopeFactory
Creates a transaction scope object.

Specified by:
createTransactionScope in interface IScopeFactory
Returns:
A new transaction scope object.

createTransactionScope

public java.lang.Object createTransactionScope(java.lang.Object scopeTarget)
Description copied from interface: IScopeFactory
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.

Specified by:
createTransactionScope in interface IScopeFactory
Returns:
An object implementing the same interfaces as the scopeTarget, and has all interface methods wrapped in a connection scope.

getInterfacesForObject

protected static java.lang.Class[] getInterfacesForObject(java.lang.Object object)
Returns all interfaces implemented by this objects class. In contrast to the Class.getInterfaces() method this method also includes the interfaces implemented by any of the object class's superclasses.

Parameters:
object - The object to return the interfaces of.
Returns:
An array of the interfaces this objects class implements.