FileDocCategorySizeDatePackage
JdbcResourceDeployer.javaAPI DocGlassfish v2 API10345Fri May 04 22:35:14 BST 2007com.sun.enterprise.resource

JdbcResourceDeployer

public class JdbcResourceDeployer extends Object implements com.sun.enterprise.server.ResourceDeployer
Handles Jdbc resource events in the server instance. When user adds a jdbc resource, the admin instance emits resource event. The jdbc resource events are propagated to this object. The methods can potentially be called concurrently, therefore implementation need to be synchronized.
author
Nazrul Islam
since
JDK1.4

Fields Summary
private static final com.sun.enterprise.util.i18n.StringManager
localStrings
private static Logger
_logger
logger for this deployer
private static final String
PM_JNDI_EXTENSION
Constructors Summary
Methods Summary
private voidcheckAndDeletePool(com.sun.enterprise.config.serverbeans.JdbcResource cr)
Checks if no more resource-refs to resources exists for the JDBC connection pool and then deletes the pool

param
cr Jdbc Resource Config bean
throws
Exception if unable to access configuration/undeploy resource.
since
8.1 pe/se/ee

        String poolName = cr.getPoolName();
        Resources res = (Resources) cr.parent();
        
        try {
            boolean poolReferred = 
                ResourcesUtil.createInstance().isJdbcPoolReferredInServerInstance(poolName);
            if (!poolReferred) {
                _logger.fine("Deleting JDBC pool " + poolName + "as there is no more " +
                        "resource-refs to the pool in this server instance");
                com.sun.enterprise.config.serverbeans.JdbcConnectionPool jcp 
                                    = res.getJdbcConnectionPoolByName(poolName);
                //Delete/Undeploy Pool
                JdbcConnectionPoolDeployer deployer = 
                        new JdbcConnectionPoolDeployer();
                deployer.actualUndeployResource(jcp);
            }
        } catch (ConfigException ce) {
            _logger.warning(ce.getMessage());
            _logger.fine("Exception while deleting pool : " + ce );
            throw ce;
        }
    
public synchronized voiddeployResource(java.lang.Object resource)
Deploy the resource into the server's runtime naming context

param
resource a resource object (eg. JmsResource)
exception
Exception thrown if fail

                              
	       
        
        com.sun.enterprise.config.serverbeans.JdbcResource jdbcRes = 
            (com.sun.enterprise.config.serverbeans.JdbcResource) resource;
        
        if (jdbcRes.isEnabled()) {
            String jndiName = jdbcRes.getJndiName();
	    String poolName = jdbcRes.getPoolName();

        // loads dependent jdbc connection pool if not loaded
        loadPool(jdbcRes);

	    ManagementObjectManager mgr = Switch.getSwitch().getManagementObjectManager();
	    mgr.registerJDBCResource( jndiName );
	    ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
	    runtime.createConnectorResource( jndiName, poolName, null);
	    runtime.createConnectorResource( getPMJndiName( jndiName),
	            poolName, null);
	    _logger.finest("deployed resource " + jndiName );	    
        } else {
            _logger.log(Level.INFO, "core.resource_disabled", 
                new Object[] {jdbcRes.getJndiName(), 
                              IASJ2EEResourceFactoryImpl.JDBC_RES_TYPE});
        }
    
public synchronized voiddisableResource(java.lang.Object resource)
Disable the resource in the server's runtime naming context

param
resource a resource object (eg. JmsResource)
exception
Exception thrown if fail

        undeployResource(resource);
    
public synchronized voidenableResource(java.lang.Object resource)
Enable the resource in the server's runtime naming context

param
resource a resource object (eg. JmsResource)
exception
Exception thrown if fail

        deployResource(resource);
    
private java.lang.StringgetPMJndiName(java.lang.String jndiName)

        return jndiName + PM_JNDI_EXTENSION;
    
public java.lang.ObjectgetResource(java.lang.String name, com.sun.enterprise.config.serverbeans.Resources rbeans)
Utility method to find a resource from Resources beans and converte it to a resource object to be used by the implemented ResourceDeployer

param
name resource name (normally the jndi-name)
param
rbeans Resources config-beans
exception
Exception thrown if fail


        Object res = rbeans.getJdbcResourceByJndiName(name);

        if (res == null) {
            String msg = localStrings.getString("resource.no_resource",name);
            throw new Exception(msg);
        }

        return res;
    
private voidloadPool(com.sun.enterprise.config.serverbeans.JdbcResource jr)


        String poolName = jr.getPoolName();
        Resources resources = (Resources) jr.parent();
        ConfigBean cb = resources.getJdbcConnectionPoolByName(poolName);
        if (cb != null) {
            try {
                InitialContext ic = new InitialContext();
                ic.lookup(ConnectorAdminServiceUtils.
                                getReservePrefixedJNDINameForPool(poolName));
            } catch (Exception e) {
                // pool is not loaded
                JdbcConnectionPoolDeployer deployer = 
                        new JdbcConnectionPoolDeployer();
                deployer.actualDeployResource(cb);
            }
        }
    
public synchronized voidredeployResource(java.lang.Object resource)
Redeploy the resource into the server's runtime naming context

param
resource a resource object (eg. JmsResource)
exception
Exception thrown if fail


        undeployResource(resource);
        deployResource(resource);
    
public synchronized voidundeployResource(java.lang.Object resource)
Undeploy the resource from the server's runtime naming context

param
resource a resource object (eg. JmsResource)
exception
Exception thrown if fail


        com.sun.enterprise.config.serverbeans.JdbcResource jdbcRes = 
            (com.sun.enterprise.config.serverbeans.JdbcResource) resource;
        
	String jndiName = jdbcRes.getJndiName();
	String pmJndiName = getPMJndiName( jdbcRes.getJndiName() );

	ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
	runtime.deleteConnectorResource( jndiName );
	runtime.deleteConnectorResource( pmJndiName );
	
        ManagementObjectManager mgr =
                Switch.getSwitch().getManagementObjectManager();
        mgr.unregisterJDBCResource( jndiName );

        //Since 8.1 PE/SE/EE - if no more resource-ref to the pool 
        //of this resource exists in this server instance, remove 
        //pool from connector runtime
        checkAndDeletePool(jdbcRes);