Example usage for org.springframework.orm.jpa.persistenceunit MutablePersistenceUnitInfo addManagedClassName

List of usage examples for org.springframework.orm.jpa.persistenceunit MutablePersistenceUnitInfo addManagedClassName

Introduction

In this page you can find the example usage for org.springframework.orm.jpa.persistenceunit MutablePersistenceUnitInfo addManagedClassName.

Prototype

public void addManagedClassName(String managedClassName) 

Source Link

Document

Add a managed class name to the persistence provider's metadata.

Usage

From source file:org.xaloon.core.jpa.spring.EntityProvidingPUPostProcessor.java

public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) {
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Processing persistence unit " + mutablePersistenceUnitInfo);
    }//from  w ww.  j  a  va 2  s  .  c o  m

    for (Map.Entry<String, EntityListProvider> entry : applicationContext
            .getBeansOfType(EntityListProvider.class).entrySet()) {
        EntityListProvider provider = entry.getValue();
        for (String entityClass : provider.getEntities()) {
            if (mutablePersistenceUnitInfo.getManagedClassNames().contains(entityClass)) {
                LOGGER.info("Entity " + entityClass + " is already registered. Duplicate resides in bean named "
                        + entry.getKey());
            } else {
                LOGGER.info("Adding entity " + entityClass + " from bean named " + entry.getKey());
                mutablePersistenceUnitInfo.addManagedClassName(entityClass);
            }
        }
    }

}

From source file:fr.paris.lutece.util.jpa.JPAPersistenceUnitPostProcessor.java

/**
 * Scans for *.orm.xml and adds Entites from classpath.
 *
 * @param pui the pui//  w w w.  j  ava 2 s.c  om
 */
@Override
public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
    _Log.info("Scanning for JPA orm.xml files");

    for (File ormFile : getListORMFiles()) {
        String ormAbsolutePath = ormFile.getAbsolutePath();
        _Log.info("Found ORM file : " + ormAbsolutePath);
        pui.addMappingFileName(ormAbsolutePath.substring(ormAbsolutePath.indexOf(CLASSPATH_PATH_IDENTIFIER)));
    }

    _Log.info("Scanning for JPA entities...");

    Set<String> entityClasses = AnnotationUtil.find(Entity.class.getName());
    entityClasses.addAll(AnnotationUtil.find(Embeddable.class.getName()));
    entityClasses.addAll(AnnotationUtil.find(MappedSuperclass.class.getName()));

    for (String strClass : entityClasses) {
        _Log.info("Found entity class : " + strClass);

        if (!pui.getManagedClassNames().contains(strClass)) {
            pui.addManagedClassName(strClass);
        }
    }

    if (_Log.isDebugEnabled()) {
        dumpPersistenceUnitInfo(pui);
    }
}

From source file:net.ggtools.maven.ddlgenerator.MultiConfigAwarePersistenceUnitManager.java

/**
 * Merges a persistence unit to another one. Takes care of handling both
 * managed classes and urls. If the persistence unit has managed classes,
 * only merge these and prevents scanning. If no managed classes are
 * available, add the url of the module for entity scanning.
 *
 * @param from the persistence unit to handle
 * @param to   the target (merged) persistence unit
 */// w  ww  . ja v  a 2s .co  m
protected void mergePersistenceUnit(MutablePersistenceUnitInfo from, MutablePersistenceUnitInfo to) {
    if (from.getMappingFileNames().size() != 0) {
        for (String s : from.getMappingFileNames()) {
            if (log.isDebugEnabled()) {
                log.debug("Adding entity [" + s + "]");
            }
            to.addMappingFileName(s);
        }
        if (log.isDebugEnabled()) {
            log.debug("Added [" + from.getMappingFileNames().size() + "] mapping file to " + "persistence unit["
                    + to.getPersistenceUnitName() + "]");
        }
    } else if (from.getManagedClassNames().size() != 0) {
        for (String s : from.getManagedClassNames()) {
            if (log.isDebugEnabled()) {
                log.debug("Adding entity [" + s + "]");
            }
            to.addManagedClassName(s);
        }
        if (log.isDebugEnabled()) {
            log.debug("Added [" + from.getManagedClassNames().size() + "] managed classes to "
                    + "persistence unit[" + to.getPersistenceUnitName() + "]");
        }
    } else {
        to.addJarFileUrl(from.getPersistenceUnitRootUrl());
        if (log.isDebugEnabled()) {
            log.debug("Added [" + from.getPersistenceUnitRootUrl() + "] for entity scanning "
                    + "to persistence unit[" + to.getPersistenceUnitName() + "]");
        }
    }
}

From source file:org.broadleafcommerce.common.extensibility.jpa.MergePersistenceUnitManager.java

@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);
        }/*from   w  w  w  . ja  v a 2s . c  o  m*/
    }
    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()) {
        // Avoid duplicate class scanning by Ejb3Configuration. Do not re-add the URL to the list of jars for this
        // 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);
                    }
                }
            }
        }
    }
    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());
    }
}