Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    *
    * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
    *
    * The contents of this file are subject to the terms of either the GNU
    * General Public License Version 2 only ("GPL") or the Common Development
    * and Distribution License("CDDL") (collectively, the "License").  You
    * may not use this file except in compliance with the License.  You can
   * obtain a copy of the License at
   * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
   * or packager/legal/LICENSE.txt.  See the License for the specific
   * language governing permissions and limitations under the License.
   *
   * When distributing the software, include this License Header Notice in each
   * file and include the License file at packager/legal/LICENSE.txt.
   *
   * GPL Classpath Exception:
   * Oracle designates this particular file as subject to the "Classpath"
   * exception as provided by Oracle in the GPL Version 2 section of the License
   * file that accompanied this code.
   *
   * Modifications:
   * If applicable, add the following below the License Header, with the fields
   * enclosed by brackets [] replaced by your own identifying information:
   * "Portions Copyright [year] [name of copyright owner]"
   *
   * Contributor(s):
   * If you wish your version of this file to be governed by only the CDDL or
   * only the GPL Version 2, indicate your decision by adding "[Contributor]
   * elects to include this software in this distribution under the [CDDL or GPL
   * Version 2] license."  If you don't indicate a single choice of license, a
   * recipient has the option to distribute your version of this file under
   * either the CDDL, the GPL Version 2 or to extend the choice of license to
   * its licensees as provided above.  However, if you add GPL Version 2 code
   * and therefore, elected the GPL Version 2 license, then the option applies
   * only if the new code is made subject to such option by the copyright
   * holder.
   */
  
  package com.sun.enterprise.connectors.service;
  
  
  import  javax.resource.ResourceException;
  import  javax.resource.spi.ConnectionRequestInfo;
  import  javax.resource.spi.ManagedConnection;
  import  javax.resource.spi.ManagedConnectionFactory;
  import  javax.resource.spi.TransactionSupport;
  import java.util.*;
Connector connection pool admin service performs the functionality of creation, deletion, recreation, testing of the pools.

Author(s):
Srikanth P and Aditya Gore
  
  
  
      private static StringManager localStrings =
              StringManager.getManager(ConnectorConnectionPoolAdminServiceImpl.class);

    
Default constructor
  
          super();
  
      }

    
Creates connector connection pool in the connector container.

Parameters:
ccp ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
cdd ConnectorDescriptor obejct which abstracts the ra.xml
rarName Name of the resource adapter
Throws:
ConnectorRuntimeException When creation of pool fails.
 
                                               ConnectionDefDescriptor cddString rarName)
             throws ConnectorRuntimeException {
 
         if ((ccp == null) || (cdd == null) || (rarName == null)) {
 
             if(.isLoggable(.)) {
                 .log(."Wrong parameters for pool creation ");
             }
             String i18nMsg = .getString("ccp_adm.wrong_params_for_create");
             throw new ConnectorRuntimeException(i18nMsg);
         }
         ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();
 
         ConnectorDescriptor connectorDescriptor = .getDescriptor(rarName);
 
         if (connectorDescriptor == null) {
             String i18nMsg = .getString("ccp_adm.no_conn_pool_obj"rarName);
             ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
             .log(."rardeployment.connector_descriptor_notfound_registry"rarName);
             .log(.""cre);
             throw cre;
         }
         cdi.setRarName(rarName);
         cdi.setResourceAdapterClassName(
                 connectorDescriptor.getResourceAdapterClass());
                 cdd.getManagedConnectionFactoryImpl());
         cdi.setConnectionClass(cdd.getConnectionImpl());
         cdi.setConnectionInterface(cdd.getConnectionIntf());
         cdi.setMCFConfigProperties(cdd.getConfigProperties());
                 connectorDescriptor.getConfigProperties());
         createConnectorConnectionPool(ccpcdi);
     }

    
Creates connector connection pool in the connector container.

Parameters:
connectorPoolObj ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
connectorDescInfo ConnectorDescriptorInfo object which abstracts the connection definition values present in ra.xml
Throws:
ConnectorRuntimeException When creation of pool fails.
 
 
     private void createConnectorConnectionPool(
             ConnectorConnectionPool connectorPoolObj,
             ConnectorDescriptorInfo connectorDescInfo)
             throws ConnectorRuntimeException {
 
         connectorPoolObj.setConnectorDescriptorInfo(connectorDescInfo);
         createConnectorConnectionPool(connectorPoolObj);
     }

    
