org.axiondb.engine.tables
Class BaseDiskTable

java.lang.Object
  extended by org.axiondb.event.BaseTableModificationPublisher
      extended by org.axiondb.engine.tables.BaseTable
          extended by org.axiondb.engine.tables.BaseDiskTable
All Implemented Interfaces:
RowSource, Table
Direct Known Subclasses:
BaseFlatfileTable, DiskTable

public abstract class BaseDiskTable
extends BaseTable
implements Table

Abstract base disk-resident implementation of Table. BaseDiskTable manages the column meta-data for a disk-based table.

Version:
$Revision: 1.9 $ $Date: 2004/09/09 23:47:44 $

Field Summary
protected  File _dataFile
          The name of my ".data" file.
protected  File _dbdir
           
protected  org.apache.commons.collections.primitives.IntList _freeIds
          List of free ids.
protected  String _freeIdsFileName
          The name of my ".frid" file.
protected  int _modCount
           
protected  org.apache.commons.collections.primitives.LongList _pidx
          List of offsets into the .data file, by row id.
protected  String _pidxFileName
           
protected  int _rowCount
           
protected static long INVALID_OFFSET
           
 
Fields inherited from interface org.axiondb.Table
REGULAR_TABLE_TYPE, SYSTEM_TABLE_TYPE
 
Constructor Summary
BaseDiskTable(String name, Database db, TableFactory factory)
           
 
Method Summary
 void addColumn(Column col)
          Add the given Columnto this table.
 void addColumn(Column col, boolean metaUpdateNeeded)
           
 void addConstraint(Constraint constraint)
           
protected  void appendLongFile(String file, long value)
          Appends a long value to a file.
protected  void appendLongFile(String file, org.apache.commons.collections.primitives.LongList value)
          Appends several long values to a file.
 void applyDeletes(org.apache.commons.collections.primitives.IntCollection rowIds)
          Remove the specified rows from this table and any associated indices.
 void applyInserts(Collection rows)
          Insert the given rows into this table and any associated indices.
protected abstract  void applyInserts(Iterator rows)
           
 void applyUpdates(Collection rows)
          Update the given rows in this table and any associated indices.
protected abstract  void applyUpdates(Iterator rows)
           
protected  void clearDataFileReference()
           
protected  void clearMetaFileReference()
           
protected  void closeFiles()
           
protected  void createOrLoadDataFile()
           
protected  void createOrLoadFreeIdsFile()
           
protected  void createOrLoadMetaFile()
           
protected  void createOrLoadPidxFile()
           
protected  boolean deleteFile(File file)
           
 void drop()
          Drop this table from the database.
 void freeRowId(int id)
          Un-reserve a row id.
protected  String getCanonicalPath(File file)
           
protected abstract  File getDataFile()
           
protected  String getDefaultDataFileExtension()
           
protected abstract  File getLobDir()
           
protected  File getMetaFile()
           
 int getNextRowId()
          Reserve a row id.
protected  RandomAccessFile getReadFile()
           
protected  File getRootDir()
           
 Row getRow(int id)
           
protected abstract  Row getRowByOffset(int idToAssign, long ptr)
           
 int getRowCount()
          Return the number of Rows I contain.
protected  File getTableFile(String extension)
           
protected  RandomAccessFile getWriteFile()
           
protected  void initFiles(File basedir, boolean datafilesonly)
           
protected  void initializeRowCount()
           
protected  RandomAccessFile openFile(File file, boolean writable)
           
protected  org.apache.commons.collections.primitives.IntList parseIntFile(File file)
          Reads a list of int values from a file.
protected  void parseMetaFile(File file)
           
protected  void parseTableProperties(ObjectInputStream in)
           
 void populateIndex(Index index)
          Populate an Index, adding my current rows to it.
protected abstract  void reloadDataFile()
           
 void remount(File newdir, boolean datafilesonly)
          Notify this table that its disk-location has moved.
 void removeIndex(Index index)
          Remove an index, both from the indices and as a TableModificationListener
 void rename(String oldName, String newName)
           
protected  void renameFile(File dir, String old, String name, String ext)
           
