org.hibernate.impl

Class StatelessSessionImpl

Implemented Interfaces:
JDBCContext.Context, Serializable, SessionImplementor, StatelessSession, TransactionFactory.Context

public class StatelessSessionImpl
extends AbstractSessionImpl
implements JDBCContext.Context, StatelessSession

Author:
Gavin King

Field Summary

Fields inherited from class org.hibernate.impl.AbstractSessionImpl

factory

Method Summary

void
afterOperation(boolean success)
void
afterScrollOperation()
void
afterTransactionBegin(Transaction tx)
We cannot rely upon this method being called! It is only called if we are using Hibernate Transaction API.
void
afterTransactionCompletion(boolean successful, Transaction tx)
protected boolean
autoFlushIfRequired(Set querySpaces)
void
beforeTransactionCompletion(Transaction tx)
Transaction
beginTransaction()
Begin a Hibernate transaction.
String
bestGuessEntityName(Object object)
void
close()
Close the stateless session and release the JDBC connection.
Connection
connection()
Returns the current JDBC connection associated with this instance.

If the session is using aggressive connection release (as in a CMT environment), it is the application's responsibility to close the connection returned by this call.
Criteria
createCriteria(Class persistentClass)
Create a new Criteria instance, for the given entity class, or a superclass of an entity class.
Criteria
createCriteria(Class persistentClass, String alias)
Create a new Criteria instance, for the given entity class, or a superclass of an entity class, with the given alias.
Criteria
createCriteria(String entityName)
Create a new Criteria instance, for the given entity name.
Criteria
createCriteria(String entityName, String alias)
Create a new Criteria instance, for the given entity name, with the given alias.
void
delete(Object entity)
Delete a row.
void
delete(String entityName, Object entity)
Delete a row.
int
executeNativeUpdate(NativeSQLQuerySpecification nativeSQLQuerySpecification, QueryParameters queryParameters)
int
executeUpdate(String query, QueryParameters queryParameters)
void
flush()
Object
get(Class entityClass, Serializable id)
Retrieve a row.
Object
get(Class entityClass, Serializable id, LockMode lockMode)
Retrieve a row, obtaining the specified lock mode.
Object
get(String entityName, Serializable id)
Retrieve a row.
Object
get(String entityName, Serializable id, LockMode lockMode)
Retrieve a row, obtaining the specified lock mode.
Batcher
getBatcher()
CacheMode
getCacheMode()
ConnectionReleaseMode
getConnectionReleaseMode()
Serializable
getContextEntityIdentifier(Object object)
int
getDontFlushFromFind()
Map
getEnabledFilters()
EntityMode
getEntityMode()
EntityPersister
getEntityPersister(String entityName, Object object)
Object
getEntityUsingInterceptor(EntityKey key)
String
getFetchProfile()
Type
getFilterParameterType(String filterParameterName)
Object
getFilterParameterValue(String filterParameterName)
FlushMode
getFlushMode()
Interceptor
getInterceptor()
JDBCContext
getJDBCContext()
EventListeners
getListeners()
PersistenceContext
getPersistenceContext()
long
getTimestamp()
Transaction
getTransaction()
Get the current Hibernate transaction.
String
guessEntityName(Object entity)
Object
immediateLoad(String entityName, Serializable id)
void
initializeCollection(PersistentCollection collection, boolean writing)
Serializable
insert(Object entity)
Insert a row.
Serializable
insert(String entityName, Object entity)
Insert a row.
Object
instantiate(String entityName, Serializable id)
Object
internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)
boolean
isAutoCloseSessionEnabled()
boolean
isConnected()
boolean
isEventSource()
boolean
isFlushBeforeCompletionEnabled()
boolean
isFlushModeNever()
boolean
isOpen()
boolean
isTransactionInProgress()
Iterator
iterate(String query, QueryParameters queryParameters)
Iterator
iterateFilter(Object collection, String filter, QueryParameters queryParameters)
List
list(String query, QueryParameters queryParameters)
List
list(CriteriaImpl criteria)
List
listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
List
listFilter(Object collection, String filter, QueryParameters queryParameters)
void
managedClose()
void
managedFlush()
void
refresh(Object entity)
Refresh the entity instance state from the database.
void
refresh(Object entity, LockMode lockMode)
Refresh the entity instance state from the database.
void
refresh(String entityName, Object entity)
Refresh the entity instance state from the database.
void
refresh(String entityName, Object entity, LockMode lockMode)
Refresh the entity instance state from the database.
ScrollableResults
scroll(String query, QueryParameters queryParameters)
ScrollableResults
scroll(CriteriaImpl criteria, ScrollMode scrollMode)
ScrollableResults
scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
void
setAutoClear(boolean enabled)
void
setCacheMode(CacheMode cm)
void
setFetchProfile(String name)
void
setFlushMode(FlushMode fm)
boolean
shouldAutoClose()
void
update(Object entity)
Update a row.
void
update(String entityName, Object entity)
Update a row.

