com.jenkov.mrpersister.scope
Class ConnectionScope
java.lang.Object
com.jenkov.mrpersister.scope.ConnectionScope
- All Implemented Interfaces:
- IScopeAction, IScopeBoundary, java.lang.reflect.InvocationHandler
public class ConnectionScope
- extends java.lang.Object
- implements IScopeBoundary, IScopeAction, java.lang.reflect.InvocationHandler
An implementation of the IScopeBoundary that can mark
the boundaries of a connection scope. Users of the scoping features
will not use this class directly. It is used by the ScopeFactory class.
- Author:
- Jakob Jenkov - Copyright 2005 Jenkov Development
Method Summary |
java.lang.Object |
inScope()
This method is called by the scope boundary object when
it is time to execute the actions inside the scope. |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
|
java.lang.Object |
scope()
|
java.lang.Object |
scope(IScopeAction scopeAction)
Executes the given action within this scope. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
dataSource
protected ScopingDataSource dataSource
scopeTarget
protected java.lang.Object scopeTarget
ConnectionScope
public ConnectionScope(ScopingDataSource dataSource)
ConnectionScope
public ConnectionScope(ScopingDataSource dataSource,
java.lang.Object scopeTarget)
scope
public java.lang.Object scope()
scope
public java.lang.Object scope(IScopeAction scopeAction)
- Description copied from interface:
IScopeBoundary
- Executes the given action within this scope.
- Specified by:
scope
in interface IScopeBoundary
- Parameters:
scopeAction
- The action to be executed within this scope.
- Returns:
- The return value of the scope action's inScope() method.
inScope
public java.lang.Object inScope()
throws java.lang.Throwable
- Description copied from interface:
IScopeAction
- This method is called by the scope boundary object when
it is time to execute the actions inside the scope.
As you may have noticed the connection that is scoped
is not passed to the IScopeAction in this method.
Your implementation of the IScopeAction interface
must have a reference to the ScopingDataSource, from
which it obtains it's connections. The ScopingDataSource
can be obtained from the IScopeFactory you are using,
or you can instantiate one yourself. Just remember that
the ScopingDataSource referenced by your IScopeAction
implementation has to be the same instance as referenced
by the IScopeBoundary instance, calling the inScope() method
of your IScopeAction implementation.
- Specified by:
inScope
in interface IScopeAction
- Returns:
- An object if your IScopeAction chooses to.
- Throws:
java.lang.Throwable
- If something goes wrong inside the IScopeAction.
The surrounding IScopeBoundary object will take
the correct measures to close the connection and
rollback any ongoing transaction.
invoke
public java.lang.Object invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
- Specified by:
invoke
in interface java.lang.reflect.InvocationHandler
- Throws:
java.lang.Throwable