Search in sources :

Example 1 with PersistenceUnitInfo

use of javax.persistence.spi.PersistenceUnitInfo in project robo4j by Robo4J.

the class PersistenceContextBuilder method build.

public PersistenceContextBuilder build() {
    PersistenceDescriptorFactory persistenceDescriptorFactory = new PersistenceDescriptorFactory();
    PersistenceUnitInfo persistenceUnitInfo = persistenceDescriptorFactory.get(RoboClassLoader.getInstance().getClassLoader(), sourceType, packages);
    PersistenceUnitDescriptor persistenceUnitDescriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo);
    EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilderImpl(persistenceUnitDescriptor, new HashMap<>());
    registeredClasses = persistenceDescriptorFactory.registeredClasses();
    dataSourceContext = new DataSourceProxy(builder.build());
    return this;
}
Also used : PersistenceUnitInfoDescriptor(org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor) EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) PersistenceDescriptorFactory(com.robo4j.db.sql.jpa.PersistenceDescriptorFactory) PersistenceUnitDescriptor(org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)

Example 2 with PersistenceUnitInfo

use of javax.persistence.spi.PersistenceUnitInfo in project spring-framework by spring-projects.

the class ExtendedEntityManagerCreator method createProxy.

/**
	 * Actually create the EntityManager proxy.
	 * @param rawEntityManager raw EntityManager
	 * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect
	 * and PersistenceUnitInfo from
	 * @param containerManaged whether to follow container-managed EntityManager
	 * or application-managed EntityManager semantics
	 * @param synchronizedWithTransaction whether to automatically join ongoing
	 * transactions (according to the JPA 2.1 SynchronizationType rules)
	 * @return the EntityManager proxy
	 */
private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) {
    Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null");
    JpaDialect jpaDialect = emfInfo.getJpaDialect();
    PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo();
    Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null);
    return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(), emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction);
}
Also used : PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo)

Example 3 with PersistenceUnitInfo

use of javax.persistence.spi.PersistenceUnitInfo in project Payara by payara.

the class DefaultProviderVerification method check.

public Result check(Descriptor descriptor) {
    PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
    Result result = getInitializedResult();
    result.setStatus(Result.PASSED);
    PersistenceProvider provider;
    final String appLocation = getVerifierContext().getAbstractArchive().getURI().getPath();
    final InstrumentableClassLoader cl = InstrumentableClassLoader.class.cast(pu.getParent().getClassLoader());
    PersistenceUnitInfo pi = new AVKPersistenceUnitInfoImpl(pu, appLocation, cl);
    logger.fine("PersistenceInfo for PU is :\n" + pi);
    Properties props = new Properties();
    // This property is set to indicate that TopLink should only
    // validate the descriptors etc. and not try to login to database.
    props.put(PersistenceUnitProperties.VALIDATION_ONLY_PROPERTY, // NOI18N
    "TRUE");
    // This property is used so that TopLink throws validation exceptions
    // as opposed to printing CONFIG level messages to console.
    // e.g. if mapping file does not exist, we will get an exception.
    props.put(PersistenceUnitProperties.THROW_EXCEPTIONS, // NOI18N
    "TRUE");
    // the following property is needed as it initializes the logger in TL
    props.put(PersistenceUnitProperties.TARGET_SERVER, // NOI18N
    "SunAS9");
    // Turn off enhancement during verification. For details,
    // refer to http://glassfish.dev.java.net/issues/show_bug.cgi?id=3295
    props.put(PersistenceUnitProperties.WEAVING, "FALSE");
    provider = new org.eclipse.persistence.jpa.PersistenceProvider();
    EntityManagerFactory emf = null;
    try {
        emf = provider.createContainerEntityManagerFactory(pi, props);
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "emf = {0}", emf);
    } catch (IntegrityException ie) {
        result.setStatus(Result.FAILED);
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        for (Object o : ie.getIntegrityChecker().getCaughtExceptions()) {
            Exception e = Exception.class.cast(o);
            result.addErrorDetails(e.getMessage());
        }
    } catch (ValidationException ve) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(ve.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", ve);
    } catch (DatabaseException de) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(de.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", de);
    } catch (PersistenceException pe) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(pe.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", pe);
    } finally {
        if (emf != null) {
            emf.close();
        }
    }
    return result;
}
Also used : ValidationException(org.eclipse.persistence.exceptions.ValidationException) InstrumentableClassLoader(org.glassfish.api.deployment.InstrumentableClassLoader) PersistenceProvider(javax.persistence.spi.PersistenceProvider) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) AVKPersistenceUnitInfoImpl(com.sun.enterprise.tools.verifier.persistence.AVKPersistenceUnitInfoImpl) Properties(java.util.Properties) PersistenceUnitProperties(org.eclipse.persistence.config.PersistenceUnitProperties) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) PersistenceException(javax.persistence.PersistenceException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) Result(com.sun.enterprise.tools.verifier.Result) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceException(javax.persistence.PersistenceException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor)

