Search in sources :

Example 1 with XaDataSourceService

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

the class DataSourceDefinitionInjectionSource method getResourceValue.

public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final String poolName = uniqueName(context, jndiName);
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
    try {
        final Class<?> clazz = module.getClassLoader().loadClass(className);
        clearUnknownProperties(reflectionIndex, clazz, properties);
        populateProperties(reflectionIndex, clazz, properties);
        DsSecurityImpl dsSecurity = new DsSecurityImpl(user, password, null, false, null, null);
        if (XADataSource.class.isAssignableFrom(clazz) && transactional) {
            final DsXaPoolImpl xaPool = new DsXaPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize), initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize), maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize), Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Defaults.IS_SAME_RM_OVERRIDE, Defaults.INTERLEAVING, Defaults.PAD_XID, Defaults.WRAP_XA_RESOURCE, Defaults.NO_TX_SEPARATE_POOL, Boolean.FALSE, null, Defaults.FAIR, null);
            final ModifiableXaDataSource dataSource = new ModifiableXaDataSource(transactionIsolation(), null, dsSecurity, null, null, null, null, null, null, poolName, true, jndiName, false, false, Defaults.CONNECTABLE, Defaults.TRACKING, Defaults.MCP, Defaults.ENLISTMENT_TRACE, properties, className, null, null, xaPool, null);
            final XaDataSourceService xds = new XaDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader());
            xds.getDataSourceConfigInjector().inject(dataSource);
            startDataSource(xds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, support);
        } else {
            final DsPoolImpl commonPool = new DsPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize), initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize), maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize), Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Boolean.FALSE, null, Defaults.FAIR, null);
            final ModifiableDataSource dataSource = new ModifiableDataSource(url, null, className, null, transactionIsolation(), properties, null, dsSecurity, null, null, null, null, null, false, poolName, true, jndiName, Defaults.SPY, Defaults.USE_CCM, transactional, Defaults.CONNECTABLE, Defaults.TRACKING, Defaults.MCP, Defaults.ENLISTMENT_TRACE, commonPool);
            final LocalDataSourceService ds = new LocalDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader());
            ds.getDataSourceConfigInjector().inject(dataSource);
            startDataSource(ds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, support);
        }
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XADataSource(javax.sql.XADataSource) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) XaDataSourceService(org.jboss.as.connector.subsystems.datasources.XaDataSourceService) LocalDataSourceService(org.jboss.as.connector.subsystems.datasources.LocalDataSourceService) ModifiableDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableDataSource) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DsSecurityImpl(org.jboss.as.connector.metadata.ds.DsSecurityImpl) DsPoolImpl(org.jboss.jca.common.metadata.ds.DsPoolImpl) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) DsXaPoolImpl(org.jboss.jca.common.metadata.ds.DsXaPoolImpl) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 2 with XaDataSourceService

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

the class DsXmlDeploymentInstallProcessor method deploy.

