コード例 #1
0
  private void dbInit() {
    // Initialize connection pool
    String driver, url, user, pass;

    if (plugin.getConfig().getBoolean("mysql.enabled")) { // MySQL
      dbms = DBMS.MySQL;
      ConfigurationSection cs = plugin.getConfig().getConfigurationSection("mysql");
      String host = cs.getString("host");
      int port = cs.getInt("port");
      String db = cs.getString("database");

      driver = "com.mysql.jdbc.Driver";
      url = "jdbc:mysql://" + host + ":" + port + "/" + db + "?zeroDateTimeBehavior=convertToNull";
      user = cs.getString("user");
      pass = cs.getString("password");
    } else { // H2
      driver = "org.h2.Driver";
      url =
          "jdbc:h2:" + plugin.getDataFolder() + File.separator + "xAuth;MODE=MySQL;IGNORECASE=TRUE";
      user = "******";
      pass = "";
    }

    try {
      connPool = new ConnectionPool(driver, url, user, pass);
    } catch (ClassNotFoundException e) {
      xAuthLog.severe("Failed to create instance of " + getDBMS() + " JDBC Driver!", e);
    }

    // Register tables
    activeTables.add(Table.ACCOUNT);
    activeTables.add(Table.PLAYERDATA);

    // Activate session table only if session length is higher than zero
    if (plugin.getConfig().getInt("session.length") > 0) activeTables.add(Table.SESSION);

    // Activate location table only if location protection is enabled
    if (plugin.getConfig().getBoolean("guest.protect-location")) activeTables.add(Table.LOCATION);

    // Activate lockout table only if lockouts are enabled
    if (plugin.getConfig().getInt("strikes.lockout-length") > 0) activeTables.add(Table.LOCKOUT);
  }
コード例 #2
0
  public String getTable(Table tbl) {
    if (dbms == DBMS.H2) return tbl.getName();

    return plugin.getConfig().getString("mysql.tables." + tbl.toString().toLowerCase());
  }