1 25 26 package org.objectweb.easybeans.persistence; 27 28 import javax.persistence.EntityManager; 29 import javax.persistence.EntityNotFoundException; 30 import javax.persistence.EntityTransaction; 31 import javax.persistence.FlushModeType; 32 import javax.persistence.LockModeType; 33 import javax.persistence.PersistenceException; 34 import javax.persistence.Query; 35 import javax.persistence.TransactionRequiredException; 36 37 44 public class TxEntityManager implements EntityManager { 45 46 49 private TxEntityManagerHandler handler; 50 51 55 public TxEntityManager(final TxEntityManagerHandler handler) { 56 this.handler = handler; 57 } 58 59 63 public EntityManager getCurrentEntityManager() { 64 return handler.getCurrent(); 65 } 66 67 74 public void persist(final Object entity) throws IllegalArgumentException , TransactionRequiredException { 75 getCurrentEntityManager().persist(entity); 76 } 77 78 88 public <T> T merge(final T entity) throws IllegalArgumentException , TransactionRequiredException { 89 return getCurrentEntityManager().merge(entity); 90 } 91 92 99 public void remove(final Object entity) throws IllegalArgumentException , TransactionRequiredException { 100 getCurrentEntityManager().remove(entity); 101 } 102 103 113 public <T> T find(final Class <T> entityClass, final Object primaryKey) throws IllegalArgumentException { 114 return getCurrentEntityManager().find(entityClass, primaryKey); 115 } 116 117 134 public <T> T getReference(final Class <T> entityClass, final Object primaryKey) throws IllegalArgumentException , 135 EntityNotFoundException { 136 return getCurrentEntityManager().getReference(entityClass, primaryKey); 137 } 138 139 144 public void flush() throws TransactionRequiredException, PersistenceException { 145 getCurrentEntityManager().flush(); 146 } 147 148 153 public void setFlushMode(final FlushModeType flushMode) { 154 getCurrentEntityManager().setFlushMode(flushMode); 155 156 } 157 158 163 public FlushModeType getFlushMode() { 164 return getCurrentEntityManager().getFlushMode(); 165 } 166 167 177 public void lock(final Object entity, final LockModeType lockMode) throws PersistenceException, 178 IllegalArgumentException , TransactionRequiredException { 179 getCurrentEntityManager().lock(entity, lockMode); 180 } 181 182 193 public void refresh(final Object entity) throws IllegalArgumentException , TransactionRequiredException, 194 EntityNotFoundException { 195 getCurrentEntityManager().refresh(entity); 196 } 197 198 203 public void clear() { 204 getCurrentEntityManager().clear(); 205 } 206 207 213 public boolean contains(final Object entity) throws IllegalArgumentException { 214 return getCurrentEntityManager().contains(entity); 215 } 216 217 223 public Query createQuery(final String ejbqlString) throws IllegalArgumentException { 224 return getCurrentEntityManager().createQuery(ejbqlString); 225 } 226 227 235 public Query createNamedQuery(final String name) throws IllegalArgumentException { 236 return getCurrentEntityManager().createNamedQuery(name); 237 } 238 239 245 public Query createNativeQuery(final String sqlString) { 246 return getCurrentEntityManager().createNativeQuery(sqlString); 247 } 248 249 255 public Query createNativeQuery(final String sqlString, final Class resultClass) { 256 return getCurrentEntityManager().createNativeQuery(sqlString, resultClass); 257 } 258 259 265 public Query createNativeQuery(final String sqlString, final String resultSetMapping) { 266 return getCurrentEntityManager().createNativeQuery(sqlString, resultSetMapping); 267 } 268 269 272 public void joinTransaction() { 273 getCurrentEntityManager().joinTransaction(); 274 } 275 276 279 public Object getDelegate() { 280 return getCurrentEntityManager().getDelegate(); 281 } 282 283 292 public void close() throws IllegalStateException { 293 getCurrentEntityManager().close(); 294 } 295 296 300 public boolean isOpen() { 301 return getCurrentEntityManager().isOpen(); 302 } 303 304 311 public EntityTransaction getTransaction() throws IllegalStateException { 312 return getCurrentEntityManager().getTransaction(); 313 } 314 315 } 316 | Popular Tags |