Ok, it's back to giving me problems. I don't know what the issue is
here.

Mark, do you think you can you shoot me over one very simple working
example of AOP advice with a service layer in ColdBox? Doesn't have to
be anything complicated, just one simple example where the handler
calls the service layer, which has one AOP advised method. (that gets
advised every time I call that method)

Basically, I want every time I call getBean("userservice").saveuser
(user) for it to be advised.

The example I gave above sort of works, but only the first call of
saveuser is advised because the init method only runs when the bean is
created, not every time.

In my handler I want to do:

userService = getPlugin("ioc").getBean("userService");
user = instance.Transfer.new("users.user");
user.setFirstName("test");
userService.saveuser(user)

And have it advised.

If I do this:

transaction = getPlugin("ioc").getBean("TransferTransaction");
                args = structNew();
                args.user = user;
transaction.execute(userService, "saveuser", args);

I get stack overflow after the first time.

If I put the advise in the init() method of the service, it only
happens once.

Thanks!!

On Jul 1, 5:54 am, Mark Mandel <mark.man...@gmail.com> wrote:
> Should work.. not sure what is going on... the unit tests all pass.
>
> What CF platform are you on?
>
> Mark
>
> On Wed, Jul 1, 2009 at 10:34 PM, whostheJBoss 
> <dotfus...@changethings.org>wrote:
>
>
>
>
>
> > I'm using                 transaction.execute(userService, "saveuser",
> > args)
>
> > On Jul 1, 4:58 am, Mark Mandel <mark.man...@gmail.com> wrote:
> > > Turn on debug on the advise() method, make sure it's wrapping the method
> > you
> > > expect it to be.
>
> > > It will show you in trace
>
> > > Mark
>
> > > On Wed, Jul 1, 2009 at 9:57 PM, whostheJBoss <dotfus...@changethings.org
> > >wrote:
>
> > > > innoDB
>
> > > > On Jul 1, 4:49 am, Mark Mandel <mark.man...@gmail.com> wrote:
> > > > > You're not using myISAM tables are you?
>
> > > > > Mark
>
> > > > > On Wed, Jul 1, 2009 at 9:23 PM, whostheJBoss <
> > dotfus...@changethings.org
> > > > >wrote:
>
> > > > > > It's on MySQL 5, and no, this is a clean Transfer, not the modified
> > > > > > AOP version.
>
> > > > > > On Jul 1, 4:00 am, Mark Mandel <mark.man...@gmail.com> wrote:
> > > > > > > What DB is this on?
>
> > > > > > > Is this your modified code? I believe you made significant
> > changes to
> > > > the
> > > > > > > way transaction AOP worked?
>
> > > > > > > Mark
>
> > > > > > > On Wed, Jul 1, 2009 at 8:52 PM, whostheJBoss <
> > > > dotfus...@changethings.org
> > > > > > >wrote:
>
> > > > > > > > Perhaps I'm doing this totally wrong, but this is what I'm
> > > > trying...
>
> > > > > > > > I have a bean called userService:
>
> > > > > > > > <bean id="userService" class="model.users.userService">
> > > > > > > >        <constructor-arg name="transfer">
> > > > > > > >                <ref bean="Transfer" />
> > > > > > > >        </constructor-arg>
> > > > > > > >        <constructor-arg name="transaction">
> > > > > > > >                <ref bean="TransferTransaction" />
> > > > > > > >        </constructor-arg>
> > > > > > > >        <constructor-arg name="userGateway">
> > > > > > > >                <ref bean="userGateway"/>
> > > > > > > >        </constructor-arg>
> > > > > > > > </bean>
>
> > > > > > > > This is the TransferTransaction that I am passing to the
> > > > constructor
> > > > > > > > on userService:
>
> > > > > > > > <bean id="TransferTransaction" factory-bean="ColdboxOCM"
> > factory-
> > > > > > > > method="get">
> > > > > > > >   <constructor-arg
> > name="objectKey"><value>TransferTransaction</
> > > > > > > > value></constructor-arg>
> > > > > > > > </bean>
>
> > > > > > > > In the init method of userService I do:
>
> > > > > > > >        <cffunction name="init" access="public" output="false"
> > > > > > > > returntype="userService">
> > > > > > > >                <cfargument name="transfer"
> > > > type="transfer.com.Transfer"
> > > > > > > > required="true" />
> > > > > > > >                <cfargument name="transaction"
> > > > > > > > type="transfer.com.sql.transaction.Transaction" required="true"
> > />
> > > > > > > >                <cfargument name="userGateway"
> > type="userGateway"
> > > > > > > > required="true" />
>
> > > > > > > >                <cfset variables.transfer = arguments.transfer
> > />
> > > > > > > >                <cfset variables.userGateway =
> > arguments.userGateway
> > > > />
>
> > > > > > > >                <cfset
> > > > arguments.transaction.advise(this,"saveuser")>
>
> > > > > > > >                <cfreturn this/>
> > > > > > > >        </cffunction>
>
> > > > > > > > Now, as far as I'm aware, this should now wrap saveuser method
> > on
> > > > > > > > userService in a transaction, so that if anything fails inside
> > of a
> > > > > > > > call to userService's saveuser method then all database actions
> > > > that
> > > > > > > > happened during the transaction (during the saveuser method)
> > will
> > > > be
> > > > > > > > rolled back.
>
> > > > > > > > In my handler I do:
>
> > > > > > > >                userService =
> > > > getPlugin("ioc").getBean("userService");
> > > > > > > >                user = instance.Transfer.new("users.user");
> > > > > > > >                user.setEmail("t...@test.com");
> > > > > > > >                user.setPassword("test");
> > > > > > > >                user.setAccountType(2);
> > > > > > > >                userService.saveuser(user);
>
> > > > > > > > So, this works and the database entry is created.
>
> > > > > > > > However, if I go into my userService and add some bad code in
> > the
> > > > > > > > saveuser method:
>
> > > > > > > >        <cffunction name="saveuser" access="public"
> > output="false"
> > > > > > > > returntype="void">
> > > > > > > >                <cfargument name="user" type="any"
> > required="true"
> > > > />
>
> > > > > > > >                <cfset variables.transfer.save(arguments.user)
> > />
> > > > > > > >                <cfset
> > variables.transfer.save(arguments.FAKEOBJECT)
> > > > />
> > > > > > > >        </cffunction>
>
> > > > > > > > Since FAKEOBJECT doesn't exist, it throws an error. However,
> > the
> > > > save
> > > > > > > > right before it worked and stays in the database.
>
> > > > > > > > I was under the impression that this kind of transaction would
> > roll
> > > > > > > > back the first save also when the FAKEOBJECT save failed since
> > they
> > > > > > > > are both advised by this:
>
> > > > > > > >                <cfset
> > > > arguments.transaction.advise(this,"saveuser")>
>
> > > > > > > > I have also tried do this inside of my handler instead:
>
> > > > > > > > transaction = getPlugin("ioc").getBean("TransferTransaction");
>
> > > > > > > >                userService =
> > > > getPlugin("ioc").getBean("userService");
> > > > > > > >                user = instance.Transfer.new("users.user");
> > > > > > > >                user.setEmail("t...@test.com");
> > > > > > > >                user.setPassword("test");
> > > > > > > >                user.setAccountType(2);
>
> > > > > > > >                args = structNew();
> > > > > > > >                args.user = user;
> > > > > > > >                transaction.execute(userService, "saveuser",
> > args)
>
> > > > > > > > But I get the same results. When there is no bad code in the
> > > > saveuser
> > > > > > > > method, it works fine and I see the insert in the database, but
> > > > when I
> > > > > > > > add the FAKEOBJECT to produce an error like so:
>
> > > > > > > >                <cfset variables.transfer.save(arguments.user)
> > />
> > > > > > > >                <cfset
> > variables.transfer.save(arguments.FAKEOBJECT)
> > > > />
>
> > > > > > > > The first save isn't rolled back, the new object stays in the
> > > > > > > > database.
>
> > > > > > > > Any ideas why a simple transaction isn't rolling back the
> > database?
>
> > > > > > > > Thanks!
>
> > > > > > > --
> > > > > > > E: mark.man...@gmail.com
> > > > > > > T:http://www.twitter.com/neurotic
> > > > > > > W:www.compoundtheory.com
>
> > > > > --
> > > > > E: mark.man...@gmail.com
> > > > > T:http://www.twitter.com/neurotic
> > > > > W:www.compoundtheory.com
>
> > > --
> > > E: mark.man...@gmail.com
> > > T:http://www.twitter.com/neurotic
> > > W:www.compoundtheory.com
>
> --
> E: mark.man...@gmail.com
> T:http://www.twitter.com/neurotic
> W:www.compoundtheory.com
--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
"transfer-dev" group.
To post to this group, send email to transfer-dev@googlegroups.com
To unsubscribe from this group, send email to 
transfer-dev-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to