Package redempt.redlib.sql
Class SQLCache
java.lang.Object
redempt.redlib.sql.SQLCache
A cache to store the values in a single column of a single SQL table
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the cache.void
Deletes a row from the table by its primary keys, and removes it from the cache.void
flush()
Flushes the cache, saving all changes that were made.void
Flushes a single value from the cache, saving changes that were made to itString[]
boolean
Checks whether a value has been cached by its primary keysprotected boolean
keyNamesMatch
(String[] matches) void
Removes a cached value, but does not affect the table<T> T
Gets the cached value for a row, or queries it if it has not been cached yetselectLong
(Object... primaryKeys) Gets the cached value for a Long row, or queries it if it has not been cached yetselectString
(Object... primaryKeys) Gets the cached value for a String row, or queries it if it has not been cached yetvoid
Updates the cached value for a row
-
Constructor Details
-
SQLCache
-
-
Method Details
-
getTableName
- Returns:
- The name of the table this SQLCache is for
-
getColumnName
- Returns:
- The name of the column this SQLCache is for
-
getPrimaryKeyNames
- Returns:
- The names of the primary keys used to access and mutate the column this SQLCache is for
-
keyNamesMatch
-
delete
Deletes a row from the table by its primary keys, and removes it from the cache. This operation will always use a query.- Parameters:
primaryKeys
- The keys to use to delete the row
-
remove
Removes a cached value, but does not affect the table- Parameters:
primaryKeys
- The keys used to access the value
-
update
Updates the cached value for a row- Parameters:
value
- The value to cacheprimaryKeys
- The primary keys used to mutate the row
-
select
Gets the cached value for a row, or queries it if it has not been cached yet- Type Parameters:
T
- The type of the value- Parameters:
primaryKeys
- The primary keys used to access the row- Returns:
- The value
-
selectString
Gets the cached value for a String row, or queries it if it has not been cached yet- Parameters:
primaryKeys
- The primary keys used to access the row- Returns:
- The String value
-
selectLong
Gets the cached value for a Long row, or queries it if it has not been cached yet- Parameters:
primaryKeys
- The primary keys used to access the row- Returns:
- The Long value
-
isCached
Checks whether a value has been cached by its primary keys- Parameters:
primaryKeys
- The primary keys used to access the row- Returns:
- Whether the value has been cached
-
clear
public void clear()Clears the cache. WARNING: This will revert all changes that have not been flushed! No updates performed throughupdate(Object, Object...)
will be committed! -
flush
public void flush()Flushes the cache, saving all changes that were made. -
flush
Flushes a single value from the cache, saving changes that were made to it- Parameters:
primaryKeys
- The primary keys used to access the row
-