/*******************************************************************************
 * Copyright (c) 1998, 2010 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
 * which accompanies this distribution. 
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at 
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     Oracle - initial API and implementation from Oracle TopLink
 ******************************************************************************/  
package org.eclipse.persistence.platform.server.sunas;

import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.transaction.sunas.SunAS9TransactionController;
import org.eclipse.persistence.platform.server.ServerPlatformBase;
import org.eclipse.persistence.logging.SessionLog;
import org.eclipse.persistence.logging.JavaLog;

/**
 * PUBLIC:
 *
 * This is the concrete subclass responsible for representing SunAS9-specific server behavior.
 *
 * This platform overrides:
 *
 * getExternalTransactionControllerClass(): to use an SunAS9-specific controller class
 *
 */
public class SunAS9ServerPlatform extends ServerPlatformBase {

    /**
     * INTERNAL:
     * Default Constructor: All behavior for the default constructor is inherited
     */
    public SunAS9ServerPlatform(DatabaseSession newDatabaseSession) {
        super(newDatabaseSession);
    }

    /**
     * INTERNAL: getExternalTransactionControllerClass(): Answer the class of external transaction controller to use
     * for SUN AS9. This is read-only.
     *
     * @return Class externalTransactionControllerClass
     *
     * @see org.eclipse.persistence.transaction.JTATransactionController
     * @see ServerPlatformBase#isJTAEnabled()
     * @see ServerPlatformBase#disableJTA()
     * @see ServerPlatformBase#initializeExternalTransactionController()
     */
    public Class getExternalTransactionControllerClass() {
    	if (externalTransactionControllerClass == null){
    		externalTransactionControllerClass = SunAS9TransactionController.class;
    	}
        return externalTransactionControllerClass;
    }

    public SessionLog getServerLog() {
        return  new JavaLog();
    }
}

@@ -772,16 +772,90 @@
 nas;%0D%0A%0D%0A
+import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;%0D%0A
 import o
@@ -904,16 +904,16 @@
 ssion;%0D%0A
-
 import o
@@ -1154,16 +1154,161 @@
 Log;%0D%0A%0D%0A
+import java.lang.reflect.Method;%0D%0Aimport java.security.AccessController;%0D%0Aimport java.security.PrivilegedAction;%0D%0Aimport java.sql.Connection;%0D%0A%0D%0A
 /**%0D%0A * 
@@ -2542,16 +2542,16 @@
     %09%7D%0D%0A
-
         
@@ -2599,24 +2599,1920 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
+%0D%0A    public java.sql.Connection unwrapConnection(final Connection connection)  %7B%0D%0A        Connection unwrappedConnection;%0D%0A%0D%0A        if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) %7B%0D%0A            unwrappedConnection = AccessController.doPrivileged(new PrivilegedAction%3CConnection%3E() %7B%0D%0A                public Connection run() %7B%0D%0A                    return unwrapGlassFishConnectionHelper(connection);%0D%0A                %7D%0D%0A            %7D);%0D%0A        %7D else %7B%0D%0A            unwrappedConnection = unwrapGlassFishConnectionHelper(connection);%0D%0A        %7D%0D%0A%0D%0A        if (unwrappedConnection == null) %7B%0D%0A            unwrappedConnection = super.unwrapConnection(connection);%0D%0A        %7D%0D%0A        return unwrappedConnection;%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * @return unwrapped GlassFish connection, null if connection can not be unwrapped.%0D%0A     */%0D%0A    private Connection unwrapGlassFishConnectionHelper(Connection connection) %7B%0D%0A        // Currently %22GlassFish%22 creates a separate instance of jdbc connector classloader%0D%0A        // for each application. The connection wrapper passed here is created using this class loader. Hence caching%0D%0A        // the class will not help.%0D%0A        // If GlassFish behavior changes, both reflective call below should be cached. %0D%0A        Connection unwrappedConnection = null;%0D%0A        try %7B%0D%0A            Class connectionWrapperClass = connection.getClass().getClassLoader().loadClass(%22com.sun.gjc.spi.base.ConnectionHolder%22);%0D%0A            if(connectionWrapperClass.isInstance(connection) ) %7B%0D%0A                Method unwrapMethod = connectionWrapperClass.getDeclaredMethod(%22getConnection%22);%0D%0A                unwrappedConnection = (Connection) unwrapMethod.invoke(connection);%0D%0A            %7D%0D%0A        %7D catch (Exception e) %7B%0D%0A            getDatabaseSession().getSessionLog().logThrowable(SessionLog.WARNING, e);%0D%0A        %7D%0D%0A%0D%0A        return unwrappedConnection;%0D%0A    %7D%0D%0A%0D%0A
     public S

Fix for issue 300568. Add logic to unwrap connection on GlassFish. Reviewed by Tom.