<commit_before>package org.apache.ibatis.jdbc;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

public class DataSourceUtils {

  /**
   * For each type, the supported DatabaseProductNameS
   *
   * TODO is this useful?
   */
  private static Map<String, Collection<String>> TYPE_NAME = new HashMap<String, Collection<String>>();

  /**
   * For each DatabaseProductName, the related type
   */
  private static Map<String, String> NAME_TYPE = new HashMap<String, String>();

  static {
    // data kindly borrowed from DbVisualizer (http://www.dbvis.com/)
    register("cache", "Cache");
    register("db2", "DB2");
    register("db2", "DB2 (DataDirect)");
    register("generic", "DB2 for AS/400 (JTOpen)");
    register("firebird", "Firebird");
    register("frontbase", "FrontBase");
    register("neoview", "HP Neoview");
    register("hsql", "HSQLDB server");
    register("hsql", "HSQLDB embedded");
    register("h2", "H2 server");
    register("h2", "H2 embedded");
    register("informix", "Informix");
    register("informix", "Informix (DataDirect)");
    register("derby", "JavaDB/Derby server");
    register("derby", "JavaDB/Derby embedded");
    register("jdatastore", "JDataStore");
    register("generic", "JDBC/ODBC Bridge");
    register("maxdb", "MaxDB");
    register("generic", "McKoi");
    register("mimer", "Mimer");
    register("mysql", "MySQL");
    register("netezza", "Netezza");
    register("oracle", "Oracle Thin");
    register("oracle", "Oracle OCI");
    register("oracle", "Oracle (DataDirect)");
    register("pervasive", "Pervasive");
    register("postgresql", "PostgreSQL");
    register("progress", "Progress");
    register("sqlite", "SQLite");
    register("sqlserver", "SQL Server (DataDirect)");
    register("sqlserver", "SQL Server (jTDS)");
    register("sqlserver", "SQL Server (Microsoft JDBC Driver)");
    register("sqlserver", "SQL Server 2008 (Microsoft JDBC Driver)");
    register("sybase-ase", "Sybase ASE (jTDS)");
    register("sybase-ase", "Sybase ASE (JConnect)");
    register("sybase-asa", "Sybase SQL Anywhere (JConnect)");
    register("sybase", "Sybase (DataDirect)");
  }

  private static void register(String type, String databaseProductName) {
    Collection<String> names = TYPE_NAME.get(type);
    if (names == null) {
      names = new ArrayList<String>();
      TYPE_NAME.put(type, names);
    }
    TYPE_NAME.put(type, names);

    NAME_TYPE.put(databaseProductName, type);
  }

  public static String getDatabaseName(DataSource dataSource) {
    Connection con = null;
    try {
      con = dataSource.getConnection();<commit_msg>better looking DB types/names registration<commit_after>package org.apache.ibatis.jdbc;

import static java.util.Arrays.asList;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

public class DataSourceUtils {

  /**
   * For each type, the supported DatabaseProductNameS
   *
   * TODO is this useful?
   */
  private static Map<String, Collection<String>> TYPE_NAME = new HashMap<String, Collection<String>>();

  /**
   * For each DatabaseProductName, the related type
   */
  private static Map<String, String> NAME_TYPE = new HashMap<String, String>();

  static {
    // data kindly borrowed from DbVisualizer (http://www.dbvis.com/)
    register("cache", "Cache");
    register("db2", "DB2",
                    "DB2 (DataDirect)");
    register("generic", "DB2 for AS/400 (JTOpen)",
                        "JDBC/ODBC Bridge", "McKoi");
    register("firebird", "Firebird");
    register("frontbase", "FrontBase");
    register("neoview", "HP Neoview");
    register("hsql", "HSQLDB server",
                     "HSQLDB embedded");
    register("h2", "H2 server",
                   "H2 embedded");
    register("informix", "Informix",
                         "Informix (DataDirect)");
    register("derby", "JavaDB/Derby server",
                      "JavaDB/Derby embedded");
    register("jdatastore", "JDataStore");
    register("maxdb", "MaxDB");
    register("mimer", "Mimer");
    register("mysql", "MySQL");
    register("netezza", "Netezza");
    register("oracle", "Oracle Thin",
                       "Oracle OCI",
                       "Oracle (DataDirect)");
    register("pervasive", "Pervasive");
    register("postgresql", "PostgreSQL");
    register("progress", "Progress");
    register("sqlite", "SQLite");
    register("sqlserver", "SQL Server (DataDirect)",
                          "SQL Server (jTDS)",
                          "SQL Server (Microsoft JDBC Driver)",
                          "SQL Server 2008 (Microsoft JDBC Driver)" );
    register("sybase-ase", "Sybase ASE (jTDS)",
                           "Sybase ASE (JConnect)",
                           "Sybase SQL Anywhere (JConnect)");
    register("sybase", "Sybase (DataDirect)");
  }

  private static void register(String type, String...databaseProductNames) {
    TYPE_NAME.put(type, asList(databaseProductNames));

    for (String databaseProductName : databaseProductNames) {
      NAME_TYPE.put(databaseProductName, type);
    }
  }

  public static String getDatabaseName(DataSource dataSource) {
    Connection con = null;
    try {
      con = dataSource.getConnection();
{'fraction_non_alphanumeric': 0.15217391304347827, 'fraction_numerical': 0.005434782608695652, 'mean_word_length': 3.4168, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '977871', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1619, 'n_words': 390}