Skip to content

Commit

Permalink
add new operations to PersistenceUnitUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Aug 10, 2023
1 parent 827d3ba commit 4f5f0ac
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 0 deletions.
98 changes: 98 additions & 0 deletions api/src/main/java/jakarta/persistence/PersistenceUnitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
*/

// Contributors:
// Gavin King - 3.2
// Linda DeMichiel - 2.1
// Linda DeMichiel - 2.0

package jakarta.persistence;

import jakarta.persistence.metamodel.Attribute;

/**
* Utility interface between the application and the persistence
* provider managing the persistence unit.
Expand All @@ -39,6 +42,17 @@ public interface PersistenceUnitUtil extends PersistenceUtil {
*/
public boolean isLoaded(Object entity, String attributeName);

/**
* Determine the load state of a given persistent attribute
* of an entity belonging to the persistence unit.
* @param entity entity instance containing the attribute
* @param attribute attribute whose load state is to be determined
* @return false if entity's state has not been loaded or if
* the attribute state has not been loaded, else true
* @since 3.2
*/
public <E> boolean isLoaded(E entity, Attribute<? super E,?> attribute);

/**
* Determine the load state of an entity belonging to the
* persistence unit. This method can be used to determine the
Expand All @@ -54,6 +68,90 @@ public interface PersistenceUnitUtil extends PersistenceUtil {
*/
public boolean isLoaded(Object entity);

/**
* Load the persistent value of a given persistent attribute
* of an entity belonging to the persistence unit and to an
* open persistence context.
* After this method returns, {@link #isLoaded(Object,String)}
* must return true with the given entity instance and attribute.
* @param entity entity instance
* @param attributeName the name of the attribute to be loaded
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public void load(Object entity, String attributeName);

/**
* Load the persistent value of a given persistent attribute
* of an entity belonging to the persistence unit and to an
* open persistence context.
* After this method returns, {@link #isLoaded(Object,Attribute)}
* must return true with the given entity instance and attribute.
* @param entity entity instance to be loaded
* @param attribute the attribute to be loaded
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public <E> void load(E entity, Attribute<? super E,?> attribute);

/**
* Load the persistent state of an entity belonging to the
* persistence unit and to an open persistence context.
* After this method returns, {@link #isLoaded(Object)} must
* return true with the given entity instance.
* @param entity entity instance to be loaded
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public void load(Object entity);

/**
* Return true if the given entity belonging to the persistence
* unit and to an open persistence context is an instance of the
* given entity class, or false otherwise. This method may, but
* is not required to, load the given entity by side effect.
* @param entity entity instance
* @param entityClass an entity class belonging to the persistence
* unit
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* or if the given class is not an entity class belonging to the
* persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public boolean isInstance(Object entity, Class<?> entityClass);

/**
* Return the concrete entity class if the given entity belonging
* to the persistence unit and to an open persistence context.
* This method may, but is not required to, load the given entity
* by side effect.
* @param entity entity instance
* @return an entity class belonging to the persistence unit
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public <T> Class<? extends T> getClass(T entity);

/**
* Return the id of the entity.
* A generated id is not guaranteed to be available until after
Expand Down
2 changes: 2 additions & 0 deletions spec/src/main/asciidoc/appendixes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Added support for specifying null precedence when ordering JPQL and criteria que

Added _getSingleResultOrNull()_ to _Query_, _TypedQuery_, _StoredProcedureQuery_

Added new operations to _PersistenceUnitUtil_

Overload _concat()_ to accept list of expressions in _CriteriaBuilder_

Overload _where()_, _having()_, _and()_, and _or()_ to accept _List<Predicate>_ in _CriteriaQuery_ and _CriteriaBuilder_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,8 @@ been obtained.
----
package jakarta.persistence;
import jakarta.persistence.metamodel.Attribute;
/**
* Utility interface between the application and the persistence
* provider managing the persistence unit.
Expand All @@ -1401,6 +1403,17 @@ public interface PersistenceUnitUtil extends PersistenceUtil {
*/
public boolean isLoaded(Object entity, String attributeName);
/**
* Determine the load state of a given persistent attribute
* of an entity belonging to the persistence unit.
* @param entity entity instance containing the attribute
* @param attribute attribute whose load state is to be determined
* @return false if entity's state has not been loaded or if
* the attribute state has not been loaded, else true
* @since 3.2
*/
public <E> boolean isLoaded(E entity, Attribute<? super E,?> attribute);
/**
* Determine the load state of an entity belonging to the
* persistence unit. This method can be used to determine the
Expand All @@ -1416,6 +1429,90 @@ public interface PersistenceUnitUtil extends PersistenceUtil {
*/
public boolean isLoaded(Object entity);
/**
* Load the persistent value of a given persistent attribute
* of an entity belonging to the persistence unit and to an
* open persistence context.
* After this method returns, {@link #isLoaded(Object,String)}
* must return true with the given entity instance and attribute.
* @param entity entity instance
* @param attributeName the name of the attribute to be loaded
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public void load(Object entity, String attributeName);
/**
* Load the persistent value of a given persistent attribute
* of an entity belonging to the persistence unit and to an
* open persistence context.
* After this method returns, {@link #isLoaded(Object,Attribute)}
* must return true with the given entity instance and attribute.
* @param entity entity instance to be loaded
* @param attribute the attribute to be loaded
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public <E> void load(E entity, Attribute<? super E,?> attribute);
/**
* Load the persistent state of an entity belonging to the
* persistence unit and to an open persistence context.
* After this method returns, {@link #isLoaded(Object)} must
* return true with the given entity instance.
* @param entity entity instance to be loaded
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public void load(Object entity);
/**
* Return true if the given entity belonging to the persistence
* unit and to an open persistence context is an instance of the
* given entity class, or false otherwise. This method may, but
* is not required to, load the given entity by side effect.
* @param entity entity instance
* @param entityClass an entity class belonging to the persistence
* unit
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* or if the given class is not an entity class belonging to the
* persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public boolean isInstance(Object entity, Class<?> entityClass);
/**
* Return the concrete entity class if the given entity belonging
* to the persistence unit and to an open persistence context.
* This method may, but is not required to, load the given entity
* by side effect.
* @param entity entity instance
* @return an entity class belonging to the persistence unit
* @throws IllegalArgumentException if the given object is not an
* instance of an entity class belonging to the persistence unit
* @throws PersistenceException if the entity is not associated
* with an open persistence context or cannot be loaded from the
* database
* @since 3.2
*/
public <T> Class<? extends T> getClass(T entity);
/**
* Return the id of the entity.
* A generated id is not guaranteed to be available until after
Expand Down

0 comments on commit 4f5f0ac

Please sign in to comment.