protected  void renameTableFiles(String oldName, String name)
           
protected  void saveIndices()
           
protected  void saveIndicesAfterTruncate()
           
protected  void setPidx(int rowid, long dataFileOffset)
           
 void shutdown()
          The database is shutting down, shutdown this table also.
 void truncate()
          Unconditionally delete all rows in this table.
protected  void tryToRemove(Iterator iter)
           
protected  void updateLongFile(RandomAccessFile pidxFile, long pidxFileOffset, long dataFileoffset)
          Updates a long value to a file.
protected  void writeFridFile()
           
protected  void writeIntFile(String file, org.apache.commons.collections.primitives.IntList list)
          Writes a list of int values to a file.
protected  void writeLongFile(String file, org.apache.commons.collections.primitives.LongList list)
          Writes a list of long values to a file.
protected  void writeMetaFile(File file)
           
protected  void writeNameToFile(File file, Object obj)
           
protected  void writePidxFile()
           
protected  void writeTableProperties(ObjectOutputStream out)
           
 
Methods inherited from class org.axiondb.engine.tables.BaseTable
addIndex, addRow, applyDeletesToIndices, applyInsertsToIndices, applyUpdatesToIndices, checkConstraints, checkConstraints, deleteRow, getColumn, getColumn, getColumnCount, getColumnIdentifiers, getColumnIndex, getConstraints, getIndexedRows, getIndexForColumn, getIndices, getMatchingRows, getName, getRowIterator, getRowIterator, getType, hasColumn, hasDeferredConstraint, hasIndex, isColumnIndexed, isPrimaryKeyConstraintExists, isUniqueConstraintExists, makeRowDecorator, makeTransactableTable, notifyColumnsOfNewLobDir, readColumns, readConstraints, removeConstraint, setName, setType, toString, truncateIndices, updateRow, writeColumns, writeConstraints
 
Methods inherited from class org.axiondb.event.BaseTableModificationPublisher
addTableModificationListener, getTableModificationListeners, publishEvent, removeTableModificationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.axiondb.Table
addIndex, addRow, addTableModificationListener, getColumn, getColumn, getColumnCount, getColumnIdentifiers, getColumnIndex, getConstraints, getIndexedRows, getIndexForColumn, getIndices, getMatchingRows, getName, getRowIterator, getType, hasColumn, hasIndex, isColumnIndexed, isPrimaryKeyConstraintExists, isUniqueConstraintExists, makeRowDecorator, makeTransactableTable, removeConstraint, removeTableModificationListener, updateRow
 

Field Detail

INVALID_OFFSET

protected static final long INVALID_OFFSET
See Also:
Constant Field Values

_dataFile

protected File _dataFile
The name of my ".data" file.


_dbdir

protected File _dbdir

_freeIds

protected org.apache.commons.collections.primitives.IntList _freeIds
List of free ids.


_freeIdsFileName

protected String _freeIdsFileName
The name of my ".frid" file.


_modCount

protected int _modCount

_pidx

protected org.apache.commons.collections.primitives.LongList _pidx
List of offsets into the .data file, by row id.


_pidxFileName

protected String _pidxFileName

_rowCount

protected int _rowCount
Constructor Detail

BaseDiskTable

public BaseDiskTable(String name,
                     Database db,
                     TableFactory factory)
              throws AxionException
Throws:
AxionException
Method Detail

applyInserts

protected abstract void applyInserts(Iterator rows)
                              throws AxionException
Throws:
AxionException

applyUpdates

protected abstract void applyUpdates(Iterator rows)
                              throws AxionException
Throws:
AxionException

getDataFile

protected abstract File getDataFile()

getLobDir

protected abstract File getLobDir()

getRowByOffset

protected abstract Row getRowByOffset(int idToAssign,
                                      long ptr)
                               throws AxionException
Throws:
AxionException

reloadDataFile

protected abstract void reloadDataFile()
                                throws AxionException
Throws:
AxionException

addColumn

public void addColumn(Column col)
               throws AxionException
Description copied from class: BaseTable
Add the given Columnto this table. This implementation throws an AxionExceptionif rows have already been added to the table.

