FileDocCategorySizeDatePackage
ConnectorConnectionPoolAdminServiceImpl.javaAPI DocGlassfish v2 API69012Thu Jul 26 03:27:26 BST 2007com.sun.enterprise.connectors

ConnectorConnectionPoolAdminServiceImpl

public class ConnectorConnectionPoolAdminServiceImpl extends ConnectorServiceImpl implements ConnectorAdminService
This is connector connection pool admin service. It performs the functionality of creation,deletion,recreation, testing of the pools.
author
Srikanth P and Aditya Gore

Fields Summary
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public ConnectorConnectionPoolAdminServiceImpl()
Default constructor


           

      
        super();
        initialize();
    
Methods Summary
private voidcreateAndAddPool(java.lang.String poolName, PoolType pt)

        PoolManager poolMgr = Switch.getSwitch().getPoolManager();
        try {
	    poolMgr.createEmptyConnectionPool( poolName, pt );
        } catch( PoolingException pe ) {
            String i18nMsg = localStrings.getString(
                "ccp_adm.failed_to_create_pool_object");
            ConnectorRuntimeException cre = 
                new ConnectorRuntimeException( i18nMsg );
            cre.initCause( pe );
            throw cre;
        }
    
public voidcreateConnectorConnectionPool(ConnectorConnectionPool ccp, java.lang.String connectionDefinitionName, java.lang.String rarName, ElementProperty[] props, SecurityMap[] securityMaps)
Creates connector connection pool in the connector container.

param
ccp ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
param
connectionDefinitionName Connection definition name against which connection pool is being created
param
rarName Name of the resource adapter
param
props Properties of MCF which are present in domain.xml These properties override the ones present in ra.xml
param
securityMaps Array fo security maps.
throws
ConnectorRuntimeException When creation of pool fails.


        if( (ccp == null) ||  (connectionDefinitionName == null) 
                          || (rarName == null)) {
            _logger.log(Level.FINE,"Wrong parameters for pool creation ");
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.wrong_params_for_create");
            throw new ConnectorRuntimeException( i18nMsg );
        }
        ConnectorDescriptor connectorDescriptor = 
                                _registry.getDescriptor(rarName);
        if(connectorDescriptor == null) {
            ifSystemRarLoad(rarName);
            connectorDescriptor = _registry.getDescriptor(rarName);
        }
        if (connectorDescriptor == null) {
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.no_conn_pool_obj");
            ConnectorRuntimeException cre = new ConnectorRuntimeException(
                            i18nMsg );
            _logger.log(Level.SEVERE,
              "rardeployment.connector_descriptor_notfound_registry",rarName);
            _logger.log(Level.SEVERE,"",cre);
            throw cre; 
        }
        Set connectionDefs =  
          connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();
        ConnectionDefDescriptor cdd = null;
        Iterator it = connectionDefs.iterator();
        while(it.hasNext()) {
          cdd = (ConnectionDefDescriptor)it.next();
          if(connectionDefinitionName.equals(cdd.getConnectionFactoryIntf()))
              break;

        }
        ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();

        cdi.setRarName(rarName);
        cdi.setResourceAdapterClassName(
                    connectorDescriptor.getResourceAdapterClass());
        cdi.setConnectionDefinitionName(cdd.getConnectionFactoryIntf());
        cdi.setManagedConnectionFactoryClass(
                    cdd.getManagedConnectionFactoryImpl());
        cdi.setConnectionFactoryClass(cdd.getConnectionFactoryImpl());
        cdi.setConnectionFactoryInterface(cdd.getConnectionFactoryIntf());
        cdi.setConnectionClass(cdd.getConnectionImpl());
        cdi.setConnectionInterface(cdd.getConnectionIntf());
        Set mergedProps = ConnectorDDTransformUtils.mergeProps(props, 
                      cdd.getConfigProperties());
        cdi.setMCFConfigProperties(mergedProps);
        cdi.setResourceAdapterConfigProperties(
                    connectorDescriptor.getConfigProperties());
        ccp.setSecurityMaps(SecurityMapUtils.getConnectorSecurityMaps(securityMaps));
        createConnectorConnectionPool(ccp , cdi);
    
public voidcreateConnectorConnectionPool(ConnectorConnectionPool ccp, ConnectionDefDescriptor cdd, java.lang.String rarName)
Creates connector connection pool in the connector container.

param
ccp ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
param
cdd ConnectorDescriptor obejct which abstracts the ra.xml
param
rarName Name of the resource adapter
throws
ConnectorRuntimeException When creation of pool fails.


        if( (ccp == null) ||  (cdd == null) || (rarName == null)) {

            _logger.log(Level.FINE,"Wrong parameters for pool creation ");
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.wrong_params_for_create");
            throw new ConnectorRuntimeException( i18nMsg );
        }
        ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo(); 

        ConnectorDescriptor connectorDescriptor = _registry.getDescriptor(
                                                          rarName);
        if(connectorDescriptor == null) {
            ifSystemRarLoad(rarName);
            connectorDescriptor = _registry.getDescriptor(rarName);
        }

        if (connectorDescriptor == null) {
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.no_conn_pool_obj");
            ConnectorRuntimeException cre = new 
	        ConnectorRuntimeException(i18nMsg);
            _logger.log(Level.SEVERE,
                  "rardeployment.connector_descriptor_notfound_registry",
                  rarName);
            _logger.log(Level.SEVERE,"",cre);
            throw cre;
        }
        cdi.setRarName(rarName);
        cdi.setResourceAdapterClassName(
                          connectorDescriptor.getResourceAdapterClass());
        cdi.setConnectionDefinitionName(cdd.getConnectionFactoryIntf());
	cdi.setManagedConnectionFactoryClass(
                          cdd.getManagedConnectionFactoryImpl());
	cdi.setConnectionFactoryClass(cdd.getConnectionFactoryImpl());
	cdi.setConnectionFactoryInterface(cdd.getConnectionFactoryIntf());
	cdi.setConnectionClass(cdd.getConnectionImpl());
	cdi.setConnectionInterface(cdd.getConnectionIntf());
	cdi.setMCFConfigProperties(cdd.getConfigProperties());
	cdi.setResourceAdapterConfigProperties(
                          connectorDescriptor.getConfigProperties());
        createConnectorConnectionPool(ccp , cdi);
    
private voidcreateConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj, ConnectorDescriptorInfo connectorDescInfo)
Creates connector connection pool in the connector container.

param
ccp ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
param
connectorDescInfo ConnectorDescriptorInfo object which abstracts the connection definition values present in ra.xml
throws
ConnectorRuntimeException When creation of pool fails.


	connectorPoolObj.setConnectorDescriptorInfo( connectorDescInfo );
        createConnectorConnectionPool( connectorPoolObj );
    
public voidcreateConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj)
Creates connector connection pool in the connector container.

