java.lang.Object
org.broadleafcommerce.common.extensibility.jpa.ORMConfigDto
All Implemented Interfaces:
Serializable

public class ORMConfigDto extends Object implements Serializable

Holder for mapping files (orm.xml) and entity classes to be contributed to the MergePersistenceUnitManager without being specified directly in a persistence.xml file. Use cases this is designed to support:

  • Prividing a fully-qualified-classname to add to the managed classes of the persistence unit (like an additional @Entity class)
  • Providing a classpath-relative location to an orm.xml file to add to the mapping files for additional queries

Generally, this will be registered conditionally within an @Conditional. Example:

 @Bean
 @ConditionalOnClass("com.broadleafcommerce.somemodule.domain.DomainClass")
 public ORMConfigDto newManagedDomainClass() {
     return new ORMConfigDto("blPU")
         .addClassName("com.broadleafcommerce.somemodule.domain.DomainClass");
 }
 

Note that this functionality can also be achieved by creating multiple persistence.xml files and conditionally adding it to blMergedPersistenceXmlLocations like so:

 @Merge("blMergedPersistenceXmlLocations")
 @ConditionalOnClass("com.broadleafcommerce.somemodule.domain.DomainClass")
 public ORMConfigDto newManagedDomainClass() {
     return Arrays.asList("persistence-domainclass.xml");
 }
 

This can be attractive if you have a large set of classes or mapping files to dynamically add to a persistence unit.

Author:
Nick Crum ncrum, Phillip Verheyden (phillipuniverse)
See Also:
  • Field Details

    • puName

      protected String puName
    • classNames

      protected List<String> classNames
    • mappingFiles

      protected List<String> mappingFiles
  • Constructor Details

    • ORMConfigDto

      public ORMConfigDto(String puName)
      Parameters:
      puName - the persistence unit that this should be apart of (usually "blPU"
  • Method Details

    • getPuName

      public String getPuName()
      Returns:
      the persistence unit that this should be apart of
    • addClassName

      public ORMConfigDto addClassName(String className)
      Adds the given class name o the persistence unit. Note that this should generally not reference the class name by DomainClass.class.getName(). Doing so will trigger the class to be loaded which can cause it to skip class transformation
      Parameters:
      className - a fully-qualfied classname that should be added to this persistence unit's managed classes. This is equivalent to specifying an additional <class></class> entry in a persistence.xml
      Returns:
      this
    • getClassNames

      @Nullable public List<String> getClassNames()
    • setClassNames

      public ORMConfigDto setClassNames(List<String> classNames)
      See Also:
    • addMappingFile

      public ORMConfigDto addMappingFile(String mappingFile)
      Adds the given mapping file to the persistence unit
      Parameters:
      mappingFile - a classpath-relative location to a .orm.xml file that contains additional HQL queries or other XML configuration. This is equivalent to using the <mapping-file></mapping-file> entry in a persistence.xml
      Returns:
      this
    • getMappingFiles

      public List<String> getMappingFiles()
    • setMappingFiles

      public ORMConfigDto setMappingFiles(List<String> mappingFiles)
      See Also: