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.util;
 
 
 import  javax.resource.spi.ManagedConnectionFactory;
 import  javax.resource.spi.security.PasswordCredential;
 import java.util.List;
This is an util class for creating poolObjects of the type ConnectorConnectionPool from ConnectorDescriptor and also using the default values.

Author(s):
Srikanth P
 
 
 public final class ConnectionPoolObjectsUtils {
     private ConnectionPoolObjectsUtils() { /* disallow instantiation */ }
 
     public static final String ELEMENT_PROPERTY = "ElementProperty";
     private static final Logger _logger = LogDomains.getLogger(ConnectionPoolObjectsUtils.class,.);
 
     private static final String VALIDATE_ATMOST_EVERY_IDLE_SECS =
             "com.sun.enterprise.connectors.ValidateAtmostEveryIdleSecs";
 
 
     private static final StringManager localStrings =
             StringManager.getManager(ConnectionPoolObjectsUtils.class);

    
Creates default ConnectorConnectionPool consisting of default pool values.

Parameters:
poolInfo Name of the pool
Returns:
ConnectorConnectionPool created ConnectorConnectionPool instance
 
            PoolInfo poolInfoString rarName) {
        ConnectorConnectionPool connectorPoolObj =
                new ConnectorConnectionPool(poolInfo);
        connectorPoolObj.setMaxPoolSize("20");
        connectorPoolObj.setSteadyPoolSize("10");
        connectorPoolObj.setMaxWaitTimeInMillis("7889");
        connectorPoolObj.setIdleTimeoutInSeconds("789");
        connectorPoolObj.setPoolResizeQuantity("2");
        connectorPoolObj.setFailAllConnections(false);
        connectorPoolObj.setMatchConnections(true); //always
        setDefaultAdvancedPoolAttributes(connectorPoolObj);
        try {
            connectorPoolObj.setTransactionSupport(getTransactionSupportFromRaXml(rarName));
        } catch (Exception ex) {
            if(.isLoggable(.)) {
                .fine("error in setting txSupport");
            }
        }
        return connectorPoolObj;
    }

    
Sets default values for advanced pool properties

Parameters:
connectorPoolObj Connector Connection Pool
    private static void setDefaultAdvancedPoolAttributes(ConnectorConnectionPool connectorPoolObj) {
        //Other advanced attributes like connection-leak-reclaim, lazy-connection-enlistment,
        //lazy-connection-association, associate-with-thread are boolean values which are not required
        //to be explicitly initialized to default values.
    }

    
Creates ConnectorConnectionPool object pertaining to the pool props mentioned in the sun-ra/xml i.e it represents the pool mentioned in the sun-ra.xm.

