1 23 24 31 package com.sun.enterprise.admin.verifier.tests; 32 33 36 37 import com.sun.enterprise.config.serverbeans.Server; 40 import com.sun.enterprise.config.serverbeans.*; 41 import com.sun.enterprise.config.serverbeans.Resources; 42 import com.sun.enterprise.config.serverbeans.Applications; 43 import com.sun.enterprise.config.ConfigContext; 44 import com.sun.enterprise.config.ConfigContextEvent; 45 import com.sun.enterprise.config.ConfigException; 46 import com.sun.enterprise.config.serverbeans.JdbcResource; 47 import com.sun.enterprise.config.serverbeans.JdbcConnectionPool; 48 49 import com.sun.enterprise.admin.verifier.*; 50 51 import java.util.logging.Logger ; 53 import java.util.logging.Level ; 54 import com.sun.logging.LogDomains; 55 56 57 public class JdbcConnectionPoolTest extends ServerXmlTest implements ServerCheck { 58 59 static Logger _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER); 61 62 static int minPool=0; 63 static String connValReqd=null; 64 static String connValMethod=null; 65 66 public JdbcConnectionPoolTest() { 67 } 68 69 public Result check(ConfigContext context) { 71 Result result; 72 result = super.getInitializedResult(); 73 103 return result; 104 } 105 106 public Result check(ConfigContextEvent ccce) { 108 Result result = new Result(); 109 result.passed("Passed **"); 110 ConfigContext context = ccce.getConfigContext(); 111 Object value = ccce.getObject(); 112 String choice = ccce.getChoice(); 113 114 String beanName = ccce.getBeanName(); 115 if(beanName!=null) { 116 String name = ccce.getName(); 117 return testSave(name,(String )value); 118 } 119 120 JdbcConnectionPool pool = (JdbcConnectionPool)value; 121 String poolName = pool.getName(); 122 123 if(StaticTest.checkObjectName(poolName, result)) 125 result.passed("Valid Object Name"); 126 else { 127 result.failed("Connection Pool Name Invalid "); 128 return result; 129 } 130 132 String datasourceClassname = pool.getDatasourceClassname(); 133 134 137 138 if (choice != null && choice.equals("DELETE")){ 139 try{ 140 Domain domain = (Domain)context.getRootConfigBean(); 144 Resources resource = domain.getResources(); 145 JdbcResource[] jdbcResource = resource.getJdbcResource(); 146 if(jdbcResource.length == 0) 147 result.passed("Connect Pool not used by data source"); 148 for(int i=0;i<jdbcResource.length;i++){ 149 if(jdbcResource[i].getPoolName().equals(poolName)) { 150 result.failed("Connection Pool Used by Existing data source, cannot delete pool"); 151 break; 152 } 153 else 154 result.passed("Connect Pool not used by data source"); 155 } 156 } 157 catch(Exception e) { 158 } 159 } 160 else { 161 if(pool.isIsConnectionValidationRequired() && pool.getConnectionValidationMethod().equals("table")) { 162 if(pool.getValidationTableName() == null || pool.getValidationTableName().equals("")) 163 result.failed("Required Table Name if Connection validation method is Table"); 164 else 165 result.passed("Validation Table Name"); 166 } 167 else 168 result.passed("****** Passed Validation Table Name"); 169 } 170 return result; 171 } 172 173 public Result testSave(String name, String value) { 174 Result result = new Result(); 175 result.passed("Passed **"); 176 if(name.equals(ServerTags.STEADY_POOL_SIZE)) { 177 try { 178 JdbcConnectionPoolTest.minPool = Integer.parseInt(value); 179 result.passed("Passed "); 180 }catch(NumberFormatException e) { 181 result.failed("Bad Number : Steady pool size"); 182 } 183 } 184 if(name.equals(ServerTags.MAX_POOL_SIZE)){ 185 try { 186 int maxPool = Integer.parseInt(value); 187 if(maxPool < JdbcConnectionPoolTest.minPool) 188 result.failed("Steady Pool size must be less than or equal to Maximum Pool size"); 189 else 190 result.passed("Passed "); 191 }catch(NumberFormatException e) { 192 result.failed("Bad Number : Max pool size"); 193 } 194 } 195 if(name.equals(ServerTags.IS_CONNECTION_VALIDATION_REQUIRED)){ 196 JdbcConnectionPoolTest.connValReqd = value; 197 } 198 if(name.equals(ServerTags.CONNECTION_VALIDATION_METHOD)){ 199 JdbcConnectionPoolTest.connValMethod = value; 200 } 201 if(name.equals(ServerTags.VALIDATION_TABLE_NAME)){ 202 if(connValReqd.equals("true")) { 203 if(connValMethod.equals("table")) { 204 if(value == null || value.equals("")) 205 result.failed("Required table name"); 206 else 207 result.passed("Passed ***"); 208 } 209 else 210 result.passed("Passed ***"); 211 } 212 else 213 result.passed("Passed ***"); 214 } 220 if (name.equals(ServerTags.TRANSACTION_ISOLATION_LEVEL)) { 222 if (value != null) { 223 String isolation = (String ) value; 224 225 if (isolation.equals("")) 226 result.failed("Transaction Isolation Level not specified"); 227 else if ((isolation.equals("read-uncommitted")) || 228 (isolation.equals("read-committed")) || 229 (isolation.equals("repeatable-read")) || 230 (isolation.equals("serializable"))) 231 result.passed("Valid Transaction Isolation Level"); 232 else result.failed("Invalid Transaction Isolation Level: " + isolation); 233 } 234 } 235 if(name.equals(ServerTags.IDLE_TIMEOUT_IN_SECONDS)) { 237 if(value != null) { 238 try { 239 Integer.parseInt(value); 240 result.passed("Passed ***"); 241 } catch(NumberFormatException e) { 242 result.failed("Idle Timeout : invalid number"); 243 } 244 } 245 } 246 return result; 247 } 248 249 public boolean isInValidDataSource(Result result, String datasourceClassname) { 250 boolean failed = true; 251 try { 252 Class c1 = Class.forName(datasourceClassname); 253 Object obj = c1.newInstance(); 254 if (obj instanceof javax.sql.DataSource ) { 255 result.passed("Valid Data Source"); 256 failed = false; 257 } 258 else if(obj instanceof javax.sql.XADataSource ) { 259 result.passed("Valid XA DataSource"); 260 failed = false; 261 } 262 else 263 result.failed("Invalid Data Source Class not implementing, javax.sql.DataSource or javax.sql.XADataSource"); 264 }catch(Exception e) { 265 _logger.log(Level.FINE, "serverxmlverifier.error_instantiation", e.getMessage()); 267 result.failed("Invalid DataSource class"); 268 } 269 return failed; 270 } 271 } 272 | Popular Tags |