Search in sources :

Example 1 with ImmediateResourceReferenceFactory

use of org.jboss.as.weld.util.ImmediateResourceReferenceFactory in project wildfly by wildfly.

the class WeldJpaInjectionServices method registerPersistenceUnitInjectionPoint.

@Override
public ResourceReferenceFactory<EntityManagerFactory> registerPersistenceUnitInjectionPoint(final InjectionPoint injectionPoint) {
    //TODO: cache this stuff
    final PersistenceUnit context = getResourceAnnotated(injectionPoint).getAnnotation(PersistenceUnit.class);
    if (context == null) {
        throw WeldLogger.ROOT_LOGGER.annotationNotFound(PersistenceUnit.class, injectionPoint.getMember());
    }
    final String scopedPuName = getScopedPUName(deploymentUnit, context.unitName(), injectionPoint.getMember());
    final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName);
    final ServiceController<?> serviceController = deploymentUnit.getServiceRegistry().getRequiredService(persistenceUnitServiceName);
    //now we have the service controller, as this method is only called at runtime the service should
    //always be up
    final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue();
    return new ImmediateResourceReferenceFactory<EntityManagerFactory>(persistenceUnitService.getEntityManagerFactory());
}
Also used : PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) PersistenceUnit(javax.persistence.PersistenceUnit) ServiceName(org.jboss.msc.service.ServiceName) ImmediateResourceReferenceFactory(org.jboss.as.weld.util.ImmediateResourceReferenceFactory)

Aggregations

PersistenceUnit (javax.persistence.PersistenceUnit)1 PersistenceUnitServiceImpl (org.jboss.as.jpa.service.PersistenceUnitServiceImpl)1 ImmediateResourceReferenceFactory (org.jboss.as.weld.util.ImmediateResourceReferenceFactory)1 ServiceName (org.jboss.msc.service.ServiceName)1