1 45 46 47 package org.openejb.core.entity; 48 49 import java.lang.reflect.Method ; 50 51 import org.openejb.Container; 52 import org.openejb.RpcContainer; 53 import org.openejb.core.ivm.EjbObjectProxyHandler; 54 import org.openejb.util.proxy.ProxyManager; 55 56 65 public class EntityEjbObjectHandler extends EjbObjectProxyHandler { 66 67 private final static class RegistryEntry{ 68 final Object primaryKey; 69 final Object deploymentId; 70 final Object containerId; 71 72 RegistryEntry(Object primaryKey, Object deploymentId, Object containerId) { 73 if(primaryKey==null || deploymentId==null || containerId==null) { 74 throw new IllegalArgumentException (); 75 } 76 this.primaryKey=primaryKey; 77 this.deploymentId=deploymentId; 78 this.containerId=containerId; 79 } 80 81 public boolean equals(Object other) { 82 if(other==this) { 83 return true; 84 } 85 if(other instanceof RegistryEntry) { 86 RegistryEntry otherEntry = (RegistryEntry) other; 87 return primaryKey.equals(otherEntry.primaryKey) && 88 deploymentId.equals(otherEntry.deploymentId) && 89 containerId.equals(otherEntry.containerId); 90 } 91 return false; 92 } 93 94 public int hashCode() { 95 return primaryKey.hashCode(); 96 } 97 } 98 107 private Object registryId; 108 109 public EntityEjbObjectHandler(RpcContainer container, Object pk, Object depID){ 110 super(container, pk, depID); 111 } 112 113 120 public static Object getRegistryId(Object primKey, Object deployId, Container contnr){ 121 return new RegistryEntry(primKey, deployId, contnr.getContainerID()); 122 } 123 124 135 public Object getRegistryId(){ 136 if(registryId== null) 137 registryId= getRegistryId(primaryKey, deploymentID, container); 138 return registryId; 139 } 140 141 142 protected Object getPrimaryKey(Method method, Object [] args, Object proxy) throws Throwable { 143 return primaryKey; 144 } 145 146 156 protected Object isIdentical(Method method, Object [] args, Object proxy) throws Throwable { 157 checkAuthorization(method); 158 159 Object hndr = ProxyManager.getInvocationHandler(proxy); 160 161 if(hndr instanceof EntityEjbObjectHandler){ 162 163 EntityEjbObjectHandler handler = (EntityEjbObjectHandler)hndr; 164 165 170 if(this.getRegistryId().equals(handler.getRegistryId())){ 171 return Boolean.TRUE; 172 } 173 } 174 return Boolean.FALSE; 175 176 } 177 178 protected Object remove(Method method, Object [] args, Object proxy) throws Throwable { 179 checkAuthorization(method); 180 Object value = container.invoke(deploymentID, method, args, primaryKey, getThreadSpecificSecurityIdentity()); 181 185 invalidateAllHandlers(getRegistryId()); 186 return value; 187 } 188 189 } 190 | Popular Tags |