HHH-2879 Remove use of generics due to proxy issues

This commit is contained in:
edalquist 2011-09-30 16:44:43 -05:00 committed by Steve Ebersole
parent 2d03ca322d
commit 8796fe5ed6
2 changed files with 33 additions and 38 deletions

View File

@ -38,19 +38,33 @@ public interface IdentifierLoadAccess<T> {
public IdentifierLoadAccess<T> with(LockOptions lockOptions);
/**
* Same behavior as {@link Session#load(Class, java.io.Serializable)}
*
* @param id The primary key of the entity
* @return The entity
* @throws HibernateException if the entity does not exist
* Return the persistent instance of the given entity class with the given identifier,
* assuming that the instance exists. This method might return a proxied instance that
* is initialized on-demand, when a non-identifier method is accessed.
* <br><br>
* You should not use this method to determine if an instance exists (use <tt>get()</tt>
* instead). Use this only to retrieve an instance that you assume exists, where non-existence
* would be an actual error.
* <br><br>
* Due to the nature of the proxy functionality the return type of this method cannot use
* the generic type.
*
* @param theClass a persistent class
* @param id a valid identifier of an existing persistent instance of the class
* @return the persistent instance or proxy
* @throws HibernateException
*/
public T getReference(Serializable id);
public Object getReference(Serializable id);
/**
* Same behavior as {@link Session#get(Class, java.io.Serializable)}
*
* @param id The primary key of the entity
* @return The entity or null if it does not exist
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
* with the session, return that instance. This method never returns an uninitialized instance.)
*
* @param clazz a persistent class
* @param id an identifier
* @return a persistent instance or null
* @throws HibernateException
*/
public T load(Serializable id);
public Object load(Serializable id);
}

View File

@ -2174,12 +2174,8 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
private final String entityName;
private final Class<T> entityClass;
private LockOptions lockOptions;
@Deprecated
private LockMode lockMode;
/**
* Note that the specified entity MUST be castable using {@link Class#cast(Object)}
* on the specified entityClass
*/
private IdentifierLoadAccessImpl(String entityName, Class<T> entityClass) {
this.entityName = entityName;
@ -2191,9 +2187,6 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
*/
@Override
public final IdentifierLoadAccessImpl<T> with(LockOptions lockOptions) {
if (this.lockMode != null) {
throw new IllegalArgumentException("Cannot specify by LockOptions and LockMode on a single IdentifierLoadAccessImpl");
}
this.lockOptions = lockOptions;
return this;
}
@ -2204,10 +2197,8 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
*/
@Deprecated
public final IdentifierLoadAccessImpl<T> with(LockMode lockMode) {
if (this.lockOptions != null) {
throw new IllegalArgumentException("Cannot specify by LockOptions and LockMode on a single IdentifierLoadAccessImpl");
}
this.lockMode = lockMode;
this.lockOptions = new LockOptions();
this.lockOptions.setLockMode(lockMode);
return this;
}
@ -2215,17 +2206,12 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
* @see org.hibernate.IdentifierLoadAccess#getReference(java.io.Serializable)
*/
@Override
public final T getReference(Serializable id) {
public final Object getReference(Serializable id) {
if (this.lockOptions != null) {
LoadEvent event = new LoadEvent(id, entityName, lockOptions, SessionImpl.this);
fireLoad( event, LoadEventListener.LOAD );
return this.entityClass.cast(event.getResult());
return event.getResult();
}
if (this.lockMode != null) {
LoadEvent event = new LoadEvent(id, entityName, lockMode, SessionImpl.this);
fireLoad( event, LoadEventListener.LOAD );
return this.entityClass.cast(event.getResult());
}
LoadEvent event = new LoadEvent(id, entityName, false, SessionImpl.this);
boolean success = false;
@ -2235,7 +2221,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id );
}
success = true;
return this.entityClass.cast(event.getResult());
return event.getResult();
}
finally {
afterOperation(success);
@ -2246,16 +2232,11 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
* @see org.hibernate.IdentifierLoadAccess#load(java.io.Serializable)
*/
@Override
public final T load(Serializable id) {
public final Object load(Serializable id) {
if (this.lockOptions != null) {
LoadEvent event = new LoadEvent(id, entityName, lockOptions, SessionImpl.this);
fireLoad( event, LoadEventListener.GET );
return this.entityClass.cast(event.getResult());
}
if (this.lockMode != null) {
LoadEvent event = new LoadEvent(id, entityName, lockMode, SessionImpl.this);
fireLoad( event, LoadEventListener.GET );
return this.entityClass.cast(event.getResult());
return event.getResult();
}
LoadEvent event = new LoadEvent(id, entityName, false, SessionImpl.this);
@ -2263,7 +2244,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
try {
fireLoad(event, LoadEventListener.GET);
success = true;
return this.entityClass.cast(event.getResult());
return event.getResult();
}
finally {
afterOperation(success);