public class DbSession
extends java.lang.Object
Constructor and Description |
---|
DbSession(org.hibernate.SessionFactory sessionFactory) |
Modifier and Type | Method and Description |
---|---|
org.hibernate.Transaction |
beginTransaction()
Begin a unit of work and return the associated
Transaction object. |
org.hibernate.Session.LockRequest |
buildLockRequest(org.hibernate.LockOptions lockOptions)
Build a LockRequest that specifies the LockMode, pessimistic lock timeout and lock scope.
|
void |
cancelQuery()
Cancel the execution of the current query.
|
void |
clear()
Completely clear the session.
|
java.sql.Connection |
close()
End the session by releasing the JDBC connection and cleaning up.
|
java.sql.Connection |
connection()
Deprecated.
(scheduled for removal in 4.x). Replacement depends on need; for doing direct JDBC stuff use
doWork(org.hibernate.jdbc.Work) ; for opening a 'temporary Session' use (TBD). |
boolean |
contains(java.lang.Object object)
Check if this instance is associated with this Session.
|
org.hibernate.Criteria |
createCriteria(java.lang.Class persistentClass)
Create
Criteria instance for the given class (entity or subclasses/implementors). |
org.hibernate.Criteria |
createCriteria(java.lang.Class persistentClass,
java.lang.String alias)
Create
Criteria instance for the given class (entity or subclasses/implementors),
using a specific alias. |
org.hibernate.Criteria |
createCriteria(java.lang.String entityName)
Create
Criteria instance for the given entity name. |
org.hibernate.Criteria |
createCriteria(java.lang.String entityName,
java.lang.String alias)
Create
Criteria instance for the given entity name, using a specific alias. |
org.hibernate.Query |
createFilter(java.lang.Object collection,
java.lang.String queryString)
Create a
Query instance for the given collection and filter string. |
org.hibernate.Query |
createQuery(java.lang.String queryString)
Create a
Query instance for the given HQL query string. |
org.hibernate.SQLQuery |
createSQLQuery(java.lang.String queryString)
Create a
SQLQuery instance for the given SQL query string. |
void |
delete(java.lang.Object object)
Remove a persistent instance from the datastore.
|
void |
delete(java.lang.String entityName,
java.lang.Object object)
Remove a persistent instance from the datastore.
|
void |
disableFetchProfile(java.lang.String name)
Disable a particular fetch profile on this session.
|
void |
disableFilter(java.lang.String filterName)
Disable the named filter for the current session.
|
void |
doWork(org.hibernate.jdbc.Work work)
Controller for allowing users to perform JDBC related work using the Connection managed by
this Session.
|
void |
enableFetchProfile(java.lang.String name)
Enable a particular fetch profile on this session.
|
org.hibernate.Filter |
enableFilter(java.lang.String filterName)
Enable the named filter for this current session.
|
void |
evict(java.lang.Object object)
Remove this instance from the session cache.
|
void |
flush()
Force this session to flush.
|
java.lang.Object |
get(java.lang.Class clazz,
java.io.Serializable id)
Return the persistent instance of the given entity class with the given identifier, or null
if there is no such persistent instance.
|
java.lang.Object |
get(java.lang.Class clazz,
java.io.Serializable id,
org.hibernate.LockMode lockMode)
Deprecated.
LockMode parameter should be replaced with LockOptions
|
java.lang.Object |
get(java.lang.Class clazz,
java.io.Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, or null
if there is no such persistent instance.
|
java.lang.Object |
get(java.lang.String entityName,
java.io.Serializable id)
Return the persistent instance of the given named entity with the given identifier, or null
if there is no such persistent instance.
|
java.lang.Object |
get(java.lang.String entityName,
java.io.Serializable id,
org.hibernate.LockMode lockMode)
Deprecated.
LockMode parameter should be replaced with LockOptions
|
java.lang.Object |
get(java.lang.String entityName,
java.io.Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, or null
if there is no such persistent instance.
|
org.hibernate.CacheMode |
getCacheMode()
Get the current cache mode.
|
org.hibernate.LockMode |
getCurrentLockMode(java.lang.Object object)
Determine the current lock mode of the given object.
|
org.hibernate.Filter |
getEnabledFilter(java.lang.String filterName)
Retrieve a currently enabled filter by name.
|
java.lang.String |
getEntityName(java.lang.Object object)
Return the entity name for a persistent entity.
|
org.hibernate.FlushMode |
getFlushMode()
Get the current flush mode for this session.
|
java.io.Serializable |
getIdentifier(java.lang.Object object)
Return the identifier value of the given entity as associated with this session.
|
org.hibernate.LobHelper |
getLobHelper()
Retrieve this session's helper/delegate for creating LOB instances.
|
org.hibernate.Query |
getNamedQuery(java.lang.String queryName)
Create a
Query instance for the named query string defined in the metadata. |
org.hibernate.SessionFactory |
getSessionFactory()
Get the session factory which created this session.
|
org.hibernate.stat.SessionStatistics |
getStatistics()
Get the statistics for this session.
|
org.hibernate.Transaction |
getTransaction()
Get the
Transaction instance associated with this session. |
org.hibernate.TypeHelper |
getTypeHelper()
Convenience access to the
TypeHelper associated with this session's
SessionFactory . |
boolean |
isConnected()
Check if the session is currently connected.
|
boolean |
isDefaultReadOnly()
Will entities and proxies that are loaded into this session be made read-only by default? To
determine the read-only/modifiable setting for a particular entity or proxy:
|
boolean |
isDirty()
Does this session contain any changes which must be synchronized with the database? In other
words, would any DML operations be executed if we flushed this session?
|
boolean |
isFetchProfileEnabled(java.lang.String name)
Is a particular fetch profile enabled on this session?
|
boolean |
isOpen()
Check if the session is still open.
|
boolean |
isReadOnly(java.lang.Object entityOrProxy)
Is the specified entity or proxy read-only? To get the default read-only/modifiable setting
used for entities and proxies that are loaded into the session:
|
java.lang.Object |
load(java.lang.Class theClass,
java.io.Serializable id)
Return the persistent instance of the given entity class with the given identifier, assuming
that the instance exists.
|
java.lang.Object |
load(java.lang.Class theClass,
java.io.Serializable id,
org.hibernate.LockMode lockMode)
Deprecated.
LockMode parameter should be replaced with LockOptions
|
java.lang.Object |
load(java.lang.Class theClass,
java.io.Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, obtaining
the specified lock mode, assuming the instance exists.
|
void |
load(java.lang.Object object,
java.io.Serializable id)
Read the persistent state associated with the given identifier into the given transient
instance.
|
java.lang.Object |
load(java.lang.String entityName,
java.io.Serializable id)
Return the persistent instance of the given entity class with the given identifier, assuming
that the instance exists.
|
java.lang.Object |
load(java.lang.String entityName,
java.io.Serializable id,
org.hibernate.LockMode lockMode)
Deprecated.
LockMode parameter should be replaced with LockOptions
|
java.lang.Object |
load(java.lang.String entityName,
java.io.Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, obtaining
the specified lock mode, assuming the instance exists.
|
void |
lock(java.lang.Object object,
org.hibernate.LockMode lockMode)
Deprecated.
instead call buildLockRequest(LockMode).lock(object)
|
void |
lock(java.lang.String entityName,
java.lang.Object object,
org.hibernate.LockMode lockMode)
Deprecated.
instead call buildLockRequest(LockMode).lock(entityName, object)
|
java.lang.Object |
merge(java.lang.Object object)
Copy the state of the given object onto the persistent object with the same identifier.
|
java.lang.Object |
merge(java.lang.String entityName,
java.lang.Object object)
Copy the state of the given object onto the persistent object with the same identifier.
|
void |
persist(java.lang.Object object)
Make a transient instance persistent.
|
void |
persist(java.lang.String entityName,
java.lang.Object object)
Make a transient instance persistent.
|
void |
refresh(java.lang.Object object)
Re-read the state of the given instance from the underlying database.
|
void |
refresh(java.lang.Object object,
org.hibernate.LockMode lockMode)
Deprecated.
LockMode parameter should be replaced with LockOptions
|
void |
refresh(java.lang.Object object,
org.hibernate.LockOptions lockOptions)
Re-read the state of the given instance from the underlying database, with the given
LockMode.
|
void |
replicate(java.lang.Object object,
org.hibernate.ReplicationMode replicationMode)
Persist the state of the given detached instance, reusing the current identifier value.
|
void |
replicate(java.lang.String entityName,
java.lang.Object object,
org.hibernate.ReplicationMode replicationMode)
Persist the state of the given detached instance, reusing the current identifier value.
|
java.io.Serializable |
save(java.lang.Object object)
Persist the given transient instance, first assigning a generated identifier.
|
java.io.Serializable |
save(java.lang.String entityName,
java.lang.Object object)
Persist the given transient instance, first assigning a generated identifier.
|
void |
saveOrUpdate(java.lang.Object object)
Either
save(Object) or update(Object) the given instance, depending upon
resolution of the unsaved-value checks (see the manual for discussion of unsaved-value
checking). |
void |
saveOrUpdate(java.lang.String entityName,
java.lang.Object object)
Either
save(String, Object) or update(String, Object) the given instance,
depending upon resolution of the unsaved-value checks (see the manual for discussion of
unsaved-value checking). |
void |
setCacheMode(org.hibernate.CacheMode cacheMode)
Set the cache mode.
|
void |
setDefaultReadOnly(boolean readOnly)
Change the default for entities and proxies loaded into this session from modifiable to
read-only mode, or from modifiable to read-only mode.
|
void |
setFlushMode(org.hibernate.FlushMode flushMode)
Set the flush mode for this session.
|
void |
setReadOnly(java.lang.Object entityOrProxy,
boolean readOnly)
Set an unmodified persistent object to read-only mode, or a read-only object to modifiable
mode.
|
void |
update(java.lang.Object object)
Update the persistent instance with the identifier of the given detached instance.
|
void |
update(java.lang.String entityName,
java.lang.Object object)
Update the persistent instance with the identifier of the given detached instance.
|
public org.hibernate.Transaction beginTransaction()
Transaction
object. If a new
underlying transaction is required, begin the transaction. Otherwise continue the new work in
the context of the existing underlying transaction.getTransaction()
public org.hibernate.Transaction getTransaction()
Transaction
instance associated with this session. The concrete type of the
returned Transaction
object is determined by the
hibernate.transaction_factory
property.public org.hibernate.Query getNamedQuery(java.lang.String queryName)
Query
instance for the named query string defined in the metadata.queryName
- the name of a query defined externallypublic org.hibernate.Query createQuery(java.lang.String queryString)
Query
instance for the given HQL query string.queryString
- The HQL querypublic org.hibernate.SQLQuery createSQLQuery(java.lang.String queryString)
SQLQuery
instance for the given SQL query string.queryString
- The SQL querypublic org.hibernate.Criteria createCriteria(java.lang.Class persistentClass)
Criteria
instance for the given class (entity or subclasses/implementors).persistentClass
- The class, which is an entity, or has entity subclasses/implementorspublic org.hibernate.Criteria createCriteria(java.lang.Class persistentClass, java.lang.String alias)
Criteria
instance for the given class (entity or subclasses/implementors),
using a specific alias.persistentClass
- The class, which is an entity, or has entity subclasses/implementorsalias
- The alias to usepublic org.hibernate.Criteria createCriteria(java.lang.String entityName)
Criteria
instance for the given entity name.entityName
- The entity name @return The criteria instance for manipulation and
executionpublic org.hibernate.Criteria createCriteria(java.lang.String entityName, java.lang.String alias)
Criteria
instance for the given entity name, using a specific alias.entityName
- The entity namealias
- The alias to usepublic void flush() throws org.hibernate.HibernateException
setFlushMode(FlushMode)
,
Transaction.commit()
calls this method).
Flushing is the process of synchronizing the underlying persistent store with
persistable state held in memory.org.hibernate.HibernateException
- Indicates problems flushing the session or talking to the
database.public void setFlushMode(org.hibernate.FlushMode flushMode)
FlushMode.MANUAL
at the start of the session (in order to achieve some extra
performance).flushMode
- the new flush modeFlushMode
public org.hibernate.FlushMode getFlushMode()
public void setCacheMode(org.hibernate.CacheMode cacheMode)
cacheMode
- The new cache mode.public org.hibernate.CacheMode getCacheMode()
public org.hibernate.SessionFactory getSessionFactory()
SessionFactory
public java.sql.Connection close() throws org.hibernate.HibernateException
disconnect()
it.org.hibernate.HibernateException
- Indicates problems cleaning up.public void cancelQuery() throws org.hibernate.HibernateException
org.hibernate.HibernateException
- There was a problem canceling the querypublic java.sql.Connection connection() throws org.hibernate.HibernateException
doWork(org.hibernate.jdbc.Work)
; for opening a 'temporary Session' use (TBD).org.hibernate.HibernateException
- if the Session is disconnectedpublic boolean isOpen()
public boolean isConnected()
public boolean isDirty() throws org.hibernate.HibernateException
org.hibernate.HibernateException
- could not perform dirtying checkingpublic boolean isDefaultReadOnly()
Session.isReadOnly(Object)
public void setDefaultReadOnly(boolean readOnly)
readOnly
- true, the default for loaded entities/proxies is read-only; false, the
default for loaded entities/proxies is modifiableTo override this session's read-only/modifiable
setting for entities and proxies loaded by a Query:
,
Query.setReadOnly(boolean)
public java.io.Serializable getIdentifier(java.lang.Object object)
object
- a persistent instanceorg.hibernate.TransientObjectException
- if the instance is transient or associated with a different
sessionpublic boolean contains(java.lang.Object object)
object
- an instance of a persistent classpublic void evict(java.lang.Object object)
object
- The entity to evictjava.lang.NullPointerException
- if the passed object is null
java.lang.IllegalArgumentException
- if the passed object is not defined as an entity@Deprecated public java.lang.Object load(java.lang.Class theClass, java.io.Serializable id, org.hibernate.LockMode lockMode)
theClass
- a persistent classid
- a valid identifier of an existing persistent instance of the classlockMode
- the lock levelpublic java.lang.Object load(java.lang.Class theClass, java.io.Serializable id, org.hibernate.LockOptions lockOptions)
theClass
- a persistent classid
- a valid identifier of an existing persistent instance of the classlockOptions
- contains the lock level@Deprecated public java.lang.Object load(java.lang.String entityName, java.io.Serializable id, org.hibernate.LockMode lockMode)
entityName
- a persistent classid
- a valid identifier of an existing persistent instance of the classlockMode
- the lock levelpublic java.lang.Object load(java.lang.String entityName, java.io.Serializable id, org.hibernate.LockOptions lockOptions)
entityName
- a persistent classid
- a valid identifier of an existing persistent instance of the classlockOptions
- contains the lock levelpublic java.lang.Object load(java.lang.Class theClass, java.io.Serializable id)
theClass
- a persistent classid
- a valid identifier of an existing persistent instance of the classpublic java.lang.Object load(java.lang.String entityName, java.io.Serializable id)
entityName
- a persistent classid
- a valid identifier of an existing persistent instance of the classpublic void load(java.lang.Object object, java.io.Serializable id)
object
- an "empty" instance of the persistent classid
- a valid identifier of an existing persistent instance of the classpublic void replicate(java.lang.Object object, org.hibernate.ReplicationMode replicationMode)
cascade="replicate"
object
- a detached instance of a persistent classreplicationMode
- The replication mode to usepublic void replicate(java.lang.String entityName, java.lang.Object object, org.hibernate.ReplicationMode replicationMode)
cascade="replicate"
entityName
- The entity nameobject
- a detached instance of a persistent classreplicationMode
- The replication mode to usepublic java.io.Serializable save(java.lang.Object object)
cascade="save-update"
object
- a transient instance of a persistent classpublic java.io.Serializable save(java.lang.String entityName, java.lang.Object object)
cascade="save-update"
entityName
- The entity nameobject
- a transient instance of a persistent classpublic void saveOrUpdate(java.lang.Object object)
save(Object)
or update(Object)
the given instance, depending upon
resolution of the unsaved-value checks (see the manual for discussion of unsaved-value
checking).
This operation cascades to associated instances if the association is mapped with
cascade="save-update"
object
- a transient or detached instance containing new or updated stateSession.save(java.lang.Object)
,
Session.update(Object object)
public void saveOrUpdate(java.lang.String entityName, java.lang.Object object)
save(String, Object)
or update(String, Object)
the given instance,
depending upon resolution of the unsaved-value checks (see the manual for discussion of
unsaved-value checking).
This operation cascades to associated instances if the association is mapped with
cascade="save-update"
entityName
- The entity nameobject
- a transient or detached instance containing new or updated stateSession.save(String,Object)
,
Session.update(String,Object)
public void update(java.lang.Object object)
cascade="save-update"
object
- a detached instance containing updated statepublic void update(java.lang.String entityName, java.lang.Object object)
cascade="save-update"
entityName
- The entity nameobject
- a detached instance containing updated statepublic java.lang.Object merge(java.lang.Object object)
cascade="merge"
The semantics of this method are defined by JSR-220.object
- a detached instance with state to be copiedpublic java.lang.Object merge(java.lang.String entityName, java.lang.Object object)
cascade="merge"
The semantics of this method are defined by JSR-220.entityName
- The entity nameobject
- a detached instance with state to be copiedpublic void persist(java.lang.Object object)
cascade="persist"
The semantics of this method are defined by JSR-220.object
- a transient instance to be made persistentpublic void persist(java.lang.String entityName, java.lang.Object object)
cascade="persist"
The semantics of this method are defined by JSR-220.entityName
- The entity nameobject
- a transient instance to be made persistentpublic void delete(java.lang.Object object)
cascade="delete"
object
- the instance to be removedpublic void delete(java.lang.String entityName, java.lang.Object object)
cascade="delete"
entityName
- The entity name for the instance to be removed.object
- the instance to be removed@Deprecated public void lock(java.lang.Object object, org.hibernate.LockMode lockMode)
object
- a persistent or transient instancelockMode
- the lock level@Deprecated public void lock(java.lang.String entityName, java.lang.Object object, org.hibernate.LockMode lockMode)
entityName
- The name of the entityobject
- a persistent or transient instancelockMode
- the lock levelpublic org.hibernate.Session.LockRequest buildLockRequest(org.hibernate.LockOptions lockOptions)
session.buildLockRequest().setLockMode(LockMode.PESSIMISTIC_WRITE).setTimeOut(60000).lock(entity);
lockOptions
- contains the lock levelpublic void refresh(java.lang.Object object)
object
- a persistent or detached instance@Deprecated public void refresh(java.lang.Object object, org.hibernate.LockMode lockMode)
object
- a persistent or detached instancelockMode
- the lock mode to usepublic void refresh(java.lang.Object object, org.hibernate.LockOptions lockOptions)
object
- a persistent or detached instancelockOptions
- contains the lock mode to usepublic org.hibernate.LockMode getCurrentLockMode(java.lang.Object object)
object
- a persistent instancepublic org.hibernate.Query createFilter(java.lang.Object collection, java.lang.String queryString)
Query
instance for the given collection and filter string. Contains an
implicit FROM
element named this
which refers to the defined table for the
collection elements, as well as an implicit WHERE
restriction for this particular
collection instance's key value.collection
- a persistent collectionqueryString
- a Hibernate query fragment.public void clear()
public java.lang.Object get(java.lang.Class clazz, java.io.Serializable id)
clazz
- a persistent classid
- an identifier@Deprecated public java.lang.Object get(java.lang.Class clazz, java.io.Serializable id, org.hibernate.LockMode lockMode)
clazz
- a persistent classid
- an identifierlockMode
- the lock modepublic java.lang.Object get(java.lang.Class clazz, java.io.Serializable id, org.hibernate.LockOptions lockOptions)
clazz
- a persistent classid
- an identifierlockOptions
- the lock modepublic java.lang.Object get(java.lang.String entityName, java.io.Serializable id)
entityName
- the entity nameid
- an identifier@Deprecated public java.lang.Object get(java.lang.String entityName, java.io.Serializable id, org.hibernate.LockMode lockMode)
entityName
- the entity nameid
- an identifierlockMode
- the lock modepublic java.lang.Object get(java.lang.String entityName, java.io.Serializable id, org.hibernate.LockOptions lockOptions)
entityName
- the entity nameid
- an identifierlockOptions
- contains the lock modepublic java.lang.String getEntityName(java.lang.Object object)
object
- a persistent entitypublic org.hibernate.Filter enableFilter(java.lang.String filterName)
filterName
- The name of the filter to be enabled.public org.hibernate.Filter getEnabledFilter(java.lang.String filterName)
filterName
- The name of the filter to be retrieved.public void disableFilter(java.lang.String filterName)
filterName
- The name of the filter to be disabled.public org.hibernate.stat.SessionStatistics getStatistics()
public boolean isReadOnly(java.lang.Object entityOrProxy)
entityOrProxy
- an entity or HibernateProxytrue
if the entity or proxy is read-only, false
if the entity or
proxy is modifiable.Session.isDefaultReadOnly()
public void setReadOnly(java.lang.Object entityOrProxy, boolean readOnly)
entityOrProxy
- an entity or HibernateProxyreadOnly
- true
if the entity or proxy should be made read-only; false
if the entity or proxy should be made modifiableTo override this session's
read-only/modifiable setting for entities and proxies loaded by a Query:
,
Query.setReadOnly(boolean)
public void doWork(org.hibernate.jdbc.Work work) throws org.hibernate.HibernateException
work
- The work to be performed.org.hibernate.HibernateException
- Generally indicates wrapped SQLException
public boolean isFetchProfileEnabled(java.lang.String name) throws org.hibernate.UnknownProfileException
name
- The name of the profile to be checked.org.hibernate.UnknownProfileException
- Indicates that the given name does not match any known
profile namesfor discussion of this feature
public void enableFetchProfile(java.lang.String name) throws org.hibernate.UnknownProfileException
name
- The name of the fetch profile to be enabled.org.hibernate.UnknownProfileException
- Indicates that the given name does not match any known
profile namesfor discussion of this feature
public void disableFetchProfile(java.lang.String name) throws org.hibernate.UnknownProfileException
name
- The name of the fetch profile to be disabled.org.hibernate.UnknownProfileException
- Indicates that the given name does not match any known
profile namesfor discussion of this feature
public org.hibernate.TypeHelper getTypeHelper()
TypeHelper
associated with this session's
SessionFactory
.
Equivalent to calling getSessionFactory()
.getTypeHelper()
TypeHelper
associated with this session's SessionFactory
public org.hibernate.LobHelper getLobHelper()
Copyright © 2018 OpenMRS Inc.. All Rights Reserved.