Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] AJDT 1.3 and aspectj

All,

I am wondering if anyone else has experience any sort of problem with how aspect are being applied with AJDT 1.3 and the latest version of aspectj. What I am seeing under Jboss 3.2.6 is that my aspects that previous worked for transaction control and database connections are no longer working. This appears to a be a gradual degration of hte systems [about 4 hours or so] the JCA control in JBoss finaly times out and effectively crahses the system. I can not stress enough that the only that changes was my migration from 1.2 variants of aspectj and AJDT to the newest version when this started to occur.

Thanks in advance,

Ron

Here are a sample of what those aspects look like and some of the cooperating code:

package com.tascon.tim.provider.hibernate;

import com.tascon.tim.util.HibernateHelper;

public aspect TransactionControl
{
   pointcut transaction(HibernateTransaction tc) :
           target(tc) && execution(public * HibernateTransaction.*(..));
before(HibernateTransaction tc) : transaction(tc)
   {
       HibernateHelper.start();
   }

   after(HibernateTransaction tc) returning : transaction(tc)
   {
       HibernateHelper.commit();
   }
after(HibernateTransaction tc) throwing : transaction(tc)
   {
       HibernateHelper.rollback();
   }
}


package com.tascon.tim.provider.hibernate;

import com.tascon.tim.util.HibernateHelper;

public aspect HibernateAspect
{
pointcut hibernateClassList() : within(com.tascon.tim.provider.hibernate.*); pointcut hibernateFetch(HibernateProviderBase hpb) : execution(public * *.*(..)) && !execution(public * *.set*(..)) && target(hpb); before(HibernateProviderBase hpb) : hibernateClassList() && hibernateFetch(hpb)
   {
       try
       {
           hpb.sess = HibernateHelper.openSession();
       }
       catch(Exception e)
       {
       }
   }
after(HibernateProviderBase hpb) :
       hibernateClassList() && hibernateFetch(hpb)
   {
       HibernateHelper.closeSession();
   }
}

package com.tascon.tim.aop;

import java.sql.Connection;
import java.sql.ResultSet;

import com.tascon.tim.DBAccessor;
import com.tascon.tim.util.DatabaseHelper;

privileged aspect ConnectionCleaner {
   pointcut DatasourceConnection(DBAccessor db) :
       execution(public !ResultSet && !Connection DBAccessor.*(..))
       && target(db);

before(DBAccessor db) : DatasourceConnection(db) && !cflowbelow(DatasourceConnection(DBAccessor))
   {
       try {
           db.con = DatabaseHelper.getDataSourceConnection();
       } catch (Exception e) {
       }
   }

after(DBAccessor db) : DatasourceConnection(db) && !cflowbelow(DatasourceConnection(DBAccessor))
   {
       DatabaseHelper.close(db.con);
   }

// known JDBC Connection leak, but htis done via a Direct Connection creation and does not cause a lockup.
   pointcut JdbcConnection(DBAccessor db) :
       execution(public ResultSet DBAccessor.*(..))
       && target(db);

before(DBAccessor db) : JdbcConnection(db) && !cflowbelow(JdbcConnection(DBAccessor))
   {
       try {

           System.out.println("Getting JDBC connection");
           db.con = DatabaseHelper.getJdbcConnection();
       } catch (Exception e) {
       }
   }
}

/*
* Created on Nov 19, 2003
*
* To change the template for this generated file go to Window - Preferences -
* Java - Code Generation - Code and Comments
*/
package com.tascon.tim.util;
import java.util.Iterator;

