Class JDBCStatementCache.BoundedLinkedHashMap

All Implemented Interfaces:
Serializable, Cloneable, Map<StatementKey,PreparedStatement>, SequencedMap<StatementKey,PreparedStatement>
Enclosing class:
JDBCStatementCache

private static class JDBCStatementCache.BoundedLinkedHashMap extends LinkedHashMap<StatementKey,PreparedStatement>
A LinkedHashMap with an upper bound on the number of entries.

If the maximum size is exceeded, the oldest entry is automatically removed after the new entry has been inserted.

  • Field Details

    • maxSize

      private final int maxSize
      Maximum number of entries.
  • Constructor Details

    • BoundedLinkedHashMap

      public BoundedLinkedHashMap(int maxCapacity)
      Creates a bounded LinkedHashMap with the specified maximum size.

      Iteration is by insertion-order.

      Parameters:
      maxCapacity - maximum size of the map
  • Method Details

    • removeEldestEntry

      protected boolean removeEldestEntry(Map.Entry<StatementKey,PreparedStatement> eldest)
      Tells if an entry should be removed from the map.

      If the cache has exceeded its maximum size, the oldest element will be marked for removal. The oldest element will be removed after the new element has been inserted.

      Overrides:
      removeEldestEntry in class LinkedHashMap<StatementKey,PreparedStatement>
      Parameters:
      eldest - the element picked out for removal
      Returns:
      true if the element is to be removed, false if not.