Methods inherited from class org.hibernate.impl.AbstractSessionImpl

createQuery, createSQLQuery, errorIfClosed, getFactory, getHQLQueryPlan, getNamedQuery, getNamedSQLQuery, getNativeSQLQueryPlan, isClosed, list, scroll, setClosed

Method Details

afterOperation

public void afterOperation(boolean success)

afterScrollOperation

public void afterScrollOperation()
Specified by:
afterScrollOperation in interface SessionImplementor

afterTransactionBegin

public void afterTransactionBegin(Transaction tx)
We cannot rely upon this method being called! It is only called if we are using Hibernate Transaction API.
Specified by:
afterTransactionBegin in interface JDBCContext.Context

afterTransactionCompletion

public void afterTransactionCompletion(boolean successful,
                                       Transaction tx)
Specified by:
afterTransactionCompletion in interface JDBCContext.Context
afterTransactionCompletion in interface SessionImplementor

autoFlushIfRequired

protected boolean autoFlushIfRequired(Set querySpaces)
            throws HibernateException

beforeTransactionCompletion

public void beforeTransactionCompletion(Transaction tx)
Specified by:
beforeTransactionCompletion in interface JDBCContext.Context
beforeTransactionCompletion in interface SessionImplementor

beginTransaction

public Transaction beginTransaction()
            throws HibernateException
Begin a Hibernate transaction.
Specified by:
beginTransaction in interface StatelessSession

bestGuessEntityName

public String bestGuessEntityName(Object object)
Specified by:
bestGuessEntityName in interface SessionImplementor

close

public void close()
Close the stateless session and release the JDBC connection.
Specified by:
close in interface StatelessSession

connection

public Connection connection()
Returns the current JDBC connection associated with this instance.

If the session is using aggressive connection release (as in a CMT environment), it is the application's responsibility to close the connection returned by this call. Otherwise, the application should not close the connection.
Specified by:
connection in interface StatelessSession
connection in interface SessionImplementor

createCriteria

public Criteria createCriteria(Class persistentClass)
Create a new Criteria instance, for the given entity class, or a superclass of an entity class. Entities returned by the query are detached.
Specified by:
createCriteria in interface StatelessSession
Parameters:
persistentClass - a class, which is persistent, or has persistent subclasses
Returns:
Criteria

createCriteria

public Criteria createCriteria(Class persistentClass,
                               String alias)
Create a new Criteria instance, for the given entity class, or a superclass of an entity class, with the given alias. Entities returned by the query are detached.
Specified by:
createCriteria in interface StatelessSession
Parameters:
persistentClass - a class, which is persistent, or has persistent subclasses
Returns:
Criteria

createCriteria

public Criteria createCriteria(String entityName)
Create a new Criteria instance, for the given entity name. Entities returned by the query are detached.
Specified by:
createCriteria in interface StatelessSession
Parameters:
entityName -
Returns:
Criteria

createCriteria

public Criteria createCriteria(String entityName,
                               String alias)
Create a new Criteria instance, for the given entity name, with the given alias. Entities returned by the query are detached.
Specified by:
createCriteria in interface StatelessSession
Parameters:
entityName -
Returns:
Criteria

delete

public void delete(Object entity)
Delete a row.
Specified by:
delete in interface StatelessSession
Parameters:
entity - a detached entity instance

delete

public void delete(String entityName,
                   Object entity)
Delete a row.
Specified by:
delete in interface StatelessSession
Parameters:
entityName - The entityName for the entity to be deleted
entity - a detached entity instance

executeNativeUpdate

public int executeNativeUpdate(NativeSQLQuerySpecification nativeSQLQuerySpecification,
                               QueryParameters queryParameters)
            throws HibernateException
Specified by:
executeNativeUpdate in interface SessionImplementor

executeUpdate

public int executeUpdate(String query,
                         QueryParameters queryParameters)
            throws HibernateException
Specified by:
executeUpdate in interface SessionImplementor

flush

public void flush()
Specified by:
flush in interface SessionImplementor

