package net.northking.cctp.maven.analyse.dialects;

import net.northking.cctp.maven.analyse.JDBCConfig;

/**
 * 数据库方言集合
 *
 * @author 谢秀松
 * @since 1.0
 */
public final class DBDialects
{
  /**
   * 单例模式：实例对象
   */
  private static DBDialects instance = new DBDialects();

  /**
   * 单例模式，隐藏构造函数
   */
  private DBDialects()
  {
  }

  /**
   * 单例模式，获取实例对象
   *
   * @return 实例对象
   */
  public static DBDialects getInstance()
  {
    return instance;
  }

  /**
   * 获取数据库方言对象
   *
   * @return 数据库方言对象
   */
  public Dialect getDialect()
  {
    JDBCConfig jdbcConfig = JDBCConfig.getInstance();
    String database = jdbcConfig.getDriverClass();
    Dialect dialect = null;
    if (database.toUpperCase().contains("POSTGRESQL"))
    {
      dialect = PostgreSQLDialect.getInstance();
    } else if (database.toUpperCase().contains("MYSQL"))
    {
      dialect = MySQLDialect.getInstance();
    } else if (database.toUpperCase().contains("ORACLE") || database.toUpperCase().contains("INFORMIX"))
    {
      return dialect;
    }
    return dialect;
  }


}
