/** * {@inheritDoc} */ @SuppressWarnings("rawtypes") @Override public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) { EntityManagerFactory emf; LOG.tracef("Starting createEntityManagerFactory for persistenceUnitName %s", persistenceUnitName); try { final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, properties); if (builder == null) { LOG.trace("Could not obtain matching EntityManagerFactoryBuilder, returning null"); emf = null; } else { emf = builder.build(); } } catch (PersistenceException pe) { throw pe; } catch (Exception ex) { LOG.debug("Unable to build entity manager factory", ex); throw new PersistenceException("Unable to build entity manager factory", ex); } return emf; }
/** * Generates schema from passed persistence unit name and {@link Map} of * properties */ @SuppressWarnings("rawtypes") @Override public boolean generateSchema(String persistenceUnitName, Map map) { LOG.tracef("Starting generateSchema for persistenceUnitName %s", persistenceUnitName); boolean valid; final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, map); if (builder == null) { LOG.trace("Could not obtain matching EntityManagerFactoryBuilder, returning false"); valid = Boolean.FALSE; } else { builder.generateSchema(); valid = Boolean.TRUE; } return valid; }
@Override @SuppressWarnings("rawtypes") protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties, ClassLoader providedClassLoader) { EntityManagerFactoryBuilder builder; LOG.tracef("Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s", persistenceUnitName); final Map integration = wrap(properties); PersistenceUnitDescriptor persistenceUnit = getPersistenceXmlDescriptor(persistenceUnitName, properties, providedClassLoader); if (persistenceUnit == null) { LOG.debug("Found no matching persistence units"); builder = null; } else { builder = Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, integration, providedClassLoader); } return builder; }
@Component public EntityManagerFactory entityManagerFactory () { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(); PersistenceUnitDescriptor descriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo); EntityManagerFactoryBuilder entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(descriptor, null); return entityManagerFactoryBuilder.build(); }
/** * {@inheritDoc} */ @Override public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) { LOGGER.trace("Starting createEntityManagerFactory for persistenceUnitName {}", persistenceUnitName); try { final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, properties); if (builder == null) { LOGGER.trace("Could not obtain matching EntityManagerFactoryBuilder, returning null"); return null; } else { EntityManagerFactoryImpl impl = (EntityManagerFactoryImpl) builder; TypeResolver typeResolver = impl.getSessionFactory().getTypeResolver(); return builder.build(); } } catch (PersistenceException pe) { throw pe; } catch (Exception e) { LOGGER.debug("Unable to build entity manager factory", e); throw new PersistenceException("Unable to build entity manager factory", e); } // EntityManagerFactory entityManagerFactory = super.createEntityManagerFactory(persistenceUnitName, // properties); // if (entityManagerFactory instanceof EntityManagerFactoryImpl) { // SessionFactoryImpl sessionFactory = ((EntityManagerFactoryImpl) // entityManagerFactory).getSessionFactory(); // TypeResolver typeResolver = sessionFactory.getTypeResolver(); // // typeResolver.registerTypeOverride(type, keys); // } // return entityManagerFactory; }
@Override protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties, ClassLoader providedClassLoader) { PersistenceUnitInfo info = new RapidoidPersistenceUnitInfo(persistenceUnitName, dataSource, providedClassLoader); PersistenceUnitInfoDescriptor persistenceUnit = new PersistenceUnitInfoDescriptor(info); return emfBuilder(persistenceUnit, properties, providedClassLoader); }
@Test public void testAlternativeHibernateConfigFile() { JdbcClient h2 = JDBC.h2("test").init(); DataSource dataSource = h2.bootstrapDatasource(); CustomHibernatePersistenceProvider provider = new CustomHibernatePersistenceProvider(dataSource); Map props = U.map("hibernate.ejb.cfgfile", "hibernate.xml"); EntityManagerFactoryBuilder emfBuilder = provider.getEntityManagerFactoryBuilderOrNull("test", props, this.getClass().getClassLoader()); assertNotNull(emfBuilder); }
/** * Generates schema from {@link PersistenceUnitInfo} instance */ @SuppressWarnings("rawtypes") @Override public void generateSchema(PersistenceUnitInfo info, Map map) { LOG.tracef("Starting generateSchema : PUI.name=%s", info.getPersistenceUnitName()); PersistenceUnitDescriptor descriptor = getPersistenceUnitDescriptor(info); final EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(descriptor, map); builder.generateSchema(); }
/** * Gets {@link EntityManagerFactoryBuilder} for passed unit name and * {@link Map} of properties */ @SuppressWarnings("rawtypes") protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties) { EntityManagerFactoryBuilder emfBuilder; ClassLoader loader = MetaConfig.getOverridenClassLoader(metaConfig); emfBuilder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, properties, loader); return emfBuilder; }
@Override protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map props, @Nullable ClassLoader classLoader) { return new SdcctEntityManagerFactoryBuilder(persistenceUnitDescriptor, props, classLoader); }
@Override protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map integration, ClassLoader cl) { return emfBuilder(persistenceUnitDescriptor, integration, cl); }
private EntityManagerFactoryBuilder emfBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map integration, ClassLoader cl) { CustomDescriptor descriptor = new CustomDescriptor(persistenceUnitDescriptor, names); return super.getEntityManagerFactoryBuilder(descriptor, integration, cl); }