<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<!-- MHonArc v2.6.10 -->
	<channel>
		<title>aspectj-users</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/maillist.html</link>
		<description>aspectj-users</description>
		<language>en-us</language>
		<pubDate>Fri, 06 Nov 2009 11:31:19 GMT</pubDate>
		<lastBuildDate>Fri, 06 Nov 2009 11:31:19 GMT</lastBuildDate>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<generator>MHonArc RSS 2.0 RCFile</generator>
		<managingEditor>webmaster@eclipse.org (Webmaster)</managingEditor>
		<webMaster>webmaster@eclipse.org (Webmaster)</webMaster>
		<image>
			<title>aspectj-users</title>
			<url>http://www.eclipse.org/eclipse.org-common/themes/Phoenix/images/eclipse_home_header.jpg</url>
			<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/maillist.html</link>
		</image>
 

	<item>
		<title>Re: [aspectj-users] A transaction question</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11455.html</link>
		<description>_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users -- View this message in context: http://old.nabble.com/A-transaction-question-tp26195112p26203290.ht...</description>
		<content:encoded><![CDATA[<tt>Hi Neo,<br>
it should work, if you don't find the manager there it could be because 
two different instances of AbstractTransaction aspect are intercepting 
the two methods. This happens if you declared your aspect with a 
specific instantiation rule.</tt><br>
<br>
<tt>By default, aspects are singletons. That means that there will be only 
one instance of AbstractTransaction in your application (well, in your 
classloader). Since this is sometimes a limit, AspectJ supports 
different instantiation systems, like perthis, pertarget, percflow 
etc... If you use one of these construct, then a new instance of your 
aspect will be created for each &quot;this&quot;, each &quot;target&quot; etc.. in this 
case, when you use this.manager inside your aspect, it could be null 
cause it is actually a different instance.</tt><br>
<br>
<tt>Could you post the complete aspect declaration, so that we can see which 
instantiation rule you are using?</tt><br>
<br>
<pre style="margin: 0em;"><br>Hope this helps,
Simone</pre><br>
<tt>neo anderson wrote:
</tt><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><tt>Thank you very much. Now I am able to obtain EntityManager whilst method<br>
setEntityManager get called. </tt><br>
<br>
<tt>But a new question: how can I assign the captured variable e.g.<br>
EntityManager to the variable in an Aspect? For instance, </tt><br>
<br>
<pre style="margin: 0em;">... aspect AbstractionTransaction ...{
        private EntityManager manager;
        void around(EntityManager manager): obtainEntityManager(manager) &amp;&amp;
cflow(tx()){
System.out.println(&quot;manager:&quot;+manager); // manager instance is not null
                this.manager = manager; // but assign to the member of
aspect seemingly does not work</pre><br>
<pre style="margin: 0em;">                proceed(manager);
        }</pre><br>
<pre style="margin: 0em;">}</pre><br>
<pre style="margin: 0em;">My AbstractTransaction aspect contains a variable manager and I would like
to assign when the setEntityManager get called. Because in the example of
Aspectj in Action, the method intercepted will return Connection, which is
different from the method I have. Is there any chance to assign the variable
so that I can apply entitymanager to the pointcut when scope() is executed?
Or what is the right way to do this?</pre><br>
<pre style="margin: 0em;">       Object around(): scope(){
System.out.println(&quot;===========&gt; EntityManager:&quot;+manager); // after
assigned, it is still null
                Object result = proceed();
                return result;
        }</pre><br>
<tt>Sorry if this question is too newbie. I search on the internet and read<br>
again the book Aspectj in Action, but seems there is no such explain. </tt><br>
<br>
<tt>Thanks for patiently answer my question. </tt><br>
<br>
<tt>I appreciate it. </tt><br>
<br>
<pre style="margin: 0em;"><br></pre><br>
<tt><br>Andy Clement wrote:<br>
  
</tt><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><pre style="margin: 0em;">The method you are intercepting (setEntityManager) has a void return
type, so your advice should too.  The proceed() call you are using
will ensure your replacement is passed to the setEntityManager call.</pre><br>
<pre style="margin: 0em;">Andy</pre><br>
<tt>2009/11/4 neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;:<br>
    
</tt><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><pre style="margin: 0em;">Hi Mark &amp; Andy. Thanks for your reply. I really appreciate your help.</pre><br>
<pre style="margin: 0em;">I change to use args, but now it thorws message:</pre><br>
<pre style="margin: 0em;">[error] incompatible return type applying to method-call(void
example.AccountDao.setEntityManager(example.EntityManager))</pre><br>
<pre style="margin: 0em;">[error] incompatible return type applying to method-call(void
example.AccountDao.setEntityManager(example.EntityManager))
dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());</pre><br>
<pre style="margin: 0em;">[warning] advice defined in example.AbstractTransaction has not been
applied
[Xlint:adviceDidNotMatch]</pre><br>
<pre style="margin: 0em;">I check the syntax and read the example in e.g.
<a  href="http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false">http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false</a></pre><br>
<pre style="margin: 0em;">The way to capture the EntityManager looks correct.</pre><br>
<pre style="margin: 0em;">public pointcut(EntityManager manager): call(*
AccountDao.setEntityManager(EntityManger)) &amp;&amp; args(manager);</pre><br>
<pre style="margin: 0em;">Is there any place I may go wrong? I test to move the .aj files and
compile
.java source. Everthing works fine. I am confused.</pre><br>
<pre style="margin: 0em;">I appreciate any suggestion.</pre><br>
<pre style="margin: 0em;">Thank you very much.</pre><br>
<tt><br>Mark Cooke-6 wrote:<br>
      
</tt><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><pre style="margin: 0em;">Hi,
It's been a while since I've used AspectJ in anger but as no-one else
has
replied yet...</pre><br>
<pre style="margin: 0em;">I'd say you probably want &quot;args(manager)&quot; instead of &quot;target(manager)&quot;
in
the obtainEntityManager pointcut.
The target of the call will be an AccountDAO, not an EntityManager.</pre><br>
<pre style="margin: 0em;">See
<a  href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html">http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html</a></pre><br>
<pre style="margin: 0em;">HTH!
Mark.</pre><br>
<pre style="margin: 0em;">--- On Wed, 4/11/09, neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt; wrote:</pre><br>
<tt>        
</tt><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><pre style="margin: 0em;">From: neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;
Subject: [aspectj-users] A transaction question
To: aspectj-users@xxxxxxxxxxx
Date: Wednesday, 4 November, 2009, 12:09</pre><br>
<pre style="margin: 0em;">I am learning how to modulize transaction using aspectj,
but encounter a
problem that EntityManager I try to capture is always null.
The compiler
issues message saying that the advice can not be applied.
as below:</pre><br>
<pre style="margin: 0em;">... advice defined in example.AbstractTransaction has not
been applied
[Xlint:adviceDidNotMatch]</pre><br>
<pre style="margin: 0em;">What should I change so that I can capture the
EntityManager while it is
created (whilst calling to
AccountDao.setEntityManager(..))?</pre><br>
<pre style="margin: 0em;">Thanks for help.</pre><br>
<pre style="margin: 0em;">Main.java</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">public class Main{
    public static void main(String args[]){
        Main m = new Main();
        m.process();
    }
    void process(){
        AccountDao dao = new
AccountDao();</pre><br>
<pre style="margin: 0em;">dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
        User u = new
User(&quot;1&quot;, &quot;Smith&quot;);
        u.setAddress(&quot;123
Test Road, London.&quot;);
        dao.save(u);</pre><br>
<pre style="margin: 0em;"><br>dao.list();
    }
}</pre><br>
<pre style="margin: 0em;">AccountDao.java</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">import java.util.List;
import java.util.ArrayList;</pre><br>
<pre style="margin: 0em;"><br>public class AccountDao{</pre><br>
<pre style="margin: 0em;">    private EntityManager manager;</pre><br>
<pre style="margin: 0em;">    private static List&lt;User&gt; database
= new ArrayList&lt;User&gt;();</pre><br>
<pre style="margin: 0em;">    public void
setEntityManager(EntityManager manager){
        this.manager =
manager;
    }</pre><br>
<pre style="margin: 0em;">    public void save(User user){</pre><br>
<pre style="margin: 0em;">database.add(user);
    }</pre><br>
<pre style="margin: 0em;">    public void list(){
        for(User u :
database){</pre><br>
<pre style="margin: 0em;">System.out.println(&quot;&gt;&gt;&gt;[AccountDao.java]&quot;+u);</pre><br>
<pre style="margin: 0em;">        }
    }
}</pre><br>
<pre style="margin: 0em;">User.java</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">public class User{
    private String id;
    private String name;
    private String address;
    public User(String id, String name){
        this.id = id;
        this.name = name;
    }</pre><br>
<pre style="margin: 0em;">    public String getId(){
        return this.id;
    }</pre><br>
<pre style="margin: 0em;">    public String getName(){
        return this.name;
    }</pre><br>
<pre style="margin: 0em;">    public String getAddress(){
        return this.address;
    }</pre><br>
<pre style="margin: 0em;">    public void setAddress(String address){
        this.address =
address;
    }</pre><br>
<pre style="margin: 0em;">    public String toString(){
        return &quot;&lt;User
[id:&quot;+id+&quot;][name:&quot;+name+&quot;][address:&quot;+address+&quot;]&gt;&quot;;
    }
}</pre><br>
<pre style="margin: 0em;"><br>PersistenceCreator.java</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">public class PersistenceCreator{
    private static EntityManagerFactory
