Skip to content

Commit

Permalink
continued work on replacing LoadPlan with SQL AST approach - cleanup;
Browse files Browse the repository at this point in the history
change expected type of entity identifier values from Serializable to Object
  • Loading branch information
sebersole committed Nov 7, 2019
1 parent e522cbe commit 5b3c6c4
Show file tree
Hide file tree
Showing 221 changed files with 1,300 additions and 1,456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.hibernate;

import java.io.Serializable;
import java.util.Optional;

import org.hibernate.graph.GraphSemantic;
Expand Down Expand Up @@ -55,7 +54,7 @@ default IdentifierLoadAccess<T> with(RootGraph<T> graph) {
*
* @return the persistent instance or proxy
*/
T getReference(Serializable id);
T getReference(Object id);

/**
* Return the persistent instance with the given identifier, or null if there is no such persistent instance.
Expand All @@ -66,7 +65,7 @@ default IdentifierLoadAccess<T> with(RootGraph<T> graph) {
*
* @return The persistent instance or {@code null}
*/
T load(Serializable id);
T load(Object id);

/**
* Same semantic as {@link #load} except that here {@link Optional} is returned to
Expand All @@ -76,5 +75,5 @@ default IdentifierLoadAccess<T> with(RootGraph<T> graph) {
*
* @return The persistent instance, if one, wrapped in Optional
*/
Optional<T> loadOptional(Serializable id);
Optional<T> loadOptional(Object id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.graph.GraphSemantic;
Expand Down Expand Up @@ -107,12 +106,12 @@ default MultiIdentifierLoadAccess<T> with(RootGraph<T> graph) {
* and {@link #enableReturnOfDeletedEntities} for options which effect
* the size and "shape" of the return list.
*
* @param ids The ids to load
* @param <K> The identifier type
*
* @param ids The ids to load
* @return The persistent entities.
*/
<K extends Serializable> List<T> multiLoad(K... ids);
<K> List<T> multiLoad(K... ids);

/**
* Perform a load of multiple entities by identifiers. See {@link #enableOrderedReturn}
Expand All @@ -124,5 +123,5 @@ default MultiIdentifierLoadAccess<T> with(RootGraph<T> graph) {
*
* @return The persistent entities.
*/
<K extends Serializable> List<T> multiLoad(List<K> ids);
<K> List<T> multiLoad(List<K> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.hibernate;

import java.io.Serializable;
import java.util.Optional;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,27 @@
* @author Gavin King
*/
public class NonUniqueObjectException extends HibernateException {
private final Serializable identifier;
private final Object identifier;
private final String entityName;

/**
* Constructs a NonUniqueObjectException using the given information.
*
* @param message A message explaining the exception condition
* @param message A message explaining the exception condition
* @param entityId The identifier of the entity
* @param entityName The name of the entity
*/
public NonUniqueObjectException(String message, Serializable entityId, String entityName) {
public NonUniqueObjectException(String message, Object entityId, String entityName) {
super( message );
this.entityName = entityName;
this.identifier = entityId;
}

/**
* Constructs a NonUniqueObjectException using the given information, using a standard message.
*
* @param entityId The identifier of the entity
* @param entityId The identifier of the entity
* @param entityName The name of the entity
*/
public NonUniqueObjectException(Serializable entityId, String entityName) {
public NonUniqueObjectException(Object entityId, String entityName) {
this(
"A different object with the same identifier value was already associated with the session",
entityId,
Expand All @@ -52,7 +50,7 @@ public String getEntityName() {
return entityName;
}

public Serializable getIdentifier() {
public Object getIdentifier() {
return identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package org.hibernate;

import java.io.Serializable;

/**
* Thrown when the user tries to do something illegal with a deleted object.
*
Expand All @@ -16,12 +14,11 @@
public class ObjectDeletedException extends UnresolvableObjectException {
/**
* Constructs an ObjectDeletedException using the given information.
*
* @param message A message explaining the exception condition
* @param message A message explaining the exception condition
* @param identifier The identifier of the entity
* @param entityName The name of the entity
*/
public ObjectDeletedException(String message, Serializable identifier, String entityName) {
public ObjectDeletedException(String message, Object identifier, String entityName) {
super( message, identifier, entityName );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package org.hibernate;

import java.io.Serializable;

/**
* Thrown when <tt>Session.load()</tt> fails to select a row with
* the given primary key (identifier value). This exception might not
Expand All @@ -24,11 +22,14 @@
public class ObjectNotFoundException extends UnresolvableObjectException {
/**
* Constructs a ObjectNotFoundException using the given information.
*
* @param identifier The identifier of the entity
* @param identifier The identifier of the entity
* @param entityName The name of the entity
*/
public ObjectNotFoundException(Serializable identifier, String entityName) {
public ObjectNotFoundException(Object identifier, String entityName) {
super( identifier, entityName );
}

public ObjectNotFoundException(String entityName, Object identifier) {
this( identifier, entityName );
}
}
54 changes: 25 additions & 29 deletions hibernate-core/src/main/java/org/hibernate/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hibernate.graph.RootGraph;
import org.hibernate.jdbc.ReturningWork;
import org.hibernate.jdbc.Work;
import org.hibernate.jpa.HibernateEntityManager;
import org.hibernate.stat.SessionStatistics;

/**
Expand Down Expand Up @@ -235,7 +234,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* To override this session's read-only/modifiable setting for entities
* and proxies loaded by a Query:
* @see Query#setReadOnly(boolean)
* @see org.hibernate.query.Query#setReadOnly(boolean)
*
* @param readOnly true, the default for loaded entities/proxies is read-only;
* false, the default for loaded entities/proxies is modifiable
Expand All @@ -252,7 +251,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
* @throws TransientObjectException if the instance is transient or associated with
* a different session
*/
Serializable getIdentifier(Object object);
Object getIdentifier(Object object);

/**
* Check if this entity is associated with this Session. This form caters to
Expand Down Expand Up @@ -281,17 +280,17 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
* Return the persistent instance of the given entity class with the given identifier,
* obtaining the specified lock mode, assuming the instance exists.
* <p/>
* Convenient form of {@link #load(Class, Serializable, LockOptions)}
* Convenient form of {@link #load(Class, Object, LockOptions)}
*
* @param theClass a persistent class
* @param id a valid identifier of an existing persistent instance of the class
* @param lockMode the lock level
*
* @return the persistent instance or proxy
*
* @see #load(Class, Serializable, LockOptions)
* @see #load(Class, Object, LockOptions)
*/
<T> T load(Class<T> theClass, Serializable id, LockMode lockMode);
<T> T load(Class<T> theClass, Object id, LockMode lockMode);

/**
* Return the persistent instance of the given entity class with the given identifier,
Expand All @@ -302,23 +301,23 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
* @param lockOptions contains the lock level
* @return the persistent instance or proxy
*/
<T> T load(Class<T> theClass, Serializable id, LockOptions lockOptions);
<T> T load(Class<T> theClass, Object id, LockOptions lockOptions);

/**
* Return the persistent instance of the given entity class with the given identifier,
* obtaining the specified lock mode, assuming the instance exists.
* <p/>
* Convenient form of {@link #load(String, Serializable, LockOptions)}
* Convenient form of {@link #load(String, Object, LockOptions)}
*
* @param entityName a persistent class
* @param id a valid identifier of an existing persistent instance of the class
* @param lockMode the lock level
*
* @return the persistent instance or proxy
*
* @see #load(String, Serializable, LockOptions)
* @see #load(String, Object, LockOptions)
*/
Object load(String entityName, Serializable id, LockMode lockMode);
Object load(String entityName, Object id, LockMode lockMode);

/**
* Return the persistent instance of the given entity class with the given identifier,
Expand All @@ -330,7 +329,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return the persistent instance or proxy
*/
Object load(String entityName, Serializable id, LockOptions lockOptions);
Object load(String entityName, Object id, LockOptions lockOptions);

/**
* Return the persistent instance of the given entity class with the given identifier,
Expand All @@ -346,7 +345,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return the persistent instance or proxy
*/
<T> T load(Class<T> theClass, Serializable id);
<T> T load(Class<T> theClass, Object id);

/**
* Return the persistent instance of the given entity class with the given identifier,
Expand All @@ -362,16 +361,13 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return the persistent instance or proxy
*/
Object load(String entityName, Serializable id);
Object load(String entityName, Object id);

/**
* Read the persistent state associated with the given identifier into the given transient
* instance.
*
* @param object an "empty" instance of the persistent class
* @param id a valid identifier of an existing persistent instance of the class
*/
void load(Object object, Serializable id);
void load(Object object, Object id);

/**
* Persist the state of the given detached instance, reusing the current
Expand Down Expand Up @@ -404,7 +400,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return the generated identifier
*/
Serializable save(Object object);
Object save(Object object);

/**
* Persist the given transient instance, first assigning a generated identifier. (Or
Expand All @@ -417,7 +413,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return the generated identifier
*/
Serializable save(String entityName, Object object);
Object save(String entityName, Object object);

/**
* Either {@link #save(Object)} or {@link #update(Object)} the given
Expand Down Expand Up @@ -693,25 +689,25 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return a persistent instance or null
*/
<T> T get(Class<T> entityType, Serializable id);
<T> T get(Class<T> entityType, Object id);

/**
* 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.)
* Obtain the specified lock mode if the instance exists.
* <p/>
* Convenient form of {@link #get(Class, Serializable, LockOptions)}
* Convenient form of {@link #get(Class, Object, LockOptions)}
*
* @param entityType The entity type
* @param id an identifier
* @param lockMode the lock mode
*
* @return a persistent instance or null
*
* @see #get(Class, Serializable, LockOptions)
* @see #get(Class, Object, LockOptions)
*/
<T> T get(Class<T> entityType, Serializable id, LockMode lockMode);
<T> T get(Class<T> entityType, Object id, LockMode lockMode);

/**
* Return the persistent instance of the given entity class with the given identifier,
Expand All @@ -725,7 +721,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return a persistent instance or null
*/
<T> T get(Class<T> entityType, Serializable id, LockOptions lockOptions);
<T> T get(Class<T> entityType, Object id, LockOptions lockOptions);

/**
* Return the persistent instance of the given named entity with the given identifier,
Expand All @@ -737,23 +733,23 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return a persistent instance or null
*/
Object get(String entityName, Serializable id);
Object get(String entityName, Object id);

/**
* 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.)
* Obtain the specified lock mode if the instance exists.
* <p/>
* Convenient form of {@link #get(String, Serializable, LockOptions)}
* Convenient form of {@link #get(String, Object, LockOptions)}
*
* @param entityName the entity name
* @param id an identifier
* @param lockMode the lock mode
*
* @return a persistent instance or null
*
* @see #get(String, Serializable, LockOptions)
* @see #get(String, Object, LockOptions)
*/
Object get(String entityName, Serializable id, LockMode lockMode);

Expand All @@ -769,7 +765,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return a persistent instance or null
*/
Object get(String entityName, Serializable id, LockOptions lockOptions);
Object get(String entityName, Object id, LockOptions lockOptions);

/**
* Return the entity name for a persistent entity.
Expand Down Expand Up @@ -936,7 +932,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* To override this session's read-only/modifiable setting for entities
* and proxies loaded by a Query:
* @see Query#setReadOnly(boolean)
* @see org.hibernate.query.Query#setReadOnly(boolean)
*
* @param entityOrProxy an entity or HibernateProxy
* @param readOnly {@code true} if the entity or proxy should be made read-only; {@code false} if the entity or
Expand Down
Loading

0 comments on commit 5b3c6c4

Please sign in to comment.