当前位置: 首页>>代码示例>>Java>>正文


Java DefaultPersistenceUnitManager类代码示例

本文整理汇总了Java中org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager的典型用法代码示例。如果您正苦于以下问题:Java DefaultPersistenceUnitManager类的具体用法?Java DefaultPersistenceUnitManager怎么用?Java DefaultPersistenceUnitManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultPersistenceUnitManager类属于org.springframework.orm.jpa.persistenceunit包,在下文中一共展示了DefaultPersistenceUnitManager类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureMergedItems

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
@PostConstruct
public void configureMergedItems() {
    String[] tempLocations;
    try {
        Field persistenceXmlLocations = DefaultPersistenceUnitManager.class.getDeclaredField("persistenceXmlLocations");
        persistenceXmlLocations.setAccessible(true);
        tempLocations = (String[]) persistenceXmlLocations.get(this);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    for (String legacyLocation : tempLocations) {
        if (!legacyLocation.endsWith("/persistence.xml")) {
            //do not add the default JPA persistence location by default
            mergedPersistenceXmlLocations.add(legacyLocation);
        }
    }
    setPersistenceXmlLocations(mergedPersistenceXmlLocations.toArray(new String[mergedPersistenceXmlLocations.size()]));

    if (!mergedDataSources.isEmpty()) {
        setDataSources(mergedDataSources);
    }
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:23,代码来源:MergePersistenceUnitManager.java

示例2: persistenceUnitManager

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
/**
 * @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.
 */
@Bean
public PersistenceUnitManager persistenceUnitManager(DataSource dataSource) {
    DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager();
    manager.setPersistenceXmlLocation("classpath:META-INF/pedal-test-persistence.xml");
    manager.setDefaultDataSource(dataSource);
    return manager;
}
 
开发者ID:eclecticlogic,项目名称:pedal-dialect,代码行数:12,代码来源:JpaConfiguration.java

示例3: generateSchema

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
public void generateSchema() throws MojoFailureException
{
    final Map<String, Object> cfg = buildCfg();
    String[] allBasePackages = this.getBasePackages();
    getLog().info("Using base packages " + StringUtils.arrayToDelimitedString(allBasePackages, ", "));
    final PersistenceProvider provider = new PersistenceProvider();
    final DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager();
    manager.setDefaultPersistenceUnitRootLocation(null);
    manager.setDefaultPersistenceUnitName("default");
    manager.setPackagesToScan(allBasePackages);
    manager.setPersistenceXmlLocations(new String[0]);
    manager.afterPropertiesSet();

    final SmartPersistenceUnitInfo puInfo = (SmartPersistenceUnitInfo) manager.obtainDefaultPersistenceUnitInfo();
    puInfo.setPersistenceProviderPackageName(provider.getClass().getName());
    getLog().info("Entities found : " + puInfo.getManagedClassNames().size());
    getLog().debug("Managed class names:\n    * " + StringUtils.collectionToDelimitedString(puInfo.getManagedClassNames(), "\n    * "));
    puInfo.getProperties().putAll(cfg);
    provider.generateSchema(new DelegatingPuInfo(puInfo), cfg);
}
 
开发者ID:ethlo,项目名称:eclipselink-maven-plugin,代码行数:21,代码来源:EclipselinkDdlGenerationMojo.java

示例4: postProcessBeforeInitialization

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LocalContainerEntityManagerFactoryBean) {
		((LocalContainerEntityManagerFactoryBean) bean).setLoadTimeWeaver(this.ltw);
	}
	if (bean instanceof DefaultPersistenceUnitManager) {
		((DefaultPersistenceUnitManager) bean).setLoadTimeWeaver(this.ltw);
	}
	return bean;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AbstractJpaTests.java

示例5: corePersistenceUnitManager

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
@Bean(name="corePersistenceUnitManager")
@Primary
public PersistenceUnitManager corePersistenceUnitManager(DatabaseSelector dataSource) {
	DefaultPersistenceUnitManager persistenceUnitManager = new DefaultPersistenceUnitManager();
	persistenceUnitManager.setDefaultDataSource(dataSource);
	persistenceUnitManager.setPackagesToScan("edu.cmu.cs.lti.discoursedb.core.model");
	persistenceUnitManager.setDefaultPersistenceUnitName("corePersistenceUnitManager");
	return persistenceUnitManager;
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:10,代码来源:BaseConfiguration.java

示例6: systemPersistenceUnitManager

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
@Bean(name="systemPersistenceUnitManager")
public PersistenceUnitManager systemPersistenceUnitManager() {
	DefaultPersistenceUnitManager persistenceUnitManager = new DefaultPersistenceUnitManager();
	persistenceUnitManager.setDefaultDataSource(this.systemDataSource());
	persistenceUnitManager.setPackagesToScan("edu.cmu.cs.lti.discoursedb.system.model");
	persistenceUnitManager.setDefaultPersistenceUnitName("systemPersistenceUnitManager");
	return persistenceUnitManager;
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:9,代码来源:SystemDbConfiguration.java

示例7: createPersistenceUnitManager

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
/**
 * Creates a persistence unit manager.
 *
 * @return a persistence unit manager.
 */
protected DefaultPersistenceUnitManager createPersistenceUnitManager() {
    DefaultPersistenceUnitManager pum = new DefaultPersistenceUnitManager();
    // IMPORTANT! - setting these to empty String arrays, this triggers the DefaultPersistenceUnitManager to
    // behave appropriately and ignore persistence.xml files from META-INF/persistence.xml as well as allowing for
    // an empty/minimal persistence unit to be created.
    //
    // Note that while Intellij complains about "Redundant array creation for calling varargs method", we really do
    // need to pass an empty array here in order for this code to work properly.
    pum.setPersistenceXmlLocations(new String[0]);
    pum.setMappingResources(new String[0]);
    pum.setPackagesToScan(new String[0]);
    return pum;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:19,代码来源:KradEntityManagerFactoryBean.java

示例8: postProcessBeforeInitialization

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LocalContainerEntityManagerFactoryBean) {
		((LocalContainerEntityManagerFactoryBean) bean).setLoadTimeWeaver(this.ltw);
	}
	if (bean instanceof DefaultPersistenceUnitManager) {
		((DefaultPersistenceUnitManager) bean).setLoadTimeWeaver(this.ltw);
	}
	return bean;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:10,代码来源:AbstractJpaTests.java

示例9: preparePersistentUnitManager

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
private PersistenceUnitManager preparePersistentUnitManager(Config config, String prefix, DataSource datasource) {
	DefaultPersistenceUnitManager persistenceUnitManager = new DefaultPersistenceUnitManager();
	persistenceUnitManager.setDefaultDataSource(datasource);
	persistenceUnitManager.setPersistenceXmlLocations(new String[] {determineConfigProperty(config, prefix, "PersistenceXmlLocation", "META-INF/persistence.xml")});
	persistenceUnitManager.setDefaultPersistenceUnitRootLocation(determineConfigProperty(config, prefix, "PersistenceUnitRootLocation", "classpath:"));
	RicePersistenceUnitPostProcessor postProcessor = new RicePersistenceUnitPostProcessor();
	postProcessor.setJtaDataSource(datasource);
	persistenceUnitManager.setPersistenceUnitPostProcessors(new RicePersistenceUnitPostProcessor[] { postProcessor });
	persistenceUnitManager.afterPropertiesSet();
	return persistenceUnitManager;
}
 
开发者ID:aapotts,项目名称:kuali_rice,代码行数:12,代码来源:RiceLocalContainerEntityManagerFactoryBean.java

示例10: createEMFWithSpring

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
private EntityManagerFactory createEMFWithSpring(){

        DriverManagerDataSource dataSource = new DriverManagerDataSource();

        // DriverManagerDataSource uses the context classloader for some reason...
        ClassLoader cl1 = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(EvoEntityManagerFactory.class.getClassLoader());
        dataSource.setDriverClassName(org.hsqldb.jdbcDriver.class.getName());
        dataSource.setUrl("jdbc:hsqldb:mem:.");
        dataSource.setUsername("sa");
        dataSource.setPassword("");
        Thread.currentThread().setContextClassLoader(cl1);

        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(dataSource);
        em.setPackagesToScan(""); //search everything on classpath
        em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());


        try {
            /*
                The code in this class works fine on Mac, but somehow it crashes on Debian (Lux cluster).
                So, the following is just a workaround, although not fully understood while on Debian
                it was behaving differently
             */
            Field f = LocalContainerEntityManagerFactoryBean.class.getDeclaredField("internalPersistenceUnitManager");
            f.setAccessible(true);
            DefaultPersistenceUnitManager m = (DefaultPersistenceUnitManager)f.get(em);
            m.setDefaultPersistenceUnitRootLocation(null);
        } catch (Exception e) {
            e.printStackTrace();
        }

        Properties properties = new Properties();
        properties.setProperty("hibernate.show_sql", "true");
        properties.setProperty("hibernate.dialect", HSQLDialect.class.getName());
        properties.setProperty("hibernate.connection.shutdown", "true");
        properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
        properties.setProperty("hibernate.classloading.use_current_tccl_as_parent", "false");
        em.setJpaProperties(properties);


        em.afterPropertiesSet();

        return em.getObject();
    }
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:47,代码来源:EvoEntityManagerFactory.java

示例11: generate

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
private void generate() throws Exception {
    Map<String, Object> map = JpaSchemaGeneratorUtils.buildProperties(this);
    if (getVendor() == null) {
        // with persistence.xml
        Persistence.generateSchema(this.persistenceUnitName, map);
    } else {
        PersistenceProvider provider = getProviderClass().newInstance();
        List<String> packages = getPackageToScan();
        if (packages.isEmpty()) {
            throw new IllegalArgumentException("packageToScan is required on xml-less mode.");
        }

        DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager();
        manager.setDefaultPersistenceUnitName(getPersistenceUnitName());
        manager.setPackagesToScan(packages.toArray(new String[packages.size()]));
        // issue #22
        Field persistenceXmlLocations = manager.getClass().getDeclaredField("persistenceXmlLocations");
        persistenceXmlLocations.setAccessible(true);
        persistenceXmlLocations.set(manager, new String[0]);
        manager.afterPropertiesSet();

        SmartPersistenceUnitInfo info = (SmartPersistenceUnitInfo) manager.obtainDefaultPersistenceUnitInfo();
        info.setPersistenceProviderPackageName(provider.getClass().getName());
        info.getProperties().putAll(map);

        // Path persistenceXml = null;
        /* @formatter:off */
        // if (Vendor.datanucleus.equals(getVendor())) {
        // // datanucleus must need persistence.xml
        // Path path = Paths.get(project.getBuild().getOutputDirectory(), "META-INF");
        // persistenceXml = Files.createTempFile(path, "persistence-", ".xml");
        // try (BufferedWriter writer = Files.newBufferedWriter(persistenceXml, StandardCharsets.UTF_8)) {
        // PrintWriter out = new PrintWriter(writer);
        // out.println("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
        // out.println("<persistence version=\"2.1\"");
        // out.println(" xmlns=\"http://xmlns.jcp.org/xml/ns/persistence\"
        // xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
        // out.println(" xsi:schemaLocation=\"http://xmlns.jcp.org/xml/ns/persistence
        // http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd\">");
        // out.printf(" <persistence-unit name=\"%s\" transaction-type=\"RESOURCE_LOCAL\">\n",
        // info.getPersistenceUnitName());
        // out.println(" <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>");
        // out.println(" <exclude-unlisted-classes>false</exclude-unlisted-classes>");
        // out.println(" </persistence-unit>");
        // out.println("</persistence>");
        // }
        // map.put(PropertyNames.PROPERTY_PERSISTENCE_XML_FILENAME, persistenceXml.toAbsolutePath().toString());
        // // datanucleus does not support execution order...
        // map.remove(PersistenceUnitProperties.SCHEMA_GENERATION_CREATE_SOURCE);
        // map.remove(PersistenceUnitProperties.SCHEMA_GENERATION_DROP_SOURCE);
        // }
        /* @formatter:on */

        try {
            provider.generateSchema(info, map);
        } finally {
            // if (persistenceXml != null) {
            // Files.delete(persistenceXml);
            // }
        }
    }
}
 
开发者ID:divinespear,项目名称:jpa-schema-maven-plugin,代码行数:63,代码来源:JpaSchemaGeneratorMojo.java

示例12: getPersistenceUnitManager

import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; //导入依赖的package包/类
/**
 * Returns a reference to the internal {@link DefaultPersistenceUnitManager} which is used by this factory bean.
 *
 * @return the internal persistence unit manager, will never return null
 */
protected DefaultPersistenceUnitManager getPersistenceUnitManager() {
    return persistenceUnitManager;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:9,代码来源:KradEntityManagerFactoryBean.java


注:本文中的org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。