use of org.broadleafcommerce.common.extensibility.jpa.convert.BroadleafClassTransformer in project BroadleafCommerce by BroadleafCommerce.
the class MergePersistenceUnitManager method addTransformersToPersistenceUnits.
/**
* Adds all of the configured {@link #classTransformers} to all of the persistence units
* @return whether or not there was a LoadTimeWeaver registered
* @throws Exception if there was an undetectable problem during transformer addition
*/
protected boolean addTransformersToPersistenceUnits() throws Exception {
boolean weaverRegistered = true;
for (PersistenceUnitInfo pui : mergedPus.values()) {
if (pui.getProperties().containsKey(AvailableSettings.USE_CLASS_ENHANCER) && "true".equalsIgnoreCase(pui.getProperties().getProperty(AvailableSettings.USE_CLASS_ENHANCER))) {
pui.addTransformer(new InterceptFieldClassFileTransformer(pui.getManagedClassNames()));
}
for (BroadleafClassTransformer transformer : classTransformers) {
try {
boolean isTransformerQualified = !(transformer instanceof NullClassTransformer) && (pui.getPersistenceUnitName().equals("blPU") && !(transformer instanceof BroadleafPersistenceUnitDeclaringClassTransformer)) || ((transformer instanceof BroadleafPersistenceUnitDeclaringClassTransformer) && pui.getPersistenceUnitName().equals(((BroadleafPersistenceUnitDeclaringClassTransformer) transformer).getPersistenceUnitName()));
if (isTransformerQualified) {
pui.addTransformer(transformer);
}
} catch (Exception e) {
weaverRegistered = handleClassTransformerRegistrationProblem(transformer, e);
}
}
}
weaverRegistered = addNamedQueriesToPersistenceUnits(weaverRegistered);
return weaverRegistered;
}
use of org.broadleafcommerce.common.extensibility.jpa.convert.BroadleafClassTransformer in project BroadleafCommerce by BroadleafCommerce.
the class MergePersistenceUnitManager method exceptionIfEntityMarkerNotFound.
/**
* Detects the presence of the {@link EntityMarkerClassTransformer} and throws an exception if this is misconfigured. If there
* are no class transformes within {@link #mergedClassTransformers} then this does nothing
*/
protected void exceptionIfEntityMarkerNotFound() {
if (CollectionUtils.isNotEmpty(mergedClassTransformers)) {
boolean foundEntityMarkerTransformer = IterableUtils.find(mergedClassTransformers, new Predicate<BroadleafClassTransformer>() {
@Override
public boolean evaluate(BroadleafClassTransformer object) {
return EntityMarkerClassTransformer.class.isAssignableFrom(object.getClass());
}
}) != null;
if (!foundEntityMarkerTransformer) {
BeanDefinition transformersBeanDef = ((BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory()).getBeanDefinition("blMergedClassTransformers");
String msg = "The EntityMarkerClassTransformer was not detected as registered in the the list of blMergedClassTransformers. This is" + " usually caused the blMergedClassTransformers being overridden in a different configuration. Without this transformer Broadleaf" + " is unable to validate whether or not class transformation happened as expected. This bean was registered as " + transformersBeanDef + " but it should have been detected as registerd in bl-common-applicationContext.xml. Change the definition in " + transformersBeanDef.getResourceDescription() + " to instead utilize the EarlyStageMergeBeanPostProcessor in XML or an @Merge(targetRef=\"blMergedClassTransformers\" early = true) in a Java configuration class";
throw new IllegalStateException(msg);
}
}
}
use of org.broadleafcommerce.common.extensibility.jpa.convert.BroadleafClassTransformer in project BroadleafCommerce by BroadleafCommerce.
the class MergePersistenceUnitManager method postProcessPersistenceUnitInfo.
@Override
protected void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo newPU) {
super.postProcessPersistenceUnitInfo(newPU);
ConfigurationOnlyState state = ConfigurationOnlyState.getState();
String persistenceUnitName = newPU.getPersistenceUnitName();
MutablePersistenceUnitInfo pui = getMergedUnit(persistenceUnitName, newPU);
List<String> managedClassNames = newPU.getManagedClassNames();
for (String managedClassName : managedClassNames) {
if (!pui.getManagedClassNames().contains(managedClassName)) {
pui.addManagedClassName(managedClassName);
}
}
List<String> mappingFileNames = newPU.getMappingFileNames();
for (String mappingFileName : mappingFileNames) {
if (!pui.getMappingFileNames().contains(mappingFileName)) {
pui.addMappingFileName(mappingFileName);
}
}
pui.setExcludeUnlistedClasses(newPU.excludeUnlistedClasses());
for (URL url : newPU.getJarFileUrls()) {
// persistence unit or duplicate the persistence unit root URL location (both types of locations are scanned)
if (!pui.getJarFileUrls().contains(url) && !pui.getPersistenceUnitRootUrl().equals(url)) {
pui.addJarFileUrl(url);
}
}
if (pui.getProperties() == null) {
pui.setProperties(newPU.getProperties());
} else {
Properties props = newPU.getProperties();
if (props != null) {
for (Object key : props.keySet()) {
pui.getProperties().put(key, props.get(key));
for (BroadleafClassTransformer transformer : classTransformers) {
try {
transformer.compileJPAProperties(props, key);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
disableSchemaCreateIfApplicable(persistenceUnitName, pui);
if (state == null || !state.isConfigurationOnly()) {
if (newPU.getJtaDataSource() != null) {
pui.setJtaDataSource(newPU.getJtaDataSource());
}
if (newPU.getNonJtaDataSource() != null) {
pui.setNonJtaDataSource(newPU.getNonJtaDataSource());
}
} else {
pui.getProperties().setProperty("hibernate.hbm2ddl.auto", "none");
pui.getProperties().setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
}
pui.setTransactionType(newPU.getTransactionType());
if (newPU.getPersistenceProviderClassName() != null) {
pui.setPersistenceProviderClassName(newPU.getPersistenceProviderClassName());
}
if (newPU.getPersistenceProviderPackageName() != null) {
pui.setPersistenceProviderPackageName(newPU.getPersistenceProviderPackageName());
}
}
Aggregations