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:
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.
ORMConfigPersistenceUnitPostProcessor},
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected List<String> |
classNames |
protected List<String> |
mappingFiles |
protected String |
puName |
| Constructor and Description |
|---|
ORMConfigDto(String puName) |
| Modifier and Type | Method and Description |
|---|---|
ORMConfigDto |
addClassName(String className)
Adds the given class name o the persistence unit.
|
ORMConfigDto |
addMappingFile(String mappingFile)
Adds the given mapping file to the persistence unit
|
List<String> |
getClassNames() |
List<String> |
getMappingFiles() |
String |
getPuName() |
ORMConfigDto |
setClassNames(List<String> classNames) |
ORMConfigDto |
setMappingFiles(List<String> mappingFiles) |
protected String puName
public ORMConfigDto(String puName)
puName - the persistence unit that this should be apart of (usually "blPU"public String getPuName()
public ORMConfigDto addClassName(String className)
DomainClass.class.getName().
Doing so will trigger the class to be loaded which can cause it to skip class transformationclassName - 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.xmlthispublic ORMConfigDto setClassNames(List<String> classNames)
addClassName(String)public ORMConfigDto addMappingFile(String mappingFile)
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.xmlthispublic ORMConfigDto setMappingFiles(List<String> mappingFiles)
addMappingFile(String)Copyright © 2019. All rights reserved.