1 23 24 37 package com.sun.enterprise.resource; 38 39 import com.sun.enterprise.config.serverbeans.ElementProperty; 40 import com.sun.enterprise.config.serverbeans.JdbcConnectionPool; 41 import com.sun.enterprise.config.serverbeans.Resources; 42 import com.sun.enterprise.connectors.ConnectorConnectionPool; 43 import com.sun.enterprise.connectors.ConnectorConstants; 44 import com.sun.enterprise.connectors.ConnectorDescriptorInfo; 45 import com.sun.enterprise.connectors.ConnectorRuntime; 46 import com.sun.enterprise.connectors.ConnectorRuntimeException; 47 import com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils; 48 import com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils; 49 import com.sun.enterprise.deployment.archivist.ConnectorArchivist; 50 import com.sun.enterprise.deployment.ConnectionDefDescriptor; 51 import com.sun.enterprise.deployment.ConnectorDescriptor; 52 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 53 import com.sun.enterprise.deployment.EnvironmentProperty; 54 import com.sun.enterprise.NamingManager; 55 import com.sun.enterprise.resource.ResourceInstaller; 56 import com.sun.enterprise.server.Constants; 57 import com.sun.enterprise.server.ResourceDeployer; 58 import com.sun.enterprise.Switch; 59 import com.sun.enterprise.util.i18n.StringManager; 60 import com.sun.enterprise.util.Utility; 61 import com.sun.logging.LogDomains; 62 63 import java.io.File ; 64 import java.util.ArrayList ; 65 import java.util.HashMap ; 66 import java.util.HashSet ; 67 import java.util.Iterator ; 68 import java.util.ListIterator ; 69 import java.util.logging.Level ; 70 import java.util.logging.Logger ; 71 import java.util.Map ; 72 import java.util.MissingResourceException ; 73 import java.util.Set ; 74 75 85 86 88 public class JdbcConnectionPoolDeployer implements ResourceDeployer { 89 90 static private StringManager sm = StringManager.getManager( 91 JdbcConnectionPoolDeployer.class); 92 static private String msg = sm.getString("resource.restart_needed"); 93 94 static private Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 95 96 public synchronized void deployResource(Object resource) throws Exception { 97 105 _logger.fine(" JdbcConnectionPoolDeployer - deployResource : " + resource + " calling actualDeploy"); 106 actualDeployResource(resource); 107 } 108 109 115 public synchronized void actualDeployResource(Object resource) throws Exception { 116 _logger.fine(" JdbcConnectionPoolDeployer - actualDeployResource : " + resource ); 117 com.sun.enterprise.config.serverbeans.JdbcConnectionPool adminPool = 118 (com.sun.enterprise.config.serverbeans.JdbcConnectionPool) resource; 119 120 121 ConnectorConnectionPool connConnPool = createConnectorConnectionPool( 122 adminPool); 123 124 125 try { 127 ConnectorRuntime.getRuntime().createConnectorConnectionPool( 128 connConnPool); 129 } catch( ConnectorRuntimeException cre ) { 130 cre.printStackTrace(); 131 } 132 } 133 134 public synchronized void undeployResource(Object resource) throws Exception { 135 _logger.fine(" JdbcConnectionPoolDeployer - unDeployResource : " + 136 "calling actualUndeploy of " + resource); 137 actualUndeployResource(resource); 138 } 139 140 147 148 public synchronized void actualUndeployResource(Object resource) throws Exception { 149 _logger.fine(" JdbcConnectionPoolDeployer - unDeployResource : " + resource); 150 151 com.sun.enterprise.config.serverbeans.JdbcConnectionPool jdbcConnPool = 152 (com.sun.enterprise.config.serverbeans.JdbcConnectionPool) resource; 153 154 String poolName = jdbcConnPool.getName(); 155 ConnectorRuntime runtime = ConnectorRuntime.getRuntime(); 156 runtime.deleteConnectorConnectionPool( poolName ); 157 if ( _logger.isLoggable( Level.FINEST ) ) { 158 _logger.finest("Pool Undeployed"); 159 } 160 } 161 162 169 public synchronized void redeployResource(Object resource) throws Exception { 170 171 com.sun.enterprise.config.serverbeans.JdbcConnectionPool adminPool 172 = (com.sun.enterprise.config.serverbeans.JdbcConnectionPool) 173 resource; 174 175 176 if (!ConnectorRuntime.getRuntime(). 179 isConnectorConnectionPoolDeployed(adminPool.getName())) { 180 181 _logger.fine("The JDBC connection pool " + adminPool.getName() 182 + " is not referred or not yet created in this server " 183 + "instance and hence pool redeployment is ignored"); 184 return; 185 } 186 187 ConnectorConnectionPool connConnPool = createConnectorConnectionPool( 188 adminPool); 189 190 if (connConnPool == null) { 191 throw new ConnectorRuntimeException("Unable to create ConnectorConnectionPool"+ 192 "from JDBC connection pool"); 193 } 194 195 ConnectorRuntime runtime = ConnectorRuntime.getRuntime(); 197 HashSet excludes = new HashSet (); 198 excludes.add( "TransactionIsolation"); 201 excludes.add( "GuaranteeIsolationLevel"); 202 excludes.add( "ValidationTableName"); 203 excludes.add( "ConnectionValidationRequired"); 204 excludes.add( "ValidationMethod"); 205 try { 206 _logger.finest("Calling reconfigure pool"); 207 boolean poolRecreateRequired = 208 runtime.reconfigureConnectorConnectionPool(connConnPool, 209 excludes); 210 if ( poolRecreateRequired ) { 211 _logger.finest("Pool recreation required"); 212 runtime.recreateConnectorConnectionPool( connConnPool ); 213 _logger.finest("Pool recreation done"); 214 } 215 } catch( ConnectorRuntimeException cre ) { 216 cre.printStackTrace(); 217 throw cre; 218 } 219 } 220 221 228 public synchronized void enableResource(Object resource) throws Exception { 229 throw new UnsupportedOperationException (msg); 230 } 231 232 239 public synchronized void disableResource(Object resource) throws Exception { 240 throw new UnsupportedOperationException (msg); 241 } 242 243 244 252 public Object getResource(String name, Resources rbeans) throws Exception { 253 Object res = rbeans.getJdbcConnectionPoolByName(name); 254 255 if (res == null) { 256 String msg = sm.getString("resource.no_resource",name); 257 throw new Exception (msg); 258 } 259 260 return res; 261 } 262 263 271 private ConnectorDescriptor createConnectorDescriptor( 272 String moduleDir ) { 273 274 ConnectorDescriptor connectorDescriptor = null ; 275 FileArchive fa = new FileArchive(); 276 try { 277 fa.open( moduleDir ); ConnectorArchivist archivist = new ConnectorArchivist(); 279 connectorDescriptor = (ConnectorDescriptor) 280 archivist.open(fa); 281 } catch( Exception ioe ) { 282 ioe.printStackTrace(); 283 } 284 285 return connectorDescriptor; 286 } 287 288 289 299 private EnvironmentProperty[] getMCFConfigProperties( 300 JdbcConnectionPool adminPool, 301 ConnectorConnectionPool conConnPool, ConnectorDescriptor connDesc ) 302 { 303 304 ArrayList propList = new ArrayList (); 305 306 propList.add( new EnvironmentProperty("ClassName", 307 adminPool.getDatasourceClassname() == null ? "" : 308 adminPool.getDatasourceClassname(), 309 "The datasource class name", 310 "java.lang.String") ); 311 312 313 propList.add( new EnvironmentProperty("ConnectionValidationRequired", 314 adminPool.isIsConnectionValidationRequired()+"", 315 "Is connection validation required", 316 "java.lang.String" )); 317 318 propList.add( new EnvironmentProperty("ValidationMethod", 319 adminPool.getConnectionValidationMethod() == null ? "" : 320 adminPool.getConnectionValidationMethod(), 321 "How the connection is validated", 322 "java.lang.String") ); 323 324 propList.add( new EnvironmentProperty("ValidationTableName", 325 adminPool.getValidationTableName() == null ? 326 "" : adminPool.getValidationTableName(), 327 "Validation Table name", 328 "java.lang.String") ); 329 330 propList.add( new EnvironmentProperty("TransactionIsolation", 331 adminPool.getTransactionIsolationLevel() == null ? "" : 332 adminPool.getTransactionIsolationLevel(), 333 "Transaction Isolatin Level", 334 "java.lang.String") ); 335 336 propList.add( new EnvironmentProperty("GuaranteeIsolationLevel", 337 adminPool.isIsIsolationLevelGuaranteed() + "", 338 "Transaction Isolation Guarantee", 339 "java.lang.String") ); 340 341 342 Set connDefDescSet = connDesc.getOutboundResourceAdapter(). 344 getConnectionDefs(); 345 if ( connDefDescSet.size() != 1 ) { 347 throw new MissingResourceException ("Only one connDefDesc present", 348 null, null ); 349 } 350 351 Iterator iter = connDefDescSet.iterator(); 352 353 Set mcfConfigProps = null; 356 while( iter.hasNext() ) { 357 mcfConfigProps = ((ConnectionDefDescriptor)iter.next()). 358 getConfigProperties(); 359 } 360 if (mcfConfigProps != null) { 361 362 Map mcfConPropKeys = new HashMap (); 363 Iterator mcfConfigPropsIter = mcfConfigProps.iterator(); 364 while( mcfConfigPropsIter.hasNext() ) { 365 String key = ((EnvironmentProperty)mcfConfigPropsIter.next()). 366 getName(); 367 mcfConPropKeys.put( key.toUpperCase(), key ); 368 } 369 370 String driverProperties = ""; 371 for( ElementProperty rp : adminPool.getElementProperty()) { 372 if ( rp == null ) { 373 continue; 374 } 375 String name = (String ) rp.getName(); 376 377 if ( "MATCHCONNECTIONS".equals( name.toUpperCase()) ) { 381 conConnPool.setMatchConnections( toBoolean( rp.getValue(), false ) ); 384 logFine("MATCHCONNECTIONS"); 385 386 } else if ( "LAZYCONNECTIONASSOCIATION".equals(name.toUpperCase()) ) { 387 ConnectionPoolObjectsUtils.setLazyEnlistAndLazyAssocProperties(rp.getValue(),adminPool, conConnPool); 388 logFine("LAZYCONNECTIONASSOCIATION"); 389 390 } else if ( "LAZYCONNECTIONENLISTMENT".equals(name.toUpperCase()) ) { 391 conConnPool.setLazyConnectionEnlist( toBoolean( rp.getValue(), false )) ; 392 logFine("LAZYCONNECTIONENLISTMENT"); 393 394 } else if ("ASSOCIATEWITHTHREAD".equals( name.toUpperCase() ) ) { 395 conConnPool.setAssociateWithThread( toBoolean(rp.getValue(), false)) ; 396 logFine( "ASSOCIATEWITHTHREAD"); 397 398 } else if ("CONNECTIONLEAKTRACING".equals(name.toUpperCase())) { 399 conConnPool.setConnectionLeakTracing(toBoolean(rp.getValue(), false)); 400 logFine("CONNECTIONLEAKTRACING"); 401 402 } else if ("USERNAME".equals(name.toUpperCase()) || 403 "USER".equals( name.toUpperCase() ) ) { 404 405 propList.add( new EnvironmentProperty( "User", 406 rp.getValue(), "user name", "java.lang.String") ); 407 408 } else if ("PASSWORD".equals(name.toUpperCase()) ) { 409 410 propList.add( new EnvironmentProperty( "Password", 411 rp.getValue(), "Password", "java.lang.String") ); 412 413 } else if (mcfConPropKeys.containsKey(name.toUpperCase())) { 414 415 propList.add( new EnvironmentProperty( 416 (String )mcfConPropKeys.get(name.toUpperCase()), 417 rp.getValue() == null ? "" : (rp.getValue()).toString(), 418 "Some property", 419 "java.lang.String") ); 420 } else { 421 driverProperties = driverProperties + "set" + name 422 + "#" + rp.getValue() +"##"; 423 } 424 } 425 426 if (! driverProperties.equals("") ) { 427 propList.add( new EnvironmentProperty("DriverProperties", 428 driverProperties, 429 "some proprietarty properties", 430 "java.lang.String")); 431 } 432 } 433 434 435 propList.add( new EnvironmentProperty("Delimiter", 436 "#", "delim", "java.lang.String" ) ); 437 EnvironmentProperty[] eProps = new EnvironmentProperty[ propList.size() ]; 439 ListIterator propListIter = propList.listIterator(); 440 441 for( int i = 0; propListIter.hasNext(); i++ ) { 442 eProps[i] = (EnvironmentProperty) propListIter.next(); 443 } 444 445 return eProps; 446 447 } 448 449 private String getSystemModuleLocation(String moduleName) { 450 String j2eeModuleDirName = System.getProperty(Constants.INSTALL_ROOT) + 451 File.separator + "lib" + File.separator + "install" + 452 File.separator + "applications" + File.separator + moduleName; 453 454 return j2eeModuleDirName; 455 456 } 457 private boolean toBoolean( Object prop, boolean defaultVal ) { 458 if ( prop == null ) { 459 return defaultVal; 460 } 461 return (new Boolean ( ((String )prop).toLowerCase())).booleanValue(); 462 } 463 464 private void logFine( String msg ) { 465 if ( _logger.isLoggable(Level.FINE) && msg != null ) { 466 _logger.fine( msg ); 467 } 468 } 469 470 public ConnectorConnectionPool createConnectorConnectionPool( 471 JdbcConnectionPool adminPool) 472 { 473 474 String moduleName = getModuleName( adminPool ); 475 String moduleDir = getSystemModuleLocation( moduleName ); 476 int txSupport = getTxSupport( moduleName ); 477 478 ConnectorDescriptor connDesc = createConnectorDescriptor( moduleDir ); 479 480 ConnectorConnectionPool conConnPool = new ConnectorConnectionPool( 482 adminPool.getName() ); 483 484 conConnPool.setTransactionSupport( txSupport ); 485 setConnectorConnectionPoolAttributes( conConnPool, adminPool ); 486 487 488 489 ConnectorDescriptorInfo connDescInfo = 491 createConnectorDescriptorInfo( connDesc, moduleName ); 492 493 494 connDescInfo.setMCFConfigProperties( 495 getMCFConfigProperties( adminPool, conConnPool, connDesc ) ); 496 497 connDescInfo.setResourceAdapterConfigProperties((Set ) null ); 499 500 conConnPool.setConnectorDescriptorInfo( connDescInfo ); 501 502 return conConnPool; 503 504 } 505 506 private String getModuleName( JdbcConnectionPool jcp ) { 507 508 String resType = jcp.getResType(); 509 String dsClassName = jcp.getDatasourceClassname(); 510 511 String moduleName = ConnectorConstants.JDBCDATASOURCE_RA_NAME; 512 513 if (resType == null) { 514 return moduleName; 516 } 517 518 if ("javax.sql.XADataSource".equals(resType) && dsClassName != null) { 519 520 try { 521 Class dsClass = Utility.loadClass( dsClassName ); 522 if (javax.sql.XADataSource .class.isAssignableFrom(dsClass)) { 523 return ConnectorConstants.JDBCXA_RA_NAME; 524 } 525 } catch (ClassNotFoundException e) { 526 } 528 } 529 530 if ("javax.sql.ConnectionPoolDataSource".equals(resType) && 531 dsClassName != null) { 532 533 try { 534 Class dsClass = Utility.loadClass( dsClassName ); 535 if (javax.sql.ConnectionPoolDataSource .class.isAssignableFrom(dsClass)) { 536 return ConnectorConstants.JDBCCONNECTIONPOOLDATASOURCE_RA_NAME; 537 } 538 } catch (ClassNotFoundException e) { 539 } 541 } 542 543 return moduleName; 544 545 } 546 547 private int getTxSupport( String moduleName ) { 548 if ( ConnectorConstants.JDBCXA_RA_NAME.equals(moduleName)) { 549 return ConnectionPoolObjectsUtils.parseTransactionSupportString( 550 ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING ); 551 } 552 553 return ConnectionPoolObjectsUtils.parseTransactionSupportString( 554 ConnectorConstants.LOCAL_TRANSACTION_TX_SUPPORT_STRING ); 555 } 556 557 private ConnectorDescriptorInfo createConnectorDescriptorInfo( 558 ConnectorDescriptor connDesc, String moduleName ) 559 { 560 ConnectorDescriptorInfo connDescInfo = new ConnectorDescriptorInfo(); 561 562 connDescInfo.setManagedConnectionFactoryClass( 563 connDesc.getOutboundResourceAdapter(). 564 getManagedConnectionFactoryImpl() ); 565 566 connDescInfo.setRarName( moduleName ); 567 568 connDescInfo.setResourceAdapterClassName( connDesc. 569 getResourceAdapterClass() ); 570 571 connDescInfo.setConnectionDefinitionName( 572 connDesc.getOutboundResourceAdapter(). 573 getConnectionFactoryIntf() ); 574 575 connDescInfo.setConnectionFactoryClass( 576 connDesc.getOutboundResourceAdapter(). 577 getConnectionFactoryImpl() ); 578 579 connDescInfo.setConnectionFactoryInterface( 580 connDesc.getOutboundResourceAdapter(). 581 getConnectionFactoryIntf() ); 582 583 connDescInfo.setConnectionClass( 584 connDesc.getOutboundResourceAdapter(). 585 getConnectionImpl() ); 586 587 connDescInfo.setConnectionInterface( 588 connDesc.getOutboundResourceAdapter(). 589 getConnectionIntf() ); 590 591 return connDescInfo; 592 } 593 594 private void setConnectorConnectionPoolAttributes( 595 ConnectorConnectionPool ccp, JdbcConnectionPool adminPool ) 596 { 597 ccp.setMaxPoolSize( adminPool.getMaxPoolSize() != null ? 598 adminPool.getMaxPoolSize() : 599 adminPool.getDefaultMaxPoolSize() ); 600 601 ccp.setSteadyPoolSize( adminPool.getSteadyPoolSize() != null ? 602 adminPool.getSteadyPoolSize() : 603 adminPool.getDefaultSteadyPoolSize() ); 604 605 ccp.setMaxWaitTimeInMillis( 606 adminPool.getMaxWaitTimeInMillis() != null ? 607 adminPool.getMaxWaitTimeInMillis() : 608 adminPool.getDefaultMaxWaitTimeInMillis() ); 609 610 ccp.setPoolResizeQuantity( 611 adminPool.getPoolResizeQuantity() != null ? 612 adminPool.getPoolResizeQuantity() : 613 adminPool.getDefaultPoolResizeQuantity()); 614 615 ccp.setIdleTimeoutInSeconds( 616 adminPool.getIdleTimeoutInSeconds() != null ? 617 adminPool.getIdleTimeoutInSeconds() : 618 adminPool.getDefaultIdleTimeoutInSeconds() ); 619 620 ccp.setFailAllConnections(adminPool.isFailAllConnections()); 621 622 ccp.setConnectionValidationRequired( 623 adminPool.isIsConnectionValidationRequired() ); 624 625 ccp.setNonTransactional( 626 adminPool.isNonTransactionalConnections() ); 627 ccp.setNonComponent( adminPool.isAllowNonComponentCallers() ); 628 629 ccp.setMatchConnections( false ); 633 ccp.setLazyConnectionAssoc( false ); 634 ccp.setAssociateWithThread( false ); 635 ccp.setConnectionLeakTracing( false ); 636 637 } 638 639 } 640 | Popular Tags |