Class SQLCache

java.lang.Object
redempt.redlib.sql.SQLCache

public class SQLCache extends Object
A cache to store the values in a single column of a single SQL table
  • Constructor Details

  • Method Details

    • getTableName

      public String getTableName()
      Returns:
      The name of the table this SQLCache is for
    • getColumnName

      public String getColumnName()
      Returns:
      The name of the column this SQLCache is for
    • getPrimaryKeyNames

      public String[] getPrimaryKeyNames()
      Returns:
      The names of the primary keys used to access and mutate the column this SQLCache is for
    • keyNamesMatch

      protected boolean keyNamesMatch(String[] matches)
    • delete

      public void delete(Object... primaryKeys)
      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

      public void remove(Object... primaryKeys)
      Removes a cached value, but does not affect the table
      Parameters:
      primaryKeys - The keys used to access the value
    • update

      public void update(Object value, Object... primaryKeys)
      Updates the cached value for a row
      Parameters:
      value - The value to cache
      primaryKeys - The primary keys used to mutate the row
    • select

      public <T> T select(Object... primaryKeys)
      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

      public String selectString(Object... primaryKeys)
      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

      public Long selectLong(Object... primaryKeys)
      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

      public boolean isCached(Object... primaryKeys)
      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 through update(Object, Object...) will be committed!
    • flush

      public void flush()
      Flushes the cache, saving all changes that were made.
    • flush

      public void flush(Object... primaryKeys)
      Flushes a single value from the cache, saving changes that were made to it
      Parameters:
      primaryKeys - The primary keys used to access the row