get

public Object get(Class entityClass,
                  Serializable id)
Retrieve a row.
Specified by:
get in interface StatelessSession
Returns:
a detached entity instance

get

public Object get(Class entityClass,
                  Serializable id,
                  LockMode lockMode)
Retrieve a row, obtaining the specified lock mode.
Specified by:
get in interface StatelessSession
Returns:
a detached entity instance

get

public Object get(String entityName,
                  Serializable id)
Retrieve a row.
Specified by:
get in interface StatelessSession
Returns:
a detached entity instance

get

public Object get(String entityName,
                  Serializable id,
                  LockMode lockMode)
Retrieve a row, obtaining the specified lock mode.
Specified by:
get in interface StatelessSession
Returns:
a detached entity instance

getBatcher

public Batcher getBatcher()
Specified by:
getBatcher in interface SessionImplementor

getCacheMode

public CacheMode getCacheMode()
Specified by:
getCacheMode in interface SessionImplementor

getConnectionReleaseMode

public ConnectionReleaseMode getConnectionReleaseMode()
Specified by:
getConnectionReleaseMode in interface JDBCContext.Context

getContextEntityIdentifier

public Serializable getContextEntityIdentifier(Object object)
Specified by:
getContextEntityIdentifier in interface SessionImplementor

getDontFlushFromFind

public int getDontFlushFromFind()
Specified by:
getDontFlushFromFind in interface SessionImplementor

getEnabledFilters

public Map getEnabledFilters()
Specified by:
getEnabledFilters in interface SessionImplementor

getEntityMode

public EntityMode getEntityMode()
Specified by:
getEntityMode in interface SessionImplementor

getEntityPersister

public EntityPersister getEntityPersister(String entityName,
                                          Object object)
            throws HibernateException
Specified by:
getEntityPersister in interface SessionImplementor

getEntityUsingInterceptor

public Object getEntityUsingInterceptor(EntityKey key)
            throws HibernateException
Specified by:
getEntityUsingInterceptor in interface SessionImplementor

getFetchProfile

public String getFetchProfile()
Specified by:
getFetchProfile in interface SessionImplementor

getFilterParameterType

public Type getFilterParameterType(String filterParameterName)
Specified by:
getFilterParameterType in interface SessionImplementor

getFilterParameterValue

public Object getFilterParameterValue(String filterParameterName)
Specified by:
getFilterParameterValue in interface SessionImplementor

getFlushMode

public FlushMode getFlushMode()
Specified by:
getFlushMode in interface SessionImplementor

getInterceptor

public Interceptor getInterceptor()
Specified by:
getInterceptor in interface SessionImplementor

getJDBCContext

public JDBCContext getJDBCContext()
Specified by:
getJDBCContext in interface SessionImplementor

getListeners

public EventListeners getListeners()
Specified by:
getListeners in interface SessionImplementor

getPersistenceContext

public PersistenceContext getPersistenceContext()
Specified by:
getPersistenceContext in interface SessionImplementor

getTimestamp

public long getTimestamp()
Specified by:
getTimestamp in interface SessionImplementor

getTransaction

public Transaction getTransaction()
            throws HibernateException
Get the current Hibernate transaction.
Specified by:
getTransaction in interface StatelessSession

guessEntityName

public String guessEntityName(Object entity)
            throws HibernateException
Specified by:
guessEntityName in interface SessionImplementor

immediateLoad

public Object immediateLoad(String entityName,
                            Serializable id)
            throws HibernateException
Specified by:
immediateLoad in interface SessionImplementor

initializeCollection

public void initializeCollection(PersistentCollection collection,
                                 boolean writing)
            throws HibernateException
Specified by:
initializeCollection in interface SessionImplementor

insert

public Serializable insert(Object entity)
Insert a row.
Specified by:
insert in interface StatelessSession
Parameters:
entity - a new transient instance

insert

public Serializable insert(String entityName,
                           Object entity)
Insert a row.
Specified by:
insert in interface StatelessSession
Parameters:
entityName - The entityName for the entity to be inserted
entity - a new transient instance
Returns:
the identifier of the instance

instantiate

public Object instantiate(String entityName,
                          Serializable id)
            throws HibernateException
Specified by:
instantiate in interface SessionImplementor

internalLoad

public Object internalLoad(String entityName,
                           Serializable id,
                           boolean eager,
                           boolean nullable)
            throws HibernateException
Specified by:
internalLoad in interface SessionImplementor

isAutoCloseSessionEnabled

