Example usage for org.springframework.orm.jpa.persistenceunit DefaultPersistenceUnitManager setPersistenceXmlLocation

List of usage examples for org.springframework.orm.jpa.persistenceunit DefaultPersistenceUnitManager setPersistenceXmlLocation

Introduction

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

Prototype

public void setPersistenceXmlLocation(String persistenceXmlLocation) 

Source Link

Document

Specify the location of the persistence.xml files to load.

Usage

From source file:com.eclecticlogic.pedal.JpaConfiguration.java

/**
 * @return Introduce custom persistence unit manager so that we can use the orm.xml file to rename the table
 * mapping for Student.java and verify that we pick up the renamed mapping via ProviderAccess.
 *//* w  w  w  . java 2  s .co m*/
@Bean
public PersistenceUnitManager persistenceUnitManager(DataSource dataSource) {
    DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager();
    manager.setPersistenceXmlLocation("classpath:META-INF/pedal-test-persistence.xml");
    manager.setDefaultDataSource(dataSource);
    return manager;
}

From source file:com.mycompany.projetsportmanager.spring.configuration.BaseConfiguration.java

/**
 * Builds the persistence unit manager.//from w  w  w  . j a v  a  2  s  .c  o m
 * @param dataSource the datasource.
 * @return the persistence unit manager.
 */
@Bean
public DefaultPersistenceUnitManager persistenceUnitManager() {
    DefaultPersistenceUnitManager defaultPersistenceUnitManager = new DefaultPersistenceUnitManager();
    defaultPersistenceUnitManager.setPersistenceXmlLocation("classpath*:/META-INF/persistence.xml");
    defaultPersistenceUnitManager.setDefaultDataSource(dataSource);
    return defaultPersistenceUnitManager;
}

From source file:com.brienwheeler.apps.schematool.SchemaToolBean.java

@SuppressWarnings("unchecked")
private PersistenceUnitManager simulateDefaultPum(NonInitializingClassPathXmlApplicationContext context,
        BeanDefinition emfBeanDef) {/*w ww .ja  v  a 2 s .com*/
    // Simulate Spring's use of DefaultPersistenceUnitManager
    DefaultPersistenceUnitManager defpum = new DefaultPersistenceUnitManager();

    // Set the location of the persistence XML -- when using the DPUM,
    // you can only set one persistence XML location on the EntityManagerFactory
    PropertyValue locationProperty = emfBeanDef.getPropertyValues().getPropertyValue("persistenceXmlLocation");
    if (locationProperty == null || !(locationProperty.getValue() instanceof TypedStringValue)) {
        throw new RuntimeException(
                "no property 'persistenceXmlLocation' defined on bean: " + emfContextBeanName);
    }

    // Since PersistenceUnitPostProcessors may do things like set properties
    // onto the persistence unit, we need to instantiate them here so that
    // they get called when preparePersistenceUnitInfos() executes
    PropertyValue puiPostProcProperty = emfBeanDef.getPropertyValues()
            .getPropertyValue("persistenceUnitPostProcessors");
    if (puiPostProcProperty != null && puiPostProcProperty.getValue() instanceof ManagedList) {
        List<PersistenceUnitPostProcessor> postProcessors = new ArrayList<PersistenceUnitPostProcessor>();
        for (BeanDefinitionHolder postProcBeanDef : (ManagedList<BeanDefinitionHolder>) puiPostProcProperty
                .getValue()) {
            String beanName = postProcBeanDef.getBeanName();
            BeanDefinition beanDefinition = postProcBeanDef.getBeanDefinition();
            PersistenceUnitPostProcessor postProcessor = (PersistenceUnitPostProcessor) context
                    .createBean(beanName, beanDefinition);
            postProcessors.add(postProcessor);
        }
        defpum.setPersistenceUnitPostProcessors(
                postProcessors.toArray(new PersistenceUnitPostProcessor[postProcessors.size()]));
    }

    defpum.setPersistenceXmlLocation(((TypedStringValue) locationProperty.getValue()).getValue());
    defpum.preparePersistenceUnitInfos();

    return defpum;
}