public boolean contains(BeanIdentifier id) { return get(id) != null; }
/** * Gets an enumeration of the attribute names present in the underlying * storage * * @return The attribute names */ protected Collection<String> getPrefixedAttributeNames() { return getNamingScheme().filterIds(getAttributeNames()); }
public LockedBean lock(final BeanIdentifier id) { LockStore lockStore = getLockStore(); if(lockStore == null) { //if the lockstore is null then no locking is necessary, as the underlying //context is single threaded return null; } return lockStore.lock(id); }
public Iterator<BeanIdentifier> iterator() { Iterator<BeanIdentifier> iterator; if (isAttributeLazyFetchingEnabled()) { // Merge the bean identifiers from the local bean store and the backing store Set<BeanIdentifier> identifiers = new HashSet<>(); for (BeanIdentifier id : beanStore) { identifiers.add(id); } for (String prefixedId : getPrefixedAttributeNames()) { identifiers.add(getNamingScheme().deprefix(prefixedId)); } iterator = identifiers.iterator(); } else { iterator = beanStore.iterator(); } return iterator; }
public void clear() { Iterator<BeanIdentifier> it = iterator(); while (it.hasNext()) { BeanIdentifier id = it.next(); if (isAttached()) { String prefixedId = namingScheme.prefix(id); removeAttribute(prefixedId); } it.remove(); ContextLogger.LOG.contextualInstanceRemoved(id, this); } ContextLogger.LOG.contextCleared(this); }
if (!attached) { attached = true; if (isLocalBeanStoreSyncNeeded()) { if (!beanStore.delegate().isEmpty()) { String prefixedId = getNamingScheme().prefix(id); ContextLogger.LOG.updatingStoreWithContextualUnderId(instance, id); setAttribute(prefixedId, instance); if (!isAttributeLazyFetchingEnabled()) { fetchUninitializedAttributes();
/** * Fetch all relevant attributes from the backing store and copy instances which are not present in the local bean store. */ public void fetchUninitializedAttributes() { for (String prefixedId : getPrefixedAttributeNames()) { BeanIdentifier id = getNamingScheme().deprefix(prefixedId); if (!beanStore.contains(id)) { ContextualInstance<?> instance = (ContextualInstance<?>) getAttribute(prefixedId); beanStore.put(id, instance); ContextLogger.LOG.addingDetachedContextualUnderId(instance, id); } } }
@Override public <T> ContextualInstance<T> get(BeanIdentifier id) { ContextualInstance<T> instance = beanStore.get(id); if(instance == null && isAttached() && isAttributeLazyFetchingEnabled()) { instance = cast(getAttribute(namingScheme.prefix(id))); if(instance != null) { beanStore.put(id, instance); } } ContextLogger.LOG.contextualInstanceFound(id, instance, this); return instance; }
@Override public <T> ContextualInstance<T> remove(BeanIdentifier id) { ContextualInstance<T> instance = beanStore.remove(id); if (instance != null) { if (isAttached()) { removeAttribute(namingScheme.prefix(id)); } ContextLogger.LOG.contextualInstanceRemoved(id, this); } return instance; }
@Override public <T> void put(BeanIdentifier id, ContextualInstance<T> instance) { beanStore.put(id, instance); // moved due to WELD-892 if (isAttached()) { setAttribute(namingScheme.prefix(id), instance); } ContextLogger.LOG.contextualInstanceAdded(instance.getContextual(), id, this); }
public boolean destroy(HttpSession session) { final BoundBeanStore beanStore = getBeanStore(); if (beanStore == null) { try { HttpConversationContext conversationContext = getConversationContext(); setBeanStore(new EagerSessionBeanStore(namingScheme, session, getServiceRegistry())); activate(); invalidate(); conversationContext.destroy(session); deactivate(); setBeanStore(null); return true; } finally { cleanup(); } } else { // We are in a request, invalidate it invalidate(); if (beanStore instanceof AttributeBeanStore) { AttributeBeanStore attributeBeanStore = ((AttributeBeanStore) beanStore); if (attributeBeanStore.isAttributeLazyFetchingEnabled()) { // At this moment we have to sync the local bean store and the backing store attributeBeanStore.fetchUninitializedAttributes(); } } getConversationContext().destroy(session); return false; } }
@Override public <T> ContextualInstance<T> get(BeanIdentifier id) { ContextualInstance<T> instance = super.get(id); if (instance == null && isAttached()) { String prefixedId = getNamingScheme().prefix(id); instance = cast(getAttribute(prefixedId)); } if (resetHttpSessionAttributeOnBeanAccess && instance != null){ put(id, instance); } return instance; }