Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.hsqldb
Class TextCache  view TextCache download TextCache.java

java.lang.Object
  extended byorg.hsqldb.Cache
      extended byorg.hsqldb.TextCache
Direct Known Subclasses:
ReverseTextCache

class TextCache
extends Cache

Handles operations on a DatabaseFile object and uses signle TextDdatbaseRowInput and TextDatabaseRowOutput objects to read and write rows of data to the file in text table format.

Version:
1.7.0

Nested Class Summary
private  class TextCache.TextSource
           
 
Field Summary
private  java.lang.String fs
           
protected  int iFreePos
           
protected  java.lang.String ignoredFirst
           
protected  boolean ignoreFirst
           
protected  TextDatabaseRowInput in
           
private  java.lang.String lvs
           
static java.lang.String NL
           
private  DatabaseRowOutputInterface out
           
protected  boolean readOnly
           
protected  DatabaseFile rFile
           
protected  java.lang.String sName
           
private  java.lang.String vs
           
 
Constructor Summary
(package private) TextCache(java.lang.String name, java.lang.String propPrefix, HsqlDatabaseProperties props)
          TextCache constructor declaration
 
Method Summary
(package private)  void add(CachedRow r)
          Adds a Row to the Cache.
(package private)  void cleanUp()
          Cleans up this Cache object.
(package private)  void closeFile()
          Closes this object's database file without flushing pending writes.
(package private)  void flush()
          flush method declaration
(package private)  void free(CachedRow r)
          Marks space in this object's cache file as free.
(package private)  int getFreePos()
          Getter for iFreePos member
(package private)  CachedRow getRow(int pos, Table t)
          Reads a Row object from this Cache that corresponds to the (pos) file offset in .data file.
protected  CachedRow makeRow(int pos, Table t)
          Constructs a new Row for the specified table, using row data read at the specified position (pos) in this object's database file.
(package private)  void open(boolean readonly)
          open method declaration
(package private)  void purge()
           
protected  void remove(CachedRow r)
          Removes a Row from this Cache object.
(package private)  void reopen()
           
protected  void saveAll()
          Writes out all cached Rows.
protected  void saveRow(CachedRow r)
          Writes out the specified Row.
protected  void setStorageSize(CachedRow r)
          Calculates the number of bytes required to store a Row in this object's database file.
private  java.lang.String translateSep(java.lang.String sep)
           
private  java.lang.String translateSep(java.lang.String sep, boolean isProperty)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NL

public static final java.lang.String NL

fs

private java.lang.String fs

vs

private java.lang.String vs

lvs

private java.lang.String lvs

out

private DatabaseRowOutputInterface out

readOnly

protected boolean readOnly

in

protected TextDatabaseRowInput in

ignoreFirst

protected boolean ignoreFirst

ignoredFirst

protected java.lang.String ignoredFirst

sName

protected java.lang.String sName

iFreePos

protected int iFreePos

rFile

protected DatabaseFile rFile
Constructor Detail

TextCache

TextCache(java.lang.String name,
          java.lang.String propPrefix,
          HsqlDatabaseProperties props)
    throws java.sql.SQLException
TextCache constructor declaration

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

Method Detail

translateSep

private java.lang.String translateSep(java.lang.String sep)

translateSep

private java.lang.String translateSep(java.lang.String sep,
                                      boolean isProperty)

open

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

The open method creates or opens a database file.

Overrides:
open in class Cache

reopen

void reopen()
      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.

Overrides:
flush in class Cache

purge

void purge()
     throws java.sql.SQLException

free

void free(CachedRow r)
    throws java.sql.SQLException
Description copied from class: Cache
Marks space in this object's cache file as free.

Note: If there exists more than MAX_FREE_COUNT free positions, then they are probably all too small, so we start a new list.

todo: This is wrong when deleting lots of records

Overrides:
free in class Cache

setStorageSize

protected void setStorageSize(CachedRow r)
                       throws java.sql.SQLException
Description copied from class: Cache
Calculates the number of bytes required to store a Row in this object's database file.

Overrides:
setStorageSize in class Cache

makeRow

protected CachedRow makeRow(int pos,
                            Table t)
                     throws java.sql.SQLException
Description copied from class: Cache
Constructs a new Row for the specified table, using row data read at the specified position (pos) in this object's database file.

Overrides:
makeRow in class Cache

saveRow

protected void saveRow(CachedRow r)
                throws java.io.IOException,
                       java.sql.SQLException
Description copied from class: Cache
Writes out the specified Row.

Overrides:
saveRow in class Cache

closeFile

void closeFile()
         throws java.sql.SQLException
Closes this object's database file without flushing pending writes.


add

void add(CachedRow r)
   throws java.sql.SQLException
Adds a Row to the Cache.

A Row is added by walking the list of CacheFree objects to see if there is available space to store it, reusing space if it exists. Otherwise , this object's cache file is grown to accomadate it.


getRow

CachedRow getRow(int pos,
                 Table t)
           throws java.sql.SQLException
Reads a Row object from this Cache that corresponds to the (pos) file offset in .data file.


cleanUp

void cleanUp()
       throws java.sql.SQLException
Cleans up this Cache object.

This method is called when this Cache object grows too large.

Cleanup is done by checking the iLastAccess member of this object's in-memory Rows and removing those that have been least recently accessed (classic LRU algoritm).


remove

protected void remove(CachedRow r)
               throws java.sql.SQLException
Removes a Row from this Cache object. Note: This method is called by the cleanUp method.


saveAll

protected void saveAll()
                throws java.sql.SQLException
Writes out all cached Rows.


getFreePos

int getFreePos()
Getter for iFreePos member