1 22 package org.jboss.ejb.plugins; 23 24 import java.rmi.RemoteException ; 25 import java.rmi.NoSuchObjectException ; 26 27 import org.jboss.ejb.Container; 28 import org.jboss.ejb.EntityContainer; 29 import org.jboss.ejb.EnterpriseContext; 30 import org.jboss.ejb.EntityEnterpriseContext; 31 import org.jboss.ejb.GlobalTxEntityMap; 32 import org.jboss.metadata.EntityMetaData; 33 import org.jboss.metadata.ConfigurationMetaData; 34 import org.jboss.util.propertyeditor.PropertyEditors; 35 36 44 public class EntityInstanceCache 45 extends AbstractInstanceCache 46 implements org.jboss.ejb.EntityCache, EntityInstanceCacheMBean 47 { 48 50 52 private EntityContainer m_container; 53 54 56 58 60 61 public void setContainer(Container c) 62 { 63 m_container = (EntityContainer)c; 64 } 65 66 public Object createCacheKey(Object id) 68 { 69 return id; 70 } 71 72 public EnterpriseContext get(Object id) 74 throws RemoteException , NoSuchObjectException 75 { 76 EnterpriseContext rtn = null; 77 rtn = super.get(id); 78 return rtn; 79 } 80 81 84 public void remove(String id) 85 throws Exception 86 { 87 EntityMetaData metaData = (EntityMetaData) m_container.getBeanMetaData(); 88 String primKeyClass = metaData.getPrimaryKeyClass(); 89 Object key = PropertyEditors.convertValue(id, primKeyClass); 90 remove(key); 91 } 92 93 public void destroy() 94 { 95 synchronized( this ) 96 { 97 this.m_container = null; 98 } 99 super.destroy(); 100 } 101 102 protected Object getKey(EnterpriseContext ctx) 103 { 104 return ((EntityEnterpriseContext)ctx).getCacheKey(); 105 } 106 107 protected void setKey(Object id, EnterpriseContext ctx) 108 { 109 ((EntityEnterpriseContext)ctx).setCacheKey(id); 110 ctx.setId(id); 111 } 112 113 protected synchronized Container getContainer() 114 { 115 return m_container; 116 } 117 118 protected void passivate(EnterpriseContext ctx) throws RemoteException 119 { 120 m_container.getPersistenceManager().passivateEntity((EntityEnterpriseContext)ctx); 121 } 122 123 protected void activate(EnterpriseContext ctx) throws RemoteException 124 { 125 m_container.getPersistenceManager().activateEntity((EntityEnterpriseContext)ctx); 126 } 127 128 protected EnterpriseContext acquireContext() throws Exception 129 { 130 return m_container.getInstancePool().get(); 131 } 132 133 protected void freeContext(EnterpriseContext ctx) 134 { 135 m_container.getInstancePool().free(ctx); 136 } 137 138 protected boolean canPassivate(EnterpriseContext ctx) 139 { 140 if (ctx.isLocked()) 141 { 142 return false; 144 } 145 146 if (ctx.getTransaction() != null) 147 { 148 return false; 149 } 150 151 Object key = ((EntityEnterpriseContext)ctx).getCacheKey(); 152 return m_container.getLockManager().canPassivate(key); 153 } 154 155 157 159 protected void unableToPassivateDueToCtxLock(EnterpriseContext ctx, boolean passivateAfterCommit) 160 { 161 EntityEnterpriseContext ectx = (EntityEnterpriseContext)ctx; 162 ectx.setPassivateAfterCommit(passivateAfterCommit); 163 ConfigurationMetaData config = m_container.getBeanMetaData().getContainerConfiguration(); 164 if(!config.isStoreNotFlushed() && ectx.hasTxSynchronization()) 165 { 166 ectx.setTxAssociation(GlobalTxEntityMap.PREVENT_SYNC); 167 } 168 } 169 170 172 } 174 | Popular Tags |