Specified by:
addColumn in interface Table
Overrides:
addColumn in class BaseTable
Throws:
AxionException

addColumn

public void addColumn(Column col,
                      boolean metaUpdateNeeded)
               throws AxionException
Throws:
AxionException

addConstraint

public void addConstraint(Constraint constraint)
                   throws AxionException
Specified by:
addConstraint in interface Table
Overrides:
addConstraint in class BaseTable
Throws:
AxionException

applyDeletes

public void applyDeletes(org.apache.commons.collections.primitives.IntCollection rowIds)
                  throws AxionException
Description copied from interface: Table
Remove the specified rows from this table and any associated indices. This process is allowed to be destructive, the table my delete values from the given list.

Specified by:
applyDeletes in interface Table
Specified by:
applyDeletes in class BaseTable
Throws:
AxionException

applyInserts

public void applyInserts(Collection rows)
                  throws AxionException
Description copied from interface: Table
Insert the given rows into this table and any associated indices. This process is allowed to be destructive, the table my delete rows from the given list.

Specified by:
applyInserts in interface Table
Specified by:
applyInserts in class BaseTable
Parameters:
rows - a collection of Rows
Throws:
AxionException

applyUpdates

public void applyUpdates(Collection rows)
                  throws AxionException
Description copied from interface: Table
Update the given rows in this table and any associated indices. This process is allowed to be destructive, the table my delete rows from the given list.

Specified by:
applyUpdates in interface Table
Specified by:
applyUpdates in class BaseTable
Throws:
AxionException

drop

public void drop()
          throws AxionException
Description copied from interface: Table
Drop this table from the database.

Specified by:
drop in interface Table
Overrides:
drop in class BaseTable
Throws:
AxionException

freeRowId

public void freeRowId(int id)
Description copied from interface: Table
Un-reserve a row id.

Specified by:
freeRowId in interface Table
Specified by:
freeRowId in class BaseTable

getNextRowId

public int getNextRowId()
Description copied from interface: Table
Reserve a row id.

Specified by:
getNextRowId in interface Table
Specified by:
getNextRowId in class BaseTable

getRow

public Row getRow(int id)
           throws AxionException
Specified by:
getRow in interface RowSource
Specified by:
getRow in class BaseTable
Throws:
AxionException

getRowCount

public int getRowCount()
Description copied from interface: Table
Return the number of Rows I contain.

Specified by:
getRowCount in interface Table
Specified by:
getRowCount in class BaseTable

populateIndex

public void populateIndex(Index index)
                   throws AxionException
Description copied from interface: Table
Populate an Index, adding my current rows to it. Does not addthe index.

Specified by:
populateIndex in interface Table
Specified by:
populateIndex in class BaseTable
Throws:
AxionException
See Also:
Table.addIndex(org.axiondb.Index)

remount

public void remount(File newdir,
                    boolean datafilesonly)
             throws AxionException
Description copied from interface: Table
Notify this table that its disk-location has moved.

Specified by:
remount in interface Table
Overrides:
remount in class BaseTable
Throws:
AxionException

removeIndex

public void removeIndex(Index index)
                 throws AxionException
Description copied from interface: Table
Remove an index, both from the indices and as a TableModificationListener

Specified by:
removeIndex in interface Table
Overrides:
removeIndex in class BaseTable
Throws:
AxionException

rename

public void rename(String oldName,
                   String newName)
            throws AxionException
Specified by:
rename in interface Table
Overrides:
rename in class BaseTable
Throws:
AxionException

truncate

public void truncate()
              throws AxionException
Description copied from interface: Table
Unconditionally delete all rows in this table.

Specified by:
truncate in interface Table
Throws:
AxionException

shutdown

public void shutdown()
              throws AxionException
Description copied from interface: Table
The database is shutting down, shutdown this table also.

Specified by:
shutdown in interface Table
Overrides:
shutdown in class BaseTable
Throws:
AxionException

appendLongFile

protected void appendLongFile(String file,
                              long value)
                       throws AxionException
Appends a long value to a file.

Parameters:
file - the Fileto append to
value - the value to write
Throws:
AxionException

appendLongFile

