站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate 3.2.4 正式版 API 英文文档

StatelessSessionImpl (Hibernate API Documentation) - Hibernate 3.2.4 正式版 API 英文文档


org.hibernate.impl
Class StatelessSessionImpl

java.lang.Object
  extended byorg.hibernate.impl.AbstractSessionImpl
      extended byorg.hibernate.impl.StatelessSessionImpl
All Implemented Interfaces:
JDBCContext.Context, Serializable, SessionImplementor, StatelessSession, TransactionFactory.Context

public class StatelessSessionImpl
extends AbstractSessionImpl
implements JDBCContext.Context, StatelessSession

Author:
Gavin King
See Also:
Serialized Form

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)
          Notify the session that the transaction completed, so we no longer own the old locks.
protected  boolean autoFlushIfRequired(Set querySpaces)
           
 void beforeTransactionCompletion(Transaction tx)
          Notify the session that the transaction is about to complete
 Transaction beginTransaction()
          Begin a Hibernate transaction.
 String bestGuessEntityName(Object object)
          The best guess entity name for an entity not in an association
 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)
          Execute a native SQL update or delete query
 int executeUpdate(String query, QueryParameters queryParameters)
          Execute a HQL update or delete query
 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()
          Get the prepared statement Batcher for this session
 CacheMode getCacheMode()
           
 ConnectionReleaseMode getConnectionReleaseMode()
           
 Serializable getContextEntityIdentifier(Object object)
          Return the identifier of the persistent object, or null if not associated with the session
 int getDontFlushFromFind()
           
 Map getEnabledFilters()
          Return the currently enabled filters.
 EntityMode getEntityMode()
           
 EntityPersister getEntityPersister(String entityName, Object object)
          Get the EntityPersister for any instance
 Object getEntityUsingInterceptor(EntityKey key)
          Get the entity instance associated with the given Key, calling the Interceptor if necessary
 String getFetchProfile()
           
 Type getFilterParameterType(String filterParameterName)
          Retreive the type for a given filter parrameter.
 Object getFilterParameterValue(String filterParameterName)
          Retreive the currently set value for a filter parameter.
 FlushMode getFlushMode()
           
 Interceptor getInterceptor()
          Retrieves the interceptor currently in use by this event source.
 JDBCContext getJDBCContext()
           
 EventListeners getListeners()
          Retrieves the configured event listeners from this event source.
 PersistenceContext getPersistenceContext()
          Get the persistence context for this session
 long getTimestamp()
          System time before the start of the transaction
 Transaction getTransaction()
          Get the current Hibernate transaction.
 String guessEntityName(Object entity)
          The guessed entity name for an entity not in an association
 Object immediateLoad(String entityName, Serializable id)
          Load an instance immediately.
 void initializeCollection(PersistentCollection collection, boolean writing)
          Initialize the collection (if not already initialized)
 Serializable insert(Object entity)
          Insert a row.
 Serializable insert(String entityName, Object entity)
          Insert a row.
 Object instantiate(String entityName, Serializable id)
          Instantiate the entity class, initializing with the given identifier
 Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)
          Load an instance without checking if it was deleted.
 boolean isAutoCloseSessionEnabled()
           
 boolean isConnected()
           
 boolean isEventSource()
           
 boolean isFlushBeforeCompletionEnabled()
           
 boolean isFlushModeNever()
           
 boolean isOpen()
           
 boolean isTransactionInProgress()
          Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?
 Iterator iterate(String query, QueryParameters queryParameters)
          Execute an iterate() query
 Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters)
          Iterate a filter
 List list(CriteriaImpl criteria)
          Execute a criteria query
 List list(String query, QueryParameters queryParameters)
          Execute a find() query
 List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
          Execute an SQL Query
 List listFilter(Object collection, String filter, QueryParameters queryParameters)
          Execute a filter
 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(CriteriaImpl criteria, ScrollMode scrollMode)
          Execute a criteria query
 ScrollableResults scroll(String query, QueryParameters queryParameters)
          Execute a scroll() query
 ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
          Execute an SQL Query
 void setAutoClear(boolean enabled)
          Enable/disable automatic cache clearing from after transaction completion (for EJB3)
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hibernate.transaction.TransactionFactory.Context
getFactory, isClosed
 
Methods inherited from interface org.hibernate.StatelessSession
createQuery, createSQLQuery, getNamedQuery
 

