FileDocCategorySizeDatePackage
ServerPlatformBase.javaAPI DocGlassfish v2 API17494Tue May 22 16:54:48 BST 2007oracle.toplink.essentials.platform.server

ServerPlatformBase

public abstract class ServerPlatformBase extends Object implements ServerPlatform
Implementation of oracle.toplink.essentials.platform.server.ServerPlatform PUBLIC: This is the abstract superclass of all platforms for all servers. Each DatabaseSession contains an instance of the receiver, to help the DatabaseSession determine: - Which external transaction controller to use - Whether or not to enable JTA (external transaction control) - How to register/unregister for runtime services (JMX/MBean) - Whether or not to enable runtime services - How to launch container Threads Subclasses already exist to provide configurations for Oc4J, WebLogic, and WebSphere. If the user wants a different external transaction controller class or to provide some different behaviour than the provided ServerPlatform(s), we recommend subclassing oracle.toplink.essentials.platform.server.ServerPlatformBase (or a subclass), and overriding: ServerPlatformBase.getExternalTransactionControllerClass() ServerPlatformBase.registerMBean() ServerPlatformBase.unregisterMBean() for the desired behaviour.
see
oracle.toplink.essentials.platform.server.ServerPlatformBase public API: String getServerNameAndVersion()

Fields Summary
protected Class
externalTransactionControllerClass
externalTransactionControllerClass: This is a user-specifiable class defining the class of external transaction controller to be set into the DatabaseSession
private boolean
isRuntimeServicesEnabled
INTERNAL: isRuntimeServicesEnabled: Determines if the JMX Runtime Services will be deployed at runtime
private boolean
isJTAEnabled
INTERNAL: isJTAEnabled: Determines if the external transaction controller will be populated into the DatabaseSession at runtime
private boolean
isCMP
INTERNAL: isCMP: true if the container created the server platform, because we're configured for CMP.
private DatabaseSessionImpl
databaseSession
INTERNAL: databaseSession: The instance of DatabaseSession that I am helping.
Constructors Summary
public ServerPlatformBase(DatabaseSessionImpl newDatabaseSession)
INTERNAL: Default Constructor: Initialize so that runtime services and JTA are enabled. Set the DatabaseSession that I will be helping.

        this.isRuntimeServicesEnabled = true;
        this.isJTAEnabled = true;
        this.databaseSession = newDatabaseSession;
        this.setIsCMP(false);
    
Methods Summary
public voiddisableJTA()
INTERNAL: disableJTA(): Configure the receiver such that my external transaction controller class will be ignored, and will NOT be used to populate DatabaseSession's external transaction controller class at runtime. TopLink will NOT be configured to register for callbacks for beforeCompletion and afterCompletion.

return
void
see
#getExternalTransactionControllerClass()
see
#isJTAEnabled()

        this.ensureNotLoggedIn();
        this.isJTAEnabled = false;
    
public voiddisableRuntimeServices()
INTERNAL: disableRuntimeServices(): Configure the receiver such that no JMX/MBean will be registered to provide runtime services for my DatabaseSession at runtime.

return
void
see
#isRuntimeServicesEnabled()

        this.ensureNotLoggedIn();
        this.isRuntimeServicesEnabled = false;
    
protected voidensureNotLoggedIn()
INTERNAL: Make sure that the DatabaseSession has not logged in yet. Throw a ValidationException if we have.

        //RCM: Allow for a null database session
        if (getDatabaseSession() == null) {
            return;
        }
        if (getDatabaseSession().isConnected()) {
            throw ValidationException.serverPlatformIsReadOnlyAfterLogin(this.getClass().getName());
        }
    
protected voidexternalTransactionControllerNotNullWarning()
INTERNAL: externalTransactionControllerNotNullWarning(): When the external transaction controller is being initialized, we warn the developer if they have already defined the external transaction controller in some way other than subclassing ServerPlatformBase.

