semorg.sql.tables
Class Enumeration

java.lang.Object
  extended by semorg.sql.tables.Enumeration

public class Enumeration
extends Object

This class model the enumerations used in the application.


Field Summary
private static String checkForAnnexString
          SQL query to check if a annex is already in use.
private static String checkForCountryString
          SQL query to check if a country name is already in use.
private static String checkForSalutationString
          SQL query to check if a salutation is already in use.
private static String checkForTitleString
          SQL query to check if a title is already in use.
private static String createTableSQLString
          SQL statement for creating the table "enumeration" (if not exists).
private static String deleteString
          Parameterized SQL statement for deleting a data record.
private static String insertString
          Parameterized SQL statement for inserting a data record.
private static String queryString
          SQL query to get all enumerations with a given type.
private static String tableName
          The name of the corresponding table in the db.
private  int type
          The type of the current enumeration.
static int TYPE_ANNEX
          Enumerations of this type refering to annexes.
static int TYPE_COUNTRY
          Enumerations of this type refering to salutations.
static int TYPE_SALUTATION
          Enumerations of this type refering to salutations.
static int TYPE_TITLE
          Enumerations of this type refering to titles.
private static String[] updateAnnexStrings
          SQL queries to update all occurrences of a annexes to a new value.
private static String[] updateCountryStrings
          SQL queries to update all occurrences of a country name to a new value.
private static String[] updateSalutationStrings
          SQL queries to update all occurrences of a salutation to a new value.
private static String updateString
          Parameterized SQL statement for updating a data record in the table enumeration.
private static String[] updateTitleStrings
          SQL queries to update all occurrences of a title to a new value.
private  String value
          The value of the current enumeration.
 
Constructor Summary
Enumeration(int type, String value)
          Creates instances of this class with the given parameters.
 
Method Summary
static void addAnnexEnums(org.eclipse.swt.widgets.Combo annexCombo)
          Adds all enumerations of the type 3 to the given Combo field.
static void addCountryEnums(org.eclipse.swt.widgets.Combo countryCombo)
          Adds all enumerations of the type 2 to the given Combo field.
private static void addEnums(org.eclipse.swt.widgets.Combo combo, int type)
          Adds all enumerations of the given type to the given Combo field.
static void addSalutationEnums(org.eclipse.swt.widgets.Combo salutationCombo)
          Adds all enumerations of the type 0 to the given Combo field.
static void addTitleEnums(org.eclipse.swt.widgets.Combo titleCombo)
          Adds all enumerations of the type 1 to the given Combo field.
static void createEnumerationTable(Statement statement)
          Creates the table "enumeration" if it does not exist.
static Enumeration createNewEnumInDB(int type, String value)
           
 int getType()
           
 String getValue()
           
private static DistinctVector<Enumeration> getVector(ResultSet resultSet)
          Creates for each element in a given ResultSet instance an object of this class and returns a vector with the resulting class objects.
static DistinctVector<Enumeration> getVectorFromDB(int type)
          Creates a PreparedStatement instance with the given parameter, executes the query and returns a vector of instances of this class corresponding to the ResultSet of the query.
static void insertAnnexStringInDB(String annex)
          Inserts the given annex into the database.
static void insertcountryStringInDB(String country)
          Inserts the given country into the database.
static void insertSalutationStringInDB(String salutation)
          Inserts the given salutation into the database.
static void insertTitleStringInDB(String title)
          Inserts the given title into the database.
 boolean removeFromDB()
          This method checks first if the enumeration to delete is already in use and if not deletes it form the db.
 void setValueInDB(String value)
          Replaces all occurrences of the actual enumeration to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_SALUTATION

public static final int TYPE_SALUTATION
Enumerations of this type refering to salutations.

See Also:
Constant Field Values

TYPE_TITLE

public static final int TYPE_TITLE
Enumerations of this type refering to titles.

See Also:
Constant Field Values

TYPE_COUNTRY

public static final int TYPE_COUNTRY
Enumerations of this type refering to salutations.

See Also:
Constant Field Values

TYPE_ANNEX

public static final int TYPE_ANNEX
Enumerations of this type refering to annexes.

See Also:
Constant Field Values

tableName

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


createTableSQLString

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


insertString

private static String insertString
Parameterized SQL statement for inserting a data record.


deleteString

private static String deleteString
Parameterized SQL statement for deleting a data record.


updateString

private static String updateString
Parameterized SQL statement for updating a data record in the table enumeration.


queryString

private static String queryString
SQL query to get all enumerations with a given type.


checkForSalutationString

