Class CachedSQLiteDatabase
java.lang.Object
me.github.simonplays15.betterbansystem.core.database.Database
me.github.simonplays15.betterbansystem.core.database.sqlite.SQLiteDatabase
me.github.simonplays15.betterbansystem.core.database.sqlite.CachedSQLiteDatabase
- All Implemented Interfaces:
IDatabase
This class extends the SQLiteDatabase class and provides caching capabilities for
select queries.
It maintains a cache map that stores the results of previous select queries based on the table name
and condition.
The cache is cleared whenever an insert, update, delete or query operation is performed.
Additionally, the cache is also cleared when an index is created on a collection.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateIndex(String collectionName, String fieldName, boolean unique) Creates an index on a specified field in a given collection.voidDeletes a record from the specified table based on the primary key.voidInserts data into the specified table.voidExecutes a database query with the given query string.Executes a SELECT query on the specified table with the given condition.Retrieves all records from the specified table.voidupdate(String tableName, String primaryKey, Object primaryKeyValue, @NotNull Map<String, Object> newData) Updates a record in the specified table with new data based on the primary key.Methods inherited from class me.github.simonplays15.betterbansystem.core.database.sqlite.SQLiteDatabase
commitTransaction, connect, createDatabaseAndTables, disconnect, executeQuery, rollbackTransaction, startTransaction
-
Constructor Details
-
CachedSQLiteDatabase
public CachedSQLiteDatabase()
-
-
Method Details
-
select
Executes a SELECT query on the specified table with the given condition. Returns a list of maps, where each map represents a row of the result set with column names as keys and column values as values.- Specified by:
selectin interfaceIDatabase- Overrides:
selectin classSQLiteDatabase- Parameters:
tableName- the name of the table to querycondition- the condition to apply in the WHERE clause of the query- Returns:
- a list of maps representing the result set of the SELECT query
-
selectAll
Retrieves all records from the specified table.- Specified by:
selectAllin interfaceIDatabase- Overrides:
selectAllin classSQLiteDatabase- Parameters:
tableName- the name of the table- Returns:
- a list of maps representing each record in the table
-
insert
Inserts data into the specified table.- Specified by:
insertin interfaceIDatabase- Overrides:
insertin classSQLiteDatabase- Parameters:
tableName- the name of the tabledata- a Map containing the column names and their corresponding values
-
update
public void update(String tableName, String primaryKey, Object primaryKeyValue, @NotNull @NotNull Map<String, Object> newData) Updates a record in the specified table with new data based on the primary key.- Specified by:
updatein interfaceIDatabase- Overrides:
updatein classSQLiteDatabase- Parameters:
tableName- the name of the table to updateprimaryKey- the name of the primary key columnprimaryKeyValue- the value of the primary key of the record to updatenewData- a map containing the new column-value pairs to update
-
delete
Deletes a record from the specified table based on the primary key.- Specified by:
deletein interfaceIDatabase- Overrides:
deletein classSQLiteDatabase- Parameters:
tableName- the name of the table where the record will be deletedprimaryKey- the name of the primary key columnprimaryKeyValue- the value of the primary key for the record to be deleted
-
query
Executes a database query with the given query string.- Specified by:
queryin interfaceIDatabase- Overrides:
queryin classSQLiteDatabase- Parameters:
queryString- The SQL query string to execute
-
createIndex
Creates an index on a specified field in a given collection. This method overrides the createIndex method from the SQLiteDatabase class in order to provide caching capabilities for select queries. It maintains a cache map that stores the results of previous select queries based on the table name and condition. The cache is cleared whenever an insert, update, delete or query operation is performed. Additionally, the cache is also cleared when an index is created on a collection.- Specified by:
createIndexin interfaceIDatabase- Overrides:
createIndexin classSQLiteDatabase- 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- Indicates whether the index should enforce uniqueness.
-