Class MariaDBStore

java.lang.Object
com.gmt2001.datastore.DataStore
com.gmt2001.datastore.MariaDBStore

public final class MariaDBStore extends DataStore
Author:
gmt2001
  • Method Details

    • instance

      public static MariaDBStore instance()
    • instance

      public static MariaDBStore instance(String configStr)
    • CanConnect

      public boolean CanConnect()
      Description copied from class: DataStore
      Tests if the connection to the database succeeds
      Overrides:
      CanConnect in class DataStore
      Returns:
      true on success
    • AddFile

      public void AddFile(String fName)
      Description copied from class: DataStore
      Creates a new table
      Overrides:
      AddFile in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
    • AddFile

      public void AddFile(Connection connection, String fName)
    • RemoveKey

      public void RemoveKey(String fName, String section, String key)
      Description copied from class: DataStore
      Deletes the row that matches the given table, section, and key

      If section is null, deletes all rows with a matching table and key, regardless of section

      Overrides:
      RemoveKey in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
    • RemoveSection

      public void RemoveSection(String fName, String section)
      Description copied from class: DataStore
      Deletes all rows that match the given table and section
      Overrides:
      RemoveSection in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section
    • RemoveFile

      public void RemoveFile(String fName)
      Description copied from class: DataStore
      Deletes the table
      Overrides:
      RemoveFile in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
    • RenameFile

      public void RenameFile(String fNameSource, String fNameDest)
      Description copied from class: DataStore
      Renames the table
      Overrides:
      RenameFile in class DataStore
      Parameters:
      fNameSource - a table name for an existing table, without the phantombot_ prefix
      fNameDest - a new table name that does not yet exist, without the phantombot_ prefix
    • FileExists

      public boolean FileExists(String fName)
      Description copied from class: DataStore
      Indicates if the given table already exists
      Overrides:
      FileExists in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      Returns:
      true if the table exists
    • FileExists

      public boolean FileExists(Connection connection, String fName)
    • GetFileList

      public String[] GetFileList()
      Description copied from class: DataStore
      Returns a list of tables in the database.

      Only tables with the phantombot_ prefix are returned. The prefix is removed

      Overrides:
      GetFileList in class DataStore
      Returns:
      an array of table names
    • GetCategoryList

      public String[] GetCategoryList(String fName)
      Description copied from class: DataStore
      Returns a list of all values in the section column within the table
      Overrides:
      GetCategoryList in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      Returns:
      an array of sections
    • GetKeyList

      public String[] GetKeyList(String fName, String section)
      Description copied from class: DataStore
      Returns a list of all values in the variable column within the table and section
      Overrides:
      GetKeyList in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      an array of variables
    • GetKeyValueList

      public KeyValue[] GetKeyValueList(String fName, String section)
      Description copied from class: DataStore
      Returns a list of all variable/value pairs within the table and section
      Overrides:
      GetKeyValueList in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      an array of KeyValue pairs denoting the variables and values
    • GetKeysByOrder

      public String[] GetKeysByOrder(String fName, String section, String order, String limit, String offset)
      Description copied from class: DataStore
      Returns a list of values in the variable column within the table and section, sorted naturally
      Overrides:
      GetKeysByOrder in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrder

      public String[] GetKeysByNumberOrder(String fName, String section, String order, String limit, String offset)
      Description copied from class: DataStore
      Returns a list of values in the variable column within the table and section, sorted naturally as integers
      Overrides:
      GetKeysByNumberOrder in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeysByOrderValue

      public String[] GetKeysByOrderValue(String fName, String section, String order, String limit, String offset)
      Description copied from class: DataStore
      Returns a list of values in the variable column within the table and section, sorted naturally by the value column
      Overrides:
      GetKeysByOrderValue in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrderValue

      public String[] GetKeysByNumberOrderValue(String fName, String section, String order, String limit, String offset)
      Description copied from class: DataStore
      Returns a list of values in the variable column within the table and section, sorted naturally by the value column as integers
      Overrides:
      GetKeysByNumberOrderValue in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeysByLikeValues

      public String[] GetKeysByLikeValues(String fName, String section, String search)
      Description copied from class: DataStore
      Returns a list of values in the variable column within the table and section, where the value of the value column contains the search phrase
      Overrides:
      GetKeysByLikeValues in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the value column to match against
      Returns:
      a list of variables
    • GetKeysByLikeKeys

      public String[] GetKeysByLikeKeys(String fName, String section, String search)
      Description copied from class: DataStore
      Returns a list of values in the variable column within the table and section, where the value of the variable column contains the search phrase
      Overrides:
      GetKeysByLikeKeys in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the variable column to match against
      Returns:
      a list of variables
    • GetKeysByLikeKeysOrder

      public String[] GetKeysByLikeKeysOrder(String fName, String section, String search, String order, String limit, String offset)
      Description copied from class: DataStore
      Returns a list of values in the variable column within the table and section, where the value of the variable column contains the search phrase, sorted naturally
      Overrides:
      GetKeysByLikeKeysOrder in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the variable column to match against
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • HasKey

      public boolean HasKey(String fName, String section, String key)
      Description copied from class: DataStore
      Indicates if the given table contains a row matching the given section and key
      Overrides:
      HasKey in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) or null for all sections
      key - the value of the variable column
      Returns:
      true if the key exists
    • GetKeyByValue

      public String GetKeyByValue(String fName, String section, String value)
      Description copied from class: DataStore
      Returns the value of the variable column for the given table, section, and value
      Overrides:
      GetKeyByValue in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      value - the value of the value column
      Returns:
      the variable; null if not found
    • GetString

      public String GetString(String fName, String section, String key)
      Description copied from class: DataStore
      Returns the value of the value column for the given table, section, and key as a string

      A return value of null may denote that the table/row is not found, or that the actual stored value is SQL NULL. Use DataStore.HasKey(String, String, String) to verify if the row exists

      Overrides:
      GetString in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      the value
    • SetBatchString

      public void SetBatchString(String fName, String section, String[] keys, String[] values)
      Description copied from class: DataStore
      Performs a bulk DataStore.SetString(String, String, String, String) operation, using available database features to do so more efficiently.

      The array index of the keys and value params are linked

      Overrides:
      SetBatchString in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      keys - the values of the variable column to update
      values - the new values to set the value column to
    • SetString

      public void SetString(String fName, String section, String key, String value)
      Description copied from class: DataStore
      Sets the value of the value column for the given table, section, and key as a string
      Overrides:
      SetString in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to update
      value - the new value of the value column
    • IncreaseBatchString

      public void IncreaseBatchString(String fName, String section, String[] keys, String value)
      Description copied from class: DataStore
      Increases the value of the value column as an integer for all keys of the given table and section
      Overrides:
      IncreaseBatchString in class DataStore
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      keys - the values of the variable column to update
      value - the new value to increase the value column by
    • query

      public List<List<String>> query(String sql, String[] replacements)
      Description copied from class: DataStore
      Executes an SQL query

      The query is executed using a PreparedStatement with calls to PreparedStatement.setString(int, String)

      For example:
      executeSql("SELECT * FROM foo WHERE bar = ?", ["baz"])

      The value "baz" is escaped to prevent SQL injection, then inserted in place of the ?

      This yields the final query of
      SELECT * FROM foo WHERE bar = "baz"

      You can use ? as many times as necessary, but must provide the same number of elements in the replacements array for the replacement to work

      Replacements are performed in order from left to right

      Exceptions from failed SQL queries are NOT returned or thrown, but are logged in the core-error log

      Overrides:
      query in class DataStore
      Parameters:
      sql - The query to execute
      replacements - Replacements for PreparedStatement.setString(int, String)
      Returns:
      An List of data as strings representing the result set, if the query was a DQL statement; an empty list otherwise. The outer list represents rows; the inner array represents columns; the values of the inner list represent the value of the row-column pair at that index as a string