semorg.sql.tables
Class Person

java.lang.Object
  extended by semorg.sql.tables.AbstractTable
      extended by semorg.sql.tables.Person
All Implemented Interfaces:
SimpleIDKey
Direct Known Subclasses:
Associate, Client, Lecturer

public abstract class Person
extends AbstractTable
implements SimpleIDKey

This class models a person and serves as the superclass for several classes which model different roles of persons, such as Client or Lecturer.


Field Summary
protected  String annex
          The annex.
protected  Date birthday
          The birthday.
protected  String city
          The city.
protected  String country
          The country.
private static String createTableSQLString
          SQL statement for creating the table "person" (if not exists).
protected  String email
          The email address.
protected  String fax
          The fax number.
protected  Date firstContact
          The date of the first contact.
protected  String firstname
          The firstname.
protected  int id
          The DB-ID.
static List<Integer> lockedIds
          This list contains the ids of data records which are locked for further editing, because they are actually edited.
protected  String mobile
          The number of the mobile.
protected  String name
          The name (lastname).
protected  String notices
          The notices.
protected static String personInsertString
          Parameterized SQL statement for inserting a person.
protected static String personUpdateString
          Parameterized SQL statement for updating a person data record.
protected  String phone
          The phone number.
protected  String salutation
          The salutation.
protected  String shortinfo
          The short information.
protected  String street
          The street.
private static String tableName
          The name of the corresponding table in the db.
protected  String title
          The title.
protected  String zipCode
          The zip code.
 
Fields inherited from class semorg.sql.tables.AbstractTable
creationDate, modificationDate, NULL_ID
 
Constructor Summary
protected Person(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 shortinfo, String notices, Timestamp creationDate, Timestamp modificationDate)
          Creates an instance of this class with the given values.
 
Method Summary
static void createPersonTable(Statement statement)
          Creates the table "person" if it does not exist.
 boolean equals(Object otherPerson)
          If the given object is an instance of the Person class this method compares the id of the given and the actual object, otherwise it calls the equal-method of the AbstractTable class with the given object.
 String getAnnex()
           
 Date getBirthday()
           
 String getCity()
           
static Vector<DBColumn> getColumns()
          Returns a vector of DBColumn instances according to the properties of the table "person".
 String getCountry()
           
 String getEmail()
           
 String getFax()
           
 Date getFirstContact()
           
 String getFirstname()
           
 int getId()
          Returns the DB-ID of a database records.
 String getMobile()
           
 String getName()
           
 String getNotices()
           
 String getPhone()
           
 String getSalutation()
           
 String getShortinfo()
           
 String getStreet()
           
 String getTitle()
           
 String getZipCode()
           
 int hashCode()
          Returns the id.
 int insertIntoDB()
          Converts the actual Person object into a database person record and inserts it into the table person.
static void removeFromDB(Iterable selectedElements)
          Removes the given elements from the table "person".
 void setAnnex(String annex)
           
 void setBirthday(Date birthday)
           
 void setCity(String city)
           
 void setCountry(String country)
           
 void setEmail(String email)
           
 void setFax(String fax)
           
 void setFirstContact(Date firstContact)
           
 void setFirstname(String firstname)
           
 void setMobile(String mobile)
           
 void setName(String name)
           
 void setNotices(String notices)
           
 void setNumber(int number)
           
 void setPhone(String phone)
           
 void setSalutation(String salutation)
           
 void setShortinfo(String shortinfo)
           
 void setStreet(String street)
           
 void setTitle(String title)
           
 void setZipCode(String zipCode)
           
static boolean tableOK()
          Checks if the according DB table exists.
 void updateDB()
          Converts the actual Person object into a database person record and updates a existing record to the changes made.
 
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

lockedIds

public static List<Integer> lockedIds
This list contains the ids of data records which are locked for further editing, because they are actually edited.

If a data record is to get edited, its id will be inserted into this list. Through this an exclusive access to the actual data record is assured which is meant to avoid that mutiple editing of the same record leads to inconsistencies in the data base.


id

protected int id
The DB-ID.


salutation

protected String salutation
The salutation.


title

protected String title
The title.


firstname

protected String firstname
The firstname.


name

protected String name
The name (lastname).


street

protected String street
The street.


zipCode

protected String zipCode
The zip code.


city

protected String city
The city.


country

protected String country
The country.


annex

protected String annex
The annex.


phone

protected String phone
The phone number.


mobile

