The Artima Developer Community
Sponsored Link

Java Buzz Forum
Exceptional Transactions and Bad AOP Idioms

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Exceptional Transactions and Bad AOP Idioms Posted: Jun 1, 2004 11:11 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Exceptional Transactions and Bad AOP Idioms
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

I needed yet-another-cmt-in-j2se so went about it the "right way" -- using aspects. It drilled into me a serious trap I have fallen into -- using globals (static singletons) for communication with aspects =/ Lets look at what I am doing:

This is a simple implementation of container manager transactions in AspectJ =) It doesn't support all six declarations, but only the four that I actually use (requires, supports, never, mandatory). Supports is the default.

package org.skife.transition;

public abstract aspect Transition
{
    abstract pointcut require();

    abstract pointcut mandatory();

    abstract pointcut never();

    pointcut transacted() : require() && !cflowbelow(require());

    before() : never() {
        Transaction tx = TxProxy.instance().currentTransaction();
        if (tx != null && tx.isInProgress()) {
            throw new IllegalStateException("'NEVER' tx method invoked inside tx");
        }
    }

    before() : mandatory() {
        Transaction tx = TxProxy.instance().currentTransaction();
        if (tx == null || !tx.isInProgress()) {
            throw new IllegalStateException("'MANDATORY' tx method invoked outside tx");
        }
    }

    /**
     * Begin a transaction if one is not in progress
     */
    before() : transacted() {
        Transaction tx = TxProxy.instance().currentTransaction();
        if (tx == null) {
            tx = TxProxy.instance().newTransaction();
        }
        if (!tx.isInProgress()) {
            tx.begin();
        }
    }

    /**
     * Commit Transaction
     */
    after() returning : transacted() {
        Transaction tx = TxProxy.instance().currentTransaction();
        if (tx != null && tx.isInProgress()) {
            tx.commit();
        }
    }

    /**
     * Rollback on exception
     */
    after() throwing : transacted() {
        Transaction tx = TxProxy.instance().currentTransaction();
        if (tx != null && tx.isInProgress()) {
            tx.rollback();
        }
    }
}

Once again it uses a singleton helper class to handle interactions with the external system (whatever provides the transaction service -- JDBC, OJB, JTA, Hibernate, Spring, etc). This type of singleton bridge seems to be coming up a lot in my aspects, unfortunately. I think it points out a serious weakness in my knowledge of how to use the tool.

Adrian Colyer has done some work with letting Spring configure aspects in AspectJ, and I need to play with this some more. That may be an answer. He seems to use rather intimate knowledge of how AspectJ compiles aspects in though, which I am not sure I am comfortable depending on if it isn't part of the spec =/

The problem I run into is when I need to have the same aspects talking to different component implementations in the same VM. BANG. It is the wonderful service-lookup issue all over again.

Read: Exceptional Transactions and Bad AOP Idioms

Topic: That's impossible Previous Topic   Next Topic Topic: Week of many releases

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use