@Override public Properties getProperties() { return persistenceUnitInfo.getProperties(); }
public Ejb3Configuration getConfiguration() { synchronized(this) { if (configuration == null) { Ejb3Configuration temp = new Ejb3Configuration(); String previousValue = persistenceUnitInfo.getProperties().getProperty("hibernate.hbm2ddl.auto"); persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", "none"); configuration = temp.configure(persistenceUnitInfo, new HashMap()); configuration.getHibernateConfiguration().buildSessionFactory(); if (previousValue != null) { persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", previousValue); } } } return configuration; }
boolean weaverRegistered = true; for (PersistenceUnitInfo pui : mergedPus.values()) { if (pui.getProperties().containsKey(AvailableSettings.USE_CLASS_ENHANCER) && "true".equalsIgnoreCase(pui.getProperties().getProperty(AvailableSettings.USE_CLASS_ENHANCER))) { pui.addTransformer(new InterceptFieldClassFileTransformer(pui.getManagedClassNames()));
@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()); }
@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()); }
@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()); }
@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()); }
@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(); }
Properties props = pu1.getProperties(); assertEquals(2, props.keySet().size()); assertEquals("on", props.getProperty("com.acme.persistence.sql-logging"));
@Override public EntityManagerFactory createContainerEntityManagerFactory(final PersistenceUnitInfo info, final Map map) { final String keyspaceName = value(KEYSPACE_PROP, map, info.getProperties()); final String host = value(HOST_PROP, map, info.getProperties()); final String clusterName = value(CLUSTER_PROP, map, info.getProperties()); final String consistency = value(CONSISTENCY_PROP, map, info.getProperties()); final Keyspace keyspace = keyspace(host, clusterName, keyspaceName, consistency); final AnnotationScanner scanner = createScanner(value(SCANNER, map, info.getProperties())); return new EntityManagerFactoryImpl(info, keyspace, scanner); }
public EntityManagerFactoryImpl(final PersistenceUnitInfo info, final Keyspace space, final AnnotationScanner scanner) { if (!info.excludeUnlistedClasses()) { final Class<?>[] classes = new Class<?>[info.getManagedClassNames().size()]; final ClassLoader cl = Thread.currentThread().getContextClassLoader(); int i = 0; for (String name : info.getManagedClassNames()) { try { classes[i++] = cl.loadClass(name); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } em = new EntityManagerImpl(space, this, classes); } else { em = new EntityManagerImpl(space, this, info.getProperties().getProperty(PACKAGES_TO_SCAN).split(","), scanner); } }
metadata.getProperties().putAll(puInfo.getProperties());
@Override public Properties getProperties() { return persistenceUnitInfo.getProperties(); }
@Override public Properties getProperties() { return delegator.getProperties(); }
protected Map mergeWithExistingMap(Map m) { if(persistenceUnitInfo != null) { return mergeMaps(m, persistenceUnitInfo.getProperties()); } else { return m; } }
public static boolean mustBeCompositeMember(PersistenceUnitInfo puInfo) { String mustBeCompositeMemberStr = PropertiesHandler.getPropertyValue(PersistenceUnitProperties.COMPOSITE_UNIT_MEMBER, puInfo.getProperties(), false); if(mustBeCompositeMemberStr != null) { return mustBeCompositeMemberStr.equals("true"); } else { return false; } } public static boolean isComposite(PersistenceUnitInfo puInfo) {
public static boolean isComposite(PersistenceUnitInfo puInfo) { String isCompositeString = PropertiesHandler.getPropertyValue(PersistenceUnitProperties.COMPOSITE_UNIT, puInfo.getProperties(), false); if(isCompositeString != null) { return isCompositeString.equals("true"); } else { return false; } }
protected Map mergeWithExistingMap(Map m) { if(predeployProperties != null) { return mergeMaps(m, predeployProperties); } else if(persistenceUnitInfo != null) { return mergeMaps(m, persistenceUnitInfo.getProperties()); } else { return m; } }
/** * Creates an EntityManagerFactory for a persistence unit specified by the property overrides. The EMF is created by parsing all persistence.xml files on * the classpath. * * @param overrides persistence unit property overrides * @param classLoader the persistence unit classloader * @return the entity manager factory * @throws Fabric3Exception if there is an error creating the factory */ private EntityManagerFactory createEntityManagerFactory(PersistenceOverrides overrides, ClassLoader classLoader) throws Fabric3Exception { List<PersistenceUnitInfo> infos = parser.parse(classLoader); String unitName = overrides.getUnitName(); for (PersistenceUnitInfo info : infos) { if (!unitName.equals(info.getPersistenceUnitName())) { // Not the most efficient approach: parse all of the persistence units and only keep the one we are requested in, potentially // resulting in parsing the units multiple times. // This must be done since the overrides may not be loaded for all units continue; } Properties unitProperties = info.getProperties(); unitProperties.setProperty(HIBERNATE_LOOKUP, F3TransactionManagerLookup.class.getName()); unitProperties.putAll(overrides.getProperties()); PersistenceUnitInfoDescriptor descriptor = new PersistenceUnitInfoDescriptor(info); EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilderImpl(descriptor, Collections.emptyMap(), classLoader); return builder.build(); } throw new Fabric3Exception("Persistence unit not defined for: " + unitName); }
@Override protected EntityManagerFactory createEntityManagerFactory(PersistenceUnitInfo persistenceUnitInfo) { org.eclipse.persistence.jpa.PersistenceProvider p = new org.eclipse.persistence.jpa.PersistenceProvider(); EntityManagerFactoryImpl factory = (EntityManagerFactoryImpl)p.createContainerEntityManagerFactory(persistenceUnitInfo, C.Map()); ClassLoader sessionLoader = factory.getServerSession().getLoader(); if (app().classLoader() != sessionLoader) { HashMap properties = new HashMap<>(); properties.put(PersistenceUnitProperties.CLASSLOADER, app().classLoader()); properties.putAll(persistenceUnitInfo.getProperties()); factory.refreshMetadata(properties); } return factory; } }