1 23 24 29 package com.sun.jdo.spi.persistence.support.sqlstore.ejb; 30 31 import java.util.ResourceBundle ; 32 33 import javax.transaction.*; 34 import com.sun.jdo.spi.persistence.utility.I18NHelper; 35 import com.sun.jdo.api.persistence.support.PersistenceManagerFactory; 36 import com.sun.jdo.api.persistence.support.JDOFatalInternalException; 37 import com.sun.jdo.spi.persistence.utility.logging.Logger; 38 import com.sun.jdo.spi.persistence.support.sqlstore.LogHelperPersistenceManager; 39 40 45 public class EJBHelper { 46 47 48 private final static ResourceBundle messages = I18NHelper.loadBundle( 49 "com.sun.jdo.spi.persistence.support.sqlstore.Bundle", EJBHelper.class.getClassLoader()); 51 52 53 private static Logger logger = LogHelperPersistenceManager.getLogger(); 54 55 59 static TransactionHelper myHelper = DefaultTransactionHelper.getInstance(); 60 61 68 public static void registerTransactionHelper (TransactionHelper h) { 69 myHelper = h; 70 if (myHelper == null) { 71 myHelper = DefaultTransactionHelper.getInstance(); 72 } 73 } 74 75 82 public static Transaction getTransaction() { 83 return myHelper.getTransaction(); 84 } 85 86 93 public static UserTransaction getUserTransaction() { 94 return myHelper.getUserTransaction(); 95 } 96 97 100 public static boolean isManaged() { 101 return myHelper.isManaged(); 102 } 103 104 112 public static int translateStatus(int st) { 113 return myHelper.translateStatus(st); 114 } 115 116 126 public static PersistenceManagerFactory replaceInternalPersistenceManagerFactory( 127 PersistenceManagerFactory pmf) { 128 return myHelper.replaceInternalPersistenceManagerFactory(pmf); 129 } 130 131 139 public static Object preInvoke(Object component) { 140 return myHelper.preInvoke(component); 141 } 142 143 149 public static void postInvoke(Object im) { 150 myHelper.postInvoke(im); 151 } 152 153 166 public static void registerSynchronization(Transaction jta, 167 Synchronization sync) throws RollbackException, SystemException { 168 myHelper.registerSynchronization(jta, sync); 169 } 170 171 182 public static java.sql.Connection getConnection(Object resource, 183 String username, String password) throws java.sql.SQLException { 184 return myHelper.getConnection(resource, username, password); 185 } 186 187 198 public static java.sql.Connection getNonTransactionalConnection( 199 Object resource, String username, String password) 200 throws java.sql.SQLException { 201 202 return myHelper.getNonTransactionalConnection(resource, 203 username, password); 204 } 205 206 207 213 public static TransactionManager getLocalTransactionManager() { 214 return myHelper.getLocalTransactionManager(); 215 } 216 217 221 public static java.sql.Statement unwrapStatement(java.sql.Statement stmt) { 222 return myHelper.unwrapStatement(stmt); 223 } 224 225 230 public static void setPersistenceManagerFactoryDefaults(PersistenceManagerFactory pmf) { 231 myHelper.setPersistenceManagerFactoryDefaults(pmf); 232 } 233 234 241 public static String getDDLNamePrefix(Object info) { 242 return myHelper.getDDLNamePrefix(info); 243 } 244 245 253 public static void registerApplicationLifeCycleEventListener( 254 ApplicationLifeCycleEventListener listener) { 255 myHelper.registerApplicationLifeCycleEventListener(listener); 256 } 257 258 264 private static class DefaultTransactionHelper implements TransactionHelper { 265 266 private static final DefaultTransactionHelper instance = new DefaultTransactionHelper(); 267 268 271 public static DefaultTransactionHelper getInstance() {return instance;} 272 273 280 public Transaction getTransaction() { return null; } 281 282 289 public UserTransaction getUserTransaction() { return null; } 290 291 294 public boolean isManaged() { return false; } 295 296 303 public int translateStatus(int st) { return st; } 304 305 313 public PersistenceManagerFactory replaceInternalPersistenceManagerFactory( 314 PersistenceManagerFactory pmf) { return pmf; } 315 316 324 public Object preInvoke(Object component) { 325 throw new JDOFatalInternalException(I18NHelper.getMessage( 326 messages, "ejb.ejbhelper.nonmanaged", "preInvoke")); } 328 329 337 public void postInvoke(Object im) { 338 throw new JDOFatalInternalException(I18NHelper.getMessage( 339 messages, "ejb.ejbhelper.nonmanaged", "postInvoke")); } 341 342 354 public void registerSynchronization(Transaction jta, 355 Synchronization sync) throws RollbackException, SystemException { } 356 357 368 public java.sql.Connection getConnection(Object resource, 369 String username, String password) throws java.sql.SQLException { 370 throw new JDOFatalInternalException(I18NHelper.getMessage( 371 messages, "ejb.ejbhelper.nonmanaged", "getConnection")); } 373 374 385 public java.sql.Connection getNonTransactionalConnection( 386 Object resource, String username, String password) 387 throws java.sql.SQLException { 388 389 throw new JDOFatalInternalException(I18NHelper.getMessage( 390 messages, "ejb.ejbhelper.nonmanaged", "getNonTransactionalConnection")); } 393 394 400 public TransactionManager getLocalTransactionManager() { 401 throw new JDOFatalInternalException(I18NHelper.getMessage( 402 messages, "ejb.ejbhelper.nonmanaged", "getLocalTransactionManager")); } 404 405 409 public java.sql.Statement unwrapStatement(java.sql.Statement stmt) { 410 if (stmt instanceof com.sun.jdo.spi.persistence.support.sqlstore.connection.StatementImpl) { 411 return ((com.sun.jdo.spi.persistence.support.sqlstore.connection.StatementImpl)stmt).unwrapStatement(); 412 } else { 413 return stmt; 414 } 415 } 416 417 423 public void setPersistenceManagerFactoryDefaults(PersistenceManagerFactory pmf) {} 424 425 433 public String getDDLNamePrefix(Object info) { 434 throw new JDOFatalInternalException(I18NHelper.getMessage( 435 messages, "ejb.ejbhelper.nonmanaged", "getDDLNamePrefix")); } 437 438 441 public void registerApplicationLifeCycleEventListener( 442 ApplicationLifeCycleEventListener listener) { 443 } 445 } 446 } 447 | Popular Tags |