de.janicke.hj.tools.servlet
Class AbstractVocAdmin

java.lang.Object
  |
  +--de.janicke.hj.tools.servlet.AbstractVocAdmin
Direct Known Subclasses:
SimpleVocAdmin

public abstract class AbstractVocAdmin
extends java.lang.Object

Handles the vocable administration with a Database.


Constructor Summary
AbstractVocAdmin()
           
 
Method Summary
abstract  boolean addLanguage(User user, java.lang.String languagename)
          Adds a language to the database.
abstract  boolean addUnit(User user, java.lang.String unitname)
          Adds a unit to the database.
abstract  boolean addVocable(Vocable vocableSet, User user)
          Adds a vocable object in the database with the owner given by the userId of the user.
abstract  boolean checkVocable(Vocable vocable, int modus)
          Checks if the vocable is in the database.
abstract  boolean delLanguage(User user, int languageId)
          Deletes a language from the database.
 boolean delLanguage(User user, java.lang.String languagename)
          Deletes a language from the database.
abstract  boolean delUnit(User user, int unitId)
          Deletes a unit specified by unitId from the database.
 boolean delUnit(User user, java.lang.String unitname)
          Deletes a unit from the database.
abstract  boolean delVocable(Vocable vocable, User user)
          Deletes a record of the database selected by the vocId of the vocable-object.
abstract  boolean editVocable(Vocable vocableSet, boolean status, User user)
          Edits the state of a record in the database selected by the vocId of the vocable object.
abstract  boolean editVocable(Vocable vocableSet, User user)
          Edits a record of the database selected by the vocId of the vocable object.
abstract  java.util.Vector getAllLanguages()
          Returns a vector of all languages defined in the database.
abstract  java.util.Vector getAllUnitNames()
          Gets all unitnames specified in the database.
abstract  int getLanguageIdByLanguagename(java.lang.String languagename)
          Returns the id of the language from the database.
 java.util.Vector getResultSet(User user, int lang1, int lang2)
          Returns a vector of vocable objects from the database, where userId and languages, given by the languageId, equals with the database.
abstract  java.util.Vector getResultSet(User user, int lang1, int lang2, java.lang.String date)
          Returns a vector of vocable objects from the database, where userId, languages given by the languageId equals with the database and where the date of the vocable is younger than the given date.
 java.util.Vector getResultSet(User user, java.lang.String langName1, java.lang.String langName2)
          Returns a vector of vocable objects from the database, where userId and languages, given by the language, equals with the database.
 java.util.Vector getResultSet(User user, java.lang.String langName1, java.lang.String langName2, java.lang.String date)
          Returns a vector of vocable objects from the database, where userId, languages given by the language equals with the database and where the date of the vocable is younger than the given date.
abstract  int getUnitIdByUnitName(java.lang.String unitName)
          Gets the UnitId by looking for the unitname in the Database.
abstract  Vocable getVocable(int vocId)
          Returns the vocable object specified by the vocId.
abstract  Vocable getVocable(User user, int langId1, int langId2, int modus, java.lang.String date, int unitId)
          Returns a vocable object from a user out of the database.
 Vocable getVocable(User user, int langId1, int langId2, int modus, java.lang.String date, java.lang.String unit)
          Returns a vocable object from a user out of the database.
 Vocable getVocable(User user, java.lang.String lang1, java.lang.String lang2, int modus, java.lang.String date, int unitid)
          Returns a vocable object from a user out of the database.
abstract  Vocable getVocableFromResultSetByDateRandomly(java.util.Vector resultSet)
          Returns a vocable object from a vector of vocable object, choosen randomly by an algorithmen using the date of the vocable object.
abstract  Vocable getVocableFromResultSetByStateRandomly(java.util.Vector resultSet)
          Returns a vocable object from a vector of vocable object, choosen randomly by an algorithmen using the state of the vocable object.
abstract  Vocable getVocableFromResultSetRandomly(java.util.Vector resultSet)
          Returns a vocable object from a vector of vocable object, choosen randomly.
abstract  void init()
          Initializes the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractVocAdmin

public AbstractVocAdmin()
Method Detail

init

public abstract void init()
                   throws java.lang.Exception
Initializes the database. compiles SQL statements.
Returns:
true if succeeded,
if the database is not opened or the compilation of the SQL statements fails, it throws an Exception.
Throws:
java.lang.Exception - if there is no connect to the database, or the precompile of SQL statements fails.

getVocable

public abstract Vocable getVocable(User user,
                                   int langId1,
                                   int langId2,
                                   int modus,
                                   java.lang.String date,
                                   int unitId)
                            throws java.lang.IllegalArgumentException,
                                   java.sql.SQLException
