lib.jGroupware.utils
Class Database

java.lang.Object
  extended bylib.jGroupware.utils.Database

public class Database
extends java.lang.Object

Class to handle all jGroupware library database work

Author:
Gareth Webber

Constructor Summary
Database()
           
 
Method Summary
 void deleteCollection(java.sql.Connection mySQLConnection, java.lang.String command, java.lang.String[] parameters)
          Delete a collection from the database
 int getNewId(java.sql.Connection mySQLConnection, java.lang.String getCurrentIdCommand, java.lang.String saveUpdatedIdCommand)
          Gets the newId attribute of the Database object
 java.util.Collection loadCollection(BeanFactory factory, java.util.Map beanMapping, java.sql.Connection mySQLConnection, java.lang.String command, java.lang.String[] parameters)
          Method that loads a collection of objects from a database
 java.lang.Object loadElement(BeanFactory factory, java.util.Map beanMapping, java.sql.Connection mySQLConnection, java.lang.String command, java.lang.String[] parameters)
          Method that loads an element from a database
 void saveBean(java.lang.Object bean, java.util.Map beanMapping, java.sql.Connection mySQLConnection, java.lang.String command)
          Update a bean in the database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Database

public Database()
Method Detail

loadCollection

public java.util.Collection loadCollection(BeanFactory factory,
                                           java.util.Map beanMapping,
                                           java.sql.Connection mySQLConnection,
                                           java.lang.String command,
                                           java.lang.String[] parameters)
                                    throws DatabaseErrorException
Method that loads a collection of objects from a database

Parameters:
mySQLConnection - Connection to the database
command - SQL command to run (with ? characters representing substitutions)
parameters - Any additional parameters for substitution into command
beanMapping - Map from bean attributes to SQL column names
factory - Factory used to create beans that are loaded into collection
Returns:
Collection of beans with data loaded from SQL query
Throws:
DatabaseErrorException - Caused by any exception on the way

loadElement

public java.lang.Object loadElement(BeanFactory factory,
                                    java.util.Map beanMapping,
                                    java.sql.Connection mySQLConnection,
                                    java.lang.String command,
                                    java.lang.String[] parameters)
                             throws DatabaseErrorException
Method that loads an element from a database

Parameters:
mySQLConnection - Connection to the database
command - SQL command to run (with ? characters representing substitutions)
parameters - Any additional parameters for substitution into command
beanMapping - Map from bean attributes to SQL column names
factory - Factory used to create beans that are loaded into collection
Returns:
Bean with data loaded from SQL query
Throws:
DatabaseErrorException - Caused by any exception on the way

deleteCollection

public void deleteCollection(java.sql.Connection mySQLConnection,
                             java.lang.String command,
                             java.lang.String[] parameters)
                      throws DatabaseErrorException
Delete a collection from the database

Parameters:
mySQLConnection - Connection to the database
command - SQL command to run (with ? characters representing substitutions)
parameters - Any additional parameters for substitution into command
Throws:
DatabaseErrorException - Caused by any exception on the way

saveBean

public void saveBean(java.lang.Object bean,
                     java.util.Map beanMapping,
                     java.sql.Connection mySQLConnection,
                     java.lang.String command)
              throws DatabaseErrorException
Update a bean in the database

Parameters:
bean - Object to be updated within the database
mySQLConnection - Connection to the database
command - SQL command to run (with ? characters representing substitutions)
beanMapping - Description of the Parameter
Throws:
DatabaseErrorException - Caused by any exception on the way

getNewId

public int getNewId(java.sql.Connection mySQLConnection,
                    java.lang.String getCurrentIdCommand,
                    java.lang.String saveUpdatedIdCommand)
             throws DatabaseErrorException
Gets the newId attribute of the Database object

Parameters:
getCurrentIdCommand - Description of the Parameter
saveUpdatedIdCommand - Description of the Parameter
mySQLConnection - Description of the Parameter
Returns:
The newId value
Throws:
DatabaseErrorException - Description of the Exception