Class CachedMongoDBDatabase
java.lang.Object
me.github.simonplays15.betterbansystem.core.database.Database
me.github.simonplays15.betterbansystem.core.database.mongodb.MongoDBDatabase
me.github.simonplays15.betterbansystem.core.database.mongodb.CachedMongoDBDatabase
- All Implemented Interfaces:
IDatabase
A subclass of MongoDBDatabase that implements caching for enhanced performance.
This class maintains a cache of query results to avoid accessing the database unnecessarily.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateIndex(String collectionName, String fieldName, boolean unique) Creates an index in the specified collection on the given field.voidDeletes a record from the specified table based on the primary key value.voidInserts a new document into the specified table in the MongoDB database.voidExecutes a query on the MongoDB database and clears the cache.Retrieves a list of rows from a database table based on the given condition.Retrieves all records from the specified table in the MongoDB database.voidupdate(String tableName, String primaryKey, Object primaryKeyValue, @NotNull Map<String, Object> newData) Updates a document in the specified MongoDB collection and clears the cache for the updated collection.Methods inherited from class me.github.simonplays15.betterbansystem.core.database.mongodb.MongoDBDatabase
commitTransaction, connect, createDatabaseAndTables, disconnect, executeQuery, rollbackTransaction, startTransaction
-
Constructor Details
-
CachedMongoDBDatabase
public CachedMongoDBDatabase()
-
-
Method Details
-
select
Retrieves a list of rows from a database table based on the given condition. If the result is already present in the cache, it is returned from the cache instead of querying the database.- Specified by:
selectin interfaceIDatabase- Overrides:
selectin classMongoDBDatabase- Parameters:
tableName- the name of the table to select fromcondition- the condition to use for selecting rows- Returns:
- a list of maps representing the selected rows, where each map contains column names as keys and column values as values
-
selectAll
Retrieves all records from the specified table in the MongoDB database.- Specified by:
selectAllin interfaceIDatabase- Overrides:
selectAllin classMongoDBDatabase- Parameters:
tableName- the name of the table to select from- Returns:
- a list of maps representing the selected records
-
insert
Inserts a new document into the specified table in the MongoDB database.- Specified by:
insertin interfaceIDatabase- Overrides:
insertin classMongoDBDatabase- Parameters:
tableName- the name of the table to insert the document intodata- a map containing the data to be inserted, with the field names as keys and the field values as values
-
update
public void update(String tableName, String primaryKey, Object primaryKeyValue, @NotNull @NotNull Map<String, Object> newData) Updates a document in the specified MongoDB collection and clears the cache for the updated collection.- Specified by:
updatein interfaceIDatabase- Overrides:
updatein classMongoDBDatabase- Parameters:
tableName- the name of the collectionprimaryKey- the name of the primary key fieldprimaryKeyValue- the value of the primary key for the document to updatenewData- aMapof field names and their updated values
-
delete
Deletes a record from the specified table based on the primary key value. This method overrides the delete method in the super class and additionally clears the cache of query results that are associated with the deleted table.- Specified by:
deletein interfaceIDatabase- Overrides:
deletein classMongoDBDatabase- Parameters:
tableName- the name of the tableprimaryKey- the name of the primary key columnprimaryKeyValue- the value of the primary key to match
-
query
Executes a query on the MongoDB database and clears the cache.- Specified by:
queryin interfaceIDatabase- Overrides:
queryin classMongoDBDatabase- Parameters:
queryString- the query string to execute
-
createIndex
Creates an index in the specified collection on the given field.- Specified by:
createIndexin interfaceIDatabase- Overrides:
createIndexin classMongoDBDatabase- Parameters:
collectionName- the name of the collection where the index is to be createdfieldName- the name of the field on which the index is to be createdunique- true if the index should enforce a unique constraint, false otherwise
-