Method Detail

insert

public Serializable insert(Object entity)
Description copied from interface: StatelessSession
Insert a row.

Specified by:
insert in interface StatelessSession
Parameters:
entity - a new transient instance

insert

public Serializable insert(String entityName,
                           Object entity)
Description copied from interface: StatelessSession
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

delete

public void delete(Object entity)
Description copied from interface: StatelessSession
Delete a row.

Specified by:
delete in interface StatelessSession
Parameters:
entity - a detached entity instance

delete

public void delete(String entityName,
                   Object entity)
Description copied from interface: StatelessSession
Delete a row.

Specified by:
delete in interface StatelessSession
Parameters:
entityName - The entityName for the entity to be deleted
entity - a detached entity instance

update

public void update(Object entity)
Description copied from interface: StatelessSession
Update a row.

Specified by:
update in interface StatelessSession
Parameters:
entity - a detached entity instance

update

public void update(String entityName,
                   Object entity)
Description copied from interface: StatelessSession
Update a row.

Specified by:
update in interface StatelessSession
Parameters:
entityName - The entityName for the entity to be updated
entity - a detached entity instance

get

public Object get(Class entityClass,
                  Serializable id)
Description copied from interface: StatelessSession
Retrieve a row.

Specified by:
get in interface StatelessSession
Returns:
a detached entity instance

get

public Object get(Class entityClass,
                  Serializable id,
                  LockMode lockMode)
Description copied from interface: StatelessSession
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)
Description copied from interface: StatelessSession
Retrieve a row.

Specified by:
get in interface StatelessSession
Returns:
a detached entity instance

get

public Object get(String entityName,
                  Serializable id,
                  LockMode lockMode)
Description copied from interface: StatelessSession
Retrieve a row, obtaining the specified lock mode.

Specified by:
get in interface StatelessSession
Returns:
a detached entity instance

refresh

public void refresh(Object entity)
Description copied from interface: StatelessSession
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(String entityName,
                    Object entity)
Description copied from interface: StatelessSession
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(Object entity,
                    LockMode lockMode)
Description copied from interface: StatelessSession
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,
                    LockMode lockMode)
Description copied from interface: StatelessSession
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.

immediateLoad

public Object immediateLoad(String entityName,
                            Serializable id)
                     throws HibernateException
Description copied from interface: SessionImplementor
Load an instance immediately. This method is only called when lazily initializing a proxy. Do not return the proxy.

Specified by:
immediateLoad in interface SessionImplementor
Throws:
HibernateException

initializeCollection

public void initializeCollection(PersistentCollection collection,
                                 boolean writing)
                          throws HibernateException
Description copied from interface: SessionImplementor
Initialize the collection (if not already initialized)

Specified by:
initializeCollection in interface SessionImplementor
Throws:
HibernateException

instantiate

public Object instantiate(String entityName,
                          Serializable id)
                   throws HibernateException
Description copied from interface: SessionImplementor
Instantiate the entity class, initializing with the given identifier

Specified by:
instantiate in interface SessionImplementor
Throws:
HibernateException

internalLoad

public Object internalLoad(String entityName,
                           Serializable id,
                           boolean eager,
                           boolean nullable)
                    throws HibernateException
Description copied from interface: SessionImplementor
Load an instance without checking if it was deleted. When nullable is disabled this method may create a new proxy or return an existing proxy; if it does not exist, throw an exception. When nullable is enabled, the method does not create new proxies (but might return an existing proxy); if it does not exist, return null. When eager is enabled, the object is eagerly fetched

Specified by:
internalLoad in interface SessionImplementor
Throws:
HibernateException

iterate

public Iterator iterate(String query,
                        QueryParameters queryParameters)
                 throws HibernateException
Description copied from interface: SessionImplementor
Execute an iterate() query

Specified by:
iterate in interface SessionImplementor
Throws:
HibernateException

iterateFilter

public Iterator iterateFilter(Object collection,
                              String filter,
                              QueryParameters queryParameters)
                       throws HibernateException
Description copied from interface: SessionImplementor
Iterate a filter

Specified by:
iterateFilter in interface SessionImplementor
Throws:
HibernateException

listFilter

public List listFilter(Object collection,
                       String filter,
                       QueryParameters queryParameters)
                throws HibernateException
Description copied from interface: SessionImplementor
Execute a filter

Specified by:
listFilter in interface SessionImplementor
Throws:
HibernateException

isOpen

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

close

public void close()
Description copied from interface: StatelessSession
Close the stateless session and release the JDBC connection.

Specified by:
close in interface StatelessSession

getConnectionReleaseMode

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

isAutoCloseSessionEnabled

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

isFlushBeforeCompletionEnabled

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

isFlushModeNever

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

managedClose

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

managedFlush

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

shouldAutoClose

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

afterTransactionCompletion

public void afterTransactionCompletion(boolean successful,
                                       Transaction tx)
Description copied from interface: SessionImplementor
Notify the session that the transaction completed, so we no longer own the old locks. (Also we should release cache softlocks.) May be called multiple times during the transaction completion process. Also called after an autocommit, in which case the second argument is null.

Specified by:
afterTransactionCompletion in interface JDBCContext.Context

beforeTransactionCompletion

public void beforeTransactionCompletion(Transaction tx)
Description copied from interface: SessionImplementor
Notify the session that the transaction is about to complete

Specified by:
beforeTransactionCompletion in interface JDBCContext.Context

bestGuessEntityName

public String bestGuessEntityName(Object object)
Description copied from interface: SessionImplementor
The best guess entity name for an entity not in an association

Specified by:
bestGuessEntityName in interface SessionImplementor

connection

public Connection connection()
Description copied from interface: StatelessSession
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

executeUpdate

public int executeUpdate(String query,
                         QueryParameters queryParameters)
                  throws HibernateException
Description copied from interface: SessionImplementor
Execute a HQL update or delete query

Specified by:
executeUpdate in interface SessionImplementor
Throws:
HibernateException

getBatcher

public Batcher getBatcher()
Description copied from interface: SessionImplementor
Get the prepared statement Batcher for this session

Specified by:
getBatcher in interface SessionImplementor

getCacheMode

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

getDontFlushFromFind

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

getEnabledFilters

public Map getEnabledFilters()
Description copied from interface: SessionImplementor
Return the currently enabled filters. The filter map is keyed by filter name, with values corresponding to the FilterImpl instance.

Specified by:
getEnabledFilters in interface SessionImplementor
Returns:
The currently enabled filters.

getContextEntityIdentifier

public Serializable getContextEntityIdentifier(Object object)
Description copied from interface: SessionImplementor
Return the identifier of the persistent object, or null if not associated with the session

Specified by:
getContextEntityIdentifier in interface SessionImplementor

getEntityMode

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

getEntityPersister

public EntityPersister getEntityPersister(String entityName,
                                          Object object)
                                   throws HibernateException
Description copied from interface: SessionImplementor
Get the EntityPersister for any instance

Specified by:
getEntityPersister in interface SessionImplementor
Parameters:
entityName - optional entity name
object - the entity instance
Throws:
HibernateException

getEntityUsingInterceptor

public Object getEntityUsingInterceptor(EntityKey key)
                                 throws HibernateException
Description copied from interface: SessionImplementor
Get the entity instance associated with the given Key, calling the Interceptor if necessary

Specified by:
getEntityUsingInterceptor in interface SessionImplementor
Throws:
HibernateException

getFilterParameterType

public Type getFilterParameterType(String filterParameterName)
Description copied from interface: SessionImplementor
Retreive the type for a given filter parrameter.

Specified by:
getFilterParameterType in interface SessionImplementor
Parameters:
filterParameterName - The filter parameter name in the format {FILTER_NAME.PARAMETER_NAME}.

getFilterParameterValue

public Object getFilterParameterValue(String filterParameterName)
Description copied from interface: SessionImplementor
Retreive the currently set value for a filter parameter.

Specified by:
getFilterParameterValue in interface SessionImplementor
Parameters:
filterParameterName - The filter parameter name in the format {FILTER_NAME.PARAMETER_NAME}.
Returns:
The filter parameter value.

getFlushMode

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

getInterceptor

public Interceptor getInterceptor()
Description copied from interface: SessionImplementor
Retrieves the interceptor currently in use by this event source.

Specified by:
getInterceptor in interface SessionImplementor
Returns:
The interceptor.

getListeners

public EventListeners getListeners()
Description copied from interface: SessionImplementor
Retrieves the configured event listeners from this event source.

