>For the sake of discussion, view the Tapestry listener method as the DAO layer method. I want to wrap a transaction around that.
>The question is, how can you wrap this transaction boundary around Tapestry listener invocations?


Lets assume:
- we have two DAO classes UserDAO and AddressDAO;
- listener method is updateUser( User, Address) method on UserDAO;

1. the trick employs factory pattern, that means that some object (HiveMind, or CGLib enhancer factory ) has a method
getSingleton( Class clazz );


2. on a page we would have a field like this:
UserDAO udao = (UserDAO ) factory.getSingleton( UserDAO.class);

udao will NOT be instance of UserDAO class but its subclass (in case of CGLib) or wrapped interface implementation in case of HM;

3. Factory makes sure that every method of original DAO classes is wrapped in transaction and exception handling logic;

4. At runtime method udao.updateUser( User, Address) will call AddressDAO like this
updateUser( User, Address){
...
AddressDAO adao = (AddressDAO) factory.getSingleton( AddressDAO.class);
adao.updateAddress( a );
}


updateAddress( a ) will work within the current transaction because enhanced logic sees it in ThreadLocal environment, as the other DAO classes.
So, we can invoke multiple methods before transaction commit or rollback.


Note, if we will call adao.updateAddress( a ) directly from another listener method, then this method WILL start transaction and then finish it properly.
That is what I call transparent and non-obtrusive



You seem to be too Tapestry focused, try imagine that there is no T(yet), but just a bunch of JUnit test cases:
my approach is very JUnit friendly - it works just fine and provides same Transactional context for those bare JUnit tests.
It allows convenient and fast code-compile-test cycles.



Hope it is clearer now.

Erik Hatcher wrote:

On May 11, 2005, at 12:09 PM, Konstantin Iignatyev wrote:

Erik Hatcher wrote:



I don't see how it'd be transparent. What is more transparent than a listener that doesn't have any explicit commits or rollbacks in it? In fact, my Tapestry code will have no direct use of Cayenne's API if all goes as planned.



IMO a proxy wrapped POJO is more transparent because it works properly no matter who and why calls its methods. My trick works with the assumption
that transactions starts when a thread enters first DAO layer method and finishes when the thread leaves it. It also correctly propagates the same transaction to all others call of DAO layer if necessary.


So, I do not know details of your implementation, but generally speaking if your object has business methods and they invoke DAO layer, then my trick works just fine.


For the sake of discussion, view the Tapestry listener method as the DAO layer method. I want to wrap a transaction around that.

The question is, how can you wrap this transaction boundary around Tapestry listener invocations?

There is not a way to intercept listener method invocations with HiveMind that I know of. If you know of a way, could you please share?


The trick is to intercept invocations of all or selected methods on certain DAO objects (singletons) no matter who invokes them.
That is just a matter of using proper HM interceptor, pretty much like the one I have used to compare performance of AOP
http://kgionline.com/articles/aop_1/aop_perf.jsp , scroll down to HM case.



Let me repeat one more time - the trick completely decouples DAO from all its users (UI, batch, WS, etc).
Actually all those DAOs become equivalents of Stateless Session Beans where every method is transactional.


And every method invocation is followed by a commit? I want to be a bit less fine grained than that, and make several business method calls possibly before a commit occurs. I assume that is what you do with yours, I'm just not clear on that based on what you just said.

That may or may not work for you, but I certainly discourage explicit transaction management in UI.


I'm definitely working to avoid explicit transaction management, that is the crux of my issue here.

My disclaimer is that I've historically avoided the database tier as others have been much more skilled and actually enjoyed it more than I do - so I'm learning this stuff now because I'm a one-man team on my current project.

    Erik


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--
Thanks,

Konstantin Ignatyev

http://www.kgionline.com





PS: If this is a typical day on planet earth, humans will add fifteen million 
tons of carbon to the atmosphere, destroy 115 square miles of tropical 
rainforest, create seventy-two miles of desert, eliminate between forty to one 
hundred species, erode seventy-one million tons of topsoil, add 2.700 tons of 
CFCs to the stratosphere, and increase their population by 263.000

Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools. New York: State University of New York Press, 1997: (4) (5) (p.206)


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to