param
ccp ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
throws
ConnectorRuntimeException When creation of pool fails.


        String poolName = connectorPoolObj.getName();
        if( connectorPoolObj == null || poolName == null) {
            _logger.log(Level.FINE,"Wrong parameters for pool creation ");
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.wrong_params_for_create");
            throw new ConnectorRuntimeException( i18nMsg );
        }
        String jndiNameForPool = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForPool(poolName);
        try {
            Switch.getSwitch().getNamingManager().publishObject(
                          jndiNameForPool,(Object)connectorPoolObj,true);
            ManagedConnectionFactory mcf =
                          obtainManagedConnectionFactory(poolName);
            if(mcf == null) {
 	        InitialContext ic = new InitialContext();
                ic.unbind(jndiNameForPool);
	        String i18nMsg = localStrings.getString(
	            "ccp_adm.failed_to_create_mcf");
		ConnectorRuntimeException cre = new 
		    ConnectorRuntimeException( i18nMsg );    
                _logger.log(Level.SEVERE,"rardeployment.mcf_creation_failure",
                           poolName);
                _logger.log(Level.SEVERE,"",cre);
		throw cre;
            }

        } catch(NamingException ex) {
	   
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.failed_to_publish_in_jndi");
            ConnectorRuntimeException cre = new 
		    ConnectorRuntimeException( i18nMsg );
            cre.initCause(ex);
            _logger.log(Level.SEVERE,"rardeployment.pool_jndi_bind_failure",
                         poolName);
            _logger.log(Level.SEVERE,"",cre);
            throw cre;
        } catch(NullPointerException ex) {
            try {
 	       	InitialContext ic = new InitialContext();
                ic.unbind(jndiNameForPool);
            } catch(NamingException ne) {
                _logger.log(Level.FINE, 
                     "Failed to unbind connection pool object  ",poolName);
            }
	    
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.failed_to_register_mcf");
            ConnectorRuntimeException cre = new 
		    ConnectorRuntimeException( i18nMsg );
            cre.initCause(ex);
            _logger.log(Level.SEVERE,"rardeployment.mcf_registration_failure",
                                     poolName);
            _logger.log(Level.SEVERE,"",cre);
            throw cre;
        } 
    
public voidcreateConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj, java.lang.String security, java.util.Set configProperties)
Creates connector connection pool in the connector container. cannot be used for 1.5 rar cases

param
ccp ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
param
security unused
param
configProperties MCF config properties
throws
ConnectorRuntimeException When creation of pool fails.

        if( connectorPoolObj == null || configProperties == null) {
             _logger.log(Level.FINE,"Wrong parameters for pool creation ");
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.wrong_params_for_create");
            throw new ConnectorRuntimeException( i18nMsg );
        }
        String poolName = connectorPoolObj.getName();
        String moduleName = 
                    connectorPoolObj.getConnectorDescriptorInfo().getRarName();
        String connectionDefinitionName = 
                    connectorPoolObj.getConnectorDescriptorInfo().
                    getConnectionDefinitionName();

        ConnectorDescriptor connectorDescriptor = 
                    _registry.getDescriptor(moduleName);
        if(connectorDescriptor == null) {
            ifSystemRarLoad(moduleName);
            connectorDescriptor = _registry.getDescriptor(moduleName);
        }

        if(connectorDescriptor == null) {
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.null_connector_desc");
            ConnectorRuntimeException cre = new 
		    ConnectorRuntimeException( i18nMsg );    
             _logger.log(Level.SEVERE,"rardeployment.null_mcf_in_registry", 
                    moduleName); 
             _logger.log(Level.SEVERE,"", cre); 
            throw cre;
        }

        Set connectionDefs = 
          connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();

        Iterator iterator = connectionDefs.iterator();

        ConnectionDefDescriptor connectionDefDescriptor = null;

        while(iterator.hasNext()){
              connectionDefDescriptor = 
                       (ConnectionDefDescriptor) iterator.next();
              if(connectionDefinitionName.equals(
                       connectionDefDescriptor.getConnectionFactoryIntf()))
                 break;
        }

        ConnectorDescriptorInfo connectorDescInfo = 
                 ConnectorDDTransformUtils.getConnectorDescriptorInfo(
                 connectionDefDescriptor);
        connectorDescInfo.setMCFConfigProperties(configProperties);
        connectorDescInfo.setRarName(moduleName);
        connectorDescInfo.setResourceAdapterClassName(
                     connectorDescriptor.getResourceAdapterClass());

        createConnectorConnectionPool(connectorPoolObj,connectorDescInfo);
    
public voiddeleteConnectorConnectionPool(java.lang.String poolName)
Deletes connector Connection pool

param
poolName Name of the pool to delete
throws
ConnectorRuntimeException if pool deletion operation fails

        deleteConnectorConnectionPool(poolName,false);
    
public voiddeleteConnectorConnectionPool(java.lang.String poolName, boolean cascade)
Deletes connector Connection pool. Here check in made whether resources pertaining to pool are present in domain.xml.

param
poolName Name of the pool to delete
param
cascade If true all the resources associed with that are also deleted from connector container If false and if some resources pertaining to pool are present deletion operation fails . If no resources are present pool is deleted.
throws
ConnectorRuntimeException if pool deletion operation fails


        if(poolName==null){
            _logger.log( Level.WARNING,"Deletion of pool : poolName null.");
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.null_pool_name");
            throw new ConnectorRuntimeException( i18nMsg );
        }
 
        boolean errorOccured=false;
        ResourcesUtil resUtil = ResourcesUtil.createInstance();
        Object[] connectorResourcesJndiNames = 
                        resUtil.getConnectorResourcesJndiNames(poolName);
        if(cascade==true && connectorResourcesJndiNames != null) {
           for(int i=0;i<connectorResourcesJndiNames.length;++i) {
               try {
                   getRuntime().deleteConnectorResource(
                              (String)connectorResourcesJndiNames[i]);
               } catch(ConnectorRuntimeException cre) {
                 errorOccured=true;
               }
           }

        } else if(connectorResourcesJndiNames != null && 
                      connectorResourcesJndiNames.length != 0) {

           // FIXME: ResourcesUtil class needs to change so that 
           // it is reference friendly.
           // Refer to bug 5004451
           /*
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.connector_res_exist");
            ConnectorRuntimeException cre = new 
		    ConnectorRuntimeException( i18nMsg );    
           _logger.log(Level.SEVERE,"rardeployment.resources_exist",
                                     poolName);
           _logger.log(Level.SEVERE,"",cre);
            throw cre;
            */
        }
        killPool(poolName);
        boolean result = _registry.removeManagedConnectionFactory(poolName);
        if(result == false && !resUtil.poolBelongsToSystemRar(poolName)) {
            _logger.log( Level.FINE,
                           "rardeployment.mcf_removal_failure",poolName);
	    return;
        }
        try {
            String jndiNameForPool = ConnectorAdminServiceUtils.
                getReservePrefixedJNDINameForPool( poolName );
            InitialContext ic = new InitialContext();
            ic.unbind(jndiNameForPool);
        } catch(NamingException ne) {
            if(resUtil.poolBelongsToSystemRar(poolName)) {
                return;
            }
            _logger.log(Level.SEVERE,
                   "rardeployment.connectionpool_removal_from_jndi_error", 
                   poolName);
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.failed_to_remove_from_jndi");
	    ConnectorRuntimeException cre = new 
	        ConnectorRuntimeException( i18nMsg );	
            cre.initCause(ne);
            _logger.log(Level.SEVERE,"",cre);
	    throw cre;
        }
        if(errorOccured==true && !resUtil.poolBelongsToSystemRar(poolName)) {
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.failed_to_delete_conn_res" );
	    ConnectorRuntimeException cre = new 
		    ConnectorRuntimeException( i18nMsg );    
            _logger.log(Level.SEVERE,
                "rardeployment.all_resources_removal_error", poolName);
            _logger.log(Level.SEVERE,"",cre);
            throw cre;
        }
    