Creates connector connection pool in the connector container.

Parameters:
connectorPoolObj ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
Throws:
ConnectorRuntimeException When creation of pool fails.
 
     public void createConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj)
             throws ConnectorRuntimeException {
 
         if(connectorPoolObj == null) {
             if(.isLoggable(.)) {
                 .log(."Wrong parameters for pool creation ");
             }
             String i18nMsg = .getString("ccp_adm.wrong_params_for_create");
             throw new ConnectorRuntimeException(i18nMsg);
         }
         PoolInfo poolInfo = connectorPoolObj.getPoolInfo();
         String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
         try {
 
             .getResourceNamingService().publishObject(poolInfojndiNameForPoolconnectorPoolObjtrue);
             ManagedConnectionFactory mcf = obtainManagedConnectionFactory(poolInfo);
             if (mcf == null) {
                 .getResourceNamingService().unpublishObject(poolInfojndiNameForPool);
                 String i18nMsg = .getString("ccp_adm.failed_to_create_mcf"poolInfo);
                 ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
                 .log(."rardeployment.mcf_creation_failure"poolInfo);
                 .log(.""cre);
                 throw cre;
             }
 
         } catch (NamingException ex) {
 
             String i18nMsg = .getString("ccp_adm.failed_to_publish_in_jndi"poolInfo);
             ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
             cre.initCause(ex);
             .log(."rardeployment.pool_jndi_bind_failure"poolInfo);
             .log(.""cre);
             throw cre;
         } catch (NullPointerException ex) {
             try {
                 .getResourceNamingService().unpublishObject(poolInfojndiNameForPool);
             } catch (NamingException ne) {
                 if(.isLoggable(.)) {
                     .log(."Failed to unbind connection pool object  "poolInfo);
                 }
             }
 
             String i18nMsg = .getString("ccp_adm.failed_to_register_mcf"poolInfo);
             ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
             cre.initCause(ex);
             .log(."rardeployment.mcf_registration_failure"poolInfo);
             .log(.""cre);
             throw cre;
         }
     }

    
Creates connector connection pool in the connector container. cannot be used for 1.5 rar cases

