org.hsqldb
Class Cache

java.lang.Object
  |
  +--org.hsqldb.Cache

class Cache
extends java.lang.Object

Cache class declaration

The cache class implements the handling of cached tables.

See Also:
Row, CacheFree

Constructor Summary
(package private) Cache(java.lang.String name)
          Cache constructor declaration
 
Method Summary
(package private)  void add(Row r)
          add method declaration
(package private)  void cleanUp()
          cleanUp method declaration
(package private)  void flush()
          flush method declaration
(package private)  void free(Row r, int pos, int length)
          free method declaration
(package private)  Row getRow(int pos, Table t)
          getRow method declaration
(package private)  void open(boolean readonly)
          open method declaration
(package private)  void shutdown()
          shutdown method declaration
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

Cache(java.lang.String name)
Cache constructor declaration

The cache constructor sets up the initial parameters of the cache object, setting the name used for the file, etc.

Parameters:
name - of database file
Method Detail

open

void open(boolean readonly)
    throws java.sql.SQLException
open method declaration

The open method creates or opens a database file.

Parameters:
flag - that indicates if this cache is readonly
Throws:
java.sql.SQLException -  

flush

void flush()
     throws java.sql.SQLException
flush method declaration

The flush method saves all cached data to the file, saves the free position and closes the file.

Throws:
java.sql.SQLException -  

shutdown

void shutdown()
        throws java.sql.SQLException
shutdown method declaration

the shutdown method closes the cache file. It does not flush pending writes.

Throws:
java.sql.SQLException -  

free

void free(Row r,
          int pos,
          int length)
    throws java.sql.SQLException
free method declaration

This method marks space in the database file as free.

Note: If more than MAX_FREE_COUNT free positios then they are probably all are too small anyway; so we start a new list

todo: This is wrong when deleting lots of records

Parameters:
r - (Row object to be marked free)
pos - (Offset in the file this Row was stored at)
length - (Size of the Row object to free)
Throws:
java.sql.SQLException -  

add

void add(Row r)
   throws java.sql.SQLException
add method declaration

This method adds a Row to the Cache. It walks the list of CacheFree objects to see if there is available space to store the new Row, reusing space if it exists, otherwise we grow the file.

Parameters:
r - (Row to be added to Cache)
Throws:
java.sql.SQLException -  

getRow

Row getRow(int pos,
           Table t)
     throws java.sql.SQLException
getRow method declaration

This method reads a Row object from the cache.

Parameters:
pos - (offset of the requested Row in the cache)
t - (Table this Row belongs to)
Returns:
The Row Object as read from the cache.
Throws:
java.sql.SQLException -  

cleanUp

void cleanUp()
       throws java.sql.SQLException
cleanUp method declaration

This method cleans up the cache when it grows too large. It works by checking Rows in held in the Cache's iLastAccess member and removing Rows that haven't been accessed in the longest time.

Throws:
java.sql.SQLException -