@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(); }
/** * Enriches and configures passed {@link PersistenceUnitInfo} wrapper * * @param info * @return {@link PersistenceUnitDescriptor} */ protected PersistenceUnitDescriptor getPersistenceUnitDescriptor(PersistenceUnitInfo info) { PersistenceUnitDescriptor descriptor = new PersistenceUnitSwapDescriptor(info); PersistenceDescriptorUtils.resolve(descriptor, metaConfig); return descriptor; }
/** * {@inheritDoc} * <p/> * Improved with transaction and data source swapping properties */ @SuppressWarnings("rawtypes") @Override public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { EntityManagerFactory emf; LOG.tracef("Starting createContainerEntityManagerFactory : %s", info.getPersistenceUnitName()); PersistenceUnitDescriptor descriptor = getPersistenceUnitDescriptor(info); emf = Bootstrap.getEntityManagerFactoryBuilder(descriptor, properties).build(); return emf; }
/** * 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(); }
private static void setTransactionType(PersistenceUnitDescriptor persistenceUnit, PersistenceUnitTransactionType type) { if (persistenceUnit instanceof ParsedPersistenceXmlDescriptor) { ObjectUtils.cast(persistenceUnit, ParsedPersistenceXmlDescriptor.class).setTransactionType(type); } else if (persistenceUnit instanceof PersistenceUnitSwapDescriptor) { ObjectUtils.cast(persistenceUnit, PersistenceUnitSwapDescriptor.class).setTransactionType(type); } }
private static void setNonJtaDataSource(PersistenceUnitDescriptor persistenceUnit, Object dataSource) { if (persistenceUnit instanceof ParsedPersistenceXmlDescriptor) { ObjectUtils.cast(persistenceUnit, ParsedPersistenceXmlDescriptor.class).setNonJtaDataSource(dataSource); } else if (persistenceUnit instanceof PersistenceUnitSwapDescriptor) { ObjectUtils.cast(persistenceUnit, PersistenceUnitSwapDescriptor.class).setNonJtaDataSource(dataSource); } }
private static void addClasses(PersistenceUnitDescriptor persistenceUnit, List<String> classes) { if (persistenceUnit instanceof ParsedPersistenceXmlDescriptor) { ObjectUtils.cast(persistenceUnit, ParsedPersistenceXmlDescriptor.class).addClasses(classes); } else if (persistenceUnit instanceof PersistenceUnitSwapDescriptor) { ObjectUtils.cast(persistenceUnit, PersistenceUnitSwapDescriptor.class).addClasses(classes); } }
/** * Resolves data source from {@link MetaConfig} object * * @param persistenceUnit * @param metaConfig */ public static void resolveDataSource(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) { Object dataSource = persistenceUnit.getJtaDataSource(); if (MetaConfig.isSwapDataSource(metaConfig)) { setNonJtaDataSource(persistenceUnit, dataSource); } }
/** * Resolves entity classes from {@link MetaConfig} object * * @param persistenceUnit * @param metaConfig */ public static void resolveEntities(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) { List<String> classes = MetaConfig.getClasses(metaConfig); if (CollectionUtils.valid(classes)) { addClasses(persistenceUnit, classes); } }
public SdcctEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnit, Map props, @Nullable ClassLoader classLoader) { super(persistenceUnit, props, classLoader); }
@Override protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map props, @Nullable ClassLoader classLoader) { return new SdcctEntityManagerFactoryBuilder(persistenceUnitDescriptor, props, classLoader); }
protected static EntityManagerFactoryBuilderImpl getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map<String, Object> integration, ClassLoader providedClassLoader) { return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoader ); }
public CustomDescriptor(PersistenceUnitDescriptor descriptor, List<String> names) { this.descriptor = descriptor; this.names = names; this.names.addAll(U.safe(descriptor.getManagedClassNames())); }
@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); }
/** * Creates {@link PersistenceUnitDescriptor} for passed persistence unit * name {@link Map} of properties and {@link ClassLoader} instance * * @param persistenceUnitName * @param properties * @param providedClassLoader * @return {@link PersistenceUnitDescriptor} */ @SuppressWarnings({ "rawtypes" }) public PersistenceUnitDescriptor getPersistenceXmlDescriptor(String persistenceUnitName, Map properties, ClassLoader providedClassLoader) { ParsedPersistenceXmlDescriptor descriptor = null; final Map integration = wrap(properties); final List<ParsedPersistenceXmlDescriptor> units; try { units = PersistenceXmlParserImpl.locatePersistenceUnits(integration, metaConfig); } catch (Exception ex) { LOG.debug("Unable to locate persistence units", ex); throw new PersistenceException("Unable to locate persistence units", ex); } LOG.debugf("Located and parsed %s persistence units; checking each", units.size()); if (persistenceUnitName == null && units.size() > CollectionUtils.SINGLTON_LENGTH) { // no persistence-unit name to look for was given and we found // multiple persistence-units throw new PersistenceException("No name provided and multiple persistence units found"); } boolean notMatches = Boolean.TRUE; Iterator<ParsedPersistenceXmlDescriptor> descriptorIterator = units.iterator(); ParsedPersistenceXmlDescriptor persistenceUnit; while (descriptorIterator.hasNext() && notMatches) { persistenceUnit = descriptorIterator.next(); LOG.debugf( "Checking persistence-unit [name=%s, explicit-provider=%s] against incoming persistence unit name [%s]", persistenceUnit.getName(), persistenceUnit.getProviderClassName(), persistenceUnitName); final boolean matches = (persistenceUnitName == null || persistenceUnitName.equals(persistenceUnit.getName())); notMatches = Boolean.FALSE.equals(matches); if (notMatches) { LOG.debug("Excluding from consideration due to name mis-match"); // See if we (Hibernate) are the persistence provider } else if (Boolean.FALSE.equals(ProviderChecker.isProvider(persistenceUnit, properties))) { LOG.debug("Excluding from consideration due to provider mis-match"); } else { descriptor = persistenceUnit; } } return descriptor; }
@SuppressWarnings({ "rawtypes" }) public PersistenceUnitDescriptor getPersistenceUnitDescriptor(String persistenceUnitName, Map properties) { PersistenceUnitDescriptor persistenceUnit; ClassLoader loader = MetaConfig.getOverridenClassLoader(metaConfig); persistenceUnit = getPersistenceXmlDescriptor(persistenceUnitName, properties, loader); return persistenceUnit; }
/** * Resolved which transaction type should be set from {@link MetaConfig} * object * * @param persistenceUnit * @param metaConfig */ public static void resolveTransactionType(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) { if (MetaConfig.isSwapDataSource(metaConfig)) { setTransactionType(persistenceUnit, PersistenceUnitTransactionType.RESOURCE_LOCAL); } }
/** * Changes JPA configuration and resolves additional data from * {@link MetaConfig} parameter * * @param persistenceUnit * @param metaConfig */ public static void resolve(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) { PersistenceDescriptorUtils.resolveTransactionType(persistenceUnit, metaConfig); PersistenceDescriptorUtils.resolveDataSource(persistenceUnit, metaConfig); PersistenceDescriptorUtils.resolveEntities(persistenceUnit, metaConfig); }