1 28 29 package com.caucho.ejb.entity; 30 31 import com.caucho.amber.entity.EntityItem; 32 import com.caucho.ejb.AbstractContext; 33 import com.caucho.ejb.AbstractServer; 34 import com.caucho.ejb.xa.EjbTransactionManager; 35 36 import javax.ejb.EJBObject ; 37 import javax.ejb.EntityContext ; 38 import javax.ejb.FinderException ; 39 import javax.ejb.Handle ; 40 import javax.ejb.HomeHandle ; 41 import javax.ejb.RemoveException ; 42 import javax.transaction.UserTransaction ; 43 import java.util.logging.Level ; 44 45 48 public abstract class QEntityContext extends AbstractContext 49 implements EntityContext { 50 protected final EntityServer _server; 51 public Object _primaryKey; 52 53 private Object _remoteView; 54 private EJBObject _remote; 55 56 protected QEntityContext(EntityServer server) 57 { 58 _server = server; 59 } 60 61 64 public AbstractServer getServer() 65 { 66 return _server; 67 } 68 69 72 public EntityServer getEntityServer() 73 { 74 return _server; 75 } 76 77 80 public EjbTransactionManager getTransactionManager() 81 { 82 return getEntityServer().getTransactionManager(); 83 } 84 85 88 public HomeHandle getHomeHandle() 89 { 90 return getServer().getHomeHandle(); 91 } 92 93 public void setPrimaryKey(Object key) 94 { 95 _primaryKey = key; 96 } 97 98 101 public Object getPrimaryKey() 102 throws IllegalStateException 103 { 104 if (_primaryKey == null) { 105 throw new IllegalStateException ("Can't get primary key. The context may belong to a home instance or it may be called before ejbActivate or ejbCreate."); 106 } 107 else 108 return _primaryKey; 109 } 110 111 114 public Object _caucho_getPrimaryKey() 115 { 116 return _primaryKey; 117 } 118 119 123 public UserTransaction getUserTransaction() 124 throws IllegalStateException 125 { 126 throw new IllegalStateException ("Entity beans may not call getUserTransaction()"); 127 } 128 129 132 public Handle getHandle() 133 { 134 return getEntityServer().createHandle(_primaryKey); 135 } 136 137 140 public EJBObject getEJBObject() 141 throws IllegalStateException 142 { 143 149 return getRemoteView(); 150 } 151 152 155 public void postCreate(Object primaryKey) 156 { 157 _primaryKey = primaryKey; 158 159 getEntityServer().postCreate(primaryKey, this); 160 } 161 162 165 public void remove(Handle handle) 166 { 167 getServer().remove(handle); 168 } 169 170 173 public void remove(Object primaryKey) 174 { 175 getServer().remove(primaryKey); 176 } 177 178 public void _caucho_remove_callback(Class listenClass, Object primaryKey) 179 throws RemoveException 180 { 181 } 182 183 186 public void invalidateHomeCache() 187 { 188 getServer().invalidateCache(); 189 } 190 191 194 public void update() 195 { 196 } 197 198 201 protected void __caucho_setAmber(EntityItem item) 202 { 203 } 204 205 public abstract void _caucho_load() throws FinderException ; 206 207 210 public void removeEvent() 211 { 212 try { 213 destroy(); 214 } catch (Exception e) { 215 log.log(Level.WARNING, e.toString(), e); 216 } 217 } 218 219 222 public void destroy() throws Exception 223 { 224 super.destroy(); 225 226 _remote = null; 227 _remoteView = null; 228 } 229 } 230 | Popular Tags |