Search in sources :

Example 1 with DriverService

use of org.jboss.as.connector.services.driver.DriverService in project wildfly by wildfly.

the class DriverProcessor method deploy.

/**
 * {@inheritDoc}
 */
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ServicesAttachment servicesAttachment = deploymentUnit.getAttachment(Attachments.SERVICES);
    if (module != null && servicesAttachment != null) {
        final ModuleClassLoader classLoader = module.getClassLoader();
        final List<String> driverNames = servicesAttachment.getServiceImplementations(Driver.class.getName());
        int idx = 0;
        for (String driverClassName : driverNames) {
            try {
                final Class<? extends Driver> driverClass = classLoader.loadClass(driverClassName).asSubclass(Driver.class);
                final Constructor<? extends Driver> constructor = driverClass.getConstructor();
                final Driver driver = constructor.newInstance();
                final int majorVersion = driver.getMajorVersion();
                final int minorVersion = driver.getMinorVersion();
                final boolean compliant = driver.jdbcCompliant();
                if (compliant) {
                    DEPLOYER_JDBC_LOGGER.deployingCompliantJdbcDriver(driverClass, majorVersion, minorVersion);
                } else {
                    DEPLOYER_JDBC_LOGGER.deployingNonCompliantJdbcDriver(driverClass, majorVersion, minorVersion);
                }
                String driverName = deploymentUnit.getName();
                if ((driverName.contains(".") && !driverName.endsWith(".jar")) || driverNames.size() != 1) {
                    driverName += "_" + driverClassName + "_" + majorVersion + "_" + minorVersion;
                }
                InstalledDriver driverMetadata = new InstalledDriver(driverName, driverClass.getName(), null, null, majorVersion, minorVersion, compliant);
                DriverService driverService = new DriverService(driverMetadata, driver);
                phaseContext.getServiceTarget().addService(ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")), driverService).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()).setInitialMode(Mode.ACTIVE).install();
                if (idx == 0 && driverNames.size() != 1) {
                    // create short name driver service
                    // reset driverName to the deployment unit name
                    driverName = deploymentUnit.getName();
                    driverMetadata = new InstalledDriver(driverName, driverClass.getName(), null, null, majorVersion, minorVersion, compliant);
                    driverService = new DriverService(driverMetadata, driver);
                    phaseContext.getServiceTarget().addService(ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")), driverService).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()).setInitialMode(Mode.ACTIVE).install();
                }
                idx++;
            } catch (Throwable e) {
                DEPLOYER_JDBC_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
            }
        }
    }
}
Also used : InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) ServicesAttachment(org.jboss.as.server.deployment.ServicesAttachment) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) Driver(java.sql.Driver) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DriverService(org.jboss.as.connector.services.driver.DriverService)

Example 2 with DriverService

use of org.jboss.as.connector.services.driver.DriverService in project wildfly by wildfly.

the class JdbcDriverAdd method startDriverServices.

public static void startDriverServices(final ServiceTarget target, final ModuleIdentifier moduleId, Driver driver, final String driverName, final Integer majorVersion, final Integer minorVersion, final String dataSourceClassName, final String xaDataSourceClassName) throws IllegalStateException {
    final int majorVer = driver.getMajorVersion();
    final int minorVer = driver.getMinorVersion();
    if ((majorVersion != null && majorVersion != majorVer) || (minorVersion != null && minorVersion != minorVer)) {
        throw ConnectorLogger.ROOT_LOGGER.driverVersionMismatch();
    }
    final boolean compliant = driver.jdbcCompliant();
    if (compliant) {
        SUBSYSTEM_DATASOURCES_LOGGER.deployingCompliantJdbcDriver(driver.getClass(), majorVer, minorVer);
    } else {
        SUBSYSTEM_DATASOURCES_LOGGER.deployingNonCompliantJdbcDriver(driver.getClass(), majorVer, minorVer);
    }
    InstalledDriver driverMetadata = new InstalledDriver(driverName, moduleId, driver.getClass().getName(), dataSourceClassName, xaDataSourceClassName, majorVer, minorVer, compliant);
    DriverService driverService = new DriverService(driverMetadata, driver);
    final ServiceBuilder<Driver> builder = target.addService(ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")), driverService).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()).setInitialMode(ServiceController.Mode.ACTIVE);
    builder.install();
}
Also used : InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) Driver(java.sql.Driver) DriverService(org.jboss.as.connector.services.driver.DriverService)

Aggregations

Driver (java.sql.Driver)2 DriverService (org.jboss.as.connector.services.driver.DriverService)2 InstalledDriver (org.jboss.as.connector.services.driver.InstalledDriver)2 DriverRegistry (org.jboss.as.connector.services.driver.registry.DriverRegistry)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ServicesAttachment (org.jboss.as.server.deployment.ServicesAttachment)1 Module (org.jboss.modules.Module)1 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)1