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

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

Introduction

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

Prototype

public void setProperties(Properties properties) 

Source Link

Usage

From source file:com.brienwheeler.lib.db.MergingPersistenceUnitPostProcessor.java

/**
 * Post-process the persistence unit information.  If we have seen this persistence
 * unit name before, merge any newly-defined classes in.  Also, if any properties
 * are set on this post-processor, set them onto the target PersistenceUnitInfo
 *///from  w ww  .j av a 2  s  . c o m
@Override
public synchronized void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
    ValidationUtils.assertNotNull(pui, "persistenceUnitInfo cannot be null");
    Set<String> classes = puiClasses.get(pui.getPersistenceUnitName());
    if (classes == null) {
        classes = new LinkedHashSet<String>();
        puiClasses.put(pui.getPersistenceUnitName(), classes);
    }
    pui.getManagedClassNames().addAll(classes);
    classes.addAll(pui.getManagedClassNames());

    if (properties != null)
        pui.setProperties(properties);
}

From source file:it.scoppelletti.programmerpower.data.spi.PersistenceUnitPropertySetConfigurator.java

/**
 * Applica il contributo alla configurazione.
 *
 * <P>Questa implementazione del metodo {@code configure} imposta
 * sull&rsquo;unit&agrave; di persistenza {@code info} le propriet&agrave;
 * impostate sul profilo di configurazione {@code config} (sovrascrivendo
 * le propriet&agrave; eventualmente gi&agrave; impostate).</P>
 * //w w w  .  j a  v  a 2  s.c o m
 * @param info   Unit&agrave; di persistenza.
 * @param config Nome del profilo di configurazione.
 */
public void configure(MutablePersistenceUnitInfo info, String config) {
    Properties cfgProps, jpaProps;
    ConfigGroup cfgGroup;

    if (Strings.isNullOrEmpty(config)) {
        return;
    }

    myLogger.debug("Persistence Unit Configuration: {}.", config);
    cfgGroup = new ConfigGroup(DataUtils.CONFIG_DATA);
    cfgProps = cfgGroup.getProperties(config);
    if (cfgProps == null) {
        return;
    }

    jpaProps = info.getProperties();
    jpaProps.putAll(cfgProps);
    info.setProperties(jpaProps);
}

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 ww w.  ja  v a2s . c om
    }
    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());
    }
}