gov.grants.apply.dao
Class GetOpportunityListDao

java.lang.Object
  extended bygov.grants.apply.dao.GetOpportunityListDao

public class GetOpportunityListDao
extends java.lang.Object

Author:
Enoch Moses GetOpportunity Data Access Object (DAO). This class contains all database handling that is needed to permanently store and retrieve GetOpportunity object instances. Modified to work w

Constructor Summary
GetOpportunityListDao()
           
 
Method Summary
 int countAll(java.sql.Connection conn)
          coutAll-method.
 void create(java.sql.Connection conn, GetOpportunityList valueObject)
          create-method.
protected  int databaseUpdate(java.sql.Connection conn, java.sql.PreparedStatement stmt)
          databaseUpdate-method.
 void delete(java.sql.Connection conn, GetOpportunityList valueObject)
          delete-method.
 void deleteAll(java.sql.Connection conn)
          deleteAll-method.
 java.lang.String getDaogenVersion()
          getDaogenVersion will return information about generator which created these sources.
protected  java.util.List listQuery(java.sql.Connection conn, java.sql.PreparedStatement stmt)
          databaseQuery-method.
 void load(java.sql.Connection conn, GetOpportunityList valueObject)
          load-method.
 java.util.List loadAll(java.sql.Connection conn)
          LoadAll-method.
 void save(java.sql.Connection conn, GetOpportunityList valueObject)
          save-method.
 java.util.List searchMatching(java.sql.Connection conn, GetOpportunityList valueObject)
          searchMatching-Method.
protected  void singleQuery(java.sql.Connection conn, java.sql.PreparedStatement stmt, GetOpportunityList valueObject)
          databaseQuery-method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GetOpportunityListDao

public GetOpportunityListDao()
Method Detail

load

public void load(java.sql.Connection conn,
                 GetOpportunityList valueObject)
          throws java.sql.SQLException
load-method. This will load valueObject contents from database using Primary-Key as identifier. Upper layer should use this so that valueObject instance is created and only primary-key should be specified. Then call this method to complete other persistent information. This method will overwrite all other fields except primary-key and possible runtime variables. If load can not find matching row, NotFoundException will be thrown.

Parameters:
conn - This method requires working database connection.
valueObject - This parameter contains the class instance to be loaded. Primary-key field must be set for this to work properly.
Throws:
java.sql.SQLException

loadAll

public java.util.List loadAll(java.sql.Connection conn)
                       throws java.sql.SQLException
LoadAll-method. This will read all contents from database table and build an Vector containing valueObjects. Please note, that this method will consume huge amounts of resources if table has lot's of rows. This should only be used when target tables have only small amounts of data.

Parameters:
conn - This method requires working database connection.
Throws:
java.sql.SQLException

create

public void create(java.sql.Connection conn,
                   GetOpportunityList valueObject)
            throws java.sql.SQLException
create-method. This will create new row in database according to supplied valueObject contents. Make sure that values for all NOT NULL columns are correctly specified. Also, if this table does not use automatic surrogate-keys the primary-key must be specified. After INSERT command this method will read the generated primary-key back to valueObject if automatic surrogate-keys were used.

Parameters:
conn - This method requires working database connection.
valueObject - This parameter contains the class instance to be created. If automatic surrogate-keys are not used the Primary-key field must be set for this to work properly.
Throws:
java.sql.SQLException

save

public void save(java.sql.Connection conn,
                 GetOpportunityList valueObject)
          throws NotFoundException,
                 java.sql.SQLException
save-method. This method will save the current state of valueObject to database. Save can not be used to create new instances in database, so upper layer must make sure that the primary-key is correctly specified. Primary-key will indicate which instance is going to be updated in database. If save can not find matching row, NotFoundException will be thrown.

Parameters:
conn - This method requires working database connection.
valueObject - This parameter contains the class instance to be saved. Primary-key field must be set for this to work properly.
Throws:
NotFoundException
java.sql.SQLException

