semorg.sql.tables
Class ClientBooking

java.lang.Object
  extended by semorg.sql.tables.AbstractTable
      extended by semorg.sql.tables.Booking
          extended by semorg.sql.tables.ClientBooking
All Implemented Interfaces:
SimpleIDKey

public class ClientBooking
extends Booking

Models the booking of a presentation by a client.


Field Summary
private static String clientBookingInsertString
          SQL query to insert a clientbooking record.
private static String clientBookingUpdateString
          SQL query to update a clientbooking record.
private  int clientId
          The id of the client who booked the presentation.
private static String createTableSQLString
          SQL statement for creating the table "clientbooking" (if not exists).
private  int debitorId
          The of the debitor for a client booking.
private  int presentationId
          The id of the presantation booked by the client.
private static String queryString
          SQL query to get all clientbooking records from the database.
private  int substituteId
          The id of substitute for a client.
private static String tableName
          The name of the corresponding table in the db.
 
Fields inherited from class semorg.sql.tables.Booking
billed, bookingInsertString, bookingUpdateString, confirmed, enrolled, id, lockedIds, messaged, signedOff
 
Fields inherited from class semorg.sql.tables.AbstractTable
creationDate, modificationDate, NULL_ID
 
Constructor Summary
ClientBooking(int id, Date enrolled, Date confirmed, Date billed, Date signedOff, Date messaged, int presentationId, int clientId, int debitorId, int substituteId, Timestamp creationDate, Timestamp modificationDate)
          Creates an instance of the class Client with the given parameters.
 
Method Summary
static void createClientBookingTable(Statement statement)
          Creates the table "clientbooking" if it does not exist.
static DistinctVector<ClientBooking> getBookingsForPresentation(int presentationId)
          Returns all bookings for a presentation for a given presentation id.
static DistinctVector<ClientBooking> getBookingsOfClient(int clientId)
          Returns all bookings of a client according to the given client id.
static ClientBooking getClientBooking(int bookingId)
          Returns a ClientBooking instance for a given id of a clientbooking record.
 int getClientId()
           
static Vector<DBColumn> getColumns()
          Returns a vector of DBColumn instances according to the properties of the tables "clientbooking".
 int getDebitorId()
           
static ClientBooking getNext(int currentId)
          Returns for a DB-ID the ClientBooking instance according to the record which has the next bigger id.
 int getPresentationId()
           
static ClientBooking getPrevious(int currentId)
          Returns for a DB-ID the ClientBooking instance according to the record which has the next smaller id.
 String getSubstituteDescription()
          Returns the first- and the lastname of the substitute for a ClientBooking.
 int getSubstituteId()
           
private static DistinctVector<ClientBooking> getVector(ResultSet resultSet)
          Creates for each element in a given ResultSet instance an ClientBooking object and returns a vector with the resulting ClientBooking instances.
static DistinctVector<ClientBooking> getVectorFromDB(Vector<DBConstraint> additionalConstraints, String sortString)
          Creates a PreparedStatement instance with the given parameters, executes the query and returns a vector of ClientBooking instances corresponding to the ResultSet of the query.
 int insertIntoDB()
           Inserts a clientbooking record into the db.
 void setClientId(int clientId)
           
 void setDebitorId(int debitorId)
           
 void setPresentationId(int presentationId)
           
 void setSubstituteId(int substituteId)
           
static boolean tableOK()
          Checks if the according DB table exists.
 void updateDB()
           Updates a clientbooking record in the database.
 
Methods inherited from class semorg.sql.tables.Booking
createBookingTable, equals, getBilled, getConfirmed, getEnrolled, getId, getMessaged, getSignedOff, hashCode, removeFromDB, setBilled, setConfirmed, setEnrolled, setMessaged, setSignedOff
 
Methods inherited from class semorg.sql.tables.AbstractTable
addDBTableChangedListener, createExtendedQueryString, fireTableChangedEvent, getColumns, getCreationDate, getModificationDate, getNext, getPrevious, removeDBTableChangedListener, setModificationDate, tableOK
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

presentationId

private int presentationId
The id of the presantation booked by the client.


clientId

private int clientId
The id of the client who booked the presentation.


debitorId

private int debitorId
The of the debitor for a client booking.


substituteId

private int substituteId
The id of substitute for a client.


tableName

private static String tableName
The name of the corresponding table in the db.


queryString

private static String queryString
SQL query to get all clientbooking records from the database. (delives also the inherited attributes)


clientBookingInsertString

private static String clientBookingInsertString
SQL query to insert a clientbooking record.


clientBookingUpdateString

private static String clientBookingUpdateString
SQL query to update a clientbooking record.


createTableSQLString

private static String createTableSQLString
SQL statement for creating the table "clientbooking" (if not exists).

Constructor Detail

ClientBooking

public ClientBooking(int id,
                     Date enrolled,
                     Date confirmed,
                     Date billed,
                     Date signedOff,
                     Date messaged,
                     int presentationId,
                     int clientId,
                     int debitorId,
                     int substituteId,
                     Timestamp creationDate,
                     Timestamp modificationDate)
              throws SQLException
Creates an instance of the class Client with the given parameters.

Throws:
SQLException
Method Detail

getSubstituteDescription

public String getSubstituteDescription()
Returns the first- and the lastname of the substitute for a ClientBooking.

