protected Object getKey(EnterpriseContext ctx) { return ((EntityEnterpriseContext)ctx).getCacheKey(); }
public void insert(EnterpriseContext instance) { if(instance == null) throw new IllegalArgumentException("Can't insert a null object in the cache"); EntityEnterpriseContext entity = (EntityEnterpriseContext) instance; getLocalCache().put(entity.getCacheKey(), instance); }
/** * associate entity with transaction */ public void associate(Transaction tx, EntityEnterpriseContext entity) throws RollbackException, SystemException { HashMap entityMap = (HashMap) m_map.get(tx); if(entityMap == null) { entityMap = new HashMap(); m_map.set(tx, entityMap); } //EntityContainer.getGlobalTxEntityMap().associate(tx, entity); entityMap.put(entity.getCacheKey(), entity); }
/** * Create a new instance synchronization instance. */ InstanceSynchronization(Transaction tx, EntityEnterpriseContext ctx) { this.tx = tx; this.ctx = ctx; this.lock = container.getLockManager().getLock(ctx.getCacheKey()); }
protected boolean canPassivate(EnterpriseContext ctx) { if (ctx.isLocked()) { // The context is in the interceptor chain return false; } if (ctx.getTransaction() != null) { return false; } Object key = ((EntityEnterpriseContext)ctx).getCacheKey(); return m_container.getLockManager().canPassivate(key); }
protected boolean canPassivate(EnterpriseContext ctx) { if(ctx.isLocked()) { // The context is in the interceptor chain return false; } if(ctx.getTransaction() != null) { return false; } Object key = ((EntityEnterpriseContext) ctx).getCacheKey(); return container.getLockManager().canPassivate(key); }
private Object findSingleObject(Transaction tx, Method method, Object[] args, EntityEnterpriseContext instance, GenericEntityObjectFactory factory) throws Exception { if(method.getName().equals("findByPrimaryKey")) { if(args[0] == null) throw new IllegalArgumentException("findByPrimaryKey called with null argument."); if(metaData.getContainerConfiguration().getCommitOption() != ConfigurationMetaData.B_COMMIT_OPTION) { Object key = instance.getCacheKey(); if(key == null) { key = ((EntityCache)instanceCache).createCacheKey(args[0]); } if(instanceCache.isActive(key)) { return factory.getEntityEJBObject(key); } } } else if(!metaData.getContainerConfiguration().getSyncOnCommitOnly()) { EntityContainer.synchronizeEntitiesWithinTransaction(tx); } return getPersistenceManager().findEntity(method, args, instance, factory); }
container.getInstanceCache().remove(ctx.getCacheKey());
BeanLock lock = container.getLockManager().getLock(ctx.getCacheKey()); cache.remove(ctx.getCacheKey()); container.getLockManager().removeLockRef(ctx.getCacheKey());
public Object invokeHome(Invocation mi) throws Exception { EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext(); Transaction tx = mi.getTransaction(); Object rtn = getNext().invokeHome(mi); // An anonymous context was sent in, so if it has an id it is a real instance now if(ctx.getId() != null) { // it doesn't need to be read, but it might have been changed from the db already. ctx.setValid(true); if(tx != null) { BeanLock lock = container.getLockManager().getLock(ctx.getCacheKey()); try { lock.schedule(mi); register(ctx, tx); // Set tx lock.endInvocation(mi); } finally { container.getLockManager().removeLockRef(lock.getId()); } } } return rtn; }