Parameters:
poolInfo Name of the pool
desc ConnectorDescriptor which represent ra.xml and sun-ra.xml.
Returns:
ConnectorConnectionPool created ConnectorConnectionPool instance
            PoolInfo poolInfoConnectorDescriptor descString rarName) {
        ConnectorConnectionPool connectorPoolObj =
                new ConnectorConnectionPool(poolInfo);
        SunConnector sundesc = desc.getSunDescriptor();
        ResourceAdapter sunRAXML = sundesc.getResourceAdapter();
        connectorPoolObj.setMaxPoolSize(
                (StringsunRAXML.getValue(.));
        connectorPoolObj.setSteadyPoolSize(
                (StringsunRAXML.getValue(.));
        connectorPoolObj.setMaxWaitTimeInMillis((StringsunRAXML.getValue(
                .));
        connectorPoolObj.setIdleTimeoutInSeconds((StringsunRAXML.getValue(
                .));
        connectorPoolObj.setPoolResizeQuantity((String"2");
        connectorPoolObj.setFailAllConnections(false);
        connectorPoolObj.setMatchConnections(true); //always
        setDefaultAdvancedPoolAttributes(connectorPoolObj);
        try {
            connectorPoolObj.setTransactionSupport(getTransactionSupportFromRaXml(rarName));
        } catch (Exception ex) {
            if(.isLoggable(.)) {
                .fine("error in setting txSupport");
            }
        }
        boolean validateAtmostEveryIdleSecs = false;
        //For SunRAPool, get the value of system property VALIDATE_ATMOST_EVERY_IDLE_SECS.
            validateAtmostEveryIdleSecs = true;
            if (.isLoggable(.)) {
                .log(."CCP.ValidateAtmostEveryIdleSecs.Set"poolInfo);
            }
        }
        connectorPoolObj.setValidateAtmostEveryIdleSecs(validateAtmostEveryIdleSecs);
        return connectorPoolObj;
    }

    
Return the interger representation container transaction support value equivalent to the javax.resource.spi.TransactionSupport enum value.

Parameters:
mcfTS javax.resource.spi.TransactionSupport
Returns:
container equivalent value
    public static int convertSpecTxSupportToContainerTxSupport(
            javax.resource.spi.TransactionSupport.TransactionSupportLevel mcfTS) {
        int containerEquivalentValue ;
        switch (mcfTS) {
            case LocalTransaction:
                containerEquivalentValue =  .;
                break;
            case NoTransaction:
                containerEquivalentValue = .;
                break;
            case XATransaction:
                containerEquivalentValue = .;
                break;
            default :
                containerEquivalentValue = .;
                break;
        }
        if (.isLoggable(.)) {
            .fine("convertSpecTxSupportToContainerTxSupport: passed in mcfTransactionSupport =>" + mcfTS + ", " +
                    "converted container equivalent value: " + containerEquivalentValue);
        }
        return containerEquivalentValue;
    }


    
Return the integer representation of the transaction-support attribure

Parameters:
txSupport one of
  • NoTransaction
  • LocalTransaction
  • XATransaction
Returns:
one of
  • ConnectorConstants.UNDEFINED_TRANSACTION_INT
  • ConnectorConstants.NO_TRANSACTION_INT
  • ConnectorConstants.LOCAL_TRANSACTION_INT
  • ConnectorConstants.XA_TRANSACTION_INT
    public static int parseTransactionSupportString(String txSupport) {
        int txSupportIntVal = .;
        if (txSupport == null) {
            if (.isLoggable(.)) {
                .fine("txSupport is null");
            }
            return txSupportIntVal;
        }
        if (.isLoggable(.)) {
            .fine("parseTransactionSupportString: passed in txSupport =>" + txSupport);
        }
            txSupportIntVal = .;
        } else if (..equals(txSupport)) {
            txSupportIntVal = .;
        } else if (..equals(txSupport)) {
            txSupportIntVal = .;
        }
        return txSupportIntVal;
    }
    public static boolean isTxSupportConfigurationSane(int txSupportString raName) {
        int raXmlTxSupport = .;
        try {
            raXmlTxSupport = ConnectionPoolObjectsUtils.getTransactionSupportFromRaXml(raName);
        } catch (Exception e) {
            .log(.,
                    (e.getMessage() != null ? e.getMessage() : "  "));
        }
        if (.isLoggable(.)) {
            .log(."isTxSupportConfigSane:: txSupport => "
                    + txSupport + "  raXmlTxSupport => " + raXmlTxSupport);
        }
        return (txSupport <= raXmlTxSupport);
    }


    
A utility method to map TransactionSupport ints as represented in ConnectorConstants to the new TransactionSupport enum
    public static TransactionSupport getTransactionSupport(int ts) {
        switch (ts) {
            case .:
                return .;
            case .:
                return .;
            case .:
                return .;
        }
        return null;
    }
    public static String getValueFromMCF(String propPoolInfo poolInfo,
                                         ManagedConnectionFactory mcf) {
        String result = null;
        try {
            Method m = mcf.getClass().getMethod("get" + prop, (java.lang.Class[]) null);
            result = (Stringm.invoke(mcf, (java.lang.Object[]) null);
        } catch (Throwable t) {
            if (.isLoggable(.)) {
                .log(.t.getMessage(), t);
            }
        }
        return result == null ? "" : result;
    }
    public static Subject createSubject(ManagedConnectionFactory mcf,
                                        final ResourcePrincipal prin) {
        final Subject tempSubject = new Subject();
        if (prin != null) {
            String password = prin.getPassword();
            if (password != null) {
                final PasswordCredential pc =
                        new PasswordCredential(prin.getName(),
                                password.toCharArray());
                pc.setManagedConnectionFactory(mcf);
                AccessController.doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        tempSubject.getPrincipals().add(prin);
                        tempSubject.getPrivateCredentials().add(pc);
                        return null;
                    }
                });
            }
        }
        return tempSubject;
    }
            domainCcp) {
        String poolName = domainCcp.getName();
        return isPoolSystemPool(poolName);
    }
    public static boolean isPoolSystemPool(String poolName) {
        Pattern pattern = Pattern.compile("#");
        Matcher matcher = pattern.matcher(poolName);
        // If the pool name does not contain #, return false
        if (!matcher.find()) {
            return false;
        }
        matcher.reset();
        String moduleNameFromPoolName = null;
        int matchCount = 0;
        while (matcher.find()) {
            matchCount++;
            int patternStart = matcher.start();
            moduleNameFromPoolName = poolName.substring(0, patternStart);
        }
        // If pool name contains more than 2 #, return false as the 
        // default system pool will have exacly one # for a standalone rar
        // and exactly two #s for an embedded rar
        ResourcesUtil resUtil = ResourcesUtil.createInstance();
        switch (matchCount) {
            case 1:
                if (resUtil.belongToStandAloneRar(moduleNameFromPoolName))
                    return true;
            default:
                return false;
        }
    }


     