private voiddump(java.lang.String poolName)

        try {
            ConfigContext ctx = com.sun.enterprise.admin.server.core.AdminService.
                    getAdminService().getAdminContext().getAdminConfigContext();
            Domain dom = ServerBeansFactory.getDomainBean(ctx);
            Resources res = dom.getResources();
    
            ConfigBean dasContextBean = null;
    
            com.sun.enterprise.config.serverbeans.JdbcConnectionPool
                    jdbcPool = res.getJdbcConnectionPoolByName(poolName);
    
            //Determine whether the pool is JDBC Pool or Connector Connection Pool and dump accordingly
            if (jdbcPool != null) {
                dasContextBean = (ConfigBean) jdbcPool;
            } else {
                com.sun.enterprise.config.serverbeans.ConnectorConnectionPool ccPool =
                        res.getConnectorConnectionPoolByName(poolName);
                if (ccPool != null) {
                    dasContextBean = (ConfigBean) ccPool;
                }
            }
    
            if (dasContextBean != null) {
                StringBuffer str = new StringBuffer();
                dasContextBean.dump(str, "\t\t");
                _logger.log(Level.FINE, "DAS CONTEXT IS : " + str);
            }
        } catch (Exception e) {
            _logger.log(Level.WARNING, "Exception while dumping pool details ", e.fillInStackTrace());
        }
    
public java.sql.ConnectiongetConnection(java.lang.String jndiName, java.lang.String user, java.lang.String password)
Get a sql connection from the DataSource specified by the jdbcJndiName. This API is intended to be used in the DAS. The motivation for having this API is to provide the CMP backend a means of acquiring a connection during the codegen phase. If a user is trying to deploy an app on a remote server, without this API, a resource reference has to be present both in the DAS and the server instance. This makes the deployment more complex for the user since a resource needs to be forcibly created in the DAS Too. This API will mitigate this need.

param
jndiName the jndi name of the resource being used to get Connection from This resource can either be a pmf resource or a jdbc resource
param
user the user used to authenticate this request
param
password the password used to authenticate this request
return
a java.sql.Connection
throws
java.sql.SQLException in case of errors

        java.sql.Connection con = null;
	try {
            DASResourcesUtil.setAdminConfigContext();
            String poolName = getPoolNameFromResourceJndiName( jndiName );
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("ConnectorRuntime.getConnection :: poolName : " + poolName );
            }
	    //Maintain consitency with the ConnectionManagerImpl change to be checked in later
	    String passwd = (password == null ) ? "" : password;

	    //From what we have seen so far, the user cannot be null 
	    //but password can be
	    //if user is null we will use default authentication
	    //TODO: Discuss if this is the right thing to do
	    ResourcePrincipal prin = (user == null) ? 
	        null : new ResourcePrincipal(user, password);
	    con = (java.sql.Connection) getUnpooledConnection( poolName, prin, true);
	    if ( con == null ) {
	        String i18nMsg = localStrings.getString(
	           "ccp_adm.null_unpooled_connection");
		SQLException sqle = new SQLException( i18nMsg );
		throw sqle;
	    }
	} catch( ResourceException re ) {
	    SQLException sqle = new SQLException( re.getMessage() );
	    sqle.initCause( re );
	    _logger.log( Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
	    if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine( " getConnection in ConnectorRuntime failed : " + re );
	    }
            throw sqle;
	}catch (ConfigException ex) {
            SQLException sqle = new SQLException( ex.getMessage() );
	    sqle.initCause( ex );
	    _logger.log( Level.WARNING, "jdbc.exc_get_conn", ex.getMessage());
	    if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine( " getConnection in ConnectorRuntime failed : " + ex );
	    }
            throw sqle;
        }finally {
	    try {
	        DASResourcesUtil.resetAdminConfigContext();
	    } catch( Exception e ) {
		if (_logger.isLoggable(Level.FINE)) {
	            _logger.fine("caught exception while setting " + 
		        "getConnectionFromConnectorRuntime to false");
		}    
	    }

	}

	return con; 
    
public java.sql.ConnectiongetConnection(java.lang.String jndiName)
Get a sql connection from the DataSource specified by the jdbcJndiName. This API is intended to be used in the DAS. The motivation for having this API is to provide the CMP backend a means of acquiring a connection during the codegen phase. If a user is trying to deploy an app on a remote server, without this API, a resource reference has to be present both in the DAS and the server instance. This makes the deployment more complex for the user since a resource needs to be forcibly created in the DAS Too. This API will mitigate this need.

param
jndiName the jndi name of the resource being used to get Connection from This resource can either be a pmf resource or a jdbc resource
return
a java.sql.Connection
throws
java.sql.SQLException in case of errors

	java.sql.Connection con = null;
	try {
	    DASResourcesUtil.setAdminConfigContext();
	    String poolName = getPoolNameFromResourceJndiName( jndiName );
            if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine("ConnectorRuntime.getConnection :: poolName : " 
		    + poolName );
	    }
	    con = (java.sql.Connection) getUnpooledConnection( poolName, null, 
	        true );
	    if ( con == null ) {
	        String i18nMsg = localStrings.getString(
	           "ccp_adm.null_unpooled_connection");
		SQLException sqle = new SQLException( i18nMsg );
		throw sqle;
	    }
	} catch( ResourceException re ) {
	    SQLException sqle = new SQLException( re.getMessage() );
	    sqle.initCause( re );
	    _logger.log( Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
	    if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine( "Exception : " + re );
	    }
	    throw sqle;
	}catch (ConfigException ex) {
            SQLException sqle = new SQLException( ex.getMessage() );
	    sqle.initCause( ex );
	    _logger.log( Level.WARNING, "jdbc.exc_get_conn", ex.getMessage());
	    if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine( " getConnection in ConnectorRuntime failed : " + ex );
	    }
            throw sqle;
        } finally {
	    try {
	        DASResourcesUtil.resetAdminConfigContext();
	    } catch( Exception e ) {
		if (_logger.isLoggable(Level.FINE)) {
	            _logger.fine("caught exception while setting " + 
		        "getConnectionFromConnectorRuntime to false");
		}    
	    }
	}

	return con;
    