Returns:
a String with the structure firstname + " " + lastname or the empty string if no substitute exists.

getVector

private static DistinctVector<ClientBooking> getVector(ResultSet resultSet)
Creates for each element in a given ResultSet instance an ClientBooking object and returns a vector with the resulting ClientBooking instances.

Parameters:
resultSet - given ResultSet instance.
Returns:
a DistinctVector instance filled with the created ClientBooking instances.

getVectorFromDB

public static DistinctVector<ClientBooking> getVectorFromDB(Vector<DBConstraint> additionalConstraints,
                                                            String sortString)
                                                     throws SQLException
Creates a PreparedStatement instance with the given parameters, executes the query and returns a vector of ClientBooking instances corresponding to the ResultSet of the query.

Parameters:
additionalConstraints - additional conditions of the WHERE-clause
sortString - sort string with the following structure ORDER BY attribute [ASC|DSC]
Returns:
a DistinctVector instance filled with the created ClientBooking instances.
Throws:
SQLException - if the PreparedStatement can't be created or the execution of the query fails.

tableOK

public static boolean tableOK()
Checks if the according DB table exists.

Returns:
true, if the table is ok, false otherwise.
See Also:
AbstractTable.tableOK(String)

createClientBookingTable

public static void createClientBookingTable(Statement statement)
                                     throws SQLException
Creates the table "clientbooking" if it does not exist.

Parameters:
statement - instance of the class Statement, which is used for executing the SQL statement createTableSQLString.
Throws:
SQLException - If the execution of the given statement with the query createTableSQLString or its closing fails.

insertIntoDB

public int insertIntoDB()
                 throws SQLException

Inserts a clientbooking record into the db.

To do so, it first inserts a record into the table "booking", secondly a record into the table "clientbooking". These two records are linked by a PK-FK-association.

Finally it fires a TableChanged-Event-Listener to update the UI.

Overrides:
insertIntoDB in class Booking
Returns:
the auto-generated id of the inserted tupel.
Throws:
SQLException - If the auto-generated id can't resolved from the db, i.e. it hasnt been generated, or the PreparedStatement instance can't be created or executed, this exception is thrown.
See Also:
Booking.insertIntoDB()

updateDB

public void updateDB()
              throws SQLException

Updates a clientbooking record in the database.

To do so, it firstly updates the corresponding record in the "booking" table and secondly the record in the "clientbooking" table.

Finally it fires a TableChanged-Event-Listener to update the UI.

Overrides:
updateDB in class Booking
Throws:
SQLException - If the auto-generated id can't resolved from the db, i.e. it hasnt been generated, or the PreparedStatement instance can't be created or executed, this exception is thrown.
See Also:
Person.updateDB()

getColumns

public static Vector<DBColumn> getColumns()
Returns a vector of DBColumn instances according to the properties of the tables "clientbooking".

Returns:
the vector of DBColumn instances according to the properties of the class ClientBooking.
See Also:
AbstractTable.getColumns(String tableAbbreviation)

getClientBooking

public static ClientBooking getClientBooking(int bookingId)
                                      throws SQLException
Returns a ClientBooking instance for a given id of a clientbooking record.

Parameters:
bookingId - the id of the wanted ClientBooking instance
Returns:
a ClientBooking object correspoding to the given id.
Throws:
SQLException - if the creating or executing of database query fails.

getNext

public static ClientBooking getNext(int currentId)
Returns for a DB-ID the ClientBooking instance according to the record which has the next bigger id.

Parameters:
currentId - the key of the current record
Returns:
the ClientBooking instance corresponding to the next record in the table "clientbooking" or if it does not exist the ClientBooking instance with the smallest id.
See Also:
AbstractTable.getNext(String, DBColumn, int)

getPrevious

public static ClientBooking getPrevious(int currentId)
Returns for a DB-ID the ClientBooking instance according to the record which has the next smaller id.

Parameters:
currentId - the key of the current record
Returns:
the ClientBooking instance corresponding to the previous record in the table "clientbooking" or if it does not exist the ClientBooking instance with the biggest id.
See Also:
AbstractTable.getPrevious(String, DBColumn, int)

getClientId

public int getClientId()

setClientId

public void setClientId(int clientId)

getDebitorId

public int getDebitorId()

setDebitorId

public void setDebitorId(int debitorId)

getPresentationId

public int getPresentationId()

setPresentationId

public void setPresentationId(int presentationId)

getBookingsOfClient

public static DistinctVector<ClientBooking> getBookingsOfClient(int clientId)
                                                         throws SQLException
Returns all bookings of a client according to the given client id.

Parameters:
clientId - the id of a client
Returns:
a DistinctVector instance filled with all ClientBooking instances corresponding to the client with the given id.
Throws:
SQLException - if the creation or execution of the database query fails.

getBookingsForPresentation

public static DistinctVector<ClientBooking> getBookingsForPresentation(int presentationId)
                                                                throws SQLException
Returns all bookings for a presentation for a given presentation id.

Parameters:
presentationId - the id of a presentation
Returns:
a DistinctVector instance filled with all ClientBooking instances corresponding to the presentation with the given id.
Throws:
SQLException - if the creation or execution of the database query fails.

getSubstituteId

public int getSubstituteId()

setSubstituteId

public void setSubstituteId(int substituteId)