public boolean isAutoCloseSessionEnabled()
Specified by:
isAutoCloseSessionEnabled in interface JDBCContext.Context

isConnected

public boolean isConnected()
Specified by:
isConnected in interface SessionImplementor

isEventSource

public boolean isEventSource()
Specified by:
isEventSource in interface SessionImplementor

isFlushBeforeCompletionEnabled

public boolean isFlushBeforeCompletionEnabled()
Specified by:
isFlushBeforeCompletionEnabled in interface TransactionFactory.Context

isFlushModeNever

public boolean isFlushModeNever()
Specified by:
isFlushModeNever in interface TransactionFactory.Context

isOpen

public boolean isOpen()
Specified by:
isOpen in interface SessionImplementor

isTransactionInProgress

public boolean isTransactionInProgress()
Specified by:
isTransactionInProgress in interface SessionImplementor

iterate

public Iterator iterate(String query,
                        QueryParameters queryParameters)
            throws HibernateException
Specified by:
iterate in interface SessionImplementor

iterateFilter

public Iterator iterateFilter(Object collection,
                              String filter,
                              QueryParameters queryParameters)
            throws HibernateException
Specified by:
iterateFilter in interface SessionImplementor

list

public List list(String query,
                 QueryParameters queryParameters)
            throws HibernateException
Specified by:
list in interface SessionImplementor

list

public List list(CriteriaImpl criteria)
            throws HibernateException
Specified by:
list in interface SessionImplementor

listCustomQuery

public List listCustomQuery(CustomQuery customQuery,
                            QueryParameters queryParameters)
            throws HibernateException
Specified by:
listCustomQuery in interface SessionImplementor

listFilter

public List listFilter(Object collection,
                       String filter,
                       QueryParameters queryParameters)
            throws HibernateException
Specified by:
listFilter in interface SessionImplementor

managedClose

public void managedClose()
Specified by:
managedClose in interface TransactionFactory.Context

managedFlush

public void managedFlush()
Specified by:
managedFlush in interface TransactionFactory.Context

refresh

public void refresh(Object entity)
Refresh the entity instance state from the database.
Specified by:
refresh in interface StatelessSession
Parameters:
entity - The entity to be refreshed.

refresh

public void refresh(Object entity,
                    LockMode lockMode)
Refresh the entity instance state from the database.
Specified by:
refresh in interface StatelessSession
Parameters:
entity - The entity to be refreshed.
lockMode - The LockMode to be applied.

refresh

public void refresh(String entityName,
                    Object entity)
Refresh the entity instance state from the database.
Specified by:
refresh in interface StatelessSession
Parameters:
entityName - The entityName for the entity to be refreshed.
entity - The entity to be refreshed.

refresh

public void refresh(String entityName,
                    Object entity,
                    LockMode lockMode)
Refresh the entity instance state from the database.
Specified by:
refresh in interface StatelessSession
Parameters:
entityName - The entityName for the entity to be refreshed.
entity - The entity to be refreshed.
lockMode - The LockMode to be applied.

scroll

public ScrollableResults scroll(String query,
                                QueryParameters queryParameters)
            throws HibernateException
Specified by:
scroll in interface SessionImplementor

scroll

public ScrollableResults scroll(CriteriaImpl criteria,
                                ScrollMode scrollMode)
Specified by:
scroll in interface SessionImplementor

scrollCustomQuery

public ScrollableResults scrollCustomQuery(CustomQuery customQuery,
                                           QueryParameters queryParameters)
            throws HibernateException
Specified by:
scrollCustomQuery in interface SessionImplementor

setAutoClear

public void setAutoClear(boolean enabled)
Specified by:
setAutoClear in interface SessionImplementor

setCacheMode

public void setCacheMode(CacheMode cm)
Specified by:
setCacheMode in interface SessionImplementor

setFetchProfile

public void setFetchProfile(String name)
Specified by:
setFetchProfile in interface SessionImplementor

setFlushMode

public void setFlushMode(FlushMode fm)
Specified by:
setFlushMode in interface SessionImplementor

shouldAutoClose

public boolean shouldAutoClose()
Specified by:
shouldAutoClose in interface TransactionFactory.Context

update

public void update(Object entity)
Update a row.
Specified by:
update in interface StatelessSession
Parameters:
entity - a detached entity instance

update

public void update(String entityName,
                   Object entity)
Update a row.
Specified by:
update in interface StatelessSession
Parameters:
entityName - The entityName for the entity to be updated
entity - a detached entity instance