Search in sources :

Example 6 with Injector

use of org.jboss.msc.inject.Injector in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method entityManagerBind.

private static void entityManagerBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, final PersistenceUnitMetadata pu, ServiceName puServiceName, TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry) {
    if (pu.getProperties().containsKey(ENTITYMANAGER_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGER_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the transaction scoped entity manager to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(new TransactionScopedEntityManager(pu.getScopedPersistenceUnitName(), Collections.emptyMap(), value.getEntityManagerFactory(), SynchronizationType.SYNCHRONIZED, transactionSynchronizationRegistry, transactionManager))));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) TransactionScopedEntityManager(org.jboss.as.jpa.container.TransactionScopedEntityManager) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 7 with Injector

use of org.jboss.msc.inject.Injector in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method entityManagerFactoryBind.

private static void entityManagerFactoryBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, PersistenceUnitMetadata pu, ServiceName puServiceName) {
    if (pu.getProperties().containsKey(ENTITYMANAGERFACTORY_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGERFACTORY_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the entity manager factory to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value.getEntityManagerFactory())));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 8 with Injector

use of org.jboss.msc.inject.Injector in project wildfly by wildfly.

the class ServiceInjectionSource method getResourceValue.

/**
     * {@inheritDoc}
     */
public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) {
    Injector inject = ManagedReferenceFactory.class.isAssignableFrom(serviceValueType) ? injector : new ManagedReferenceInjector(injector);
    serviceBuilder.addDependency(serviceName, serviceValueType, inject);
}
Also used : ManagedReferenceInjector(org.jboss.as.naming.ManagedReferenceInjector) ManagedReferenceInjector(org.jboss.as.naming.ManagedReferenceInjector) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory)

Aggregations

Injector (org.jboss.msc.inject.Injector)8 ServiceName (org.jboss.msc.service.ServiceName)4 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)3 BinderService (org.jboss.as.naming.service.BinderService)3 ImmediateValue (org.jboss.msc.value.ImmediateValue)3 EJBClientDescriptorMetaData (org.jboss.as.ee.metadata.EJBClientDescriptorMetaData)2 RemotingProfileService (org.jboss.as.ejb3.remote.RemotingProfileService)2 PersistenceUnitServiceImpl (org.jboss.as.jpa.service.PersistenceUnitServiceImpl)2 PhaseOnePersistenceUnitServiceImpl (org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl)2 ManagedReference (org.jboss.as.naming.ManagedReference)2 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)2 ContextNames (org.jboss.as.naming.deployment.ContextNames)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 CastingInjector (org.jboss.msc.inject.CastingInjector)2 InjectionException (org.jboss.msc.inject.InjectionException)2 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)2 InjectedValue (org.jboss.msc.value.InjectedValue)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1