Class TableCacheTable<K extends Comparable<? super K>,R extends Row<K,?>>

java.lang.Object
com.aoapps.dao.base.AbstractTable<K,R>
com.aoapps.dao.base.TableCacheTable<K,R>
All Implemented Interfaces:
Table<K,R>, Iterable<R>, Collection<R>

public abstract class TableCacheTable<K extends Comparable<? super K>,R extends Row<K,?>> extends AbstractTable<K,R>
Caches results by querying the entire table upon first use. The cache is per-request and per-user.
  1. All rows are loaded and stored unsorted
  2. allRowsLoaded is called, given unsorted rows
  3. Map is built upon first call to get(K)
  4. Rows are sorted upon first call to getRows
  • Field Details

    • unsortedRowsCache

      protected final ThreadLocal<Set<? extends R extends Row<K,?>>> unsortedRowsCache
  • Constructor Details

    • TableCacheTable

      protected TableCacheTable(Class<K> keyClass, Class<R> rowClass, Model model)
  • Method Details

    • clearCaches

      public void clearCaches()
      Clears all caches for the current thread.
    • tableUpdated

      public void tableUpdated()
      When the table is updated, all caches are cleared for the current thread.
    • getUnsortedRows

      public Set<? extends R> getUnsortedRows() throws SQLException
      Throws:
      SQLException
    • allRowsLoaded

      protected void allRowsLoaded(Set<? extends R> rows) throws SQLException
      Called when all rows have been loaded at once. This allows for subclasses to populate any views or caches.

      This default implementation does nothing.

      Throws:
      SQLException
    • getRows

      public SortedSet<? extends R> getRows() throws SQLException
      Throws:
      SQLException
    • get

      public R get(K key) throws NoRowException, SQLException
      Throws:
      NoRowException
      SQLException
    • getRowsNoCache

      protected abstract Set<? extends R> getRowsNoCache() throws SQLException
      Throws:
      SQLException