1 22 package org.jboss.ejb.plugins; 23 24 import org.jboss.ejb.EntityContainer; 25 import org.jboss.ejb.EntityPersistenceManager; 26 import org.jboss.ejb.EntityEnterpriseContext; 27 import org.jboss.ejb.InstancePool; 28 import org.jboss.ejb.AllowedOperationsAssociation; 29 import org.jboss.invocation.Invocation; 30 import org.jboss.invocation.InvocationType; 31 32 import javax.ejb.EJBException ; 33 import javax.ejb.TimedObject ; 34 import javax.ejb.Timer ; 35 import java.lang.reflect.Method ; 36 import java.rmi.RemoteException ; 37 38 56 public class EntityMultiInstanceInterceptor 57 extends AbstractInterceptor 58 { 59 61 63 65 66 protected static final Method ejbTimeout; 67 static 68 { 69 try 70 { 71 ejbTimeout = TimedObject .class.getMethod("ejbTimeout", new Class []{Timer .class}); 72 } 73 catch (Exception e) 74 { 75 throw new ExceptionInInitializerError (e); 76 } 77 } 78 79 81 83 85 public Object invokeHome(Invocation mi) 86 throws Exception 87 { 88 EntityContainer ec = (EntityContainer) getContainer(); 90 EntityEnterpriseContext ctx = (EntityEnterpriseContext) ec.getInstancePool().get(); 91 92 mi.setEnterpriseContext(ctx); 94 95 ctx.setTransaction(mi.getTransaction()); 97 98 ctx.setPrincipal(mi.getPrincipal()); 100 101 AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_HOME); 102 103 Object result; 104 try 105 { 106 result = getNext().invokeHome(mi); 108 } 109 finally 110 { 111 AllowedOperationsAssociation.popInMethodFlag(); 112 } 113 114 if (ctx.getId() == null) 116 { 117 ctx.setTransaction(null); 118 ec.getInstancePool().free(ctx); 119 } 120 121 return result; 123 } 124 125 public Object invoke(Invocation mi) 126 throws Exception 127 { 128 129 Object key = mi.getId(); 131 132 EntityEnterpriseContext ctx = null; 133 EntityContainer ec = (EntityContainer) container; 134 if (mi.getTransaction() != null) 135 { 136 } 138 if (ctx == null) 139 { 140 InstancePool pool = ec.getInstancePool(); 141 try 142 { 143 ctx = (EntityEnterpriseContext) pool.get(); 144 } 145 catch (EJBException e) 146 { 147 throw e; 148 } 149 catch (RemoteException e) 150 { 151 throw e; 152 } 153 catch (Exception e) 154 { 155 InvocationType type = mi.getType(); 156 boolean isLocal = (type == InvocationType.LOCAL || type == InvocationType.LOCALHOME); 157 if (isLocal) 158 throw new EJBException ("Unable to get an instance from the pool", e); 159 else 160 throw new RemoteException ("Unable to get an intance from the pool", e); 161 } 162 ctx.setCacheKey(key); 163 ctx.setId(key); 164 EntityPersistenceManager pm = ec.getPersistenceManager(); 165 pm.activateEntity(ctx); 166 } 167 168 boolean trace = log.isTraceEnabled(); 169 if( trace ) log.trace("Begin invoke, key="+key); 170 171 ctx.setTransaction(mi.getTransaction()); 174 175 ctx.setPrincipal(mi.getPrincipal()); 177 EnterpriseBeanPolicyContextHandler.setEnterpriseBean(ctx.getInstance()); 179 180 mi.setEnterpriseContext(ctx); 182 183 if (ejbTimeout.equals(mi.getMethod())) 184 AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_TIMEOUT); 185 else 186 AllowedOperationsAssociation.pushInMethodFlag(IN_BUSINESS_METHOD); 187 188 try 189 { 190 Object ret = getNext().invoke(mi); 191 return ret; 192 } 193 finally 194 { 195 AllowedOperationsAssociation.popInMethodFlag(); 196 } 197 } 198 } 199 | Popular Tags |