public static java.util.SetgetConnectionDefinitionProperties(java.lang.String connectionDefinitionClassName)
Gets the properties of the Java bean connection definition class that have setter methods defined

param
connectionDefinitionClassName The Connection Definition Java bean class for which overrideable properties are required.
return
A Set of properties that have a setter method defined in the Connection Definition class

        return ConnectionDefinitionUtils.getConnectionDefinitionProperties(
            connectionDefinitionClassName);
    
public static java.util.MapgetConnectionDefinitionPropertiesAndDefaults(java.lang.String connectionDefinitionClassName)
Gets the properties of the Java bean connection definition class that have setter methods defined and the default values as provided by the Connection Definition java bean developer.

param
connectionDefinitionClassName The Connection Definition Java bean class for which overrideable properties are required.
return
Map [property, defaultValue]

        return ConnectionDefinitionUtils
            .getConnectionDefinitionPropertiesAndDefaults(
            connectionDefinitionClassName);
    
private ConnectorConnectionPoolgetConnectorConnectionPool(java.lang.String poolName)
Returns the connector connection pool object corresponding to the pool name

param
poolName Name of the pool.MCF pertaining to this pool is created/returned.
return
Connector connection pool corresponding to this instance
throws
ConnectorRuntimeException if creation/retrieval of MCF fails

                String jndiNameForPool = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForPool ( poolName );
                InitialContext ic = new InitialContext();
                ConnectorConnectionPool connectorConnectionPool =
                        (ConnectorConnectionPool) ic.lookup(jndiNameForPool);
                if(connectorConnectionPool == null) {
                    String i18nMsg = localStrings.getString(
                        "ccp_adm.null_pool");
                     ConnectorRuntimeException cre = new
                         ConnectorRuntimeException( i18nMsg );
                    _logger.log(Level.SEVERE,
                        "rardeployment.connectionpool_object_null",poolName);
                    if (_logger.isLoggable( Level.FINE ) ) {
                        _logger.log(Level.FINE,"",cre);
                    }
                    throw cre;
                }
		return connectorConnectionPool;
	
private com.sun.enterprise.config.serverbeans.ConnectorConnectionPoolgetConnectorConnectionPoolServerBean(java.lang.String poolName)

	if ( poolName == null ) {
	    throw new ConfigException("null poolname");
	}

	ConfigContext ctxt = null;

	if ( ResourcesUtil.isDAS() ) {
	    ctxt = com.sun.enterprise.admin.server.core.AdminService.
	        getAdminService().getAdminContext().getAdminConfigContext();
	} else {
	    ctxt = ApplicationServer.getServerContext().getConfigContext();
	}
	Domain dom = ServerBeansFactory.getDomainBean( ctxt );
	Resources res = dom.getResources(); 
        
	return res.getConnectorConnectionPoolByName( poolName );
	
    
private ResourcePrincipalgetDefaultResourcePrincipal(java.lang.String poolName, ManagedConnectionFactory mcf)

        // All this to get the default user name and principal 
        ConnectorConnectionPool connectorConnectionPool = null;
        try {
            String jndiNameForPool = ConnectorAdminServiceUtils.
                getReservePrefixedJNDINameForPool( poolName );
            InitialContext ic = new InitialContext();
            connectorConnectionPool = 
                    (ConnectorConnectionPool) ic.lookup(jndiNameForPool);
	} catch (NamingException ne ) {
	    throw ne;
	}
	
        ConnectorDescriptorInfo cdi = connectorConnectionPool.
            getConnectorDescriptorInfo();
        
        Set mcfConfigProperties = cdi.getMCFConfigProperties();
        Iterator mcfConfPropsIter = mcfConfigProperties.iterator();
        String userName = null;
        String password = null;
        while( mcfConfPropsIter.hasNext() ) {
            EnvironmentProperty prop =
            (EnvironmentProperty)mcfConfPropsIter.next();
            
            if ( prop.getName().toUpperCase().equals("USERNAME") || 
                 prop.getName().toUpperCase().equals("USER") ) {
                userName = prop.getValue();
            } else if ( prop.getName().toUpperCase().equals("PASSWORD") ) {
                password = prop.getValue();
                try{
                    password = RelativePathResolver.getRealPasswordFromAlias(password);
                }catch(Exception e){
                    _logger.log(Level.WARNING,"unable_to_get_password_from_alias",e); 
                }
            }
        }

        // To avoid using "", "" as the default username password, try to get
        // the username and password from MCF, to use in subject. MQ adapter
        // cannot use "","" as the username/password.

        if (userName == null || userName.trim().equals("")) {
            userName = ConnectionPoolObjectsUtils.getValueFromMCF("UserName", poolName, mcf);
            //It is possible that ResourceAdapter may have getUser() instead of 
            //getUserName() property getter
            if(userName.trim().equals("")){
                userName =  ConnectionPoolObjectsUtils.getValueFromMCF("User", poolName, mcf);
            }
            password = ConnectionPoolObjectsUtils.getValueFromMCF("Password", poolName, mcf);
        }
        //Now return the ResourcePrincipal
        return new ResourcePrincipal( userName, password );
    
private com.sun.enterprise.config.serverbeans.JdbcConnectionPoolgetJdbcConnectionPoolServerBean(java.lang.String poolName)

	if ( poolName == null ) {
	    throw new ConfigException("null poolname");
	}

	ConfigContext ctxt = null;

	if ( ResourcesUtil.isDAS() ) {
	    ctxt = com.sun.enterprise.admin.server.core.AdminService.
	        getAdminService().getAdminContext().getAdminConfigContext();
	} else {
	    ctxt = ApplicationServer.getServerContext().getConfigContext();
	}
	Domain dom = ServerBeansFactory.getDomainBean( ctxt );
	Resources res = dom.getResources(); 
        
	return res.getJdbcConnectionPoolByName( poolName );
	
    
private ConnectorConnectionPoolgetOriginalConnectorConnectionPool(java.lang.String poolName)

        	
	ConnectorConnectionPool ccpOrig = null;
	
        String jndiNameForPool = ConnectorAdminServiceUtils.
            getReservePrefixedJNDINameForPool( poolName );
        InitialContext ic = new InitialContext();
        try {
            ccpOrig = (ConnectorConnectionPool) ic.lookup( jndiNameForPool );
        } catch(NamingException ne) {
            if(checkAndLoadPoolResource(poolName)) {
                ccpOrig = (ConnectorConnectionPool)ic.lookup( jndiNameForPool );
            } else {
                throw ne;
            }

        }
	
        return ccpOrig;
    
private java.lang.StringgetPoolNameFromResourceJndiName(java.lang.String jndiName)
Gets the Pool name that this JDBC resource points to. In case of a PMF resource gets the pool name of the pool pointed to by jdbc resource being pointed to by the PMF resource