/**
 * Process a deployment for standard ra deployment files. Will parse the xml
 * file and attach a configuration discovered during processing.
 *
 * @param phaseContext the deployment unit context
 * @throws DeploymentUnitProcessingException
 */
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    final List<DataSources> dataSourcesList = deploymentUnit.getAttachmentList(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY);
    final boolean legacySecurityPresent = support.hasCapability("org.wildfly.legacy-security");
    for (DataSources dataSources : dataSourcesList) {
        if (dataSources.getDrivers() != null && !dataSources.getDrivers().isEmpty()) {
            ConnectorLogger.DS_DEPLOYER_LOGGER.driversElementNotSupported(deploymentUnit.getName());
        }
        ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        if (dataSources.getDataSource() != null && !dataSources.getDataSource().isEmpty()) {
            for (int i = 0; i < dataSources.getDataSource().size(); i++) {
                DataSource ds = (DataSource) dataSources.getDataSource().get(i);
                if (ds.isEnabled() && ds.getDriver() != null) {
                    try {
                        final String jndiName = Util.cleanJndiName(ds.getJndiName(), ds.isUseJavaContext());
                        LocalDataSourceService lds = new LocalDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName));
                        lds.getDataSourceConfigInjector().inject(buildDataSource(ds));
                        final String dsName = ds.getJndiName();
                        final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, false);
                        installManagementModel(ds, deploymentUnit, addr);
                        // TODO why have we been ignoring a configured legacy security domain but no legacy security present?
                        boolean useLegacySecurity = legacySecurityPresent && isLegacySecurityRequired(ds.getSecurity());
                        startDataSource(lds, jndiName, ds.getDriver(), serviceTarget, getRegistration(false, deploymentUnit), getResource(dsName, false, deploymentUnit), dsName, useLegacySecurity, ds.isJTA(), support);
                    } catch (DeploymentUnitProcessingException dupe) {
                        throw dupe;
                    } catch (Exception e) {
                        throw ConnectorLogger.ROOT_LOGGER.exceptionDeployingDatasource(e, ds.getJndiName());
                    }
                } else {
                    ConnectorLogger.DS_DEPLOYER_LOGGER.debugf("Ignoring: %s", ds.getJndiName());
                }
            }
        }
        if (dataSources.getXaDataSource() != null && !dataSources.getXaDataSource().isEmpty()) {
            for (int i = 0; i < dataSources.getXaDataSource().size(); i++) {
                XaDataSource xads = (XaDataSource) dataSources.getXaDataSource().get(i);
                if (xads.isEnabled() && xads.getDriver() != null) {
                    try {
                        String jndiName = Util.cleanJndiName(xads.getJndiName(), xads.isUseJavaContext());
                        XaDataSourceService xds = new XaDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName));
                        xds.getDataSourceConfigInjector().inject(buildXaDataSource(xads));
                        final String dsName = xads.getJndiName();
                        final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, true);
                        installManagementModel(xads, deploymentUnit, addr);
                        final Credential credential = xads.getRecovery() == null ? null : xads.getRecovery().getCredential();
                        // TODO why have we been ignoring a configured legacy security domain but no legacy security present?
                        boolean useLegacySecurity = legacySecurityPresent && (isLegacySecurityRequired(xads.getSecurity()) || isLegacySecurityRequired(credential));
                        startDataSource(xds, jndiName, xads.getDriver(), serviceTarget, getRegistration(true, deploymentUnit), getResource(dsName, true, deploymentUnit), dsName, useLegacySecurity, true, support);
                    } catch (Exception e) {
                        throw ConnectorLogger.ROOT_LOGGER.exceptionDeployingDatasource(e, xads.getJndiName());
                    }
                } else {
                    ConnectorLogger.DS_DEPLOYER_LOGGER.debugf("Ignoring %s", xads.getJndiName());
                }
            }
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) Credential(org.jboss.jca.common.api.metadata.common.Credential) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ModifiableXaDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource) XaDataSource(org.jboss.jca.common.api.metadata.ds.XaDataSource) ModifiableDataSource(org.jboss.as.connector.subsystems.datasources.ModifiableDataSource) DataSource(org.jboss.jca.common.api.metadata.ds.DataSource) LocalDataSourceService(org.jboss.as.connector.subsystems.datasources.LocalDataSourceService) XaDataSourceService(org.jboss.as.connector.subsystems.datasources.XaDataSourceService) DataSources(org.jboss.jca.common.api.metadata.ds.DataSources) PathAddress(org.jboss.as.controller.PathAddress) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

LocalDataSourceService (org.jboss.as.connector.subsystems.datasources.LocalDataSourceService)2 ModifiableDataSource (org.jboss.as.connector.subsystems.datasources.ModifiableDataSource)2 ModifiableXaDataSource (org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource)2 XaDataSourceService (org.jboss.as.connector.subsystems.datasources.XaDataSourceService)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 XADataSource (javax.sql.XADataSource)1 DsSecurityImpl (org.jboss.as.connector.metadata.ds.DsSecurityImpl)1 PathAddress (org.jboss.as.controller.PathAddress)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)1 Credential (org.jboss.jca.common.api.metadata.common.Credential)1 DataSource (org.jboss.jca.common.api.metadata.ds.DataSource)1 DataSources (org.jboss.jca.common.api.metadata.ds.DataSources)1 XaDataSource (org.jboss.jca.common.api.metadata.ds.XaDataSource)1 DsPoolImpl (org.jboss.jca.common.metadata.ds.DsPoolImpl)1 DsXaPoolImpl (org.jboss.jca.common.metadata.ds.DsXaPoolImpl)1 Module (org.jboss.modules.Module)1