protected String mobile
The number of the mobile.


fax

protected String fax
The fax number.


email

protected String email
The email address.


birthday

protected Date birthday
The birthday.


firstContact

protected Date firstContact
The date of the first contact.


shortinfo

protected String shortinfo
The short information.


notices

protected String notices
The notices.


tableName

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


personInsertString

protected static String personInsertString
Parameterized SQL statement for inserting a person.


createTableSQLString

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


personUpdateString

protected static String personUpdateString
Parameterized SQL statement for updating a person data record.

Constructor Detail

Person

protected Person(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 shortinfo,
                 String notices,
                 Timestamp creationDate,
                 Timestamp modificationDate)
Creates an instance of this class with the given values.

Method Detail

getAnnex

public String getAnnex()

getBirthday

public Date getBirthday()

getCity

public String getCity()

getCountry

public String getCountry()

getEmail

public String getEmail()

getFax

public String getFax()

getFirstname

public String getFirstname()

getMobile

public String getMobile()

getName

public String getName()

getNotices

public String getNotices()

getId

public int getId()
Description copied from interface: SimpleIDKey
Returns the DB-ID of a database records.

Specified by:
getId in interface SimpleIDKey

getPhone

public String getPhone()

getSalutation

public String getSalutation()

getShortinfo

public String getShortinfo()

getStreet

public String getStreet()

getTitle

public String getTitle()

getZipCode

public String getZipCode()

getFirstContact

public Date getFirstContact()

setAnnex

public void setAnnex(String annex)

setBirthday

public void setBirthday(Date birthday)

setCity

public void setCity(String city)

setCountry

public void setCountry(String country)

setEmail

public void setEmail(String email)

setFax

public void setFax(String fax)

setFirstContact

public void setFirstContact(Date firstContact)

setFirstname

public void setFirstname(String firstname)

setMobile

public void setMobile(String mobile)

setName

public void setName(String name)

setNotices

public void setNotices(String notices)

setNumber

public void setNumber(int number)

setPhone

public void setPhone(String phone)

setSalutation

public void setSalutation(String salutation)

setShortinfo

public void setShortinfo(String shortinfo)

setStreet

public void setStreet(String street)

setTitle

public void setTitle(String title)

setZipCode

public void setZipCode(String zipCode)

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)

createPersonTable

public static void createPersonTable(Statement statement)
                              throws SQLException
Creates the table "person" 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
Converts the actual Person object into a database person record and inserts it into the table person. Furthermore this method queries the auto-generated id, sets the appropriate property id and returns the id. If a salutation, title, country or annex has been inserted into the form, this method also inserts the concerning properties into the table "enumeration" for later use. Finally it fires a TableChanged-EventListener to update the UI.

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.

updateDB

public void updateDB()
              throws SQLException
Converts the actual Person object into a database person record and updates a existing record to the changes made. If a salutation, title, country or annex has been inserted into the form, this method also inserts the concerning properties into the table "enumeration" for later use. Finally it fires a TableChanged-EventListener to update the UI.

Throws:
SQLException - If the PreparedStatement instance can't be created or executed, this exception is thrown.

removeFromDB

public static void removeFromDB(Iterable selectedElements)
                         throws SQLException
Removes the given elements from the table "person".

Hint: The given elements should be ONLY deleted from the table "person", i.e. NOT in the extending classes/tables, because the rest is done by the dbms in order to fullfill a FK-constraint with an ON-DELETE-cascade.

Due to the FK connections (with an ON-DELETE-cascade) this method fires several TableChanged-Events to update the UI.

Parameters:
selectedElements - the elements, which should be deleted from the database.
Throws:
SQLException - Throws a SQL exception if the Statement instance can't be created or executed.

getColumns

public static Vector<DBColumn> getColumns()
Returns a vector of DBColumn instances according to the properties of the table "person". Note that this function maps the names of the database columns to the names of the GUI tables.

Returns:
the vector of DBColumn instances.
See Also:
AbstractTable.getColumns(String tableAbbreviation)

hashCode

public int hashCode()
Returns the id.

Overrides:
hashCode in class Object

equals

public boolean equals(Object otherPerson)
If the given object is an instance of the Person class this method compares the id of the given and the actual object, otherwise it calls the equal-method of the AbstractTable class with the given object.

Overrides:
equals in class Object
Parameters:
otherPerson - object to be compared with the actual object.
Returns:
true if the id of the given object and the actual object are the same, false otherwise.