Package org.jboss.as.jpa.service

Examples of org.jboss.as.jpa.service.PersistenceUnitServiceImpl


        final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName);

        final ServiceController<?> serviceController = serviceRegistry.getRequiredService(persistenceUnitServiceName);
        //now we have the service controller, as this method is only called at runtime the service should
        //always be up
        PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue();
        return new TransactionScopedEntityManager(scopedPuName, new HashMap<Object, Object>(), persistenceUnitService.getEntityManagerFactory());
    }
View Full Code Here


        final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName);

        final ServiceController<?> serviceController = serviceRegistry.getRequiredService(persistenceUnitServiceName);
        //now we have the service controller, as this method is only called at runtime the service should
        //always be up
        PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue();
        return persistenceUnitService.getEntityManagerFactory();
    }
View Full Code Here

            //  look provider up if we didn't use the providers packaged with the application
            if (provider == null) {
                provider = lookupProvider(pu);
            }

            final PersistenceUnitServiceImpl service = new PersistenceUnitServiceImpl(classLoader, pu, adaptor, provider);

            phaseContext.getDeploymentUnit().addToAttachmentList(REMOVAL_KEY, new PersistenceAdaptorRemoval(pu, adaptor));

            // add persistence provider specific properties
            adaptor.addProviderProperties(properties, pu);


            final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
            // add the PU service as a dependency to all EE components in this scope
            this.addPUServiceDependencyToComponents(components, puServiceName);

            deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);

            ServiceBuilder<PersistenceUnitServiceImpl> builder = serviceTarget.addService(puServiceName, service);
            boolean useDefaultDataSource = true;
            final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
            final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());

            if (jtaDataSource != null && jtaDataSource.length() > 0) {
                if (jtaDataSource.startsWith("java:")) {
                    builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                    useDefaultDataSource = false;
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(jtaDataSource), new CastingInjector<DataSource>(service.getJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
                if (nonJtaDataSource.startsWith("java:")) {
                    builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
                    useDefaultDataSource = false;
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(nonJtaDataSource), new CastingInjector<DataSource>(service.getNonJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            // JPA 2.0 8.2.1.5, container provides default JTA datasource
            if (useDefaultDataSource) {
                final String defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
                if (defaultJtaDataSource != null &&
                    defaultJtaDataSource.length() > 0) {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(defaultJtaDataSource), new CastingInjector<DataSource>(service.getJtaDataSourceInjector(), DataSource.class));
                    JPA_LOGGER.tracef("%s is using the default data source '%s'", puServiceName, defaultJtaDataSource);
                }
            }

            adaptor.addProviderDependencies(phaseContext.getServiceRegistry(), serviceTarget, builder, pu);

            if (pu.getProperties().containsKey(JNDI_PROPERTY)) {
                String jndiName = pu.getProperties().get(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);
                }
                JPA_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();
            }

            builder.setInitialMode(ServiceController.Mode.ACTIVE)
                .addInjection(service.getPropertiesInjector(), properties)
                .addInjection(persistenceUnitRegistry.getInjector())
                .install();

            JPA_LOGGER.tracef("added PersistenceUnitService for '%s'.  PU is ready for injector action.", puServiceName);
            addManagementConsole(deploymentUnit, pu, service, adaptor);
View Full Code Here

    private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
        // read all non-transient fields
        in.defaultReadObject();
        final ServiceController<?> controller = CurrentServiceContainer.getServiceContainer().getService(JPAServiceNames.getPUServiceName(puScopedName));
        final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) controller.getService();
        emf = persistenceUnitService.getEntityManagerFactory();
    }
View Full Code Here

            this.pu = pu;
        }

        @Override
        public ManagedReference getReference() {
            PersistenceUnitServiceImpl service = (PersistenceUnitServiceImpl) deploymentUnit.getServiceRegistry().getRequiredService(puServiceName).getValue();
            EntityManagerFactory emf = service.getEntityManagerFactory();

            if (!ENTITY_MANAGER_FACTORY_CLASS.equals(injectionTypeName)) { // inject non-standard wrapped class (e.g. org.hibernate.SessionFactory)
                Class extensionClass;
                try {
                    // make sure we can access the target class type
View Full Code Here

            this.pu = pu;
        }

        @Override
        public ManagedReference getReference() {
            PersistenceUnitServiceImpl service = (PersistenceUnitServiceImpl) deploymentUnit.getServiceRegistry().getRequiredService(puServiceName).getValue();
            EntityManagerFactory emf = service.getEntityManagerFactory();
            EntityManager entityManager;
            boolean standardEntityManager = ENTITY_MANAGER_CLASS.equals(injectionTypeName);

            if (type.equals(PersistenceContextType.TRANSACTION)) {
                entityManager = new TransactionScopedEntityManager(unitName, properties, emf);
View Full Code Here

            if (!ValidationMode.NONE.equals(pu.getValidationMode())) {
                // Get the CDI-enabled ValidatorFactory
                validatorFactory = deploymentUnit.getAttachment(BeanValidationAttachments.VALIDATOR_FACTORY);
            }

            final PersistenceUnitServiceImpl service = new PersistenceUnitServiceImpl(classLoader, pu, adaptor, provider, PersistenceUnitRegistryImpl.INSTANCE, deploymentUnit.getServiceName(), validatorFactory);

            deploymentUnit.addToAttachmentList(REMOVAL_KEY, new PersistenceAdaptorRemoval(pu, adaptor));

            // add persistence provider specific properties
            adaptor.addProviderProperties(properties, pu);

            final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
            deploymentUnit.putAttachment(JpaAttachments.PERSISTENCE_UNIT_SERVICE_KEY, puServiceName);

            deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, puServiceName);

            deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);

            ServiceBuilder<PersistenceUnitService> builder = serviceTarget.addService(puServiceName, service);
            boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu);
            final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
            final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());

            if (jtaDataSource != null && jtaDataSource.length() > 0) {
                if (jtaDataSource.startsWith("java:")) {
                    if (jtaDataSource.equals(EE_DEFAULT_DATASOURCE)) { // explicit use of default datasource
                        useDefaultDataSource = true;
                    }
                    else {
                        builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                        useDefaultDataSource = false;
                    }
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(jtaDataSource), new CastingInjector<>(service.getJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
                if (nonJtaDataSource.startsWith("java:")) {
                    builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
                    useDefaultDataSource = false;
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(nonJtaDataSource), new CastingInjector<>(service.getNonJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            // JPA 2.0 8.2.1.5, container provides default JTA datasource
            if (useDefaultDataSource) {
                // try the default datasource defined in the ee subsystem
                String defaultJtaDataSource = null;
                if (eeModuleDescription != null) {
                    defaultJtaDataSource = eeModuleDescription.getDefaultResourceJndiNames().getDataSource();
                }

                if (defaultJtaDataSource == null ||
                        defaultJtaDataSource.isEmpty()) {
                    // try the datasource defined in the jpa subsystem
                    defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
                }
                if (defaultJtaDataSource != null &&
                    !defaultJtaDataSource.isEmpty()) {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(defaultJtaDataSource), new CastingInjector<>(service.getJtaDataSourceInjector(), DataSource.class));
                    JPA_LOGGER.tracef("%s is using the default data source '%s'", puServiceName, defaultJtaDataSource);
                }
            }

            // JPA 2.1 sections 3.5.1 + 9.1 require the CDI bean manager to be passed to the peristence provider
            // if the persistence unit is contained in a deployment that is a CDI bean archive (has beans.xml).
            if (allowCdiBeanManagerAccess && WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
                builder.addDependency(beanManagerServiceName(deploymentUnit)new CastingInjector<BeanManager>(service.getBeanManagerInjector(), BeanManager.class));
            }

            try {
                // save a thread local reference to the builder for setting up the second level cache dependencies
                CacheDeploymentListener.setInternalDeploymentServiceBuilder(builder);
                adaptor.addProviderDependencies(pu);
            }
            finally {
                CacheDeploymentListener.clearInternalDeploymentServiceBuilder();
            }

            /**
             * handle extension that binds a transaction scoped entity manager to specified JNDI location
             */
            entityManagerBind(eeModuleDescription, serviceTarget, pu, puServiceName);

            /**
             * handle extension that binds an entity manager factory to specified JNDI location
             */
            entityManagerFactoryBind(eeModuleDescription, serviceTarget, pu, puServiceName);

            builder.setInitialMode(ServiceController.Mode.ACTIVE)
                .addInjection(service.getPropertiesInjector(), properties);

            // get async executor from Services.addServerExecutorDependency
            addServerExecutorDependency(builder, service.getExecutorInjector(), false);

            builder.install();

            JPA_LOGGER.tracef("added PersistenceUnitService for '%s'.  PU is ready for injector action.", puServiceName);
            addManagementConsole(deploymentUnit, pu, adaptor);
View Full Code Here

            if (!ValidationMode.NONE.equals(pu.getValidationMode())) {
                // Get the CDI-enabled ValidatorFactory
                validatorFactory = deploymentUnit.getAttachment(BeanValidationAttachments.VALIDATOR_FACTORY);
            }

            final PersistenceUnitServiceImpl service = new PersistenceUnitServiceImpl(classLoader, pu, adaptor, provider, PersistenceUnitRegistryImpl.INSTANCE, deploymentUnit.getServiceName(), validatorFactory);

            deploymentUnit.addToAttachmentList(REMOVAL_KEY, new PersistenceAdaptorRemoval(pu, adaptor));

            // add persistence provider specific properties
            adaptor.addProviderProperties(properties, pu);

            final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
            deploymentUnit.putAttachment(JpaAttachments.PERSISTENCE_UNIT_SERVICE_KEY, puServiceName);

            deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, puServiceName);

            deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);

            ServiceBuilder<PersistenceUnitService> builder = serviceTarget.addService(puServiceName, service);
            // the PU service has to depend on the JPAService which is responsible for setting up the necessary JPA infrastructure (like registering the cache EventListener(s))
            // @see https://issues.jboss.org/browse/WFLY-1531 for details
            builder.addDependency(JPAServiceNames.getJPAServiceName());

            // add dependency on first phase
            builder.addDependency(puServiceName.append(FIRST_PHASE), new CastingInjector<>(service.getPhaseOnePersistenceUnitServiceImplInjector(), PhaseOnePersistenceUnitServiceImpl.class));

            boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu);
            final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
            final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());

            if (jtaDataSource != null && jtaDataSource.length() > 0) {
                if (jtaDataSource.startsWith("java:")) {
                    if (jtaDataSource.equals(EE_DEFAULT_DATASOURCE)) { // explicit use of default datasource
                        useDefaultDataSource = true;
                    }
                    else {
                        builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                        useDefaultDataSource = false;
                    }
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(jtaDataSource), new CastingInjector<>(service.getJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
                if (nonJtaDataSource.startsWith("java:")) {
                    builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
                    useDefaultDataSource = false;
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(nonJtaDataSource), new CastingInjector<>(service.getNonJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            // JPA 2.0 8.2.1.5, container provides default JTA datasource
            if (useDefaultDataSource) {
                // try the default datasource defined in the ee subsystem
                String defaultJtaDataSource = null;
                if (eeModuleDescription != null) {
                    defaultJtaDataSource = eeModuleDescription.getDefaultResourceJndiNames().getDataSource();
                }

                if (defaultJtaDataSource == null ||
                        defaultJtaDataSource.isEmpty()) {
                    // try the datasource defined in the jpa subsystem
                    defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
                }
                if (defaultJtaDataSource != null &&
                    !defaultJtaDataSource.isEmpty()) {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(defaultJtaDataSource), new CastingInjector<>(service.getJtaDataSourceInjector(), DataSource.class));
                    JPA_LOGGER.tracef("%s is using the default data source '%s'", puServiceName, defaultJtaDataSource);
                }
            }

            // JPA 2.1 sections 3.5.1 + 9.1 require the CDI bean manager to be passed to the peristence provider
            // if the persistence unit is contained in a deployment that is a CDI bean archive (has beans.xml).
            if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
                builder.addDependency(beanManagerServiceName(deploymentUnit)new CastingInjector<BeanManager>(service.getBeanManagerInjector(), BeanManager.class));
            }

            try {
                // save a thread local reference to the builder for setting up the second level cache dependencies
                CacheDeploymentListener.setInternalDeploymentServiceBuilder(builder);
                adaptor.addProviderDependencies(pu);
            }
            finally {
                CacheDeploymentListener.clearInternalDeploymentServiceBuilder();
            }


            /**
             * handle extension that binds a transaction scoped entity manager to specified JNDI location
             */
            entityManagerBind(eeModuleDescription, serviceTarget, pu, puServiceName);

            /**
             * handle extension that binds an entity manager factory to specified JNDI location
             */
            entityManagerFactoryBind(eeModuleDescription, serviceTarget, pu, puServiceName);

            builder.setInitialMode(ServiceController.Mode.ACTIVE)
                .addInjection(service.getPropertiesInjector(), properties);

            // get async executor from Services.addServerExecutorDependency
            addServerExecutorDependency(builder, service.getExecutorInjector(), false);

            builder.install();

            JPA_LOGGER.tracef("added PersistenceUnitService (phase 2 of 2) for '%s'.  PU is ready for injector action.", puServiceName);
            addManagementConsole(deploymentUnit, pu, adaptor);
View Full Code Here

            this.pu = pu;
        }

        @Override
        public ManagedReference getReference() {
            PersistenceUnitServiceImpl service = (PersistenceUnitServiceImpl) serviceRegistry.getRequiredService(puServiceName).getValue();
            EntityManagerFactory emf = service.getEntityManagerFactory();

            if (!ENTITY_MANAGER_FACTORY_CLASS.equals(injectionTypeName)) { // inject non-standard wrapped class (e.g. org.hibernate.SessionFactory)
                Class extensionClass;
                try {
                    // make sure we can access the target class type
View Full Code Here

            this.jpaDeploymentSettings = jpaDeploymentSettings;
        }

        @Override
        public ManagedReference getReference() {
            PersistenceUnitServiceImpl service = (PersistenceUnitServiceImpl) serviceRegistry.getRequiredService(puServiceName).getValue();
            EntityManagerFactory emf = service.getEntityManagerFactory();
            EntityManager entityManager;
            boolean standardEntityManager = ENTITY_MANAGER_CLASS.equals(injectionTypeName);

            if (type.equals(PersistenceContextType.TRANSACTION)) {
                entityManager = new TransactionScopedEntityManager(unitName, properties, emf, synchronizationType);
View Full Code Here

TOP

Related Classes of org.jboss.as.jpa.service.PersistenceUnitServiceImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.