Annotation PointCut Advisor, and Transaction Advice in CVS

22 views
Skip to first unread message

Mark Mandel

unread,
Mar 4, 2009, 6:29:21 PM3/4/09
to coldspri...@googlegroups.com
Hey guys,

I've committed a couple of enhancements to ColdSpring CVS that may be
useful to you all.

The first is PointCutAdvisor that uses annotations (extra meta data on
cffunction), to specify where you want to use Advice.

Example usage:

<cffunction name="loginUser" hint="logs in a user" access="public"
returntype="boolean" output="false" transaction="true">
<cfargument name="username" hint="the username" type="string"
required="Yes">
<cfargument name="password" hint="the password" type="string"
required="Yes">

//stuff
</cffunction>

Where 'transaction' is the annotation.

To configure the annotation, there is a <map> passed into the
AnnotationPointCutAdvisor, with key-value pairs for the annotation to
look for, and the value it should have.

<!-- User Service -->
<bean id="UserService" class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="UserServiceTarget"/>
</property>
<property name="interceptorNames">
<list>
<value>TransactionAdvisor</value>
</list>
</property>
</bean>

<!-- AOP Classes -->
<bean id="TransactionAdvice" class="model.java.cs.TransactionAdvice"/>

<bean id="TransactionAdvisor"
class="coldspring.aop.support.AnnotationPointCutAdvisor">
<property name="advice">
<ref bean="TransactionAdvice" />
</property>
<property name="annotations">
<map>
<entry key="transaction">
<value>true</value>
</entry>
</map>
</property>
</bean>

To map to any value of the annotation (or really just check that it is
there), you can use the wildcard '*' as

<bean id="TransactionAdvisor"
class="coldspring.aop.support.AnnotationPointCutAdvisor">
<property name="advice">
<ref bean="TransactionAdvice" />
</property>
<property name="annotations">
<map>
<entry key="transaction">
<value>*</value>
</entry>
</map>
</property>
</bean>

The second is a Transaction Advice, that is nestable - i.e. if a
Transaction Advised method calls another Transaction Advised method,
the inner one will be escaped, and will be merged into the Outer
transaction.

You can apply the Transaction advice as per normal (I like it with the
AnnoationPointCutAdvisor myself), and can be configured as such:

<bean id="TransactionAdvice"
class="coldspring.aop.advice.SimpleTransactionAdvice"/>

Let me know if you run into any issues.

Mark

--
E: mark....@gmail.com
W: www.compoundtheory.com

Peter J. Farrell

unread,
Mar 4, 2009, 6:38:12 PM3/4/09
to coldspri...@googlegroups.com
Thanks for the enhancement Mark. Definitely looks promising. Wondering
if you add support to namespace the annotations (configurable).
Something like:

<bean id="TransactionAdvisor"
class="coldspring.aop.support.AnnotationPointCutAdvisor">
<property name="advice">
<ref bean="TransactionAdvice" />
</property>
<property name="annotations">
<map>
<entry key="transaction">
<value>true</value>
</entry>
</map>
</property>

<property name="namespacePrefix"><value>cs</value></property>
</bean>

And then the method would look something like this:

<cffunction name="loginUser" access="public" returntype="boolean"
output="false" cs:transaction="true">

This way it's a lot easier to see that the annotation belongs to
ColdSpring and not part of some magic CFML stuff. Thoughts?

Best,
Peter

Mark Mandel said the following on 3/4/2009 5:29 PM:

Tony Nelson

unread,
Mar 5, 2009, 10:47:25 AM3/5/09
to ColdSpring-Users
Couldn't you simply set your annotation to <entry
key="cs:transaction">?

-Tony

Mark Mandel

unread,
Mar 5, 2009, 7:36:07 PM3/5/09
to coldspri...@googlegroups.com
I suppose it depends if you feel that annotations should come from
*somewhere*, or if they should be just markers, that could be used by
anyone.

Regardless, I just committed a bug fix to the
AnnotationPointCutAdvisor... it was returning a match on ALL methods
in a CFC, if only 1 method in that cfc had the annotation, which was
pretty silly.

Mark
Reply all
Reply to author
Forward
0 new messages