Specified by:
getListeners in interface SessionImplementor
Returns:
The configured event listeners.

getPersistenceContext

public PersistenceContext getPersistenceContext()
Description copied from interface: SessionImplementor
Get the persistence context for this session

Specified by:
getPersistenceContext in interface SessionImplementor

getTimestamp

public long getTimestamp()
Description copied from interface: SessionImplementor
System time before the start of the transaction

Specified by:
getTimestamp in interface SessionImplementor

guessEntityName

public String guessEntityName(Object entity)
                       throws HibernateException
Description copied from interface: SessionImplementor
The guessed entity name for an entity not in an association

Specified by:
guessEntityName in interface SessionImplementor
Throws:
HibernateException

isConnected

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

isTransactionInProgress

public boolean isTransactionInProgress()
Description copied from interface: SessionImplementor
Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?

Specified by:
isTransactionInProgress in interface SessionImplementor

setAutoClear

public void setAutoClear(boolean enabled)
Description copied from interface: SessionImplementor
Enable/disable automatic cache clearing from after transaction completion (for EJB3)

Specified by:
setAutoClear in interface SessionImplementor

setCacheMode

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

setFlushMode

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

getTransaction

public Transaction getTransaction()
                           throws HibernateException
Description copied from interface: StatelessSession
Get the current Hibernate transaction.

Specified by:
getTransaction in interface StatelessSession
Throws:
HibernateException

beginTransaction

public Transaction beginTransaction()
                             throws HibernateException
Description copied from interface: StatelessSession
Begin a Hibernate transaction.

Specified by:
beginTransaction in interface StatelessSession
Throws:
HibernateException

isEventSource

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

list

public List list(String query,
                 QueryParameters queryParameters)
          throws HibernateException
Description copied from interface: SessionImplementor
Execute a find() query

Specified by:
list in interface SessionImplementor
Throws:
HibernateException

afterOperation

public void afterOperation(boolean success)

createCriteria

public Criteria createCriteria(Class persistentClass,
                               String alias)
Description copied from interface: StatelessSession
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,
                               String alias)
Description copied from interface: StatelessSession
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

createCriteria

public Criteria createCriteria(Class persistentClass)
Description copied from interface: StatelessSession
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(String entityName)
Description copied from interface: StatelessSession
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

scroll

public ScrollableResults scroll(CriteriaImpl criteria,
                                ScrollMode scrollMode)
Description copied from interface: SessionImplementor
Execute a criteria query

Specified by:
scroll in interface SessionImplementor

list

public List list(CriteriaImpl criteria)
          throws HibernateException
Description copied from interface: SessionImplementor
Execute a criteria query

Specified by:
list in interface SessionImplementor
Throws:
HibernateException

listCustomQuery

public List listCustomQuery(CustomQuery customQuery,
                            QueryParameters queryParameters)
                     throws HibernateException
Description copied from interface: SessionImplementor
Execute an SQL Query

Specified by:
listCustomQuery in interface SessionImplementor
Throws:
HibernateException

scrollCustomQuery

public ScrollableResults scrollCustomQuery(CustomQuery customQuery,
                                           QueryParameters queryParameters)
                                    throws HibernateException
Description copied from interface: SessionImplementor
Execute an SQL Query

Specified by:
scrollCustomQuery in interface SessionImplementor
Throws:
HibernateException

scroll

public ScrollableResults scroll(String query,
                                QueryParameters queryParameters)
                         throws HibernateException
Description copied from interface: SessionImplementor
Execute a scroll() query

Specified by:
scroll in interface SessionImplementor
Throws:
HibernateException

afterScrollOperation

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

flush

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

getFetchProfile

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

getJDBCContext

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

setFetchProfile

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

afterTransactionBegin

public void afterTransactionBegin(Transaction tx)
Description copied from interface: JDBCContext.Context
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

autoFlushIfRequired

protected boolean autoFlushIfRequired(Set querySpaces)
                               throws HibernateException
Throws:
HibernateException

executeNativeUpdate

public int executeNativeUpdate(NativeSQLQuerySpecification nativeSQLQuerySpecification,
                               QueryParameters queryParameters)
                        throws HibernateException
Description copied from interface: SessionImplementor
Execute a native SQL update or delete query

Specified by:
executeNativeUpdate in interface SessionImplementor
Throws:
HibernateException