1 21 package oracle.toplink.essentials.platform.server; 23 24 import java.security.AccessController ; 25 import java.security.PrivilegedActionException ; 26 27 import oracle.toplink.essentials.exceptions.ValidationException; 28 import oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl; 29 import oracle.toplink.essentials.sessions.ExternalTransactionController; 30 import oracle.toplink.essentials.internal.localization.ToStringLocalization; 31 import oracle.toplink.essentials.logging.AbstractSessionLog; 32 import oracle.toplink.essentials.logging.SessionLog; 33 import oracle.toplink.essentials.internal.security.PrivilegedAccessHelper; 34 import oracle.toplink.essentials.internal.security.PrivilegedNewInstanceFromClass; 35 import oracle.toplink.essentials.internal.databaseaccess.Platform; 36 37 70 public abstract class ServerPlatformBase implements ServerPlatform { 71 72 76 protected Class externalTransactionControllerClass; 77 78 82 private boolean isRuntimeServicesEnabled; 83 84 89 private boolean isJTAEnabled; 90 91 96 private boolean isCMP; 97 98 102 private DatabaseSessionImpl databaseSession; 103 104 109 public ServerPlatformBase(DatabaseSessionImpl newDatabaseSession) { 110 this.isRuntimeServicesEnabled = true; 111 this.isJTAEnabled = true; 112 this.databaseSession = newDatabaseSession; 113 this.setIsCMP(false); 114 } 115 116 121 public DatabaseSessionImpl getDatabaseSession() { 122 return this.databaseSession; 123 } 124 125 133 public String getServerNameAndVersion() { 134 return ToStringLocalization.buildMessage("unknown"); 135 } 136 137 146 public String getModuleName() { 147 return "unknown"; 148 } 149 150 168 public abstract Class getExternalTransactionControllerClass(); 169 170 180 public void setExternalTransactionControllerClass(Class newClass) { 181 this.externalTransactionControllerClass = newClass; 182 } 183 184 196 public void initializeExternalTransactionController() { 197 this.ensureNotLoggedIn(); 198 199 if (!isJTAEnabled() && !isCMP()) { 202 return; 203 } 204 if (!isJTAEnabled() && isCMP()) { 206 AbstractSessionLog.getLog().warning("jta_cannot_be_disabled_in_cmp"); 207 } 208 209 try { 213 if (getDatabaseSession().getExternalTransactionController() != null) { 214 this.externalTransactionControllerNotNullWarning(); 215 return; 216 } 217 ExternalTransactionController controller = null; 218 if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ 219 try { 220 controller = (ExternalTransactionController)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(this.getExternalTransactionControllerClass())); 221 } catch (PrivilegedActionException exception) { 222 Exception throwableException = exception.getException(); 223 if (throwableException instanceof InstantiationException ) { 224 throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName()); 225 } else { 226 throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName()); 227 } 228 } 229 } else { 230 controller = (ExternalTransactionController)PrivilegedAccessHelper.newInstanceFromClass(this.getExternalTransactionControllerClass()); 231 } 232 getDatabaseSession().setExternalTransactionController(controller); 233 } catch (InstantiationException instantiationException) { 234 throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName()); 235 } catch (IllegalAccessException illegalAccessException) { 236 throw ValidationException.cannotCreateExternalTransactionController(getExternalTransactionControllerClass().getName()); 237 } 238 } 239 240 248 protected void externalTransactionControllerNotNullWarning() { 249 getDatabaseSession().warning("External_transaction_controller_not_defined_by_server_platform", SessionLog.EJB); 250 } 251 252 263 public boolean isJTAEnabled() { 264 return this.isJTAEnabled; 265 } 266 267 278 public void disableJTA() { 279 this.ensureNotLoggedIn(); 280 this.isJTAEnabled = false; 281 } 282 283 290 public boolean isRuntimeServicesEnabled() { 291 return this.isRuntimeServicesEnabled; 292 } 293 294 301 public void disableRuntimeServices() { 302 this.ensureNotLoggedIn(); 303 this.isRuntimeServicesEnabled = false; 304 } 305 306 317 public void registerMBean() { 318 if (!this.isRuntimeServicesEnabled()) { 319 return; 320 } 321 this.serverSpecificRegisterMBean(); 322 } 323 324 336 public void serverSpecificRegisterMBean() { 337 } 338 339 348 public void unregisterMBean() { 349 if (!this.isRuntimeServicesEnabled()) { 350 return; 351 } 352 this.serverSpecificUnregisterMBean(); 353 } 354 355 361 public java.sql.Connection unwrapOracleConnection(Platform platform, java.sql.Connection connection){ 362 try { 363 return connection.getMetaData().getConnection(); 364 } catch (java.sql.SQLException e){ 365 ((DatabaseSessionImpl)getDatabaseSession()).log(SessionLog.WARNING, SessionLog.CONNECTION, "cannot_unwrap_connection", e); 366 return connection; 367 } 368 } 369 370 371 381 public void serverSpecificUnregisterMBean() { 382 } 383 384 393 public void launchContainerRunnable(Runnable runnable) { 394 new Thread (runnable).start(); 395 } 396 397 402 protected void ensureNotLoggedIn() { 403 if (getDatabaseSession() == null) { 405 return; 406 } 407 if (getDatabaseSession().isConnected()) { 408 throw ValidationException.serverPlatformIsReadOnlyAfterLogin(this.getClass().getName()); 409 } 410 } 411 412 419 public oracle.toplink.essentials.logging.SessionLog getServerLog() { 420 return new ServerLog(); 421 } 422 423 428 public boolean isCMP() { 429 return isCMP; 430 } 431 432 437 public void setIsCMP(boolean isThisCMP) { 438 isCMP = isThisCMP; 439 } 440 441 } 442 | Popular Tags |