1 21 package oracle.toplink.essentials.internal.ejb.cmp3; 23 24 import java.util.Map ; 25 26 import javax.persistence.FlushModeType; 27 import javax.persistence.Query; 28 29 import oracle.toplink.essentials.exceptions.EJBQLException; 30 import oracle.toplink.essentials.expressions.Expression; 31 import oracle.toplink.essentials.queryframework.DatabaseQuery; 32 import oracle.toplink.essentials.queryframework.ResultSetMappingQuery; 33 import oracle.toplink.essentials.threetier.ServerSession; 34 import oracle.toplink.essentials.internal.ejb.cmp3.transaction.*; 35 import oracle.toplink.essentials.internal.localization.ExceptionLocalization; 36 37 49 50 53 54 55 public class EntityManagerImpl 56 extends oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl 57 implements oracle.toplink.essentials.ejb.cmp3.EntityManager 58 { 59 60 private FlushModeType flushMode; 61 62 68 public EntityManagerImpl(String sessionName, boolean propagatePersistenceContext, boolean extended){ 69 super(sessionName, propagatePersistenceContext, extended); 70 flushMode = FlushModeType.AUTO; 71 } 72 73 77 public EntityManagerImpl(ServerSession serverSession, boolean propagatePersistenceContext, boolean extended){ 78 this(serverSession, null, propagatePersistenceContext, extended); 79 } 80 81 87 public EntityManagerImpl(ServerSession serverSession, Map properties, boolean propagePersistenceContext, boolean extended){ 88 super(serverSession, properties, propagePersistenceContext, extended); 89 flushMode = FlushModeType.AUTO; 90 } 91 92 98 public EntityManagerImpl(EntityManagerFactoryImpl factory, Map properties, boolean propagePersistenceContext, boolean extended){ 99 super(factory, properties, propagePersistenceContext, extended); 100 flushMode = FlushModeType.AUTO; 101 } 102 103 110 public <T> T merge(T entity){ 111 try{ 112 return (T) mergeInternal(entity); 113 }catch (RuntimeException e){ 114 this.transaction.setRollbackOnlyInternal(); 115 throw e; 116 } 117 } 118 119 129 public <T> T find(Class <T> entityClass, Object primaryKey){ 130 return (T) findInternal(entityClass, primaryKey); 131 } 132 133 151 public <T> T getReference(Class <T> entityClass, Object primaryKey) { 152 Object returnValue = findInternal(entityClass, primaryKey); 153 if (returnValue ==null){ 154 Object [] o = {primaryKey}; 155 String message = ExceptionLocalization.buildMessage("no_entities_retrieved_for_get_reference", o); 156 throw new javax.persistence.EntityNotFoundException(message); 157 } 158 return (T)returnValue; 159 } 160 161 167 public Query createQuery(String ejbqlString){ 168 169 verifyOpen(); 170 171 EJBQueryImpl ejbqImpl; 172 173 try 174 { 175 ejbqImpl = new EJBQueryImpl(ejbqlString, this); 176 } 177 178 catch(EJBQLException ex) 179 { 180 throw new IllegalArgumentException (ExceptionLocalization.buildMessage("wrap_ejbql_exception"), ex); 181 } 182 183 return ejbqImpl; 184 } 185 191 public Query createNamedQuery(String name){ 192 verifyOpen(); 193 return new EJBQueryImpl(name, this, true); 194 } 195 201 public Query createNativeQuery(String sqlString){ 202 verifyOpen(); 203 return new EJBQueryImpl( EJBQueryImpl.buildSQLDatabaseQuery( sqlString, false), this ); 204 } 205 206 210 public javax.persistence.Query createNativeQuery(String sqlString, Class resultType){ 211 DatabaseQuery query = createNativeQueryInternal(sqlString, resultType); 212 return new EJBQueryImpl(query, this); 213 } 214 215 223 public Query createNativeQuery(String sqlString, String resultSetMapping){ 224 verifyOpen(); 225 ResultSetMappingQuery query = new ResultSetMappingQuery(); 226 query.setSQLResultSetMappingName(resultSetMapping); 227 query.setSQLString(sqlString); 228 query.setIsUserDefined(true); 229 return new EJBQueryImpl(query, this); 230 } 231 232 237 public FlushModeType getFlushMode() { 238 return flushMode; 239 } 240 241 246 public void setFlushMode(FlushModeType flushMode) { 247 this.flushMode = flushMode; 248 } 249 250 253 public javax.persistence.Query createQuery(Expression expression, Class resultType){ 254 DatabaseQuery query = createQueryInternal(expression, resultType); 255 return new EJBQueryImpl(query, this); 256 } 257 258 266 public javax.persistence.EntityTransaction getTransaction(){ 267 return ((TransactionWrapper)transaction).getTransaction(); 268 } 269 270 274 public boolean isFlushModeAUTO() { 275 return flushMode == FlushModeType.AUTO; 276 } 277 278 protected void setJTATransactionWrapper() { 279 transaction = new JTATransactionWrapper(this); 280 } 281 282 protected void setEntityTransactionWrapper() { 283 transaction = new EntityTransactionWrapper(this); 284 } 285 } 286 | Popular Tags |