/** * A part of the facade over the JPA API. * Create an EntityManagerFactory using the given PersistenceUnitInfo and properties. * @param info * @param properties * @return */ protected EntityManagerFactoryImpl createEntityManagerFactory(PersistenceUnitInfo info, Map<String, ?> properties) { PersistenceProvider provider = new PersistenceProvider(); EntityManagerFactory emf = provider.createContainerEntityManagerFactory(info, properties); return (EntityManagerFactoryImpl) emf; }
/** * Called by Persistence class when an EntityManagerFactory * is to be created. * * @param emName The name of the persistence unit * @param properties A Map of properties for use by the * persistence provider. These properties may be used to * override the values of the corresponding elements in * the persistence.xml file or specify values for * properties not specified in the persistence.xml. * @return EntityManagerFactory for the persistence unit, * or null if the provider is not the right provider */ @Override public EntityManagerFactory createEntityManagerFactory(String emName, Map properties){ Map nonNullProperties = (properties == null) ? new HashMap() : properties; if (checkForProviderProperty(nonNullProperties)){ String name = (emName == null) ? "" : emName; JPAInitializer initializer = getInitializer(name, nonNullProperties); return createEntityManagerFactoryImpl(initializer.findPersistenceUnitInfo(name, nonNullProperties), nonNullProperties, true); } // Not EclipseLink so return null; return null; }
/** * Create database schemas and/or tables and/or create DDL * scripts as determined by the supplied properties. * <p> * Called by the Persistence class when schema generation is to occur as a * separate phase from creation of the entity manager factory. * <p> * @param info the name of the persistence unit * @param properties properties for schema generation; these may also * contain provider-specific properties. The value of these * properties override any values that may have been configured * elsewhere. * @throws PersistenceException if insufficient or inconsistent * configuration information is provided of if schema generation * otherwise fails * * @since Java Persistence 2.1 */ @Override public void generateSchema(PersistenceUnitInfo info, Map properties) { if (checkForProviderProperty(properties)) { // Bug 458462 - Generate the DDL and then close. This method is // called when running within a container. createContainerEntityManagerFactoryImpl(info, properties, false).close(); } }
/** Create a new persistence provider for unit tests. */ public static PersistenceProvider testPersistenceProvider() { return new org.eclipse.persistence.jpa.PersistenceProvider(); }
new PersistenceProvider().createEntityManagerFactory("streamflow-pu", properties);
private void performDllGeneration() throws MalformedURLException { for (String eachDatabaseProductName : this.databaseProductNames) { String[] allBasePackages = this.getBasePackages(); this.logger.info("Using base packages " + Joiner.on(", ").join(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 MutablePersistenceUnitInfo puInfo = (MutablePersistenceUnitInfo) manager.obtainDefaultPersistenceUnitInfo(); puInfo.setPersistenceProviderPackageName(provider.getClass().getName()); puInfo.setPersistenceUnitRootUrl(new URL("http://foo.bar")); this.logger.info("Managed classes found: " + puInfo.getManagedClassNames().size()); this.logger.debug("Managed class names:\n -> " + Joiner.on("\n -> ").join(puInfo.getManagedClassNames())); final Map<String, Object> properties = this.buildProperties(eachDatabaseProductName); puInfo.getProperties().putAll(properties); provider.generateSchema(puInfo, properties); } } }
SEPersistenceUnitInfo puInfo = (SEPersistenceUnitInfo) pu.getPersistenceUnitInfo(); JPAInitializer initializer = new PersistenceProvider().getInitializer(name, null); Map<String, Object> props = new HashMap<String, Object>();
return createContainerEntityManagerFactory(info, properties);
EntityManagerSetupImpl emSetupImpl = null; String puName = puInfo.getPersistenceUnitName(); JPAInitializer initializer = getInitializer(puInfo.getPersistenceUnitName(), properties); return (EntityManagerFactoryImpl) createEntityManagerFactory(puName, properties);
/** * Called by the container when an EntityManagerFactory * is to be created. * * @param info Metadata for use by the persistence provider * @return EntityManagerFactory for the persistence unit * specified by the metadata * @param properties A Map of integration-level properties for use * by the persistence provider. */ @Override public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { return createContainerEntityManagerFactoryImpl(info, properties, true); }
/** Create a new persistence provider for unit tests. */ public static PersistenceProvider mkTestPersistenceProvider() { return new org.eclipse.persistence.jpa.PersistenceProvider(); }
/** * A part of the facade over the JPA API. * Create an EntityManagerFactory using the given PersistenceUnitInfo and properties. * @param info * @param properties * @return */ protected EntityManagerFactoryImpl createEntityManagerFactory(PersistenceUnitInfo info, Map<String, ?> properties) { PersistenceProvider provider = new PersistenceProvider(); EntityManagerFactory emf = provider.createContainerEntityManagerFactory(info, properties); return (EntityManagerFactoryImpl) emf; }
props.put(PersistenceUnitProperties.SESSION_CUSTOMIZER,MySessionCustomizer.class.getName()); EntityManagerFactory factory = new PersistenceProvider().createEntityManagerFactory(pu.getPersistenceUnitName(), props);
if (checkForProviderProperty(nonNullProperties)) { JPAInitializer initializer = getInitializer(puName, nonNullProperties); SEPersistenceUnitInfo puInfo = initializer.findPersistenceUnitInfo(puName, nonNullProperties); if (puInfo != null && checkForProviderProperty(properties)) { createEntityManagerFactoryImpl(puInfo, properties, false).close(); return true;
@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; } }
@Override public List<PersistenceProvider> getPersistenceProviders() { return Arrays.<PersistenceProvider>asList(new DummyPersistenceProvider(), new org.eclipse.persistence.jpa.PersistenceProvider()); }