see
#getExternalTransactionControllerClass()

        getDatabaseSession().warning("External_transaction_controller_not_defined_by_server_platform", SessionLog.EJB);
    
public oracle.toplink.essentials.internal.sessions.DatabaseSessionImplgetDatabaseSession()
INTERNAL: getDatabaseSession(): Answer the instance of DatabaseSession the receiver is helping.

return
DatabaseSession databaseSession

        return this.databaseSession;
    
public abstract java.lang.ClassgetExternalTransactionControllerClass()
INTERNAL: getExternalTransactionControllerClass(): Answer the class of external transaction controller to use For this server platform. This is read-only. If the user wants a different external transaction controller class than the provided ServerPlatform(s), we recommend subclassing oracle.toplink.essentials.platform.server.ServerPlatformBase (or a subclass), and overriding: ServerPlatformBase.getExternalTransactionControllerClass() for the desired behaviour.

return
Class externalTransactionControllerClass
see
oracle.toplink.essentials.transaction.JTATransactionController
see
#isJTAEnabled()
see
#disableJTA()

public java.lang.StringgetModuleName()
INTERNAL: getModuleName(): Answer the name of the module (jar name) that my session is associated with. Answer "unknown" if there is no module name available. Default behaviour is to return "unknown".

return
String moduleName

        return "unknown";
    
public oracle.toplink.essentials.logging.SessionLoggetServerLog()
INTERNAL: getServerLog(): Return the ServerLog for this platform Return the default ServerLog in the base

return
oracle.toplink.essentials.logging.SessionLog

        return new ServerLog();
    
public java.lang.StringgetServerNameAndVersion()
PUBLIC: getServerNameAndVersion(): Talk to the relevant server class library, and get the server name and version Default is "unknown"

return
String serverNameAndVersion

        return ToStringLocalization.buildMessage("unknown");
    
public voidinitializeExternalTransactionController()
INTERNAL: initializeExternalTransactionController(): Populate the DatabaseSession's external transaction controller with an instance of my transaction controller class. To change the external transaction controller class, we recommend creating a subclass of ServerPlatformBase, and overriding getExternalTransactionControllerClass().

see
ServerPlatformBase
return
void

        this.ensureNotLoggedIn();

        //BUG 3975114: Even if JTA is disabled, override if we're in CMP
        //JTA must never be disable during CMP (WLS/Oc4j)
        if (!isJTAEnabled() && !isCMP()) {
            return;
        }
        //BUG 3975114: display a warning if JTA is disabled and we're in CMP
        if (!isJTAEnabled() && isCMP()) {
            AbstractSessionLog.getLog().warning("jta_cannot_be_disabled_in_cmp");
        }

        //check if the transaction controller class is overridden by a preLogin or equivalent,
        //or if the transaction controller was already defined, in which case they should have written 
        //a subclass. Show a warning
        try {
            if (getDatabaseSession().getExternalTransactionController() != null) {
                this.externalTransactionControllerNotNullWarning();
                return;
            }
            ExternalTransactionController controller = null;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    controller = (ExternalTransactionController)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(this.getExternalTransactionControllerClass()));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof InstantiationException) {
                        throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName());
                    } else {
                        throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName());
                    }
                }
            } else {
                controller = (ExternalTransactionController)PrivilegedAccessHelper.newInstanceFromClass(this.getExternalTransactionControllerClass());
            }
            getDatabaseSession().setExternalTransactionController(controller);
        } catch (InstantiationException instantiationException) {
            throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName());
        } catch (IllegalAccessException illegalAccessException) {
            throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName());
        }
    
public booleanisCMP()
INTERNAL: isCMP(): Answer true if we're in the context of CMP (i.e. the container created me)

return
boolean

        return isCMP;
    
