FileDocCategorySizeDatePackage
JdbcConnectionPoolTest.javaAPI DocGlassfish v2 API12487Fri May 04 22:34:10 BST 2007com.sun.enterprise.admin.verifier.tests

JdbcConnectionPoolTest

public class JdbcConnectionPoolTest extends ServerXmlTest implements ServerCheck
PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms. Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All rights reserved.

Fields Summary
static Logger
_logger
static int
minPool
static String
connValReqd
static String
connValMethod
Constructors Summary
public JdbcConnectionPoolTest()

    
      
    
Methods Summary
public Resultcheck(com.sun.enterprise.config.ConfigContext context)

        Result result;
        result = super.getInitializedResult();
        // 8.0 XML Verifier
        /*try {
            Server server = (Server)context.getRootConfigBean();
            Resources resource = server.getResources();
            JdbcConnectionPool[] pool = resource.getJdbcConnectionPool();
            for(int i=0;i<pool.length;i++){
                int minPool=0, maxPool=0;
                try {
                    minPool = Integer.parseInt(pool[i].getSteadyPoolSize());
                    maxPool = Integer.parseInt(pool[i].getMaxPoolSize());
                } catch(NumberFormatException e) {
                    result.failed("Bad Number");
                }
                if(maxPool < minPool) 
                    result.failed("Steady Pool size should be less than or equal to Maximum Pool size");
                if(pool[i].isIsConnectionValidationRequired() && pool[i].getConnectionValidationMethod().equals("table")) {
                        if(pool[i].getValidationTableName() == null || pool[i].getValidationTableName().equals(""))
                            result.failed("Required Table Name if Connection validation method is Table for " + pool[i].getName() );
                        else
                            result.passed("Validation Table Name for " + pool[i].getName() );
                }
                else
                        result.passed("Validation Passed for Connection Pool" + pool[i].getName());
            }
        }
        catch(Exception ex) {
            // Logging
            _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
            result.failed("Exception : " + ex.getMessage());
        }*/
        return result;
    
public Resultcheck(com.sun.enterprise.config.ConfigContextEvent ccce)

        Result result = new Result();
        result.passed("Passed **");
        ConfigContext context = ccce.getConfigContext();
        Object value = ccce.getObject();
        String choice = ccce.getChoice();
        
        String beanName = ccce.getBeanName();
        if(beanName!=null) {
               String name = ccce.getName();
               return testSave(name,(String)value);
        }
        
        JdbcConnectionPool pool = (JdbcConnectionPool)value;
        String poolName = pool.getName();
        
        // check if connction pool name is valid object name Bug : 4698687 : start
        if(StaticTest.checkObjectName(poolName, result)) 
            result.passed("Valid Object Name");
        else {
            result.failed("Connection Pool Name Invalid ");
            return result;
        }
        // End Bug : 4698687
        
        String datasourceClassname = pool.getDatasourceClassname();
        
        // to be uncommented once warning is implemented
        /*if(isInValidDataSource(result, datasourceClassname))
            return result;*/
        
        if (choice != null && choice.equals("DELETE")){
            try{
                    // 8.0 XML Verifier
                    //Server server = (Server)context.getRootConfigBean();
                    //Resources resource = server.getResources();
                    Domain domain = (Domain)context.getRootConfigBean();
                    Resources resource = domain.getResources();
                    JdbcResource[] jdbcResource = resource.getJdbcResource();
                    if(jdbcResource.length == 0)
                            result.passed("Connect Pool not used by data source");
                    for(int i=0;i<jdbcResource.length;i++){
                        if(jdbcResource[i].getPoolName().equals(poolName)) {
                                result.failed("Connection Pool Used by Existing data source, cannot delete pool");
                                break;
                        }
                        else 
                               result.passed("Connect Pool not used by data source");
                    }
            }
            catch(Exception e) {
            }
        }
        else {
                 if(pool.isIsConnectionValidationRequired() && pool.getConnectionValidationMethod().equals("table")) {
                        if(pool.getValidationTableName() == null || pool.getValidationTableName().equals(""))
                               result.failed("Required Table Name if Connection validation method is Table");
                        else
                               result.passed("Validation Table Name");
                }
                else
                     result.passed("****** Passed Validation Table Name");
        }
        return result;
     