Returns a vocable object from a user out of the database. The algorithm to look up the vocable object is determined by the modus.
langId1 specifies the language from which the vocable object has to be translated to langId2.
The vocable has to be reorganised (see: getResultSet() )
Parameters:
user - The owner of the vocables.
langId1 - The source language.
langId2 - The destination language to translate to.
modus - The mode that determines how to get the vocabluaries.
date - The oldest date to get the vocabluaries from.
unitid - The unit id to get the vocabluaries from.
Returns:
Returns a vocable object, if there were vocabluaries owned by user.
null if there were no vocabluaries owned by this user. Or there was no vocable "younger" than the given date.

getVocable

public Vocable getVocable(User user,
                          java.lang.String lang1,
                          java.lang.String lang2,
                          int modus,
                          java.lang.String date,
                          int unitid)
                   throws java.lang.IllegalArgumentException,
                          java.sql.SQLException
Returns a vocable object from a user out of the database. How to get the vocable object is given by the modus.
It gets the languageId's out of lang1 and lang2 by using getLanguageByIdLanguagename() an then calls getVocable() with the languageId's.
The vocable has to be reorganised (see: getResultSet() )
Parameters:
user - The owner of the vocables.
lang1 - The source language.
lang2 - The destination language to translate to.
modus - The mode that determines how to get the vocabluaries.
date - The oldest date to get the vocabluaries from.
unitid - The unit id to get the vocabluaries from.
Returns:
Returns a vocable object, if there were vocabluaries owned by user.
null if there were no vocabluaries owned by this user. Or there was no vocable "younger" than the given date.
Throws:
InvalidArgumentException - if
the modus was invalid. or the languages do not exists. or there is no unit found for unitid
java.sql.SQLException - if data couldn't be retrieved from the database.

getVocable

public Vocable getVocable(User user,
                          int langId1,
                          int langId2,
                          int modus,
                          java.lang.String date,
                          java.lang.String unit)
                   throws java.lang.IllegalArgumentException,
                          java.sql.SQLException
Returns a vocable object from a user out of the database. How to get the vocable object is given by the modus.
It gets the languageId's out of lang1 and lang2 by using getLanguageByIdLanguagename() and getting the unitId by using getUnitIdByUnitName(). Then calls getVocable() with the languageId's.
The vocable has to be reorganised (see: getResultSet() )
Parameters:
user - The owner of the vocables.
langId1 - The source language.
langId2 - The destination language to translate to.
modus - The mode that determines how to get the vocabluaries.
date - The oldest date to get the vocabluaries from.
unit - The unit to get the vocabluaries from.
Returns:
Returns a vocable object, if there were vocabluaries owned by user.
null if there were no vocabluaries owned by this user. Or there was no vocable "younger" than the given date.
Throws:
InvalidArgumentException - if
the modus was invalid. or the languages do not exists. or there is no unit found for unit
java.sql.SQLException - if data couldn't be retrieved from the database.

getVocable

public abstract Vocable getVocable(int vocId)
                            throws java.sql.SQLException
Returns the vocable object specified by the vocId.
Parameters:
vocId - The primary key of the vocable table in the database.
user - The owner of the vocable.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

getVocableFromResultSetRandomly

public abstract Vocable getVocableFromResultSetRandomly(java.util.Vector resultSet)
                                                 throws java.sql.SQLException
Returns a vocable object from a vector of vocable object, choosen randomly.
Parameters:
resultSet - A vector of vocable objects.
Returns:
A vocable object, choosen randomly from the given resultSet.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

getVocableFromResultSetByStateRandomly

public abstract Vocable getVocableFromResultSetByStateRandomly(java.util.Vector resultSet)
                                                        throws java.sql.SQLException
Returns a vocable object from a vector of vocable object, choosen randomly by an algorithmen using the state of the vocable object.
Parameters:
resultSet - A vector of vocable objects.
Returns:
A vocable object, choosen by an algorithmen from the given resultSet.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

getVocableFromResultSetByDateRandomly

public abstract Vocable getVocableFromResultSetByDateRandomly(java.util.Vector resultSet)
                                                       throws java.sql.SQLException
Returns a vocable object from a vector of vocable object, choosen randomly by an algorithmen using the date of the vocable object.
Parameters:
resultSet - A set of vocable objects.
Returns:
A vocable object, choosen by an algorithmen from the given resultSet.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

getResultSet

public java.util.Vector getResultSet(User user,
                                     int lang1,
                                     int lang2)
                              throws java.sql.SQLException