param
jndiName the jndi name of the resource being used to get Connection from This resource can either be a pmf resource or a jdbc resource
return
poolName of the pool that this resource directly/indirectly points to

        String poolName = null ;
        JdbcResource jdbcRes = null;
        DASResourcesUtil resourcesUtil = (DASResourcesUtil)ResourcesUtil.createInstance();
	
        //check if the jndi name is that of a pmf resource or a jdbc resource
        PersistenceManagerFactoryResource pmfRes = 
                resourcesUtil.getPMFResourceByJndiName(jndiName );
	if (pmfRes != null) {
	    jdbcRes = resourcesUtil.getJdbcResourceByJndiName(
                    pmfRes.getJdbcResourceJndiName());
	} else {
	    jdbcRes = resourcesUtil.getJdbcResourceByJndiName(jndiName);
	}

	if ( jdbcRes != null ) {
            if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine( "jdbcRes is ---: " + jdbcRes.getJndiName() );
	        _logger.fine( "poolName is ---: " + jdbcRes.getPoolName() );
	    }
	}
	return jdbcRes == null ? null : jdbcRes.getPoolName();    
    
private ActiveResourceAdaptergetResourceAdapter(ConnectorConnectionPool connectorConnectionPool)
Returns the resource adapter object corresponding to the pool

param
connectorConnectionPool Name of the pool. MCF pertaining to this pool is created/returned.
return
Resource adapter instance corresponding to this pool.
throws
ConnectorRuntimeException if creation/retrieval of RA fails

 
                String rarName = connectorConnectionPool.
                                  getConnectorDescriptorInfo().getRarName();
                ActiveResourceAdapter activeResourceAdapter =
                                  _registry.getActiveResourceAdapter(rarName);
                if(activeResourceAdapter == null) {
                    ifSystemRarLoad(rarName);
                    activeResourceAdapter =
                             _registry.getActiveResourceAdapter(rarName);
                }
                if( activeResourceAdapter == null) {
                    String i18nMsg = localStrings.getString(
                        "ccp_adm.active_ra_not_init");

                    ConnectorRuntimeException cre = new
                        ConnectorRuntimeException( i18nMsg );
                    _logger.log(Level.SEVERE,
                      "rardeployment.resourceadapter_not_initialized",rarName);
                    if (_logger.isLoggable( Level.FINE ) ) {
                        _logger.log(Level.FINE,"",cre);
                    }
                    throw cre;
                }
		return activeResourceAdapter;
        
private java.lang.ObjectgetUnpooledConnection(java.lang.String poolName, ResourcePrincipal prin, boolean returnConnectionHandle)
This method is used to provide backend functionality for the ping-connection-pool asadmin command. Briefly the design is as follows:
1. obtainManagedConnectionFactory for the poolname
2. lookup ConnectorDescriptorInfo from InitialContext using poolname
3. from cdi get username and password
4. create ResourcePrincipal using default username and password
5. create a Subject from this (doPriveleged)
6. createManagedConnection using above subject
7. add a dummy ConnectionEventListener to the mc that simply handles connectionClosed 8. getConnection from the ManagedConnection with above subject

param
poolName The poolname from whose MCF to obtain the unpooled mc
param
prin The ResourcePrincipal to use for authenticating the request if not null. If null, the pool's default authentication mechanism is used
param
returnConnectionHandle If true will return the logical connection handle derived from the Managed Connection, else will only return mc
return
an unPooled connection
throws
ResourceException for various error conditions

        //Get the ManagedConnectionFactory for this poolName
	ManagedConnectionFactory mcf = null;
	boolean needToUndeployPool = false;
        com.sun.enterprise.config.serverbeans.JdbcConnectionPool 
	    jdbcPoolToDeploy = null;
        com.sun.enterprise.config.serverbeans.ConnectorConnectionPool 
	    ccPoolToDeploy = null;


        try {
	    mcf = obtainManagedConnectionFactory( poolName );
	    
	} catch( ConnectorRuntimeException cre ) {
            logFine("getUnpooledConnection :: obtainManagedConnectionFactory " +
	        "threw exception. SO doing checkAndLoadPoolResource");	    
            if(checkAndLoadPoolResource(poolName)) { 
                logFine("getUnpooledConnection:: checkAndLoadPoolResource is true");
                try {
		    //deploy the pool resource if not already done
		    //The pool resource would get loaded in case we are in DAS
		    //due to the checkAndLoadPoolResource call
		    //but in EE, if the pool we are trying to access is in a
		    //remote instance, the pool will not have been created
		    if ( ! isConnectorConnectionPoolDeployed( poolName ) ) {
                        logFine("getUnpooledConnection :: " + 
			    "isConnectorConnectionPoolDeployed is false");
		        try {
		            jdbcPoolToDeploy = getJdbcConnectionPoolServerBean( poolName );
			    if ( jdbcPoolToDeploy != null ) {
		                (new JdbcConnectionPoolDeployer()).deployResource( 
			            jdbcPoolToDeploy );	
                                logFine("getUnpooledConnection :: force deployed the " + 
			            "JdbcConnectionPool : " + poolName);	
			    } else {
			        ccPoolToDeploy = getConnectorConnectionPoolServerBean(
				    poolName );
			        (new ConnectorConnectionPoolDeployer()).deployResource(
				    ccPoolToDeploy);
                                logFine("getUnpooledConnection :: force deployed the " + 
			            "ConnectorConnectionPool :" + poolName);	
			    }
			    needToUndeployPool = true;
		        } catch(Exception e ) {
		            _logger.log( Level.SEVERE, 
		                "jdbc.could_not_do_actual_deploy for : ", poolName );
		            throw new ResourceException( e );    
		        }
		    }
                    logFine("getUnpooledConnection :: " + 
		        "Now calling obtainManagedConnectionFactory again");		    
	            mcf = obtainManagedConnectionFactory( poolName );
                    logFine("getUnpooledConnection:: " + 
		        "done obtainManagedConnectionFactory again");		    
	        } catch( ConnectorRuntimeException creAgain ) {
		    String l10nMsg = localStrings.getString(
		        "pingpool.cannot_obtain_mcf");
		    _logger.log( Level.WARNING, "jdbc.pool_not_reachable", 
                        l10nMsg );
		    ResourceException e = new ResourceException( l10nMsg );
		    e.initCause( creAgain );
		    throw e;
                }
            } else {
	        _logger.log( Level.WARNING, "jdbc.pool_not_reachable", 
                         cre.getMessage() );
		String l10nMsg = localStrings.getString(
		        "pingpool.cannot_obtain_mcf");
                ResourceException e = new ResourceException( l10nMsg );
                e.initCause( cre );
                throw e;

            }
	}
        
	
        ResourcePrincipal resourcePrincipal = null;
	if (prin == null ) {
	    try {
                resourcePrincipal = getDefaultResourcePrincipal( poolName, mcf);
            } catch( NamingException ne) {
	        _logger.log(Level.WARNING, "jdbc.pool_not_reachable", 
                            ne.getMessage() );
                String l10nMsg = localStrings.getString(
	            "pingpool.name_not_bound");
                ResourceException e = new ResourceException( l10nMsg + poolName  );   	
	        e.initCause( ne );
	        throw e;
	    }
	} else {
	    resourcePrincipal = prin;
	}
        
	final Subject defaultSubject = 
            ConnectionPoolObjectsUtils.createSubject( mcf, resourcePrincipal);

	  
	if (_logger.isLoggable(Level.FINE)) {
	    _logger.fine("using subject: " + defaultSubject);
	    
	}
        
	ManagedConnection mc = null;
	//Create the ManagedConnection
	mc = mcf.createManagedConnection( defaultSubject, null );

	//We are done with the pool for now, so undeploy if we deployed
	//it here
        if ( needToUndeployPool ) {
	    if (jdbcPoolToDeploy != null ) {
	    logFine("getUnpooledConnection :: need to force undeploy pool");
                try {
                    (new JdbcConnectionPoolDeployer()).undeployResource( 
                        jdbcPoolToDeploy );	
                } catch( Exception e ) {
                    _logger.fine( "getUnpooledConnection: error undeploying pool");
                }
	        logFine("getUnpooledConnection :: done.. force undeploy of pool");
	    } else {
	        try {
                    (new ConnectorConnectionPoolDeployer()).undeployResource( 
                        ccPoolToDeploy );	
                } catch( Exception e ) {
                    _logger.fine( "getUnpooledConnection: error undeploying pool");
                }
	        logFine("getUnpooledConnection :: done.. force undeploy of pool");
            }
        }

	//Add our dummy ConnectionEventListener impl.
	//This impl only knows how to handle connectionClosed events
	mc.addConnectionEventListener( new UnpooledConnectionEventListener() );
        return returnConnectionHandle ? 
	    mc.getConnection( defaultSubject, null ) :
	    mc;
    