Example 4 with PersistenceUnitInfo

use of javax.persistence.spi.PersistenceUnitInfo in project BroadleafCommerce by BroadleafCommerce.

the class MergePersistenceUnitManager method triggerClassLoadForManagedClasses.

/**
 * Triggers a class load via this class's {@link ClassLoader} for all of the classes in all of the persistence units
 *
 * @throws ClassNotFoundException if there was a problem in the class load
 * @return all of the classes that were loaded via this process
 */
protected List<String> triggerClassLoadForManagedClasses() throws ClassNotFoundException {
    List<String> managedClassNames = new ArrayList<>();
    for (PersistenceUnitInfo pui : mergedPus.values()) {
        for (String managedClassName : pui.getManagedClassNames()) {
            if (!managedClassNames.contains(managedClassName)) {
                // Force-load this class so that we are able to ensure our instrumentation happens globally.
                // If transformation is happening, it should be tracked in EntityMarkerClassTransformer
                Class.forName(managedClassName, true, getClass().getClassLoader());
                managedClassNames.add(managedClassName);
            }
        }
    }
    return managedClassNames;
}
Also used : ArrayList(java.util.ArrayList) MutablePersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo)

Example 5 with PersistenceUnitInfo

use of javax.persistence.spi.PersistenceUnitInfo in project BroadleafCommerce by BroadleafCommerce.

the class MergePersistenceUnitManager method addNamedQueriesToPersistenceUnits.

protected boolean addNamedQueriesToPersistenceUnits(boolean weaverRegistered) throws Exception {
    // still be transformed by the previous registered transformers
    for (PersistenceUnitInfo pui : mergedPus.values()) {
        // Add annotated named query support from QueryConfiguration beans
        List<NamedQuery> namedQueries = new ArrayList<>();
        List<NamedNativeQuery> nativeQueries = new ArrayList<>();
        for (QueryConfiguration config : queryConfigurations) {
            if (pui.getPersistenceUnitName().equals(config.getPersistenceUnit())) {
                NamedQueries annotation = config.getClass().getAnnotation(NamedQueries.class);
                if (annotation != null) {
                    namedQueries.addAll(Arrays.asList(annotation.value()));
                }
                NamedNativeQueries annotation2 = config.getClass().getAnnotation(NamedNativeQueries.class);
                if (annotation2 != null) {
                    nativeQueries.addAll(Arrays.asList(annotation2.value()));
                }
            }
        }
        if (!namedQueries.isEmpty() || !nativeQueries.isEmpty()) {
            QueryConfigurationClassTransformer transformer = new QueryConfigurationClassTransformer(namedQueries, nativeQueries, pui.getManagedClassNames());
            try {
                pui.addTransformer(transformer);
            } catch (Exception e) {
                weaverRegistered = handleClassTransformerRegistrationProblem(transformer, e);
            }
        }
    }
    return weaverRegistered;
}
Also used : NamedNativeQuery(javax.persistence.NamedNativeQuery) NamedNativeQueries(javax.persistence.NamedNativeQueries) ArrayList(java.util.ArrayList) NamedQueries(javax.persistence.NamedQueries) NamedQuery(javax.persistence.NamedQuery) MutablePersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo)

Aggregations

PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)11 EntityManagerFactory (javax.persistence.EntityManagerFactory)4 PersistenceProvider (javax.persistence.spi.PersistenceProvider)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 MutablePersistenceUnitInfo (org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo)3 Annotation (java.lang.annotation.Annotation)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Set (java.util.Set)2 CreationalContext (javax.enterprise.context.spi.CreationalContext)2 Bean (javax.enterprise.inject.spi.Bean)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 PersistenceException (javax.persistence.PersistenceException)2 SynchronizationType (javax.persistence.SynchronizationType)2 ValidationMode (javax.persistence.ValidationMode)2 PersistenceDescriptorFactory (com.robo4j.db.sql.jpa.PersistenceDescriptorFactory)1 PersistenceUnitDescriptor (com.sun.enterprise.deployment.PersistenceUnitDescriptor)1 PersistenceUnitsDescriptor (com.sun.enterprise.deployment.PersistenceUnitsDescriptor)1 Result (com.sun.enterprise.tools.verifier.Result)1 AVKPersistenceUnitInfoImpl (com.sun.enterprise.tools.verifier.persistence.AVKPersistenceUnitInfoImpl)1