1 23 24 29 package com.sun.jdo.spi.persistence.support.sqlstore.ejb; 30 31 import java.util.ResourceBundle ; 32 33 import javax.ejb.EJBObject ; 34 import javax.ejb.EJBLocalObject ; 35 import javax.ejb.EJBContext ; 36 import javax.ejb.EntityContext ; 37 38 import com.sun.jdo.api.persistence.support.JDOFatalInternalException; 39 import com.sun.jdo.api.persistence.support.PersistenceManager; 40 import com.sun.jdo.api.persistence.support.PersistenceManagerFactory; 41 import com.sun.jdo.api.persistence.support.Transaction; 42 43 import com.sun.jdo.spi.persistence.utility.I18NHelper; 44 import com.sun.jdo.spi.persistence.utility.logging.Logger; 45 import com.sun.jdo.spi.persistence.support.sqlstore.LogHelperPersistenceManager; 46 import com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerImpl; 47 import com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerWrapper; 48 49 53 public class CMPHelper { 54 55 56 private final static ResourceBundle messages = I18NHelper.loadBundle( 57 "com.sun.jdo.spi.persistence.support.sqlstore.Bundle", CMPHelper.class.getClassLoader()); 59 60 61 private static Logger logger = LogHelperPersistenceManager.getLogger(); 62 63 67 private static ContainerHelper containerHelper = null; 68 69 73 private static long counter = System.currentTimeMillis(); 74 75 81 public static void registerContainerHelper (ContainerHelper h) { 82 containerHelper = h; 83 } 84 85 89 90 public synchronized static long getNextId() { 91 counter++; 92 return counter; 93 } 94 95 110 public static Object getContainer(Object info) { 111 return getContainerHelper().getContainer(info); 112 } 113 114 124 public static EJBObject getEJBObject(Object pk, Object container) { 125 return getContainerHelper().getEJBObject(pk, container); 126 } 127 128 138 public static EJBLocalObject getEJBLocalObject(Object pk, Object container) { 139 return getContainerHelper().getEJBLocalObject(pk, container); 140 } 141 142 155 public static EJBLocalObject getEJBLocalObject(Object pk, Object container, 156 EJBContext context) { 157 return getContainerHelper().getEJBLocalObject(pk, container, context); 158 } 159 160 168 public static void removeByEJBLocalObject(EJBLocalObject ejb, Object container) { 169 getContainerHelper().removeByEJBLocalObject(ejb, container); 170 } 171 172 180 public static void removeByPK(Object pk, Object container) { 181 getContainerHelper().removeByPK(pk, container); 182 } 183 184 193 public static void setCascadeDeleteAfterSuperEJBRemove(EntityContext context) { 194 getContainerHelper().setCascadeDeleteAfterSuperEJBRemove(context); 195 } 196 197 204 public static PersistenceManagerFactory getPersistenceManagerFactory(Object container) { 205 return getContainerHelper().getPersistenceManagerFactory(container); 206 } 207 208 216 public static void assertValidLocalObject(Object o, Object container) { 217 getContainerHelper().assertValidLocalObject(o, container); 218 } 219 220 228 public static void assertValidRemoteObject(Object o, Object container) { 229 getContainerHelper().assertValidRemoteObject(o, container); 230 } 231 232 239 public static void preSelect(Object container) { 240 getContainerHelper().preSelect(container); 241 } 242 243 250 public static int getNumericConverterPolicy(Object container) { 251 return getContainerHelper().getNumericConverterPolicy(container); 252 } 253 254 261 public static void beginInternalTransaction(PersistenceManager pm) { 262 getContainerHelper().beginInternalTransaction(pm); 263 } 264 265 272 public static void commitInternalTransaction(PersistenceManager pm) { 273 getContainerHelper().commitInternalTransaction(pm); 274 } 275 276 283 public static void rollbackInternalTransaction(PersistenceManager pm) { 284 getContainerHelper().rollbackInternalTransaction(pm); 285 } 286 287 296 public static javax.transaction.Transaction suspendCurrentTransaction() { 297 return getContainerHelper().suspendCurrentTransaction(); 298 } 299 300 307 public static void resumeCurrentTransaction( 308 javax.transaction.Transaction tx) { 309 310 getContainerHelper().resumeCurrentTransaction(tx); 311 } 312 313 316 public static void flush(PersistenceManager pm) { 317 Transaction tx = pm.currentTransaction(); 318 if (tx != null && tx.isActive()) { 320 PersistenceManagerWrapper pmw = (PersistenceManagerWrapper)pm; 321 PersistenceManagerImpl pmi = 322 (PersistenceManagerImpl)pmw.getPersistenceManager(); 323 pmi.internalFlush(); 324 } 325 } 326 327 332 private static ContainerHelper getContainerHelper() { 333 if (containerHelper == null) { 334 throw new JDOFatalInternalException(I18NHelper.getMessage( 335 messages, "ejb.cmphelper.nonmanaged")); } 337 338 return containerHelper; 339 } 340 } 341 | Popular Tags |