Class CachedMySQLDatabase
java.lang.Object
me.github.simonplays15.betterbansystem.core.database.Database
me.github.simonplays15.betterbansystem.core.database.mysql.MySQLDatabase
me.github.simonplays15.betterbansystem.core.database.mysql.CachedMySQLDatabase
- All Implemented Interfaces:
IDatabase
A cached implementation of MySQLDatabase that provides caching for database queries.
This class extends MySQLDatabase.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
createIndex
(String collectionName, String fieldName, boolean unique) Creates an index on a specified field in a collection.void
Deletes a record from the specified table based on the primary key and its value.void
Inserts data into the specified table and clears the corresponding cache entries.void
Clears the cache and executes the given query string.Executes a SELECT query on a specified table with a provided condition.Retrieves all rows from the specified table in the database.void
update
(String tableName, String primaryKey, Object primaryKeyValue, @NotNull Map<String, Object> newData) Updates a record in the specified table with the given primary key and new data.Methods inherited from class me.github.simonplays15.betterbansystem.core.database.mysql.MySQLDatabase
commitTransaction, connect, createDatabaseAndTables, disconnect, executeQuery, rollbackTransaction, startTransaction
-
Constructor Details
-
CachedMySQLDatabase
public CachedMySQLDatabase()
-
-
Method Details
-
select
Executes a SELECT query on a specified table with a provided condition.- Specified by:
select
in interfaceIDatabase
- Overrides:
select
in classMySQLDatabase
- Parameters:
tableName
- the name of the table to select fromcondition
- 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
Retrieves all rows from the specified table in the database.- Specified by:
selectAll
in interfaceIDatabase
- Overrides:
selectAll
in classMySQLDatabase
- Parameters:
tableName
- the name of the table to select from- Returns:
- a list of maps containing the rows from the table
-
insert
Inserts data into the specified table and clears the corresponding cache entries.- Specified by:
insert
in interfaceIDatabase
- Overrides:
insert
in classMySQLDatabase
- Parameters:
tableName
- the name of the tabledata
- 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 interfaceIDatabase
- Overrides:
update
in classMySQLDatabase
- Parameters:
tableName
- the name of the table to updateprimaryKey
- the name of the primary key columnprimaryKeyValue
- the value of the primary key for the record to updatenewData
- a map of column names to new values for the record
-
delete
Deletes a record from the specified table based on the primary key and its value.- Specified by:
delete
in interfaceIDatabase
- Overrides:
delete
in classMySQLDatabase
- Parameters:
tableName
- the name of the tableprimaryKey
- the primary key column nameprimaryKeyValue
- the value of the primary key to match for deletion
-
query
Clears the cache and executes the given query string.- Specified by:
query
in interfaceIDatabase
- Overrides:
query
in classMySQLDatabase
- Parameters:
queryString
- the query string to execute
-
createIndex
Creates an index on a specified field in a collection.- Specified by:
createIndex
in interfaceIDatabase
- Overrides:
createIndex
in classMySQLDatabase
- Parameters:
collectionName
- the name of the collection on which to create the indexfieldName
- the name of the field on which to create the indexunique
-true
if the index should be unique,false
otherwise
-