de.janicke.hj.tools.servlet
Class SimpleVocAdmin

java.lang.Object
  |
  +--de.janicke.hj.tools.servlet.AbstractVocAdmin
        |
        +--de.janicke.hj.tools.servlet.SimpleVocAdmin
All Implemented Interfaces:
VocAdmin

public class SimpleVocAdmin
extends AbstractVocAdmin
implements VocAdmin

Handles the vocable administration with a Database.


Constructor Summary
SimpleVocAdmin(Database database)
          Constructor sets the Database.
 
Method Summary
 boolean addLanguage(User user, java.lang.String languagename)
          Adds a language to the database.
 boolean addUnit(User user, java.lang.String unitname)
          Adds a unit to the database.
 boolean addVocable(Vocable vocableSet, User user)
          Adds a vocable object in the database with the owner given by the userId of the user.
 boolean checkVocable(Vocable vocable, int modus)
          Checks if the vocable is in the database.
 boolean delLanguage(User user, int languageId)
          Deletes a language from the database.
 boolean delUnit(User user, int unitId)
          Deletes a unit specified by unitId from the database.
 boolean delVocable(Vocable vocable, User user)
          Deletes a record of the database selected by the vocId of the vocable-object.
 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.
 boolean editVocable(Vocable vocableSet, User user)
          Edits a record of the database selected by the vocId of the vocable object.
 java.util.Vector getAllLanguages()
          Returns a vector of all languages defined in the database.
 java.util.Vector getAllUnitNames()
          Gets all unitnames specified in the database.
 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, java.lang.String date)
          Returns a vector of vocable objects from the database, where userId and languages, given by the languageId, equals with the database.
 int getUnitIdByUnitName(java.lang.String unitName)
          Gets the UnitId by looking for the unitname in the Database.
 Vocable getVocable(int vocId)
          Returns the vocable object specified by the vocId.
 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 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.
 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.
 Vocable getVocableFromResultSetRandomly(java.util.Vector resultSet)
          Returns a vocable object from a vector of vocable object, choosen randomly.
 void init()
          Initializes the database.
 
Methods inherited from class de.janicke.hj.tools.servlet.AbstractVocAdmin
delLanguage, delUnit, getResultSet, getResultSet, getResultSet, getVocable, getVocable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.janicke.hj.tools.servlet.VocAdmin
delLanguage, delUnit, getResultSet, getResultSet, getResultSet, getVocable, getVocable
 

Constructor Detail

SimpleVocAdmin

public SimpleVocAdmin(Database database)
Constructor sets the Database.
Parameters:
database - The used Database.
Method Detail

init

public void init()
          throws java.lang.Exception
Initializes the database. compiles SQL statements.
Specified by:
init in interface VocAdmin
Overrides:
init in class AbstractVocAdmin
Throws:
java.lang.Exception - if there is no connect to the database, or the precompile of SQL statements fails.

getVocable

public Vocable getVocable(User user,
                          int langId1,
                          int langId2,
                          int modus,
                          java.lang.String date,
                          int unitId)
                   throws java.lang.IllegalArgumentException,
                          java.sql.SQLException
Description copied from interface: VocAdmin
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() )
Specified by:
getVocable in interface VocAdmin
Overrides:
getVocable in class AbstractVocAdmin
Following copied from interface: de.janicke.hj.tools.servlet.VocAdmin
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(int vocId)
                   throws java.sql.SQLException
Returns the vocable object specified by the vocId.
Specified by:
getVocable in interface VocAdmin
Overrides:
getVocable in class AbstractVocAdmin
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 Vocable getVocableFromResultSetRandomly(java.util.Vector resultSet)
                                        throws java.sql.SQLException
Returns a vocable object from a vector of vocable object, choosen randomly.
Specified by:
getVocableFromResultSetRandomly in interface VocAdmin
Overrides:
getVocableFromResultSetRandomly in class AbstractVocAdmin
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 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.
Specified by:
getVocableFromResultSetByStateRandomly in interface VocAdmin
Overrides:
getVocableFromResultSetByStateRandomly in class AbstractVocAdmin
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 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.
Specified by:
getVocableFromResultSetByDateRandomly in interface VocAdmin
Overrides:
getVocableFromResultSetByDateRandomly in class AbstractVocAdmin
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,
                                     java.lang.String date)
                              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.
Specified by:
getResultSet in interface VocAdmin
Overrides:
getResultSet in class AbstractVocAdmin
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.

checkVocable

public boolean checkVocable(Vocable vocable,
                            int modus)
                     throws java.lang.IllegalArgumentException,
                            java.sql.SQLException
Checks if the vocable is in the database.
Specified by:
checkVocable in interface VocAdmin
Overrides:
checkVocable in class AbstractVocAdmin
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 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.
Specified by:
addUnit in interface VocAdmin
Overrides:
addUnit in class AbstractVocAdmin
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,
                       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.
Specified by:
delUnit in interface VocAdmin
Overrides:
delUnit in class AbstractVocAdmin
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 int getUnitIdByUnitName(java.lang.String unitName)
                        throws java.sql.SQLException
Gets the UnitId by looking for the unitname in the Database.
Specified by:
getUnitIdByUnitName in interface VocAdmin
Overrides:
getUnitIdByUnitName in class AbstractVocAdmin
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 java.util.Vector getAllUnitNames()
                                 throws java.sql.SQLException
Gets all unitnames specified in the database.
Specified by:
getAllUnitNames in interface VocAdmin
Overrides:
getAllUnitNames in class AbstractVocAdmin
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 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.
Specified by:
addLanguage in interface VocAdmin
Overrides:
addLanguage in class AbstractVocAdmin
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,
                           int languageId)
                    throws java.sql.SQLException
Deletes a language from the database. The User.su_flag has to be checked to allow the deleting.
Specified by:
delLanguage in interface VocAdmin
Overrides:
delLanguage in class AbstractVocAdmin
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 java.util.Vector getAllLanguages()
                                 throws java.sql.SQLException
Returns a vector of all languages defined in the database.
Specified by:
getAllLanguages in interface VocAdmin
Overrides:
getAllLanguages in class AbstractVocAdmin
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 int getLanguageIdByLanguagename(java.lang.String languagename)
                                throws java.sql.SQLException
Returns the id of the language from the database.
Specified by:
getLanguageIdByLanguagename in interface VocAdmin
Overrides:
getLanguageIdByLanguagename in class AbstractVocAdmin
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 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.
Specified by:
addVocable in interface VocAdmin
Overrides:
addVocable in class AbstractVocAdmin
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 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.
Specified by:
delVocable in interface VocAdmin
Overrides:
delVocable in class AbstractVocAdmin
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 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.
Specified by:
editVocable in interface VocAdmin
Overrides:
editVocable in class AbstractVocAdmin
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 boolean editVocable(Vocable vocableSet,
                           User user)
                    throws java.sql.SQLException
Edits a record of the database selected by the vocId of the vocable object.
Specified by:
editVocable in interface VocAdmin
Overrides:
editVocable in class AbstractVocAdmin
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.