Class JpaMetadataProviderImpl

java.lang.Object
org.kuali.rice.krad.data.provider.impl.MetadataProviderBase
org.kuali.rice.krad.data.jpa.JpaMetadataProviderImpl
All Implemented Interfaces:
JpaMetadataProvider, MetadataProvider, Provider
Direct Known Subclasses:
EclipseLinkJpaMetadataProviderImpl

public abstract class JpaMetadataProviderImpl extends MetadataProviderBase implements JpaMetadataProvider
A superclass which handles most of the JPA metadata extraction.

It handles everything which can be done via the standard javax.persistence annotations. Any implementation-specific annotations must be processed in the provided abstract hook methods.

Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Field Details

    • entityManager

      protected javax.persistence.EntityManager entityManager
      The entity manager used in interacting with the database.
  • Constructor Details

    • JpaMetadataProviderImpl

      public JpaMetadataProviderImpl()
  • Method Details

    • populateImplementationSpecificEntityLevelMetadata

      protected abstract void populateImplementationSpecificEntityLevelMetadata(DataObjectMetadataImpl metadata, javax.persistence.metamodel.EntityType<?> entityType)
      Hook called after all "standard" annotations are processed to perform any further extraction based on the internals of the JPA implementation.
      Parameters:
      metadata - The metadata for the data object.
      entityType - The entity type of the data object.
    • populateImplementationSpecificAttributeLevelMetadata

      protected abstract void populateImplementationSpecificAttributeLevelMetadata(DataObjectAttributeImpl attribute, javax.persistence.metamodel.SingularAttribute<?,?> attr)
      Hook called after all "standard" attribute-level annotations are processed to perform any further extraction based on the internals of the JPA implementation.
      Parameters:
      attribute - The attribute metadata for the data object.
      attr - The persistent single-valued property or field.
    • populateImplementationSpecificCollectionLevelMetadata

      protected abstract void populateImplementationSpecificCollectionLevelMetadata(DataObjectCollectionImpl collection, javax.persistence.metamodel.PluralAttribute<?,?,?> cd)
      Hook called after all "standard" field-level annotations are processed on attributes identified as "plural" to perform any further extraction based on the internals of the JPA implementation.
      Parameters:
      collection - The collection metadata for the data object.
      cd - The persistent collection-valued attribute.
    • populateImplementationSpecificRelationshipLevelMetadata

      protected abstract void populateImplementationSpecificRelationshipLevelMetadata(DataObjectRelationshipImpl relationship, javax.persistence.metamodel.SingularAttribute<?,?> rd)
      Hook called after all "standard" field-level annotations are processed on attributes identified as "associations" to perform any further extraction based on the internals of the JPA implementation.
      Parameters:
      relationship - The relationship metadata for the data object.
      rd - The persistent single-valued property or field.
    • addExtensionRelationship

      public abstract DataObjectRelationship addExtensionRelationship(Class<?> entityClass, String extensionPropertyName, Class<?> extensionEntity)
      Given the parameters, injects into the JPA repository a 1:1 relationship between the parent entity and the extension entity via the given property name (which must exist on the entityClass).
      Specified by:
      addExtensionRelationship in interface JpaMetadataProvider
      Parameters:
      entityClass - The parent (owning) class which must be already known to the JPA persistence unit. This one's metadata will be modified within the internals of the JPA metadata.
      extensionPropertyName - The property on the parent class which will hold the extensionEntity. This property must be of the type of the extension entity or a superclass. (Object will work.)
      extensionEntity - The child/extension class which needs to be linked. It must also already be known to JPA.
      Returns:
      A 1:1 relationship between the parent entry and the extension entity via the given property name.
    • initializeMetadata

      protected void initializeMetadata(Collection<Class<?>> types)
      Performs the initialization of the provider with the given set of types.

      If the list is null or empty, the provider is expected to discover the types via other means, or do nothing if the types cannot be discovered.

      Specified by:
      initializeMetadata in class MetadataProviderBase
    • getMetadataForClass

      public DataObjectMetadata getMetadataForClass(Class<?> persistableClass)
      Extracts the data from the JPA Persistence Unit. This code assumes that the given class is persistable.
      Parameters:
      persistableClass - Class which will be looked up in OJB's static descriptor repository.
      Returns:
      the metadata for the class
    • getPrimaryKeyAttributeNames

      protected List<String> getPrimaryKeyAttributeNames(javax.persistence.metamodel.EntityType<?> entityType)
      Gets the attribute names for the primary keys from the given entity type.
      Parameters:
      entityType - The entity type of the data object.
      Returns:
      A list of primary key attribute names.
    • getSingularAttributes

      protected List<DataObjectAttribute> getSingularAttributes(Class<?> persistableClass, Collection<?> fields, List<String> primaryKeyAttributes)
      Gets a list of attributes for this data object.
      Parameters:
      persistableClass - The class of the data object.
      fields - The collection of singular attributes to process.
      primaryKeyAttributes - The list of primary key attribute names.
      Returns:
      The list of attributes for this data object.
    • getAttributeMetadata

      protected DataObjectAttribute getAttributeMetadata(Class<?> persistableClass, javax.persistence.metamodel.SingularAttribute<?,?> attr, List<String> primaryKeyAttributes)
      Gets a single field's metadata from the property descriptor.
      Parameters:
      persistableClass - The class of the data object.
      attr - The singular attribute to process.
      primaryKeyAttributes - The list of primary key attribute names.
      Returns:
      The DataObjectAttribute containing the metadata for the given attribute on the provided Class
    • getCollectionsFromMetadata

      protected List<DataObjectCollection> getCollectionsFromMetadata(Set<javax.persistence.metamodel.PluralAttribute> collections)
      Gets a collection's metadata from the property descriptor.
      Parameters:
      collections - The list of plural attributes to process.
      Returns:
      The list of collections for this data object.
    • getCollectionMetadataFromCollectionAttribute

      protected DataObjectCollection getCollectionMetadataFromCollectionAttribute(javax.persistence.metamodel.PluralAttribute cd)
      Extracts the collection metadata from a single JPA PluralAttribute object.
      Parameters:
      cd - The plural attribute to process.
      Returns:
      The collection metadata from a single JPA PluralAttribute object.
    • getRelationships

      protected List<DataObjectRelationship> getRelationships(Set<?> references)
      Gets the list of relationships for this data object.
      Parameters:
      references - The list of singular attribute references.
      Returns:
      The list of relationships for this data object.
    • getRelationshipMetadata

      protected DataObjectRelationship getRelationshipMetadata(javax.persistence.metamodel.SingularAttribute rd)
      Gets a single field's relationship metadata.
      Parameters:
      rd - The singular attribute to process.
      Returns:
      The single field's relationship metadata.
    • isClassPersistable

      public boolean isClassPersistable(Class<?> type)
      Determines whether the given class can be persisted.
      Overrides:
      isClassPersistable in class MetadataProviderBase
      Parameters:
      type - the class to check for persistability.
      Returns:
      true if the class is persistable, false otherwise.
    • setEntityManager

      public void setEntityManager(javax.persistence.EntityManager entityManager)
      Setter for the entity manager.
      Parameters:
      entityManager - The entity manager to set.
    • getEntityManager

      public javax.persistence.EntityManager getEntityManager()
      Gets the entity manager for interacting with the database.
      Returns:
      The entity manager for interacting with the database.