1 29 30 package com.caucho.amber.manager; 31 32 import com.caucho.util.L10N; 33 34 import javax.persistence.EntityManager; 35 import javax.persistence.EntityTransaction; 36 import javax.persistence.FlushModeType; 37 import javax.persistence.LockModeType; 38 import javax.persistence.Query; 39 import java.util.logging.Logger ; 40 41 44 public class EntityManagerProxy implements EntityManager { 45 private static final L10N L = new L10N(EntityManagerProxy.class); 46 private static final Logger log 47 = Logger.getLogger(EntityManagerProxy.class.getName()); 48 49 private AmberPersistenceUnit _persistenceUnit; 50 51 public EntityManagerProxy(AmberPersistenceUnit persistenceUnit) 52 { 53 _persistenceUnit = persistenceUnit; 54 } 55 56 59 public void persist(Object entity) 60 { 61 getCurrent().persist(entity); 62 } 63 64 67 public <T> T merge(T entity) 68 { 69 return getCurrent().merge(entity); 70 } 71 72 75 public void remove(Object entity) 76 { 77 getCurrent().remove(entity); 78 } 79 80 83 89 90 93 public <T> T find(Class <T> entityClass, Object primaryKey) 94 { 95 return getCurrent().find(entityClass, primaryKey); 96 } 97 98 101 public <T> T getReference(Class <T> entityClass, Object primaryKey) 102 { 103 return getCurrent().getReference(entityClass, primaryKey); 104 } 105 106 109 public FlushModeType getFlushMode() 110 { 111 return getCurrent().getFlushMode(); 112 } 113 114 117 public void setFlushMode(FlushModeType mode) 118 { 119 getCurrent().setFlushMode(mode); 120 } 121 122 125 public void lock(Object entity, LockModeType lockMode) 126 { 127 getCurrent().lock(entity, lockMode); 128 } 129 130 133 public void clear() 134 { 135 getCurrent().clear(); 136 } 137 138 141 public void flush() 142 { 143 getCurrent().flush(); 144 } 145 146 149 public void joinTransaction() 150 { 151 throw new UnsupportedOperationException (); 152 } 153 154 157 public Object getDelegate() 158 { 159 throw new UnsupportedOperationException (); 160 } 161 162 165 public void close() 166 { 167 throw new IllegalStateException (L.l("Container-manager persistence context may not be closed.")); 168 } 169 170 173 public Query createQuery(String sql) 174 { 175 return getCurrent().createQuery(sql); 176 } 177 178 181 public Query createNamedQuery(String sql) 182 { 183 return getCurrent().createNamedQuery(sql); 184 } 185 186 189 public Query createNativeQuery(String sql) 190 { 191 return getCurrent().createNativeQuery(sql); 192 } 193 194 197 public Query createNativeQuery(String sql, String map) 198 { 199 return getCurrent().createNativeQuery(sql, map); 200 } 201 202 205 public Query createNativeQuery(String sql, Class retType) 206 { 207 return getCurrent().createNativeQuery(sql, retType); 208 } 209 210 213 public void refresh(Object entity) 214 { 215 getCurrent().refresh(entity); 216 } 217 218 221 public boolean contains(Object entity) 222 { 223 return getCurrent().contains(entity); 224 } 225 226 229 public EntityTransaction getTransaction() 230 { 231 return getCurrent().getTransaction(); 232 } 233 234 237 public boolean isOpen() 238 { 239 return true; 240 } 241 242 245 private AmberConnection getCurrent() 246 { 247 return _persistenceUnit.getThreadConnection(); 248 } 249 250 public String toString() 251 { 252 AmberConnection aConn = getCurrent(); 253 254 if (aConn != null) 255 return "EntityManagerProxy[" + aConn.getPersistenceUnit().getName() + "]"; 256 else 257 return "EntityManagerProxy[closed]"; 258 } 259 } 260 | Popular Tags |