Parameters:
connectorPoolObj ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
security unused
configProperties MCF config properties
Throws:
ConnectorRuntimeException When creation of pool fails.
 
     public void createConnectorConnectionPool(
             ConnectorConnectionPool connectorPoolObjString security,
             Set configPropertiesthrows ConnectorRuntimeException {
         if (connectorPoolObj == null || configProperties == null) {
             if(.isLoggable(.)) {
                 .log(."Wrong parameters for pool creation ");
             }
             String i18nMsg = .getString("ccp_adm.wrong_params_for_create");
             throw new ConnectorRuntimeException(i18nMsg);
         }
         String moduleName =
                 connectorPoolObj.getConnectorDescriptorInfo().getRarName();
         String connectionDefinitionName =
                 connectorPoolObj.getConnectorDescriptorInfo().
                         getConnectionDefinitionName();
 
         ConnectorDescriptor connectorDescriptor =
                 .getDescriptor(moduleName);
 
         if (connectorDescriptor == null) {
             String i18nMsg = .getString("ccp_adm.null_connector_desc"moduleName);
             ConnectorRuntimeException cre = new
                     ConnectorRuntimeException(i18nMsg);
             .log(."rardeployment.null_mcf_in_registry"moduleName);
             .log(.""cre);
             throw cre;
         }
 
         Set connectionDefs =
                 connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();
 
         Iterator iterator = connectionDefs.iterator();
 
         ConnectionDefDescriptor connectionDefDescriptor = null;
 
         while (iterator.hasNext()) {
             connectionDefDescriptor =
                     (ConnectionDefDescriptoriterator.next();
             if (connectionDefinitionName.equals(
                     connectionDefDescriptor.getConnectionFactoryIntf()))
                 break;
         }
 
         ConnectorDescriptorInfo connectorDescInfo =
                 ConnectorDDTransformUtils.getConnectorDescriptorInfo(
                         connectionDefDescriptor);
         connectorDescInfo.setMCFConfigProperties(configProperties);
         connectorDescInfo.setRarName(moduleName);
         connectorDescInfo.setResourceAdapterClassName(
                 connectorDescriptor.getResourceAdapterClass());
 
         createConnectorConnectionPool(connectorPoolObjconnectorDescInfo);
     }


    
Deletes connector Connection pool

Parameters:
poolInfo Name of the pool to delete
Throws:
ConnectorRuntimeException if pool deletion operation fails
 
 
     public void deleteConnectorConnectionPool(PoolInfo poolInfo)
             throws ConnectorRuntimeException {
         deleteConnectorConnectionPool(poolInfofalse );
     }

    
Deletes connector Connection pool. Here check in made whether resources pertaining to pool are present in domain.xml.

Parameters:
poolInfo Name of the pool to delete
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
 
 
     public void deleteConnectorConnectionPool(PoolInfo poolInfoboolean cascade)
             throws ConnectorRuntimeException {
 
         if (poolInfo == null) {
             .log(."ccp_adm.null_pool_name");
             String i18nMsg = .getString("ccp_adm.null_pool_name");
             throw new ConnectorRuntimeException(i18nMsg);
         }
 
         boolean errorOccured = false;
 
         /*  Not needed as --cascade is handled via v3's application life cycle contracts
 
                 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) {
 
                 }
         */
         killPool(poolInfo);
         boolean result = .removeManagedConnectionFactory(poolInfo);
 
         if (!result) {
             if(.isLoggable(.)) {
                 .log(."rardeployment.mcf_removal_failure"poolInfo);
             }
             return;
         }
 
         try {
             //String originalPoolName = ConnectorAdminServiceUtils.getOriginalResourceName(poolName);
             String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
             .getResourceNamingService().unpublishObject(poolInfojndiNameForPool);
         } catch (NamingException ne) {
             .log(."rardeployment.connectionpool_removal_from_jndi_error"poolInfo);
             String i18nMsg = .getString("ccp_adm.failed_to_remove_from_jndi"poolInfo);
             ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
             cre.initCause(ne);
             .log(.""cre);
             throw cre;
         }
         if (errorOccured){
             String i18nMsg = .getString("ccp_adm.failed_to_delete_conn_res"poolInfo);
             ConnectorRuntimeException cre = new
                     ConnectorRuntimeException(i18nMsg);
             .log(."rardeployment.all_resources_removal_error"poolInfo);
             .log(.""cre);
             throw cre;
         }
     }

    
Kills a specific pool

Parameters:
poolInfo poolName to kill
 
     public void killPool(PoolInfo poolInfo) {
         .getPoolManager().killPool(poolInfo);
     }

    
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.

Parameters:
connectionDefinitionClassName The Connection Definition Java bean class for which overrideable properties are required.
Returns:
Map<String, Object> String represents property name and Object is the defaultValue that is a primitive type or String
 
     public static Map<StringObjectgetConnectionDefinitionPropertiesAndDefaults(String connectionDefinitionClassNameString resType) {
         return ConnectionDefinitionUtils
                 .getConnectionDefinitionPropertiesAndDefaults(
                         connectionDefinitionClassNameresType);
     }

    
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

Parameters:
poolInfo connection-pool name
Returns:
true if the connection pool is healthy. false otherwise
Throws:
ResourceException if pool is not usable
 
     public boolean testConnectionPool(PoolInfo poolInfo)
             throws ResourceException {
         //dump(poolName); //TODO V3 no way to call dump ?
         ManagedConnection con = null;
         try {
             //Create the ManagedConnection
             con = (ManagedConnection) getUnpooledConnection(poolInfonullfalse);
         } catch (Exception re) {
             //Since we have an exception, the pool is not good
             Object params[] = new Object[]{poolInfore.getMessage()};
             .log(."test.connection.pool.failed"params);
             ResourceException e = new ResourceException(re.getLocalizedMessage() +
                     " Please check the server.log for more details.");
             e.initCause(re);
             throw e;
         } finally {
             try {
                 //destroy the MC
                 if (con != null) {
                     con.destroy();
                 }
             } catch (Throwable e) {
                 //ignore
             }
         }
 
         //We did not get a ResourceException, so pool must be OK
         return true;
     }

    
Utility method that is used to get the default subject for the specified mcf and resource principal.

Parameters:
poolInfo
mcf
prin
Returns:
Throws:
javax.resource.ResourceException
 
     protected Subject getDefaultSubject(PoolInfo poolInfo, ManagedConnectionFactory mcf,
             ResourcePrincipal printhrows ResourceException {
         ResourcePrincipal resourcePrincipal = null;
         if (prin == null) {
             try {
                 resourcePrincipal = getDefaultResourcePrincipal(poolInfomcf);
             } catch (NamingException ne) {
                 .log(."jdbc.pool_not_reachable",
                         ne.getMessage());
                 String l10nMsg = .getString(
                         "pingpool.name_not_bound"poolInfo);
                 ResourceException e = new ResourceException(l10nMsg + poolInfo);
                 e.initCause(ne);
                 throw e;
             }
         } else {
             resourcePrincipal = prin;
         }
 
         final Subject defaultSubject =
                 ConnectionPoolObjectsUtils.createSubject(mcfresourcePrincipal);
 
 
         if (.isLoggable(.)) {
             .fine("using subject: " + defaultSubject);
 
         }        
         return defaultSubject;
     }

    
Utility method to get Managed connection from the supplied mcf and default subject.

Parameters:
mcf
defaultSubject
Returns:
Throws:
javax.resource.ResourceException
 
     protected ManagedConnection getManagedConnection(ManagedConnectionFactory mcf
             Subject defaultSubject, ConnectionRequestInfo cReqInfothrows ResourceException {
         
         ManagedConnection mc = null;
         
         //Create the ManagedConnection
         mc = mcf.createManagedConnection(defaultSubjectcReqInfo);
         return mc;
 
     }    
 
 /*
     */
Utility method to get a managed connection factory for the jdbc connection pool name.

Parameters:
poolName
Returns:
Throws:
javax.resource.ResourceException
 /*
 
     protected ManagedConnectionFactory getManagedConnectionFactory(String poolName) 
             throws ResourceException {
         ManagedConnectionFactory mcf = null;
         try {
             mcf = obtainManagedConnectionFactory(poolName);
 
         } catch (ConnectorRuntimeException cre) {
             logFine("getUnpooledConnection :: obtainManagedConnectionFactory " +
                     "threw exception. Doing checkAndLoadPoolResource");
             if (checkAndLoadPool(poolName)) {
                 logFine("getUnpooledConnection:: checkAndLoadPoolResource is true");
                 try {
                     */
 /* TODO not needed for non-cluster
                  //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", poolName);
                     _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", poolName);
                 ResourceException e = new ResourceException(l10nMsg);
                 e.initCause(cre);
                 throw e;
 
             }
         }
         return mcf;
     }
 */

    
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

Parameters:
poolInfo The poolname from whose MCF to obtain the unpooled mc
principal The ResourcePrincipal to use for authenticating the request if not null. If null, the pool's default authentication mechanism is used
returnConnectionHandle If true will return the logical connection handle derived from the Managed Connection, else will only return mc
Returns:
an unPooled connection
Throws:
ResourceException for various error conditions
 
     public Object getUnpooledConnection(PoolInfo poolInfoResourcePrincipal principalboolean returnConnectionHandle)
             throws ResourceException {
         ManagedConnectionFactory mcf = null;
         ResourcePool poolToDeploy = null;
         boolean needToUndeployPool = false;
         ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
 
         try {
             //START CR 6597868
             if (!isPoolReferredByResource(poolInfo)) {
                 if (.isMCFCreated(poolInfo)){
                     unloadAndKillPool(poolInfo);
                 }
             }
             //END CR 6597868
             mcf = obtainManagedConnectionFactory(poolInfonew Hashtable());
         } catch (ConnectorRuntimeException re) {
             logFine("getUnpooledConnection :: obtainManagedConnectionFactory " +
                     "threw exception. So doing checkAndLoadPoolResource");
             if (checkAndLoadPool(poolInfo)) {
                 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(poolInfo)) {
                         logFine("getUnpooledConnection :: isConnectorConnectionPoolDeployed is false");
                         try {
                             poolToDeploy = (ResourcePool)
                                     ConnectorsUtil.getResourceByName(runtime.getResources(poolInfo), ResourcePool.classpoolInfo.getName());
                             runtime.getResourceDeployer(poolToDeploy).deployResource(poolToDeploy);
                             logFine("getUnpooledConnection :: force deployed the ConnectionPool : " + poolInfo);
                             needToUndeployPool = true;
                         } catch (Exception e) {
                             .log(."jdbc.could_not_do_actual_deploy for : "poolInfo);
                             throw new ResourceException(e);
                         }
                     }
                     logFine("getUnpooledConnection :: Now calling obtainManagedConnectionFactory again");
                     mcf = obtainManagedConnectionFactory(poolInfo);
                     logFine("getUnpooledConnection:: done obtainManagedConnectionFactory again");
 
                 } catch (ConnectorRuntimeException creAgain) {
                     String l10nMsg = .getString(
                             "pingpool.cannot_obtain_mcf"poolInfo);
                     .log(."jdbc.pool_not_reachable"l10nMsg);
                     ResourceException e = new ResourceException(l10nMsg);
                     e.initCause(creAgain);
                     throw e;
                 }
             } else {
                 .log(."jdbc.pool_not_reachable"re.getMessage());
                 String l10nMsg = .getString("pingpool.cannot_obtain_mcf"poolInfo);
                 ResourceException e = new ResourceException(l10nMsg);
                 e.initCause(re);
                 throw e;
             }
         }
 
         ResourcePrincipal resourcePrincipal = null;
         if (principal == null) {
             try {
                 resourcePrincipal = getDefaultResourcePrincipal(poolInfomcf);
             } catch (NamingException ne) {
                 .log(."jdbc.pool_not_reachable"ne.getMessage());
                 String l10nMsg = .getString("pingpool.name_not_bound"poolInfo);
                 ResourceException e = new ResourceException(l10nMsg + poolInfo);
                 e.initCause(ne);
                 throw e;
             }
         } else {
             resourcePrincipal = principal;
         }
 
         final Subject defaultSubject = ConnectionPoolObjectsUtils.createSubject(mcfresourcePrincipal);
 
         if (.isLoggable(.)) {
             .fine("using subject: " + defaultSubject);
         }
 
         //Create the ManagedConnection
         ManagedConnection mc = mcf.createManagedConnection(defaultSubjectnull);
         //We are done with the pool for now, so undeploy if we deployed
         //it here
         if (needToUndeployPool) {
             if (poolToDeploy != null) {
                 logFine("getUnpooledConnection :: need to force undeploy pool");
                 try {
                     runtime.getResourceDeployer(poolToDeploy).undeployResource(poolToDeploy);
                 } catch (Exception e) {
                     if(.isLoggable(.)) {
                         .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(defaultSubjectnull) : mc;
     }
 
     //START CR 6597868
     
This method is used to find out if pool is linked to data-source or not if pool is not linked then ping will not take changes to pool dynamically.

Parameters:
poolInfo pool-name
Returns:
boolean indicating whether the pool is referred or not
 
     private boolean isPoolReferredByResource(PoolInfo poolInfo){
         ResourcesUtil resUtil = ResourcesUtil.createInstance();
         boolean isJdbcPoolReferredInServerInstance = false;
         Collection<ConnectorRuntimeExtensionextensions =
                 Globals.getDefaultHabitat().getAllServices(ConnectorRuntimeExtension.class);
         for(ConnectorRuntimeExtension extension : extensions) {
             isJdbcPoolReferredInServerInstance = extension.isConnectionPoolReferredInServerInstance(poolInfo);
         }
 
         return (resUtil.isPoolReferredInServerInstance(poolInfo) || isJdbcPoolReferredInServerInstance);
     }
     //END CR 6597868
 

    
Utility method to get property value from ConnectorDescriptorInfo.

Parameters:
prop
Returns:
 
     public String getPropertyValue(String prop,
             ConnectorConnectionPool connectorConnectionPool) {
         String result = null;
         ConnectorDescriptorInfo cdi = connectorConnectionPool.getConnectorDescriptorInfo();
 
         Set mcfConfigProperties = cdi.getMCFConfigProperties();
         Iterator mcfConfPropsIter = mcfConfigProperties.iterator();
         while (mcfConfPropsIter.hasNext()) {
             ConnectorConfigProperty  envProp = (ConnectorConfigProperty ) mcfConfPropsIter.next();
 
             if (envProp.getName().toUpperCase(Locale.getDefault()).equals(prop)) {
                 result = envProp.getValue();
             } 
         }
         return result;
     }
 
         ManagedConnectionFactory mcf ) throws NamingException {
         return getDefaultResourcePrincipal(poolInfomcfnull);
     }
     
     /*
     * Returns a ResourcePrincipal object populated with a pool's
     * default USERNAME and PASSWORD
     *
     * @throws NamingException if poolname lookup fails
     */
                                                           ManagedConnectionFactory mcfHashtable env)
             throws NamingException {
         String userName = null;
         String password = null;
         // All this to get the default user name and principal
         ConnectorConnectionPool connectorConnectionPool = null;
         try {
             String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
             connectorConnectionPool = (ConnectorConnectionPool)
                     .getResourceNamingService().lookup(poolInfojndiNameForPoolenv);
         } catch (NamingException ne) {
             throw ne;
         }
 
         userName = getPropertyValue("USERNAME"connectorConnectionPool);
         if(userName == null) {
             userName = getPropertyValue("USER"connectorConnectionPool);
         }
         password = getPropertyValue("PASSWORD"connectorConnectionPool);
         try {
             password = RelativePathResolver.getRealPasswordFromAlias(password);
         } catch(Exception e) {
             .log(."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"poolInfomcf);
             //It is possible that ResourceAdapter may have getUser() instead of
             //getUserName() property getter
             if (userName.trim().equals("")) {
                 userName = ConnectionPoolObjectsUtils.getValueFromMCF("User"poolInfomcf);
             }
             password = ConnectionPoolObjectsUtils.getValueFromMCF("Password"poolInfomcf);
         }
         //Now return the ResourcePrincipal
         return new ResourcePrincipal(userNamepassword);
     }

    
Rebinds the connection pool with matchning flag set.

Parameters:
poolInfo pool for which matching need to be switched on
Throws:
ConnectorRuntimeException , if a Naming error occurs.
 
     public void switchOnMatching(PoolInfo poolInfothrows ConnectorRuntimeException {
         try {
             ConnectorConnectionPool origCcp =
                     getOriginalConnectorConnectionPool(poolInfo);
             origCcp.setMatchConnections(true);
 
             //now rebind the object in jndi
             String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
 
 
             .getResourceNamingService().unpublishObject(poolInfojndiNameForPool);
             .getResourceNamingService().publishObject(poolInfojndiNameForPoolorigCcptrue);
         } catch (NamingException e) {
             ConnectorRuntimeException ex =
                     new ConnectorRuntimeException(e.getMessage());
             throw(ConnectorRuntimeExceptionex.initCause(e);
         }
     }

   
Create a ConnectorConnectionPool from information in memory
 
             PoolInfo poolInfothrows NamingException {
 
         ConnectorConnectionPool ccpOrig = null;
 
         String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
         try {
             ccpOrig = (ConnectorConnectionPool).getResourceNamingService().lookup(poolInfojndiNameForPool);
         } catch (NamingException ne) {
                 throw ne;
         }
         return ccpOrig;
     }
 
         throws ConnectorRuntimeExceptionNamingException  {
         return getConnectorConnectionPool(poolInfonull);
     }
    
    
Returns the connector connection pool object corresponding to the pool name

Parameters:
poolInfo Name of the pool.MCF pertaining to this pool is created/returned.
Returns:
Connector connection pool corresponding to this instance
Throws:
ConnectorRuntimeException if creation/retrieval of MCF fails
 
             throws ConnectorRuntimeExceptionNamingException {
         String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
 
         ConnectorConnectionPool connectorConnectionPool = (ConnectorConnectionPool)
                 .getResourceNamingService().lookup(poolInfojndiNameForPoolenv);
         if (connectorConnectionPool == null) {
             String i18nMsg = .getString("ccp_adm.null_pool"poolInfo);
             ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
             .log(."rardeployment.connectionpool_object_null"poolInfo);
             if (.isLoggable(.)) {
                 .log(.""cre);
             }
             throw cre;
         }
         return connectorConnectionPool;
     }

    
Returns the resource adapter object corresponding to the pool

Parameters:
connectorConnectionPool Name of the pool. MCF pertaining to this pool is created/returned.
Returns:
Resource adapter instance corresponding to this pool.
Throws:
ConnectorRuntimeException if creation/retrieval of RA fails
 
     private ActiveResourceAdapter getResourceAdapter(ConnectorConnectionPool connectorConnectionPool)
             throws ConnectorRuntimeException {
 
         String rarName = connectorConnectionPool.getConnectorDescriptorInfo().getRarName();
         ActiveResourceAdapter activeResourceAdapter = getActiveResourceAdapter(rarName);
         if (activeResourceAdapter == null) {
             String i18nMsg = .getString("ccp_adm.active_ra_not_init"rarName);
 
             ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
             .log(."rardeployment.resourceadapter_not_initialized"rarName);
             if (.isLoggable(.)) {
                 .log(.""cre);
             }
             throw cre;
         }
         return activeResourceAdapter;
     }
 
             throws ConnectorRuntimeException {
         ActiveResourceAdapter activeResourceAdapter = .getActiveResourceAdapter(rarName);
         //we dont need this check for normal resources of domain.xml config, but datasource-definition needs it.
         if (activeResourceAdapter == null) {
             ifSystemRarLoad(rarName);
             activeResourceAdapter = .getActiveResourceAdapter(rarName);
         }
         return activeResourceAdapter;
     }

    
Returns the MCF instances.

Parameters:
poolInfo Name of the pool.MCF pertaining to this pool is created/returned.
Returns:
created/already present MCF instance
Throws:
ConnectorRuntimeException if creation/retrieval of MCF fails
 
     public ManagedConnectionFactory[] obtainManagedConnectionFactories(
            PoolInfo poolInfothrows ConnectorRuntimeException {
 	ManagedConnectionFactory[] mcfs = null;
         String raName = null;
         try {
 		ActiveResourceAdapter activeResourceAdapter =
             raName = activeResourceAdapter.getModuleName();
                 mcfs =
                      activeResourceAdapter.
                         createManagedConnectionFactories
                                 (conPoolnull);
         } catch(NamingException ne) {
             String i18nMsg = .getString(
                 "pingpool.name_not_bound"poolInfo);
             ConnectorRuntimeException cre = new
                 ConnectorRuntimeExceptioni18nMsg);
             cre.initCause(ne);
             if (.isLoggable(.)) {
                 .log(."rardeployment.jndi_lookup_failed",
                         poolInfo);
                 .log(.""cre);
             }
             //_logger.log(Level.SEVERE,"",cre);
             throw cre;
         }
         catch(NullPointerException ne) {
             String i18nMsg = .getString(
                 "ccp_adm.failed_to_register_mcf"poolInfo);
             ConnectorRuntimeException cre = new
                 ConnectorRuntimeExceptioni18nMsg );
             cre.initCause(ne);
             .log(.,"mcf_add_toregistry_failed",poolInfo);
             if (.isLoggable. ) ) {
                 .log(.,"",cre);
             }
             //_logger.log(Level.SEVERE,"",cre);
             throw cre;
         }
         for(ManagedConnectionFactory mcf : mcfs){
             validateMCF(mcfraName);
         }
 	return mcfs;
     }
 
     private void validateMCF(ManagedConnectionFactory mcfString raName) {
         .getConnectorBeanValidator().validateJavaBean(mcfraName);
     }
 
 
     public ManagedConnectionFactory obtainManagedConnectionFactory(PoolInfo poolInfothrows ConnectorRuntimeException{
         return obtainManagedConnectionFactory(poolInfonull);
     }
    
    
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.

Parameters:
poolInfo Name of the pool.MCF pertaining to this pool is created/returned.
Returns:
created/already present MCF instance
Throws:
ConnectorRuntimeException if creation/retrieval of MCF fails
    public ManagedConnectionFactory obtainManagedConnectionFactory(PoolInfo poolInfoHashtable env)
            throws ConnectorRuntimeException {
        try {
            if (.isMCFCreated(poolInfo)) {
                return .getManagedConnectionFactory(poolInfo);
            } else {
                ConnectorConnectionPool connectorConnectionPool = getConnectorConnectionPool(poolInfoenv);
                ActiveResourceAdapter activeResourceAdapter = getResourceAdapter(connectorConnectionPool);
                ClassLoader loader = activeResourceAdapter.getClassLoader();
                ManagedConnectionFactory mcf = activeResourceAdapter.
                        createManagedConnectionFactory(connectorConnectionPoolloader);
                if (mcf != null) {
                    //validate MCF before it is used or related pooling infrastructure is created.
                    validateMCF(mcfactiveResourceAdapter.getModuleName());
                    ResourcePrincipal prin =
                            getDefaultResourcePrincipal(poolInfomcfenv);
                    Subject s = ConnectionPoolObjectsUtils.createSubject(mcfprin);
                    int txSupport = connectorConnectionPool.getTransactionSupport();
                    //JSR-322 : check the runtime transaction level support of MCF and use appropriately.
                    if (mcf instanceof javax.resource.spi.TransactionSupport) {
                        TransactionSupport.TransactionSupportLevel mcfTS =
                                ((javax.resource.spi.TransactionSupport) mcf).getTransactionSupport();
                        int containerTxSupport = ConnectionPoolObjectsUtils.convertSpecTxSupportToContainerTxSupport(mcfTS);
                        boolean isValidTxSupportLevel = ConnectionPoolObjectsUtils.isTxSupportConfigurationSane(
                                containerTxSupportactiveResourceAdapter.getModuleName());
                        if (isValidTxSupportLevel) {
                            txSupport = containerTxSupport;
                        } else {
                            Object params[] = { mcfTSactiveResourceAdapter.getModuleName() };
                            String i18nMsg = .getString("ccp_adm_service.incorrect_tx_support"params);
                            ConnectorRuntimeException cre = new
                                    ConnectorRuntimeException(i18nMsg);
                            .log(."rardeployment.incorrect_tx_support",
                                    connectorConnectionPool.getName());
                            throw cre;
                        }
                    }
                    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
                        if (lazyAssoc) {
                            String str = System.getProperty(
                                    "com.sun.enterprise.resource.AllowLazyAssociationWithPM""FALSE");
                            if (str.toUpperCase(Locale.getDefault()).trim().equals("FALSE")) {
                                lazyAssoc = false;
                            }
                        }
                    }
                    PoolMetaData pmd = new PoolMetaData(poolInfomcfstxSupportprin,
                            isPMisNonTxlazyEnlistableruntimeSecurityMaplazyAssoc);
                    logFine(pmd.toString());
                    .addManagedConnectionFactory(poolInfopmd);
                }
                PoolType pt = getPoolType(connectorConnectionPool);
                createAndAddPool(poolInfoptenv);
                return mcf;
            }
        } catch (NamingException ne) {
            String i18nMsg = .getString("pingpool.name_not_bound"poolInfo);
            ConnectorRuntimeException cre = new
                    ConnectorRuntimeException(i18nMsg);
            cre.initCause(ne);
            if(.isLoggable(.)) {
                .log(."rardeployment.jndi_lookup_failed"poolInfo);
                .log(.""cre);
            }
            throw cre;
        }
        catch (NullPointerException ne) {
            String i18nMsg = .getString("ccp_adm.failed_to_register_mcf"poolInfo);
            ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
            cre.initCause(ne);
            .log(."mcf_add_toregistry_failed"poolInfo);
            if (.isLoggable(.)) {
                .log(.""cre);
            }
            throw cre;
        }
    }
    private PoolType getPoolType(ConnectorConnectionPool connectorConnectionPool) {
        PoolType pt = .;
        if (!connectorConnectionPool.isPoolingOn()) {
            pt = .;
        } else if (connectorConnectionPool.isAssociateWithThread()) {
            pt = .;
        } else if (connectorConnectionPool.isPartitionedPool()) {
            pt = .;
        }
        return pt;
    }
    public PoolType getPoolType(PoolInfo poolInfothrows ConnectorRuntimeException {
        ConnectorConnectionPool ccp;
        try {
            ccp = getConnectorConnectionPool(poolInfo);
        } catch (NamingException e) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
            cre.initCause(e);
            throw cre;
        }
        return getPoolType(ccp);
    }
    private void logFine(String msg) {
        if (msg != null) {
            if (.isLoggable(.)) {
                .fine(msg);
            }
        }
    }

    
create an empty connection pool

Parameters:
poolInfo pool to be created
pt type of pool
Throws:
ConnectorRuntimeException
    private void createAndAddPool(PoolInfo poolInfoPoolType ptHashtable envthrows ConnectorRuntimeException {
        PoolManager poolMgr = .getPoolManager();
        try {
            poolMgr.createEmptyConnectionPool(poolInfoptenv);