|
Letzte
Bearbeitung dieses Dokuments: |
Code
Erklärungen
und Anwendungsbeispiele
Verwandte
Dokumentation
package
js_base.dba;
/*
*
de: Package für die Verbindung zur Datenbank.
*
en: Package for the connection to the database. */
import
java.sql.*;
/*
*
de: Package mit der Basisklasse für ein Database-Access Objekt.
*
en: Package with the baseclass for a database-access object. */
import
js_base.dba.JSBS_DBA;
/*
*
de:
*
Package mit der Klasse mit dem minimalen Set an Parametern. Diese enthält das Arbeitsdatum.
*
Das Arbeitsdatum wird für die Selektion bei verschiedenen Abfragen gebraucht.
*
en:
*
Package with the class with the minimal set of parameters. Those contains the working-date.
*
The working-date is needed for the selection at different database requests. */
import
js_base.structures.JSBS_MinimalParameters;
/**
*
* @author kurt[at]javascout(dot)biz
*
@date 2007-07-17
*
* @description
*
de:
*
Data-Base-Access (DBA) Objekt für die Tabelle 'Parameter'.
*
*
Diese Tabelle ist etwas unterschiedlich zu anderen DB-Tabellen.
*
'Parameter' enthält verschiedene Business Objects - wobei jedes BO
*
nur eine geringe Anzahl von Datensätzen umfasst - innerhalb einer Datenbank-Tabelle.
*
*
Deswegen können die Datensätze verschiedener Business Objects können innerhalb einer
*
einzigen Datenbank-Tabelle gespeichert werden. Das vermeidet ein unnötiges Wachsen
*
der Namen der Datenbank-Tabelle und spart Speicherplatz.
*
*
Bitte beachten Sie die Beschreibungen bei der Deklaration der Variablen.
*
*
Anwender-bekannter Schlüssel: ParameterName, Value01, Value02, Value03, Value04, Value05.
*
*
en: *
Data-Base-Access (DBA) Object for the table
'Parameter'.
*
* This table is slightly different to other DB-tables:
* 'Parameter'
represents different Business Objects – where each BO
has
* only a few numbers of datasets –
within one database-table.
*
* So, the
datasets of different Business Objects can be stored within only
one
* database-table. This avoids a needless
growth of table-names and saves storage space.
*
* Please
see the description at the variables-declaration.
*
* User-Key: ParameterName, Value01, Value02,
Value03, Value04, Value05.
*
* @change-log
*
when who why
*
--------------------------------------------------------
* 2010-04-27 KG Added Method selectByObjectID(...)
* 2011-01-22 KG Added Methods needed for the sychronization when using 'MobileClient'. *
*/
public
class JSBS_Parameter_DBA
extends
JSBS_DBA
{
/*
*
VARIABLE / VARIABLES
* -------------------- */
/*
*
de:
*
ParameterName; das ist die Referenz, welches Business Object dem Datensatz zugeordnet ist.
*
en: *
ParameterName; that is the reference which Business Object is mapped
to the record. */
public
String
ParameterName
=
"";
/*
*
de:
*
Value / Wert (01 .. 20); der Daten-Inhalt hängt von der Definition innerhalb des
*
Business Object (besonders im Server-Side Teil - BOS) ab, das dieses DBA verwendet.
*
Die Zuordnung des Attribut-Wertes eine Business Object zum Attribut dieses DBA - und
*
umgekehrt - ist in den Methoden 'setDBAAttributes' (BOS-Klasse) und 'getDBAAttributes'
*
(BO-Klasse) festgelegt.
*
en: *
Value (01 .. 20); data-content depending on the definition within the
Business Object
* (particularly the
Server-Side-derivation – BOS) using this DBA.
* The
mapping of the attribute-value of a Business Object to the attribute
of this DBA
* - and vice-versa – is defined
within the methods 'setDBAAttributes' (BOS-class)
and
* 'getDBAAttributes' (BO-class). */
public
String
Value01
=
"";
public
String
Value02
=
"";
public
String
Value03
=
"";
public
String
Value04
=
"";
public
String
Value05
=
"";
public
String
Value06
=
"";
public
String
Value07
=
"";
public
String
Value08
=
"";
public
String
Value09
=
"";
public
String
Value10
=
"";
public
String
Value11
=
"";
public
String
Value12
=
"";
public
String
Value13
=
"";
public
String
Value14
=
"";
public
String
Value15
=
"";
public
String
Value16
=
"";
public
String
Value17
=
"";
public
String
Value18
=
"";
public
String
Value19
=
"";
public
String
Value20
=
"";
/*
*
de:
*
KONSTANTEN für den Namen der Datenbank-Tabelle, Attribut-Namen und Attributs-Liste für
*
SELECT und UPDATE.
*
--------------------
*
Eine detaillierte Beschreibung für jedes Attribut finden Sie unter VARIABLE.
*
*
en:
*
CONSTANTS for database-table name, attribute names and attribute
lists for SELECT and UPDATE
* --------------------
* For
a detailed description of each attribute please see under VARIABLES.
*/
/*
* de: Name der Datenbank-Tabelle.
*
en: Name of the database-table. */
protected
final static String
CONST_TABLE_NAME
=
"Parameter";
/*
*
de: Namen der Datenbank-Attribute.
*
en: Name of the database-attributes. */
protected
final static String
CONST_ParameterName
=
"ParameterName";
protected
final static String
CONST_Value01
=
"Value01";
protected
final static String
CONST_Value02
=
"Value02";
protected
final static String
CONST_Value03
=
"Value03";
protected
final static String
CONST_Value04
=
"Value04";
protected
final static String
CONST_Value05
=
"Value05";
protected
final static String
CONST_Value06
=
"Value06";
protected
final static String
CONST_Value07
=
"Value07";
protected
final static String
CONST_Value08
=
"Value08";
protected
final static String
CONST_Value09
=
"Value09";
protected
final static String
CONST_Value10
=
"Value10";
protected
final static String
CONST_Value11
=
"Value11";
protected
final static String
CONST_Value12
=
"Value12";
protected
final static String
CONST_Value13
=
"Value13";
protected
final static String
CONST_Value14
=
"Value14";
protected
final static String
CONST_Value15
=
"Value15";
protected
final static String
CONST_Value16
=
"Value16";
protected
final static String
CONST_Value17
=
"Value17";
protected
final static String
CONST_Value18
=
"Value18";
protected
final static String
CONST_Value19
=
"Value19";
protected
final static String
CONST_Value20
=
"Value20";
/*
*
de:
*
Zeichenkette mit allen Attributen;
*
kann verwendet werden für SELECT- und INSERT-Operationen auf Datenbank-Tabellen.
*
en: *
String with all attributes;
* can be used when
accessing database-tables for SELECT and INSERT. */
final
static String
CONST_ALL_ATTRIBUTES_LIST
=
CONST_COMMON_ATTRIBUTES_LIST
+
",
" +
CONST_ParameterName
+
",
" +
CONST_Value01
+
",
" +
CONST_Value02
+
",
" +
CONST_Value03
+
",
" +
CONST_Value04
+
",
" +
CONST_Value05
+
",
" +
CONST_Value06
+
",
" +
CONST_Value07
+
",
" +
CONST_Value08
+
",
" +
CONST_Value09
+
",
" +
CONST_Value10
+
",
" +
CONST_Value11
+
",
" +
CONST_Value12
+
",
" +
CONST_Value13
+
",
" +
CONST_Value14
+
",
" +
CONST_Value15
+
",
" +
CONST_Value16
+
",
" +
CONST_Value17
+
",
" +
CONST_Value18
+
",
" +
CONST_Value19
+
",
" +
CONST_Value20;
/*
*
de:
*
Zeichenkette mit allen Attributen für UPDATE-Operation auf Datensätze der Datenbank.
*
en: *
String with all attributes to be used for UPDATE on database-records.
*/
final
static String
CONST_ALL_ATTRIBUTES_LIST_FOR_UPDATE
=
"update
" +
CONST_TABLE_NAME
+
"
set " +
CONST_COMMON_ATTRIBUTES_LIST_FOR_UPDATE
+
CONST_ParameterName
+
"
=?, " +
CONST_Value01
+
"
=?, " +
CONST_Value02
+
"
=?, " +
CONST_Value03
+
"
=?, " +
CONST_Value04
+
"
=?, " +
CONST_Value05
+
"
=?, " +
CONST_Value06
+
"
=?, " +
CONST_Value07
+
"
=?, " +
CONST_Value08
+
"
=?, " +
CONST_Value09
+
"
=?, " +
CONST_Value10
+
"
=?, " +
CONST_Value11
+
"
=?, " +
CONST_Value12
+
"
=?, " +
CONST_Value13
+
"
=?, " +
CONST_Value14
+
"
=?, " +
CONST_Value15
+
"
=?, " +
CONST_Value16
+
"
=?, " +
CONST_Value17
+
"
=?, " +
CONST_Value18
+
"
=?, " +
CONST_Value19
+
"
=?, " +
CONST_Value20
+
"
=? "+
"
where ";
/*
*
de:
*
Zeichenkette für alle Attribute bei einer SELECT-Operation.
*
en: *
String to get all attributes at a SELECT operation. */
final
static String
CONST_SELECT_ALL_ATTRIBUTES
=
"select
" +
CONST_ALL_ATTRIBUTES_LIST
+
"
from " +
CONST_TABLE_NAME;
/*
* METHODEN / METHODS
* --------------------------
*/
/* --------------------------
*
* de:
* METHODE zum Übertragen der Werte vom SQL-ResultSet (eine Klasse innerhalb des Package
* java.sql die durch ein SELECT gefüllt wird) in die Variablen dieser Klasse.
* en:
* METHOD to
transfer the values from the SQL-ResultSet (a class within the
package
* java.sql that is filled by a SELECT) to the
variables of this class. */
public
void getValuesFromSQLResultSet(ResultSet
parmSQLResultSet)
throws SQLException
{
/*
* de:
* Methode der geerbten Superklasse aufrufen um die Werte der Common Attributes
* (Allgemeine Attribute) zu übertragen
* en:
* Use
the method from the inherited superclass to transfer values of Common
Attributes.
*/
try {
getSQLResultSetForCommonAttributes(parmSQLResultSet);
}
catch (SQLException
SQLExc) {throw SQLExc;}
/*
* de: Übertragen der Werte der spezifischen Attribute dieser Tabelle.
* en: Transfer
the values of table-specific attributes.
*/
try {
this.ParameterName
=
parmSQLResultSet.getString(CONST_ParameterName);
this.Value01
=
parmSQLResultSet.getString(CONST_Value01);
this.Value02
=
parmSQLResultSet.getString(CONST_Value02);
this.Value03
=
parmSQLResultSet.getString(CONST_Value03);
this.Value04
=
parmSQLResultSet.getString(CONST_Value04);
this.Value05
=
parmSQLResultSet.getString(CONST_Value05);
this.Value06
=
parmSQLResultSet.getString(CONST_Value06);
this.Value07
=
parmSQLResultSet.getString(CONST_Value07);
this.Value08
=
parmSQLResultSet.getString(CONST_Value08);
this.Value09
=
parmSQLResultSet.getString(CONST_Value09);
this.Value10
=
parmSQLResultSet.getString(CONST_Value10);
this.Value11
=
parmSQLResultSet.getString(CONST_Value11);
this.Value12
=
parmSQLResultSet.getString(CONST_Value12);
this.Value13
=
parmSQLResultSet.getString(CONST_Value13);
this.Value14
=
parmSQLResultSet.getString(CONST_Value14);
this.Value15
=
parmSQLResultSet.getString(CONST_Value15);
this.Value16
=
parmSQLResultSet.getString(CONST_Value16);
this.Value17
=
parmSQLResultSet.getString(CONST_Value17);
this.Value18
=
parmSQLResultSet.getString(CONST_Value18);
this.Value19
=
parmSQLResultSet.getString(CONST_Value19);
this.Value20
=
parmSQLResultSet.getString(CONST_Value20);
}
catch (SQLException
SQLExc) {throw SQLExc;}
}
/* --------------------
* de:
* METHODE zum Übertragen der der Werte der Variablen dieser Klasse auf das PreparedStatement.
* PreparedStatement ist eine Klasse innerhalb des Package java.sql das den SQL-Befehl
* (SQL-Statement) und die neuen Werte für die Attribute bevor ein INSERT oder UPDATE
* aufgerufen wird.
* en:
* METHOD
to transfer the values from the variables of this class to the
PreparedStatement.
* PreparedStatement is a class
within the package java.sql that contains the SQL-Statement
* and
the new values for the attributes before a INSERT or UPDATE is
called. */
public
void setValuesToSQLStatement(PreparedStatement
parmSQLStatement)
throws SQLException
{
/*
* de:
* Methode der geerbten Superklasse aufrufen um die Werte der Allgemeinen Attribute
* (Common Attributes) zu übertragen.
* en:
* Use
the method from the inherited superclass to transfer values of Common
Attributes.
*/
try {
setSQLStatementWithCommonAttributes(parmSQLStatement);
}
catch (SQLException
SQLExc) {throw SQLExc;}
/*
* de: Werte der spezifischen Attribute der Tabelle übertragen.
* en: Transfer
the values of table-specific attributes. */
try {
parmSQLStatement.setString(10,
ParameterName);
parmSQLStatement.setString(11,
Value01);
parmSQLStatement.setString(12,
Value02);
parmSQLStatement.setString(13,
Value03);
parmSQLStatement.setString(14, Value04);
parmSQLStatement.setString(15, Value05);
parmSQLStatement.setString(16, Value06);
parmSQLStatement.setString(17, Value07);
parmSQLStatement.setString(18, Value08);
parmSQLStatement.setString(19, Value09);
parmSQLStatement.setString(20, Value10);
parmSQLStatement.setString(21, Value11);
parmSQLStatement.setString(22, Value12);
parmSQLStatement.setString(23, Value13);
parmSQLStatement.setString(24, Value14);
parmSQLStatement.setString(25, Value15);
parmSQLStatement.setString(26, Value16);
parmSQLStatement.setString(27, Value17);
parmSQLStatement.setString(28, Value18);
parmSQLStatement.setString(29, Value19);
parmSQLStatement.setString(30,
Value20);
}
catch (SQLException
SQLExc) {throw SQLExc;}
}
/* --------------------
* de:
* METHODE zum Einfügen (INSERT) der Werte in den Variablen dieses Objekts in die
* Datenbank-Tabelle.
* Voraussetzung ist, dass der DataSetID (Primärschlüssel der Tabelle) zuvor geprüft
* wurde, ob nicht bereits ein Datensatz mit dem gleichen Wert in der Tabelle existiert.
* en:
* METHOD
to INSERT the values in the variables of this object into the
database-table.
* Prerequisite is, that the DataSetId
(Primary Key of the table) was checked before that
* another
record with the same DataSetId does not already exist in the table.
*/
public
void insert(Connection
parmDBCon) {
/*
* de:
* Aufbauen des SQL-Kommandos in einer eigenen Zeichenkette (String).
* Das Kommando in einer eigenen Zeichenkette (und nicht als Parameter in der Methode
* 'prepareStatement') zeigt klarer den Aufbau des Kommandos.
* en:
* Build
the SQL-Command in a String.
* The Command is put into
an extra String (and not as parameter of the 'prepareStatement'
* method) to
see more clearly what the content of the command. */
final String
locstrSQLCommand = "insert
into " +
CONST_TABLE_NAME
+
"
(" +
CONST_ALL_ATTRIBUTES_LIST
+
")
VALUES (" +
"?,
?, ?, ?, ?, ?, ?, ?, ?, "
+
"?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
/*
* de: 'PreparedStatement'; eine spezielle Klasse für INSERT und UPDATE Operationen auf die Datenbank.
* en: 'PreparedStatement';
a special class for INSERT and UPDATE operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/*
* de: 'PreparedStatement' mit dem SQL-Kommando füllen.
* en: Fill
the 'PreparedStatement' with the SQL-command.
*/
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/*
* de: Übertragen der Attribute von diesem Objekt in das 'PreparedStatement'.
* en: Transfer
the attributes from this object to the 'PreparedStatement'.
*/
setValuesToSQLStatement(SQLStatement);
/*
* de: Datenbank-Operation für das INSERT ausführen.
* en: Perform
the database-operation for INSERT.
*/
SQLStatement.executeUpdate();
/*
* de:
* Datenbank-Operation wurde ohne Fehler ausgeführt; dieses durch eine leere Zeichenkette an die
* aufrufende Methode zurück melden.
* en:
* Database
operation run without an error; report this to the calling method by
an empty string. */
ErrorMsg =
"";
}
catch (SQLException
SQLExc) {
/*
* de: Ein Fehler ist bei der DB-Operation aufgetreten; Fehler-Meldung holen.
* en: An
error occured while running the DB-operation; get the error
message. */
ErrorMsg =
SQLExc.getMessage();
}
}
/* --------------------
* de:
* METHODE zum Ändern (UPDATE) eines bestehenden Datensatzes in der DB-Tabelle.
* Das ist eine 'Wrapper-Methode' für einen einfacheren Aufruf der Methode wenn
* der Primärschlüssel (DataSetID) nicht verändert werden muss.
* 'Connection' ist eine Klasse aus dem Package 'java.sql' und enthält die
* Verbindung zum Datenbanksystem.
*
* en: * METHOD
to change (UPDATE) an existing record of the DB-table.
* This is a 'wrapper-method' for a simpler call of the method if the primary-key
* (DataSetID) does not have to be changed.
* 'Connection' is a class of the package 'java.sql' and contains the connection to * the database-system. */
public
void update(Connection
parmDBCon) {
/*
* de: Aufrufen der Methode in der die eigentliche Arbeit gemacht wird.
* en: Call the method where the real work is done. */
update(parmDBCon, 0);
}
/*
* de:
* METHODE zum Ändern eines bestehenden Datensatzes in der DB-Tabelle wobei auch der
* Primärschlüssel (DataSetID) geändert werden kann.
* Das Ändern des Wertes von DataSetID kann nötig sein wenn in der Version 'MobileClient'
* auf dem 'asynchronen' Gerät und auf dem Server zufällig ein gleicher Wertfür den
* DataSetID generiert wurde.
* Dann muss auf der Datenbank des mobilen Client mit dieser Methode der DataSetID
* (Primärschlüssel) geändert werden.
* Ist der Wert im Parameter 'parmDataSetIDToSelect' 0, dann wird der Wert von DataSetID
* nicht geändert.
* 'Connection' ist eine Klasse aus dem package 'java.sql' und enthält die Verbindung
* zum Datenbanksystem.
*
* en:
* METHOD to change an existing dataset of the DB-table where the primary-key (DataSetID)
* can be changed, too.
* The change of the value of DataSetID may be neccessary if accidentally an identical value
* is assigned on the 'asynchronous' client and on the server in the version 'MobileClient'.
* Then, on the database of the mobile client, the value of the DataSetID (primary-key)
* must be changed.
* If the value of the parameter 'parmDataSetIDToSelect' is 0, then the value of DataSetID will
* not be changed. * 'Connection' is a class of the package 'java.sql' and contains the connection to * the database-system. */
public
void update(Connection
parmDBCon, double parmDataSetIDToSelect) {
/*
* de:
* Definieren der Variablen mit dem DataSetID der später für die Selektion beim
* Datenbank-Zugriff verwendet wird.
* en:
* Define the variables with the DataSetID that is used later for the selection at the
* database-access. */
double dblDataSetIDToSelect;
/*
* de:
* Wenn im Parameter der Wert '0' übergeben wurde, dann wird für die Selektion von der
* Datenbank der Wert aus diesem Objekt verwendet.
* en:
* If the value '0' was passed within the parameter, then the value of this object is used
* for the selection from the database. */
if (parmDataSetIDToSelect == 0) dblDataSetIDToSelect = this.DataSetID;
/*
* de:
* Wenn im Parameter ein Wert übergeben wurde, dann wird der Wert aus dem Parameter
* für die Selektion von der Datenbank verwendet.
* en:
* If a value was passed within the parameter, then the value of the parameter is used
* for the selection from the database. */
else dblDataSetIDToSelect = parmDataSetIDToSelect;
/*
* de:
* Aufbauen des SQL-Kommandos in einer eigenen Zeichenkette (String).
* Das Kommando in einer eigenen Zeichenkette (und nicht als Parameter in der Methode
* 'prepareStatement') zeigt klarer den Aufbau des Kommandos.
* en:
* Build
the SQL-Command in a String.
* The Command is put into
an extra String (and not as parameter of the 'prepareStatement'
* method) to
see more clearly what the content of the command. */
final String
locstrSQLCommand = CONST_ALL_ATTRIBUTES_LIST_FOR_UPDATE
+
CONST_DataSetID
+
"
=?";
/*
* de: 'PreparedStatement'; eine spezielle Klasse für INSERT und UPDATE Operationen auf die Datenbank.
* en: 'PreparedStatement';
a special class for INSERT and UPDATE operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/*
* de: 'PreparedStatement' mit dem SQL-Kommando füllen.
* en: Fill
the 'PreparedStatement' with the SQL-command.
*/
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/*
* de: Übertragen der Attributs-Werte von diesem Objekt auf das 'PreparedStatement'
* en: Transfer
the attribute-values from this object to the 'PreparedStatement'.
*/
setValuesToSQLStatement(SQLStatement);
/*
* de:
* Übertragen des Primärschlüssels für die Selektion des zu ändernden Datensatzes in das
* 'PreparedStatement'.
* en:
* Transfer the primary-key for the selection of the dataset to be changed into the
* 'PreparedStatement'.
*/
SQLStatement.setDouble(31, dblDataSetIDToSelect);
/*
* de: Datenbank-Operation für das UPDATE ausführen.
* en: Perform
the database-operation for UPDATE.
*/
SQLStatement.executeUpdate();
/*
* de:
* Datenbank-Operation wurde ohne Fehler ausgeführt; dieses durch eine leere Zeichenkette an die
* aufrufende Methode zurück melden.
* en:
* Database
operation run without an error; report this to the calling method by
an empty string. */
ErrorMsg =
"";
}
catch (SQLException
SQLExc) {
/*
* de: Ein Fehler ist bei der DB-Operation aufgetreten; Fehler-Meldung holen.
* en: An
error occured while running the DB-operation; get the error
message. */
ErrorMsg =
SQLExc.getMessage();
}
}
/* --------------------
* de:
* METHODE zum Lesen eines Datensatzes der durch den DataSetID identifiziert wird.
* Nchdem dieses Attribut der Primärschlüssel ist kann nur ein Datensatz gefunden werden.
* Der zurück gelieferte Wert signalisiert ob der gesuchte Datensatz auf der
* Datenbank-Tabelle gefunden wurde.
*
* en: * METHOD
to read a record identified by the DataSetID.
* As
this attribute is the primary key of the table, only one record can
be found.
* The return value signals if the requested
record was found on the database-table. */
public
boolean selectByDataSetID(Connection
parmDBCon, double
parmDataSetID)
{
/*
* de:
* Aufbauen des SQL-Kommandos in einer eigenen Zeichenkette (String).
* Das Kommando in einer eigenen Zeichenkette (und nicht als Parameter in der Methode
* 'prepareStatement') zeigt klarer den Aufbau des Kommandos.
* en:
* Build
the SQL-Command in a String.
* The Command is put into
an extra String (and not as parameter of the 'prepareStatement'
* method) to
see more clearly what the content of the command. */
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_DataSetID
+
"
=?";
/*
* de: 'PreparedStatement'; eine spezielle Klasse für INSERT und UPDATE Operationen auf die Datenbank.
* en: 'PreparedStatement';
a special class for INSERT and UPDATE operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/*
* de: 'PreparedStatement' mit dem SQL-Kommando füllen.
* en: Fill
the 'PreparedStatement' with the SQL-command.
*/
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/*
* de:
* Übertragen des Primärschlüssels für die Selektion des zu ändernden Datensatzes in das
* 'PreparedStatement'.
* en:
* Transfer the primary-key for the selection of the dataset to be changed into the
* 'PreparedStatement'.
*/
SQLStatement.setDouble(1,
parmDataSetID);
/* de: Ausführen der Datenbank-Operation für das SELECT.
* en: Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* de: Prüfen ob ein Datensatz gefunden wurde.
* en: Verify
if a record was found */
if (!SQLResultSet.next())
{
/* de: Datensatz auf der Datenbank nicht vorhanden; über den Rückgabe-Wert an die aufrufende Methode signalisieren.
* en: No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* de:
* Datensatz auf der Datenbank vorhanden; Übertragen der Werte im 'SQLResultSet'
* auf die Variablen in diesem Objekt.
* en:
* Database-record
found; transfer the values of the 'SQLResultSet'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/* de:
* Operation auf die Datenbank ohne Fehler ausgeführt; an die aufrufende Methode durch eine
* leere Zeichenkette signalisieren.
* en:
* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* de: Während der DB-Operation ist ein Fehler aufgetreten; Beschriebungs-Text des Fehlers übernehmen.
* en: An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* de: Die Datenbank-Operation hat mit einem Fehler geendet; an die aufrufende Methode durch den Rückgabewert signalisieren.
* en: Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}
/* --------------------
* de:
* METHODE zum Lesen des Datensatzes der durch den ObjectID identifiziert wird.
* Ein Datensatz mit diesem Wert kann zu einem bestimmten Zeitpunkt nur einmal gültig sein -
* deswegen kann mit der SQL-Abfrage nur ein Datensatz gefunden werden.
* Die zurück gelieferte Variable signaliesiert ob der gefragte Datensatz in der Datenbank gefunden
* wurde.
* en: * METHOD
to read a Data-Set identified by the ObjectID.
* Only one dataset with this value can be valid at a given time - therfore only one dataset can be * found with the SQL-command.
* The
return value signals if the requested record was found on the
database-table. */
public
boolean selectByObjectID(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
double
parmObjectID) {
/*
* de:
* Aufbauen des SQL-Kommandos in einer Zeichenkette.
* Das Kommando wird zuerst in einer Zeichenkette codiert (und nicht direkt in der
* prepareStatement Methode) um das SQL-Kommando klarer erkennen zu können.
* en:
* Build
the SQL-Command in a String.
* 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 = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ObjectID
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* de: Umwandeln des aktuellen Datums (aus dem übergebenen Parametern) in das java.sql.Date Format.
* en: Convert
the actual date (in the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
/* de: 'PreparedStatement'; eine spezielle Klasse für Operationen auf die Datenbank.
* en: 'PreparedStatement';
a special class for operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/* de: 'PreparedStatement' erstellen und mit dem SQL-Kommando füllen.
* en: Construct
the 'PreparedStatement' and fill it with the SQL-command.
*/
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/* de: Füllen der Variablen im 'PreparedStatement'.
* en: Fill
the variables in the 'PreparedStatement'.
*/
SQLStatement.setDouble(1,
parmObjectID);
SQLStatement.setDate(2,
locdteWorkDate);
SQLStatement.setDate(3,
locdteWorkDate);
/* de: Ausführen der Datenbank-Operation für das SELECT.
* en: Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* de: Prüfen ob ein Datensatz gefunden wurde.
* en: Verify
if a record was found */
if (!SQLResultSet.next())
{
/* de: Datensatz auf der Datenbank nicht vorhanden; über den Rückgabe-Wert an die aufrufende Methode signalisieren.
* en: No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* de:
* Datensatz auf der Datenbank vorhanden; Übertragen der Werte im 'SQLResultSet'
* auf die Variablen in diesem Objekt.
* en:
* Database-record
found; transfer the values of the 'SQLResultSet'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* de: Prüfen ob die Gültigkeit des gefundenen Datensatzes nicht erst in der Zukunft startet.
* en: Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* de: Gefundener Datensatz noch nicht gültig; einen Status 'Nicht gefunden' zurückliefern.
* en: Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* de:
* Operation auf die Datenbank ohne Fehler ausgeführt; an die aufrufende Methode durch eine
* leere Zeichenkette signalisieren.
* en:
* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* de: Während der DB-Operation ist ein Fehler aufgetreten; Beschriebungs-Text des Fehlers übernehmen.
* en: An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* de: Die Datenbank-Operation hat mit einem Fehler geendet; an die aufrufende Methode durch den Rückgabewert signalisieren.
* en: Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}
/* --------------------
* de:
* METHODE zum Lesen des Datensatzes der durch den Anwender-bekannten Schlüssel identifiziert wird;
* für diese Objekt ist das die Kombination aus: ParameterName und Value01 .. 05.
* Diese Kombination kann zu einem bestimmten Zeitpunkt nur einmal vorkommen - deswegen kann
* mit der SQL-Abfrage nur ein Datensatz gefunden werden.
* Die zurück gelieferte Variable signaliesiert ob der gefragte Datensatz in der Datenbank gefunden
* wurde.
* en: * METHOD
to read a Data-Set identified by the User-Known-Key;
* for
this object it is the combination of: ParameterName and Value01 ..
05.
* As this combination can occur only once for a
certain time, only one record can be found.
* The
return value signals if the requested record was found on the
database-table. */
public
boolean selectByUserKnownKey(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03, String parmValue04, String parmValue05) {
/*
* de:
* Aufbauen des SQL-Kommandos in einer Zeichenkette.
* Das Kommando wird zuerst in einer Zeichenkette codiert (und nicht direkt in der
* prepareStatement Methode) um das SQL-Kommando klarer erkennen zu können.
* en:
* Build
the SQL-Command in a String.
* 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 = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and " +
CONST_Value01
+
"
=?" +
"
and " +
CONST_Value02
+
"
=?" +
"
and " +
CONST_Value03
+
"
=?" +
"
and " +
CONST_Value04
+
"
=?" +
"
and " +
CONST_Value05
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* de: Umwandeln des aktuellen Datums (aus dem übergebenen Parametern) in das java.sql.Date Format.
* en: Convert
the actual date (in the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
/* de: 'PreparedStatement'; eine spezielle Klasse für Operationen auf die Datenbank.
* en: 'PreparedStatement';
a special class for operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/* de: 'PreparedStatement' erstellen und mit dem SQL-Kommando füllen.
* en: Construct
the 'PreparedStatement' and fill it with the SQL-command.
*/
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/* de: Füllen der Variablen im 'PreparedStatement'.
* en: Fill
the variables in the 'PreparedStatement'.
*/
SQLStatement.setInt(1,
parmMinParm.intClientID);
SQLStatement.setString(2,
parmParameterName); SQLStatement.setString(3,
parmValue01);
SQLStatement.setString(4,
parmValue02);
SQLStatement.setString(5,
parmValue03);
SQLStatement.setString(6,
parmValue04);
SQLStatement.setString(7,
parmValue05);
SQLStatement.setDate(8,
locdteWorkDate);
SQLStatement.setDate(9,
locdteWorkDate);
/* de: Ausführen der Datenbank-Operation für das SELECT.
* en: Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* de: Prüfen ob ein Datensatz gefunden wurde.
* en: Verify
if a record was found */
if (!SQLResultSet.next())
{
/* de: Datensatz auf der Datenbank nicht vorhanden; über den Rückgabe-Wert an die aufrufende Methode signalisieren.
* en: No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* de:
* Datensatz auf der Datenbank vorhanden; Übertragen der Werte im 'SQLResultSet'
* auf die Variablen in diesem Objekt.
* en:
* Database-record
found; transfer the values of the 'SQLResultSet'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* de: Prüfen ob die Gültigkeit des gefundenen Datensatzes nicht erst in der Zukunft startet.
* en: Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* de: Gefundener Datensatz noch nicht gültig; einen Status 'Nicht gefunden' zurückliefern.
* en: Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* de:
* Operation auf die Datenbank ohne Fehler ausgeführt; an die aufrufende Methode durch eine
* leere Zeichenkette signalisieren.
* en:
* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* de: Während der DB-Operation ist ein Fehler aufgetreten; Beschriebungs-Text des Fehlers übernehmen.
* en: An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* de: Die Datenbank-Operation hat mit einem Fehler geendet; an die aufrufende Methode durch den Rückgabewert signalisieren.
* en: Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}/* --------------------
* Methods
that are derivations from the method to read by giving all attributes
of the User-Known-Key.
* These methods are used by Business
Objects that use less than Value01 .. 05 for the User-Known-Key.
*/
public
boolean selectByUserKnownKey(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03, String parmValue04) {
/* Build
the SQL-Command in a String.
* 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 = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and " +
CONST_Value01
+
"
=?" +
"
and " +
CONST_Value02
+
"
=?" +
"
and " +
CONST_Value03
+
"
=?" +
"
and " +
CONST_Value04
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* Convert
the actual date (in the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = 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.setInt(1,
parmMinParm.intClientID);
SQLStatement.setString(2,
parmParameterName); SQLStatement.setString(3,
parmValue01);
SQLStatement.setString(4,
parmValue02);
SQLStatement.setString(5,
parmValue03);
SQLStatement.setString(6,
parmValue04);
SQLStatement.setDate(7,
locdteWorkDate);
SQLStatement.setDate(8,
locdteWorkDate);
/* Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* Verify
if a record was found */
if (!SQLResultSet.next())
{
/* No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* Database-record
found; transfer the values of the 'PreparedStatement'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}
/*
***** */
public
boolean selectByUserKnownKey(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03) {
/* Build
the SQL-Command in a String.
* 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 = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and " +
CONST_Value01
+
"
=?" +
"
and " +
CONST_Value02
+
"
=?" +
"
and " +
CONST_Value03
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* Convert
the actual date (in the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = 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.setInt(1,
parmMinParm.intClientID);
SQLStatement.setString(2,
parmParameterName); SQLStatement.setString(3,
parmValue01);
SQLStatement.setString(4,
parmValue02);
SQLStatement.setString(5,
parmValue03);
SQLStatement.setDate(6,
locdteWorkDate);
SQLStatement.setDate(7,
locdteWorkDate);
/* Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* Verify
if a record was found */
if (!SQLResultSet.next())
{
/* No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* Database-record
found; transfer the values of the 'PreparedStatement'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}
/*
***** */
public
boolean selectByUserKnownKey(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String parmValue02) {
/* Build
the SQL-Command in a String.
* 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 = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and " +
CONST_Value01
+
"
=?" +
"
and " +
CONST_Value02
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* Convert
the actual date (in the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = 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.setInt(1,
parmMinParm.intClientID);
SQLStatement.setString(2,
parmParameterName); SQLStatement.setString(3,
parmValue01);
SQLStatement.setString(4,
parmValue02);
SQLStatement.setDate(5,
locdteWorkDate);
SQLStatement.setDate(6,
locdteWorkDate);
/* Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* Verify
if a record was found */
if (!SQLResultSet.next())
{
/* No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* Database-record
found; transfer the values of the 'PreparedStatement'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}
/*
***** */
public
boolean selectByUserKnownKey(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01) {
/* Build
the SQL-Command in a String.
* 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 = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and " +
CONST_Value01
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* Convert
the actual date (in the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = 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.setInt(1,
parmMinParm.intClientID);
SQLStatement.setString(2,
parmParameterName); SQLStatement.setString(3,
parmValue01);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setDate(5,
locdteWorkDate);
/* Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* Verify
if a record was found */
if (!SQLResultSet.next())
{
/* No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* Database-record
found; transfer the values of the 'PreparedStatement'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}
/*
***** */
public
boolean selectByUserKnownKey(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName) {
/* de:
* 'Bauen' des SQL-Kommandos in einer Zeichenkette.
* Das SQL-Kommando wird zuerst in einer eigenen Zeichenkette aufgebaut (und nicht gleich
* als Parameter der preparedStatement Methode) um das SQL-Kommando klar sehen zu können.
* Das ist hilfreich wenn es notwendig ist, den Debugger einzusetzen.
* en:
* Build
the SQL-Command in a String.
* The Command is put into
an extra String (and not into the prepareStatement method)
* to
see more clearly how the SQL-command looks like.
* This is helpful when debugging. */
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* de: Umwandeln des aktuellen Datums (aus den übergebenen Parametern) in das java.sql.Date Format.
* en: Convert
the actual date (from the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
/* de: 'PreparedStatement'; eine spezielle Klasse für Operationen auf die Datenbank.
* en: 'PreparedStatement';
a special class for operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/* de: 'PreparedStatement' konstruieren und mit dem SQL-Kommando füllen.
* en: Construct
the 'PreparedStatement' and fill it with the SQL-command.
*/
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/* de: Füllen der Variablen im 'PreparedStatement'.
* en: Fill
the variable(s) in the 'PreparedStatement'.
*/
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
/* de: Ausführen der Datenbank-Operation für ein SELECT.
* en: Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* Verify
if a record was found */
if (!SQLResultSet.next())
{
/* No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* Database-record
found; transfer the values of the 'PreparedStatement'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}
/* --------------------
* de:
* METHODE
zum Lesen eines Datensatzes, dessen Werte für den
Anwender-bekannten Schlüssel
* in der
Sortier-Reihenfolge nach den Werten, die als Parameter übergeben
werden, auftreten.
* Mit diesen Werten und dem
Arbeitsdatum (im Parameter JSBS_MinimalParameters enthalten)
* kann
maximal ein Datensatz gefunden werden.
* Über den
zurückgegebenen 'boolean' Wert wird der aufrufenden Methode
signalisiert,
* ob ein Datensatz gefunden
wurde.
* 'Connection' ist eine Klasse aus dem package
'java.sql' und verwaltet die
* Verbindung zum
Datenbanksystem.
* en:
* METHOD to read a
Data-Set which values for the User-Known-Key appear after the values
* passed as parameters in the sort order for the
User-Known-Key.
* With the values passed as parameters
and the 'working-date'
* (part of parameter
JSBS_MinimalParameters), only one record can be found.
* The
'boolean' return value signals if the requested record was found on
the database-table.
* 'Connection' is a class within
the package 'java.sql' and maintains the connection
* to
the database-system. */
public
boolean selectNext(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03, String parmValue04, String parmValue05) {
/* de:
* 'Bauen'
des SQL-Kommandos in einer eigenen Zeichenkette (und nicht gleich
in
* die 'prepareStetement' Methode) um beim Debuggen
klarer sehen zu können
* wie das SQL-Kommando
aussieht
* en:
* Build the SQL-Command in
an extra String (and not into the prepareStatement method)
* to
see more clearly what the command is when debugging.
*/
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
=?"
+ "
and "
+
CONST_Value04
+ "
=?"
+ "
and "
+
CONST_Value05
+ "
>?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
=?"
+ "
and "
+
CONST_Value04
+ "
>?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
>?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
>?"
+
")
or "
+ CONST_Value01
+ "
>?"
+
")
"
+
"
order by "
+ CONST_Value01
+ "
asc, "
+ CONST_Value02
+ "
asc, " +
CONST_Value03
+ "
asc, "
+ CONST_Value04
+ "
asc, " +
CONST_Value05
+ "
asc, "
+
CONST_ValidFrom
+ "
desc, "
+ CONST_ValidTill
+ "
asc " +
"
limit 1 ";
/* de:
Aktuelles Datum (aus den Parametern) in das java.sql.Date Format
konvertieren.
* en: Convert the actual date (in the
passed parameters) to the java.sql.Date format. */
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
/* de:
'PreparedStatemen'; eine spezielle Klasse die Kommandos auf der
Datenbank ausführt.
* en: 'PreparedStatement'; a
special class for operations toward the database.
*/
PreparedStatement
SQLStatement;
try {
/* de:
'PreparedStatement' 'konstruieren' und mit dem SQL-Kommando
füllen.
* en: Construct the 'PreparedStatement'
and fill it with the SQL-command. */
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
/* de:
Variable(n) im 'PreparedStatement' mit Werten füllen.
* en:
Fill the variable(s) in the 'PreparedStatement'.
*/
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue03);
SQLStatement.setString(8,
parmValue04);
SQLStatement.setString(9,
parmValue05);
SQLStatement.setString(10,
parmValue01);
SQLStatement.setString(11,
parmValue02);
SQLStatement.setString(12,
parmValue03);
SQLStatement.setString(13,
parmValue04);
SQLStatement.setString(14,
parmValue01);
SQLStatement.setString(15,
parmValue02);
SQLStatement.setString(16,
parmValue03);
SQLStatement.setString(17,
parmValue01);
SQLStatement.setString(18,
parmValue02);
SQLStatement.setString(19,
parmValue01);
/* de:
Datenbank-Operation für ein SELECT ausführen.
* en:
Perform the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/* de:
Prüfen ob ein Datensatz gefunden wurde.
* en:
Verify if a record was found */
if (!SQLResultSet.next())
{
/* de:
Kein Datensatz gefunden; an die aufrufende Methode über den
'return'-Wert signalisieren.
* en: No database-record
found; signal to the calling method by the return-value
*/
ErrorMsg =
"";
return
false;
}
else {
/* de:
* Datensatz
gefunden; Werte aus dem 'PreparedStatement' auf die
* Variablen
dieses Objektes übertragen.
* en:
* Database-record
found; transfer the values of the 'PreparedStatement'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/* de:
Zur Sicherheit noch einmal prüfenob der Datensatz nicht erst in
Zukunft gültig ist.
* en: Verify that the
validity of the found dataset does not start in the future –
just to be sure. */
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* de:
Gefundener Datensatz noch nicht gültig; den Status 'Not Found'
zurückliefern.
* en: Found dataset not already
valid; return a status of 'Not Found'. */
ErrorMsg =
"";
return
false;
}
/* de:
* Datenbank-Operation
ohne Fehler ausgeführt. dieses an die aufrufende Methode durch
eine
* leere Zeichenkette für die Fehler-Meldung
und den return-Wert melden.
* en:
* Database
operation run without an error; report this to the calling method by
an empty string
* for the error-message and the return
value. */
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* de:
* Ein Fehler ist beim Ausführen der DB-Operation
aufgetreten;
* Text-Nachricht des Datenbank-Systems
übernehmen.
* en:
* An error
occured while running the DB-operation; get the textual message of
the database-system. */
ErrorMsg =
SQLExc.getMessage();
/* de:
* Datenbank-Operation war mit Fehler;
* an
die aufrufende Methode melden, dass ein gültiger Datensatz
nicht gefunden wurde.
* en:
* Database
operation run with an error; report to the calling method that a
valid dataset was not found. */
return
false;
}
}
/* --------------------
* de:
* Methoden
die Abwandlung der Methode, zum Selektieren des nächsten
Datensatzes für einen
* Anwender-bekannten
Schlüssel bestehend aus Value01 bis Value05.
* Kommentare
für den Code entfallen weil die Methoden fast gleich der obigen
sind.
* en:
* Methods that are
derivations from the method to select the next dataset for a given
User-Known-Key
* consisting of Value01 till Value05.
*
The following methods are used by Business Objects that use less than
Value01 .. 05 for the User-Known-Key.
* Comments are
obeyed as the methods are nearly the same as the above method.
*/
public
boolean selectNext(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03, String parmValue04) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
=?"
+ "
and "
+
CONST_Value04
+ "
>?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
>?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
>?"
+
")
or "
+ CONST_Value01
+ "
>?"
+
")
"
+
"
order by "
+ CONST_Value01
+ "
asc, "
+ CONST_Value02
+ "
asc, " +
CONST_Value03
+ "
asc, "
+ CONST_Value04
+ "
asc, " +
CONST_Value05
+ "
asc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue03);
SQLStatement.setString(8,
parmValue04);
SQLStatement.setString(9,
parmValue01);
SQLStatement.setString(10,
parmValue02);
SQLStatement.setString(11,
parmValue03);
SQLStatement.setString(12,
parmValue01);
SQLStatement.setString(13,
parmValue02);
SQLStatement.setString(14,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
*/
public
boolean selectNext(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
>?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
>?"
+
")
or "
+ CONST_Value01
+ "
>?"
+
")
"
+
"
order by "
+ CONST_Value01
+ "
asc, "
+ CONST_Value02
+ "
asc, " +
CONST_Value03
+ "
asc, "
+ CONST_Value04
+ "
asc, " +
CONST_Value05
+ "
asc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue03);
SQLStatement.setString(8,
parmValue01);
SQLStatement.setString(9,
parmValue02);
SQLStatement.setString(10,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
*/
public
boolean selectNext(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String parmValue02) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
>?"
+
")
or "
+ CONST_Value01
+ "
>?"
+
")
"
+
"
order by "
+ CONST_Value01
+ "
asc, "
+ CONST_Value02
+ "
asc, " +
CONST_Value03
+ "
asc, "
+ CONST_Value04
+ "
asc, " +
CONST_Value05
+ "
asc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
*/
public
boolean selectNext(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and "
+ CONST_Value01
+ "
>?"
+
"
order by "
+ CONST_Value01
+ "
asc, "
+ CONST_Value02
+ "
asc, " +
CONST_Value03
+ "
asc, "
+ CONST_Value04
+ "
asc, " +
CONST_Value05
+ "
asc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
* de:
* METHODE
zum Lesen eines Datensatzes, dessen Werte für den
Anwender-bekannten Schlüssel
* in der
Sortier-Reihenfolge vor den Werten, die als Parameter übergeben
werden, auftreten.
* Kommentare
für den Code entfallen weil die Methoden fast gleich der Methoden selectNext(...)
sind.
* en:
* METHOD to read a
Data-Set which values for the User-Known-Key appear before the values
* passed as parameters in the sort order for the
User-Known-Key.
* Comments are
obeyed as the methods are nearly the same as the methods 'selectNext(...).
*/
public
boolean selectPrevious(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03, String parmValue04, String parmValue05) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
=?"
+ "
and "
+
CONST_Value04
+ "
=?"
+ "
and "
+
CONST_Value05
+ " <?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
=?"
+ "
and "
+
CONST_Value04
+ " <?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ " <?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ " <?"
+
")
or "
+ CONST_Value01
+ " <?"
+
")
"
+
"
order by "
+ CONST_Value01
+ " desc, "
+ CONST_Value02
+ " desc, " +
CONST_Value03
+ " desc, "
+ CONST_Value04
+ " desc, " +
CONST_Value05
+ " desc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
= parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue03);
SQLStatement.setString(8,
parmValue04);
SQLStatement.setString(9,
parmValue05);
SQLStatement.setString(10,
parmValue01);
SQLStatement.setString(11,
parmValue02);
SQLStatement.setString(12,
parmValue03);
SQLStatement.setString(13,
parmValue04);
SQLStatement.setString(14,
parmValue01);
SQLStatement.setString(15,
parmValue02);
SQLStatement.setString(16,
parmValue03);
SQLStatement.setString(17,
parmValue01);
SQLStatement.setString(18,
parmValue02);
SQLStatement.setString(19,
parmValue01);
ResultSet
SQLResultSet = SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
*/
public
boolean selectPrevious(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03, String parmValue04) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ "
=?"
+ "
and "
+
CONST_Value04
+ " <?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ " <?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ " <?"
+
")
or "
+ CONST_Value01
+ " <?"
+
")
"
+
"
order by "
+ CONST_Value01
+ " desc, "
+ CONST_Value02
+ " desc, " +
CONST_Value03
+ " desc, "
+ CONST_Value04
+ " desc, " +
CONST_Value05
+ " desc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue03);
SQLStatement.setString(8,
parmValue04);
SQLStatement.setString(9,
parmValue01);
SQLStatement.setString(10,
parmValue02);
SQLStatement.setString(11,
parmValue03);
SQLStatement.setString(12,
parmValue01);
SQLStatement.setString(13,
parmValue02);
SQLStatement.setString(14,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
*/
public
boolean selectPrevious(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String
parmValue02,
String
parmValue03) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ "
=?"
+ "
and "
+
CONST_Value03
+ " <?"
+
")
or ("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ " <?"
+
")
or "
+ CONST_Value01
+ " <?"
+
")
"
+
"
order by "
+ CONST_Value01
+ " desc, "
+ CONST_Value02
+ " desc, " +
CONST_Value03
+ " desc, "
+ CONST_Value04
+ " desc, " +
CONST_Value05
+ " desc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue03);
SQLStatement.setString(8,
parmValue01);
SQLStatement.setString(9,
parmValue02);
SQLStatement.setString(10,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
*/
public
boolean selectPrevious(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01, String parmValue02) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and (("
+ CONST_Value01
+ "
=?"
+ "
and "
+
CONST_Value02
+ " <?"
+
")
or "
+ CONST_Value01
+ " <?"
+
")
"
+
"
order by "
+ CONST_Value01
+ " desc, "
+ CONST_Value02
+ " desc, " +
CONST_Value03
+ " desc, "
+ CONST_Value04
+ " desc, " +
CONST_Value05
+ " desc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
SQLStatement.setString(6,
parmValue02);
SQLStatement.setString(7,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
*/
public
boolean selectPrevious(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue01) {
final String
locstrSQLCommand = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and "
+ CONST_ValidFrom
+ "
<=?"
+
"
and "
+ CONST_ValidTill
+ "
>=?"
+
"
and "
+ CONST_Value01
+ " <?"
+
"
order by "
+ CONST_Value01
+ " desc, "
+ CONST_Value02
+ " desc, " +
CONST_Value03
+ " desc, "
+ CONST_Value04
+ " desc, " +
CONST_Value05
+ " desc, "
+
CONST_ValidFrom
+ " desc, "
+ CONST_ValidTill
+ " asc " +
"
limit 1 ";
Date
locdteWorkDate = new
Date(parmMinParm.calWorkDate.getTime().getTime());
PreparedStatement
SQLStatement;
try {
SQLStatement
=
parmDBCon.prepareStatement(locstrSQLCommand);
SQLStatement.setInt(1,
parmMinParm.intClientID); SQLStatement.setString(2,
parmParameterName);
SQLStatement.setDate(3,
locdteWorkDate);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setString(5,
parmValue01);
ResultSet
SQLResultSet =
SQLStatement.executeQuery();
if (!SQLResultSet.next())
{
ErrorMsg =
"";
return
false;
}
else {
getValuesFromSQLResultSet(SQLResultSet);
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
ErrorMsg =
"";
return
false;
}
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
ErrorMsg =
SQLExc.getMessage();
return
false;
}
}
/* --------------------
* de:
* METHODE zum Lesen des Datensatzes der durch die Attribute 'ParameterName' und 'Value02' identifiziert wird.
* Vorbedingung für das korrekte Ergebnis dieser Methode ist, dass durch den Datenbank-Entwurf und Methoden
* des Anwendungsprogramms sicher gestellt wird, dass der Wert im Attribut 'Value02' zu jedem Zeitpunkt nur
* einmal (für einen Wert im Attribut 'ParameterName') vorkommt.
* Diese Methode ist dazu bestimmt einen Datensatz, der neben dem Anwender-bekannten-Schlüssel (im Attribut
* 'Value01') noch durch den Wert im Attribut 'Value02' eindeutig bestimmt wird, von der Datenbank lesen
* zu können.
* en: * METHOD
to read a Data-Set identified by the attributes 'ParameterName' and 'Value02'.
* Prerequisite for a correct result of this method is, that the database-design and methods of the
* application-program meke sure, that that the value in attribut 'Value02' is unique (for a given value in
* attribute 'ParameterName') at a certain time.
* This method is intended to read a dataset that is - additionally to the user-known-key in attribute 'Value01' -
* uniquely defined by the value in attribute 'Value02'. */
public
boolean selectByValue02(Connection
parmDBCon, JSBS_MinimalParameters
parmMinParm,
String
parmParameterName, String parmValue02) {
/* Build
the SQL-Command in a String.
* 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 = CONST_SELECT_ALL_ATTRIBUTES
+
"
where " +
CONST_ClientID
+
"
=?" +
"
and " +
CONST_ParameterName
+
"
=?" +
"
and " +
CONST_Value02
+
"
=?" +
"
and " +
CONST_ValidFrom
+
"
<=?" +
"
and " +
CONST_ValidTill
+
"
>=?" +
"
order by " +
CONST_ValidFrom
+
"
desc, " +
CONST_ValidTill
+
"
asc";
/* Convert
the actual date (in the passed parameters) to the java.sql.Date
format. */
Date
locdteWorkDate = 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.setInt(1,
parmMinParm.intClientID);
SQLStatement.setString(2,
parmParameterName); SQLStatement.setString(3,
parmValue02);
SQLStatement.setDate(4,
locdteWorkDate);
SQLStatement.setDate(5,
locdteWorkDate);
/* Perform
the database-operation for SELECT. */
ResultSet
SQLResultSet = SQLStatement.executeQuery();
/*
* Verify
if a record was found */
if (!SQLResultSet.next())
{
/* No
database-record found; signal to the calling method by the
return-value */
ErrorMsg =
"";
return
false;
}
else {
/* Database-record
found; transfer the values of the 'PreparedStatement'
* to
the variables of this object.
*/
getValuesFromSQLResultSet(SQLResultSet);
/*
* Verify
that the validity of the found dataset does not start in the future.
*/
if (this.ValidFrom.getTime()
> locdteWorkDate.getTime()) {
/* Found
dataset not already valid; return a status of 'Not Found'.
*/
ErrorMsg =
"";
return
false;
}
/* Database
operation run without an error; report this to the calling method by
an empty string
* and the return value.
*/
ErrorMsg =
"";
return
true;
}
}
catch (SQLException
SQLExc) {
/* An
error occured while running the DB-operation; get the textual
message. */
ErrorMsg =
SQLExc.getMessage();
/* Database
operation run with an error; report this to the calling method by the
return value. */
return
false;
}
}}
Die
Methoden dieser Klasse werden innerhalb der Klasse eines
Business-Object (Server-Seite) für ein Anwendungsprogramm aufgerufen.
Einen Muster-Code für ein solches Business-Object finden Sie im Dokument Muster-Code für ein BOS (Server-Side-Klasse eines Business-Object).
|
Dokument |
Inhalt |
|
JSBS_Parameter_DBA_Set - Basisklasse für den Low-Level Zugriff auf die DB-Tabelle 'Parameter' |
Klasse für die Selektionen von der Datenbank, die per Definition mehr als einen Datensatz als Ergebnis zurück liefern können. |