private voidinitialize()

        Switch sw = Switch.getSwitch();
	if (sw.getContainerType() == ConnectorConstants.NON_ACC_CLIENT) { 
            //Invocation from a non-ACC client
	    try {
	        if (sw.getPoolManager() == null) { 
		    sw.setPoolManager(new PoolManagerImpl());
		}

	        if (sw.getNamingManager() == null) { 
		    sw.setNamingManager(new NamingManagerImpl());
		}
	    } catch(Exception e) {
                _logger.log( Level.WARNING, e.getMessage());
	    }
	}

    
public booleanisConnectorConnectionPoolDeployed(java.lang.String poolName)
Checks if a conncetor connection pool has been deployed to this server instance

param
poolName
return

        try {
            InitialContext ic = new InitialContext();
            String jndiName = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForPool( poolName ); 
            ic.lookup(jndiName);
            return true;
        } catch (NamingException e) {
            return false;
        }
    
public voidkillAllPools(java.lang.String moduleName)
Kills all the pools pertaining to the rar module.

moduleName
Rar module Name


        ResourcesUtil resUtil = ResourcesUtil.createInstance();
        Object[] poolNamesArray = resUtil.getConnectorConnectionPoolNames(
                                           moduleName);
        String poolName=null;
        for(int i=0;poolNamesArray != null && i<poolNamesArray.length;i++) {
            poolName = (String)poolNamesArray[i];
            killPool(poolName);
        }
    
public voidkillPool(java.lang.String poolName)
Kills a specific pool

param
poolName poolName to kill

        Switch.getSwitch().getPoolManager().killPool(poolName);
    
private voidlogFine(java.lang.String msg)

        if ( msg != null ) {
            if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine( msg );
	    }
        }
    
public ManagedConnectionFactory[]obtainManagedConnectionFactories(java.lang.String poolName)
Returns the MCF instances.

param
poolName Name of the pool.MCF pertaining to this pool is created/returned.
return
created/already present MCF instance
throws
ConnectorRuntimeException if creation/retrieval of MCF fails

	ManagedConnectionFactory[] mcfs = null;	
        try {
		ConnectorConnectionPool conPool = 
				getConnectorConnectionPool(poolName);	
		ActiveResourceAdapter activeResourceAdapter = 
					getResourceAdapter(conPool);
                mcfs =
                     activeResourceAdapter.
                        createManagedConnectionFactories
                                (conPool, null);
        } catch(NamingException ne) {
            String i18nMsg = localStrings.getString(
                "pingpool.name_not_bound");
            ConnectorRuntimeException cre = new
                ConnectorRuntimeException( i18nMsg);
            cre.initCause(ne);
            _logger.log(Level.FINE,"rardeployment.jndi_lookup_failed",
                               poolName);
            if (_logger.isLoggable( Level.FINE ) ) {   
                _logger.log(Level.FINE,"",cre);
            }
            //_logger.log(Level.SEVERE,"",cre);
            throw cre;
        }
        catch(NullPointerException ne) {
            String i18nMsg = localStrings.getString(
                "ccp_adm.failed_to_register_mcf");
            ConnectorRuntimeException cre = new
                ConnectorRuntimeException( i18nMsg );
            cre.initCause(ne);
            _logger.log(Level.SEVERE,"mcf_add_toregistry_failed",poolName);
            if (_logger.isLoggable( Level.FINE ) ) {   
                _logger.log(Level.FINE,"",cre);
            }
            //_logger.log(Level.SEVERE,"",cre);
            throw cre;
        }
	return mcfs;
    
public ManagedConnectionFactoryobtainManagedConnectionFactory(java.lang.String poolName)
Returns the MCF instance. If the MCF is already created and present in connectorRegistry that instance is returned. Otherwise it is created explicitly and added to ConnectorRegistry.