import javax.naming.Context;
import javax.naming.InitialContext;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
/**
* @author rdifrang
*
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Generation - Code and Comments
*/
public final class HibernateHelper
{
   private static final String FACTORY_NAME = "TIMHibernateFactory";
   public static final ThreadLocal threadLocalSession = new ThreadLocal();
public static final ThreadLocal threadLocalTransaction = new ThreadLocal();
   /**
    * Create a Hibernate Session
    *
    * @return @throws
    *         Exception
    */
   public static final Session openSession() throws Exception
   {
       Session s = (Session) threadLocalSession.get();
       if (s == null)
       {
           Context ctx = new InitialContext();
           SessionFactory factory =
               (SessionFactory) ctx.lookup(FACTORY_NAME);
           s = factory.openSession();
           threadLocalSession.set(s);
           System.out.println("RRD: HibernateHelper open session");
       }
       return s;
   }
   /**
    * Closes a Hibernate session
    */
   public static final void closeSession()
   {
       Session s = (Session) threadLocalSession.get();
       try
       {
           if (s != null)
           {
               s.flush();
               s.close();
               System.out.println("RRD: HibernateHelper close session");
           }
       }
       catch (HibernateException e)
       {
       }
       finally
       {
           threadLocalSession.set(null);
       }
   }
/**
    * Rolls back a transaction.
    */
   public static final void start()
   {
       Session s = (Session) threadLocalSession.get();
       if (s != null)
       {
           try
           {
               Transaction trans = s.beginTransaction();
               threadLocalTransaction.set(trans);
System.out.println("RRD: HibernateHelper begin transaction");
           }
           catch (HibernateException e)
           {
           }
       }
   }
   /**
    * Commits a transaction.
    */
   public static final void commit()
   {
       Transaction trans =(Transaction)threadLocalTransaction.get();
       if (trans != null)
       {
           try
           {
               trans.commit();
System.out.println("RRD: HibernateHelper commit transaction");
           }
           catch (HibernateException e)
           {
           }
           finally
           {
               threadLocalTransaction.set(null);
           }
       }
   }
   /**
    * Rolls back a transaction.
    */
   public static final void rollback()
   {
       Transaction trans =(Transaction)threadLocalTransaction.get();
       if (trans != null)
       {
           try
           {
               trans.rollback();
System.out.println("RRD: HibernateHelper rollback transaction");
           }
           catch (HibernateException e)
           {
           }
           finally
           {
               threadLocalTransaction.set(null);
           }
       }
   }
}

package com.tascon.tim.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

public class DatabaseHelper
{
private static final String driverName = "net.sourceforge.jtds.jdbc.Driver";
   private static final String serverName = "localhost";
   private static final String portNumber = "1433";
   private static final String mydatabase = serverName + ":" + portNumber;
   private static final String jtds = "/tim;tds=8.0;lastupdatecount=true";
private static final String url = "jdbc:jtds:sqlserver://" + mydatabase + jtds;
// These are filled in, but pulled out for these purposes.
   private static final String username = "";
   private static final String password = "";
public static Connection getJdbcConnection() throws Exception
   {
       // Load the JDBC driver
       Class.forName(driverName);
       // Create a connection to the database
       return DriverManager.getConnection(url, username, password);
   }
/**
    * Obtains a connection from the database.
    * @return
    */
   public static Connection getDataSourceConnection() throws Exception
   {
       // In the app server environment
       DataSource ds =
        (DataSource) EJBHomeCache.getInstanceOf().getHomeInterface(
                       "java:/TIMDS",
                       DataSource.class);
       return ds.getConnection();
   }
/**
    * Closes out a connection
    * @author RDifrang
    *
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    */
   public static void close(Connection conn)
   {
       if (conn != null)
       {
           try
           {
               conn.close();
           }
           catch (SQLException e)
           {
               // MessageLog.writeErrorMessage("getModel()", e, conn);
           }
       }
   }
   /**
    * Closes out everything you need closed.
    * @param conn
    * @param stmt
    * @param rs
    */
   public static void close(Connection conn, Statement stmt, ResultSet rs)
   {
       close(rs);
       close(stmt);
       close(conn);
   }
/**
    * Closes out everything you need closed.
    * @param stmt
    * @param rs
    */
   public static void close(Statement stmt, ResultSet rs)
   {
       close(rs);
       close(stmt);
   }
/**
    * Closes out a result set
    * @author RDifrang
    *
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    */
   public static void close(ResultSet rset)
   {
       if (rset != null)
       {
           try
           {
               rset.close();
           }
           catch (SQLException e)
           {
               // MessageLog.writeErrorMessage("getModel()", e, rset);
           }
       }
   }
   /**
    * Closes out a statement
    * @author RDifrang
    *
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    */
   public static void close(Statement stmt)
   {
       if (stmt != null)
       {
           try
           {
               stmt.close();
           }
           catch (SQLException e)
           {
               // MessageLog.writeErrorMessage("getModel()", e, stmt);
           }
       }
   }
}



Back to the top