HHH-4546 add JPA 2.0 locking. Introduce LockOptions as the wrapper and session.buildLockRequest() (replaces session.lock()).
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18053 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
49f7b49bdc
commit
ceaea5a2a3
|
@ -29,7 +29,7 @@ package org.hibernate;
|
|||
*
|
||||
* @author Scott Marlow
|
||||
*/
|
||||
public class LockRequest
|
||||
public class LockOptions
|
||||
{
|
||||
|
||||
public static final int NO_WAIT = 0;
|
||||
|
@ -42,14 +42,13 @@ public class LockRequest
|
|||
private boolean scope=false;// if true, cascade (pessimistic only) lock to collections and relationships
|
||||
// owned by the entity.
|
||||
|
||||
public LockRequest() {
|
||||
public LockOptions() {
|
||||
|
||||
}
|
||||
|
||||
public LockRequest( LockMode lockMode, int timeout, boolean scope ) {
|
||||
|
||||
|
||||
public LockOptions( LockMode lockMode) {
|
||||
this.lockMode = lockMode;
|
||||
this.timeout = timeout;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +65,7 @@ public class LockRequest
|
|||
* @param lockMode
|
||||
* @return this LockRequest instance for operation chaining.
|
||||
*/
|
||||
public LockRequest setLockMode(LockMode lockMode) {
|
||||
public LockOptions setLockMode(LockMode lockMode) {
|
||||
this.lockMode = lockMode;
|
||||
return this;
|
||||
}
|
||||
|
@ -87,7 +86,7 @@ public class LockRequest
|
|||
* @param timeout is time in milliseconds to wait for lock. -1 means wait forever and 0 means no wait.
|
||||
* @return this LockRequest instance for operation chaining.
|
||||
*/
|
||||
public LockRequest setTimeOut(int timeout) {
|
||||
public LockOptions setTimeOut(int timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
|
@ -107,7 +106,7 @@ public class LockRequest
|
|||
* @param scope
|
||||
* @return
|
||||
*/
|
||||
public LockRequest setScope(boolean scope) {
|
||||
public LockOptions setScope(boolean scope) {
|
||||
this.scope = scope;
|
||||
return this;
|
||||
}
|
|
@ -270,7 +270,7 @@ public interface Session extends Serializable {
|
|||
* @param lockMode the lock level
|
||||
* @return the persistent instance or proxy
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with a LockRequest
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
public Object load(Class theClass, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
|
@ -280,11 +280,11 @@ public interface Session extends Serializable {
|
|||
*
|
||||
* @param theClass a persistent class
|
||||
* @param id a valid identifier of an existing persistent instance of the class
|
||||
* @param lockRequest contains the lock level
|
||||
* @param lockOptions contains the lock level
|
||||
* @return the persistent instance or proxy
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public Object load(Class theClass, Serializable id, LockRequest lockRequest) throws HibernateException;
|
||||
public Object load(Class theClass, Serializable id, LockOptions lockOptions) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Return the persistent instance of the given entity class with the given identifier,
|
||||
|
@ -295,7 +295,7 @@ public interface Session extends Serializable {
|
|||
* @param lockMode the lock level
|
||||
* @return the persistent instance or proxy
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with a LockRequest
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
public Object load(String entityName, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
|
@ -305,11 +305,11 @@ public interface Session extends Serializable {
|
|||
*
|
||||
* @param entityName a persistent class
|
||||
* @param id a valid identifier of an existing persistent instance of the class
|
||||
* @param lockRequest contains the lock level
|
||||
* @param lockOptions contains the lock level
|
||||
* @return the persistent instance or proxy
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public Object load(String entityName, Serializable id, LockRequest lockRequest) throws HibernateException;
|
||||
public Object load(String entityName, Serializable id, LockOptions lockOptions) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Return the persistent instance of the given entity class with the given identifier,
|
||||
|
@ -533,23 +533,10 @@ public interface Session extends Serializable {
|
|||
* @param object a persistent or transient instance
|
||||
* @param lockMode the lock level
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with a LockRequest
|
||||
* @deprecated instead call buildLockRequest(LockMode).lock(object)
|
||||
*/
|
||||
public void lock(Object object, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Obtain the specified lock level upon the given object. This may be used to
|
||||
* perform a version check (<tt>LockMode.OPTIMISTIC</tt>), to upgrade to a pessimistic
|
||||
* lock (<tt>LockMode.PESSIMISTIC_WRITE</tt>), or to simply reassociate a transient instance
|
||||
* with a session (<tt>LockMode.NONE</tt>). This operation cascades to associated
|
||||
* instances if the association is mapped with <tt>cascade="lock" and lockRequest.getScope() == true</tt>.
|
||||
*
|
||||
* @param object a persistent or transient instance
|
||||
* @param lockRequest contains the lock level
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void lock(Object object, LockRequest lockRequest) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Obtain the specified lock level upon the given object. This may be used to
|
||||
* perform a version check (<tt>LockMode.OPTIMISTIC</tt>), to upgrade to a pessimistic
|
||||
|
@ -560,33 +547,22 @@ public interface Session extends Serializable {
|
|||
* @param object a persistent or transient instance
|
||||
* @param lockMode the lock level
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with a LockRequest
|
||||
* @deprecated instead call buildLockRequest(LockMode).lock(entityName, object)
|
||||
*/
|
||||
public void lock(String entityName, Object object, LockMode lockMode) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Obtain the specified lock level upon the given object. This may be used to
|
||||
* perform a version check (<tt>LockMode.OPTIMISTIC</tt>), to upgrade to a pessimistic
|
||||
* lock (<tt>LockMode.PESSIMISTIC_WRITE</tt>), or to simply reassociate a transient instance
|
||||
* with a session (<tt>LockMode.NONE</tt>). This operation cascades to associated
|
||||
* instances if the association is mapped with <tt>cascade="lock" and lockRequest.getScope() == true.</tt>.
|
||||
*
|
||||
* @param object a persistent or transient instance
|
||||
* @param lockRequest contains the lock level
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void lock(String entityName, Object object, LockRequest lockRequest) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Build a lockRequest that specifies the LockMode, pessimistic lock timeout and lock scope.
|
||||
* timeout and scope is ignored for optimistic locking.
|
||||
*
|
||||
* Use: LockRequest lr = session.buildLockRequest().setLockMode(LockMode.PESSIMISTIC_WRITE).setTimeOut(1000 * 60);
|
||||
* session.lock(entity, lr);
|
||||
* Use: session.buildLockRequest().
|
||||
* setLockMode(LockMode.PESSIMISTIC_WRITE).setTimeOut(1000 * 60).lock(entity);
|
||||
*
|
||||
* @param lockOptions contains the lock level
|
||||
* @return a lockRequest that can be used to lock the passed object.
|
||||
* @throws HibernateException
|
||||
*/
|
||||
LockRequest buildLockRequest();
|
||||
public LockRequest buildLockRequest(LockOptions lockOptions);
|
||||
|
||||
/**
|
||||
* Re-read the state of the given instance from the underlying database. It is
|
||||
|
@ -613,7 +589,7 @@ public interface Session extends Serializable {
|
|||
* @param object a persistent or detached instance
|
||||
* @param lockMode the lock mode to use
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with a LockRequest
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
public void refresh(Object object, LockMode lockMode) throws HibernateException;
|
||||
|
||||
|
@ -624,10 +600,10 @@ public interface Session extends Serializable {
|
|||
* useful in certain special circumstances.
|
||||
*
|
||||
* @param object a persistent or detached instance
|
||||
* @param lockRequest contains the lock mode to use
|
||||
* @param lockOptions contains the lock mode to use
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void refresh(Object object, LockRequest lockRequest) throws HibernateException;
|
||||
public void refresh(Object object, LockOptions lockOptions) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Determine the current lock mode of the given object.
|
||||
|
@ -766,7 +742,7 @@ public interface Session extends Serializable {
|
|||
* @param lockMode the lock mode
|
||||
* @return a persistent instance or null
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with a LockRequest
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
public Object get(Class clazz, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
|
@ -778,11 +754,11 @@ public interface Session extends Serializable {
|
|||
*
|
||||
* @param clazz a persistent class
|
||||
* @param id an identifier
|
||||
* @param lockRequest the lock mode
|
||||
* @param lockOptions the lock mode
|
||||
* @return a persistent instance or null
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public Object get(Class clazz, Serializable id, LockRequest lockRequest) throws HibernateException;
|
||||
public Object get(Class clazz, Serializable id, LockOptions lockOptions) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Return the persistent instance of the given named entity with the given identifier,
|
||||
|
@ -807,7 +783,7 @@ public interface Session extends Serializable {
|
|||
* @param lockMode the lock mode
|
||||
* @return a persistent instance or null
|
||||
* @throws HibernateException
|
||||
* @deprecated LockMode parameter should be replaced with a LockRequest
|
||||
* @deprecated LockMode parameter should be replaced with LockOptions
|
||||
*/
|
||||
public Object get(String entityName, Serializable id, LockMode lockMode) throws HibernateException;
|
||||
|
||||
|
@ -819,11 +795,11 @@ public interface Session extends Serializable {
|
|||
*
|
||||
* @param entityName the entity name
|
||||
* @param id an identifier
|
||||
* @param lockRequest contains the lock mode
|
||||
* @param lockOptions contains the lock mode
|
||||
* @return a persistent instance or null
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public Object get(String entityName, Serializable id, LockRequest lockRequest) throws HibernateException;
|
||||
public Object get(String entityName, Serializable id, LockOptions lockOptions) throws HibernateException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -957,4 +933,68 @@ public interface Session extends Serializable {
|
|||
* @see org.hibernate.engine.profile.FetchProfile for discussion of this feature
|
||||
*/
|
||||
public void disableFetchProfile(String name) throws UnknownProfileException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains locking details (LockMode, Timeout and Scope).
|
||||
*
|
||||
*/
|
||||
public interface LockRequest
|
||||
{
|
||||
|
||||
static final int PESSIMISTIC_NO_WAIT = 0;
|
||||
static final int PESSIMISTIC_WAIT_FOREVER = -1;
|
||||
|
||||
/**
|
||||
* Get the lock mode.
|
||||
* @return the lock mode.
|
||||
*/
|
||||
LockMode getLockMode();
|
||||
|
||||
/**
|
||||
* Specify the LockMode to be used. The default is LockMode.none.
|
||||
*
|
||||
* @param lockMode
|
||||
* @return this LockRequest instance for operation chaining.
|
||||
*/
|
||||
LockRequest setLockMode(LockMode lockMode);
|
||||
|
||||
/**
|
||||
* Get the timeout setting.
|
||||
*
|
||||
* @return timeout in milliseconds, -1 for indefinite wait and 0 for no wait.
|
||||
*/
|
||||
int getTimeOut();
|
||||
|
||||
/**
|
||||
* Specify the pessimistic lock timeout (check if your dialect supports this option).
|
||||
* The default pessimistic lock behavior is to wait forever for the lock.
|
||||
*
|
||||
* @param timeout is time in milliseconds to wait for lock. -1 means wait forever and 0 means no wait.
|
||||
* @return this LockRequest instance for operation chaining.
|
||||
*/
|
||||
LockRequest setTimeOut(int timeout);
|
||||
|
||||
/**
|
||||
* Check if locking is cascaded to owned collections and relationships.
|
||||
* @return true if locking will be extended to owned collections and relationships.
|
||||
*/
|
||||
boolean getScope();
|
||||
|
||||
/**
|
||||
* Specify if LockMode should be cascaded to owned collections and relationships.
|
||||
* The association must be mapped with <tt>cascade="lock" for scope=true to work.
|
||||
*
|
||||
* @param scope
|
||||
* @return
|
||||
*/
|
||||
LockRequest setScope(boolean scope);
|
||||
|
||||
void lock(String entityName, Object object) throws HibernateException;
|
||||
|
||||
public void lock(Object object) throws HibernateException;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.ReplicationMode;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
|
@ -167,16 +167,16 @@ public abstract class CascadingAction {
|
|||
log.trace( "cascading to lock: " + entityName );
|
||||
}
|
||||
LockMode lockMode = LockMode.NONE;
|
||||
LockRequest lr = new LockRequest();
|
||||
if ( anything instanceof LockRequest ) {
|
||||
LockRequest lockRequest = (LockRequest)anything;
|
||||
lr.setTimeOut(lockRequest.getTimeOut());
|
||||
lr.setScope( lockRequest.getScope());
|
||||
if ( lockRequest.getScope() == true ) // cascade specified lockMode
|
||||
lockMode = lockRequest.getLockMode();
|
||||
LockOptions lr = new LockOptions();
|
||||
if ( anything instanceof LockOptions) {
|
||||
LockOptions lockOptions = (LockOptions)anything;
|
||||
lr.setTimeOut(lockOptions.getTimeOut());
|
||||
lr.setScope( lockOptions.getScope());
|
||||
if ( lockOptions.getScope() == true ) // cascade specified lockMode
|
||||
lockMode = lockOptions.getLockMode();
|
||||
}
|
||||
lr.setLockMode(lockMode);
|
||||
session.lock( entityName, child, lr);
|
||||
session.buildLockRequest(lr).lock(entityName, child);
|
||||
}
|
||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
||||
// lock doesn't cascade to uninitialized collections
|
||||
|
|
|
@ -27,7 +27,7 @@ package org.hibernate.event;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
|
||||
/**
|
||||
* Defines an event class for the loading of an entity.
|
||||
|
@ -41,24 +41,24 @@ public class LoadEvent extends AbstractEvent {
|
|||
private Serializable entityId;
|
||||
private String entityClassName;
|
||||
private Object instanceToLoad;
|
||||
private LockRequest lockRequest;
|
||||
private LockOptions lockOptions;
|
||||
private boolean isAssociationFetch;
|
||||
private Object result;
|
||||
|
||||
public LoadEvent(Serializable entityId, Object instanceToLoad, EventSource source) {
|
||||
this(entityId, null, instanceToLoad, new LockRequest(), false, source);
|
||||
this(entityId, null, instanceToLoad, new LockOptions(), false, source);
|
||||
}
|
||||
|
||||
public LoadEvent(Serializable entityId, String entityClassName, LockMode lockMode, EventSource source) {
|
||||
this(entityId, entityClassName, null, lockMode, false, source);
|
||||
}
|
||||
|
||||
public LoadEvent(Serializable entityId, String entityClassName, LockRequest lockRequest, EventSource source) {
|
||||
this(entityId, entityClassName, null, lockRequest, false, source);
|
||||
public LoadEvent(Serializable entityId, String entityClassName, LockOptions lockOptions, EventSource source) {
|
||||
this(entityId, entityClassName, null, lockOptions, false, source);
|
||||
}
|
||||
|
||||
public LoadEvent(Serializable entityId, String entityClassName, boolean isAssociationFetch, EventSource source) {
|
||||
this(entityId, entityClassName, null, new LockRequest(), isAssociationFetch, source);
|
||||
this(entityId, entityClassName, null, new LockOptions(), isAssociationFetch, source);
|
||||
}
|
||||
|
||||
public boolean isAssociationFetch() {
|
||||
|
@ -72,14 +72,14 @@ public class LoadEvent extends AbstractEvent {
|
|||
LockMode lockMode,
|
||||
boolean isAssociationFetch,
|
||||
EventSource source) {
|
||||
this(entityId, entityClassName, instanceToLoad, new LockRequest().setLockMode(lockMode), isAssociationFetch, source );
|
||||
this(entityId, entityClassName, instanceToLoad, new LockOptions().setLockMode(lockMode), isAssociationFetch, source );
|
||||
}
|
||||
|
||||
private LoadEvent(
|
||||
Serializable entityId,
|
||||
String entityClassName,
|
||||
Object instanceToLoad,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
boolean isAssociationFetch,
|
||||
EventSource source) {
|
||||
|
||||
|
@ -89,17 +89,17 @@ public class LoadEvent extends AbstractEvent {
|
|||
throw new IllegalArgumentException("id to load is required for loading");
|
||||
}
|
||||
|
||||
if ( lockRequest.getLockMode() == LockMode.WRITE ) {
|
||||
if ( lockOptions.getLockMode() == LockMode.WRITE ) {
|
||||
throw new IllegalArgumentException("Invalid lock mode for loading");
|
||||
}
|
||||
else if ( lockRequest.getLockMode() == null ) {
|
||||
lockRequest.setLockMode(DEFAULT_LOCK_MODE);
|
||||
else if ( lockOptions.getLockMode() == null ) {
|
||||
lockOptions.setLockMode(DEFAULT_LOCK_MODE);
|
||||
}
|
||||
|
||||
this.entityId = entityId;
|
||||
this.entityClassName = entityClassName;
|
||||
this.instanceToLoad = instanceToLoad;
|
||||
this.lockRequest = lockRequest;
|
||||
this.lockOptions = lockOptions;
|
||||
this.isAssociationFetch = isAssociationFetch;
|
||||
}
|
||||
|
||||
|
@ -127,32 +127,32 @@ public class LoadEvent extends AbstractEvent {
|
|||
this.instanceToLoad = instanceToLoad;
|
||||
}
|
||||
|
||||
public LockRequest getLockRequest() {
|
||||
return lockRequest;
|
||||
public LockOptions getLockOptions() {
|
||||
return lockOptions;
|
||||
}
|
||||
|
||||
public LockMode getLockMode() {
|
||||
return lockRequest.getLockMode();
|
||||
return lockOptions.getLockMode();
|
||||
}
|
||||
|
||||
public void setLockMode(LockMode lockMode) {
|
||||
this.lockRequest.setLockMode(lockMode);
|
||||
this.lockOptions.setLockMode(lockMode);
|
||||
}
|
||||
|
||||
public void setLockTimeout(int timeout) {
|
||||
this.lockRequest.setTimeOut(timeout);
|
||||
this.lockOptions.setTimeOut(timeout);
|
||||
}
|
||||
|
||||
public int getLockTimeout() {
|
||||
return this.lockRequest.getTimeOut();
|
||||
return this.lockOptions.getTimeOut();
|
||||
}
|
||||
|
||||
public void setLockScope(boolean cascade) {
|
||||
this.lockRequest.setScope(cascade);
|
||||
this.lockOptions.setScope(cascade);
|
||||
}
|
||||
|
||||
public boolean getLockScope() {
|
||||
return this.lockRequest.getScope();
|
||||
return this.lockOptions.getScope();
|
||||
}
|
||||
|
||||
public Object getResult() {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
|
||||
/**
|
||||
* Defines an event class for the locking of an entity.
|
||||
|
@ -35,7 +35,7 @@ import org.hibernate.LockRequest;
|
|||
public class LockEvent extends AbstractEvent {
|
||||
|
||||
private Object object;
|
||||
private LockRequest lockRequest;
|
||||
private LockOptions lockOptions;
|
||||
private String entityName;
|
||||
|
||||
public LockEvent(String entityName, Object original, LockMode lockMode, EventSource source) {
|
||||
|
@ -43,21 +43,21 @@ public class LockEvent extends AbstractEvent {
|
|||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public LockEvent(String entityName, Object original, LockRequest lockRequest, EventSource source) {
|
||||
this(original, lockRequest, source);
|
||||
public LockEvent(String entityName, Object original, LockOptions lockOptions, EventSource source) {
|
||||
this(original, lockOptions, source);
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public LockEvent(Object object, LockMode lockMode, EventSource source) {
|
||||
super(source);
|
||||
this.object = object;
|
||||
this.lockRequest = new LockRequest().setLockMode(lockMode);
|
||||
this.lockOptions = new LockOptions().setLockMode(lockMode);
|
||||
}
|
||||
|
||||
public LockEvent(Object object, LockRequest lockRequest, EventSource source) {
|
||||
public LockEvent(Object object, LockOptions lockOptions, EventSource source) {
|
||||
super(source);
|
||||
this.object = object;
|
||||
this.lockRequest = lockRequest;
|
||||
this.lockOptions = lockOptions;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
|
@ -68,32 +68,32 @@ public class LockEvent extends AbstractEvent {
|
|||
this.object = object;
|
||||
}
|
||||
|
||||
public LockRequest getLockRequest() {
|
||||
return lockRequest;
|
||||
public LockOptions getLockOptions() {
|
||||
return lockOptions;
|
||||
}
|
||||
|
||||
public LockMode getLockMode() {
|
||||
return lockRequest.getLockMode();
|
||||
return lockOptions.getLockMode();
|
||||
}
|
||||
|
||||
public void setLockMode(LockMode lockMode) {
|
||||
this.lockRequest.setLockMode(lockMode);
|
||||
this.lockOptions.setLockMode(lockMode);
|
||||
}
|
||||
|
||||
public void setLockTimeout(int timeout) {
|
||||
this.lockRequest.setTimeOut(timeout);
|
||||
this.lockOptions.setTimeOut(timeout);
|
||||
}
|
||||
|
||||
public int getLockTimeout() {
|
||||
return this.lockRequest.getTimeOut();
|
||||
return this.lockOptions.getTimeOut();
|
||||
}
|
||||
|
||||
public void setLockScope(boolean cascade) {
|
||||
this.lockRequest.setScope(cascade);
|
||||
this.lockOptions.setScope(cascade);
|
||||
}
|
||||
|
||||
public boolean getLockScope() {
|
||||
return this.lockRequest.getScope();
|
||||
return this.lockOptions.getScope();
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
|
||||
/**
|
||||
* Defines an event class for the refreshing of an object.
|
||||
|
@ -35,7 +35,7 @@ import org.hibernate.LockRequest;
|
|||
public class RefreshEvent extends AbstractEvent {
|
||||
|
||||
private Object object;
|
||||
private LockRequest lockRequest = new LockRequest().setLockMode(LockMode.READ);
|
||||
private LockOptions lockOptions = new LockOptions().setLockMode(LockMode.READ);
|
||||
|
||||
public RefreshEvent(Object object, EventSource source) {
|
||||
super(source);
|
||||
|
@ -50,34 +50,34 @@ public class RefreshEvent extends AbstractEvent {
|
|||
if (lockMode == null) {
|
||||
throw new IllegalArgumentException("Attempt to generate refresh event with null lock mode");
|
||||
}
|
||||
this.lockRequest.setLockMode(lockMode);
|
||||
this.lockOptions.setLockMode(lockMode);
|
||||
}
|
||||
|
||||
public RefreshEvent(Object object, LockRequest lockRequest, EventSource source) {
|
||||
public RefreshEvent(Object object, LockOptions lockOptions, EventSource source) {
|
||||
this(object, source);
|
||||
if (lockRequest == null) {
|
||||
if (lockOptions == null) {
|
||||
throw new IllegalArgumentException("Attempt to generate refresh event with null lock request");
|
||||
}
|
||||
this.lockRequest = lockRequest;
|
||||
this.lockOptions = lockOptions;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public LockRequest getLockRequest() {
|
||||
return lockRequest;
|
||||
public LockOptions getLockOptions() {
|
||||
return lockOptions;
|
||||
}
|
||||
|
||||
public LockMode getLockMode() {
|
||||
return lockRequest.getLockMode();
|
||||
return lockOptions.getLockMode();
|
||||
}
|
||||
|
||||
public int getLockTimeout() {
|
||||
return this.lockRequest.getTimeOut();
|
||||
return this.lockOptions.getTimeOut();
|
||||
}
|
||||
|
||||
public boolean getLockScope() {
|
||||
return this.lockRequest.getScope();
|
||||
return this.lockOptions.getScope();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,11 +29,8 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.ObjectDeletedException;
|
||||
import org.hibernate.OptimisticLockException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.event.EventSource;
|
||||
import org.hibernate.action.EntityIncrementVersionProcess;
|
||||
import org.hibernate.action.EntityVerifyVersionProcess;
|
||||
import org.hibernate.cache.CacheKey;
|
||||
import org.hibernate.cache.access.SoftLock;
|
||||
import org.hibernate.engine.EntityEntry;
|
||||
|
@ -56,12 +53,12 @@ public class AbstractLockUpgradeEventListener extends AbstractReassociateEventLi
|
|||
*
|
||||
* @param object The entity for which to upgrade the lock.
|
||||
* @param entry The entity's EntityEntry instance.
|
||||
* @param lockRequest contains the requested lock mode.
|
||||
* @param lockOptions contains the requested lock mode.
|
||||
* @param source The session which is the source of the event being processed.
|
||||
*/
|
||||
protected void upgradeLock(Object object, EntityEntry entry, LockRequest lockRequest, EventSource source) {
|
||||
protected void upgradeLock(Object object, EntityEntry entry, LockOptions lockOptions, EventSource source) {
|
||||
|
||||
LockMode requestedLockMode = lockRequest.getLockMode();
|
||||
LockMode requestedLockMode = lockOptions.getLockMode();
|
||||
if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) {
|
||||
// The user requested a "greater" (i.e. more restrictive) form of
|
||||
// pessimistic lock
|
||||
|
|
|
@ -485,7 +485,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
return INCONSISTENT_RTN_CLASS_MARKER;
|
||||
}
|
||||
}
|
||||
upgradeLock( old, oldEntry, event.getLockRequest(), event.getSession() );
|
||||
upgradeLock( old, oldEntry, event.getLockOptions(), event.getSession() );
|
||||
}
|
||||
|
||||
return old;
|
||||
|
|
|
@ -83,7 +83,7 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
|
|||
cascadeOnLock(event, persister, entity);
|
||||
}
|
||||
|
||||
upgradeLock( entity, entry, event.getLockRequest(), event.getSession() );
|
||||
upgradeLock( entity, entry, event.getLockOptions(), event.getSession() );
|
||||
}
|
||||
|
||||
private void cascadeOnLock(LockEvent event, EntityPersister persister, Object entity) {
|
||||
|
@ -91,7 +91,7 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
|
|||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade(CascadingAction.LOCK, Cascade.AFTER_LOCK, source)
|
||||
.cascade( persister, entity, event.getLockRequest() );
|
||||
.cascade( persister, entity, event.getLockOptions() );
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
|
|
@ -142,7 +142,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
|
||||
String previousFetchProfile = source.getFetchProfile();
|
||||
source.setFetchProfile("refresh");
|
||||
Object result = persister.load( id, object, event.getLockRequest(), source );
|
||||
Object result = persister.load( id, object, event.getLockOptions(), source );
|
||||
source.setFetchProfile(previousFetchProfile);
|
||||
|
||||
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
|
||||
|
|
|
@ -69,7 +69,7 @@ import org.hibernate.TransientObjectException;
|
|||
import org.hibernate.UnresolvableObjectException;
|
||||
import org.hibernate.UnknownProfileException;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.engine.ActionQueue;
|
||||
import org.hibernate.engine.CollectionEntry;
|
||||
|
@ -742,21 +742,20 @@ public final class SessionImpl extends AbstractSessionImpl
|
|||
fireLock( new LockEvent(entityName, object, lockMode, this) );
|
||||
}
|
||||
|
||||
public void lock(String entityName, Object object, LockRequest lockRequest) throws HibernateException {
|
||||
fireLock( new LockEvent(entityName, object, lockRequest, this) );
|
||||
}
|
||||
|
||||
public LockRequest buildLockRequest() {
|
||||
return new LockRequest();
|
||||
public LockRequest buildLockRequest(LockOptions lockOptions) {
|
||||
return new LockRequestImpl(lockOptions);
|
||||
}
|
||||
|
||||
public void lock(Object object, LockMode lockMode) throws HibernateException {
|
||||
fireLock( new LockEvent(object, lockMode, this) );
|
||||
}
|
||||
|
||||
private void fireLock(String entityName, Object object, LockOptions options) {
|
||||
fireLock( new LockEvent( entityName, object, options, this) );
|
||||
}
|
||||
|
||||
public void lock(Object object, LockRequest lockRequest) throws HibernateException {
|
||||
fireLock( new LockEvent(object, lockRequest, this) );
|
||||
private void fireLock( Object object, LockOptions options) {
|
||||
fireLock( new LockEvent( object, options, this) );
|
||||
}
|
||||
|
||||
private void fireLock(LockEvent lockEvent) {
|
||||
|
@ -1037,8 +1036,8 @@ public final class SessionImpl extends AbstractSessionImpl
|
|||
return load( entityClass.getName(), id, lockMode );
|
||||
}
|
||||
|
||||
public Object load(Class entityClass, Serializable id, LockRequest lockRequest) throws HibernateException {
|
||||
return load( entityClass.getName(), id, lockRequest );
|
||||
public Object load(Class entityClass, Serializable id, LockOptions lockOptions) throws HibernateException {
|
||||
return load( entityClass.getName(), id, lockOptions);
|
||||
}
|
||||
|
||||
public Object load(String entityName, Serializable id, LockMode lockMode) throws HibernateException {
|
||||
|
@ -1047,8 +1046,8 @@ public final class SessionImpl extends AbstractSessionImpl
|
|||
return event.getResult();
|
||||
}
|
||||
|
||||
public Object load(String entityName, Serializable id, LockRequest lockRequest) throws HibernateException {
|
||||
LoadEvent event = new LoadEvent(id, entityName, lockRequest, this);
|
||||
public Object load(String entityName, Serializable id, LockOptions lockOptions) throws HibernateException {
|
||||
LoadEvent event = new LoadEvent(id, entityName, lockOptions, this);
|
||||
fireLoad( event, LoadEventListener.LOAD );
|
||||
return event.getResult();
|
||||
}
|
||||
|
@ -1057,8 +1056,8 @@ public final class SessionImpl extends AbstractSessionImpl
|
|||
return get( entityClass.getName(), id, lockMode );
|
||||
}
|
||||
|
||||
public Object get(Class entityClass, Serializable id, LockRequest lockRequest) throws HibernateException {
|
||||
return get( entityClass.getName(), id, lockRequest );
|
||||
public Object get(Class entityClass, Serializable id, LockOptions lockOptions) throws HibernateException {
|
||||
return get( entityClass.getName(), id, lockOptions);
|
||||
}
|
||||
|
||||
public Object get(String entityName, Serializable id, LockMode lockMode) throws HibernateException {
|
||||
|
@ -1067,8 +1066,8 @@ public final class SessionImpl extends AbstractSessionImpl
|
|||
return event.getResult();
|
||||
}
|
||||
|
||||
public Object get(String entityName, Serializable id, LockRequest lockRequest) throws HibernateException {
|
||||
LoadEvent event = new LoadEvent(id, entityName, lockRequest, this);
|
||||
public Object get(String entityName, Serializable id, LockOptions lockOptions) throws HibernateException {
|
||||
LoadEvent event = new LoadEvent(id, entityName, lockOptions, this);
|
||||
fireLoad(event, LoadEventListener.GET);
|
||||
return event.getResult();
|
||||
}
|
||||
|
@ -1093,8 +1092,8 @@ public final class SessionImpl extends AbstractSessionImpl
|
|||
fireRefresh( new RefreshEvent(object, lockMode, this) );
|
||||
}
|
||||
|
||||
public void refresh(Object object, LockRequest lockRequest) throws HibernateException {
|
||||
fireRefresh( new RefreshEvent(object, lockRequest, this) );
|
||||
public void refresh(Object object, LockOptions lockOptions) throws HibernateException {
|
||||
fireRefresh( new RefreshEvent(object, lockOptions, this) );
|
||||
}
|
||||
|
||||
public void refresh(Object object, Map refreshedAlready) throws HibernateException {
|
||||
|
@ -2217,4 +2216,48 @@ public final class SessionImpl extends AbstractSessionImpl
|
|||
return entity.getClass().getName();
|
||||
}
|
||||
}
|
||||
|
||||
private class LockRequestImpl implements LockRequest {
|
||||
private final LockOptions lockOptions;
|
||||
private LockRequestImpl(LockOptions lo) {
|
||||
lockOptions = new LockOptions();
|
||||
lockOptions.setLockMode(lo.getLockMode());
|
||||
lockOptions.setScope(lo.getScope());
|
||||
lockOptions.setTimeOut(lo.getTimeOut());
|
||||
}
|
||||
|
||||
public LockMode getLockMode() {
|
||||
return lockOptions.getLockMode();
|
||||
}
|
||||
|
||||
public LockRequest setLockMode(LockMode lockMode) {
|
||||
lockOptions.setLockMode(lockMode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getTimeOut() {
|
||||
return lockOptions.getTimeOut();
|
||||
}
|
||||
|
||||
public LockRequest setTimeOut(int timeout) {
|
||||
lockOptions.setTimeOut(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getScope() {
|
||||
return lockOptions.getScope();
|
||||
}
|
||||
|
||||
public LockRequest setScope(boolean scope) {
|
||||
lockOptions.setScope(scope);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void lock(String entityName, Object object) throws HibernateException {
|
||||
fireLock( entityName, object, lockOptions );
|
||||
}
|
||||
public void lock(Object object) throws HibernateException {
|
||||
fireLock( object, lockOptions );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.Iterator;
|
|||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.CascadeStyle;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.LoadQueryInfluencers;
|
||||
|
@ -98,7 +98,7 @@ public abstract class AbstractEntityJoinWalker extends JoinWalker {
|
|||
protected final void initAll(
|
||||
final String whereString,
|
||||
final String orderByString,
|
||||
final LockRequest lockRequest) throws MappingException {
|
||||
final LockOptions lockOptions) throws MappingException {
|
||||
walkEntityTree( persister, getAlias() );
|
||||
List allAssociations = new ArrayList();
|
||||
allAssociations.addAll(associations);
|
||||
|
@ -114,8 +114,8 @@ public abstract class AbstractEntityJoinWalker extends JoinWalker {
|
|||
CollectionHelper.EMPTY_MAP
|
||||
)
|
||||
);
|
||||
initPersisters(allAssociations, lockRequest.getLockMode());
|
||||
initStatementString( whereString, orderByString, lockRequest.getLockMode());
|
||||
initPersisters(allAssociations, lockOptions.getLockMode());
|
||||
initStatementString( whereString, orderByString, lockOptions.getLockMode());
|
||||
}
|
||||
|
||||
protected final void initProjection(
|
||||
|
|
|
@ -27,13 +27,11 @@ package org.hibernate.loader.entity;
|
|||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.engine.LoadQueryInfluencers;
|
||||
|
@ -132,7 +130,7 @@ public class BatchingEntityLoader implements UniqueEntityLoader {
|
|||
public static UniqueEntityLoader createBatchingEntityLoader(
|
||||
final OuterJoinLoadable persister,
|
||||
final int maxBatchSize,
|
||||
final LockRequest lockRequest,
|
||||
final LockOptions lockOptions,
|
||||
final SessionFactoryImplementor factory,
|
||||
final LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
|
||||
|
||||
|
@ -140,12 +138,12 @@ public class BatchingEntityLoader implements UniqueEntityLoader {
|
|||
int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize);
|
||||
Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ];
|
||||
for ( int i=0; i<batchSizesToCreate.length; i++ ) {
|
||||
loadersToCreate[i] = new EntityLoader(persister, batchSizesToCreate[i], lockRequest, factory, loadQueryInfluencers);
|
||||
loadersToCreate[i] = new EntityLoader(persister, batchSizesToCreate[i], lockOptions, factory, loadQueryInfluencers);
|
||||
}
|
||||
return new BatchingEntityLoader(persister, batchSizesToCreate, loadersToCreate);
|
||||
}
|
||||
else {
|
||||
return new EntityLoader(persister, lockRequest, factory, loadQueryInfluencers);
|
||||
return new EntityLoader(persister, lockOptions, factory, loadQueryInfluencers);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,17 +25,14 @@
|
|||
package org.hibernate.loader.entity;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.CascadeStyle;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.profile.FetchProfile;
|
||||
import org.hibernate.engine.profile.Fetch;
|
||||
import org.hibernate.loader.AbstractEntityJoinWalker;
|
||||
import org.hibernate.persister.entity.OuterJoinLoadable;
|
||||
import org.hibernate.type.AssociationType;
|
||||
|
@ -48,7 +45,7 @@ import org.hibernate.type.AssociationType;
|
|||
*/
|
||||
public class EntityJoinWalker extends AbstractEntityJoinWalker {
|
||||
|
||||
private final LockRequest lockRequest = new LockRequest();
|
||||
private final LockOptions lockOptions = new LockOptions();
|
||||
|
||||
public EntityJoinWalker(
|
||||
OuterJoinLoadable persister,
|
||||
|
@ -59,33 +56,33 @@ public class EntityJoinWalker extends AbstractEntityJoinWalker {
|
|||
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
|
||||
super( persister, factory, loadQueryInfluencers );
|
||||
|
||||
this.lockRequest.setLockMode(lockMode);
|
||||
this.lockOptions.setLockMode(lockMode);
|
||||
|
||||
StringBuffer whereCondition = whereString( getAlias(), uniqueKey, batchSize )
|
||||
//include the discriminator and class-level where, but not filters
|
||||
.append( persister.filterFragment( getAlias(), Collections.EMPTY_MAP ) );
|
||||
|
||||
initAll( whereCondition.toString(), "", lockRequest );
|
||||
initAll( whereCondition.toString(), "", lockOptions);
|
||||
}
|
||||
|
||||
public EntityJoinWalker(
|
||||
OuterJoinLoadable persister,
|
||||
String[] uniqueKey,
|
||||
int batchSize,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
SessionFactoryImplementor factory,
|
||||
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
|
||||
super( persister, factory, loadQueryInfluencers );
|
||||
|
||||
this.lockRequest.setLockMode(lockRequest.getLockMode());
|
||||
this.lockRequest.setTimeOut(lockRequest.getTimeOut());
|
||||
this.lockRequest.setScope(lockRequest.getScope());
|
||||
this.lockOptions.setLockMode(lockOptions.getLockMode());
|
||||
this.lockOptions.setTimeOut(lockOptions.getTimeOut());
|
||||
this.lockOptions.setScope(lockOptions.getScope());
|
||||
|
||||
StringBuffer whereCondition = whereString( getAlias(), uniqueKey, batchSize )
|
||||
//include the discriminator and class-level where, but not filters
|
||||
.append( persister.filterFragment( getAlias(), Collections.EMPTY_MAP ) );
|
||||
|
||||
initAll( whereCondition.toString(), "", lockRequest);
|
||||
initAll( whereCondition.toString(), "", lockOptions);
|
||||
}
|
||||
|
||||
protected int getJoinType(
|
||||
|
@ -102,7 +99,7 @@ public class EntityJoinWalker extends AbstractEntityJoinWalker {
|
|||
// NOTE : we override this form here specifically to account for
|
||||
// fetch profiles.
|
||||
// TODO : how to best handle criteria queries?
|
||||
if ( lockRequest.getLockMode().greaterThan( LockMode.READ ) ) {
|
||||
if ( lockOptions.getLockMode().greaterThan( LockMode.READ ) ) {
|
||||
return -1;
|
||||
}
|
||||
if ( isTooDeep( currentDepth )
|
||||
|
|
|
@ -27,7 +27,7 @@ package org.hibernate.loader.entity;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.engine.LoadQueryInfluencers;
|
||||
|
@ -57,10 +57,10 @@ public class EntityLoader extends AbstractEntityLoader {
|
|||
|
||||
public EntityLoader(
|
||||
OuterJoinLoadable persister,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
SessionFactoryImplementor factory,
|
||||
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
|
||||
this( persister, 1, lockRequest, factory, loadQueryInfluencers );
|
||||
this( persister, 1, lockOptions, factory, loadQueryInfluencers );
|
||||
}
|
||||
|
||||
public EntityLoader(
|
||||
|
@ -83,7 +83,7 @@ public class EntityLoader extends AbstractEntityLoader {
|
|||
public EntityLoader(
|
||||
OuterJoinLoadable persister,
|
||||
int batchSize,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
SessionFactoryImplementor factory,
|
||||
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
|
||||
this(
|
||||
|
@ -91,7 +91,7 @@ public class EntityLoader extends AbstractEntityLoader {
|
|||
persister.getIdentifierColumnNames(),
|
||||
persister.getIdentifierType(),
|
||||
batchSize,
|
||||
lockRequest,
|
||||
lockOptions,
|
||||
factory,
|
||||
loadQueryInfluencers
|
||||
);
|
||||
|
@ -130,7 +130,7 @@ public class EntityLoader extends AbstractEntityLoader {
|
|||
String[] uniqueKey,
|
||||
Type uniqueKeyType,
|
||||
int batchSize,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
SessionFactoryImplementor factory,
|
||||
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
|
||||
super( persister, uniqueKeyType, factory, loadQueryInfluencers );
|
||||
|
@ -139,7 +139,7 @@ public class EntityLoader extends AbstractEntityLoader {
|
|||
persister,
|
||||
uniqueKey,
|
||||
batchSize,
|
||||
lockRequest,
|
||||
lockOptions,
|
||||
factory,
|
||||
loadQueryInfluencers
|
||||
);
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.QueryException;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.StaleStateException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.cache.CacheKey;
|
||||
import org.hibernate.cache.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.entry.CacheEntry;
|
||||
|
@ -1413,16 +1413,16 @@ public abstract class AbstractEntityPersister
|
|||
Object object,
|
||||
LockMode lockMode,
|
||||
SessionImplementor session) throws HibernateException {
|
||||
getLocker( lockMode ).lock( id, version, object, LockRequest.WAIT_FOREVER, session );
|
||||
getLocker( lockMode ).lock( id, version, object, LockOptions.WAIT_FOREVER, session );
|
||||
}
|
||||
|
||||
public void lock(
|
||||
Serializable id,
|
||||
Object version,
|
||||
Object object,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
SessionImplementor session) throws HibernateException {
|
||||
getLocker( lockRequest.getLockMode() ).lock( id, version, object, lockRequest.getTimeOut(), session );
|
||||
getLocker( lockOptions.getLockMode() ).lock( id, version, object, lockOptions.getTimeOut(), session );
|
||||
}
|
||||
|
||||
public String getRootTableName() {
|
||||
|
@ -1882,13 +1882,13 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
protected UniqueEntityLoader createEntityLoader(
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
|
||||
//TODO: disable batch loading if lockMode > READ?
|
||||
return BatchingEntityLoader.createBatchingEntityLoader(
|
||||
this,
|
||||
batchSize,
|
||||
lockRequest,
|
||||
lockOptions,
|
||||
getFactory(),
|
||||
loadQueryInfluencers
|
||||
);
|
||||
|
@ -3208,7 +3208,7 @@ public abstract class AbstractEntityPersister
|
|||
);
|
||||
}
|
||||
|
||||
final UniqueEntityLoader loader = getAppropriateLoader( new LockRequest().setLockMode(lockMode), session );
|
||||
final UniqueEntityLoader loader = getAppropriateLoader( new LockOptions().setLockMode(lockMode), session );
|
||||
return loader.load( id, optionalObject, session );
|
||||
}
|
||||
|
||||
|
@ -3216,7 +3216,7 @@ public abstract class AbstractEntityPersister
|
|||
* Load an instance using either the <tt>forUpdateLoader</tt> or the outer joining <tt>loader</tt>,
|
||||
* depending upon the value of the <tt>lock</tt> parameter
|
||||
*/
|
||||
public Object load(Serializable id, Object optionalObject, LockRequest lockRequest, SessionImplementor session)
|
||||
public Object load(Serializable id, Object optionalObject, LockOptions lockOptions, SessionImplementor session)
|
||||
throws HibernateException {
|
||||
|
||||
if ( log.isTraceEnabled() ) {
|
||||
|
@ -3226,7 +3226,7 @@ public abstract class AbstractEntityPersister
|
|||
);
|
||||
}
|
||||
|
||||
final UniqueEntityLoader loader = getAppropriateLoader( lockRequest, session );
|
||||
final UniqueEntityLoader loader = getAppropriateLoader(lockOptions, session );
|
||||
return loader.load( id, optionalObject, session );
|
||||
}
|
||||
|
||||
|
@ -3249,7 +3249,7 @@ public abstract class AbstractEntityPersister
|
|||
&& filterHelper.isAffectedBy( session.getLoadQueryInfluencers().getEnabledFilters() );
|
||||
}
|
||||
|
||||
private UniqueEntityLoader getAppropriateLoader(LockRequest lockRequest, SessionImplementor session) {
|
||||
private UniqueEntityLoader getAppropriateLoader(LockOptions lockOptions, SessionImplementor session) {
|
||||
if ( queryLoader != null ) {
|
||||
// if the user specified a custom query loader we need to that
|
||||
// regardless of any other consideration
|
||||
|
@ -3258,9 +3258,9 @@ public abstract class AbstractEntityPersister
|
|||
else if ( isAffectedByEnabledFilters( session ) ) {
|
||||
// because filters affect the rows returned (because they add
|
||||
// restirctions) these need to be next in precendence
|
||||
return createEntityLoader( lockRequest, session.getLoadQueryInfluencers() );
|
||||
return createEntityLoader(lockOptions, session.getLoadQueryInfluencers() );
|
||||
}
|
||||
else if ( session.getLoadQueryInfluencers().getInternalFetchProfile() != null && LockMode.UPGRADE.greaterThan( lockRequest.getLockMode() ) ) {
|
||||
else if ( session.getLoadQueryInfluencers().getInternalFetchProfile() != null && LockMode.UPGRADE.greaterThan( lockOptions.getLockMode() ) ) {
|
||||
// Next, we consider whether an 'internal' fetch profile has been set.
|
||||
// This indicates a special fetch profile Hibernate needs applied
|
||||
// (for its merge loading process e.g.).
|
||||
|
@ -3269,10 +3269,10 @@ public abstract class AbstractEntityPersister
|
|||
else if ( isAffectedByEnabledFetchProfiles( session ) ) {
|
||||
// If the session has associated influencers we need to adjust the
|
||||
// SQL query used for loading based on those influencers
|
||||
return createEntityLoader( lockRequest, session.getLoadQueryInfluencers() );
|
||||
return createEntityLoader(lockOptions, session.getLoadQueryInfluencers() );
|
||||
}
|
||||
else {
|
||||
return ( UniqueEntityLoader ) loaders.get( lockRequest.getLockMode() );
|
||||
return ( UniqueEntityLoader ) loaders.get( lockOptions.getLockMode() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.cache.OptimisticCacheSource;
|
||||
import org.hibernate.cache.access.EntityRegionAccessStrategy;
|
||||
|
@ -330,7 +330,7 @@ public interface EntityPersister extends OptimisticCacheSource {
|
|||
/**
|
||||
* Load an instance of the persistent class.
|
||||
*/
|
||||
public Object load(Serializable id, Object optionalObject, LockRequest lockRequest, SessionImplementor session)
|
||||
public Object load(Serializable id, Object optionalObject, LockOptions lockOptions, SessionImplementor session)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
|
@ -342,7 +342,7 @@ public interface EntityPersister extends OptimisticCacheSource {
|
|||
/**
|
||||
* Do a version check (optional operation)
|
||||
*/
|
||||
public void lock(Serializable id, Object version, Object object, LockRequest lockRequest, SessionImplementor session)
|
||||
public void lock(Serializable id, Object version, Object object, LockOptions lockOptions, SessionImplementor session)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
public final class ArrayHelper {
|
||||
|
@ -84,9 +84,9 @@ public final class ArrayHelper {
|
|||
return array;
|
||||
}
|
||||
|
||||
public static LockMode[] fillArray(LockRequest lockRequest, int length) {
|
||||
public static LockMode[] fillArray(LockOptions lockOptions, int length) {
|
||||
LockMode[] array = new LockMode[length];
|
||||
Arrays.fill(array, lockRequest);
|
||||
Arrays.fill(array, lockOptions);
|
||||
return array;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.io.ObjectOutputStream;
|
|||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.HashMap;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import javax.persistence.FlushModeType;
|
||||
|
@ -521,7 +520,7 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
|
|||
if ( !contains( entity ) ) {
|
||||
throw new IllegalArgumentException( "entity not in the persistence context" );
|
||||
}
|
||||
getSession().lock( entity, getLockRequest(lockModeType, properties) );
|
||||
getSession().buildLockRequest(getLockRequest(lockModeType, properties)).lock( entity );
|
||||
}
|
||||
catch ( HibernateException he ) {
|
||||
throw convert( he );
|
||||
|
@ -529,31 +528,31 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
|
|||
|
||||
}
|
||||
|
||||
private LockRequest getLockRequest(LockModeType lockModeType, Map<String, Object> properties) {
|
||||
LockRequest lockRequest = new LockRequest();
|
||||
lockRequest.setLockMode(getLockMode(lockModeType));
|
||||
private LockOptions getLockRequest(LockModeType lockModeType, Map<String, Object> properties) {
|
||||
LockOptions lockOptions = new LockOptions();
|
||||
lockOptions.setLockMode(getLockMode(lockModeType));
|
||||
if ( properties != null ) {
|
||||
// lockRequest scope will default to false (PessimisticLockScope.NORMAL)
|
||||
// lockOptions scope will default to false (PessimisticLockScope.NORMAL)
|
||||
Object value = properties.get(PESSIMISTICLOCKSCOPE);
|
||||
if ( value instanceof String && PessimisticLockScope.valueOf((String) value) == PessimisticLockScope.EXTENDED) {
|
||||
lockRequest.setScope(true);
|
||||
lockOptions.setScope(true);
|
||||
}
|
||||
// lockRequest timeout will default to LockRequest.FOREVER_WAIT
|
||||
// lockOptions timeout will default to LockOptions.FOREVER_WAIT
|
||||
value = properties.get(PESSIMISTICLOCKTIMEOUT);
|
||||
if ( value instanceof String ) {
|
||||
int timeout = Integer.parseInt((String) value);
|
||||
if ( timeout < 0 ) {
|
||||
lockRequest.setTimeOut(LockRequest.WAIT_FOREVER);
|
||||
lockOptions.setTimeOut(LockOptions.WAIT_FOREVER);
|
||||
}
|
||||
else if( timeout == 0 ) {
|
||||
lockRequest.setTimeOut(LockRequest.NO_WAIT);
|
||||
lockOptions.setTimeOut(LockOptions.NO_WAIT);
|
||||
}
|
||||
else {
|
||||
lockRequest.setTimeOut(timeout);
|
||||
lockOptions.setTimeOut(timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
return lockRequest;
|
||||
return lockOptions;
|
||||
}
|
||||
|
||||
private LockModeType getLockModeType(LockMode lockMode) {
|
||||
|
|
|
@ -11,9 +11,8 @@ import org.hibernate.Hibernate;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.LockRequest;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.cache.CacheConcurrencyStrategy;
|
||||
import org.hibernate.cache.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.entry.CacheEntryStructure;
|
||||
import org.hibernate.cache.entry.UnstructuredCacheEntry;
|
||||
|
@ -281,15 +280,15 @@ public class CustomPersister implements EntityPersister {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see EntityPersister#load(Serializable, Object, LockRequest, SessionImplementor)
|
||||
* @see EntityPersister#load(Serializable, Object, org.hibernate.LockOptions , SessionImplementor)
|
||||
*/
|
||||
public Object load(
|
||||
Serializable id,
|
||||
Object optionalObject,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
SessionImplementor session
|
||||
) throws HibernateException {
|
||||
return load(id, optionalObject, lockRequest.getLockMode(), session);
|
||||
return load(id, optionalObject, lockOptions.getLockMode(), session);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -343,7 +342,7 @@ public class CustomPersister implements EntityPersister {
|
|||
Serializable id,
|
||||
Object version,
|
||||
Object object,
|
||||
LockRequest lockRequest,
|
||||
LockOptions lockOptions,
|
||||
SessionImplementor session
|
||||
) throws HibernateException {
|
||||
|
||||
|
|
Loading…
Reference in New Issue