org.axiondb.engine.tables
Class ExternalDatabaseTable

java.lang.Object
  extended by org.axiondb.engine.tables.ExternalDatabaseTable
All Implemented Interfaces:
ExternalTable, RowSource, Table, Transactable, TransactableTable

public class ExternalDatabaseTable
extends Object
implements ExternalTable, TransactableTable

Base implementation of ExternalTable interface.

Example: create external table emp (lname varchar(80), sid integer(6), fname varchar(80), id integer(6) not null, dob timestamp(6)) organization (loadtype='remote' SERVER='myserver' REMOTETABLE='mytablename' SCHEMA='myschema' WHERE='id > 1000');

Note : We have tested this for Oracle 8i/9i/10g , SQL Server, Sybase and DB2.

Version:
$Revision: 1.27 $ $Date: 2006/01/10 21:02:36 $
See Also:
DatabaseLink

Field Summary
 
Fields inherited from interface org.axiondb.ExternalTable
COLUMNS_ARE_CASE_SENSITIVE, DELIMITED_TABLE_TYPE, EXTERNAL_DB_TABLE_TYPE, FW_TABLE_TYPE, PROP_CATALOG, PROP_CREATE_IF_NOT_EXIST, PROP_DB, PROP_LOADTYPE, PROP_ORDERBY, PROP_REMOTETABLE, PROP_SCHEMA, PROP_VENDOR, PROP_WHERE, TAGGED_EBCDIC_TABLE_TYPE
 
Fields inherited from interface org.axiondb.Table
REGULAR_TABLE_TYPE, SYSTEM_TABLE_TYPE
 
Constructor Summary
ExternalDatabaseTable(String name, Database db)
           
 
Method Summary
 void addColumn(Column col)
          Add the given Columnto this table.
 void addConstraint(Constraint constraint)
           
 void addConstraint(Constraint constraint, boolean checkExistingRows)
           
 void addIndex(Index index)
          Add an index, associating it with a Column, and adding it as a org.axiondb.TableModificationListenerto the table.
 void addRow(Row row)
          Insert the given Row.
 void addTableModificationListener(TableModificationListener listener)
          Adds a listener to receive events on this table
 void apply()
          Apply this committedtransaction..
 void applyDeletes(org.apache.commons.collections.primitives.IntCollection rowIds)
          Remove the specified rows from this table and any associated indices.
 void applyInserts(RowCollection rows)
          Insert the given rows into this table and any associated indices.
 void applyUpdates(RowCollection rows)
          Update the given rows in this table and any associated indices.
protected  void checkConstraints(RowEvent event)
           
 void checkpoint()
           
 void commit()
          This transaction has been committed.
 void deleteRow(Row row)
          Delete the given Row.
 void drop()
          Drop this table from the database.
 void freeRowId(int id)
          Un-reserve a row id.
 Column getColumn(int index)
          Return the Columncorresponding to the given zero-based index .
 Column getColumn(String name)
          Return the Columnfor the given name .
 int getColumnCount()
          Return the number of Columns I contain.
 List getColumnIdentifiers()
          Return an readonly Listover the ColumnIdentifiersfor my Columns.
 int getColumnIndex(String name)
          Return the zero-based index of the Columnwith the given name .
 Constraint getConstraint(String name)
           
 Iterator getConstraints()
           
 String getDBLinkName()
           
protected  String getDeleteSQL()
           
 RowIterator getIndexedRows(RowSource source, Selectable node, boolean readOnly)
           
 RowIterator getIndexedRows(Selectable node, boolean readOnly)
           
 Index getIndexForColumn(Column column)
          Return the first Indexthat pertains to the given Column, or null if no such Indexexists.
 Iterator getIndices()
          Obtain an Iteratorover my indices.
protected  String getInsertSQL()
           
 RowIterator getMatchingRows(List selectables, List values, boolean readOnly)
          Obtain an iteratorover my Rows where each Selectablein the selectable list evaluatesto the corresponding value in the value list.
 String getName()
          Get the name of this table.
 int getNextRowId()
          Reserve a row id.
 Row getRow(int id)
           
 int getRowCount()
          Return the number of Rows I contain.
