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 TypeMethodDescriptionvoidcreateIndex(String collectionName, String fieldName, boolean unique) Creates an index on a specified field in a collection.voidDeletes a record from the specified table based on the primary key and its value.voidInserts data into the specified table and clears the corresponding cache entries.voidClears 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.voidupdate(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:
selectin interfaceIDatabase- Overrides:
selectin 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:
selectAllin interfaceIDatabase- Overrides:
selectAllin 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:
insertin interfaceIDatabase- Overrides:
insertin 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:
updatein interfaceIDatabase- Overrides:
updatein 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:
deletein interfaceIDatabase- Overrides:
deletein 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:
queryin interfaceIDatabase- Overrides:
queryin classMySQLDatabase- Parameters:
queryString- the query string to execute
-
createIndex
Creates an index on a specified field in a collection.- Specified by:
createIndexin interfaceIDatabase- Overrides:
createIndexin 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-trueif the index should be unique,falseotherwise
-