public booleanisJTAEnabled()
INTERNAL: isJTAEnabled(): Answer true if the DatabaseSession's external transaction controller class will be populated with my transaction controller class at runtime. If the transaction controller class is overridden in the DatabaseSession, my transaction controller class will be ignored. Answer true if TopLink will be configured to register for callbacks for beforeCompletion and afterCompletion.

return
boolean isJTAEnabled
see
#getExternalTransactionControllerClass()
see
#disableJTA()

        return this.isJTAEnabled;
    
public booleanisRuntimeServicesEnabled()
INTERNAL: isRuntimeServicesEnabled(): Answer true if the JMX/MBean providing runtime services for the receiver's DatabaseSession will be deployed at runtime.

return
boolean isRuntimeServicesEnabled
see
#disableRuntimeServices()

        return this.isRuntimeServicesEnabled;
    
public voidlaunchContainerRunnable(java.lang.Runnable runnable)
INTERNAL: launchContainerRunnable(Runnable runnable): Use the container library to start the provided Runnable. Default behaviour is to use Thread(runnable).start()

param
Runnable runnable: the instance of runnable to be "started"
return
void

        new Thread(runnable).start();
    
public voidregisterMBean()
INTERNAL: registerMBean(): Create and deploy the JMX MBean to provide runtime services for my databaseSession. Default is to do nothing.

return
void
see
#isRuntimeServicesEnabled()
see
#disableRuntimeServices()
see
#unregisterMBean()

        if (!this.isRuntimeServicesEnabled()) {
            return;
        }
        this.serverSpecificRegisterMBean();
    
public voidserverSpecificRegisterMBean()
INTERNAL: serverSpecificRegisterMBean(): Server specific implementation of the creation and deployment of the JMX MBean to provide runtime services for my databaseSession. Default is to do nothing. This should be subclassed if required.

return
void
see
#isRuntimeServicesEnabled()
see
#disableRuntimeServices()
see
#registerMBean()

    
public voidserverSpecificUnregisterMBean()
INTERNAL: serverSpecificUnregisterMBean(): Server specific implementation of the unregistration of the JMX MBean from its server. Default is to do nothing. This should be subclassed if required.

return
void
see
#isRuntimeServicesEnabled()
see
#disableRuntimeServices()

    
public voidsetExternalTransactionControllerClass(java.lang.Class newClass)
INTERNAL: setExternalTransactionControllerClass(Class newClass): Set the class of external transaction controller to use in the DatabaseSession. This is defined by the user via the sessions.xml.

see
oracle.toplink.essentials.transaction.JTATransactionController
see
#isJTAEnabled()
see
#disableJTA()
see
#initializeExternalTransactionController()

        this.externalTransactionControllerClass = newClass;
    
public voidsetIsCMP(boolean isThisCMP)
INTERNAL: setIsCMP(boolean): Define whether or not we're in the context of CMP (i.e. the container created me)

return
void

        isCMP = isThisCMP;
    
public voidunregisterMBean()
INTERNAL: unregisterMBean(): Unregister the JMX MBean that was providing runtime services for my databaseSession.

return
void
see
#isRuntimeServicesEnabled()
see
#disableRuntimeServices()
see
#registerMBean()

        if (!this.isRuntimeServicesEnabled()) {
            return;
        }
        this.serverSpecificUnregisterMBean();
    
public java.sql.ConnectionunwrapOracleConnection(oracle.toplink.essentials.internal.databaseaccess.Platform platform, java.sql.Connection connection)
INTERNAL: This method is used to unwrap the oracle connection wrapped by the application server. TopLink needs this unwrapped connection for certain Oracle Specific support. (ie TIMESTAMPTZ) This is added as a workaround for bug 4460996

        try {
            return connection.getMetaData().getConnection();
        } catch (java.sql.SQLException e){
            ((DatabaseSessionImpl)getDatabaseSession()).log(SessionLog.WARNING, SessionLog.CONNECTION, "cannot_unwrap_connection", e);
            return connection;            
        }