<commit_before>package at.ac.univie.isc.asio.config;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty;

/**
 * Record connection informations for a DB backing asio.
 *
 * @author <NAME>
 */
public class DatasourceSpec {

  public static JdbcUrlHolder connectTo(final String jdbcUrl) {
    return new JdbcUrlHolder(jdbcUrl);
  }

  // jdbc
  private final String jdbcUrl;
  private final String jdbcDriver;
  // credentials
  private final String username;
  private final String password;

  DatasourceSpec(final String jdbcUrl, final String jdbcDriver, final String username,
                        final String password) {
    super();
    checkNotNull(emptyToNull(jdbcUrl), "no JDBC connection URL given");
    this.jdbcUrl = addDefaultOptions(jdbcUrl);
    this.jdbcDriver = checkNotNull(emptyToNull(jdbcDriver), "missing driver class for %s", jdbcUrl);
    this.username = nullToEmpty(username);
    this.password = nullToEmpty(password);
  }

  private static final Pattern MYSQL_JDBC = Pattern.compile("^jdbc:mysql://.*$");
  private static final String MYSQL_DEFAULTS = "?zeroDateTimeBehavior=convertToNull";

  private String addDefaultOptions(final String jdbcUrl) {
    String processed = jdbcUrl;
    final Matcher mysqlPattern = MYSQL_JDBC.matcher(jdbcUrl);
    if (mysqlPattern.matches()) {
      processed = jdbcUrl + MYSQL_DEFAULTS;
    }
    return processed;
  }

  public String getJdbcDriver() {
    return jdbcDriver;
  }

  public String getJdbcUrl() {
    return jdbcUrl;
  }

  public String getUsername() {
    return username;
  }

  public String getPassword() {
    return password;
  }

  @Override
  public String toString() {
    return String.format("DatasourceSpec [jdbcUrl=%s, jdbcDriver=%s, username=%s, password=%s]",
        jdbcUrl, jdbcDriver, username, password);
  }

  // ************** builder


  public static class JdbcUrlHolder {
    private final String jdbcUrl;

    private JdbcUrlHolder(final String jdbcUrl) {
      this.jdbcUrl = jdbcUrl;
    }

    public JdbcConnectionHolder with(String jdbcDriver) {<commit_msg>[FIX-37] password excluded from DatasourceSpec string representation<commit_after>package at.ac.univie.isc.asio.config;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty;

/**
 * Record connection informations for a DB backing asio.
 *
 * @author <NAME>
 */
public class DatasourceSpec {

  public static JdbcUrlHolder connectTo(final String jdbcUrl) {
    return new JdbcUrlHolder(jdbcUrl);
  }

  // jdbc
  private final String jdbcUrl;
  private final String jdbcDriver;
  // credentials
  private final String username;
  private final String password;

  DatasourceSpec(final String jdbcUrl, final String jdbcDriver, final String username,
                        final String password) {
    super();
    checkNotNull(emptyToNull(jdbcUrl), "no JDBC connection URL given");
    this.jdbcUrl = addDefaultOptions(jdbcUrl);
    this.jdbcDriver = checkNotNull(emptyToNull(jdbcDriver), "missing driver class for %s", jdbcUrl);
    this.username = nullToEmpty(username);
    this.password = nullToEmpty(password);
  }

  private static final Pattern MYSQL_JDBC = Pattern.compile("^jdbc:mysql://.*$");
  private static final String MYSQL_DEFAULTS = "?zeroDateTimeBehavior=convertToNull";

  private String addDefaultOptions(final String jdbcUrl) {
    String processed = jdbcUrl;
    final Matcher mysqlPattern = MYSQL_JDBC.matcher(jdbcUrl);
    if (mysqlPattern.matches()) {
      processed = jdbcUrl + MYSQL_DEFAULTS;
    }
    return processed;
  }

  public String getJdbcDriver() {
    return jdbcDriver;
  }

  public String getJdbcUrl() {
    return jdbcUrl;
  }

  public String getUsername() {
    return username;
  }

  public String getPassword() {
    return password;
  }

  @Override
  public String toString() {
    return String.format("DatasourceSpec [jdbcUrl=%s, jdbcDriver=%s, username=%s]",
        jdbcUrl, jdbcDriver, username);
  }

  // ************** builder


  public static class JdbcUrlHolder {
    private final String jdbcUrl;

    private JdbcUrlHolder(final String jdbcUrl) {
      this.jdbcUrl = jdbcUrl;
    }

    public JdbcConnectionHolder with(String jdbcDriver) {
{'fraction_non_alphanumeric': 0.09925503943908852, 'fraction_numerical': 0.00043821209465381246, 'mean_word_length': 3.877136752136752, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2403138', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1328, 'n_words': 348}