delete

public void delete(java.sql.Connection conn,
                   GetOpportunityList valueObject)
            throws java.sql.SQLException
delete-method. This method will remove the information from database as identified by by primary-key in supplied valueObject. Once valueObject has been deleted it can not be restored by calling save. Restoring can only be done using create method but if database is using automatic surrogate-keys, the resulting object will have different primary-key than what it was in the deleted object. If delete can not find matching row, NotFoundException will be thrown.

Parameters:
conn - This method requires working database connection.
valueObject - This parameter contains the class instance to be deleted. Primary-key field must be set for this to work properly.
Throws:
java.sql.SQLException

deleteAll

public void deleteAll(java.sql.Connection conn)
               throws java.sql.SQLException
deleteAll-method. This method will remove all information from the table that matches this Dao and ValueObject couple. This should be the most efficient way to clear table. Once deleteAll has been called, no valueObject that has been created before can be restored by calling save. Restoring can only be done using create method but if database is using automatic surrogate-keys, the resulting object will have different primary-key than what it was in the deleted object. (Note, the implementation of this method should be different with different DB backends.)

Parameters:
conn - This method requires working database connection.
Throws:
java.sql.SQLException

countAll

public int countAll(java.sql.Connection conn)
             throws java.sql.SQLException
coutAll-method. This method will return the number of all rows from table that matches this Dao. The implementation will simply execute "select count(primarykey) from table". If table is empty, the return value is 0. This method should be used before calling loadAll, to make sure table has not too many rows.

Parameters:
conn - This method requires working database connection.
Throws:
java.sql.SQLException

searchMatching

public java.util.List searchMatching(java.sql.Connection conn,
                                     GetOpportunityList valueObject)
                              throws java.sql.SQLException
searchMatching-Method. This method provides searching capability to get matching valueObjects from database. It works by searching all objects that match permanent instance variables of given object. Upper layer should use this by setting some parameters in valueObject and then call searchMatching. The result will be 0-N objects in vector, all matching those criteria you specified. Those instance-variables that have NULL values are excluded in search-criteria.

Parameters:
conn - This method requires working database connection.
valueObject - This parameter contains the class instance where search will be based. Primary-key field should not be set.
Throws:
java.sql.SQLException

getDaogenVersion

public java.lang.String getDaogenVersion()
getDaogenVersion will return information about generator which created these sources.


databaseUpdate

protected int databaseUpdate(java.sql.Connection conn,
                             java.sql.PreparedStatement stmt)
                      throws java.sql.SQLException
databaseUpdate-method. This method is a helper method for internal use. It will execute all database handling that will change the information in tables. SELECT queries will not be executed here however. The return value indicates how many rows were affected. This method will also make sure that if cache is used, it will reset when data changes.

Parameters:
conn - This method requires working database connection.
stmt - This parameter contains the SQL statement to be excuted.
Throws:
java.sql.SQLException

singleQuery

protected void singleQuery(java.sql.Connection conn,
                           java.sql.PreparedStatement stmt,
                           GetOpportunityList valueObject)
                    throws java.sql.SQLException
databaseQuery-method. This method is a helper method for internal use. It will execute all database queries that will return only one row. The resultset will be converted to valueObject. If no rows were found, NotFoundException will be thrown.

Parameters:
conn - This method requires working database connection.
stmt - This parameter contains the SQL statement to be excuted.
valueObject - Class-instance where resulting data will be stored.
Throws:
java.sql.SQLException

listQuery

protected java.util.List listQuery(java.sql.Connection conn,
                                   java.sql.PreparedStatement stmt)
                            throws java.sql.SQLException
databaseQuery-method. This method is a helper method for internal use. It will execute all database queries that will return multiple rows. The resultset will be converted to the List of valueObjects. If no rows were found, an empty List will be returned.

Parameters:
conn - This method requires working database connection.
stmt - This parameter contains the SQL statement to be excuted.
Throws:
java.sql.SQLException