Returns a vector of vocable objects from the database, where userId and languages, given by the languageId, equals with the database. The vocable objects have to reorganised, so that
- Vocable.vocable1 is vocable in source language.
- Vocable.vocable2 is vocable in destination language..
Calls getResultSet(user,langid1,langid2,date) with date = null.
Parameters:
user - A User-Object.
lang1 - LanguageId of Vocable1.
lang2 - LanguageId of Vocable2.
Returns:
Returns a Vector of Vocable-Object.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

getResultSet

public java.util.Vector getResultSet(User user,
                                     java.lang.String langName1,
                                     java.lang.String langName2)
                              throws java.lang.IllegalArgumentException,
                                     java.sql.SQLException
Returns a vector of vocable objects from the database, where userId and languages, given by the language, equals with the database. The vocable objects have to reorganised, so that
- Vocable.vocable1 is vocable in source language.
- Vocable.vocable2 is vocable in destination language..
It checks the language if they exist and then calls getResultSet(user,langid1,langid2,date) with date = null.
Parameters:
user - A user object.
langName1 - Languagename of vocable1.
langName2 - Languagename of vocable2.
Returns:
Returns a vector of vocable object.
Throws:
InvalidArgumentException - if the at least one of the languages does not exists.
java.sql.SQLException - if data couldn't be retrieved from the database.

getResultSet

public abstract java.util.Vector getResultSet(User user,
                                              int lang1,
                                              int lang2,
                                              java.lang.String date)
                                       throws java.sql.SQLException
Returns a vector of vocable objects from the database, where userId, languages given by the languageId equals with the database and where the date of the vocable is younger than the given date. The vocable objects have to reorganised, so that - Vocable.vocable1 is vocable in source language.
- Vocable.vocable2 is vocable in destination language..
Parameters:
user - A user object.
lang1 - LanguageId of vocable1.
lang2 - LanguageId of vocable2.
date - The date of the oldest vocable that will be returned.
Returns:
Returns a Vector of Vocable-Object.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

getResultSet

public java.util.Vector getResultSet(User user,
                                     java.lang.String langName1,
                                     java.lang.String langName2,
                                     java.lang.String date)
                              throws java.lang.IllegalArgumentException,
                                     java.sql.SQLException
Returns a vector of vocable objects from the database, where userId, languages given by the language equals with the database and where the date of the vocable is younger than the given date. The vocable objects have to reorganised, so that - Vocable.vocable1 is vocable in source language.
- Vocable.vocable2 is vocable in destination language..
It checks the language if they exist and then calls getResultSet(user,langid1,langid2,date)
Parameters:
user - A user object.
langName1 - Languagename of vocable1.
langName2 - Languagename of vocable2.
date - The date of the oldest vocable that will be returned.
Returns:
Returns a vector of vocable object.
Throws:
InvalidArgumentException - if the at least one of the languages does not exists.
java.sql.SQLException - if data couldn't be retrieved from the database.

checkVocable

public abstract boolean checkVocable(Vocable vocable,
                                     int modus)
                              throws java.lang.IllegalArgumentException,
                                     java.sql.SQLException
Checks if the vocable is in the database.
Parameters:
vocable - The Vocable-Object to check.
modus - The current modus.
Returns:
Returns true if Vocable was answered correct, else false.
Throws:
InvalidArgumentException - if the modus was invalid.
java.sql.SQLException - if data couldn't be retrieved from the database.

addUnit

public abstract boolean addUnit(User user,
                                java.lang.String unitname)
                         throws java.sql.SQLException
Adds a unit to the database. The User.su_flag has to be checked to allow the adding.
Parameters:
user - To determine if user is superuser.
unitname - The name of the unit to add.
Returns:
Returns true if unitname was added, else false.
Throws:
java.sql.SQLException - if data couldn't be addedd to the database.

delUnit

public boolean delUnit(User user,
                       java.lang.String unitname)
                throws java.lang.IllegalArgumentException,
                       java.sql.SQLException
Deletes a unit from the database. The User.su_flag has to be checked to allow the deleting. The unitname will be checked if it exists, and then by the id deltetd with delUnit(user, unitId)
Parameters:
user - To determine if user is superuser.
unitname - The name of the unit to delete.
Returns:
Returns true if unit was deleted, else false.
Throws:
InvalidArgumentException - if the unitname does not exists.
java.sql.SQLException - if data couldn't be deleted from the database.

delUnit

public abstract boolean delUnit(User user,
                                int unitId)
                         throws java.sql.SQLException
Deletes a unit specified by unitId from the database. The User.su_flag has to be checked to allow the deleting.
Parameters:
user - To determine if user is superuser.
unitId - The id of the unit to delete.
Returns:
Returns true if unit was deleted, else false.
Throws:
java.sql.SQLException - if data couldn't be deleted from the database.

