FileDocCategorySizeDatePackage
SunTransactionHelper.javaAPI DocGlassfish v2 API11549Fri May 04 22:35:04 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.ejb

SunTransactionHelper

public class SunTransactionHelper extends TransactionHelperImpl implements com.sun.enterprise.server.event.ApplicationLoaderEventListener, com.sun.enterprise.connectors.ConnectorNamingEventListener
Sun specific implementation for TransactionHelper interface. Though this class does not have special implementation for registerSynchronization, it uses a special Transaction object that registers Synchronization instance to be processed after any bean's beforeCompletion method.

Fields Summary
private static final ResourceBundle
messages
I18N message handler
private static List
pmf_list
private static final Object
pmf_listSyncObject
private List
applicationLifeCycleEventListeners
Array of registered ApplicationLifeCycleEventListener
Constructors Summary
SunTransactionHelper()
Default constructor should not be public

 

                
     
        SunTransactionHelper helper = new SunTransactionHelper();
        EJBHelper.registerTransactionHelper (helper);
        // Register with ApplicationLoaderEventNotifier to receive Sun
        // Application Server specific lifecycle events.
        ApplicationLoaderEventNotifier.getInstance().addListener(helper);
        ConnectorRuntime.getRuntime().getResourceRebindEventNotifier().addListener(helper);
        pmf_list = new ArrayList();
     
Methods Summary
private voidcleanUpResources(java.lang.String name)
Removes all entries that correspond to the same connection factory name.

param
name the connection factory name.

        synchronized(pmf_listSyncObject) {
            for (Iterator it = pmf_list.iterator(); it.hasNext(); ) {
                PersistenceManagerFactory pmf = (PersistenceManagerFactory)it.next();        
                if (pmf.getConnectionFactoryName().equals(name)) {
                    it.remove();
                }
            }
        }
    
public voidconnectorNamingEventPerformed(com.sun.enterprise.connectors.ConnectorNamingEvent event)

inheritDoc

        if(event.getEventType() == ConnectorNamingEvent.EVENT_OBJECT_REBIND){
            String dsName = ResourceInstaller.getPMJndiName(event.getJndiName());
            cleanUpResources(dsName);
        } // Ignore all other events.
    
public java.lang.StringgetDDLNamePrefix(java.lang.Object info)
Returns name prefix for DDL files extracted from the info instance by the application server specific code. SunTransactionHelper specific code. Delegates the actual implementation to DeploymentHelper#getDDLNamePrefix(Object);

param
info the instance to use for the name generation.
return
name prefix as String.

 
        return DeploymentHelper.getDDLNamePrefix(info);
    
public javax.transaction.TransactionManagergetLocalTransactionManager()
SunTransactionHelper specific code

        try {
            return TransactionManagerFinder.appserverTM;
        } catch (ExceptionInInitializerError err) {
                throw new JDOFatalInternalException(err.getMessage());
        }
    
public java.sql.ConnectiongetNonTransactionalConnection(java.lang.Object resource, java.lang.String username, java.lang.String password)
Called in a managed environment to get a Connection from the application server specific resource. In a non-managed environment returns null as it should not be called. SunTransactionHelper specific code uses com.sun.appserv.jdbc.DataSource to get a Connection.

param
resource the application server specific resource.
param
username the resource username. If null, Connection is requested without username and password validation.
param
password the password for the resource username.
return
a Connection.
throws
java.sql.SQLException.


        java.sql.Connection rc = null;
        // resource is expected to be com.sun.appserv.jdbc.DataSource
        if (resource instanceof DataSource) {
            DataSource ds = (DataSource)resource;
            if (username == null) {
                rc = ds.getNonTxConnection();
            } else {
                rc = ds.getNonTxConnection(username, password);
            }
        } else {
            throw new JDOFatalInternalException(I18NHelper.getMessage(
                messages, "ejb.SunTransactionHelper.wrongdatasourcetype", //NOI18N
                resource.getClass().getName())); 
        }
        return rc;
    
public javax.transaction.TransactiongetTransaction()
SunTransactionHelper specific code


         
            try {
                tm = (TransactionManager) (new InitialContext()).lookup(PM_TM_NAME);
                appserverTM = (TransactionManager) (new InitialContext()).lookup(AS_TM_NAME);
            } catch (Exception e) {
                throw new JDOFatalInternalException(e.getMessage());
            }
        
       try{
            return TransactionManagerFinder.tm.getTransaction();
        } catch (Exception e) {
            throw new JDOFatalInternalException(e.getMessage());
        } catch (ExceptionInInitializerError err) {
            throw new JDOFatalInternalException(err.getMessage());
        }
    
public javax.transaction.UserTransactiongetUserTransaction()
SunTransactionHelper specific code

	try {
	    InitialContext ctx =
                (InitialContext) Class.forName("javax.naming.InitialContext").newInstance(); //NOI18N

            return (UserTransaction)ctx.lookup("java:comp/UserTransaction"); //NOI18N
	} catch (Exception e) {
	    throw new JDOFatalInternalException(e.getMessage());
	}
    
public voidhandleApplicationEvent(com.sun.enterprise.server.event.ApplicationEvent event)

inheritDoc

            // Change to switch-case if handling more than one events.
            if(ApplicationEvent.AFTER_APPLICATION_UNLOAD == event.getEventType() ) {
                ClassLoader classLoader = event.getClassLoader();
                for (Iterator iterator = applicationLifeCycleEventListeners.iterator(); 
                     iterator.hasNext();) {
                    ApplicationLifeCycleEventListener applicationLifeCycleEventListener = 
                            (ApplicationLifeCycleEventListener) iterator.next();
                    applicationLifeCycleEventListener.notifyApplicationUnloaded(classLoader);
            }
        }
    
public voidhandleEjbContainerEvent(com.sun.enterprise.server.event.EjbContainerEvent event)

inheritDoc

        //Ignore EjbContainerEvents
    
public voidregisterApplicationLifeCycleEventListener(ApplicationLifeCycleEventListener listener)

inheritDoc

        synchronized(applicationLifeCycleEventListeners) {
             applicationLifeCycleEventListeners.add(listener);
        }
    
public com.sun.jdo.api.persistence.support.PersistenceManagerFactoryreplaceInternalPersistenceManagerFactory(com.sun.jdo.api.persistence.support.PersistenceManagerFactory pmf)
SunTransactionHelper specific code


        synchronized(pmf_listSyncObject) {
	    int i = pmf_list.indexOf(pmf);
	    if (i == -1) {
	        // New PersistenceManagerFactory. Remember it.
	        pmf_list.add(pmf);
	        return pmf;
	    }

	    return (PersistenceManagerFactory)pmf_list.get(i);
        }