private static String checkForSalutationString
SQL query to check if a salutation is already in use.


checkForTitleString

private static String checkForTitleString
SQL query to check if a title is already in use.


checkForCountryString

private static String checkForCountryString
SQL query to check if a country name is already in use.


checkForAnnexString

private static String checkForAnnexString
SQL query to check if a annex is already in use.


updateSalutationStrings

private static String[] updateSalutationStrings
SQL queries to update all occurrences of a salutation to a new value.


updateTitleStrings

private static String[] updateTitleStrings
SQL queries to update all occurrences of a title to a new value.


updateCountryStrings

private static String[] updateCountryStrings
SQL queries to update all occurrences of a country name to a new value.


updateAnnexStrings

private static String[] updateAnnexStrings
SQL queries to update all occurrences of a annexes to a new value.


type

private int type
The type of the current enumeration.


value

private String value
The value of the current enumeration.

Constructor Detail

Enumeration

public Enumeration(int type,
                   String value)
Creates instances of this class with the given parameters.

Method Detail

createEnumerationTable

public static void createEnumerationTable(Statement statement)
                                   throws SQLException
Creates the table "enumeration" 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.

getVectorFromDB

public static DistinctVector<Enumeration> getVectorFromDB(int type)
                                                   throws SQLException
Creates a PreparedStatement instance with the given parameter, executes the query and returns a vector of instances of this class corresponding to the ResultSet of the query.

Parameters:
type - the type of the wanted enumerations.
Returns:
a DistinctVector instance filled with the created instances.
Throws:
SQLException - if the PreparedStatement can't be created or the execution of the query fails.

getVector

private static DistinctVector<Enumeration> getVector(ResultSet resultSet)
                                              throws SQLException
Creates for each element in a given ResultSet instance an object of this class and returns a vector with the resulting class objects.

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

getValue

public String getValue()

getType

public int getType()

createNewEnumInDB

public static Enumeration createNewEnumInDB(int type,
                                            String value)
                                     throws SQLException
Throws:
SQLException

removeFromDB

public boolean removeFromDB()
                     throws SQLException
This method checks first if the enumeration to delete is already in use and if not deletes it form the db. Otherwise the enumeration will not be deleted.

Returns:
true if the deleting was successful, otherwise false
Throws:
SQLException - Throws a SQL exception if the Statement instance can't be created or executed.

setValueInDB

public void setValueInDB(String value)
                  throws SQLException
Replaces all occurrences of the actual enumeration to the given value. Note that several database tables get updated by this method. Finally the corresponding DBTableChangedListener are fired.

Parameters:
value - the new value of the actual enumeration
Throws:
SQLException - if the PreparedStatement can't be created or the execution of the query fails.

addEnums

private static void addEnums(org.eclipse.swt.widgets.Combo combo,
                             int type)
Adds all enumerations of the given type to the given Combo field.

Parameters:
combo - the Combo field, which takes the enumeration values.
type - the type of the enumeration to add.

addSalutationEnums

public static void addSalutationEnums(org.eclipse.swt.widgets.Combo salutationCombo)
Adds all enumerations of the type 0 to the given Combo field.

Parameters:
salutationCombo - the Combo field, which takes the enumeration values.

addTitleEnums

public static void addTitleEnums(org.eclipse.swt.widgets.Combo titleCombo)
Adds all enumerations of the type 1 to the given Combo field.

Parameters:
titleCombo - the Combo field, which takes the enumeration values.

addCountryEnums

public static void addCountryEnums(org.eclipse.swt.widgets.Combo countryCombo)
Adds all enumerations of the type 2 to the given Combo field.

Parameters:
countryCombo - the Combo field, which takes the enumeration values.

addAnnexEnums

public static void addAnnexEnums(org.eclipse.swt.widgets.Combo annexCombo)
Adds all enumerations of the type 3 to the given Combo field.

Parameters:
annexCombo - the Combo field, which takes the enumeration values.

insertSalutationStringInDB

public static void insertSalutationStringInDB(String salutation)
Inserts the given salutation into the database.

Parameters:
salutation - the value of the new salutation

insertTitleStringInDB

public static void insertTitleStringInDB(String title)
Inserts the given title into the database.

Parameters:
title - the value of the new title

insertcountryStringInDB

public static void insertcountryStringInDB(String country)
Inserts the given country into the database.

Parameters:
country - the value of the new country

insertAnnexStringInDB

public static void insertAnnexStringInDB(String annex)
Inserts the given annex into the database.

Parameters:
annex - the value of the new annex