org.axiondb.engine.tables
Class ExternalDatabaseTable

java.lang.Object
  extended byorg.axiondb.event.BaseTableModificationPublisher
      extended byorg.axiondb.engine.tables.BaseTable
          extended byorg.axiondb.engine.tables.ExternalDatabaseTable
All Implemented Interfaces:
ExternalTable, RowSource, Table, Transactable, TransactableTable

public class ExternalDatabaseTable
extends BaseTable
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' ORDERBY='id' WHERE='id > 1000');

Note : We have tested this for Oracle 8i/9i , SQL Server, Sybase.
If you use WHERE, ORDER BY it is almost similar to creating a remote view, and you will not be able to update it. We use Scrollable ResultSet to perform Insert/Update/Delete operations, which may have some perfermance concern depending on the data size.

TODO: Use prepare statement for update and insert

TODO: Use Vendor specific code for truncate, table exists check, escape id

TODO: Support remote table drop, create/drop index, create/drop constraint

DROP DATABASE LINK should de-link the table and drop table should drop table on remote as well as local

Version:
$Revision: 1.2 $ $Date: 2004/09/09 23:47:44 $
See Also:
DatabaseLink

Field Summary
static String PROP_CATALOG
          Property key name for catalog name
static String PROP_DB
          Property key name for database link
static String PROP_ORDERBY
          Property key name for where filter
static String PROP_REMOTETABLE
          Property key name for remote table name
static String PROP_SCHEMA
          Property key name for schema name
static String PROP_WHERE
          Property key name for where filter
 
Fields inherited from interface org.axiondb.ExternalTable
DELIMITED_TABLE_TYPE, EXTERNAL_DB_TABLE_TYPE, FW_TABLE_TYPE, PROP_LOADTYPE, 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 addConstraint(Constraint constraint)
           
 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(Collection rows)
          Insert the given rows into this table and any associated indices.
 void applyUpdates(Collection rows)
          Update the given rows in this table and any associated indices.
protected  void assertConnection()
           
protected  void assertExternalResultSet()
           
protected  void assertUpdatable()
           
protected  void checkConstraints(RowEvent event)
           
 void commit()
          This transaction has been committed.
protected  void createOrLoadResultSet(boolean unconditionally)
           
protected  void createRemoteTableIfNotExists()
           
protected  void createResultSet()
           
 void drop()
          Drop this table from the database.
 void freeRowId(int id)
          Un-reserve a row id.
protected  String getCreateSQL()
           
protected  String getInsertSQL()
           
 int getNextRowId()
          Reserve a row id.
 Row getRow(int id)
           
protected  Row getRowByOffset(int rowId)
           
 int getRowCount()
          Return the number of Rows I contain.
protected  RowIterator getRowIterator()
           
protected  String getSelectSQL(String where, List orderByColumns)
           
 Properties getTableProperties()
          Gets Organization Property.
 TransactableTable makeTransactableTable()
          Create a TransactableTablefor this table.
 void populateIndex(Index index)
          Populate an Index, adding my current rows to it.
 void remount()
           
 void removeConstraint(String name)
           
 void rollback()
          This transaction has been aborted.
 boolean setTableProperties(Properties props)
          Sets collection of configuration properties for this external table to the given Properties instance.
protected  void setUp(DatabaseLink server)
           
 void shutdown()
          The database is shutting down, shutdown this table also.
protected  boolean tableExistsInRemoteDB()
           
 void truncate()
          Unconditionally delete all rows in this table.
 
