Search in sources :

Example 1 with InstalledDriver

use of org.jboss.as.connector.services.driver.InstalledDriver 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());
        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, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion));
                } else {
                    DEPLOYER_JDBC_LOGGER.deployingNonCompliantJdbcDriver(driverClass, Integer.valueOf(majorVersion), Integer.valueOf(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();
            } 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 InstalledDriver

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

the class GetInstalledDriverOperationHandler method execute.

@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    validator.validate(operation);
    final String name = operation.require(DRIVER_NAME.getName()).asString();
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
                ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE);
                DriverRegistry driverRegistry = DriverRegistry.class.cast(sc.getValue());
                ModelNode result = new ModelNode();
                InstalledDriver driver = driverRegistry.getInstalledDriver(name);
                ModelNode driverNode = new ModelNode();
                driverNode.get(DRIVER_NAME.getName()).set(driver.getDriverName());
                if (driver.isFromDeployment()) {
                    driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName());
                    driverNode.get(DRIVER_MODULE_NAME.getName());
                    driverNode.get(MODULE_SLOT.getName());
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName());
                } else {
                    driverNode.get(DEPLOYMENT_NAME.getName());
                    driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName());
                    driverNode.get(MODULE_SLOT.getName()).set(driver.getModuleName() != null ? driver.getModuleName().getSlot() : "");
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set(driver.getXaDataSourceClassName());
                }
                driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName());
                driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion());
                driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion());
                driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant());
                result.add(driverNode);
                context.getResult().set(result);
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with InstalledDriver

use of org.jboss.as.connector.services.driver.InstalledDriver 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

InstalledDriver (org.jboss.as.connector.services.driver.InstalledDriver)3 Driver (java.sql.Driver)2 DriverService (org.jboss.as.connector.services.driver.DriverService)2 DriverRegistry (org.jboss.as.connector.services.driver.registry.DriverRegistry)2 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ServicesAttachment (org.jboss.as.server.deployment.ServicesAttachment)1 ModelNode (org.jboss.dmr.ModelNode)1 Module (org.jboss.modules.Module)1 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)1 ServiceController (org.jboss.msc.service.ServiceController)1