factory;</pre><br>
<pre style="margin: 0em;">    public static EntityManagerFactory
createEntityManagerFactory(){
        if(null == factory)</pre><br>
<pre style="margin: 0em;">factory = new EntityManagerFactory();
        return factory;
    }
}</pre><br>
<pre style="margin: 0em;">EntityManagerFactory.java</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">public class EntityManagerFactory{</pre><br>
<pre style="margin: 0em;">    private static EntityManager manager;</pre><br>
<pre style="margin: 0em;">    public static EntityManager
createEntityManager(){
        if(null == manager){</pre><br>
<pre style="margin: 0em;">manager = new EntityManager();
        }
        return manager;
    }
}</pre><br>
<pre style="margin: 0em;">EntityManager.java</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">public class EntityManager{
}</pre><br>
<pre style="margin: 0em;">AbstractTransaction.aj</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">public abstract aspect AbstractTransaction
percflow(scope()){</pre><br>
<pre style="margin: 0em;">    private EntityManager manager;</pre><br>
<pre style="margin: 0em;">    protected abstract pointcut tx();</pre><br>
<pre style="margin: 0em;">    protected pointcut
obtainEntityManager(EntityManager manager): call(*
example.AccountDao.setEntityManager(EntityManager))
&amp;&amp; target(manager);</pre><br>
<pre style="margin: 0em;">    protected pointcut scope(): tx()
&amp;&amp; !cflowbelow(tx());</pre><br>
<pre style="margin: 0em;">    Object around(): scope(){</pre><br>
<pre style="margin: 0em;">System.out.println(&quot;EntityManager:&quot;+manager);// always null</pre><br>
<pre style="margin: 0em;">        Object result =
proceed();
        return result;
    }</pre><br>
<pre style="margin: 0em;">    EntityManager around(EntityManager
manager): obtainEntityManager(manager)
&amp;&amp; cflow(tx()){
        if(null == manager){</pre><br>
<pre style="margin: 0em;">manager = proceed(manager);</pre><br>
<tt>        }<br>
          
        return manager;<br>
    }<br>
}</tt><br>
<br>
<pre style="margin: 0em;">AccountTransaction.aj</pre><br>
<pre style="margin: 0em;">package example;</pre><br>
<pre style="margin: 0em;">public aspect AccountTransaction extends
AbstractTransaction{</pre><br>
<pre style="margin: 0em;">    protected pointcut tx(): execution(*
example.Main.process());
}
--
View this message in context:
<a  href="http://old.nabble.com/A-transaction-question-tp26195112p26195112.html">http://old.nabble.com/A-transaction-question-tp26195112p26195112.html</a>
Sent from the AspectJ - users mailing list archive at
Nabble.com.</pre><br>
<pre style="margin: 0em;">_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a></pre><br>
<tt>          
</tt></blockquote><pre style="margin: 0em;"><br>_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a></pre><br>
<tt><br>        
</tt></blockquote><pre style="margin: 0em;">--
View this message in context:
<a  href="http://old.nabble.com/A-transaction-question-tp26195112p26203290.html">http://old.nabble.com/A-transaction-question-tp26195112p26203290.html</a>
Sent from the AspectJ - users mailing list archive at Nabble.com.</pre><br>
<pre style="margin: 0em;">_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a></pre><br>
<tt>      
</tt></blockquote><pre style="margin: 0em;">_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a></pre><br>
<tt><br>    
</tt></blockquote><tt><br>  
</tt></blockquote><pre style="margin: 0em;"><br></pre><br>
<pre style="margin: 0em;">--
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
<a  href="http://www.simonegianni.it/">http://www.simonegianni.it/</a></pre><br>
<br>
]]></content:encoded>
		<pubDate>Fri, 06 Nov 2009 11:27:53 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11455.html</guid>
		<author>simoneg@xxxxxxx (Simone Gianni)</author>
	</item>
	<item>
		<title>Re: [aspectj-users] Newbie question about paramter exposure.</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11454.html</link>
		<description> </description>
		<content:encoded><![CDATA[<pre>
I just found out that in Aspectj in Action, it explains the passing context
from a join point to advice is as below:

The interpretation of context whilst using advice looks like

	Object advice(String command): p(command){
		...
	}

1.) command passing in to pointcut p()
2.) the execution object command is passed to advice(String command)
3.) which then passes to the body {...}.



neo anderson wrote:
&gt; 
&gt; Just want to practise to see if I understand it correctly.
&gt; 
&gt; The point of interest 
&gt; 
&gt; 	A.execute(&quot;ls -alh&quot;) 
&gt; 
&gt; is reached. 
&gt; 
&gt; That point of interest is specified in 
&gt; 
&gt; 	execution(* example.A.execute(String)) &amp;&amp; args(command); 
&gt; 
&gt; So the parameter value being passed in (i.e. ls -alh) is bound to the
&gt; command 
&gt; parameter in the pointcut p(String command). Thus the value of `command'
&gt; (in pointcut p(String command)) now can be replaced with &quot;ls -alh&quot; (whilst
&gt; method's executing).
&gt; 
&gt; And because an advice around(String command) is attached to the pointcut
&gt; p(String command), when the method execution join point occurs, it becomes
&gt; 
&gt; 	Object advice(String command): p(&quot;ls -alh&quot;){
&gt; 		...
&gt; 	}
&gt; 
&gt; And then when advice is invoked 
&gt; 
&gt; 	Object advice(&quot;ls -alh&quot;): p(&quot;ls -alh&quot;){
&gt; 		...
&gt; 	}
&gt; 
&gt; Am I correct to the above explanation? 
&gt; 
&gt; I discover my problem is because after reading the book e.g. Aspectj in
&gt; Action, I still do not understand very well about the flow that goes
&gt; between joint points, pointcuts and advices. In a traditional method call,
&gt; I understand (maybe not precisely) that in the class Main, when executing
&gt; `new A().execute(&quot;ls -alh&quot;)', the value `ls -alh' will pass in to the
&gt; execute() method of the class A; therefore, in the execute() function of
&gt; the class A, the variable `command' can be replaced using the value `ls
&gt; -alh' and gets printed using System.out.println() method in execution. 
&gt; 
&gt; But concept of aop looks like not the same way; so it makes me confused.
&gt; 
&gt; Please correct me if anything goes wrong. 
&gt; 
&gt; Thanks for your help. 
&gt; 
&gt; I really appreciate it.
&gt; 
&gt; 
&gt; 
&gt; 
&gt; 
&gt; Andy Clement wrote:
&gt;&gt; 
&gt;&gt; Hi,
&gt;&gt; 
&gt;&gt; Your description is ok:
&gt;&gt; 
&gt;&gt;&gt; therefore, execution of the method `new A().execute(&quot;ls -alh&quot;)' triggers
&gt;&gt;&gt; the around() advice, which passes in a value `ls -lah' (as the variable
&gt;&gt;&gt; command). That value `ls -alh' passes to
&gt;&gt;&gt; pointcut p(), which also takes a variable named command. And that
&gt;&gt;&gt; pointcut p() tries to capture the execution of a method specified as `*
&gt;&gt;&gt; example.A.execute(String)' and its argument
&gt;&gt;&gt; must be `command.'
&gt;&gt; 
&gt;&gt; let me write it another way to see if that helps.  Think about the
&gt;&gt; events that occur when the program runs:
&gt;&gt; Main.main() starts executing
&gt;&gt; it calls the Main() constructor
&gt;&gt; it calls the process() method
&gt;&gt; Main.process() method starts executing
&gt;&gt; it calls the A() constructor
&gt;&gt; it calls the execute(&quot;ls -alh&quot;) method
&gt;&gt; A.execute(&quot;ls -alh&quot;)  method starts executing *
&gt;&gt; it accesses the field System.out
&gt;&gt; it calls the method println()
&gt;&gt; 
&gt;&gt; all those are the joinpoints in your program flow and your pointcut is
&gt;&gt; choosing the one you are interested in.  You have used 'execution(*
&gt;&gt; execute(String))' which has selected the one I've marked * above.  In
&gt;&gt; your pointcut you've also said you are interested in the parameter
&gt;&gt; when the method executes, so you have used 'args' to bind it - so when
&gt;&gt; the program runs and your point of interest is reached, the parameter
&gt;&gt; value being passed in is bound to the command parameter in your
&gt;&gt; pointcut.  You have chosen to have around() advice attached to that
&gt;&gt; pointcut so when the method-execution join point occurs, your around
&gt;&gt; advice is invoked with the bound parameter value.  Unlike a regular
&gt;&gt; method call, the weaving infrastructure is looking after binding the
&gt;&gt; pointcut/advice parameter for you.
&gt;&gt; 
&gt;&gt; Andy
&gt;&gt; 
&gt;&gt; 
&gt;&gt; 
&gt;&gt; 2009/10/27 Neo Anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;:
&gt;&gt;&gt; Hi
&gt;&gt;&gt;
&gt;&gt;&gt; I am newbie to aspectj and have a question regarding to the usage of
&gt;&gt;&gt; parameters exposed in the pointcut, advice, etc. Following is the source
&gt;&gt;&gt; code:
&gt;&gt;&gt;
&gt;&gt;&gt; package aspectj;
&gt;&gt;&gt;
&gt;&gt;&gt; public aspect P{
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;public pointcut p(String command): execution(*
&gt;&gt;&gt; example.A.execute(String)) &amp;&amp; args(command);
&gt;&gt;&gt;
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;Object around(String command): p(command){
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2;System.out.println(&quot;around() advice : command:&quot;+command);
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2;return proceed(command);
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;}
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public class A{
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;public void execute(String c){
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2;System.out.println(&quot;[A.java][execute] command:&quot;+c);
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;}
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public class Main{
&gt;&gt;&gt;
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;public static void main(String args[]){
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2;new Main().process();
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;}
&gt;&gt;&gt;
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;void process(){
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2; &#xC2;new A().execute(&quot;ls -alh&quot;);
&gt;&gt;&gt; &#xC2; &#xC2; &#xC2; &#xC2;}
&gt;&gt;&gt;
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; The output :
&gt;&gt;&gt;
&gt;&gt;&gt; around() advice : command:ls -alh
&gt;&gt;&gt; [A.java][execute] command:ls -alh
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Thought I can get the code worked, I do not know how to explain the
&gt;&gt;&gt; parameter exposed in the pointcut (e.g. p(String command)) and advice
&gt;&gt;&gt; (e.g. around(String command)).
&gt;&gt;&gt;
&gt;&gt;&gt; What I understand is that
&gt;&gt;&gt;
&gt;&gt;&gt; Since the execution flow is
&gt;&gt;&gt;
&gt;&gt;&gt; new A().execute(&quot;ls -lah&quot;) [Main.java] -&gt; public void execute(String c)
&gt;&gt;&gt; [A.java]
&gt;&gt;&gt;
&gt;&gt;&gt; therefore, execution of the method `new A().execute(&quot;ls -alh&quot;)' triggers
&gt;&gt;&gt; the around() advice, which passes in a value `ls -lah' (as the variable
&gt;&gt;&gt; command). That value `ls -alh' passes to pointcut p(), which also takes
&gt;&gt;&gt; a variable named command. And that pointcut p() tries to capture the
&gt;&gt;&gt; execution of a method specified as `* example.A.execute(String)' and its
&gt;&gt;&gt; argument must be `command.'
&gt;&gt;&gt;
&gt;&gt;&gt; Is this explanation correct?
&gt;&gt;&gt;
&gt;&gt;&gt; I found out there is something not right for me, but I am not aware the
&gt;&gt;&gt; part that I do not understand.
&gt;&gt;&gt;
&gt;&gt;&gt; I appreciate any advice.
&gt;&gt;&gt;
&gt;&gt;&gt; Thank you very much.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Send instant messages to your online friends
&gt;&gt;&gt; <a  href="http://uk.messenger.yahoo.com">http://uk.messenger.yahoo.com</a>
&gt;&gt;&gt; _______________________________________________
&gt;&gt;&gt; aspectj-users mailing list
&gt;&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt;&gt;
&gt;&gt; _______________________________________________
&gt;&gt; aspectj-users mailing list
&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt; 
&gt;&gt; 
&gt; 
&gt; 