public booleanisInValidDataSource(Result result, java.lang.String datasourceClassname)

         boolean failed = true;
         try {
            Class c1 = Class.forName(datasourceClassname);
            Object obj = c1.newInstance();
            if (obj instanceof javax.sql.DataSource) {
                result.passed("Valid Data Source");
                failed = false;   
            }
            else if(obj instanceof javax.sql.XADataSource) {
                result.passed("Valid XA DataSource");
                failed = false;
            }
            else 
                result.failed("Invalid  Data Source Class not implementing, javax.sql.DataSource or javax.sql.XADataSource");
         }catch(Exception e) {
	     // Logging
	     _logger.log(Level.FINE, "serverxmlverifier.error_instantiation", e.getMessage());
             result.failed("Invalid DataSource class");
         }
         return failed;
     
public ResulttestSave(java.lang.String name, java.lang.String value)

           Result result = new Result();
           result.passed("Passed **");
           if(name.equals(ServerTags.STEADY_POOL_SIZE)) {
               try {
                    JdbcConnectionPoolTest.minPool = Integer.parseInt(value);
                    result.passed("Passed ");
               }catch(NumberFormatException e) {
                   result.failed("Bad Number : Steady pool size");
               }
           }
           if(name.equals(ServerTags.MAX_POOL_SIZE)){
               try {
                    int maxPool = Integer.parseInt(value);
                    if(maxPool < JdbcConnectionPoolTest.minPool) 
                        result.failed("Steady Pool size must be less than or equal to Maximum Pool size");
                    else 
                        result.passed("Passed ");
               }catch(NumberFormatException e) {
                   result.failed("Bad Number : Max pool size");
               }
           }
           if(name.equals(ServerTags.IS_CONNECTION_VALIDATION_REQUIRED)){
                JdbcConnectionPoolTest.connValReqd = value;
           }
           if(name.equals(ServerTags.CONNECTION_VALIDATION_METHOD)){
                JdbcConnectionPoolTest.connValMethod = value;
           }
           if(name.equals(ServerTags.VALIDATION_TABLE_NAME)){
               if(connValReqd.equals("true")) {
                   if(connValMethod.equals("table")) {
                       if(value == null || value.equals(""))
                            result.failed("Required table name");
                       else
                           result.passed("Passed ***");
                   }
                   else
                       result.passed("Passed ***");
               }
               else
                   result.passed("Passed ***");
           }// to be uncommented once warning is implemented
           /*if(name.equals(ServerTags.DATASOURCE_CLASSNAME)) {
                if(isInValidDataSource(result, value)) {
                    return result;
                }
           }*/
            // Check for transaction-isolation-level
           if (name.equals(ServerTags.TRANSACTION_ISOLATION_LEVEL)) {
                if (value != null) {
                    String isolation = (String) value;
                
                     if (isolation.equals(""))
                        result.failed("Transaction Isolation Level not specified");
                     else if ((isolation.equals("read-uncommitted")) ||
                        (isolation.equals("read-committed")) ||
                        (isolation.equals("repeatable-read")) ||
                        (isolation.equals("serializable")))
                         result.passed("Valid Transaction Isolation Level");
                     else result.failed("Invalid Transaction Isolation Level: " +  isolation);
                }
           }
           // Bug 4675624
           if(name.equals(ServerTags.IDLE_TIMEOUT_IN_SECONDS)) {
               if(value != null) {
                   try {
                       Integer.parseInt(value);
                       result.passed("Passed ***");
                   } catch(NumberFormatException e) {
                       result.failed("Idle Timeout : invalid number");
                   }
               }
           }
           return result;