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


Java PersistenceUnitInfo类代码示例

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


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

示例1: init

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Before
public void init() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());

    Map<String, Object> configuration = new HashMap<>();

    Integrator integrator = integrator();
    if (integrator != null) {
        configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator));
    }

    emf = new HibernatePersistenceProvider().createContainerEntityManagerFactory(
        persistenceUnitInfo,
        configuration
    );
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:17,代码来源:AbstractJPAProgrammaticBootstrapTest.java

示例2: generateSchemaDdlFiles

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Test
public void generateSchemaDdlFiles() throws Exception {

	final PersistenceUnitInfo persistenceUnitInfo = fb.getPersistenceUnitInfo();
	final File tempDir = Files.createTempDirectory("skipper-sql-").toFile();
	final List<String> supportedHibernateDialects = new ArrayList<>();

	supportedHibernateDialects.add("H2");
	supportedHibernateDialects.add("HSQL");
	supportedHibernateDialects.add("MySQL5");
	supportedHibernateDialects.add("Oracle10g");
	supportedHibernateDialects.add("PostgreSQL94");
	supportedHibernateDialects.add("DB2");
	supportedHibernateDialects.add("SQLServer2012");

	logger.info(
		"\n\nGenerating DDL scripts for the following dialects:\n\n"
			+ supportedHibernateDialects.stream().map((db) -> db + "Dialect").collect(Collectors.joining("\n")) + "\n");

	for (String supportedHibernateDialect : supportedHibernateDialects) {
		generateDdlFiles(supportedHibernateDialect, tempDir, persistenceUnitInfo);
	}

	logger.info("\n\nYou can find the DDL scripts in directory: " + tempDir.getAbsolutePath() + "\n");

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:27,代码来源:SchemaGenerationTests.java

示例3: getEntityManager

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
private synchronized EntityManager getEntityManager(final PersistenceUnitInfo unit) {
    if (entityManagers.containsKey(unit.getPersistenceUnitName())) {
        return entityManagers.get(unit.getPersistenceUnitName());
    }
    final String providerClassName = unit.getPersistenceProviderClassName();
    try {
        final PersistenceProvider provider = (PersistenceProvider) Class.forName(providerClassName).newInstance();
        final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(unit, new HashMap());
        final EntityManager entityManager = emf.createEntityManager();
        entityManagers.put(unit.getPersistenceUnitName(), entityManager);
        entityManager.getTransaction().begin();
        return entityManager;
    } catch (final IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new TestEEfiException("Failed to load persistence provider class " + providerClassName, e);
    }
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:17,代码来源:JpaInjectionServicesImpl.java

示例4: obtainDefaultPersistenceUnitInfo

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Override
public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() {
	if (this.persistenceUnitInfoNames.isEmpty()) {
		throw new IllegalStateException("No persistence units parsed from " +
				ObjectUtils.nullSafeToString(this.persistenceXmlLocations));
	}
	if (this.persistenceUnitInfos.isEmpty()) {
		throw new IllegalStateException("All persistence units from " +
				ObjectUtils.nullSafeToString(this.persistenceXmlLocations) + " already obtained");
	}
	if (this.persistenceUnitInfos.size() > 1) {
		return obtainPersistenceUnitInfo(this.defaultPersistenceUnitName);
	}
	PersistenceUnitInfo pui = this.persistenceUnitInfos.values().iterator().next();
	this.persistenceUnitInfos.clear();
	return pui;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:DefaultPersistenceUnitManager.java

示例5: getEntityManagerFactory

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Override
public EntityManagerFactory getEntityManagerFactory(String name) {
	logger.debug("getEntityManagerFactory() ", name);
	EntityManagerFactory emf = getCache().get(name, EntityManagerFactory.class);
	if (emf == null) {
		logger.debug("EMF not loaded, loading now...");
		Properties prop = new Properties();
		prop.setProperty(JKPersistenceUnitProperties.JDBC_DRIVER, getDriverName());
		prop.setProperty(JKPersistenceUnitProperties.JDBC_PASSWORD, getPassword());
		prop.setProperty(JKPersistenceUnitProperties.JDBC_URL, getDatabaseUrl());
		prop.setProperty(JKPersistenceUnitProperties.JDBC_USER, getUsername());
		PersistenceUnitInfo persisitnceUnitInfo = getPersisitnceUnitInfo(name, prop, getEntitiesPackages());
		emf = JKEntityManagerFactory.createEntityManagerFactory(persisitnceUnitInfo);
		logger.debug("add to emf cache ");
		getCache().cache(name, emf, EntityManagerFactory.class);
	}
	return emf;
}
 
开发者ID:kiswanij,项目名称:jk-db,代码行数:19,代码来源:JKDefaultDataSource.java

示例6: testMetaInfCase

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Test
public void testMetaInfCase() throws Exception {
	PersistenceUnitReader reader = new PersistenceUnitReader(
			new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
	String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml";
	PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

	assertNotNull(info);
	assertEquals(1, info.length);
	assertEquals("OrderManagement", info[0].getPersistenceUnitName());

	assertEquals(2, info[0].getJarFileUrls().size());
	assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0));
	assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1));

	assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:PersistenceXmlParsingTests.java

示例7: testExample2

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Test
public void testExample2() throws Exception {
	PersistenceUnitReader reader = new PersistenceUnitReader(
			new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
	String resource = "/org/springframework/orm/jpa/persistence-example2.xml";
	PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

	assertNotNull(info);
	assertEquals(1, info.length);

	assertEquals("OrderManagement2", info[0].getPersistenceUnitName());

	assertEquals(1, info[0].getMappingFileNames().size());
	assertEquals("mappings.xml", info[0].getMappingFileNames().get(0));
	assertEquals(0, info[0].getProperties().keySet().size());

	assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:PersistenceXmlParsingTests.java

示例8: testExample3

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Test
public void testExample3() throws Exception {
	PersistenceUnitReader reader = new PersistenceUnitReader(
			new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
	String resource = "/org/springframework/orm/jpa/persistence-example3.xml";
	PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

	assertNotNull(info);
	assertEquals(1, info.length);
	assertEquals("OrderManagement3", info[0].getPersistenceUnitName());

	assertEquals(2, info[0].getJarFileUrls().size());
	assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0));
	assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1));

	assertEquals(0, info[0].getProperties().keySet().size());
	assertNull(info[0].getJtaDataSource());
	assertNull(info[0].getNonJtaDataSource());

	assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:PersistenceXmlParsingTests.java

示例9: testExample5

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Test
public void testExample5() throws Exception {
	PersistenceUnitReader reader = new PersistenceUnitReader(
			new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
	String resource = "/org/springframework/orm/jpa/persistence-example5.xml";
	PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

	assertNotNull(info);
	assertEquals(1, info.length);
	assertEquals("OrderManagement5", info[0].getPersistenceUnitName());

	assertEquals(2, info[0].getMappingFileNames().size());
	assertEquals("order1.xml", info[0].getMappingFileNames().get(0));
	assertEquals("order2.xml", info[0].getMappingFileNames().get(1));

	assertEquals(2, info[0].getJarFileUrls().size());
	assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0));
	assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1));

	assertEquals("com.acme.AcmePersistence", info[0].getPersistenceProviderClassName());
	assertEquals(0, info[0].getProperties().keySet().size());

	assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:PersistenceXmlParsingTests.java

