public final class SimpleResourceHolder
extends java.lang.Object
Supports one resource per key without overwriting, that is, a resource needs to be removed before a new one can be set for the same key.
Resource management code should check for thread-bound resources via has(Object)
.
This helper isn't designed for transaction synchronization cases.
Use TransactionSynchronizationManager
and ResourceHolder
instead.
Modifier and Type | Method and Description |
---|---|
static void |
bind(java.lang.Object key,
java.lang.Object value)
Bind the given resource for the given key to the current thread.
|
static void |
clear()
Clear resources for the current thread.
|
static java.lang.Object |
get(java.lang.Object key)
Retrieve a resource for the given key that is bound to the current thread.
|
static java.util.Map<java.lang.Object,java.lang.Object> |
getResources()
Return all resources that are bound to the current thread.
|
static boolean |
has(java.lang.Object key)
Check if there is a resource for the given key bound to the current thread.
|
static java.lang.Object |
unbind(java.lang.Object key)
Unbind a resource for the given key from the current thread.
|
static java.lang.Object |
unbindIfPossible(java.lang.Object key)
Unbind a resource for the given key from the current thread.
|
public static java.util.Map<java.lang.Object,java.lang.Object> getResources()
Mainly for debugging purposes. Resource managers should always invoke
hasResource
for a specific resource key that they are interested in.
has(java.lang.Object)
public static boolean has(java.lang.Object key)
key
- the key to check (usually the resource factory)public static java.lang.Object get(java.lang.Object key)
key
- the key to check (usually the resource factory)null
if nonepublic static void bind(java.lang.Object key, java.lang.Object value)
key
- the key to bind the value to (usually the resource factory)value
- the value to bind (usually the active resource object)java.lang.IllegalStateException
- if there is already a value bound to the threadpublic static java.lang.Object unbind(java.lang.Object key) throws java.lang.IllegalStateException
key
- the key to unbind (usually the resource factory)java.lang.IllegalStateException
- if there is no value bound to the threadpublic static java.lang.Object unbindIfPossible(java.lang.Object key)
key
- the key to unbind (usually the resource factory)null
if none boundpublic static void clear()