protected  RowIterator getRowIterator()
           
 RowIterator getRowIterator(boolean readOnly)
          Obtain an iteratorover my Rows.
protected  String getSchemaWildcardForRemoteDB()
          Gets appropriate string for use in indicating wildcard search for schemas.
protected  String getSelectSQL(String where)
           
 Sequence getSequence()
           
 Iterator getTableModificationListeners()
           
 Properties getTableProperties()
          Gets Organization Property.
 String getType()
          Get the type of this table.
protected  String getUpdateSQL()
           
 boolean hasColumn(ColumnIdentifier id)
          Indicate whether the ColumnIdentifierreferences a column in this table
 boolean hasIndex(String name)
           
 boolean isColumnIndexed(Column column)
          Check to see if an Indexexists for the given Column
 boolean isPrimaryKeyConstraintExists(String columnName)
          check if primary constraint exists on a column
 boolean isUniqueConstraintExists(String columnName)
          check if unique constraint exists on a column
 boolean loadExternalTable(Properties props)
          Loads external data using the given properties table - should be called only once by the table factory.
 RowDecorator makeRowDecorator()
           
 TransactableTable makeTransactableTable()
          Create a TransactableTablefor this table.
 void migrate()
          Migrate from older version to newer version for this table
 void populateIndex(Index index)
          Populate an Index, adding my current rows to it.
 void remount()
           
 void remount(File dir, boolean datafilesonly)
          Notify this table that its disk-location has moved.
 Constraint removeConstraint(String name)
           
 void removeIndex(Index index)
          Remove an index, both from the indices and as a TableModificationListener
 void removeTableModificationListener(TableModificationListener listener)
          Removes a listener so that it stops receiving events on this table
 void rename(String oldName, String newName)
           
 void rollback()
          This transaction has been aborted.
 void setDeferAllConstraints(boolean deferAll)
           
 void setSequence(Sequence seq)
           
protected  void setUp(DatabaseLink server)
           
 void shutdown()
          The database is shutting down, shutdown this table also.
 String toString()
           
 void truncate()
          Unconditionally delete all rows in this table.
 void updateRow(Row oldrow, Row newrow)
          Update the given Row.
 void updateRow(Row oldrow, Row newrow, List cols)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExternalDatabaseTable

public ExternalDatabaseTable(String name,
                             Database db)
Method Detail

addColumn

public void addColumn(Column col)
               throws AxionException
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
Throws:
AxionException

addConstraint

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

addConstraint

public void addConstraint(Constraint constraint,
                          boolean checkExistingRows)
                   throws AxionException
Throws:
AxionException

addIndex

public void addIndex(Index index)
              throws AxionException
Description copied from interface: Table
Add an index, associating it with a Column, and adding it as a org.axiondb.TableModificationListenerto the table.

Specified by:
addIndex in interface Table
Throws:
AxionException
See Also:
Table.addIndex(org.axiondb.Index), Table.addTableModificationListener(org.axiondb.event.TableModificationListener), Table.getIndexForColumn(org.axiondb.Column), Table.isColumnIndexed(org.axiondb.Column), Table.populateIndex(org.axiondb.Index)

addRow

public void addRow(Row row)
            throws AxionException
Description copied from interface: Table
Insert the given Row.

Specified by:
addRow in interface Table
Throws:
AxionException

addTableModificationListener

public void addTableModificationListener(TableModificationListener listener)
Description copied from interface: Table
Adds a listener to receive events on this table

Specified by:
addTableModificationListener in interface Table

apply

public void apply()
           throws AxionException
Description copied from interface: Transactable
Apply this committedtransaction..

Specified by:
apply in interface Transactable
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
Throws:
AxionException

applyInserts

public void applyInserts(RowCollection rows)
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
Parameters:
rows - a collection of Rows

applyUpdates

public void applyUpdates(RowCollection rows)
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

checkpoint

public void checkpoint()
                throws AxionException
Specified by:
checkpoint in interface Table
Throws:
AxionException

commit

public void commit()
            throws AxionException
Description copied from interface: Transactable
This transaction has been committed.

Specified by:
commit in interface Transactable
Throws:
AxionException

deleteRow

public void deleteRow(Row row)
               throws AxionException
