semorg.sql.tables
Class Client

java.lang.Object
  extended by semorg.sql.tables.AbstractTable
      extended by semorg.sql.tables.Person
          extended by semorg.sql.tables.Client
All Implemented Interfaces:
SimpleIDKey

public class Client
extends Person

Models a person in the role of a client.


Field Summary
private static String clientInsertString
          SQL query to insert a client record.
private static String clientUpdateString
          SQL query to update a client record.
private static String createTableSQLString
          SQL statement for creating the table "client" (if not exists).
private  int employerId
          The id of the company which employs the client.
private static String queryString
          SQL query to get all client records from the database.
private static String tableName
          The name of the corresponding db table.
private  String task
          The task of the client in a company.
private  Float turnover
          The turnover produced by a client.
 
Fields inherited from class semorg.sql.tables.Person
annex, birthday, city, country, email, fax, firstContact, firstname, id, lockedIds, mobile, name, notices, personInsertString, personUpdateString, phone, salutation, shortinfo, street, title, zipCode
 
Fields inherited from class semorg.sql.tables.AbstractTable
creationDate, modificationDate, NULL_ID
 
Constructor Summary
Client(int id, String salutation, String title, String firstname, String name, String street, String zipCode, String city, String country, String annex, String phone, String mobile, String fax, String email, Date birthday, Date firstContact, String task, Float turnover, int employerId, String shortinfo, String notices, Timestamp creationDate, Timestamp modificationDate)
          Creates an instance of the class Client with the given parameters.
 
Method Summary
static void createClientTable(Statement statement)
          Creates the table "client" if it does not exist.
static Client getClient(int clientId)
          Returns a Client instance for a given client id.
static Vector<DBColumn> getColumns()
          Returns a vector of DBColumn instances according to the properties of the tables "person" and "client".
static DistinctVector<Client> getEmployees(int companyId)
          Returns all Client objects which are employed by a certain company specified by a given company id.
 String getEmployerDescription()
          Retrieves the employer of a client (if exists) and returns its short name.
 int getEmployerId()
           
static Client getNext(int currentId)
          Returns for a DB-ID the Client instance according to the record which has the next bigger id.
static Client getPrevious(int currentId)
          Returns for a DB-ID the Client instance according to the record which has the next smaller id.
 String getTask()
           
 Float getTurnover()
           
private static DistinctVector<Client> getVector(ResultSet resultSet)
          Creates for each element in a given ResultSet instance an Client object and returns a vector with the resulting Client instances.
static DistinctVector<Client> getVectorFromDB(Vector<DBConstraint> additionalConstraints, String sortString)
          Creates a PreparedStatement instance with the given parameters, executes the query and returns a vector of Client instances corresponding to the ResultSet of the query.
 int insertIntoDB()
           Inserts a client record into the db.
 void setEmployerId(int employerId)
           
 void setTask(String task)
           
 void setTurnover(Float turnover)
           
static boolean tableOK()
          Checks if the according DB table exists.
 void updateDB()
          Updates a client record in the database.
 
Methods inherited from class semorg.sql.tables.Person
createPersonTable, equals, getAnnex, getBirthday, getCity, getCountry, getEmail, getFax, getFirstContact, getFirstname, getId, getMobile, getName, getNotices, getPhone, getSalutation, getShortinfo, getStreet, getTitle, getZipCode, hashCode, removeFromDB, setAnnex, setBirthday, setCity, setCountry, setEmail, setFax, setFirstContact, setFirstname, setMobile, setName, setNotices, setNumber, setPhone, setSalutation, setShortinfo, setStreet, setTitle, setZipCode
 
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

task

private String task
The task of the client in a company.


turnover

private Float turnover
The turnover produced by a client.


employerId

private int employerId
The id of the company which employs the client.


tableName

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


queryString

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


clientInsertString

private static String clientInsertString
SQL query to insert a client record.


clientUpdateString

private static String clientUpdateString
SQL query to update a client record.


createTableSQLString

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

Constructor Detail

Client

public Client(int id,
              String salutation,
              String title,
              String firstname,
              String name,
              String street,
              String zipCode,
              String city,
              String country,
              String annex,
              String phone,
              String mobile,
              String fax,
              String email,
              Date birthday,
              Date firstContact,
              String task,
              Float turnover,
              int employerId,
              String shortinfo,
              String notices,
              Timestamp creationDate,
              Timestamp modificationDate)
Creates an instance of the class Client with the given parameters.

Method Detail

getEmployerDescription

public String getEmployerDescription()
Retrieves the employer of a client (if exists) and returns its short name.

Returns:
The short name of the employer of a client if the client is employed by a company which is represented in the database, otherwise the empty string.

getVector

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

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

getVectorFromDB

public static DistinctVector<Client> getVectorFromDB(Vector<DBConstraint> additionalConstraints,
                                                     String sortString)
                                              throws SQLException
Creates a PreparedStatement instance with the given parameters, executes the query and returns a vector of Client 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 Client 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)

createClientTable

public static void createClientTable(Statement statement)
                              throws SQLException
Creates the table "client" 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 client record into the db.

To do so, it first inserts a record into the table "person", secondly a record into the table "client". 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 Person
Returns:
the auto-generated id of the inserted person-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 etc.
See Also:
Person.insertIntoDB()

updateDB

public void updateDB()
              throws SQLException
Updates a client record in the database. To do so, it firstly updates the corresponding record in the "person" table and secondly the record in the "client" table.

Overrides:
updateDB in class Person
Throws:
SQLException - If the PreparedStatement instance can't be created or executed, this exception is thrown.
See Also:
Person.updateDB()

getNext

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

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

getPrevious

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

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

getColumns

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

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

getEmployerId

public int getEmployerId()

setEmployerId

public void setEmployerId(int employerId)

getTask

public String getTask()

setTask

public void setTask(String task)

getTurnover

public Float getTurnover()

setTurnover

public void setTurnover(Float turnover)

getClient

public static Client getClient(int clientId)
                        throws SQLException
Returns a Client instance for a given client id.

Parameters:
clientId - id of the wanted Client instance
Returns:
the Client instance according to the given id
Throws:
SQLException - if the client can't retrieved from the database.

getEmployees

public static DistinctVector<Client> getEmployees(int companyId)
                                           throws SQLException
Returns all Client objects which are employed by a certain company specified by a given company id.

Parameters:
companyId - the id of a company
Returns:
a vector of Client objects
Throws:
SQLException - if the creation or execution of the database query fails.