semorg.sql.tables
Class AbstractTable

java.lang.Object
  extended by semorg.sql.tables.AbstractTable
Direct Known Subclasses:
Booking, Company, Conduct, Instructor, Person, Presentation, SeminarType, Supervisor

public abstract class AbstractTable
extends Object

Super class for all table classes. Encapsulates all properties and methods, which have all table classes in common.


Field Summary
protected  Timestamp creationDate
          Date of creation of a table record.
protected  Timestamp modificationDate
          Date of modification of a table record.
static int NULL_ID
          ID for a not existing tupel (NULL-tupel).
private static Set<DBTableChangedListener> tableChangedListeners
          A set of listeners, which react on table changes.
 
Constructor Summary
AbstractTable(Timestamp creationDate, Timestamp modificationDate)
          Creates an AbstractTable instance.
 
Method Summary
static void addDBTableChangedListener(DBTableChangedListener listener)
          Inserts a listener into a set of listeners.
protected static PreparedStatement createExtendedQueryString(String queryString, Vector<DBConstraint> additionalConstraints, String sortString)
          Extends a SQL statement string with additional db constraints and / or an ORDER-BY statement and returns the appropriate PreparedStatement object.
protected static void fireTableChangedEvent(int type)
          Iterates over the set of listeners, which react on changes of the table and fires the one according to the wanted type.
protected static Vector<DBColumn> getColumns(String tableAbbreviation)
          Creates for creationDate and modificationDate two DBColumn instances and returns them.
 Timestamp getCreationDate()
          Returns the date of creation.
 Timestamp getModificationDate()
          Returns the date of modification.
protected static ResultSet getNext(String queryString, DBColumn sortColumn, int currentKey)
          Returns for a data record the following one, i.e. the record whose key is the next bigger to the key of the given record or, if it does not exists, the record with the smallest key.
protected static ResultSet getPrevious(String queryString, DBColumn sortColumn, int currentKey)
          Returns for a data record the previous one, i.e. the record whose key is the next smaller to the key of the given record or, if it does not exists, the record with the biggest key.
static void removeDBTableChangedListener(DBTableChangedListener listener)
          Removes a listener from a set of listeners.
 void setModificationDate(Timestamp modificationDate)
          Sets the date of modification.
protected static boolean tableOK(String tableName)
          Checks, whether a table exists or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableChangedListeners

private static Set<DBTableChangedListener> tableChangedListeners
A set of listeners, which react on table changes.


NULL_ID

public static final int NULL_ID
ID for a not existing tupel (NULL-tupel).

See Also:
Constant Field Values

creationDate

protected Timestamp creationDate
Date of creation of a table record.


modificationDate

protected Timestamp modificationDate
Date of modification of a table record.

Constructor Detail

AbstractTable

public AbstractTable(Timestamp creationDate,
                     Timestamp modificationDate)
Creates an AbstractTable instance.

Parameters:
creationDate - the creationDate of a table record.
modificationDate - the modificationDate of a table record.
Method Detail

getCreationDate

public Timestamp getCreationDate()
Returns the date of creation.


getModificationDate

public Timestamp getModificationDate()
Returns the date of modification.


setModificationDate

public void setModificationDate(Timestamp modificationDate)
Sets the date of modification.

Parameters:
modificationDate - the new modificationDate.

createExtendedQueryString

protected static PreparedStatement createExtendedQueryString(String queryString,
                                                             Vector<DBConstraint> additionalConstraints,
                                                             String sortString)
                                                      throws SQLException
Extends a SQL statement string with additional db constraints and / or an ORDER-BY statement and returns the appropriate PreparedStatement object.

Parameters:
queryString - SQL query string to be extended
additionalConstraints - additional conditions of the WHERE-clause.
sortString - sort string with the following structure ORDER BY attribute [ASC|DSC].
Returns:
PreparedStatement instance according to the extended query string.
Throws:
SQLException

getColumns

protected static Vector<DBColumn> getColumns(String tableAbbreviation)
Creates for creationDate and modificationDate two DBColumn instances and returns them.

Parameters:
tableAbbreviation - The abbreviation (used as prefix) for the name of the table.
Returns:
Vector with the created DBComun instances.

tableOK

protected static boolean tableOK(String tableName)
Checks, whether a table exists or not.

Returns:
true, if the DESCRIBE statement can be executed for the table, false otherwise.

getNext

protected static ResultSet getNext(String queryString,
                                   DBColumn sortColumn,
                                   int currentKey)
Returns for a data record the following one, i.e. the record whose key is the next bigger to the key of the given record or, if it does not exists, the record with the smallest key.

Hint: The mentioned behavior is only ensured, if the ID-column is used as the sortColumn.

Parameters:
queryString - the sql statement to be executed.
sortColumn - the property which is used for sorting the result set of the sql statement.
currentKey - the current key.
Returns:
ResultSet, which inlcudes one of the above-mentioned data records or null if the table is empty.

getPrevious

protected static ResultSet getPrevious(String queryString,
                                       DBColumn sortColumn,
                                       int currentKey)
Returns for a data record the previous one, i.e. the record whose key is the next smaller to the key of the given record or, if it does not exists, the record with the biggest key.

Hint: The mentioned behavior is only ensured, if the ID-column is used as the sortColumn.

Parameters:
queryString - the sql statement to be executed.
sortColumn - the property which is used for sorting the result set of the sql statement.
currentKey - the current key.
Returns:
ResultSet, which inlcudes one of the above-mentioned data records or null if the table is empty.

fireTableChangedEvent

protected static void fireTableChangedEvent(int type)
Iterates over the set of listeners, which react on changes of the table and fires the one according to the wanted type.

Parameters:
type - type of the listener, which should be fired.

addDBTableChangedListener

public static void addDBTableChangedListener(DBTableChangedListener listener)
Inserts a listener into a set of listeners.

Parameters:
listener - DBTableChangedListener instance, which should be inserted.

removeDBTableChangedListener

public static void removeDBTableChangedListener(DBTableChangedListener listener)
Removes a listener from a set of listeners.

Parameters:
listener - DBTableChangedListener instance, which is to be removed.