|
Last
revision of this document: |
This
is document contains the code for Class JS_ErrDB_Project_Set_DBA.
For
easy 'cut and paste' ;-)
package
js_errdb.dba;
import
java.sql.*;
import
js_errdb.dba.JS_ErrDB_Project_DBA;
import
js_base.dba.*;
import
js_base.structures.JSBS_MinimalParameters;
/**
*
* @author kurt@javascout.biz
*
@date 2007-01-11
*
* @description
*
Data-Base-Access (DBA) Object to read a set of data from the
table 'Project'.
*
* Please see the description at the
variables-declaration.
*
* User-Key: ProjectCode & LanguageCode.
*
* @change-log
*
when who why
*
--------------------------------------------------------
*
*/
public
class JS_ErrDB_Project_Set_DBA
extends
JSBS_DBA_Set
{
/*
* --------------------
*
Method to read all valid (at the given date) records from the table
Project'. */
public
synchronized void
getAllValidProjectLanguageCombinations(
Connection
parmDBCon, JSBS_MinimalParameters parmMinParm) {
/*
* Build
the SQL-statement.
* Use the CONSTANTs to avoid typing
errors !
* The
Command is put into an extra String (and not into the
prepareStatement method)
* to see more clearly what the
command is. */
final String
locstrSQLCommand =
JS_ErrDB_Project_DBA.CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
JS_ErrDB_Project_DBA.CONST_ValidTill
+
" >=?"
+
"
order by " +
JS_ErrDB_Project_DBA.CONST_ProjectCode
+ ",
"
+
JS_ErrDB_Project_DBA.CONST_LanguageCode
+ ", "
+
JS_ErrDB_Project_DBA.CONST_ValidFrom
+ ", "
+
JS_ErrDB_Project_DBA.CONST_ValidTill
+ "
desc";
/* Convert
the actual date to the SQL-format. */
Date
locdteActualDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
/* 'PreparedStatement';
a special class for operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/* Construct
the 'PreparedStatement' and fill it with the SQL-command.
*/
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/* Fill
the variable(s) in the 'PreparedStatement'.
*/
SQLStatement.setDate(1,
locdteActualDate);
/* Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* Transfer
the data from the ResultSet to the vector used for returning data.
*/
vecRecordSet.removeAllElements();
for (;;)
{
/* Read one record after the
other from the ResultSet */
if (!SQLResultSet.next())
return;
/* Check
if the validity is not in the future.
* Variables an
method are defined in the inherited class.
*/
locdteReadValidFrom =
SQLResultSet.getDate(JSBS_DBA.CONST_ValidFrom);
locdteReadValidTill =
SQLResultSet.getDate(JSBS_DBA.CONST_ValidTill);
if (isWithinDateRange(locdteActualDate,
locdteReadValidFrom,
locdteReadValidTill))
{
/* SQL-record
within date-range;
* construct a object corresponding
to one SQL-record (the DBA-object) and
* transfer the
data using the method of the constructed class.
*/
JS_ErrDB_Project_DBA
locstructJS_ErrDB_Project_DBA = new
JS_ErrDB_Project_DBA();
locstructJS_ErrDB_Project_DBA.getValuesFromSQLResultSet(SQLResultSet);
/* Add
this structure to the vector with the resulting DBA-objects.
* This
vector is defined in the inherited class.
*/
vecRecordSet.addElement(locstructJS_ErrDB_Project_DBA);
}
}
}
catch (SQLException
SQLExc) {
/* An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
}
}
}