Example #1
0
  public static ModifiableConnDef buildConnectionDefinitionObject(ModelNode operation)
      throws ValidateException {
    Map<String, String> configProperties = new HashMap<String, String>(0);
    //        if (operation.hasDefined(CONFIG_PROPERTIES.getName())) {
    //            configProperties = new HashMap<String,
    // String>(operation.get(CONFIG_PROPERTIES.getName()).asList().size());
    //            for (ModelNode property : operation.get(CONFIG_PROPERTIES.getName()).asList()) {
    //                configProperties.put(property.asProperty().getName(),
    // property.asProperty().getValue().asString());
    //            }
    //        }
    String className = getStringIfSetOrGetDefault(operation, CLASS_NAME.getName(), null);
    String jndiName = getStringIfSetOrGetDefault(operation, JNDINAME.getName(), null);
    String poolName = getStringIfSetOrGetDefault(operation, POOL_NAME.getName(), null);
    boolean enabled = getBooleanIfSetOrGetDefault(operation, ENABLED.getName(), Defaults.ENABLED);
    boolean useJavaContext =
        getBooleanIfSetOrGetDefault(
            operation, USE_JAVA_CONTEXT.getName(), Defaults.USE_JAVA_CONTEXT);
    boolean useCcm = getBooleanIfSetOrGetDefault(operation, USE_CCM.getName(), Defaults.USE_CCM);

    Integer maxPoolSize =
        getIntIfSetOrGetDefault(operation, MAX_POOL_SIZE.getName(), Defaults.MAX_POOL_SIZE);
    Integer minPoolSize =
        getIntIfSetOrGetDefault(operation, MIN_POOL_SIZE.getName(), Defaults.MIN_POOL_SIZE);
    boolean prefill =
        getBooleanIfSetOrGetDefault(operation, POOL_PREFILL.getName(), Defaults.PREFILL);
    boolean useStrictMin =
        getBooleanIfSetOrGetDefault(
            operation, POOL_USE_STRICT_MIN.getName(), Defaults.USE_STRICT_MIN);
    final FlushStrategy flushStrategy =
        operation.hasDefined(POOL_FLUSH_STRATEGY.getName())
            ? FlushStrategy.forName(operation.get(POOL_FLUSH_STRATEGY.getName()).asString())
            : Defaults.FLUSH_STRATEGY;

    Integer allocationRetry = getIntIfSetOrGetDefault(operation, ALLOCATION_RETRY.getName(), null);
    Long allocationRetryWaitMillis =
        getLongIfSetOrGetDefault(operation, ALLOCATION_RETRY_WAIT_MILLIS.getName(), null);
    Long blockingTimeoutMillis =
        getLongIfSetOrGetDefault(operation, BLOCKING_TIMEOUT_WAIT_MILLIS.getName(), null);
    Long idleTimeoutMinutes =
        getLongIfSetOrGetDefault(operation, IDLETIMEOUTMINUTES.getName(), null);
    Integer xaResourceTimeout =
        getIntIfSetOrGetDefault(operation, XA_RESOURCE_TIMEOUT.getName(), null);
    CommonTimeOut timeOut =
        new CommonTimeOutImpl(
            blockingTimeoutMillis,
            idleTimeoutMinutes,
            allocationRetry,
            allocationRetryWaitMillis,
            xaResourceTimeout);
    CommonPool pool =
        new CommonPoolImpl(minPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy);

    String securityDomain = getStringIfSetOrGetDefault(operation, SECURITY_DOMAIN.getName(), null);
    String securityDomainAndApplication =
        getStringIfSetOrGetDefault(operation, SECURITY_DOMAIN_AND_APPLICATION.getName(), null);
    Boolean application = getBooleanIfSetOrGetDefault(operation, APPLICATION.getName(), null);

    CommonSecurity security = null;

    if (securityDomain != null && securityDomainAndApplication != null && application != null) {
      if (application == null) application = Defaults.APPLICATION_MANAGED_SECURITY;
      security = new CommonSecurityImpl(securityDomain, securityDomainAndApplication, application);
    }

    Long backgroundValidationMillis =
        getLongIfSetOrGetDefault(operation, BACKGROUNDVALIDATIONMILLIS.getName(), null);
    boolean backgroundValidation =
        getBooleanIfSetOrGetDefault(
            operation, BACKGROUNDVALIDATION.getName(), Defaults.BACKGROUND_VALIDATION);
    boolean useFastFail =
        getBooleanIfSetOrGetDefault(operation, USE_FAST_FAIL.getName(), Defaults.USE_FAST_FAIl);
    CommonValidation validation =
        new CommonValidationImpl(backgroundValidation, backgroundValidationMillis, useFastFail);
    final String recoveryUsername =
        getStringIfSetOrGetDefault(operation, RECOVERY_USERNAME.getName(), null);
    String recoveryPassword =
        getStringIfSetOrGetDefault(operation, RECOVERY_PASSWORD.getName(), null);

    if (VaultUtil.isVaultFormat(recoveryPassword)) {
      try {
        recoveryPassword = VaultUtil.getValueAsString(recoveryPassword);
      } catch (SecurityVaultException e) {
        throw new RuntimeException(e); // TODO: use bundle from IJ
      }
    }
    final String recoverySecurityDomain =
        getStringIfSetOrGetDefault(operation, RECOVERY_SECURITY_DOMAIN.getName(), null);

    final Credential credential =
        new CredentialImpl(recoveryUsername, recoveryPassword, recoverySecurityDomain);

    final Extension recoverPlugin =
        extractExtension(
            operation, RECOVERLUGIN_CLASSNAME.getName(), RECOVERLUGIN_PROPERTIES.getName());
    final boolean noRecovery = getBooleanIfSetOrGetDefault(operation, NO_RECOVERY.getName(), false);
    Recovery recovery = new Recovery(credential, recoverPlugin, noRecovery);
    ModifiableConnDef connectionDefinition =
        new ModifiableConnDef(
            configProperties,
            className,
            jndiName,
            poolName,
            enabled,
            useJavaContext,
            useCcm,
            pool,
            timeOut,
            validation,
            security,
            recovery);

    return connectionDefinition;
  }