mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-28 06:49:09 +00:00
HHH-4489 need method "refresh(String entityName, Object obj)"
This commit is contained in:
parent
4be53e9a22
commit
eb5bc1609d
@ -302,6 +302,7 @@ public interface Session extends SharedSessionContract {
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
@Deprecated
|
||||
public Object load(Class theClass, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
@ -327,6 +328,7 @@ public interface Session extends SharedSessionContract {
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
@Deprecated
|
||||
public Object load(String entityName, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
@ -565,6 +567,7 @@ public interface Session extends SharedSessionContract {
|
||||
* @throws HibernateException
|
||||
* @deprecated instead call buildLockRequest(LockMode).lock(object)
|
||||
*/
|
||||
@Deprecated
|
||||
public void lock(Object object, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
@ -579,6 +582,7 @@ public interface Session extends SharedSessionContract {
|
||||
* @throws HibernateException
|
||||
* @deprecated instead call buildLockRequest(LockMode).lock(entityName, object)
|
||||
*/
|
||||
@Deprecated
|
||||
public void lock(String entityName, Object object, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
@ -611,6 +615,23 @@ public interface Session extends SharedSessionContract {
|
||||
*/
|
||||
public void refresh(Object object) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Re-read the state of the given instance from the underlying database. It is
|
||||
* inadvisable to use this to implement long-running sessions that span many
|
||||
* business tasks. This method is, however, useful in certain special circumstances.
|
||||
* For example
|
||||
* <ul>
|
||||
* <li>where a database trigger alters the object state upon insert or update
|
||||
* <li>after executing direct SQL (eg. a mass update) in the same session
|
||||
* <li>after inserting a <tt>Blob</tt> or <tt>Clob</tt>
|
||||
* </ul>
|
||||
*
|
||||
* @param entityName a persistent class
|
||||
* @param object a persistent or detached instance
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void refresh(String entityName, Object object) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Re-read the state of the given instance from the underlying database, with
|
||||
* the given <tt>LockMode</tt>. It is inadvisable to use this to implement
|
||||
@ -622,6 +643,7 @@ public interface Session extends SharedSessionContract {
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
@Deprecated
|
||||
public void refresh(Object object, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
@ -636,6 +658,18 @@ public interface Session extends SharedSessionContract {
|
||||
*/
|
||||
public void refresh(Object object, LockOptions lockOptions) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Re-read the state of the given instance from the underlying database, with
|
||||
* the given <tt>LockMode</tt>. It is inadvisable to use this to implement
|
||||
* long-running sessions that span many business tasks. This method is, however,
|
||||
* useful in certain special circumstances.
|
||||
*
|
||||
* @param entityName a persistent class
|
||||
* @param object a persistent or detached instance
|
||||
* @param lockOptions contains the lock mode to use
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void refresh(String entityName, Object object, LockOptions lockOptions) throws HibernateException;
|
||||
/**
|
||||
* Determine the current lock mode of the given object.
|
||||
*
|
||||
@ -689,6 +723,7 @@ public interface Session extends SharedSessionContract {
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
@Deprecated
|
||||
public Object get(Class clazz, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
@ -730,6 +765,7 @@ public interface Session extends SharedSessionContract {
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
@Deprecated
|
||||
public Object get(String entityName, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
|
@ -361,7 +361,7 @@ public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameter
|
||||
* Set the current <i>internal</i> fetch profile for this session.
|
||||
*
|
||||
* @param name The internal fetch profile name to use
|
||||
* @deprecated use #getLoadQueryInfluencers instead
|
||||
* @deprecated use {@link #getLoadQueryInfluencers} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setFetchProfile(String name);
|
||||
|
@ -137,8 +137,8 @@ public void onRefresh(RefreshEvent event, Map refreshedAlready) {
|
||||
|
||||
evictCachedCollections( persister, id, source.getFactory() );
|
||||
|
||||
String previousFetchProfile = source.getFetchProfile();
|
||||
source.setFetchProfile("refresh");
|
||||
String previousFetchProfile = source.getLoadQueryInfluencers().getInternalFetchProfile();
|
||||
source.getLoadQueryInfluencers().setInternalFetchProfile( "refresh" );
|
||||
Object result = persister.load( id, object, event.getLockOptions(), source );
|
||||
// Keep the same read-only/modifiable setting for the entity that it had before refreshing;
|
||||
// If it was transient, then set it to the default for the source.
|
||||
@ -151,7 +151,7 @@ public void onRefresh(RefreshEvent event, Map refreshedAlready) {
|
||||
source.setReadOnly( result, ( e == null ? source.isDefaultReadOnly() : e.isReadOnly() ) );
|
||||
}
|
||||
}
|
||||
source.setFetchProfile(previousFetchProfile);
|
||||
source.getLoadQueryInfluencers().setInternalFetchProfile(previousFetchProfile);
|
||||
|
||||
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
|
||||
|
||||
@ -165,7 +165,7 @@ private void evictCachedCollections(Type[] types, Serializable id, SessionFactor
|
||||
throws HibernateException {
|
||||
for ( int i = 0; i < types.length; i++ ) {
|
||||
if ( types[i].isCollectionType() ) {
|
||||
factory.evictCollection( ( (CollectionType) types[i] ).getRole(), id );
|
||||
factory.getCache().evictCollection( ( (CollectionType) types[i] ).getRole(), id );
|
||||
}
|
||||
else if ( types[i].isComponentType() ) {
|
||||
CompositeType actype = (CompositeType) types[i];
|
||||
|
@ -34,6 +34,8 @@
|
||||
public class RefreshEvent extends AbstractEvent {
|
||||
|
||||
private Object object;
|
||||
private String entityName;
|
||||
|
||||
private LockOptions lockOptions = new LockOptions().setLockMode(LockMode.READ);
|
||||
|
||||
public RefreshEvent(Object object, EventSource source) {
|
||||
@ -44,6 +46,11 @@ public RefreshEvent(Object object, EventSource source) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public RefreshEvent(String entityName, Object object, EventSource source){
|
||||
this(object, source);
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public RefreshEvent(Object object, LockMode lockMode, EventSource source) {
|
||||
this(object, source);
|
||||
if (lockMode == null) {
|
||||
@ -59,6 +66,10 @@ public RefreshEvent(Object object, LockOptions lockOptions, EventSource source)
|
||||
}
|
||||
this.lockOptions = lockOptions;
|
||||
}
|
||||
public RefreshEvent(String entityName, Object object, LockOptions lockOptions, EventSource source){
|
||||
this(object,lockOptions,source);
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return object;
|
||||
@ -72,6 +83,14 @@ public LockMode getLockMode() {
|
||||
return lockOptions.getLockMode();
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
public void setEntityName(String entityName) {
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public int getLockTimeout() {
|
||||
return this.lockOptions.getTimeOut();
|
||||
}
|
||||
|
@ -1053,7 +1053,12 @@ private void fireLoad(LoadEvent event, LoadType loadType) {
|
||||
// refresh() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public void refresh(Object object) throws HibernateException {
|
||||
fireRefresh( new RefreshEvent(object, this) );
|
||||
refresh( null, object );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(String entityName, Object object) throws HibernateException {
|
||||
fireRefresh( new RefreshEvent( entityName,object,this ) );
|
||||
}
|
||||
|
||||
public void refresh(Object object, LockMode lockMode) throws HibernateException {
|
||||
@ -1061,7 +1066,11 @@ public void refresh(Object object, LockMode lockMode) throws HibernateException
|
||||
}
|
||||
|
||||
public void refresh(Object object, LockOptions lockOptions) throws HibernateException {
|
||||
fireRefresh( new RefreshEvent(object, lockOptions, this) );
|
||||
refresh( null, object, lockOptions );
|
||||
}
|
||||
@Override
|
||||
public void refresh(String entityName, Object object, LockOptions lockOptions) throws HibernateException {
|
||||
fireRefresh( new RefreshEvent(entityName, object, lockOptions, this) );
|
||||
}
|
||||
|
||||
public void refresh(Object object, Map refreshedAlready) throws HibernateException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user