-- 
View this message in context: <a  href="http://old.nabble.com/Newbie-question-about-paramter-exposure.-tp26077620p26230259.html">http://old.nabble.com/Newbie-question-about-paramter-exposure.-tp26077620p26230259.html</a>
Sent from the AspectJ - users mailing list archive at Nabble.com.


</pre>]]></content:encoded>
		<pubDate>Fri, 06 Nov 2009 11:16:13 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11454.html</guid>
		<author>javadeveloper999@xxxxxxx (neo anderson)</author>
	</item>
	<item>
		<title>Re: [aspectj-users] A transaction question</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11453.html</link>
		<description> </description>
		<content:encoded><![CDATA[<pre>
Thank you very much. Now I am able to obtain EntityManager whilst method
setEntityManager get called. 

But a new question: how can I assign the captured variable e.g.
EntityManager to the variable in an Aspect? For instance, 

... aspect AbstractionTransaction ...{
        private EntityManager manager;
        void around(EntityManager manager): obtainEntityManager(manager) &amp;&amp;
cflow(tx()){
System.out.println(&quot;manager:&quot;+manager); // manager instance is not null
                this.manager = manager; // but assign to the member of
aspect seemingly does not work

                proceed(manager);
        }

}

My AbstractTransaction aspect contains a variable manager and I would like
to assign when the setEntityManager get called. Because in the example of
Aspectj in Action, the method intercepted will return Connection, which is
different from the method I have. Is there any chance to assign the variable
so that I can apply entitymanager to the pointcut when scope() is executed?
Or what is the right way to do this?

       Object around(): scope(){
System.out.println(&quot;===========&gt; EntityManager:&quot;+manager); // after
assigned, it is still null
                Object result = proceed();
                return result;
        }

Sorry if this question is too newbie. I search on the internet and read
again the book Aspectj in Action, but seems there is no such explain. 

Thanks for patiently answer my question. 

I appreciate it. 




Andy Clement wrote:
&gt; 
&gt; The method you are intercepting (setEntityManager) has a void return
&gt; type, so your advice should too.  The proceed() call you are using
&gt; will ensure your replacement is passed to the setEntityManager call.
&gt; 
&gt; Andy
&gt; 
&gt; 2009/11/4 neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;:
&gt;&gt;
&gt;&gt; Hi Mark &amp; Andy. Thanks for your reply. I really appreciate your help.
&gt;&gt;
&gt;&gt; I change to use args, but now it thorws message:
&gt;&gt;
&gt;&gt; [error] incompatible return type applying to method-call(void
&gt;&gt; example.AccountDao.setEntityManager(example.EntityManager))
&gt;&gt;
&gt;&gt; [error] incompatible return type applying to method-call(void
&gt;&gt; example.AccountDao.setEntityManager(example.EntityManager))
&gt;&gt; dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
&gt;&gt;
&gt;&gt; [warning] advice defined in example.AbstractTransaction has not been
&gt;&gt; applied
&gt;&gt; [Xlint:adviceDidNotMatch]
&gt;&gt;
&gt;&gt; I check the syntax and read the example in e.g.
&gt;&gt; <a  href="http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false">http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false</a>
&gt;&gt;
&gt;&gt; The way to capture the EntityManager looks correct.
&gt;&gt;
&gt;&gt; public pointcut(EntityManager manager): call(*
&gt;&gt; AccountDao.setEntityManager(EntityManger)) &amp;&amp; args(manager);
&gt;&gt;
&gt;&gt; Is there any place I may go wrong? I test to move the .aj files and
&gt;&gt; compile
&gt;&gt; .java source. Everthing works fine. I am confused.
&gt;&gt;
&gt;&gt; I appreciate any suggestion.
&gt;&gt;
&gt;&gt; Thank you very much.
&gt;&gt;
&gt;&gt;
&gt;&gt; Mark Cooke-6 wrote:
&gt;&gt;&gt;
&gt;&gt;&gt; Hi,
&gt;&gt;&gt; It's been a while since I've used AspectJ in anger but as no-one else
&gt;&gt;&gt; has
&gt;&gt;&gt; replied yet...
&gt;&gt;&gt;
&gt;&gt;&gt; I'd say you probably want &quot;args(manager)&quot; instead of &quot;target(manager)&quot;
&gt;&gt;&gt; in
&gt;&gt;&gt; the obtainEntityManager pointcut.
&gt;&gt;&gt; The target of the call will be an AccountDAO, not an EntityManager.
&gt;&gt;&gt;
&gt;&gt;&gt; See
&gt;&gt;&gt; <a  href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html">http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html</a>
&gt;&gt;&gt;
&gt;&gt;&gt; HTH!
&gt;&gt;&gt; Mark.
&gt;&gt;&gt;
&gt;&gt;&gt; --- On Wed, 4/11/09, neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt; wrote:
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; From: neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;
&gt;&gt;&gt;&gt; Subject: [aspectj-users] A transaction question
&gt;&gt;&gt;&gt; To: aspectj-users@xxxxxxxxxxx
&gt;&gt;&gt;&gt; Date: Wednesday, 4 November, 2009, 12:09
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I am learning how to modulize transaction using aspectj,
&gt;&gt;&gt;&gt; but encounter a
&gt;&gt;&gt;&gt; problem that EntityManager I try to capture is always null.
&gt;&gt;&gt;&gt; The compiler
&gt;&gt;&gt;&gt; issues message saying that the advice can not be applied.
&gt;&gt;&gt;&gt; as below:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; ... advice defined in example.AbstractTransaction has not
&gt;&gt;&gt;&gt; been applied
&gt;&gt;&gt;&gt; [Xlint:adviceDidNotMatch]
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; What should I change so that I can capture the
&gt;&gt;&gt;&gt; EntityManager while it is
&gt;&gt;&gt;&gt; created (whilst calling to
&gt;&gt;&gt;&gt; AccountDao.setEntityManager(..))?
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thanks for help.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Main.java
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class Main{
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public static void main(String args[]){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; Main m = new Main();
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; m.process();
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; void process(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; AccountDao dao = new
&gt;&gt;&gt;&gt; AccountDao();
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; User u = new
&gt;&gt;&gt;&gt; User(&quot;1&quot;, &quot;Smith&quot;);
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; u.setAddress(&quot;123
&gt;&gt;&gt;&gt; Test Road, London.&quot;);
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; dao.save(u);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; dao.list();
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; AccountDao.java
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; import java.util.List;
&gt;&gt;&gt;&gt; import java.util.ArrayList;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class AccountDao{
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private EntityManager manager;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private static List&lt;User&gt; database
&gt;&gt;&gt;&gt; = new ArrayList&lt;User&gt;();
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public void
&gt;&gt;&gt;&gt; setEntityManager(EntityManager manager){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.manager =
&gt;&gt;&gt;&gt; manager;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public void save(User user){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; database.add(user);
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public void list(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; for(User u :
&gt;&gt;&gt;&gt; database){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; System.out.println(&quot;&gt;&gt;&gt;[AccountDao.java]&quot;+u);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; User.java
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class User{
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private String id;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private String name;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private String address;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public User(String id, String name){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.id = id;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.name = name;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public String getId(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return this.id;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public String getName(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return this.name;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public String getAddress(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return this.address;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public void setAddress(String address){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.address =
&gt;&gt;&gt;&gt; address;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public String toString(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return &quot;&lt;User
&gt;&gt;&gt;&gt; [id:&quot;+id+&quot;][name:&quot;+name+&quot;][address:&quot;+address+&quot;]&gt;&quot;;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; PersistenceCreator.java
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class PersistenceCreator{
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private static EntityManagerFactory
&gt;&gt;&gt;&gt; factory;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public static EntityManagerFactory
&gt;&gt;&gt;&gt; createEntityManagerFactory(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; if(null == factory)
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; factory = new EntityManagerFactory();
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return factory;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; EntityManagerFactory.java
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class EntityManagerFactory{
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private static EntityManager manager;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; public static EntityManager
&gt;&gt;&gt;&gt; createEntityManager(){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; if(null == manager){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; manager = new EntityManager();
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return manager;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; EntityManager.java
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class EntityManager{
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; AbstractTransaction.aj
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public abstract aspect AbstractTransaction
&gt;&gt;&gt;&gt; percflow(scope()){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; private EntityManager manager;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; protected abstract pointcut tx();
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; protected pointcut
&gt;&gt;&gt;&gt; obtainEntityManager(EntityManager manager): call(*
&gt;&gt;&gt;&gt; example.AccountDao.setEntityManager(EntityManager))
&gt;&gt;&gt;&gt; &amp;&amp; target(manager);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; protected pointcut scope(): tx()
&gt;&gt;&gt;&gt; &amp;&amp; !cflowbelow(tx());
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; Object around(): scope(){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; System.out.println(&quot;EntityManager:&quot;+manager);// always null
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; Object result =
&gt;&gt;&gt;&gt; proceed();
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return result;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; EntityManager around(EntityManager
&gt;&gt;&gt;&gt; manager): obtainEntityManager(manager)
&gt;&gt;&gt;&gt; &amp;&amp; cflow(tx()){
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; if(null == manager){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; manager = proceed(manager);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return manager;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; AccountTransaction.aj
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; package example;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public aspect AccountTransaction extends
&gt;&gt;&gt;&gt; AbstractTransaction{
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &#xC2;&#xC2;&#xC2; protected pointcut tx(): execution(*
&gt;&gt;&gt;&gt; example.Main.process());
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt; --
&gt;&gt;&gt;&gt; View this message in context:
&gt;&gt;&gt;&gt; <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26195112.html">http://old.nabble.com/A-transaction-question-tp26195112p26195112.html</a>
&gt;&gt;&gt;&gt; Sent from the AspectJ - users mailing list archive at
&gt;&gt;&gt;&gt; Nabble.com.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; _______________________________________________
&gt;&gt;&gt;&gt; aspectj-users mailing list
&gt;&gt;&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt;&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; _______________________________________________
&gt;&gt;&gt; aspectj-users mailing list
&gt;&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt; --
&gt;&gt; View this message in context:
&gt;&gt; <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26203290.html">http://old.nabble.com/A-transaction-question-tp26195112p26203290.html</a>
&gt;&gt; Sent from the AspectJ - users mailing list archive at Nabble.com.
&gt;&gt;
&gt;&gt; _______________________________________________
&gt;&gt; aspectj-users mailing list
&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt;
&gt; _______________________________________________
&gt; aspectj-users mailing list
&gt; aspectj-users@xxxxxxxxxxx
&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt; 
&gt; 

-- 
View this message in context: <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26229210.html">http://old.nabble.com/A-transaction-question-tp26195112p26229210.html</a>
Sent from the AspectJ - users mailing list archive at Nabble.com.


</pre>]]></content:encoded>
		<pubDate>Fri, 06 Nov 2009 10:21:28 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11453.html</guid>
		<author>javadeveloper999@xxxxxxx (neo anderson)</author>
	</item>


	<item>
		<title>Re: [aspectj-users] A transaction question</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11452.html</link>
		<description>The method you are intercepting (setEntityManager) has a void return type, so your advice should too. The proceed() call you are using will ensure your replacement is passed to the setEntityManager call. Andy 2009/11/4 neo anderson &amp;lt;javadeveloper999@xxxxxx...</description>
		<content:encoded><![CDATA[<pre>The method you are intercepting (setEntityManager) has a void return
type, so your advice should too.  The proceed() call you are using
will ensure your replacement is passed to the setEntityManager call.

Andy

2009/11/4 neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;:
&gt;
&gt; Hi Mark &amp; Andy. Thanks for your reply. I really appreciate your help.
&gt;
&gt; I change to use args, but now it thorws message:
&gt;
&gt; [error] incompatible return type applying to method-call(void
&gt; example.AccountDao.setEntityManager(example.EntityManager))
&gt;
&gt; [error] incompatible return type applying to method-call(void
&gt; example.AccountDao.setEntityManager(example.EntityManager))
&gt; dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
&gt;
&gt; [warning] advice defined in example.AbstractTransaction has not been applied
&gt; [Xlint:adviceDidNotMatch]
&gt;
&gt; I check the syntax and read the example in e.g.
&gt; <a  href="http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false">http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false</a>
&gt;
&gt; The way to capture the EntityManager looks correct.
&gt;
&gt; public pointcut(EntityManager manager): call(*
&gt; AccountDao.setEntityManager(EntityManger)) &amp;&amp; args(manager);
&gt;
&gt; Is there any place I may go wrong? I test to move the .aj files and compile
&gt; .java source. Everthing works fine. I am confused.
&gt;
&gt; I appreciate any suggestion.
&gt;
&gt; Thank you very much.
&gt;
&gt;
&gt; Mark Cooke-6 wrote:
&gt;&gt;
&gt;&gt; Hi,
&gt;&gt; It's been a while since I've used AspectJ in anger but as no-one else has
&gt;&gt; replied yet...
&gt;&gt;
&gt;&gt; I'd say you probably want &quot;args(manager)&quot; instead of &quot;target(manager)&quot; in
&gt;&gt; the obtainEntityManager pointcut.
&gt;&gt; The target of the call will be an AccountDAO, not an EntityManager.
&gt;&gt;
&gt;&gt; See
&gt;&gt; <a  href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html">http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html</a>
&gt;&gt;
&gt;&gt; HTH!
&gt;&gt; Mark.
&gt;&gt;
&gt;&gt; --- On Wed, 4/11/09, neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt; wrote:
&gt;&gt;
&gt;&gt;&gt; From: neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;
&gt;&gt;&gt; Subject: [aspectj-users] A transaction question
&gt;&gt;&gt; To: aspectj-users@xxxxxxxxxxx
&gt;&gt;&gt; Date: Wednesday, 4 November, 2009, 12:09
&gt;&gt;&gt;
&gt;&gt;&gt; I am learning how to modulize transaction using aspectj,
&gt;&gt;&gt; but encounter a
&gt;&gt;&gt; problem that EntityManager I try to capture is always null.
&gt;&gt;&gt; The compiler
&gt;&gt;&gt; issues message saying that the advice can not be applied.
&gt;&gt;&gt; as below:
&gt;&gt;&gt;
&gt;&gt;&gt; ... advice defined in example.AbstractTransaction has not
&gt;&gt;&gt; been applied
&gt;&gt;&gt; [Xlint:adviceDidNotMatch]
&gt;&gt;&gt;
&gt;&gt;&gt; What should I change so that I can capture the
&gt;&gt;&gt; EntityManager while it is
&gt;&gt;&gt; created (whilst calling to
&gt;&gt;&gt; AccountDao.setEntityManager(..))?
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks for help.
&gt;&gt;&gt;
&gt;&gt;&gt; Main.java
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public class Main{
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public static void main(String args[]){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; Main m = new Main();
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; m.process();
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; void process(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; AccountDao dao = new
&gt;&gt;&gt; AccountDao();
&gt;&gt;&gt;
&gt;&gt;&gt; dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; User u = new
&gt;&gt;&gt; User(&quot;1&quot;, &quot;Smith&quot;);
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; u.setAddress(&quot;123
&gt;&gt;&gt; Test Road, London.&quot;);
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; dao.save(u);
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; dao.list();
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; AccountDao.java
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; import java.util.List;
&gt;&gt;&gt; import java.util.ArrayList;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; public class AccountDao{
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private EntityManager manager;
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private static List&lt;User&gt; database
&gt;&gt;&gt; = new ArrayList&lt;User&gt;();
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public void
&gt;&gt;&gt; setEntityManager(EntityManager manager){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.manager =
&gt;&gt;&gt; manager;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public void save(User user){
&gt;&gt;&gt;
&gt;&gt;&gt; database.add(user);
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public void list(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; for(User u :
&gt;&gt;&gt; database){
&gt;&gt;&gt;
&gt;&gt;&gt; System.out.println(&quot;&gt;&gt;&gt;[AccountDao.java]&quot;+u);
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; User.java
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public class User{
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private String id;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private String name;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private String address;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public User(String id, String name){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.id = id;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.name = name;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public String getId(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return this.id;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public String getName(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return this.name;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public String getAddress(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return this.address;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public void setAddress(String address){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.address =
&gt;&gt;&gt; address;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public String toString(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return &quot;&lt;User
&gt;&gt;&gt; [id:&quot;+id+&quot;][name:&quot;+name+&quot;][address:&quot;+address+&quot;]&gt;&quot;;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; PersistenceCreator.java
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public class PersistenceCreator{
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private static EntityManagerFactory
&gt;&gt;&gt; factory;
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public static EntityManagerFactory
&gt;&gt;&gt; createEntityManagerFactory(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; if(null == factory)
&gt;&gt;&gt;
&gt;&gt;&gt; factory = new EntityManagerFactory();
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return factory;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; EntityManagerFactory.java
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public class EntityManagerFactory{
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private static EntityManager manager;
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; public static EntityManager
&gt;&gt;&gt; createEntityManager(){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; if(null == manager){
&gt;&gt;&gt;
&gt;&gt;&gt; manager = new EntityManager();
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return manager;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; EntityManager.java
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public class EntityManager{
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; AbstractTransaction.aj
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public abstract aspect AbstractTransaction
&gt;&gt;&gt; percflow(scope()){
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; private EntityManager manager;
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; protected abstract pointcut tx();
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; protected pointcut
&gt;&gt;&gt; obtainEntityManager(EntityManager manager): call(*
&gt;&gt;&gt; example.AccountDao.setEntityManager(EntityManager))
&gt;&gt;&gt; &amp;&amp; target(manager);
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; protected pointcut scope(): tx()
&gt;&gt;&gt; &amp;&amp; !cflowbelow(tx());
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; Object around(): scope(){
&gt;&gt;&gt;
&gt;&gt;&gt; System.out.println(&quot;EntityManager:&quot;+manager);// always null
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; Object result =
&gt;&gt;&gt; proceed();
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return result;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; EntityManager around(EntityManager
&gt;&gt;&gt; manager): obtainEntityManager(manager)
&gt;&gt;&gt; &amp;&amp; cflow(tx()){
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; if(null == manager){
&gt;&gt;&gt;
&gt;&gt;&gt; manager = proceed(manager);
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; }
&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return manager;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; AccountTransaction.aj
&gt;&gt;&gt;
&gt;&gt;&gt; package example;
&gt;&gt;&gt;
&gt;&gt;&gt; public aspect AccountTransaction extends
&gt;&gt;&gt; AbstractTransaction{
&gt;&gt;&gt;
&gt;&gt;&gt; &#xA0;&#xA0;&#xA0; protected pointcut tx(): execution(*
&gt;&gt;&gt; example.Main.process());
&gt;&gt;&gt; }
&gt;&gt;&gt; --
&gt;&gt;&gt; View this message in context:
&gt;&gt;&gt; <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26195112.html">http://old.nabble.com/A-transaction-question-tp26195112p26195112.html</a>
&gt;&gt;&gt; Sent from the AspectJ - users mailing list archive at
&gt;&gt;&gt; Nabble.com.
&gt;&gt;&gt;
&gt;&gt;&gt; _______________________________________________
&gt;&gt;&gt; aspectj-users mailing list
&gt;&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt; _______________________________________________
&gt;&gt; aspectj-users mailing list
&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt;
&gt;&gt;
&gt;
&gt; --
&gt; View this message in context: <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26203290.html">http://old.nabble.com/A-transaction-question-tp26195112p26203290.html</a>
&gt; Sent from the AspectJ - users mailing list archive at Nabble.com.
&gt;
&gt; _______________________________________________
&gt; aspectj-users mailing list
&gt; aspectj-users@xxxxxxxxxxx
&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;

</pre>]]></content:encoded>
		<pubDate>Wed, 04 Nov 2009 19:42:53 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11452.html</guid>
		<author>andrew.clement@xxxxxxx (Andy Clement)</author>
	</item>
	<item>
		<title>Re: [aspectj-users] A transaction question</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11451.html</link>
		<description> </description>
		<content:encoded><![CDATA[<pre>
Hi Mark &amp; Andy. Thanks for your reply. I really appreciate your help. 

I change to use args, but now it thorws message:

[error] incompatible return type applying to method-call(void
example.AccountDao.setEntityManager(example.EntityManager))

[error] incompatible return type applying to method-call(void
example.AccountDao.setEntityManager(example.EntityManager))
dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());

[warning] advice defined in example.AbstractTransaction has not been applied
[Xlint:adviceDidNotMatch]

I check the syntax and read the example in e.g.
<a  href="http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false">http://books.google.com.tw/books?id=AKuBlJGl7iUC&amp;pg=PA54&amp;lpg=PA54&amp;dq=aspectj+call+args&amp;source=bl&amp;ots=58KGnyCZiN&amp;sig=5gNdHoekFrDXJne3pVe6UO5tiYQ&amp;hl=zh-TW&amp;ei=kNbxSqTEBumgjAfdnp2WAQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CB0Q6AEwBQ#v=onepage&amp;q=4-2%20capturing%20the%20parameter%20values%20passed%20on%20a%20method%20call&amp;f=false</a>

The way to capture the EntityManager looks correct. 

public pointcut(EntityManager manager): call(*
AccountDao.setEntityManager(EntityManger)) &amp;&amp; args(manager);

Is there any place I may go wrong? I test to move the .aj files and compile
.java source. Everthing works fine. I am confused.

I appreciate any suggestion. 

Thank you very much.


Mark Cooke-6 wrote:
&gt; 
&gt; Hi,
&gt; It's been a while since I've used AspectJ in anger but as no-one else has
&gt; replied yet...
&gt; 
&gt; I'd say you probably want &quot;args(manager)&quot; instead of &quot;target(manager)&quot; in
&gt; the obtainEntityManager pointcut.
&gt; The target of the call will be an AccountDAO, not an EntityManager.
&gt; 
&gt; See
&gt; <a  href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html">http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html</a>
&gt; 
&gt; HTH!
&gt; Mark.
&gt; 
&gt; --- On Wed, 4/11/09, neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt; wrote:
&gt; 
&gt;&gt; From: neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;
&gt;&gt; Subject: [aspectj-users] A transaction question
&gt;&gt; To: aspectj-users@xxxxxxxxxxx
&gt;&gt; Date: Wednesday, 4 November, 2009, 12:09
&gt;&gt; 
&gt;&gt; I am learning how to modulize transaction using aspectj,
&gt;&gt; but encounter a
&gt;&gt; problem that EntityManager I try to capture is always null.
&gt;&gt; The compiler
&gt;&gt; issues message saying that the advice can not be applied.
&gt;&gt; as below:
&gt;&gt; 
&gt;&gt; ... advice defined in example.AbstractTransaction has not
&gt;&gt; been applied
&gt;&gt; [Xlint:adviceDidNotMatch]
&gt;&gt; 
&gt;&gt; What should I change so that I can capture the
&gt;&gt; EntityManager while it is
&gt;&gt; created (whilst calling to
&gt;&gt; AccountDao.setEntityManager(..))?
&gt;&gt; 
&gt;&gt; Thanks for help.
&gt;&gt; 
&gt;&gt; Main.java
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; public class Main{
&gt;&gt; &#xC2;&#xC2;&#xC2; public static void main(String args[]){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; Main m = new Main();
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; m.process();
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; &#xC2;&#xC2;&#xC2; void process(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; AccountDao dao = new
&gt;&gt; AccountDao();
&gt;&gt; &#xC2;&#xC2;&#xC2; 
&gt;&gt; dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; User u = new
&gt;&gt; User(&quot;1&quot;, &quot;Smith&quot;);
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; u.setAddress(&quot;123
&gt;&gt; Test Road, London.&quot;);
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; dao.save(u);
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2;
&gt;&gt; dao.list();&#xC2;&#xC2;&#xC2; 
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; AccountDao.java
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; import java.util.List;
&gt;&gt; import java.util.ArrayList;
&gt;&gt; 
&gt;&gt; 
&gt;&gt; public class AccountDao{
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; private EntityManager manager;
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; private static List&lt;User&gt; database
&gt;&gt; = new ArrayList&lt;User&gt;();
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public void
&gt;&gt; setEntityManager(EntityManager manager){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.manager =
&gt;&gt; manager;
&gt;&gt; &#xC2;&#xC2;&#xC2; }&#xC2;&#xC2;&#xC2; 
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public void save(User user){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2;
&gt;&gt; database.add(user);&#xC2;&#xC2;&#xC2; 
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public void list(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; for(User u :
&gt;&gt; database){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2;
&gt;&gt; System.out.println(&quot;&gt;&gt;&gt;[AccountDao.java]&quot;+u);&#xC2;&#xC2;&#xC2;
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; }
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; User.java
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; public class User{
&gt;&gt; &#xC2;&#xC2;&#xC2; private String id;
&gt;&gt; &#xC2;&#xC2;&#xC2; private String name;
&gt;&gt; &#xC2;&#xC2;&#xC2; private String address;
&gt;&gt; &#xC2;&#xC2;&#xC2; public User(String id, String name){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.id = id;
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.name = name;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public String getId(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return this.id;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public String getName(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return this.name;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public String getAddress(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return this.address;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public void setAddress(String address){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; this.address =
&gt;&gt; address;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public String toString(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return &quot;&lt;User
&gt;&gt; [id:&quot;+id+&quot;][name:&quot;+name+&quot;][address:&quot;+address+&quot;]&gt;&quot;;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; 
&gt;&gt; PersistenceCreator.java
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; public class PersistenceCreator{
&gt;&gt; &#xC2;&#xC2;&#xC2; private static EntityManagerFactory
&gt;&gt; factory;
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public static EntityManagerFactory
&gt;&gt; createEntityManagerFactory(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; if(null == factory)
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2;
&gt;&gt; factory = new EntityManagerFactory();
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return factory;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; EntityManagerFactory.java
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; public class EntityManagerFactory{
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; private static EntityManager manager;
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; public static EntityManager
&gt;&gt; createEntityManager(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; if(null == manager){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2;
&gt;&gt; manager = new EntityManager();
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; }
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return manager;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; EntityManager.java
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; public class EntityManager{
&gt;&gt; }
&gt;&gt; 
&gt;&gt; AbstractTransaction.aj
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; public abstract aspect AbstractTransaction
&gt;&gt; percflow(scope()){
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; private EntityManager manager;
&gt;&gt; &#xC2;&#xC2;&#xC2; 
&gt;&gt; &#xC2;&#xC2;&#xC2; protected abstract pointcut tx();
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; protected pointcut
&gt;&gt; obtainEntityManager(EntityManager manager): call(*
&gt;&gt; example.AccountDao.setEntityManager(EntityManager))
&gt;&gt; &amp;&amp; target(manager);
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; protected pointcut scope(): tx()
&gt;&gt; &amp;&amp; !cflowbelow(tx());
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; Object around(): scope(){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2;
&gt;&gt; System.out.println(&quot;EntityManager:&quot;+manager);// always null
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; Object result =
&gt;&gt; proceed();
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return result;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; EntityManager around(EntityManager
&gt;&gt; manager): obtainEntityManager(manager)
&gt;&gt; &amp;&amp; cflow(tx()){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; if(null == manager){
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2;
&gt;&gt; manager = proceed(manager);
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; 
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; }
&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; &#xC2;&#xC2;&#xC2; return manager;
&gt;&gt; &#xC2;&#xC2;&#xC2; }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; AccountTransaction.aj
&gt;&gt; 
&gt;&gt; package example;
&gt;&gt; 
&gt;&gt; public aspect AccountTransaction extends
&gt;&gt; AbstractTransaction{
&gt;&gt; 
&gt;&gt; &#xC2;&#xC2;&#xC2; protected pointcut tx(): execution(*
&gt;&gt; example.Main.process());
&gt;&gt; }
&gt;&gt; -- 
&gt;&gt; View this message in context:
&gt;&gt; <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26195112.html">http://old.nabble.com/A-transaction-question-tp26195112p26195112.html</a>
&gt;&gt; Sent from the AspectJ - users mailing list archive at
&gt;&gt; Nabble.com.
&gt;&gt; 
&gt;&gt; _______________________________________________
&gt;&gt; aspectj-users mailing list
&gt;&gt; aspectj-users@xxxxxxxxxxx
&gt;&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;&gt; 
&gt; 
&gt; 
&gt; 
&gt; _______________________________________________
&gt; aspectj-users mailing list
&gt; aspectj-users@xxxxxxxxxxx
&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt; 
&gt; 

-- 
View this message in context: <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26203290.html">http://old.nabble.com/A-transaction-question-tp26195112p26203290.html</a>
Sent from the AspectJ - users mailing list archive at Nabble.com.


</pre>]]></content:encoded>
		<pubDate>Wed, 04 Nov 2009 19:39:13 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11451.html</guid>
		<author>javadeveloper999@xxxxxxx (neo anderson)</author>
	</item>
	<item>
		<title>Re: [aspectj-users] Intertype declarations results in too long names</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11450.html</link>
		<description>Just to say, if you annotate the ITD, that will be on the introduced target method - you don't need an additional 'declare @method'. @javax.persistence.Id @javax .persistence .GeneratedValue(strategy=javax.persistence.GenerationType.AUTO) @javax.persistenc...</description>
		<content:encoded><![CDATA[<tt>Huh, I would have sworn I had tried that in the past and it hadn't  
worked.  Thanks for the tip.</tt><br>
<br>
<pre style="margin: 0em;">On Nov 2, 2009, at 5:53 PM, Andy Clement wrote:</pre><br>
<blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><tt>but that adds in a declare statement
</tt></blockquote><pre style="margin: 0em;"><br>Just to say, if you annotate the ITD, that will be on the introduced
target method - you don't need an additional 'declare @method'.</pre><br>
<blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><tt>From a Roo project:
</tt></blockquote><tt>   @javax.persistence.Id<br>
    
@javax 
.persistence 
.GeneratedValue(strategy=javax.persistence.GenerationType.AUTO)<br>
   @javax.persistence.Column(name=&quot;id&quot;)<br>
   private java.lang.Long Pet.id;</tt><br>
<br>
<pre style="margin: 0em;">cheers,
Andy</pre><br>
<tt>2009/11/2 Dave Whittaker &lt;dave@xxxxxxxxxx&gt;:
</tt><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><tt>Just thought I'd throw in here with a case where I've ran into  
problems with<br>
this... JPA.  If you have common fields you want to inject into an  
entity<br>
you might try to do something like</tt><br>
<br>
<pre style="margin: 0em;">private String CommonInterface.commonField</pre><br>
<tt>And expect at runtime that will result in a db column named  
common_field, or<br>
whatever else your naming strategy comes up with.  Sure you could  
use the<br>
@Column annotation and explicitly give it a name, but that adds in  
a declare<br>
statement and it is definitely a bit confusing when you first run  
across the<br>
issue.  JPA is not the only framework to do this type of reflection  
these<br>
days, Seam's @In injection is another one that tries to determine a  
value<br>
based on the name of the field.</tt><br>
<br>
<tt>Of course i imagine this was done to avoid naming collisions when you<br>
receive fields from multiple ITDs and I'm not sure I see a better  
solution.</tt><br>
<br>
<pre style="margin: 0em;">On Nov 2, 2009, at 5:03 PM, Andrew Eisenberg wrote:</pre><br>
<blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><pre style="margin: 0em;">Hi,</pre><br>
<tt>The ajc$interField$mypack_mysubpack_MyAspect$id is internal and not<br>
expected to be directly referenced in the source code.  It is only<br>
needed for the byte code (i.e., you should not be concerned with  
it).<br>
All you need to know is that the declaration declares an Integer  
field<br>
'id' on MyClass that is private to the aspect (ie- it is not<br>
accessible anywhere outside the aspect).</tt><br>
<br>
<tt>Unless you require knowledge about the byte code, the byte code name<br>
should not be of concern to you.  However, if you do require  
knowledge<br>
about the byte code, please explain what that is and perhaps we can<br>
help you.</tt><br>
<br>
<pre style="margin: 0em;">--a</pre><br>
<tt>On Mon, Nov 2, 2009 at 2:45 PM, db &lt;dbconrado@xxxxxxxxx&gt; wrote:
</tt><blockquote style="border-left: #5555EE solid 0.2em; margin: 0em; padding-left: 0.85em"><pre style="margin: 0em;"><br>Hi All,</pre><br>
<pre style="margin: 0em;">I have an intertype declaration like this:</pre><br>
<pre style="margin: 0em;">private Integer MyClass.id;</pre><br>
<tt>but, when it was compiled/weaved, this attribute receive the name:<br>
ajc$interField$mypack_mysubpack_MyAspect$id.<br>
I want MyClass receive an id attribute and not a ajc$...$id  
attribute.<br>
How to do it?</tt><br>
<br>
<pre style="margin: 0em;">Thanks!</pre><br>
<pre style="margin: 0em;">PS: Sorry for my poor English. It isn't my native language :).</pre><br>
<pre style="margin: 0em;">_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a></pre><br>
<br>
</blockquote><pre style="margin: 0em;">_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
</pre></blockquote><pre style="margin: 0em;"><br>_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a></pre><br>
</blockquote><pre style="margin: 0em;">_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
<a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
</pre></blockquote><pre style="margin: 0em;"><br></pre><br>
]]></content:encoded>
		<pubDate>Wed, 04 Nov 2009 18:21:05 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11450.html</guid>
		<author>dave@xxxxxxx (Dave Whittaker)</author>
	</item>
	<item>
		<title>Re: [aspectj-users] A transaction question</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11449.html</link>
		<description> </description>
		<content:encoded><![CDATA[<pre>Hi,
It's been a while since I've used AspectJ in anger but as no-one else has replied yet...

I'd say you probably want &quot;args(manager)&quot; instead of &quot;target(manager)&quot; in the obtainEntityManager pointcut.
The target of the call will be an AccountDAO, not an EntityManager.

See <a  href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html">http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html</a>

HTH!
Mark.

--- On Wed, 4/11/09, neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt; wrote:

&gt; From: neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;
&gt; Subject: [aspectj-users] A transaction question
&gt; To: aspectj-users@xxxxxxxxxxx
&gt; Date: Wednesday, 4 November, 2009, 12:09
&gt; 
&gt; I am learning how to modulize transaction using aspectj,
&gt; but encounter a
&gt; problem that EntityManager I try to capture is always null.
&gt; The compiler
&gt; issues message saying that the advice can not be applied.
&gt; as below:
&gt; 
&gt; ... advice defined in example.AbstractTransaction has not
&gt; been applied
&gt; [Xlint:adviceDidNotMatch]
&gt; 
&gt; What should I change so that I can capture the
&gt; EntityManager while it is
&gt; created (whilst calling to
&gt; AccountDao.setEntityManager(..))?
&gt; 
&gt; Thanks for help.
&gt; 
&gt; Main.java
&gt; 
&gt; package example;
&gt; 
&gt; public class Main{
&gt; &#xA0;&#xA0;&#xA0; public static void main(String args[]){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; Main m = new Main();
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; m.process();
&gt; &#xA0;&#xA0;&#xA0; }
&gt; &#xA0;&#xA0;&#xA0; void process(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; AccountDao dao = new
&gt; AccountDao();
&gt; &#xA0;&#xA0;&#xA0; 
&gt; dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; User u = new
&gt; User(&quot;1&quot;, &quot;Smith&quot;);
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; u.setAddress(&quot;123
&gt; Test Road, London.&quot;);
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; dao.save(u);
&gt; 
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0;
&gt; dao.list();&#xA0;&#xA0;&#xA0; 
&gt; &#xA0;&#xA0;&#xA0; }
&gt; }
&gt; 
&gt; AccountDao.java
&gt; 
&gt; package example;
&gt; 
&gt; import java.util.List;
&gt; import java.util.ArrayList;
&gt; 
&gt; 
&gt; public class AccountDao{
&gt; 
&gt; &#xA0;&#xA0;&#xA0; private EntityManager manager;
&gt; 
&gt; &#xA0;&#xA0;&#xA0; private static List&lt;User&gt; database
&gt; = new ArrayList&lt;User&gt;();
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public void
&gt; setEntityManager(EntityManager manager){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.manager =
&gt; manager;
&gt; &#xA0;&#xA0;&#xA0; }&#xA0;&#xA0;&#xA0; 
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public void save(User user){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0;
&gt; database.add(user);&#xA0;&#xA0;&#xA0; 
&gt; &#xA0;&#xA0;&#xA0; }
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public void list(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; for(User u :
&gt; database){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0;
&gt; System.out.println(&quot;&gt;&gt;&gt;[AccountDao.java]&quot;+u);&#xA0;&#xA0;&#xA0;
&gt; 
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; }
&gt; &#xA0;&#xA0;&#xA0; }
&gt; }
&gt; 
&gt; User.java
&gt; 
&gt; package example;
&gt; 
&gt; public class User{
&gt; &#xA0;&#xA0;&#xA0; private String id;
&gt; &#xA0;&#xA0;&#xA0; private String name;
&gt; &#xA0;&#xA0;&#xA0; private String address;
&gt; &#xA0;&#xA0;&#xA0; public User(String id, String name){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.id = id;
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.name = name;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public String getId(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return this.id;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public String getName(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return this.name;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public String getAddress(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return this.address;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public void setAddress(String address){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; this.address =
&gt; address;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public String toString(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return &quot;&lt;User
&gt; [id:&quot;+id+&quot;][name:&quot;+name+&quot;][address:&quot;+address+&quot;]&gt;&quot;;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; }
&gt; 
&gt; 
&gt; PersistenceCreator.java
&gt; 
&gt; package example;
&gt; 
&gt; public class PersistenceCreator{
&gt; &#xA0;&#xA0;&#xA0; private static EntityManagerFactory
&gt; factory;
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public static EntityManagerFactory
&gt; createEntityManagerFactory(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; if(null == factory)
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0;
&gt; factory = new EntityManagerFactory();
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return factory;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; }
&gt; 
&gt; EntityManagerFactory.java
&gt; 
&gt; package example;
&gt; 
&gt; public class EntityManagerFactory{
&gt; 
&gt; &#xA0;&#xA0;&#xA0; private static EntityManager manager;
&gt; 
&gt; &#xA0;&#xA0;&#xA0; public static EntityManager
&gt; createEntityManager(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; if(null == manager){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0;
&gt; manager = new EntityManager();
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; }
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return manager;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; }
&gt; 
&gt; EntityManager.java
&gt; 
&gt; package example;
&gt; 
&gt; public class EntityManager{
&gt; }
&gt; 
&gt; AbstractTransaction.aj
&gt; 
&gt; package example;
&gt; 
&gt; public abstract aspect AbstractTransaction
&gt; percflow(scope()){
&gt; 
&gt; &#xA0;&#xA0;&#xA0; private EntityManager manager;
&gt; &#xA0;&#xA0;&#xA0; 
&gt; &#xA0;&#xA0;&#xA0; protected abstract pointcut tx();
&gt; 
&gt; &#xA0;&#xA0;&#xA0; protected pointcut
&gt; obtainEntityManager(EntityManager manager): call(*
&gt; example.AccountDao.setEntityManager(EntityManager))
&gt; &amp;&amp; target(manager);
&gt; 
&gt; &#xA0;&#xA0;&#xA0; protected pointcut scope(): tx()
&gt; &amp;&amp; !cflowbelow(tx());
&gt; 
&gt; &#xA0;&#xA0;&#xA0; Object around(): scope(){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0;
&gt; System.out.println(&quot;EntityManager:&quot;+manager);// always null
&gt; 
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; Object result =
&gt; proceed();
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return result;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; 
&gt; &#xA0;&#xA0;&#xA0; EntityManager around(EntityManager
&gt; manager): obtainEntityManager(manager)
&gt; &amp;&amp; cflow(tx()){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; if(null == manager){
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0;
&gt; manager = proceed(manager);
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; 
&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; }

&gt; &#xA0;&#xA0;&#xA0; &#xA0;&#xA0;&#xA0; return manager;
&gt; &#xA0;&#xA0;&#xA0; }
&gt; }
&gt; 
&gt; AccountTransaction.aj
&gt; 
&gt; package example;
&gt; 
&gt; public aspect AccountTransaction extends
&gt; AbstractTransaction{
&gt; 
&gt; &#xA0;&#xA0;&#xA0; protected pointcut tx(): execution(*
&gt; example.Main.process());
&gt; }
&gt; -- 
&gt; View this message in context: <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26195112.html">http://old.nabble.com/A-transaction-question-tp26195112p26195112.html</a>
&gt; Sent from the AspectJ - users mailing list archive at
&gt; Nabble.com.
&gt; 
&gt; _______________________________________________
&gt; aspectj-users mailing list
&gt; aspectj-users@xxxxxxxxxxx
&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt; 




</pre>]]></content:encoded>
		<pubDate>Wed, 04 Nov 2009 16:33:05 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11449.html</guid>
		<author>markcooke666@xxxxxxx (Mark Cooke)</author>
	</item>
	<item>
		<title>Re: [aspectj-users] A transaction question</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11448.html</link>
		<description>Just a quick observation: protected pointcut obtainEntityManager(EntityManager manager): call(* example.AccountDao.setEntityManager(EntityManager)) &amp;amp;&amp;amp; target(manager); shouldn't that be: protected pointcut obtainEntityManager(EntityManager manager): call(*...</description>
		<content:encoded><![CDATA[<pre>Just a quick observation:

 protected pointcut obtainEntityManager(EntityManager manager): call(*
example.AccountDao.setEntityManager(EntityManager)) &amp;&amp; target(manager);

shouldn't that be:

 protected pointcut obtainEntityManager(EntityManager manager): call(*
example.AccountDao.setEntityManager(EntityManager)) &amp;&amp; args(manager);

As the EntityManager is the argument to the method call and not the
target of the call (the target of the call being AccountDao)?

Andy

2009/11/4 neo anderson &lt;javadeveloper999@xxxxxxxxxxx&gt;:
&gt;
&gt; I am learning how to modulize transaction using aspectj, but encounter a
&gt; problem that EntityManager I try to capture is always null. The compiler
&gt; issues message saying that the advice can not be applied. as below:
&gt;
&gt; ... advice defined in example.AbstractTransaction has not been applied
&gt; [Xlint:adviceDidNotMatch]
&gt;
&gt; What should I change so that I can capture the EntityManager while it is
&gt; created (whilst calling to AccountDao.setEntityManager(..))?
&gt;
&gt; Thanks for help.
&gt;
&gt; Main.java
&gt;
&gt; package example;
&gt;
&gt; public class Main{
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public static void main(String args[]){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;Main m = new Main();
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;m.process();
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; &#xA0; &#xA0; &#xA0; &#xA0;void process(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;AccountDao dao = new AccountDao();
&gt;
&gt; dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;User u = new User(&quot;1&quot;, &quot;Smith&quot;);
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;u.setAddress(&quot;123 Test Road, London.&quot;);
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;dao.save(u);
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;dao.list();
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; }
&gt;
&gt; AccountDao.java
&gt;
&gt; package example;
&gt;
&gt; import java.util.List;
&gt; import java.util.ArrayList;
&gt;
&gt;
&gt; public class AccountDao{
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private EntityManager manager;
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private static List&lt;User&gt; database = new ArrayList&lt;User&gt;();
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public void setEntityManager(EntityManager manager){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;this.manager = manager;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public void save(User user){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;database.add(user);
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public void list(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;for(User u : database){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;System.out.println(&quot;&gt;&gt;&gt;[AccountDao.java]&quot;+u);
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; }
&gt;
&gt; User.java
&gt;
&gt; package example;
&gt;
&gt; public class User{
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private String id;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private String name;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private String address;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public User(String id, String name){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;this.id = id;
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;this.name = name;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public String getId(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return this.id;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public String getName(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return this.name;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public String getAddress(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return this.address;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public void setAddress(String address){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;this.address = address;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public String toString(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return &quot;&lt;User [id:&quot;+id+&quot;][name:&quot;+name+&quot;][address:&quot;+address+&quot;]&gt;&quot;;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; }
&gt;
&gt;
&gt; PersistenceCreator.java
&gt;
&gt; package example;
&gt;
&gt; public class PersistenceCreator{
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private static EntityManagerFactory factory;
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public static EntityManagerFactory createEntityManagerFactory(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;if(null == factory)
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;factory = new EntityManagerFactory();
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return factory;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; }
&gt;
&gt; EntityManagerFactory.java
&gt;
&gt; package example;
&gt;
&gt; public class EntityManagerFactory{
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private static EntityManager manager;
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;public static EntityManager createEntityManager(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;if(null == manager){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;manager = new EntityManager();
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return manager;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; }
&gt;
&gt; EntityManager.java
&gt;
&gt; package example;
&gt;
&gt; public class EntityManager{
&gt; }
&gt;
&gt; AbstractTransaction.aj
&gt;
&gt; package example;
&gt;
&gt; public abstract aspect AbstractTransaction percflow(scope()){
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;private EntityManager manager;
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;protected abstract pointcut tx();
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;protected pointcut obtainEntityManager(EntityManager manager): call(*
&gt; example.AccountDao.setEntityManager(EntityManager)) &amp;&amp; target(manager);
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;protected pointcut scope(): tx() &amp;&amp; !cflowbelow(tx());
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;Object around(): scope(){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;System.out.println(&quot;EntityManager:&quot;+manager);// always null
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;Object result = proceed();
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return result;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;EntityManager around(EntityManager manager): obtainEntityManager(manager)
&gt; &amp;&amp; cflow(tx()){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;if(null == manager){
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;manager = proceed(manager);
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0; &#xA0;return manager;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;}
&gt; }
&gt;
&gt; AccountTransaction.aj
&gt;
&gt; package example;
&gt;
&gt; public aspect AccountTransaction extends AbstractTransaction{
&gt;
&gt; &#xA0; &#xA0; &#xA0; &#xA0;protected pointcut tx(): execution(* example.Main.process());
&gt; }
&gt; --
&gt; View this message in context: <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26195112.html">http://old.nabble.com/A-transaction-question-tp26195112p26195112.html</a>
&gt; Sent from the AspectJ - users mailing list archive at Nabble.com.
&gt;
&gt; _______________________________________________
&gt; aspectj-users mailing list
&gt; aspectj-users@xxxxxxxxxxx
&gt; <a  href="https://dev.eclipse.org/mailman/listinfo/aspectj-users">https://dev.eclipse.org/mailman/listinfo/aspectj-users</a>
&gt;

</pre>]]></content:encoded>
		<pubDate>Wed, 04 Nov 2009 16:03:11 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11448.html</guid>
		<author>andrew.clement@xxxxxxx (Andy Clement)</author>
	</item>
	<item>
		<title>[aspectj-users] Problems with inter type declaring	@PersistenceContext annotated EntityManager attribute in interface</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11447.html</link>
		<description>Hi all,I have an aspect like that:declare parents: MyClass1 || MyClass2 implements HasEntityManager; @PersistenceContextprivate EntityManager HasEntityManager.entityManager; However, when I start my app in Glassfish, I get:SEVERE: Injection method name mus...</description>
		<content:encoded><![CDATA[Hi all,<br><br>I have an aspect like that:<br><br><span style="font-family: courier new,monospace;">declare parents: MyClass1 || MyClass2 implements HasEntityManager;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">@PersistenceContext</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">private EntityManager HasEntityManager.entityManager;</span><br>

<br>However, when I start my app in Glassfish, I get:<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">SEVERE: Injection method name must start with &quot;set&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&#xA0;symbol: javax.persistence.PersistenceContext</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&#xA0;location: public static void edu.tcc.t2.infra.RepositoryJPA.ajc$interFieldInit$edu_tcc_t2_infra_RepositoryJPA$edu_tcc_t2_infra_HasEntityManager$entityManager(edu.tcc.t2.infra.HasEntityManager)</span><br style="font-family: courier new,monospace;">

<br>I&#39;m using field-based annotation, so, it couldn&#39;t happen.<br>Anyone knows how to solve it?<br><br>Thanks.<br><br>PS: MyClass1 and MyClass2 are JSF managed beans.<br><br>
]]></content:encoded>
		<pubDate>Wed, 04 Nov 2009 15:22:49 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11447.html</guid>
		<author>dbconrado@xxxxxxx (db)</author>
	</item>
	<item>
		<title>[aspectj-users] A transaction question</title>
		<link>http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11446.html</link>
		<description> I am learning how to modulize transaction using aspectj, but encounter a problem that EntityManager I try to capture is always null. The compiler issues message saying that the advice can not be applied. as below: ... advice defined in example.AbstractTra...</description>
		<content:encoded><![CDATA[<pre>
I am learning how to modulize transaction using aspectj, but encounter a
problem that EntityManager I try to capture is always null. The compiler
issues message saying that the advice can not be applied. as below:

... advice defined in example.AbstractTransaction has not been applied
[Xlint:adviceDidNotMatch]

What should I change so that I can capture the EntityManager while it is
created (whilst calling to AccountDao.setEntityManager(..))?

Thanks for help.

Main.java

package example;

public class Main{
	public static void main(String args[]){
		Main m = new Main();
		m.process();
	}
	void process(){
		AccountDao dao = new AccountDao();
	
dao.setEntityManager(PersistenceCreator.createEntityManagerFactory().createEntityManager());
		User u = new User(&quot;1&quot;, &quot;Smith&quot;);
		u.setAddress(&quot;123 Test Road, London.&quot;);
		dao.save(u);

		dao.list();	
	}
}

AccountDao.java

package example;

import java.util.List;
import java.util.ArrayList;


public class AccountDao{

	private EntityManager manager;

	private static List&lt;User&gt; database = new ArrayList&lt;User&gt;();

	public void setEntityManager(EntityManager manager){
		this.manager = manager;
	}	

	public void save(User user){
		database.add(user);	
	}

	public void list(){
		for(User u : database){
			System.out.println(&quot;&gt;&gt;&gt;[AccountDao.java]&quot;+u);	
		}
	}
}

User.java

package example;

public class User{
	private String id;
	private String name;
	private String address;
	public User(String id, String name){
		this.id = id;
		this.name = name;
	}

	public String getId(){
		return this.id;
	}

	public String getName(){
		return this.name;
	}

	public String getAddress(){
		return this.address;
	}

	public void setAddress(String address){
		this.address = address;
	}

	public String toString(){
		return &quot;&lt;User [id:&quot;+id+&quot;][name:&quot;+name+&quot;][address:&quot;+address+&quot;]&gt;&quot;;
	}
}


PersistenceCreator.java

package example;

public class PersistenceCreator{
	private static EntityManagerFactory factory;

	public static EntityManagerFactory createEntityManagerFactory(){
		if(null == factory)
			factory = new EntityManagerFactory();
		return factory;
	}
}

EntityManagerFactory.java

package example;

public class EntityManagerFactory{

	private static EntityManager manager;

	public static EntityManager createEntityManager(){
		if(null == manager){
			manager = new EntityManager();
		}
		return manager;
	}
}

EntityManager.java

package example;

public class EntityManager{
}

AbstractTransaction.aj

package example;

public abstract aspect AbstractTransaction percflow(scope()){

	private EntityManager manager;
	
	protected abstract pointcut tx();

	protected pointcut obtainEntityManager(EntityManager manager): call(*
example.AccountDao.setEntityManager(EntityManager)) &amp;&amp; target(manager);

	protected pointcut scope(): tx() &amp;&amp; !cflowbelow(tx());

	Object around(): scope(){
		System.out.println(&quot;EntityManager:&quot;+manager);// always null 
		Object result = proceed();
		return result;
	}

	EntityManager around(EntityManager manager): obtainEntityManager(manager)
&amp;&amp; cflow(tx()){
		if(null == manager){
			manager = proceed(manager);
		
		}
		return manager;
	}
}

AccountTransaction.aj

package example;

public aspect AccountTransaction extends AbstractTransaction{

	protected pointcut tx(): execution(* example.Main.process());
}
-- 
View this message in context: <a  href="http://old.nabble.com/A-transaction-question-tp26195112p26195112.html">http://old.nabble.com/A-transaction-question-tp26195112p26195112.html</a>
Sent from the AspectJ - users mailing list archive at Nabble.com.


</pre>]]></content:encoded>
		<pubDate>Wed, 04 Nov 2009 12:09:43 GMT</pubDate>
		<guid isPermaLink="true">http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg11446.html</guid>
		<author>javadeveloper999@xxxxxxx (neo anderson)</author>
	</item>

 
	</channel>
	</rss>
<!-- MHonArc v2.6.10 -->
