1 28 29 package com.caucho.ejb.entity; 30 31 import com.caucho.ejb.AbstractEJBObject; 32 import com.caucho.ejb.AbstractServer; 33 import com.caucho.ejb.xa.TransactionContext; 34 import com.caucho.util.Log; 35 36 import javax.ejb.EJBHome ; 37 import javax.ejb.EJBLocalHome ; 38 import javax.ejb.EJBLocalObject ; 39 import javax.ejb.EJBObject ; 40 import javax.ejb.Handle ; 41 import java.io.Serializable ; 42 import java.rmi.RemoteException ; 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 46 49 abstract public class EntityObject extends AbstractEJBObject 50 implements Serializable , EJBLocalObject 51 { 52 protected static final Logger log = Log.open(EntityObject.class); 53 54 public static final byte _CAUCHO_IS_DEAD = QEntity._CAUCHO_IS_DEAD; 55 public static final byte _CAUCHO_IS_ACTIVE = QEntity._CAUCHO_IS_ACTIVE; 56 public static final byte _CAUCHO_IS_LOADED = QEntity._CAUCHO_IS_LOADED; 57 public static final byte _CAUCHO_IS_DIRTY = QEntity._CAUCHO_IS_DIRTY; 58 59 protected abstract QEntityContext getEntityContext(); 60 61 64 public Object getPrimaryKey() 65 { 66 return getEntityContext().getPrimaryKey(); 67 } 68 69 public Object getEJBObject() 70 { 71 return getEntityContext().getEJBObject(); 72 } 73 74 public Object getEJBLocalObject() 75 { 76 return getEntityContext().getEJBLocalObject(); 77 } 78 79 82 public EntityServer _caucho_getEntityServer() 83 { 84 return getEntityContext().getEntityServer(); 85 } 86 87 90 public boolean isMatch(EntityServer server, Object key) 91 { 92 return server == _caucho_getEntityServer() && key.equals(getPrimaryKey()); 93 } 94 95 98 public Handle getHandle() 99 { 100 return getEntityContext().getHandle(); 101 } 102 103 106 public Object _caucho_getBean(TransactionContext trans, boolean doLoad) 107 { 108 throw new UnsupportedOperationException (); 109 } 110 111 114 public Object _caucho_getBean() 115 { 116 throw new UnsupportedOperationException (); 117 } 118 119 122 public EJBHome getEJBHome() 123 { 124 try { 125 return _caucho_getEntityServer().getEJBHome(); 126 } catch (Exception e) { 127 return null; 128 } 129 } 130 131 134 public EJBLocalHome getEJBLocalHome() 135 { 136 try { 137 return (EJBLocalHome ) _caucho_getEntityServer().getEJBLocalHome(); 138 } catch (Exception e) { 139 return null; 140 } 141 } 142 143 146 public boolean isIdentical(EJBObject obj) throws RemoteException 147 { 148 return getHandle().equals(obj.getHandle()); 149 } 150 151 154 public boolean isIdentical(EJBLocalObject o) 155 { 156 if (o == null || ! getClass().equals(o.getClass())) 157 return false; 158 159 EntityObject obj = (EntityObject) o; 160 161 try { 162 Object key = getPrimaryKey(); 163 Object objKey = obj.getPrimaryKey(); 164 165 if (key != null) 166 return key.equals(objKey); 167 else 168 return objKey == null; 169 } catch (Exception e) { 170 return false; 171 } 172 } 173 174 177 183 184 187 public AbstractServer __caucho_getServer() 188 { 189 return _caucho_getEntityServer(); 190 } 191 192 195 public String __caucho_getId() 196 { 197 return _caucho_getEntityServer().encodeId(getPrimaryKey()); 198 } 199 200 203 public int hashCode() 204 { 205 try { 206 Object key = getPrimaryKey(); 207 208 if (key != null) 209 return key.hashCode(); 210 else 211 return 0; 212 } catch (Throwable e) { 213 return 0; 214 } 215 } 216 217 220 221 public boolean equals(Object o) 222 { 223 if (this == o) 224 return true; 225 226 if (o == null || ! getClass().equals(o.getClass())) 227 return false; 228 229 EntityObject obj = (EntityObject) o; 230 231 try { 232 Object key = getPrimaryKey(); 233 Object objKey = obj.getPrimaryKey(); 234 235 if (key != null) 236 return key.equals(objKey); 237 else 238 return objKey == null; 239 } catch (Throwable e) { 240 log.log(Level.WARNING, e.toString(), e); 241 242 return false; 243 } 244 } 245 246 249 public String toString() 250 { 251 Object key = ""; 252 try { 253 key = getPrimaryKey(); 254 } catch (Throwable e) { 255 } 256 257 return getClass().getName() + "[" + key + "]"; 258 } 259 } 260 | Popular Tags |