Description copied from interface: Table
Delete the given Row.

Specified by:
deleteRow in interface Table
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
Throws:
AxionException

freeRowId

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

Specified by:
freeRowId in interface Table

getColumn

public final Column getColumn(int index)
Description copied from interface: Table
Return the Columncorresponding to the given zero-based index .

Specified by:
getColumn in interface Table

getColumn

public Column getColumn(String name)
Description copied from interface: Table
Return the Columnfor the given name .

Specified by:
getColumn in interface Table

getColumnCount

public final int getColumnCount()
Description copied from interface: Table
Return the number of Columns I contain.

Specified by:
getColumnCount in interface RowSource
Specified by:
getColumnCount in interface Table

getColumnIdentifiers

public List getColumnIdentifiers()
Description copied from interface: Table
Return an readonly Listover the ColumnIdentifiersfor my Columns.

Specified by:
getColumnIdentifiers in interface Table

getColumnIndex

public int getColumnIndex(String name)
                   throws AxionException
Description copied from interface: Table
Return the zero-based index of the Columnwith the given name .

Specified by:
getColumnIndex in interface RowSource
Specified by:
getColumnIndex in interface Table
Throws:
AxionException

getConstraint

public final Constraint getConstraint(String name)
Specified by:
getConstraint in interface Table

getConstraints

public Iterator getConstraints()
Specified by:
getConstraints in interface Table

getDBLinkName

public String getDBLinkName()

getIndexedRows

public RowIterator getIndexedRows(RowSource source,
                                  Selectable node,
                                  boolean readOnly)
                           throws AxionException
Specified by:
getIndexedRows in interface Table
Throws:
AxionException

getIndexedRows

public RowIterator getIndexedRows(Selectable node,
                                  boolean readOnly)
                           throws AxionException
Specified by:
getIndexedRows in interface Table
readOnly - when true, the caller does not expect to be able to modify (i.e., call RowIterator.set(org.axiondb.Row)or RowIterator.remove()on) the returned RowIterator, the returned iterator may be unmodifiable.
Throws:
AxionException

getIndexForColumn

public Index getIndexForColumn(Column column)
Description copied from interface: Table
Return the first Indexthat pertains to the given Column, or null if no such Indexexists.

Specified by:
getIndexForColumn in interface Table
Returns:
the pertinent Column, or null if no such Indexexists

getIndices

public Iterator getIndices()
Description copied from interface: Table
Obtain an Iteratorover my indices.

Specified by:
getIndices in interface Table

getMatchingRows

public RowIterator getMatchingRows(List selectables,
                                   List values,
                                   boolean readOnly)
                            throws AxionException
Description copied from interface: Table
Obtain an iteratorover my Rows where each Selectablein the selectable list evaluatesto the corresponding value in the value list.

This is functionally similiar to executing a SELECT over this table where selectable[i] = value[i] for each value of i . The return RowIterator is not modifiable.

Specified by:
getMatchingRows in interface Table
Throws:
AxionException

getName

public final String getName()
Description copied from interface: Table
Get the name of this table.

Specified by:
getName in interface Table

getNextRowId

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

Specified by:
getNextRowId in interface Table

getRow

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

getRowCount

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

Specified by:
getRowCount in interface Table

getRowIterator

public RowIterator getRowIterator(boolean readOnly)
                           throws AxionException
Description copied from interface: Table
Obtain an iteratorover my Rows.

Specified by:
getRowIterator in interface Table
Parameters:
readOnly - when true, the caller does not expect to be able to modify (i.e., call RowIterator.set(org.axiondb.Row)or RowIterator.remove()on) the returned RowIterator, the returned iterator may be unmodifiable.
Throws:
AxionException

getSequence

public final Sequence getSequence()
Specified by:
getSequence in interface Table

getTableModificationListeners

public Iterator getTableModificationListeners()
Specified by:
getTableModificationListeners in interface Table

getTableProperties

public Properties getTableProperties()
Description copied from interface: ExternalTable
Gets Organization Property.

Specified by:
getTableProperties in interface ExternalTable
Returns:
Set of organization property key names;

getType

public final String getType()
Description copied from interface: Table
Get the type of this table.

Specified by:
getType in interface Table

