public synchronized void start(StartContext startContext) throws StartException {
    try {
      final ServiceContainer container = startContext.getController().getServiceContainer();

      deploymentMD = getDeployer().deploy(container);
      if (deploymentMD.getCfs().length != 1) {
        throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
      }
      sqlDataSource =
          new WildFlyDataSource(
              (javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName.getAbsoluteJndiName());
      DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
      CommonDeploymentService cdService = new CommonDeploymentService(deploymentMD);
      final ServiceName cdServiceName = CommonDeploymentService.getServiceName(jndiName);
      startContext
          .getController()
          .getServiceContainer()
          .addService(cdServiceName, cdService)
          // The dependency added must be the JNDI name which for subsystem resources is an alias.
          // This service
          // is also used in deployments where the capability service name is not registered for the
          // service.
          .addDependency(getServiceName(jndiName))
          .setInitialMode(ServiceController.Mode.ACTIVE)
          .install();
    } catch (Throwable t) {
      throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
    }
  }
  public synchronized void start(StartContext startContext) throws StartException {
    try {
      final ServiceContainer container = startContext.getController().getServiceContainer();

      deploymentMD = getDeployer().deploy(container);
      if (deploymentMD.getCfs().length != 1) {
        throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
      }
      sqlDataSource =
          new WildFlyDataSource((javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName);
      DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
    } catch (Throwable t) {
      throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
    }
  }
    @Override
    protected Object initAndInject(
        String className, List<? extends ConfigProperty> configs, ClassLoader cl)
        throws DeployException {
      try {
        Class clz = Class.forName(className, true, cl);
        Object o = clz.newInstance();

        if (configs != null) {
          Injection injector = new Injection();
          for (ConfigProperty cpmd : configs) {
            if (cpmd.isValueSet()) {

              if (XsdString.isNull(cpmd.getConfigPropertyType())) {
                injector.inject(
                    o,
                    cpmd.getConfigPropertyName().getValue(),
                    cpmd.getConfigPropertyValue().getValue());
              } else {
                injector.inject(
                    o,
                    cpmd.getConfigPropertyName().getValue(),
                    cpmd.getConfigPropertyValue().getValue(),
                    cpmd.getConfigPropertyType().getValue());
              }
            }
          }
        }

        return o;
      } catch (Throwable t) {
        throw ConnectorLogger.ROOT_LOGGER.deploymentFailed(t, className);
      }
    }
  /**
   * Performs the actual work of stopping the service. Should be called by {@link
   * #stop(org.jboss.msc.service.StopContext)} asynchronously from the MSC thread that invoked stop.
   */
  protected synchronized void stopService() {
    if (deploymentMD != null) {

      if (deploymentMD.getResourceAdapterKey() != null) {
        try {
          raRepository.getValue().unregisterResourceAdapter(deploymentMD.getResourceAdapterKey());
        } catch (org.jboss.jca.core.spi.rar.NotFoundException nfe) {
          ConnectorLogger.ROOT_LOGGER.exceptionDuringUnregistering(nfe);
        }
      }

      if (deploymentMD.getResourceAdapter() != null) {
        deploymentMD.getResourceAdapter().stop();

        BootstrapContextCoordinator.getInstance()
            .removeBootstrapContext(deploymentMD.getBootstrapContextIdentifier());
      }

      if (deploymentMD.getDataSources() != null && managementRepositoryValue.getValue() != null) {
        for (org.jboss.jca.core.api.management.DataSource mgtDs : deploymentMD.getDataSources()) {
          managementRepositoryValue.getValue().getDataSources().remove(mgtDs);
        }
      }

      if (deploymentMD.getConnectionManagers() != null) {
        for (ConnectionManager cm : deploymentMD.getConnectionManagers()) {
          cm.shutdown();
        }
      }
    }

    sqlDataSource = null;
  }
Exemple #5
0
  @Override
  public void performRuntime(final OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {
    // Compensating is remove
    final ModelNode address = operation.require(OP_ADDR);
    final String name = PathAddress.pathAddress(address).getLastElement().getValue();
    final String archiveOrModuleName;
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
      throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
      archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
      archiveOrModuleName = model.get(MODULE.getName()).asString();
    }

    ModifiableResourceAdapter resourceAdapter =
        RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
    List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
    if (model.get(ARCHIVE.getName()).isDefined()) {
      RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
    } else {
      RaOperationUtil.installRaServicesAndDeployFromModule(
          context, name, resourceAdapter, archiveOrModuleName, newControllers);
      if (context.isBooting()) {
        context.addStep(
            new OperationStepHandler() {
              public void execute(final OperationContext context, ModelNode operation)
                  throws OperationFailedException {

                // Next lines activate configuration on module deployed rar
                // in case there is 2 different resource-adapter config using same module deployed
                // rar
                // a Deployment sercivice could be already present and need a restart to consider
                // also this
                // newly added configuration
                ServiceName restartedServiceName =
                    RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
                if (restartedServiceName == null) {
                  RaOperationUtil.activate(context, name, archiveOrModuleName);
                }
                context.completeStep(
                    new OperationContext.RollbackHandler() {
                      @Override
                      public void handleRollback(OperationContext context, ModelNode operation) {
                        try {
                          RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
                        } catch (OperationFailedException e) {

                        }
                      }
                    });
              }
            },
            OperationContext.Stage.RUNTIME);
      }
    }
  }
    @Override
    protected ManagedConnectionFactory createMcf(
        org.jboss.jca.common.api.metadata.ds.DataSource arg0, String arg1, ClassLoader arg2)
        throws NotFoundException, DeployException {
      final LocalManagedConnectionFactory managedConnectionFactory =
          new LocalManagedConnectionFactory();
      managedConnectionFactory.setDriverClass(dataSourceConfig.getDriverClass());

      if (dataSourceConfig.getUrlDelimiter() != null) {
        try {
          managedConnectionFactory.setURLDelimiter(dataSourceConfig.getUrlDelimiter());
        } catch (Exception e) {
          throw ConnectorLogger.ROOT_LOGGER.failedToGetUrlDelimiter(e);
        }
      }

      if (dataSourceConfig.getDataSourceClass() != null) {
        managedConnectionFactory.setDataSourceClass(dataSourceConfig.getDataSourceClass());
      }

      if (dataSourceConfig.getConnectionProperties() != null) {
        managedConnectionFactory.setConnectionProperties(
            buildConfigPropsString(dataSourceConfig.getConnectionProperties()));
      }
      if (dataSourceConfig.getConnectionUrl() != null) {
        managedConnectionFactory.setConnectionURL(dataSourceConfig.getConnectionUrl());
      }

      if (dataSourceConfig.getNewConnectionSql() != null) {
        managedConnectionFactory.setNewConnectionSQL(dataSourceConfig.getNewConnectionSql());
      }

      if (dataSourceConfig.getUrlSelectorStrategyClassName() != null) {
        managedConnectionFactory.setUrlSelectorStrategyClassName(
            dataSourceConfig.getUrlSelectorStrategyClassName());
      }
      setMcfProperties(managedConnectionFactory, dataSourceConfig, dataSourceConfig.getStatement());

      return managedConnectionFactory;
    }
    public CommonDeployment deploy(ServiceContainer serviceContainer) throws DeployException {
      try {
        if (serviceContainer == null) {
          throw new DeployException(ConnectorLogger.ROOT_LOGGER.nullVar("ServiceContainer"));
        }

        HashMap<String, org.jboss.jca.common.api.metadata.ds.Driver> drivers =
            new HashMap<String, org.jboss.jca.common.api.metadata.ds.Driver>(1);

        DataSources dataSources = null;
        if (dataSourceConfig != null) {
          String driverName = dataSourceConfig.getDriver();
          InstalledDriver installedDriver =
              driverRegistry.getValue().getInstalledDriver(driverName, profile);
          if (installedDriver != null) {
            String moduleName =
                installedDriver.getModuleName() != null
                    ? installedDriver.getModuleName().getName()
                    : null;
            org.jboss.jca.common.api.metadata.ds.Driver driver =
                new DriverImpl(
                    installedDriver.getDriverName(),
                    installedDriver.getMajorVersion(),
                    installedDriver.getMinorVersion(),
                    moduleName,
                    installedDriver.getDriverClassName(),
                    installedDriver.getDataSourceClassName(),
                    installedDriver.getXaDataSourceClassName());
            drivers.put(driverName, driver);
          }
          dataSources = new DatasourcesImpl(Arrays.asList(dataSourceConfig), null, drivers);
        } else if (xaDataSourceConfig != null) {
          String driverName = xaDataSourceConfig.getDriver();
          InstalledDriver installedDriver =
              driverRegistry.getValue().getInstalledDriver(driverName, profile);
          if (installedDriver != null) {
            String moduleName =
                installedDriver.getModuleName() != null
                    ? installedDriver.getModuleName().getName()
                    : null;
            org.jboss.jca.common.api.metadata.ds.Driver driver =
                new DriverImpl(
                    installedDriver.getDriverName(),
                    installedDriver.getMajorVersion(),
                    installedDriver.getMinorVersion(),
                    moduleName,
                    installedDriver.getDriverClassName(),
                    installedDriver.getDataSourceClassName(),
                    installedDriver.getXaDataSourceClassName());
            drivers.put(driverName, driver);
          }
          dataSources = new DatasourcesImpl(null, Arrays.asList(xaDataSourceConfig), drivers);
        }

        CommonDeployment c =
            createObjectsAndInjectValue(
                new URL("file://DataSourceDeployment"),
                dsName,
                "uniqueJdbcLocalId",
                "uniqueJdbcXAId",
                dataSources,
                AbstractDataSourceService.class.getClassLoader());
        return c;
      } catch (MalformedURLException e) {
        throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(e);
      } catch (ValidateException e) {
        throw ConnectorLogger.ROOT_LOGGER.cannotDeployAndValidate(e);
      }
    }