param
poolName Name of the pool.MCF pertaining to this pool is created/returned.
return
created/already present MCF instance
throws
ConnectorRuntimeException if creation/retrieval of MCF fails

        try {
            if (_registry.isMCFCreated(poolName)) {
                return _registry.getManagedConnectionFactory( poolName );
            } else {

                ConnectorConnectionPool connectorConnectionPool = 
					getConnectorConnectionPool(poolName);
                ActiveResourceAdapter activeResourceAdapter =
                                  getResourceAdapter(connectorConnectionPool);
                ManagedConnectionFactory mcf =
                     activeResourceAdapter.
			createManagedConnectionFactory
				(connectorConnectionPool, null);
                if(mcf != null) {
		    ResourcePrincipal prin = 
		        getDefaultResourcePrincipal(poolName,mcf);
		    Subject s = ConnectionPoolObjectsUtils.createSubject(mcf, prin);
		    int txSupport = connectorConnectionPool.getTransactionSupport();

                    boolean isPM = connectorConnectionPool.isNonComponent();
                    boolean isNonTx = connectorConnectionPool.isNonTransactional();
                    ConnectorSecurityMap[] securityMaps = 
                        connectorConnectionPool.getSecurityMaps();
                    RuntimeSecurityMap runtimeSecurityMap = 
                        SecurityMapUtils.processSecurityMaps(securityMaps);
                    boolean lazyEnlistable = connectorConnectionPool.isLazyConnectionEnlist();
                    boolean lazyAssoc = connectorConnectionPool.isLazyConnectionAssoc();
                    if ( isPM || isNonTx ) {
                        /*
                        We should not do lazyEnlistment if we are an __pm
                        resource since we won't have an InvocationContext and
                        the lazy enlistment depends upon an InvocationContext
                        For a nonTx resource enlistment (lazy or otherwise)
                        doesn't come into the picture at all
                        */
                        lazyEnlistable = false;
                    }

                    if ( isPM ) {
                        //We need to switch off lazy association here because of
                        //the way our Persistence layer behaves. Adding a system
                        //property here to allow other persistence layers to use
                        //lazy association with PM resources
                        String str = System.getProperty(
                            "com.sun.enterprise.resource.AllowLazyAssociationWithPM");
                        if ( str != null && str.toUpperCase().trim().equals("TRUE") ) {
                            lazyAssoc = lazyAssoc & true;    
                        } else {
                            lazyAssoc = false;
                        }
                    }

		    PoolMetaData pmd = new PoolMetaData(poolName, mcf, s, txSupport, prin, 
                        isPM, isNonTx, lazyEnlistable, runtimeSecurityMap, lazyAssoc);
		    logFine( pmd.toString() );
                    _registry.addManagedConnectionFactory(poolName, pmd);
                }
	    
                
                PoolType pt = (connectorConnectionPool.isAssociateWithThread() ? 
                    PoolType.ASSOCIATE_WITH_THREAD_POOL : 
                    PoolType.STANDARD_POOL );

		createAndAddPool( poolName, pt );
		return mcf;
            }
        } catch(NamingException ne) {
	    String i18nMsg = localStrings.getString(
	        "pingpool.name_not_bound");
            ConnectorRuntimeException cre = new 
	        ConnectorRuntimeException( i18nMsg);		
            cre.initCause(ne);
            _logger.log(Level.FINE,"rardeployment.jndi_lookup_failed",
                               poolName);
	    if (_logger.isLoggable( Level.FINE ) ) {	
                _logger.log(Level.FINE,"",cre);
	    }
            //_logger.log(Level.SEVERE,"",cre);
            throw cre;
        }
        catch(NullPointerException ne) {
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.failed_to_register_mcf");
            ConnectorRuntimeException cre = new 
	        ConnectorRuntimeException( i18nMsg );
            cre.initCause(ne);
            _logger.log(Level.SEVERE,"mcf_add_toregistry_failed",poolName);
	    if (_logger.isLoggable( Level.FINE ) ) {	
                _logger.log(Level.FINE,"",cre);
	    }
            //_logger.log(Level.SEVERE,"",cre);
            throw cre;
        }
    
public booleanreconfigureConnectorConnectionPool(ConnectorConnectionPool ccp)
Dynamic reconfig Reconfigure a connection pool. This method compares the passed connector connection pool with the one in memory. If the pools are unequal and the MCF properties are changed a pool recreate is required. However if the pools are unequal and the MCF properties are not changed a recreate is not required

param
ccp - the Updated connector connection pool object that admin hands over
return
true - if a pool restart is required, false otherwise
throws
ConnectorRuntimeException

        return reconfigureConnectorConnectionPool( ccp, new HashSet());
    
public booleanreconfigureConnectorConnectionPool(ConnectorConnectionPool ccp, java.util.Set excludedProps)
Reconfigure a connection pool. This method compares the passed connector connection pool with the one in memory. If the pools are unequal and the MCF properties are changed a pool recreate is required. However if the pools are unequal and the MCF properties are not changed a recreate is not required

param
ccp - the Updated connector connection pool object that admin hands over
param
excludedProps - A set of excluded property names that we want to be excluded in the comparison check while comparing MCF properties
return
true - if a pool restart is required, false otherwise
throws
ConnectorRuntimeException

        logFine("ccp :\n" + ((ccp != null) ? ccp.toString(): "null"));

        //see if the new ConnectorConnectionPool is different from
	//the original one and update relevant properties
	String poolName = ccp.getName();
        ConnectorConnectionPool origCcp = null;
	try {
            origCcp = getOriginalConnectorConnectionPool( poolName );
	} catch( NamingException ne) {
	    throw new ConnectorRuntimeException( ne.getMessage() );
	}
	
	logFine("origCcp :\n" + ((origCcp != null) ? origCcp.toString() : "null"));
	
	ReconfigAction action = ConnectionPoolReconfigHelper.compare( origCcp, ccp, 
	    excludedProps );
	
	if ( action == ReconfigAction.UPDATE_MCF_AND_ATTRIBUTES ) { 
	    logFine( "@@@@ action == " + action);
	    updateMCFAndPoolAttributes( ccp );
	} else if ( action == ReconfigAction.RECREATE_POOL ) {
	    logFine( "@@@@ action == " + action);
	    return true;
	}

	return false;
    
public voidrecreateConnectorConnectionPool(ConnectorConnectionPool ccp)
Recreate a connector connection pool. This method essentially does the following things: 1. Delete the said connector connection pool
2. Bind the pool to JNDI
3. Create an MCF for this pool and register with the connector registry

param
ccp - the ConnectorConnectionPool to publish

        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        if (registry == null ) {
            throw new ConnectorRuntimeException( 
            "Cannot get ConnectorRegistry");
        }
	String poolName = ccp.getName(); 
	//First remove this pool from memory
	try { 
	    unloadAndKillPool( poolName );
        } catch( ConnectorRuntimeException cre ) {
	   throw cre;
	}
	//kill the pool
	//FIXME: deleteConnectorConnectionPool should do this
        //PoolManager poolManager = Switch.getSwitch().getPoolManager();
	//poolManager.killPool( poolName );
	   
	//Now bind the updated pool and
	//obtain a new managed connection factory for this pool
	try {
        String jndiNameForPool = ConnectorAdminServiceUtils.
                getReservePrefixedJNDINameForPool( poolName );
	    Switch.getSwitch().getNamingManager().publishObject(
	    jndiNameForPool, (Object)ccp, true );
	    ManagedConnectionFactory mcf = null;
	    mcf = obtainManagedConnectionFactory( poolName );
	    if (mcf == null ) {
                InitialContext ic = new InitialContext();
	        ic.unbind( jndiNameForPool );
	        _logger.log(Level.WARNING,
                       "rardeployment.mcf_creation_failure", poolName);
		       
	        String i18nMsg = localStrings.getString(
	            "ccp_adm.failed_to_create_mcf");
                throw new ConnectorRuntimeException( i18nMsg );
	    }

	} catch( NamingException ne ) {
	    _logger.log(Level.SEVERE,
	    "rardeployment.pool_jndi_bind_failure", poolName );
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.could_not_recreate_pool");
            ConnectorRuntimeException crex = new ConnectorRuntimeException( i18nMsg );
            crex.initCause(ne);
            throw crex;
	}

    
public voidswitchOnMatching(java.lang.String poolName)
Rebinds the connection pool with matchning flag set.