hasColumn

public boolean hasColumn(ColumnIdentifier id)
Description copied from interface: Table
Indicate whether the ColumnIdentifierreferences a column in this table

Specified by:
hasColumn in interface Table

hasIndex

public boolean hasIndex(String name)
Specified by:
hasIndex in interface Table

isColumnIndexed

public boolean isColumnIndexed(Column column)
Description copied from interface: Table
Check to see if an Indexexists for the given Column

Specified by:
isColumnIndexed in interface Table
Parameters:
column - Columnto check
Returns:
true iff there is an existing Indexfor the given Column

isPrimaryKeyConstraintExists

public boolean isPrimaryKeyConstraintExists(String columnName)
Description copied from interface: Table
check if primary constraint exists on a column

Specified by:
isPrimaryKeyConstraintExists in interface Table
Returns:
if PrimaryKeyConstraint exists on the column

isUniqueConstraintExists

public boolean isUniqueConstraintExists(String columnName)
check if unique constraint exists on a column

Specified by:
isUniqueConstraintExists in interface Table
Parameters:
columnName - name of the column
Returns:
true if uniqueConstraint exists on the column

loadExternalTable

public boolean loadExternalTable(Properties props)
                          throws AxionException
Description copied from interface: ExternalTable
Loads external data using the given properties table - should be called only once by the table factory.

Specified by:
loadExternalTable in interface ExternalTable
Parameters:
props - configuration properties for this external table
Throws:
AxionException

makeRowDecorator

public RowDecorator makeRowDecorator()
Specified by:
makeRowDecorator in interface RowSource
Specified by:
makeRowDecorator in interface Table

makeTransactableTable

public TransactableTable makeTransactableTable()
Description copied from interface: Table
Create a TransactableTablefor this table.

Specified by:
makeTransactableTable in interface Table

migrate

public void migrate()
             throws AxionException
Description copied from interface: Table
Migrate from older version to newer version for this table

Specified by:
migrate in interface Table
Throws:
AxionException

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
Throws:
AxionException
See Also:
Table.addIndex(org.axiondb.Index)

remount

public void remount()
             throws AxionException
Specified by:
remount in interface ExternalTable
Throws:
AxionException

remount

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

Specified by:
remount in interface Table
Throws:
AxionException

removeConstraint

public Constraint removeConstraint(String name)
Specified by:
removeConstraint in interface Table

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
Throws:
AxionException

removeTableModificationListener

public void removeTableModificationListener(TableModificationListener listener)
Description copied from interface: Table
Removes a listener so that it stops receiving events on this table

Specified by:
removeTableModificationListener in interface Table

rename

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

rollback

public void rollback()
              throws AxionException
Description copied from interface: Transactable
This transaction has been aborted.

Specified by:
rollback in interface Transactable
Throws:
AxionException

setDeferAllConstraints

public void setDeferAllConstraints(boolean deferAll)
Specified by:
setDeferAllConstraints in interface Table

setSequence

public void setSequence(Sequence seq)
                 throws AxionException
Specified by:
setSequence 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
Throws:
AxionException

toString

public String toString()
Overrides:
toString in class Object

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

updateRow

public void updateRow(Row oldrow,
                      Row newrow)
               throws AxionException
Description copied from interface: Table
Update the given Row.

Specified by:
updateRow in interface Table
Throws:
AxionException

updateRow

public void updateRow(Row oldrow,
                      Row newrow,
                      List cols)
               throws AxionException
Throws:
AxionException

checkConstraints

protected void checkConstraints(RowEvent event)
                         throws AxionException
Throws:
AxionException

getDeleteSQL

protected String getDeleteSQL()

getInsertSQL

protected String getInsertSQL()

getRowIterator

protected RowIterator getRowIterator()
                              throws AxionException
Throws:
AxionException

getSchemaWildcardForRemoteDB

protected String getSchemaWildcardForRemoteDB()
Gets appropriate string for use in indicating wildcard search for schemas.

Returns:
wildcard string.

getSelectSQL

protected String getSelectSQL(String where)

getUpdateSQL

protected String getUpdateSQL()

setUp

protected void setUp(DatabaseLink server)
              throws AxionException
Throws:
AxionException