<commit_before>/*
 * Copyright 2015 Adaptris Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.adaptris.core.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import org.apache.commons.lang3.BooleanUtils;
import com.adaptris.annotation.AdvancedConfig;
import com.adaptris.annotation.AutoPopulated;
import com.adaptris.annotation.InputFieldDefault;
import com.adaptris.annotation.InputFieldHint;
import com.adaptris.core.AllowsRetriesConnection;
import com.adaptris.core.CoreException;
import com.adaptris.core.util.JdbcUtil;
import com.adaptris.interlok.resolver.ExternalResolver;
import com.adaptris.security.exc.PasswordException;
import com.adaptris.util.KeyValuePairBag;
import com.adaptris.util.KeyValuePairSet;

/**
 * <p>
 * Abstract class containing configuration for JDBC Connection classes.
 * </p>
 * 
 * @author lchan
 */
public abstract class DatabaseConnection extends AllowsRetriesConnection {

  @AutoPopulated
  @NotBlank
  @InputFieldHint(style = "SQL")
  @AdvancedConfig
  private String testStatement;
  @NotBlank
  @AutoPopulated
  private String driverImp;
  @AdvancedConfig
  @InputFieldDefault(value = "true")
  private Boolean autoCommit;
  @AdvancedConfig
  @InputFieldDefault(value = "false")
  private Boolean debugMode;
  @AdvancedConfig
  @InputFieldDefault(value = "false")
  private Boolean alwaysValidateConnection;
  private String username;
  @InputFieldHint(style = "PASSWORD", external = true)
  private String password;
  @Valid
  @AdvancedConfig
  private KeyValuePairSet connectionProperties;

  private transient DataSource wrapper;

  enum ConnectionState {
    Closed, Initialising, Initialised, Starting, Started, Stopping, Stopped, Closing
  };

  private transient ConnectionState connectionState;

  /**
   * <p>
   * Creates a new instance. Defaults are auto-commit and MySQL. Always validate is false and the test statement set to<commit_msg>INTERLOK-218 Mark testConnection as deprecated<commit_after>/*
 * Copyright 2015 Adaptris Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.adaptris.core.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import com.adaptris.annotation.Removal;
import org.apache.commons.lang3.BooleanUtils;
import com.adaptris.annotation.AdvancedConfig;
import com.adaptris.annotation.AutoPopulated;
import com.adaptris.annotation.InputFieldDefault;
import com.adaptris.annotation.InputFieldHint;
import com.adaptris.core.AllowsRetriesConnection;
import com.adaptris.core.CoreException;
import com.adaptris.core.util.JdbcUtil;
import com.adaptris.interlok.resolver.ExternalResolver;
import com.adaptris.security.exc.PasswordException;
import com.adaptris.util.KeyValuePairBag;
import com.adaptris.util.KeyValuePairSet;

/**
 * <p>
 * Abstract class containing configuration for JDBC Connection classes.
 * </p>
 * 
 * @author lchan
 */
public abstract class DatabaseConnection extends AllowsRetriesConnection {

  @AutoPopulated
  @NotBlank
  @InputFieldHint(style = "SQL")
  @AdvancedConfig
  @Deprecated
  @Removal(message = "Use java.sql.Connection#isValid(int) to test a connection", version = "4.0.0")
  private String testStatement;
  @NotBlank
  @AutoPopulated
  private String driverImp;
  @AdvancedConfig
  @InputFieldDefault(value = "true")
  private Boolean autoCommit;
  @AdvancedConfig
  @InputFieldDefault(value = "false")
  private Boolean debugMode;
  @AdvancedConfig
  @InputFieldDefault(value = "false")
  private Boolean alwaysValidateConnection;
  private String username;
  @InputFieldHint(style = "PASSWORD", external = true)
  private String password;
  @Valid
  @AdvancedConfig
  private KeyValuePairSet connectionProperties;

  private transient DataSource wrapper;

  enum ConnectionState {
    Closed, Initialising, Initialised, Starting, Started, Stopping, Stopped, Closing
  };

  private transient ConnectionState connectionState;

  /**
   * <p>
   * Creates a new instance. Defaults are auto-commit and MySQL. Always validate is false and the test statement set to
{'fraction_non_alphanumeric': 0.08303655107778819, 'fraction_numerical': 0.004498594189315839, 'mean_word_length': 4.9157427937915745, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1892742', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1443, 'n_words': 461}