Concrete implementation of a Session, and also the central, organizing component
of Hibernate's internal implementation. As such, this class exposes two interfaces;
Session itself, to the application, and SessionImplementor, to other components
of Hibernate. This class is not threadsafe.
| Method from org.hibernate.impl.SessionImpl Detail: |
public void afterOperation(boolean success) {
if ( !jdbcContext.isTransactionInProgress() ) {
jdbcContext.afterNontransactionalQuery( success );
}
}
Check if there is a Hibernate or JTA transaction in progress and,
if there is not, flush if necessary, make sure the connection has
been committed (if it is not in autocommit mode) and run the after
completion processing |
public void afterScrollOperation() {
// nothing to do in a stateful session
}
|
public void afterTransactionBegin(Transaction tx) {
errorIfClosed();
interceptor.afterTransactionBegin(tx);
}
|
public void afterTransactionCompletion(boolean success,
Transaction tx) {
log.trace( "after transaction completion" );
persistenceContext.afterTransactionCompletion();
actionQueue.afterTransactionCompletion(success);
if ( rootSession == null && tx != null ) {
try {
interceptor.afterTransactionCompletion(tx);
}
catch (Throwable t) {
log.error("exception in interceptor afterTransactionCompletion()", t);
}
}
if ( autoClear ) {
clear();
}
}
|
protected boolean autoFlushIfRequired(Set querySpaces) throws HibernateException {
errorIfClosed();
if ( ! isTransactionInProgress() ) {
// do not auto-flush while outside a transaction
return false;
}
AutoFlushEvent event = new AutoFlushEvent(querySpaces, this);
AutoFlushEventListener[] autoFlushEventListener = listeners.getAutoFlushEventListeners();
for ( int i = 0; i < autoFlushEventListener.length; i++ ) {
autoFlushEventListener[i].onAutoFlush(event);
}
return event.isFlushRequired();
}
detect in-memory changes, determine if the changes are to tables
named in the query and, if so, complete execution the flush |
public void beforeTransactionCompletion(Transaction tx) {
log.trace( "before transaction completion" );
if ( rootSession == null ) {
try {
interceptor.beforeTransactionCompletion(tx);
}
catch (Throwable t) {
log.error("exception in interceptor beforeTransactionCompletion()", t);
}
}
}
|
public Transaction beginTransaction() throws HibernateException {
errorIfClosed();
if ( rootSession != null ) {
// todo : should seriously consider not allowing a txn to begin from a child session
// can always route the request to the root session...
log.warn( "Transaction started on non-root session" );
}
Transaction result = getTransaction();
result.begin();
return result;
}
|
public String bestGuessEntityName(Object object) {
if (object instanceof HibernateProxy) {
LazyInitializer initializer = ( ( HibernateProxy ) object ).getHibernateLazyInitializer();
// it is possible for this method to be called during flush processing,
// so make certain that we do not accidently initialize an uninitialized proxy
if ( initializer.isUninitialized() ) {
return initializer.getEntityName();
}
object = initializer.getImplementation();
}
EntityEntry entry = persistenceContext.getEntry(object);
if (entry==null) {
return guessEntityName(object);
}
else {
return entry.getPersister().getEntityName();
}
}
|
public void cancelQuery() throws HibernateException {
errorIfClosed();
getBatcher().cancelLastQuery();
}
|
public void clear() {
errorIfClosed();
checkTransactionSynchStatus();
persistenceContext.clear();
actionQueue.clear();
}
|
public Connection close() throws HibernateException {
log.trace( "closing session" );
if ( isClosed() ) {
throw new SessionException( "Session was already closed" );
}
if ( factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor().closeSession();
}
try {
try {
if ( childSessionsByEntityMode != null ) {
Iterator childSessions = childSessionsByEntityMode.values().iterator();
while ( childSessions.hasNext() ) {
final SessionImpl child = ( SessionImpl ) childSessions.next();
child.close();
}
}
}
catch( Throwable t ) {
// just ignore
}
if ( rootSession == null ) {
return jdbcContext.getConnectionManager().close();
}
else {
return null;
}
}
finally {
setClosed();
cleanup();
}
}
|
public Connection connection() throws HibernateException {
errorIfClosed();
return jdbcContext.borrowConnection();
}
|
public boolean contains(Object object) {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
//do not use proxiesByKey, since not all
//proxies that point to this session's
//instances are in that collection!
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
//if it is an uninitialized proxy, pointing
//with this session, then when it is accessed,
//the underlying instance will be "contained"
return li.getSession()==this;
}
else {
//if it is initialized, see if the underlying
//instance is contained, since we need to
//account for the fact that it might have been
//evicted
object = li.getImplementation();
}
}
// A session is considered to contain an entity only if the entity has
// an entry in the session's persistence context and the entry reports
// that the entity has not been removed
EntityEntry entry = persistenceContext.getEntry( object );
return entry != null && entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
}
|
public Criteria createCriteria(Class persistentClass) {
errorIfClosed();
checkTransactionSynchStatus();
return new CriteriaImpl( persistentClass.getName(), this );
}
|
public Criteria createCriteria(String entityName) {
errorIfClosed();
checkTransactionSynchStatus();
return new CriteriaImpl(entityName, this);
}
|
public Criteria createCriteria(Class persistentClass,
String alias) {
errorIfClosed();
checkTransactionSynchStatus();
return new CriteriaImpl( persistentClass.getName(), alias, this );
}
|
public Criteria createCriteria(String entityName,
String alias) {
errorIfClosed();
checkTransactionSynchStatus();
return new CriteriaImpl(entityName, alias, this);
}
|
public Query createFilter(Object collection,
String queryString) {
errorIfClosed();
checkTransactionSynchStatus();
CollectionFilterImpl filter = new CollectionFilterImpl(
queryString,
collection,
this,
getFilterQueryPlan( collection, queryString, null, false ).getParameterMetadata()
);
filter.setComment( queryString );
return filter;
}
|
public Query createQuery(String queryString) {
errorIfClosed();
checkTransactionSynchStatus();
return super.createQuery(queryString);
}
|
public SQLQuery createSQLQuery(String sql) {
errorIfClosed();
checkTransactionSynchStatus();
return super.createSQLQuery(sql);
}
|
public Query createSQLQuery(String sql,
String returnAlias,
Class returnClass) {
errorIfClosed();
checkTransactionSynchStatus();
return new SQLQueryImpl(
sql,
new String[] { returnAlias },
new Class[] { returnClass },
this,
factory.getQueryPlanCache().getSQLParameterMetadata( sql )
);
}
|
public Query createSQLQuery(String sql,
String[] returnAliases,
Class[] returnClasses) {
errorIfClosed();
checkTransactionSynchStatus();
return new SQLQueryImpl(
sql,
returnAliases,
returnClasses,
this,
factory.getQueryPlanCache().getSQLParameterMetadata( sql )
);
}
|
public void delete(Object object) throws HibernateException {
fireDelete( new DeleteEvent(object, this) );
}
Delete a persistent object |
public int delete(String query) throws HibernateException {
return delete( query, ArrayHelper.EMPTY_OBJECT_ARRAY, ArrayHelper.EMPTY_TYPE_ARRAY );
}
|
public void delete(String entityName,
Object object) throws HibernateException {
fireDelete( new DeleteEvent( entityName, object, this ) );
}
Delete a persistent object (by explicit entity name) |
public int delete(String query,
Object value,
Type type) throws HibernateException {
return delete( query, new Object[]{value}, new Type[]{type} );
}
|
public int delete(String query,
Object[] values,
Type[] types) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( query == null ) {
throw new IllegalArgumentException("attempt to perform delete-by-query with null query");
}
if ( log.isTraceEnabled() ) {
log.trace( "delete: " + query );
if ( values.length != 0 ) {
log.trace( "parameters: " + StringHelper.toString( values ) );
}
}
List list = find( query, values, types );
int deletionCount = list.size();
for ( int i = 0; i < deletionCount; i++ ) {
delete( list.get( i ) );
}
return deletionCount;
}
|
public void delete(String entityName,
Object object,
boolean isCascadeDeleteEnabled,
Set transientEntities) throws HibernateException {
fireDelete( new DeleteEvent( entityName, object, isCascadeDeleteEnabled, this ), transientEntities );
}
Delete a persistent object |
public void disableFilter(String filterName) {
errorIfClosed();
checkTransactionSynchStatus();
enabledFilters.remove(filterName);
}
|
public Connection disconnect() throws HibernateException {
errorIfClosed();
log.debug( "disconnecting session" );
return jdbcContext.getConnectionManager().manualDisconnect();
}
|
public void doWork(Work work) throws HibernateException {
try {
work.execute( jdbcContext.getConnectionManager().getConnection() );
jdbcContext.getConnectionManager().afterStatement();
}
catch ( SQLException e ) {
throw JDBCExceptionHelper.convert( factory.getSettings().getSQLExceptionConverter(), e, "error executing work" );
}
}
|
public Filter enableFilter(String filterName) {
errorIfClosed();
checkTransactionSynchStatus();
FilterImpl filter = new FilterImpl( factory.getFilterDefinition(filterName) );
enabledFilters.put(filterName, filter);
return filter;
}
|
public void evict(Object object) throws HibernateException {
fireEvict( new EvictEvent(object, this) );
}
remove any hard references to the entity that are held by the infrastructure
(references held by application or other persistant instances are okay) |
public int executeNativeUpdate(NativeSQLQuerySpecification nativeQuerySpecification,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
queryParameters.validateParameters();
NativeSQLQueryPlan plan = getNativeSQLQueryPlan(nativeQuerySpecification);
autoFlushIfRequired( plan.getCustomQuery().getQuerySpaces() );
boolean success = false;
int result = 0;
try {
result = plan.performExecuteUpdate(queryParameters, this);
success = true;
} finally {
afterOperation(success);
}
return result;
}
|
public int executeUpdate(String query,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
queryParameters.validateParameters();
HQLQueryPlan plan = getHQLQueryPlan( query, false );
autoFlushIfRequired( plan.getQuerySpaces() );
boolean success = false;
int result = 0;
try {
result = plan.performExecuteUpdate( queryParameters, this );
success = true;
}
finally {
afterOperation(success);
}
return result;
}
|
public Collection filter(Object collection,
String filter) throws HibernateException {
return listFilter( collection, filter, new QueryParameters( new Type[1], new Object[1] ) );
}
|
public Collection filter(Object collection,
String filter,
Object value,
Type type) throws HibernateException {
return listFilter( collection, filter, new QueryParameters( new Type[]{null, type}, new Object[]{null, value} ) );
}
|
public Collection filter(Object collection,
String filter,
Object[] values,
Type[] types) throws HibernateException {
Object[] vals = new Object[values.length + 1];
Type[] typs = new Type[types.length + 1];
System.arraycopy( values, 0, vals, 1, values.length );
System.arraycopy( types, 0, typs, 1, types.length );
return listFilter( collection, filter, new QueryParameters( typs, vals ) );
}
|
public List find(String query) throws HibernateException {
return list( query, new QueryParameters() );
}
Retrieve a list of persistent objects using a hibernate query |
public List find(String query,
Object value,
Type type) throws HibernateException {
return list( query, new QueryParameters(type, value) );
}
|
public List find(String query,
Object[] values,
Type[] types) throws HibernateException {
return list( query, new QueryParameters(types, values) );
}
|
public void flush() throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( persistenceContext.getCascadeLevel() > 0 ) {
throw new HibernateException("Flush during cascade is dangerous");
}
FlushEventListener[] flushEventListener = listeners.getFlushEventListeners();
for ( int i = 0; i < flushEventListener.length; i++ ) {
flushEventListener[i].onFlush( new FlushEvent(this) );
}
}
|
public void forceFlush(EntityEntry entityEntry) throws HibernateException {
errorIfClosed();
if ( log.isDebugEnabled() ) {
log.debug(
"flushing to force deletion of re-saved object: " +
MessageHelper.infoString( entityEntry.getPersister(), entityEntry.getId(), getFactory() )
);
}
if ( persistenceContext.getCascadeLevel() > 0 ) {
throw new ObjectDeletedException(
"deleted object would be re-saved by cascade (remove deleted object from associations)",
entityEntry.getId(),
entityEntry.getPersister().getEntityName()
);
}
flush();
}
|
public Object get(Class entityClass,
Serializable id) throws HibernateException {
return get( entityClass.getName(), id );
}
|
public Object get(String entityName,
Serializable id) throws HibernateException {
LoadEvent event = new LoadEvent(id, entityName, false, this);
boolean success = false;
try {
fireLoad(event, LoadEventListener.GET);
success = true;
return event.getResult();
}
finally {
afterOperation(success);
}
}
|
public Object get(Class entityClass,
Serializable id,
LockMode lockMode) throws HibernateException {
return get( entityClass.getName(), id, lockMode );
}
|
public Object get(String entityName,
Serializable id,
LockMode lockMode) throws HibernateException {
LoadEvent event = new LoadEvent(id, entityName, lockMode, this);
fireLoad(event, LoadEventListener.GET);
return event.getResult();
}
|
public ActionQueue getActionQueue() {
errorIfClosed();
checkTransactionSynchStatus();
return actionQueue;
}
|
public Batcher getBatcher() {
errorIfClosed();
checkTransactionSynchStatus();
// TODO : should remove this exposure
// and have all references to the session's batcher use the ConnectionManager.
return jdbcContext.getConnectionManager().getBatcher();
}
|
public CacheMode getCacheMode() {
checkTransactionSynchStatus();
return cacheMode;
}
|
public ConnectionReleaseMode getConnectionReleaseMode() {
checkTransactionSynchStatus();
return connectionReleaseMode;
}
|
public Serializable getContextEntityIdentifier(Object object) {
errorIfClosed();
if ( object instanceof HibernateProxy ) {
return getProxyIdentifier(object);
}
else {
EntityEntry entry = persistenceContext.getEntry(object);
return entry != null ? entry.getId() : null;
}
}
Get the id value for an object that is actually associated with the session. This
is a bit stricter than getEntityIdentifierIfNotUnsaved(). |
public LockMode getCurrentLockMode(Object object) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( object == null ) {
throw new NullPointerException( "null object passed to getCurrentLockMode()" );
}
if ( object instanceof HibernateProxy ) {
object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(this);
if ( object == null ) {
return LockMode.NONE;
}
}
EntityEntry e = persistenceContext.getEntry(object);
if ( e == null ) {
throw new TransientObjectException( "Given object not associated with the session" );
}
if ( e.getStatus() != Status.MANAGED ) {
throw new ObjectDeletedException(
"The given object was deleted",
e.getId(),
e.getPersister().getEntityName()
);
}
return e.getLockMode();
}
|
public int getDontFlushFromFind() {
return dontFlushFromFind;
}
|
public Filter getEnabledFilter(String filterName) {
checkTransactionSynchStatus();
return (Filter) enabledFilters.get(filterName);
}
|
public Map getEnabledFilters() {
errorIfClosed();
checkTransactionSynchStatus();
// First, validate all the enabled filters...
//TODO: this implementation has bad performance
Iterator itr = enabledFilters.values().iterator();
while ( itr.hasNext() ) {
final Filter filter = (Filter) itr.next();
filter.validate();
}
return enabledFilters;
}
|
public EntityMode getEntityMode() {
checkTransactionSynchStatus();
return entityMode;
}
|
public String getEntityName(Object object) {
errorIfClosed();
checkTransactionSynchStatus();
if (object instanceof HibernateProxy) {
if ( !persistenceContext.containsProxy( object ) ) {
throw new TransientObjectException("proxy was not associated with the session");
}
object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation();
}
EntityEntry entry = persistenceContext.getEntry(object);
if ( entry == null ) {
throwTransientObjectException( object );
}
return entry.getPersister().getEntityName();
}
|
public EntityPersister getEntityPersister(String entityName,
Object object) {
errorIfClosed();
if (entityName==null) {
return factory.getEntityPersister( guessEntityName( object ) );
}
else {
// try block is a hack around fact that currently tuplizers are not
// given the opportunity to resolve a subclass entity name. this
// allows the (we assume custom) interceptor the ability to
// influence this decision if we were not able to based on the
// given entityName
try {
return factory.getEntityPersister( entityName )
.getSubclassEntityPersister( object, getFactory(), entityMode );
}
catch( HibernateException e ) {
try {
return getEntityPersister( null, object );
}
catch( HibernateException e2 ) {
throw e;
}
}
}
}
|
public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException {
errorIfClosed();
// todo : should this get moved to PersistentContext?
// logically, is PersistentContext the "thing" to which an interceptor gets attached?
final Object result = persistenceContext.getEntity(key);
if ( result == null ) {
final Object newObject = interceptor.getEntity( key.getEntityName(), key.getIdentifier() );
if ( newObject != null ) {
lock( newObject, LockMode.NONE );
}
return newObject;
}
else {
return result;
}
}
|
public String getFetchProfile() {
checkTransactionSynchStatus();
return fetchProfile;
}
|
public Type getFilterParameterType(String filterParameterName) {
errorIfClosed();
checkTransactionSynchStatus();
String[] parsed = parseFilterParameterName(filterParameterName);
FilterDefinition filterDef = factory.getFilterDefinition( parsed[0] );
if (filterDef == null) {
throw new IllegalArgumentException("Filter [" + parsed[0] + "] not defined");
}
Type type = filterDef.getParameterType( parsed[1] );
if (type == null) {
// this is an internal error of some sort...
throw new InternalError("Unable to locate type for filter parameter");
}
return type;
}
|
public Object getFilterParameterValue(String filterParameterName) {
errorIfClosed();
checkTransactionSynchStatus();
String[] parsed = parseFilterParameterName(filterParameterName);
FilterImpl filter = (FilterImpl) enabledFilters.get( parsed[0] );
if (filter == null) {
throw new IllegalArgumentException("Filter [" + parsed[0] + "] currently not enabled");
}
return filter.getParameter( parsed[1] );
}
|
public FlushMode getFlushMode() {
checkTransactionSynchStatus();
return flushMode;
}
|
public Serializable getIdentifier(Object object) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.getSession() != this ) {
throw new TransientObjectException( "The proxy was not associated with this session" );
}
return li.getIdentifier();
}
else {
EntityEntry entry = persistenceContext.getEntry(object);
if ( entry == null ) {
throw new TransientObjectException( "The instance was not associated with this session" );
}
return entry.getId();
}
}
|
public Interceptor getInterceptor() {
checkTransactionSynchStatus();
return interceptor;
}
|
public JDBCContext getJDBCContext() {
errorIfClosed();
checkTransactionSynchStatus();
return jdbcContext;
}
|
public EventListeners getListeners() {
return listeners;
}
|
public Query getNamedQuery(String queryName) throws MappingException {
errorIfClosed();
checkTransactionSynchStatus();
return super.getNamedQuery(queryName);
}
|
public PersistenceContext getPersistenceContext() {
errorIfClosed();
checkTransactionSynchStatus();
return persistenceContext;
}
|
public Session getSession(EntityMode entityMode) {
if ( this.entityMode == entityMode ) {
return this;
}
if ( rootSession != null ) {
rootSession.getSession( entityMode );
}
errorIfClosed();
checkTransactionSynchStatus();
SessionImpl rtn = null;
if ( childSessionsByEntityMode == null ) {
childSessionsByEntityMode = new HashMap();
}
else {
rtn = (SessionImpl) childSessionsByEntityMode.get( entityMode );
}
if ( rtn == null ) {
rtn = new SessionImpl( this, entityMode );
childSessionsByEntityMode.put( entityMode, rtn );
}
return rtn;
}
|
public SessionFactory getSessionFactory() {
checkTransactionSynchStatus();
return factory;
}
|
public SessionStatistics getStatistics() {
checkTransactionSynchStatus();
return new SessionStatisticsImpl(this);
}
|
public long getTimestamp() {
checkTransactionSynchStatus();
return timestamp;
}
|
public Transaction getTransaction() throws HibernateException {
errorIfClosed();
return jdbcContext.getTransaction();
}
|
public String guessEntityName(Object object) throws HibernateException {
errorIfClosed();
return entityNameResolver.resolveEntityName( object );
}
|
public Object immediateLoad(String entityName,
Serializable id) throws HibernateException {
if ( log.isDebugEnabled() ) {
EntityPersister persister = getFactory().getEntityPersister(entityName);
log.debug( "initializing proxy: " + MessageHelper.infoString( persister, id, getFactory() ) );
}
LoadEvent event = new LoadEvent(id, entityName, true, this);
fireLoad(event, LoadEventListener.IMMEDIATE_LOAD);
return event.getResult();
}
Load the data for the object with the specified id into a newly created object.
This is only called when lazily initializing a proxy.
Do NOT return a proxy. |
public void initializeCollection(PersistentCollection collection,
boolean writing) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
InitializeCollectionEventListener[] listener = listeners.getInitializeCollectionEventListeners();
for ( int i = 0; i < listener.length; i++ ) {
listener[i].onInitializeCollection( new InitializeCollectionEvent(collection, this) );
}
}
|
public Object instantiate(String entityName,
Serializable id) throws HibernateException {
return instantiate( factory.getEntityPersister(entityName), id );
}
|
public Object instantiate(EntityPersister persister,
Serializable id) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
Object result = interceptor.instantiate( persister.getEntityName(), entityMode, id );
if ( result == null ) {
result = persister.instantiate( id, entityMode );
}
return result;
}
give the interceptor an opportunity to override the default instantiation |
public Object internalLoad(String entityName,
Serializable id,
boolean eager,
boolean nullable) throws HibernateException {
// todo : remove
LoadEventListener.LoadType type = nullable ?
LoadEventListener.INTERNAL_LOAD_NULLABLE :
eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
LoadEvent event = new LoadEvent(id, entityName, true, this);
fireLoad(event, type);
if ( !nullable ) {
UnresolvableObjectException.throwIfNull( event.getResult(), id, entityName );
}
return event.getResult();
}
|
public boolean isAutoCloseSessionEnabled() {
return autoCloseSessionEnabled;
}
|
public boolean isConnected() {
checkTransactionSynchStatus();
return !isClosed() && jdbcContext.getConnectionManager().isCurrentlyConnected();
}
|
public boolean isDirty() throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
log.debug("checking session dirtiness");
if ( actionQueue.areInsertionsOrDeletionsQueued() ) {
log.debug("session dirty (scheduled updates and insertions)");
return true;
}
else {
DirtyCheckEvent event = new DirtyCheckEvent(this);
DirtyCheckEventListener[] dirtyCheckEventListener = listeners.getDirtyCheckEventListeners();
for ( int i = 0; i < dirtyCheckEventListener.length; i++ ) {
dirtyCheckEventListener[i].onDirtyCheck(event);
}
return event.isDirty();
}
}
|
public boolean isEventSource() {
checkTransactionSynchStatus();
return true;
}
|
public boolean isFlushBeforeCompletionEnabled() {
return flushBeforeCompletionEnabled;
}
|
public boolean isFlushModeNever() {
return FlushMode.isManualFlushMode( getFlushMode() );
}
|
public boolean isOpen() {
checkTransactionSynchStatus();
return !isClosed();
}
|
public boolean isTransactionInProgress() {
checkTransactionSynchStatus();
return !isClosed() && jdbcContext.isTransactionInProgress();
}
|
public Iterator iterate(String query) throws HibernateException {
return iterate( query, new QueryParameters() );
}
|
public Iterator iterate(String query,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
queryParameters.validateParameters();
HQLQueryPlan plan = getHQLQueryPlan( query, true );
autoFlushIfRequired( plan.getQuerySpaces() );
dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
try {
return plan.performIterate( queryParameters, this );
}
finally {
dontFlushFromFind--;
}
}
|
public Iterator iterate(String query,
Object value,
Type type) throws HibernateException {
return iterate( query, new QueryParameters(type, value) );
}
|
public Iterator iterate(String query,
Object[] values,
Type[] types) throws HibernateException {
return iterate( query, new QueryParameters(types, values) );
}
|
public Iterator iterateFilter(Object collection,
String filter,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
FilterQueryPlan plan = getFilterQueryPlan( collection, filter, queryParameters, true );
return plan.performIterate( queryParameters, this );
}
|
public List list(CriteriaImpl criteria) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
String[] implementors = factory.getImplementors( criteria.getEntityOrClassName() );
int size = implementors.length;
CriteriaLoader[] loaders = new CriteriaLoader[size];
Set spaces = new HashSet();
for( int i=0; i < size; i++ ) {
loaders[i] = new CriteriaLoader(
getOuterJoinLoadable( implementors[i] ),
factory,
criteria,
implementors[i],
getEnabledFilters()
);
spaces.addAll( loaders[i].getQuerySpaces() );
}
autoFlushIfRequired(spaces);
List results = Collections.EMPTY_LIST;
dontFlushFromFind++;
boolean success = false;
try {
for( int i=0; i< size; i++ ) {
final List currentResults = loaders[i].list(this);
currentResults.addAll(results);
results = currentResults;
}
success = true;
}
finally {
dontFlushFromFind--;
afterOperation(success);
}
return results;
}
|
public List list(String query,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
queryParameters.validateParameters();
HQLQueryPlan plan = getHQLQueryPlan( query, false );
autoFlushIfRequired( plan.getQuerySpaces() );
List results = CollectionHelper.EMPTY_LIST;
boolean success = false;
dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
try {
results = plan.performList( queryParameters, this );
success = true;
}
finally {
dontFlushFromFind--;
afterOperation(success);
}
return results;
}
|
public List listCustomQuery(CustomQuery customQuery,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( log.isTraceEnabled() ) {
log.trace( "SQL query: " + customQuery.getSQL() );
}
CustomLoader loader = new CustomLoader( customQuery, getFactory() );
autoFlushIfRequired( loader.getQuerySpaces() );
dontFlushFromFind++;
boolean success = false;
try {
List results = loader.list(this, queryParameters);
success = true;
return results;
}
finally {
dontFlushFromFind--;
afterOperation(success);
}
}
|
public List listFilter(Object collection,
String filter,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
FilterQueryPlan plan = getFilterQueryPlan( collection, filter, queryParameters, false );
List results = CollectionHelper.EMPTY_LIST;
boolean success = false;
dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
try {
results = plan.performList( queryParameters, this );
success = true;
}
finally {
dontFlushFromFind--;
afterOperation(success);
}
return results;
}
|
public void load(Object object,
Serializable id) throws HibernateException {
LoadEvent event = new LoadEvent(id, object, this);
fireLoad( event, LoadEventListener.RELOAD );
}
|
public Object load(Class entityClass,
Serializable id) throws HibernateException {
return load( entityClass.getName(), id );
}
|
public Object load(String entityName,
Serializable id) throws HibernateException {
LoadEvent event = new LoadEvent(id, entityName, false, this);
boolean success = false;
try {
fireLoad( event, LoadEventListener.LOAD );
if ( event.getResult() == null ) {
getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id );
}
success = true;
return event.getResult();
}
finally {
afterOperation(success);
}
}
|
public Object load(Class entityClass,
Serializable id,
LockMode lockMode) throws HibernateException {
return load( entityClass.getName(), id, lockMode );
}
|
public Object load(String entityName,
Serializable id,
LockMode lockMode) throws HibernateException {
LoadEvent event = new LoadEvent(id, entityName, lockMode, this);
fireLoad( event, LoadEventListener.LOAD );
return event.getResult();
}
|
public void lock(Object object,
LockMode lockMode) throws HibernateException {
fireLock( new LockEvent(object, lockMode, this) );
}
|
public void lock(String entityName,
Object object,
LockMode lockMode) throws HibernateException {
fireLock( new LockEvent(entityName, object, lockMode, this) );
}
|
public void managedClose() {
log.trace( "automatically closing session" );
close();
}
|
public void managedFlush() {
if ( isClosed() ) {
log.trace( "skipping auto-flush due to session closed" );
return;
}
log.trace("automatically flushing session");
flush();
if ( childSessionsByEntityMode != null ) {
Iterator iter = childSessionsByEntityMode.values().iterator();
while ( iter.hasNext() ) {
( (Session) iter.next() ).flush();
}
}
}
|
public Object merge(Object object) throws HibernateException {
return merge(null, object);
}
|
public Object merge(String entityName,
Object object) throws HibernateException {
return fireMerge( new MergeEvent(entityName, object, this) );
}
|
public void merge(String entityName,
Object object,
Map copiedAlready) throws HibernateException {
fireMerge( copiedAlready, new MergeEvent(entityName, object, this) );
}
|
public void persist(Object object) throws HibernateException {
persist(null, object);
}
|
public void persist(String entityName,
Object object) throws HibernateException {
firePersist( new PersistEvent(entityName, object, this) );
}
|
public void persist(String entityName,
Object object,
Map copiedAlready) throws HibernateException {
firePersist( copiedAlready, new PersistEvent(entityName, object, this) );
}
|
public void persistOnFlush(Object object) throws HibernateException {
persist(null, object);
}
|
public void persistOnFlush(String entityName,
Object object) throws HibernateException {
firePersistOnFlush( new PersistEvent(entityName, object, this) );
}
|
public void persistOnFlush(String entityName,
Object object,
Map copiedAlready) throws HibernateException {
firePersistOnFlush( copiedAlready, new PersistEvent(entityName, object, this) );
}
|
public void reconnect() throws HibernateException {
errorIfClosed();
log.debug( "reconnecting session" );
checkTransactionSynchStatus();
jdbcContext.getConnectionManager().manualReconnect();
}
|
public void reconnect(Connection conn) throws HibernateException {
errorIfClosed();
log.debug( "reconnecting session" );
checkTransactionSynchStatus();
jdbcContext.getConnectionManager().manualReconnect( conn );
}
|
public void refresh(Object object) throws HibernateException {
fireRefresh( new RefreshEvent(object, this) );
}
|
public void refresh(Object object,
LockMode lockMode) throws HibernateException {
fireRefresh( new RefreshEvent(object, lockMode, this) );
}
|
public void refresh(Object object,
Map refreshedAlready) throws HibernateException {
fireRefresh( refreshedAlready, new RefreshEvent(object, this) );
}
|
public void replicate(Object obj,
ReplicationMode replicationMode) throws HibernateException {
fireReplicate( new ReplicateEvent(obj, replicationMode, this) );
}
|
public void replicate(String entityName,
Object obj,
ReplicationMode replicationMode) throws HibernateException {
fireReplicate( new ReplicateEvent(entityName, obj, replicationMode, this) );
}
|
public Serializable save(Object obj) throws HibernateException {
return save(null, obj);
}
|
public void save(Object obj,
Serializable id) throws HibernateException {
save(null, obj, id);
}
|
public Serializable save(String entityName,
Object object) throws HibernateException {
return fireSave( new SaveOrUpdateEvent(entityName, object, this) );
}
|
public void save(String entityName,
Object object,
Serializable id) throws HibernateException {
fireSave( new SaveOrUpdateEvent(entityName, object, id, this) );
}
|
public void saveOrUpdate(Object object) throws HibernateException {
saveOrUpdate(null, object);
}
|
public void saveOrUpdate(String entityName,
Object obj) throws HibernateException {
fireSaveOrUpdate( new SaveOrUpdateEvent(entityName, obj, this) );
}
|
public Object saveOrUpdateCopy(Object object) throws HibernateException {
return saveOrUpdateCopy( null, object );
}
|
public Object saveOrUpdateCopy(String entityName,
Object object) throws HibernateException {
return fireSaveOrUpdateCopy( new MergeEvent(entityName, object, this) );
}
|
public Object saveOrUpdateCopy(Object object,
Serializable id) throws HibernateException {
return saveOrUpdateCopy( null, object, id );
}
|
public Object saveOrUpdateCopy(String entityName,
Object object,
Serializable id) throws HibernateException {
return fireSaveOrUpdateCopy( new MergeEvent(entityName, object, id, this) );
}
|
public void saveOrUpdateCopy(String entityName,
Object object,
Map copiedAlready) throws HibernateException {
fireSaveOrUpdateCopy( copiedAlready, new MergeEvent( entityName, object, this ) );
}
|
public ScrollableResults scroll(String query,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
HQLQueryPlan plan = getHQLQueryPlan( query, false );
autoFlushIfRequired( plan.getQuerySpaces() );
dontFlushFromFind++;
try {
return plan.performScroll( queryParameters, this );
}
finally {
dontFlushFromFind--;
}
}
|
public ScrollableResults scroll(CriteriaImpl criteria,
ScrollMode scrollMode) {
errorIfClosed();
checkTransactionSynchStatus();
String entityName = criteria.getEntityOrClassName();
CriteriaLoader loader = new CriteriaLoader(
getOuterJoinLoadable(entityName),
factory,
criteria,
entityName,
getEnabledFilters()
);
autoFlushIfRequired( loader.getQuerySpaces() );
dontFlushFromFind++;
try {
return loader.scroll(this, scrollMode);
}
finally {
dontFlushFromFind--;
}
}
|
public ScrollableResults scrollCustomQuery(CustomQuery customQuery,
QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( log.isTraceEnabled() ) {
log.trace( "scroll SQL query: " + customQuery.getSQL() );
}
CustomLoader loader = new CustomLoader( customQuery, getFactory() );
autoFlushIfRequired( loader.getQuerySpaces() );
dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
try {
return loader.scroll(queryParameters, this);
}
finally {
dontFlushFromFind--;
}
}
|
public void setAutoClear(boolean enabled) {
errorIfClosed();
autoClear = enabled;
}
|
public void setCacheMode(CacheMode cacheMode) {
errorIfClosed();
checkTransactionSynchStatus();
if ( log.isTraceEnabled() ) {
log.trace("setting cache mode to: " + cacheMode);
}
this.cacheMode= cacheMode;
}
|
public void setFetchProfile(String fetchProfile) {
errorIfClosed();
checkTransactionSynchStatus();
this.fetchProfile = fetchProfile;
}
|
public void setFlushMode(FlushMode flushMode) {
errorIfClosed();
checkTransactionSynchStatus();
if ( log.isTraceEnabled() ) {
log.trace("setting flush mode to: " + flushMode);
}
this.flushMode = flushMode;
}
|
public void setReadOnly(Object entity,
boolean readOnly) {
errorIfClosed();
checkTransactionSynchStatus();
persistenceContext.setReadOnly(entity, readOnly);
}
|
public boolean shouldAutoClose() {
return isAutoCloseSessionEnabled() && !isClosed();
}
|
public String toString() {
StringBuffer buf = new StringBuffer(500)
.append( "SessionImpl(" );
if ( !isClosed() ) {
buf.append(persistenceContext)
.append(";")
.append(actionQueue);
}
else {
buf.append("< closed >");
}
return buf.append(')').toString();
}
|
public void update(Object obj) throws HibernateException {
update(null, obj);
}
|
public void update(Object obj,
Serializable id) throws HibernateException {
update(null, obj, id);
}
|
public void update(String entityName,
Object object) throws HibernateException {
fireUpdate( new SaveOrUpdateEvent(entityName, object, this) );
}
|
public void update(String entityName,
Object object,
Serializable id) throws HibernateException {
fireUpdate(new SaveOrUpdateEvent(entityName, object, id, this));
}
|