getUnitIdByUnitName

public abstract int getUnitIdByUnitName(java.lang.String unitName)
                                 throws java.lang.IllegalArgumentException,
                                        java.sql.SQLException
Gets the UnitId by looking for the unitname in the Database.
Parameters:
unitName - The name of the choosen unit.
Returns:
Returns the unitid of the unit.
Throws:
InvalidArgumentException - if the unitname does not exists.
java.sql.SQLException - if data couldn't be retrieved from the database.

getAllUnitNames

public abstract java.util.Vector getAllUnitNames()
                                          throws java.sql.SQLException
Gets all unitnames specified in the database.
Returns:
Returns a vector of Strings with all available unitnames.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

addLanguage

public abstract boolean addLanguage(User user,
                                    java.lang.String languagename)
                             throws java.sql.SQLException
Adds a language to the database. The User.su_flag has to be checked to allow the adding.
Parameters:
user - To determine if user is superuser.
languagename - The name of the language to add.
Returns:
Returns true if language was added, else false.
Throws:
java.sql.SQLException - if data couldn't be added to the database.

delLanguage

public boolean delLanguage(User user,
                           java.lang.String languagename)
                    throws java.lang.IllegalArgumentException,
                           java.sql.SQLException
Deletes a language from the database. The User.su_flag has to be checked to allow the deleting. The language will be checked if it exists, and then by the id deltetd with delLanguage(user, languageId)
Parameters:
user - To determine if user is superuser.
languagename - The name of the language to delete.
Returns:
Returns true if language was deleted, else false.
Throws:
InvalidArgumentException - if the language does not exists.
java.sql.SQLException - if data couldn't be deleted from the database.

delLanguage

public abstract boolean delLanguage(User user,
                                    int languageId)
                             throws java.sql.SQLException
Deletes a language from the database. The User.su_flag has to be checked to allow the deleting.
Parameters:
user - To determine if user is superuser.
languageId - The id of the language to delete.
Returns:
Returns true if language was deleted, else false.
Throws:
InvalidArgumentException - if the language does not exists.
java.sql.SQLException - if data couldn't be deleted from the database.

getAllLanguages

public abstract java.util.Vector getAllLanguages()
                                          throws java.sql.SQLException
Returns a vector of all languages defined in the database.
Returns:
Returns a vector of Strings of all languages defined in the database.
Throws:
java.sql.SQLException - if data couldn't be retrieved from the database.

getLanguageIdByLanguagename

public abstract int getLanguageIdByLanguagename(java.lang.String languagename)
                                         throws java.lang.IllegalArgumentException,
                                                java.sql.SQLException
Returns the id of the language from the database.
Parameters:
languagename - The language.
Returns:
The id of the language.
Throws:
InvalidArgumentException - if the language does not exists.
java.sql.SQLException - if data couldn't be retrieved from the database.

addVocable

public abstract boolean addVocable(Vocable vocableSet,
                                   User user)
                            throws java.sql.SQLException
Adds a vocable object in the database with the owner given by the userId of the user.
Parameters:
vocableSet - This vocable object will be added in the database.
user - The owner of the vocableSet.
Returns:
true if adding was successfull, else throws an SQLException.
Throws:
java.sql.SQLException - if data couldn't be added to the database.

delVocable

public abstract boolean delVocable(Vocable vocable,
                                   User user)
                            throws java.sql.SQLException
Deletes a record of the database selected by the vocId of the vocable-object. Allowed to delete are owner and superuser.
Parameters:
vocable - This vocable object will be deleted in the database.
Returns:
true if deleting was successfull, else throws SQLException.
Throws:
java.sql.SQLException - if data couldn't be deleted in the database.

editVocable

public abstract boolean editVocable(Vocable vocableSet,
                                    boolean status,
                                    User user)
                             throws java.sql.SQLException
Edits the state of a record in the database selected by the vocId of the vocable object. The state of the vocable object has to be changed by an algorithmen.
Parameters:
vocableSet - The state of this vocable object will be updated in the database.
status - If the answer was correct then status must be true else false.
user - The owner of the vocable.
Returns:
true if update was successfull, else throws an SQLException.
Throws:
java.sql.SQLException - if data couldn't be updated in the database.

editVocable

public abstract boolean editVocable(Vocable vocableSet,
                                    User user)
                             throws java.sql.SQLException
Edits a record of the database selected by the vocId of the vocable object.
Parameters:
vocableSet - This vocable object will be updated in the database.
user - The owner of the vocable.
Returns:
true if update was successfull, false otherwise.
Throws:
java.sql.SQLException - if data couldn't be updated in the database.