Class AttributeBeanStore
- java.lang.Object
-
- org.jboss.weld.contexts.beanstore.AttributeBeanStore
-
- All Implemented Interfaces:
Iterable<org.jboss.weld.serialization.spi.BeanIdentifier>,BeanStore,BoundBeanStore
- Direct Known Subclasses:
MapBeanStore
public abstract class AttributeBeanStore extends Object implements BoundBeanStore
A bound bean store backed by attributes. This bean store is "write-through" - if attached it will write any modifications to the backing store immediately. If detached modifications will not be written through. If the bean store is reattached, then any local modifications will be written to the underlying store.
This construct is not thread safe.
- Author:
- Pete Muir, Nicklas Karlsson, David Allen
-
-
Constructor Summary
Constructors Constructor Description AttributeBeanStore(NamingScheme namingScheme, boolean attributeLazyFetchingEnabled)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanattach()Attach the bean store, any updates from now on will be written through to the underlying store.voidclear()Clears the store of contextual instancesbooleancontains(org.jboss.weld.serialization.spi.BeanIdentifier id)Check if the store contains an instancebooleandetach()Detach the bean store, causing updates to longer be written through to the underlying store.voidfetchUninitializedAttributes()Fetch all relevant attributes from the backing store and copy instances which are not present in the local bean store.<T> ContextualInstance<T>get(org.jboss.weld.serialization.spi.BeanIdentifier id)Gets an instance of a contextual from the storeprotected abstract ObjectgetAttribute(String prefixedId)Gets an attribute from the underlying storageprotected abstract Iterator<String>getAttributeNames()Gets an enumeration of the attribute names present in the underlying storage.protected abstract LockStoregetLockStore()protected NamingSchemegetNamingScheme()protected Collection<String>getPrefixedAttributeNames()Gets an enumeration of the attribute names present in the underlying storagebooleanisAttached()Return true if the bean store is attachedbooleanisAttributeLazyFetchingEnabled()protected booleanisLocalBeanStoreSyncNeeded()Iterator<org.jboss.weld.serialization.spi.BeanIdentifier>iterator()LockedBeanlock(org.jboss.weld.serialization.spi.BeanIdentifier id)Gets a creation lock for the given bean id.<T> voidput(org.jboss.weld.serialization.spi.BeanIdentifier id, ContextualInstance<T> instance)Adds a bean instance to the storage<T> ContextualInstance<T>remove(org.jboss.weld.serialization.spi.BeanIdentifier id)Removes a bean instance identified by the given id.protected abstract voidremoveAttribute(String prefixedId)Removes an attribute from the underlying storageprotected abstract voidsetAttribute(String prefixedId, Object instance)Sets an instance under a key in the underlying storage-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
AttributeBeanStore
public AttributeBeanStore(NamingScheme namingScheme, boolean attributeLazyFetchingEnabled)
- Parameters:
namingScheme-attributeLazyFetchingEnabled-
-
-
Method Detail
-
detach
public boolean detach()
Detach the bean store, causing updates to longer be written through to the underlying store.- Specified by:
detachin interfaceBoundBeanStore- Returns:
- true if the bean store was detached, or false if the bean store is already detached
-
attach
public boolean attach()
Attach the bean store, any updates from now on will be written through to the underlying store.
When the bean store is attached, the detached state is assumed to be authoritative if there are any conflicts.
- Specified by:
attachin interfaceBoundBeanStore- Returns:
- true if the bean store was attached, or false if the bean store is already attached
-
fetchUninitializedAttributes
public void fetchUninitializedAttributes()
Fetch all relevant attributes from the backing store and copy instances which are not present in the local bean store.
-
isAttached
public boolean isAttached()
Description copied from interface:BoundBeanStoreReturn true if the bean store is attached- Specified by:
isAttachedin interfaceBoundBeanStore- Returns:
- true if the bean store is attached or false if the bean store has been detached
-
get
public <T> ContextualInstance<T> get(org.jboss.weld.serialization.spi.BeanIdentifier id)
Description copied from interface:BeanStoreGets an instance of a contextual from the store
-
put
public <T> void put(org.jboss.weld.serialization.spi.BeanIdentifier id, ContextualInstance<T> instance)Description copied from interface:BeanStoreAdds a bean instance to the storage
-
remove
public <T> ContextualInstance<T> remove(org.jboss.weld.serialization.spi.BeanIdentifier id)
Description copied from interface:BeanStoreRemoves a bean instance identified by the given id.
-
clear
public void clear()
Description copied from interface:BeanStoreClears the store of contextual instances
-
contains
public boolean contains(org.jboss.weld.serialization.spi.BeanIdentifier id)
Description copied from interface:BeanStoreCheck if the store contains an instance
-
getNamingScheme
protected NamingScheme getNamingScheme()
-
iterator
public Iterator<org.jboss.weld.serialization.spi.BeanIdentifier> iterator()
-
getAttribute
protected abstract Object getAttribute(String prefixedId)
Gets an attribute from the underlying storage- Parameters:
prefixedId- The (prefixed) id of the attribute- Returns:
- The data
-
removeAttribute
protected abstract void removeAttribute(String prefixedId)
Removes an attribute from the underlying storage- Parameters:
prefixedId- The (prefixed) id of the attribute to remove
-
getAttributeNames
protected abstract Iterator<String> getAttributeNames()
Gets an enumeration of the attribute names present in the underlying storage. The collection must guarantee non-interference with other threads when iterating over it using iterator.- Returns:
- The attribute names
-
getPrefixedAttributeNames
protected Collection<String> getPrefixedAttributeNames()
Gets an enumeration of the attribute names present in the underlying storage- Returns:
- The attribute names
-
setAttribute
protected abstract void setAttribute(String prefixedId, Object instance)
Sets an instance under a key in the underlying storage- Parameters:
prefixedId- The (prefixed) id of the attribute to setinstance- The instance
-
lock
public LockedBean lock(org.jboss.weld.serialization.spi.BeanIdentifier id)
Description copied from interface:BeanStoreGets a creation lock for the given bean id.
-
getLockStore
protected abstract LockStore getLockStore()
-
isLocalBeanStoreSyncNeeded
protected boolean isLocalBeanStoreSyncNeeded()
- Returns:
trueif a bean store synchronization is required duringattach()invocation,falseotherwise
-
isAttributeLazyFetchingEnabled
public boolean isAttributeLazyFetchingEnabled()
- Returns:
trueif attributes should be fetched lazily,falseotherwise
-
-