javax.persistence.spi.PersistenceUnitInfo Java Examples
The following examples show how to use
javax.persistence.spi.PersistenceUnitInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }
Example #2
Source File: DefaultPersistenceUnitManager.java From java-technology-stack with MIT License | 6 votes |
@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 && this.defaultPersistenceUnitName != null) { return obtainPersistenceUnitInfo(this.defaultPersistenceUnitName); } PersistenceUnitInfo pui = this.persistenceUnitInfos.values().iterator().next(); this.persistenceUnitInfos.clear(); return pui; }
Example #3
Source File: DefaultPersistenceUnitManager.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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; }
Example #4
Source File: JpaPersistence.java From javamelody with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public EntityManagerFactory createContainerEntityManagerFactory(final PersistenceUnitInfo info, final Map map) { initJpaCounter(); final PersistenceProvider persistenceProvider = findDelegate(map); // on surcharge PersistenceUnitInfo.getPersistenceProviderClassName() // pour retourner le PersistenceProvider délégué et pas nous même final PersistenceUnitInfo proxiedInfo = createPersistentUnitInfoProxy(info, persistenceProvider); final Map overridenMap = new HashMap(); if (map != null) { overridenMap.putAll(map); } // #869 No Persistence provider for EntityManager, with Hibernate 5.4 & JPA // (when JpaOverridePersistenceXmlClassLoader is not enough) overridenMap.put(JPA_PERSISTENCE_PROVIDER, persistenceProvider.getClass().getName()); final EntityManagerFactory entityManagerFactory = persistenceProvider .createContainerEntityManagerFactory(proxiedInfo, overridenMap); if (entityManagerFactory == null) { return null; } return JpaWrapper.createEntityManagerFactoryProxy(entityManagerFactory); }
Example #5
Source File: Hibernate3JPAHelper.java From HotswapAgent with GNU General Public License v2.0 | 6 votes |
/** * Creates the container entity manager factory proxy. * * @param info persistent unit definition * @param properties properties to create entity manager factory * @param original entity manager factory * @return proxy of entity manager */ public static EntityManagerFactory createContainerEntityManagerFactoryProxy(PersistenceUnitInfo info, Map<?,?> properties, EntityManagerFactory original) { // ensure only once if (wrappedPersistenceUnitNames.contains(info.getPersistenceUnitName())){ return original; } wrappedPersistenceUnitNames.add(info.getPersistenceUnitName()); EntityManagerFactoryProxy wrapper = EntityManagerFactoryProxy.getWrapper(info.getPersistenceUnitName()); EntityManagerFactory proxy = wrapper.proxy(original, info.getPersistenceUnitName(), info, properties); initPlugin(original); LOGGER.debug("Returning container EntityManager proxy {} instead of EntityManager {}", proxy.getClass(), original); return proxy; }
Example #6
Source File: EntityManagerFactoryProxy.java From HotswapAgent with GNU General Public License v2.0 | 6 votes |
private void buildFreshEntityManagerFactory() { try { Class ejb3ConfigurationClazz = loadClass("org.hibernate.ejb.Ejb3Configuration"); LOGGER.trace("new Ejb3Configuration()"); Object cfg = ejb3ConfigurationClazz.newInstance(); LOGGER.trace("cfg.configure( info, properties );"); if (info != null) { ReflectionHelper.invoke(cfg, ejb3ConfigurationClazz, "configure", new Class[]{PersistenceUnitInfo.class, Map.class}, info, properties); } else { ReflectionHelper.invoke(cfg, ejb3ConfigurationClazz, "configure", new Class[]{String.class, Map.class}, persistenceUnitName, properties); } LOGGER.trace("configured.buildEntityManagerFactory()"); currentInstance = (EntityManagerFactory) ReflectionHelper.invoke(cfg, ejb3ConfigurationClazz, "buildEntityManagerFactory", new Class[]{}); } catch (Exception e) { LOGGER.error("Unable to build fresh entity manager factory for persistence unit {}", persistenceUnitName); } }
Example #7
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }
Example #8
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }
Example #9
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #10
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }
Example #11
Source File: AbstractJPAProgrammaticBootstrapTest.java From high-performance-java-persistence with Apache License 2.0 | 6 votes |
@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 ); }
Example #12
Source File: EntityManagerBean.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
void init(final PersistenceUnitInfo info, final BeanManager bm) { final PersistenceProvider provider; try { provider = PersistenceProvider.class.cast( Thread.currentThread().getContextClassLoader().loadClass(info.getPersistenceProviderClassName()).newInstance()); } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new IllegalArgumentException("Bad provider: " + info.getPersistenceProviderClassName()); } final EntityManagerFactory factory = provider.createContainerEntityManagerFactory(info, new HashMap() {{ put("javax.persistence.bean.manager", bm); if (ValidationMode.NONE != info.getValidationMode()) { ofNullable(findValidatorFactory(bm)).ifPresent(factory -> put("javax.persistence.validation.factory", factory)); } }}); instanceFactory = synchronization == SynchronizationType.SYNCHRONIZED ? factory::createEntityManager : () -> factory.createEntityManager(synchronization); }
Example #13
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }
Example #14
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #15
Source File: SpringHibernateJpaPersistenceProvider.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("rawtypes") public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { final List<String> mergedClassesAndPackages = new ArrayList<String>(info.getManagedClassNames()); if (info instanceof SmartPersistenceUnitInfo) { mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages()); } return new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(info) { @Override public List<String> getManagedClassNames() { return mergedClassesAndPackages; } }, properties).build(); }
Example #16
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testExample1() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example1.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #17
Source File: EntityManagerFactoryProvider.java From hammock with Apache License 2.0 | 5 votes |
public EntityManagerFactory lookupEntityManagerFactory(String name) { return entityManagerFactoryMap.computeIfAbsent(name, s -> { PersistenceUnitInfo persistenceUnitInfo = jpaExtension.getPersistenceUnitInfo(name); if (s.equals(DEFAULT_EMF) && persistenceUnitInfo == null) { persistenceUnitInfo = getDefaultPersistenceUnitInfo(); } if (persistenceUnitInfo != null) { PersistenceProvider provider = getPersistenceProvider(); return provider.createContainerEntityManagerFactory(persistenceUnitInfo, emptyMap()); } else { Map<String, String> properties = ConfigLoader.loadAllProperties(createPrefix(s), true); return Persistence.createEntityManagerFactory(s, properties); } }); }
Example #18
Source File: SpringHibernateEjbPersistenceProvider.java From spring4-understanding with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { Ejb3Configuration cfg = new Ejb3Configuration(); if (info instanceof SmartPersistenceUnitInfo) { for (String managedPackage : ((SmartPersistenceUnitInfo) info).getManagedPackages()) { cfg.addPackage(managedPackage); } } Ejb3Configuration configured = cfg.configure(info, properties); return (configured != null ? configured.buildEntityManagerFactory() : null); }
Example #19
Source File: DefaultPersistenceUnitManager.java From java-technology-stack with MIT License | 5 votes |
@Override public PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName) { PersistenceUnitInfo pui = this.persistenceUnitInfos.remove(persistenceUnitName); if (pui == null) { if (!this.persistenceUnitInfoNames.contains(persistenceUnitName)) { throw new IllegalArgumentException( "No persistence unit with name '" + persistenceUnitName + "' found"); } else { throw new IllegalStateException( "Persistence unit with name '" + persistenceUnitName + "' already obtained"); } } return pui; }
Example #20
Source File: SpringHibernateJpaPersistenceProvider.java From java-technology-stack with MIT License | 5 votes |
@Override @SuppressWarnings("rawtypes") public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { final List<String> mergedClassesAndPackages = new ArrayList<>(info.getManagedClassNames()); if (info instanceof SmartPersistenceUnitInfo) { mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages()); } return new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(info) { @Override public List<String> getManagedClassNames() { return mergedClassesAndPackages; } }, properties).build(); }
Example #21
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testExample6() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example6.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertEquals(1, info.length); assertEquals("pu", info[0].getPersistenceUnitName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #22
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testJpa2ExcludeUnlisted() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-exclude-2.0.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals("The number of persistence units is incorrect.", 4, info.length); PersistenceUnitInfo noExclude = info[0]; assertNotNull("noExclude should not be null.", noExclude); assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName()); assertFalse("Exclude unlisted still defaults to false in 2.0.", noExclude.excludeUnlistedClasses()); PersistenceUnitInfo emptyExclude = info[1]; assertNotNull("emptyExclude should not be null.", emptyExclude); assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName()); assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses()); PersistenceUnitInfo trueExclude = info[2]; assertNotNull("trueExclude should not be null.", trueExclude); assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName()); assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses()); PersistenceUnitInfo falseExclude = info[3]; assertNotNull("falseExclude should not be null.", falseExclude); assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName()); assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses()); }
Example #23
Source File: AbstractTest.java From hibernate-types with Apache License 2.0 | 5 votes |
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<String, Object>(); HibernatePersistence hibernatePersistence = new HibernatePersistence(); return hibernatePersistence.createContainerEntityManagerFactory(persistenceUnitInfo, configuration); }
Example #24
Source File: AbstractTest.java From hibernate-types with Apache License 2.0 | 5 votes |
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<>(); configuration.put(AvailableSettings.INTERCEPTOR, interceptor()); Integrator integrator = integrator(); if (integrator != null) { configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator)); } final List<Type> additionalTypes = additionalTypes(); if (additionalTypes != null) { configuration.put("hibernate.type_contributors", (TypeContributorList) () -> { List<TypeContributor> typeContributors = new ArrayList<>(); for (Type additionalType : additionalTypes) { if (additionalType instanceof BasicType) { typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((BasicType) additionalType)); } else if (additionalType instanceof UserType) { typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((UserType) additionalType)); } else if (additionalType instanceof CompositeUserType) { typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((CompositeUserType) additionalType)); } } return typeContributors; }); } EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
Example #25
Source File: AbstractTest.java From hibernate-master-class with Apache License 2.0 | 5 votes |
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = new PersistenceUnitInfoImpl( getClass().getSimpleName(), entityClassNames(), getProperties() ); Map<String, Object> configuration = new HashMap<>(); configuration.put(org.hibernate.jpa.AvailableSettings.INTERCEPTOR, interceptor()); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
Example #26
Source File: EntityManagerFactoryProxy.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
/** * Builds the fresh entity manager factory. */ // from HibernatePersistence.createContainerEntityManagerFactory() private void buildFreshEntityManagerFactory() { try { Class<?> ejb3ConfigurationClazz = loadClass("org.hibernate.ejb.Ejb3Configuration"); LOGGER.trace("new Ejb3Configuration()"); Object cfg = ejb3ConfigurationClazz.newInstance(); LOGGER.trace("cfg.configure( info, properties );"); if (info != null) { ReflectionHelper.invoke(cfg, ejb3ConfigurationClazz, "configure", new Class[]{PersistenceUnitInfo.class, Map.class}, info, properties); } else { ReflectionHelper.invoke(cfg, ejb3ConfigurationClazz, "configure", new Class[]{String.class, Map.class}, persistenceUnitName, properties); } LOGGER.trace("configured.buildEntityManagerFactory()"); currentInstance = (EntityManagerFactory) ReflectionHelper.invoke(cfg, ejb3ConfigurationClazz, "buildEntityManagerFactory", new Class[]{}); } catch (Exception e) { LOGGER.error("Unable to build fresh entity manager factory for persistence unit {}", persistenceUnitName); } }
Example #27
Source File: AbstractTest.java From hypersistence-optimizer with Apache License 2.0 | 5 votes |
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<String, Object>(); configuration.put(AvailableSettings.INTERCEPTOR, interceptor()); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
Example #28
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testExample4() throws Exception { SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); DataSource ds = new DriverManagerDataSource(); builder.bind("java:comp/env/jdbc/MyDB", ds); PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example4.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement4", info[0].getPersistenceUnitName()); assertEquals(1, info[0].getMappingFileNames().size()); assertEquals("order-mappings.xml", info[0].getMappingFileNames().get(0)); assertEquals(3, info[0].getManagedClassNames().size()); assertEquals("com.acme.Order", info[0].getManagedClassNames().get(0)); assertEquals("com.acme.Customer", info[0].getManagedClassNames().get(1)); assertEquals("com.acme.Item", info[0].getManagedClassNames().get(2)); assertTrue("Exclude unlisted should be true when no value.", info[0].excludeUnlistedClasses()); assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info[0].getTransactionType()); assertEquals(0, info[0].getProperties().keySet().size()); builder.clear(); }
Example #29
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testJpa1ExcludeUnlisted() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-exclude-1.0.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals("The number of persistence units is incorrect.", 4, info.length); PersistenceUnitInfo noExclude = info[0]; assertNotNull("noExclude should not be null.", noExclude); assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName()); assertFalse("Exclude unlisted should default false in 1.0.", noExclude.excludeUnlistedClasses()); PersistenceUnitInfo emptyExclude = info[1]; assertNotNull("emptyExclude should not be null.", emptyExclude); assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName()); assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses()); PersistenceUnitInfo trueExclude = info[2]; assertNotNull("trueExclude should not be null.", trueExclude); assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName()); assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses()); PersistenceUnitInfo falseExclude = info[3]; assertNotNull("falseExclude should not be null.", falseExclude); assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName()); assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses()); }
Example #30
Source File: JPAPluginTest.java From minnal with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() { plugin = spy(new JPAPlugin()); provider = mock(PersistenceProvider.class); persistenceUnitInfo = mock(PersistenceUnitInfo.class); application = mock(Application.class); ApplicationConfiguration configuration = mock(ApplicationConfiguration.class); when(configuration.getName()).thenReturn("test"); when(configuration.getDatabaseConfiguration()).thenReturn(mock(DatabaseConfiguration.class)); when(application.getConfiguration()).thenReturn(configuration); doReturn(persistenceUnitInfo).when(plugin).createPersistenceUnitInfo(configuration, provider); doReturn(Arrays.asList(provider)).when(plugin).getProviders(); }