Search in sources :

Example 1 with DataSourceReferenceFactoryService

use of org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService in project wildfly by wildfly.

the class DsXmlDeploymentInstallProcessor method startDataSource.

private void startDataSource(final AbstractDataSourceService dataSourceService, final String jndiName, final String driverName, final ServiceTarget serviceTarget, final ManagementResourceRegistration registration, final Resource resource, final String managementName, boolean requireLegacySecurity, final boolean isTransactional) {
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
    final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector(), false).addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()).addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME)).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector()).addDependency(NamingService.SERVICE_NAME);
    if (requireLegacySecurity) {
        dataSourceServiceBuilder.addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, dataSourceService.getServerSecurityManager());
        dataSourceServiceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, dataSourceService.getSubjectFactoryInjector());
    }
    //Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources
    if (registration.isAllowsOverride()) {
        ManagementResourceRegistration overrideRegistration = registration.getOverrideModel(managementName);
        if (overrideRegistration == null || overrideRegistration.isAllowsOverride()) {
            overrideRegistration = registration.registerOverrideModel(managementName, DataSourcesSubsystemProviders.OVERRIDE_DS_DESC);
        }
        DataSourceStatisticsService statsService = new DataSourceStatisticsService(registration, false);
        serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService).addDependency(dataSourceServiceName).addDependency(CommonDeploymentService.getServiceName(bindInfo), CommonDeployment.class, statsService.getCommonDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
        DataSourceStatisticsService.registerStatisticsResources(resource);
    }
    // else should probably throw an ISE or something
    final ServiceName driverServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_"));
    if (driverServiceName != null) {
        dataSourceServiceBuilder.addDependency(driverServiceName, Driver.class, dataSourceService.getDriverInjector());
    }
    final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(jndiName);
    final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, javax.sql.DataSource.class, referenceFactoryService.getDataSourceInjector());
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<?> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        if (isTransactional) {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case START_REQUESTED_to_DOWN:
                    {
                        if (isTransactional) {
                            SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName);
                        break;
                    }
            }
        }
    });
    dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : DataSourceStatisticsService(org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService) DataSourceReferenceFactoryService(org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) BinderService(org.jboss.as.naming.service.BinderService) MetadataRepository(org.jboss.jca.core.spi.mdr.MetadataRepository) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) ServiceController(org.jboss.msc.service.ServiceController) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 2 with DataSourceReferenceFactoryService

use of org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService in project wildfly by wildfly.

the class DataSourceDefinitionInjectionSource method startDataSource.

private void startDataSource(final AbstractDataSourceService dataSourceService, final ContextNames.BindInfo bindInfo, final EEModuleDescription moduleDescription, final ResolutionContext context, final ServiceTarget serviceTarget, final ServiceBuilder valueSourceServiceBuilder, final Injector<ManagedReferenceFactory> injector) {
    final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
    final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector(), false).addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()).addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME)).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector()).addDependency(NamingService.SERVICE_NAME);
    // We don't need to inject legacy security subsystem services. They are only used with a configured legacy
    // security domain, and the annotation does not support configuring that
    //        if(securityEnabled) {
    //            dataSourceServiceBuilder.addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class,
    //                    dataSourceService.getServerSecurityManager());
    //            dataSourceServiceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class,
    //                    dataSourceService.getSubjectFactoryInjector());
    //        }
    final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName());
    final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, javax.sql.DataSource.class, referenceFactoryService.getDataSourceInjector());
    final BinderService binderService = new BinderService(bindInfo.getBindName(), this);
    final ServiceBuilder<?> binderBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        if (isTransactional()) {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case START_REQUESTED_to_DOWN:
                    {
                        if (isTransactional()) {
                            SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName);
                        break;
                    }
            }
        }
    });
    dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    valueSourceServiceBuilder.addDependency(bindInfo.getBinderServiceName(), ManagedReferenceFactory.class, injector);
}
Also used : DataSourceReferenceFactoryService(org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService) BinderService(org.jboss.as.naming.service.BinderService) MetadataRepository(org.jboss.jca.core.spi.mdr.MetadataRepository) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) ServiceController(org.jboss.msc.service.ServiceController)

Aggregations

DriverRegistry (org.jboss.as.connector.services.driver.registry.DriverRegistry)2 DataSourceReferenceFactoryService (org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService)2 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)2 BinderService (org.jboss.as.naming.service.BinderService)2 ManagementRepository (org.jboss.jca.core.api.management.ManagementRepository)2 MetadataRepository (org.jboss.jca.core.spi.mdr.MetadataRepository)2 ServiceController (org.jboss.msc.service.ServiceController)2 ServiceName (org.jboss.msc.service.ServiceName)2 DataSourceStatisticsService (org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService)1 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1