public static DatabaseProduct determineDatabaseProduct(String productName,
      Configuration conf) {
    DbType dbt;

    Preconditions.checkNotNull(conf, "Configuration is null");
    // Check if we are using an external database product
    boolean isExternal = MetastoreConf.getBoolVar(conf, ConfVars.USE_CUSTOM_RDBMS);

    if (theDatabaseProduct != null) {
      dbt = getDbType(productName);
      if (isExternal) {
        dbt = DbType.CUSTOM;
      }
      Preconditions.checkState(theDatabaseProduct.dbType == dbt);
      return theDatabaseProduct;
    }

    // This method may be invoked by concurrent connections
    synchronized (DatabaseProduct.class) {

      if (productName == null) {
        productName = UNDEFINED_NAME;
      }

      dbt = getDbType(productName);

      // Check for null again in case of race condition
      if (theDatabaseProduct == null) {
        if (isExternal) {
          // The DatabaseProduct will be created by instantiating an external class via
          // reflection. The external class can override any method in the current class
          String className = MetastoreConf.getVar(conf, ConfVars.CUSTOM_RDBMS_CLASSNAME);

          if (className != null) {
            try {
              theDatabaseProduct = (DatabaseProduct)
                  ReflectionUtils.newInstance(Class.forName(className), conf);

              LOG.info(String.format("Using custom RDBMS %s", className));
              dbt = DbType.CUSTOM;
            } catch (Exception e) {
              throw new RuntimeException(
                  "Caught exception instantiating custom database product", e);
            }
          } else {
            throw new RuntimeException(
                "Unexpected: metastore.use.custom.database.product was set, " +
                    "but metastore.custom.database.product.classname was not");
          }
        }

        if (theDatabaseProduct == null) {
          theDatabaseProduct = new DatabaseProduct();
        }

        theDatabaseProduct.dbType = dbt;
        theDatabaseProduct.productName = productName;
      }
    }
    return theDatabaseProduct;
  }
Determine the database product type
@param productName string to defer database connection
@return database product type
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/DatabaseProduct.java