1 23 24 37 package com.sun.enterprise.resource; 38 39 import com.sun.enterprise.server.ResourceDeployer; 40 import com.sun.enterprise.server.ResourcesUtil; 41 42 import com.sun.enterprise.config.serverbeans.Resources; 43 import com.sun.enterprise.connectors.ConnectorAdminServiceUtils; 45 import com.sun.enterprise.connectors.ConnectorRuntime; 46 47 import com.sun.enterprise.Switch; 48 import com.sun.enterprise.NamingManager; 49 import com.sun.enterprise.resource.ResourceInstaller; 50 import com.sun.enterprise.repository.JdbcConnectionPool; 51 import com.sun.enterprise.repository.IASJdbcResource; 52 import com.sun.enterprise.repository.JdbcResource; 53 import com.sun.enterprise.repository.JdbcXAResource; 54 import com.sun.enterprise.repository.IASJdbcXAResource; 55 import com.sun.enterprise.repository.J2EEResource; 56 import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl; 57 58 import java.util.logging.Logger ; 59 import java.util.logging.Level ; 60 import com.sun.logging.LogDomains; 61 import com.sun.enterprise.util.i18n.StringManager; 62 63 import com.sun.enterprise.ManagementObjectManager; 64 65 import com.sun.enterprise.connectors.ConnectorConstants; 66 import javax.naming.InitialContext ; 67 import com.sun.enterprise.config.ConfigBean; 68 import com.sun.enterprise.config.ConfigException; 69 70 71 82 public class JdbcResourceDeployer implements ResourceDeployer { 83 84 private static final StringManager localStrings = 85 StringManager.getManager("com.sun.enterprise.resource"); 86 87 private static Logger _logger=LogDomains.getLogger(LogDomains.CORE_LOGGER); 88 private static final String PM_JNDI_EXTENSION = "__pm"; 89 95 public synchronized void deployResource(Object resource) throws Exception { 96 97 com.sun.enterprise.config.serverbeans.JdbcResource jdbcRes = 98 (com.sun.enterprise.config.serverbeans.JdbcResource) resource; 99 100 if (jdbcRes.isEnabled()) { 101 String jndiName = jdbcRes.getJndiName(); 102 String poolName = jdbcRes.getPoolName(); 103 104 loadPool(jdbcRes); 106 107 ManagementObjectManager mgr = Switch.getSwitch().getManagementObjectManager(); 108 mgr.registerJDBCResource( jndiName ); 109 ConnectorRuntime runtime = ConnectorRuntime.getRuntime(); 110 runtime.createConnectorResource( jndiName, poolName, null); 111 runtime.createConnectorResource( getPMJndiName( jndiName), 112 poolName, null); 113 _logger.finest("deployed resource " + jndiName ); 114 } else { 115 _logger.log(Level.INFO, "core.resource_disabled", 116 new Object [] {jdbcRes.getJndiName(), 117 IASJ2EEResourceFactoryImpl.JDBC_RES_TYPE}); 118 } 119 } 120 121 127 public synchronized void undeployResource(Object resource) 128 throws Exception { 129 130 com.sun.enterprise.config.serverbeans.JdbcResource jdbcRes = 131 (com.sun.enterprise.config.serverbeans.JdbcResource) resource; 132 133 String jndiName = jdbcRes.getJndiName(); 134 String pmJndiName = getPMJndiName( jdbcRes.getJndiName() ); 135 136 ConnectorRuntime runtime = ConnectorRuntime.getRuntime(); 137 runtime.deleteConnectorResource( jndiName ); 138 runtime.deleteConnectorResource( pmJndiName ); 139 140 ManagementObjectManager mgr = 141 Switch.getSwitch().getManagementObjectManager(); 142 mgr.unregisterJDBCResource( jndiName ); 143 144 checkAndDeletePool(jdbcRes); 148 149 150 } 151 152 158 public synchronized void redeployResource(Object resource) 159 throws Exception { 160 161 undeployResource(resource); 162 deployResource(resource); 163 } 164 165 171 public synchronized void enableResource(Object resource) throws Exception { 172 deployResource(resource); 173 } 174 175 181 public synchronized void disableResource(Object resource) throws Exception { 182 undeployResource(resource); 183 } 184 185 186 194 public Object getResource(String name, Resources rbeans) throws Exception { 195 196 Object res = rbeans.getJdbcResourceByJndiName(name); 197 198 if (res == null) { 199 String msg = localStrings.getString("resource.no_resource",name); 200 throw new Exception (msg); 201 } 202 203 return res; 204 } 205 206 207 208 private String getPMJndiName( String jndiName ) { 209 return jndiName + PM_JNDI_EXTENSION; 210 } 211 212 private void loadPool(com.sun.enterprise.config.serverbeans.JdbcResource jr) 213 throws Exception { 214 215 String poolName = jr.getPoolName(); 216 Resources resources = (Resources) jr.parent(); 217 ConfigBean cb = resources.getJdbcConnectionPoolByName(poolName); 218 if (cb != null) { 219 try { 220 InitialContext ic = new InitialContext (); 221 ic.lookup(ConnectorAdminServiceUtils. 222 getReservePrefixedJNDINameForPool(poolName)); 223 } catch (Exception e) { 224 JdbcConnectionPoolDeployer deployer = 226 new JdbcConnectionPoolDeployer(); 227 deployer.actualDeployResource( 228 (com.sun.enterprise.config.serverbeans.JdbcConnectionPool) 229 cb); 230 } 231 } 232 } 233 234 241 private void checkAndDeletePool(com.sun.enterprise.config.serverbeans.JdbcResource 242 cr) throws Exception { 243 String poolName = cr.getPoolName(); 244 Resources res = (Resources) cr.parent(); 245 246 try { 247 boolean poolReferred = 248 ResourcesUtil.getInstance().isJdbcPoolReferredInServerInstance(poolName); 249 if (!poolReferred) { 250 _logger.fine("Deleting JDBC pool " + poolName + "as there is no more " + 251 "resource-refs to the pool in this server instance"); 252 com.sun.enterprise.config.serverbeans.JdbcConnectionPool jcp 253 = res.getJdbcConnectionPoolByName(poolName); 254 JdbcConnectionPoolDeployer deployer = 256 new JdbcConnectionPoolDeployer(); 257 deployer.actualUndeployResource(jcp); 258 } 259 } catch (ConfigException ce) { 260 _logger.warning(ce.getMessage()); 261 _logger.fine("Exception while deleting pool : " + ce ); 262 throw ce; 263 } 264 } 265 266 } 267 | Popular Tags |