public class CachingSessionFactory<F> extends Object implements SessionFactory<F>, DisposableBean
SessionFactory implementation that caches Sessions for reuse without
requiring reconnection each time the Session is retrieved from the factory.
This implementation wraps and delegates to a target SessionFactory instance.| Modifier and Type | Class and Description |
|---|---|
class |
CachingSessionFactory.CachedSession |
| Constructor and Description |
|---|
CachingSessionFactory(SessionFactory<F> sessionFactory)
Create a CachingSessionFactory with an unlimited number of sessions.
|
CachingSessionFactory(SessionFactory<F> sessionFactory,
int sessionCacheSize)
Create a CachingSessionFactory with the specified session limit.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Remove (close) any unused sessions in the pool.
|
Session<F> |
getSession()
Get a session from the pool (or block if none available).
|
void |
resetCache()
Clear the cache of sessions; also any in-use sessions will be closed when
returned to the cache.
|
void |
setPoolSize(int poolSize)
Modify the target session pool size; the actual pool size will adjust up/down
to this size as and when sessions are requested or retrieved.
|
void |
setSessionWaitTimeout(long sessionWaitTimeout)
Sets the limit of how long to wait for a session to become available.
|
void |
setTestSession(boolean testSession)
Set to true to test the session when checking one out from the cache.
|
public CachingSessionFactory(SessionFactory<F> sessionFactory)
sessionFactory - the underlying session factory.public CachingSessionFactory(SessionFactory<F> sessionFactory, int sessionCacheSize)
Do not cache a DelegatingSessionFactory, cache each delegate therein instead.
sessionFactory - The underlying session factory.sessionCacheSize - The maximum cache size.setSessionWaitTimeout(long),
setPoolSize(int)public void setSessionWaitTimeout(long sessionWaitTimeout)
sessionWaitTimeout - the session wait timeout.IllegalStateException - if the wait expires prior to a Session becoming available.public void setPoolSize(int poolSize)
poolSize - The pool size.public void setTestSession(boolean testSession)
testSession - true to test.public Session<F> getSession()
getSession in interface SessionFactory<F>public void destroy()
destroy in interface DisposableBeanpublic void resetCache()