示例10: createEntityManagerFactory

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Override
public EntityManagerFactory createEntityManagerFactory(String unitName, Map map) {
   PersistenceUnitInfo info = createPersistenceUnitInfo(unitName);
   if (info == null) {
      log.info("no persistence unit found with name " + unitName);
      return null;
   }

   if (getClass().getName().equals(info.getPersistenceProviderClassName())
         || (map != null && getClass().getName().equals(map.get(PERSISTENCE_PROVIDER_PROPERTY)))) {
      log.info("create resource_local EntityManagerFactory");
      logInfo(info, map);

      boolean loadEager = isLoadEager(info, map);
      persistenceProvider = createNativePersistenceProvider(info, map);
      map = createPersistenceProviderProperty(map, persistenceProvider);
      EntityManagerFactory nativeEntityManagerFactory = persistenceProvider.createEntityManagerFactory(unitName,
            map);
      return new CibetEntityManagerFactory(nativeEntityManagerFactory, loadEager);
   } else {
      log.debug(this.getClass().getName() + " does not match provider for persistence unit " + unitName);
      return null;
   }
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:25,代码来源:Provider.java

示例11: createPersistenceUnitInfo

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
protected PersistenceUnitInfo createPersistenceUnitInfo(String persistenceUnitName) {
   try {
      PersistenceXmlParser persistenceXmlParser = new PersistenceXmlParser();
      for (Enumeration<URL> persistenceFiles = Thread.currentThread().getContextClassLoader()
            .getResources(PERSISTENCE_FILE); persistenceFiles.hasMoreElements();) {
         URL persistenceFile = persistenceFiles.nextElement();
         persistenceXmlParser.parse(persistenceFile);
         if (persistenceXmlParser.containsPersistenceUnitInfo(persistenceUnitName)) {
            PersistenceUnitInfo persistenceUnitInfo = persistenceXmlParser
                  .getPersistenceUnitInfo(persistenceUnitName);
            return persistenceUnitInfo;
         }
      }
      return null;
   } catch (IOException e) {
      throw new PersistenceException(e);
   }
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:19,代码来源:Provider.java

示例12: logInfo

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
protected void logInfo(PersistenceUnitInfo info, Map map) {
   if (log.isDebugEnabled()) {
      if (map != null && map.size() > 0) {
         log.debug(this + " properties: ---------------------");
         Iterator<Map.Entry<?, ?>> it = map.entrySet().iterator();
         while (it.hasNext()) {
            Map.Entry<?, ?> entry = it.next();
            log.debug(entry.getKey() + " = " + entry.getValue());
         }
      }

      if (log.isDebugEnabled()) {
         log.debug("PersistenceUnitInfo properties: ---------------------");
         log.debug(info);
      }
   }

}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:19,代码来源:Provider.java

示例13: createEntityManagerFactory

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Override
public EntityManagerFactory createEntityManagerFactory(String unitName, Map map) {
   registerCibetDriver();

   PersistenceUnitInfo info = createPersistenceUnitInfo(unitName);
   if (info == null) {
      log.info("no persistence unit found with name " + unitName);
      return null;
   }

   if (getClass().getName().equals(info.getPersistenceProviderClassName())
         || (map != null && getClass().getName().equals(map.get(PERSISTENCE_PROVIDER_PROPERTY)))) {
      log.info("create resource-local JdbcBridgeEntityManagerFactory");
      logInfo(info, map);

      return new JdbcBridgeEntityManagerFactory(resolveDataSource(info));

   } else {
      log.debug(this.getClass().getName() + " does not match provider for persistence unit " + unitName);
      return null;
   }
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:23,代码来源:JdbcBridgeProvider.java

示例14: resolveDataSource

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
private DataSource resolveDataSource(PersistenceUnitInfo info) {
   String url = null;
   String user = null;
   String password = null;

   if (info.getProperties().containsKey(HIBERNATE_URL)) {
      url = info.getProperties().getProperty(HIBERNATE_URL);
      user = info.getProperties().getProperty(HIBERNATE_USER);
      password = info.getProperties().getProperty(HIBERNATE_PASSWORD);
      return new DefaultDataSource(url, user, password);
   }

   if (info.getProperties().containsKey(JAVAX_URL)) {
      url = info.getProperties().getProperty(JAVAX_URL);
      user = info.getProperties().getProperty(JAVAX_USER);
      password = info.getProperties().getProperty(JAVAX_PASSWORD);
      return new DefaultDataSource(url, user, password);
   }

   return info.getNonJtaDataSource();
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:22,代码来源:JdbcBridgeProvider.java

示例15: createContainerEntityManagerFactory

import javax.persistence.spi.PersistenceUnitInfo; //导入依赖的package包/类
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo unitInfo, Map properties) {
    if (properties == null) {
        properties = new HashMap<String, Object>();
    } else {
        properties = new HashMap<String, Object>(properties);
    }
    PersistenceProvider nativePersistenceProvider = createNativePersistenceProvider(unitInfo, properties);
    if (nativePersistenceProvider == null) {
        return null;
    }
    EntityManagerFactory nativeFactory
        = nativePersistenceProvider.createContainerEntityManagerFactory(unitInfo, properties);
    List<String> ormXmlLocations = new ArrayList<String>(unitInfo.getMappingFileNames());
    ormXmlLocations.add(DEFAULT_ORM_XML_LOCATION);
    Class<? extends SecurityContext> securityContextType = createSecurityContextType(unitInfo, properties);
    Class<? extends AccessRulesProvider> accessRulesProviderType
        = createAccessRulesProviderType(unitInfo, properties);
    return new SecureEntityManagerFactory(unitInfo.getPersistenceUnitName(),
                                          nativeFactory,
                                          ormXmlLocations,
                                          securityContextType,
                                          accessRulesProviderType);
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:25,代码来源:SecurePersistenceProvider.java


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