javatools.db
Class DbAbstractTable

java.lang.Object
  |
  +--javatools.db.DbAbstractTable
All Implemented Interfaces:
DbTableUser
Direct Known Subclasses:
DbFixedAbstractTable, DbJoinedTable, DbTable

public abstract class DbAbstractTable
extends java.lang.Object
implements DbTableUser

A class representing tabular data. Could be a real database table or the result of a SELECT. Based upon class DbTable written by Chris Bitmead, of which it is an abstraction to differentiate between real tables and results of a SELECT command.


Field Summary
protected  DbDatabase db
          The database used for the connection.
protected  int[] displaySize
          This array contains the display size for each field.
protected  java.lang.String[] names
          This array contains the names of the fields of the table.
protected  java.lang.String tableName
          The name of used table
protected  int[] types
          This array contains the SQL types for each field.
 
Constructor Summary
DbAbstractTable(DbDatabase db)
          Constructor.
 
Method Summary
 DbDeleter deleter()
          Returns a deleter for deleting rows in the database.
 boolean equals(java.lang.Object o)
          Check if an object is equal to the current one.
abstract  DbColumn getColumn(int index)
          Get the column of the given index.
abstract  DbColumn getColumn(java.lang.String name)
          Get the DbColumn representing the column with this name.
abstract  int getColumnCount()
          Returns the number of columns
abstract  DbConstraint getConstraint()
          Returns the DbConstraint object associated with this table.
 DbDatabase getDatabase()
          Get the database that this table came from
abstract  java.lang.Object getDefault(int index)
          Returns the default value for the field at the given index.
abstract  java.lang.Object getDefault(java.lang.String name)
          Returns the default value for the field whose name is specified.
 java.lang.String getFullTableName()
          Returns the complete table name.
 DbInserter inserter()
          Return an inserter for inserting new data in the database.
 DbInserter inserter(DbSelector selector)
          Return an inserter for inserting new data in the database.
 void setTableName(java.lang.String v)
          Sets the name of the referenced table.
 DbDeleter simpleDeleter()
          Returns a deleter for deleting rows in the database.
 DbInserter simpleInserter()
          Return an inserter for inserting new data in the database.
 DbInserter simpleInserter(DbSelector selector)
          Return an inserter for inserting new data in the database.
 DbUpdater simpleUpdater()
          Return an updater for updating rows in the database.
 DbUpdater updater()
          Return an updater for updating rows in the database.
 void usesTables(java.util.Set c)
          Returns used tables (useful in joined tables).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db

protected DbDatabase db
The database used for the connection.


tableName

protected java.lang.String tableName
The name of used table


names

protected java.lang.String[] names
This array contains the names of the fields of the table.


displaySize

protected int[] displaySize
This array contains the display size for each field.


types

protected int[] types
This array contains the SQL types for each field.

Constructor Detail

DbAbstractTable

public DbAbstractTable(DbDatabase db)
                throws DbException
Constructor. It sets only the database for the connection.

Parameters:
db - The database to be used
Throws:
DbException - If something goes wrong.
Method Detail

setTableName

public void setTableName(java.lang.String v)
Sets the name of the referenced table.

Parameters:
v - The table name.

getColumn

public abstract DbColumn getColumn(java.lang.String name)
                            throws DbException
Get the DbColumn representing the column with this name.

Parameters:
name - The name of tjhe needed column
Returns:
The column value
Throws:
DbException - If something goes wrong.

getColumn

public abstract DbColumn getColumn(int index)
                            throws DbException
Get the column of the given index. Index is a zero based array.

Parameters:
index - The position of the needed column.
Returns:
The column value
Throws:
DbException - If something goes wrong.

getColumnCount

public abstract int getColumnCount()
Returns the number of columns

Returns:
The number of columns.

getConstraint

public abstract DbConstraint getConstraint()
Returns the DbConstraint object associated with this table.

Returns:
The requested DbConstraint.

getDefault

public abstract java.lang.Object getDefault(int index)
                                     throws DbException
Returns the default value for the field at the given index.

Parameters:
index - The field index.
Returns:
The default value for the requested field.
Throws:
DbException - If something goes wrong.

getDefault

public abstract java.lang.Object getDefault(java.lang.String name)
                                     throws DbException
Returns the default value for the field whose name is specified.

Parameters:
name - The name of the needed field.
Returns:
The default value for the requested field.
Throws:
DbException - If something goes wrong.

getDatabase

public DbDatabase getDatabase()
Get the database that this table came from

Returns:
The database value

getFullTableName

public java.lang.String getFullTableName()
Returns the complete table name.

Returns:
The complete table name.

equals

public boolean equals(java.lang.Object o)
Check if an object is equal to the current one.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to be compared.
Returns:
true: if these object are equal; false: otherwise.

inserter

public DbInserter inserter(DbSelector selector)
                    throws DbException
Return an inserter for inserting new data in the database. This method is for SQL of the form INSERT INTO table(...) SELECT ... This inserter takes care of constraints.

Parameters:
selector - The selector to create the DbInserter object.
Returns:
The DbInserter object to insert data into the table.
Throws:
DbException - If something goes wrong.

simpleInserter

public DbInserter simpleInserter(DbSelector selector)
                          throws DbException
Return an inserter for inserting new data in the database. This method is for SQL of the form INSERT INTO table(...) SELECT ... This inserter DOES NOT take care of constraints.

Parameters:
selector - The selector to create the DbInserter object.
Returns:
The DbInserter object to perform a simple insertion.
Throws:
DbException - If something goes wrong.

inserter

public DbInserter inserter()
                    throws DbException
Return an inserter for inserting new data in the database. This method is for SQL of the form INSERT INTO table(...) VALUES(...) This inserter takes care of constraints.

Returns:
The DbInserter object to insert data into the table.
Throws:
DbException - If something goes wrong.

simpleInserter

public DbInserter simpleInserter()
                          throws DbException
Return an inserter for inserting new data in the database. This method is for SQL of the form INSERT INTO table(...) SELECT ... This inserter DOES NOT take care of constraints.

Returns:
The DbInserter object to perform a simple insertion.
Throws:
DbException - If something goes wrong.

updater

public DbUpdater updater()
                  throws DbException
Return an updater for updating rows in the database. This updater takes care of constraints.

Returns:
The DbUpdater object to perform update operations.
Throws:
DbException - If something goes wrong.

simpleUpdater

public DbUpdater simpleUpdater()
                        throws DbException
Return an updater for updating rows in the database. This updater DOES NOT take care of constraints.

Returns:
The DbUpdater object to perform update operations.
Throws:
DbException - If something goes wrong.

deleter

public DbDeleter deleter()
                  throws DbException
Returns a deleter for deleting rows in the database. This deleter takes care of constraints.

Returns:
The DbDeleter object to perform delete operations.
Throws:
DbException - If something goes wrong.

simpleDeleter

public DbDeleter simpleDeleter()
                        throws DbException
Returns a deleter for deleting rows in the database. This deleter takes care of constraints.

Returns:
The DbDeleter object to perform delete operations.
Throws:
DbException - If something goes wrong.

usesTables

public void usesTables(java.util.Set c)
Returns used tables (useful in joined tables).

Specified by:
usesTables in interface DbTableUser
Parameters:
c - The set to put used tables into.