Methods inherited from class org.axiondb.engine.tables.BaseTable
addColumn, addIndex, addRow, applyDeletesToIndices, applyInsertsToIndices, applyUpdatesToIndices, checkConstraints, deleteRow, getColumn, getColumn, getColumnCount, getColumnIdentifiers, getColumnIndex, getConstraints, getIndexedRows, getIndexForColumn, getIndices, getMatchingRows, getName, getRowIterator, getType, hasColumn, hasDeferredConstraint, hasIndex, isColumnIndexed, isPrimaryKeyConstraintExists, isUniqueConstraintExists, makeRowDecorator, notifyColumnsOfNewLobDir, readColumns, readConstraints, remount, removeIndex, rename, 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
addColumn, addIndex, addRow, addTableModificationListener, getColumn, getColumn, getColumnCount, getColumnIdentifiers, getColumnIndex, getConstraints, getIndexedRows, getIndexForColumn, getIndices, getMatchingRows, getName, getRowIterator, getType, hasColumn, hasIndex, isColumnIndexed, isPrimaryKeyConstraintExists, isUniqueConstraintExists, makeRowDecorator, remount, removeIndex, removeTableModificationListener, rename, updateRow
 

Field Detail

PROP_CATALOG

public static final String PROP_CATALOG
Property key name for catalog name

See Also:
Constant Field Values

PROP_DB

public static final String PROP_DB
Property key name for database link

See Also:
Constant Field Values

PROP_ORDERBY

public static final String PROP_ORDERBY
Property key name for where filter

See Also:
Constant Field Values

PROP_REMOTETABLE

public static final String PROP_REMOTETABLE
Property key name for remote table name

See Also:
Constant Field Values

PROP_SCHEMA

public static final String PROP_SCHEMA
Property key name for schema name

See Also:
Constant Field Values

PROP_WHERE

public static final String PROP_WHERE
Property key name for where filter

See Also:
Constant Field Values
Constructor Detail

ExternalDatabaseTable

public ExternalDatabaseTable(String name,
                             Database db)
Method Detail

addConstraint

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

removeConstraint

public void removeConstraint(String name)
Specified by:
removeConstraint in interface Table
Overrides:
removeConstraint in class BaseTable

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
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

remount

public void remount()
             throws AxionException
Specified by:
remount in interface ExternalTable
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

setTableProperties

public boolean setTableProperties(Properties props)
                           throws AxionException
Description copied from interface: ExternalTable
Sets collection of configuration properties for this external table to the given Properties instance. This describe how the data is stored the existing data file.

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

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;

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

truncate

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

Specified by:
truncate in interface Table
Returns:
true if truncation succeeded; false otherwise
Throws:
AxionException

apply

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

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

rollback

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

Specified by:
rollback in interface Transactable
Throws:
AxionException

makeTransactableTable

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

Specified by:
makeTransactableTable in interface Table
Overrides:
makeTransactableTable in class BaseTable

assertConnection

protected void assertConnection()
                         throws AxionException
Throws:
AxionException

assertExternalResultSet

protected void assertExternalResultSet()
                                throws AxionException
Throws:
AxionException

assertUpdatable

protected void assertUpdatable()
                        throws AxionException
Throws:
AxionException

checkConstraints

protected void checkConstraints(RowEvent event)
                         throws AxionException
Overrides:
checkConstraints in class BaseTable
Throws:
AxionException

createOrLoadResultSet

protected void createOrLoadResultSet(boolean unconditionally)
                              throws AxionException
Throws:
AxionException

createRemoteTableIfNotExists

protected void createRemoteTableIfNotExists()
                                     throws AxionException
Throws:
AxionException

createResultSet

protected void createResultSet()
                        throws AxionException
Throws:
AxionException

getCreateSQL

protected String getCreateSQL()

getRowByOffset

protected Row getRowByOffset(int rowId)
                      throws AxionException
Throws:
AxionException

getRowIterator

protected RowIterator getRowIterator()
                              throws AxionException
Specified by:
getRowIterator in class BaseTable
Throws:
AxionException

getSelectSQL

protected String getSelectSQL(String where,
                              List orderByColumns)

setUp

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

tableExistsInRemoteDB

protected boolean tableExistsInRemoteDB()
                                 throws AxionException
Throws:
AxionException

getInsertSQL

protected String getInsertSQL()