Validates and sets the values for LazyConnectionEnlistment and LazyConnectionAssociation.

Parameters:
lazyAssocString Property value
adminPool Config Bean
conConnPool Connector Connection Pool
    public static void setLazyEnlistAndLazyAssocProperties(String lazyAssocStringList<Propertyproperties,
                                                           ConnectorConnectionPool conConnPool){
        //Get LazyEnlistment value.
        //To set LazyAssoc to true, LazyEnlist also need to be true.
        //If LazyAssoc is true and LazyEnlist is not set, set it to true.
        //If LazyAssoc is true and LazyEnlist is false, throw exception.
        if (properties == nullreturn ;
        Property lazyEnlistElement = null;
         for(Property property : properties){
             if(property.getName().equalsIgnoreCase("LAZYCONNECTIONENLISTMENT")){
                 lazyEnlistElement = property;
             }
         }
            boolean lazyAssoc = toBooleanlazyAssocStringfalse );
            if(lazyEnlistElement != null){
                boolean lazyEnlist = toBoolean(lazyEnlistElement.getValue(),false);
                if(lazyAssoc){
                    if(lazyEnlist){
                        conConnPool.setLazyConnectionAssoctrue) ;
                        conConnPool.setLazyConnectionEnlisttrue);
                    }else{
                         .log(.,"conn_pool_obj_utils.lazy_enlist-lazy_assoc-invalid-combination",conConnPool.getName());
                        String i18nMsg = .getString(
               "cpou.lazy_enlist-lazy_assoc-invalid-combination");
                        throw new RuntimeException(i18nMsg + conConnPool.getName());
                    }
                }else{
                    conConnPool.setLazyConnectionAssoc(false);
                }
            }else{
                if(lazyAssoc){
                    conConnPool.setLazyConnectionAssoctrue) ;
                    conConnPool.setLazyConnectionEnlisttrue);
                }else{
                    conConnPool.setLazyConnectionAssocfalse) ;
                }
            }
    private static boolean toBooleanObject propboolean defaultVal ) {
        if ( prop == null ) {
            return defaultVal;
        }
        return Boolean.valueOf(((Stringprop).toLowerCase(Locale.getDefault()));
     }
    public static int getTransactionSupportFromRaXml(String rarNamethrows
            ConnectorRuntimeException {
        String txSupport =
                ConnectorRuntime.getRuntime().getConnectorDescriptor(rarName).
                        getOutboundResourceAdapter().getTransSupport();
        return parseTransactionSupportString(txSupport);
    }
New to GrepCode? Check out our FAQ X