param
matching Either true or false.
throws
ConnectorRuntimeException , if a Naming error occurs.

        try {
            ConnectorConnectionPool origCcp = 
    	    getOriginalConnectorConnectionPool( poolName );
            origCcp.setMatchConnections(true);

    	    //now rebind the object in jndi
            String jndiNameForPool = ConnectorAdminServiceUtils.
                getReservePrefixedJNDINameForPool( poolName );
            
            InitialContext ic = new InitialContext();
            ic.unbind( jndiNameForPool );
            Switch.getSwitch().getNamingManager().publishObject(
            jndiNameForPool, (Object)origCcp, true );
        } catch (NamingException e) {
            ConnectorRuntimeException ex =
            new ConnectorRuntimeException( e.getMessage());
            throw (ConnectorRuntimeException) ex.initCause(e);
        }

    
public booleantestConnectionPool(java.lang.String poolName)
asadmin test-connection-pool This method is used to provide backend functionality for the test-connection-pool asadmin command. Briefly the design is as follows:
1. obtainManagedConnection for the poolname
2. lookup ConnectorDescriptorInfo from InitialContext using poolname
3. from cdi get username and password
4. create ResourcePrincipal using default username and password
5. create a Subject from this (doPriveleged)
6. createManagedConnection using above subject
7. getConnection from the ManagedConnection with above subject

return
true if the connection pool is healthy. false otherwise
throws
ResourceException if pool is not usable

        dump(poolName);
	Object con = null;
	try {
	    //Since ping works only in DAS right now, we know for sure that
            //the ResourcesUtil that we are using is definitely DASResourcesUtil
            DASResourcesUtil.setAdminConfigContext();

	    //Create the ManagedConnection
	    con = getUnpooledConnection( poolName, null, false );
	    
	} catch( Exception re ) {
	    //Since we have an exception, the pool is not good
	    _logger.log(Level.WARNING, re.getMessage() ); 
            ResourceException e = new ResourceException( re.getMessage()); 
	    e.initCause( re );
	    throw e;
	} finally {
	    try {
	        //destroy the MC
                DASResourcesUtil.resetAdminConfigContext();
		((ManagedConnection)con).destroy();

	    } catch( Throwable e ) {
	        //ignore
	    }
	}
        
	//We did not get a ResourceException, so pool must be OK
	return true;
    
private voidunloadAndKillPool(java.lang.String poolName)
unloads and kills the connector Connection pool without checking for resources in domain.xml.

param
poolName Name of the pool to delete
throws
ConnectorRuntimeException if pool unload or kill operation fails


        killPool(poolName);
        boolean result = _registry.removeManagedConnectionFactory(poolName);
        if(result == false) {
            _logger.log( Level.SEVERE,
                           "rardeployment.mcf_removal_failure",poolName);
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.wrong_params_for_create");
            ConnectorRuntimeException cre = new 
		    ConnectorRuntimeException( i18nMsg );    
            _logger.log( Level.FINE,"",cre);
            throw cre;
        }
        try {
            String jndiNameForPool = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForPool(poolName);
            InitialContext ic = new InitialContext();
            ic.unbind(jndiNameForPool);
        } catch(NamingException ne) {
	    String i18nMsg = localStrings.getString(
	        "ccp_adm.failed_to_remove_from_jndi");
	    ConnectorRuntimeException cre = new 
	        ConnectorRuntimeException( i18nMsg );	
            cre.initCause(ne);
            _logger.log(Level.SEVERE,
                   "rardeployment.connectionpool_removal_from_jndi_error", 
                   poolName);
            _logger.log(Level.FINE,"",cre);
            throw cre;
        }
 
    
private voidupdateMCFAndPoolAttributes(ConnectorConnectionPool ccp)

        String poolName = ccp.getName();
        try {
            ConnectorConnectionPool origCcp =
                    getOriginalConnectorConnectionPool(poolName);

            //update properties
            origCcp.setSteadyPoolSize(ccp.getSteadyPoolSize());
            origCcp.setMaxPoolSize(ccp.getMaxPoolSize());
            origCcp.setMaxWaitTimeInMillis(ccp.getMaxWaitTimeInMillis());
            origCcp.setPoolResizeQuantity(ccp.getPoolResizeQuantity());
            origCcp.setIdleTimeoutInSeconds(ccp.getIdleTimeoutInSeconds());
            origCcp.setFailAllConnections(ccp.isFailAllConnections());

            //lazyEnlist, lazyAssoc and assocWithThread not required since they result
            //in a pool restart anyways, so they wouldn't have changed if we
            //came here
            origCcp.setMatchConnections(ccp.matchConnections());
            origCcp.setMaxConnectionUsage(ccp.getMaxConnectionUsage());
            origCcp.setNonComponent(ccp.isNonComponent());
            origCcp.setNonTransactional(ccp.isNonTransactional());
            origCcp.setConCreationRetryAttempts(ccp.getConCreationRetryAttempts());
            origCcp.setConCreationRetryInterval
                    (ccp.getConCreationRetryInterval());
            origCcp.setValidateAtmostOncePeriod(ccp.getValidateAtmostOncePeriod());
            origCcp.setConnectionLeakTracingTimeout(ccp.getConnectionLeakTracingTimeout());
            origCcp.setConnectionReclaim(ccp.isConnectionReclaim());

            //now rebind the object in jndi
            String jndiNameForPool = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForPool(poolName);
            InitialContext ic = new InitialContext();
            ic.unbind(jndiNameForPool);
            Switch.getSwitch().getNamingManager().publishObject(
                    jndiNameForPool, (Object) origCcp, true);

        } catch (NamingException ne) {
            throw new ConnectorRuntimeException(ne.getMessage());
        }

        //Check if this pool has been brought into memory
        //If its already in memory, just call reconfig on it

        PoolManager poolMgr = Switch.getSwitch().getPoolManager();
        try {
            poolMgr.reconfigPoolProperties(ccp);
        } catch (PoolingException pe) {
            throw new ConnectorRuntimeException(pe.getMessage());
        }
        //Run setXXX methods on the copy of the MCF that we have
        //this is done to update the MCF to reflect changes in the
        //MCF properties for which we don't really need to recreate
        //the pool
        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        ManagedConnectionFactory mcf = registry.getManagedConnectionFactory(
                poolName);
        SetMethodAction sma = new SetMethodAction(mcf,
                ccp.getConnectorDescriptorInfo().getMCFConfigProperties());
        try {
            sma.run();
        } catch (Exception e) {
            _logger.log(Level.WARNING, e.getMessage());
            ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
            cre.initCause(e);
            throw cre;
        }

        //update the properties "allow-non-component-callers" and 
        //"non-transactional-connections" in the PoolMetaData
        PoolMetaData pmd = registry.getPoolMetaData(poolName);
        pmd.setIsPM(ccp.isNonComponent());
        pmd.setIsNonTx(ccp.isNonTransactional());
        pmd.setLazyEnlistable(ccp.isLazyConnectionEnlist());
        pmd.setAuthCredentialsDefinedInPool(ccp.getAuthCredentialsDefinedInPool());

        logFine("Pool properties reconfiguration done");