protected void appendLongFile(String file,
                              org.apache.commons.collections.primitives.LongList value)
                       throws AxionException
Appends several long values to a file.

Parameters:
file - the Fileto append to
values - the values to write
Throws:
AxionException

updateLongFile

protected void updateLongFile(RandomAccessFile pidxFile,
                              long pidxFileOffset,
                              long dataFileoffset)
                       throws AxionException
Updates a long value to a file.

Parameters:
file - the Fileto append to
pidxFileOffset - the pidx file offset to write
dataFileoffset - data file pointer for a given pidx offset
Throws:
AxionException

clearDataFileReference

protected void clearDataFileReference()

closeFiles

protected void closeFiles()

getDefaultDataFileExtension

protected String getDefaultDataFileExtension()

createOrLoadFreeIdsFile

protected void createOrLoadFreeIdsFile()
                                throws AxionException
Throws:
AxionException

createOrLoadMetaFile

protected void createOrLoadMetaFile()
                             throws AxionException
Throws:
AxionException

createOrLoadDataFile

protected void createOrLoadDataFile()
                             throws AxionException
Throws:
AxionException

createOrLoadPidxFile

protected void createOrLoadPidxFile()
                             throws AxionException
Throws:
AxionException

deleteFile

protected boolean deleteFile(File file)

getCanonicalPath

protected String getCanonicalPath(File file)
                           throws AxionException
Throws:
AxionException

getMetaFile

protected File getMetaFile()

getReadFile

protected RandomAccessFile getReadFile()
                                throws AxionException
Throws:
AxionException

getRootDir

protected File getRootDir()

getTableFile

protected File getTableFile(String extension)

getWriteFile

protected RandomAccessFile getWriteFile()
                                 throws AxionException
Throws:
AxionException

openFile

protected RandomAccessFile openFile(File file,
                                    boolean writable)
                             throws AxionException
Throws:
AxionException

initFiles

protected void initFiles(File basedir,
                         boolean datafilesonly)
                  throws AxionException
Throws:
AxionException

initializeRowCount

protected void initializeRowCount()

parseIntFile

protected org.apache.commons.collections.primitives.IntList parseIntFile(File file)
                                                                  throws AxionException
Reads a list of int values from a file.

Parameters:
file - the Fileto read from
Throws:
AxionException

parseMetaFile

protected void parseMetaFile(File file)
                      throws AxionException
Throws:
AxionException

parseTableProperties

protected void parseTableProperties(ObjectInputStream in)
                             throws AxionException
Throws:
AxionException

saveIndices

protected void saveIndices()
                    throws AxionException
Throws:
AxionException

saveIndicesAfterTruncate

protected void saveIndicesAfterTruncate()
                                 throws AxionException
Throws:
AxionException

tryToRemove

protected void tryToRemove(Iterator iter)

writeFridFile

protected final void writeFridFile()
                            throws AxionException
Throws:
AxionException

writeIntFile

protected void writeIntFile(String file,
                            org.apache.commons.collections.primitives.IntList list)
                     throws AxionException
Writes a list of int values to a file.

Parameters:
file - the Fileto write to
Throws:
AxionException

writeLongFile

protected void writeLongFile(String file,
                             org.apache.commons.collections.primitives.LongList list)
                      throws AxionException
Writes a list of long values to a file.

Parameters:
file - the Fileto write to
Throws:
AxionException

writeMetaFile

protected void writeMetaFile(File file)
                      throws AxionException
Throws:
AxionException

writeNameToFile

protected void writeNameToFile(File file,
                               Object obj)
                        throws AxionException
Throws:
AxionException

writePidxFile

protected final void writePidxFile()
                            throws AxionException
Throws:
AxionException

writeTableProperties

protected void writeTableProperties(ObjectOutputStream out)
                             throws AxionException
Throws:
AxionException

setPidx

protected void setPidx(int rowid,
                       long dataFileOffset)

clearMetaFileReference

protected void clearMetaFileReference()

renameTableFiles

protected void renameTableFiles(String oldName,
                                String name)

renameFile

protected void renameFile(File dir,
                          String old,
                          String name,
                          String ext)