All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.hsgamer.hscore.database.Driver Maven / Gradle / Ivy

There is a newer version: 4.3.29
Show newest version
package me.hsgamer.hscore.database;

import java.util.List;

/**
 * A driver for database connection
 */
public interface Driver {

  /**
   * Create the property string for the URL
   *
   * @param setting   the setting
   * @param prefix    the prefix
   * @param delimiter the delimiter between the properties
   *
   * @return the property string
   */
  static String createPropertyString(Setting setting, String prefix, String delimiter) {
    StringBuilder builder = new StringBuilder();
    List properties = setting.getDriverPropertyStrings();
    if (!properties.isEmpty()) {
      builder.append(prefix);
      builder.append(String.join(delimiter, properties));
    }
    return builder.toString();
  }

  /**
   * Create the property string for the URL
   *
   * @param setting the setting
   *
   * @return the property string
   */
  static String createPropertyString(Setting setting) {
    return createPropertyString(setting, "?", "&");
  }

  /**
   * Get the driver class
   *
   * @return the driver class
   */
  Class getDriverClass();

  /**
   * Get the JDBC url from the config
   *
   * @param setting the setting
   *
   * @return the JDBC url
   */
  String convertURL(Setting setting);

  /**
   * Apply the default setting
   *
   * @param setting the setting
   */
  default void applyDefaultSetting(Setting setting) {
    // EMPTY
  }

  /**
   * Get the driver class name
   *
   * @return the driver class name
   */
  default String getDriverClassName() {
    return getDriverClass().getName();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy