All Implemented Interfaces:
IDatabase

public class CachedMySQLDatabase extends MySQLDatabase
A cached implementation of MySQLDatabase that provides caching for database queries. This class extends MySQLDatabase.
  • Constructor Details

    • CachedMySQLDatabase

      public CachedMySQLDatabase()
  • Method Details

    • select

      public List<Map<String,Object>> select (String tableName, String condition)
      Executes a SELECT query on a specified table with a provided condition.
      Specified by:
      select in interface IDatabase
      Overrides:
      select in class MySQLDatabase
      Parameters:
      tableName - the name of the table to select from
      condition - the condition to apply in the WHERE clause
      Returns:
      a List of Map objects where each Map represents a row in the result set, with column names as keys and column values as values
    • selectAll

      public List<Map<String,Object>> selectAll (String tableName)
      Retrieves all rows from the specified table in the database.
      Specified by:
      selectAll in interface IDatabase
      Overrides:
      selectAll in class MySQLDatabase
      Parameters:
      tableName - the name of the table to select from
      Returns:
      a list of maps containing the rows from the table
    • insert

      public void insert (String tableName, @NotNull @NotNull Map<String,Object> data)
      Inserts data into the specified table and clears the corresponding cache entries.
      Specified by:
      insert in interface IDatabase
      Overrides:
      insert in class MySQLDatabase
      Parameters:
      tableName - the name of the table
      data - a map containing the column names and their corresponding values to be inserted
    • update

      public void update (String tableName, String primaryKey, Object primaryKeyValue, @NotNull @NotNull Map<String,Object> newData)
      Updates a record in the specified table with the given primary key and new data.
      Specified by:
      update in interface IDatabase
      Overrides:
      update in class MySQLDatabase
      Parameters:
      tableName - the name of the table to update
      primaryKey - the name of the primary key column
      primaryKeyValue - the value of the primary key for the record to update
      newData - a map of column names to new values for the record
    • delete

      public void delete (String tableName, String primaryKey, Object primaryKeyValue)
      Deletes a record from the specified table based on the primary key and its value.
      Specified by:
      delete in interface IDatabase
      Overrides:
      delete in class MySQLDatabase
      Parameters:
      tableName - the name of the table
      primaryKey - the primary key column name
      primaryKeyValue - the value of the primary key to match for deletion
    • query

      public void query (String queryString)
      Clears the cache and executes the given query string.
      Specified by:
      query in interface IDatabase
      Overrides:
      query in class MySQLDatabase
      Parameters:
      queryString - the query string to execute
    • createIndex

      public void createIndex (String collectionName, String fieldName, boolean unique)
      Creates an index on a specified field in a collection.
      Specified by:
      createIndex in interface IDatabase
      Overrides:
      createIndex in class MySQLDatabase
      Parameters:
      collectionName - the name of the collection on which to create the index
      fieldName - the name of the field on which to create the index
      unique - true if the index should be unique, false otherwise