Implements the Interface
DaoImp
. Overrides methods to generate specific PreparedStatements
,
to execute the specific SQL Statements.-
Field Summary
Fields inherited from class de.hitec.nhplus.datastorage.DaoImp
connection
-
Constructor Summary
ConstructorDescriptionTreatmentDao
(Connection connection) The constructor initiates an object ofTreatmentDao
and passes the connection to its super class. -
Method Summary
Modifier and TypeMethodDescriptionprotected PreparedStatement
getCreateStatement
(Treatment treatment) Generates aPreparedStatement
to persist the given object ofTreatment
.protected PreparedStatement
getDeleteStatement
(long tid) Generates aPreparedStatement
to delete a treatment with the given id.protected Treatment
getInstanceFromResultSet
(ResultSet result) Maps aResultSet
of one treatment to an object ofTreatment
.getListFromResultSet
(ResultSet result) Maps aResultSet
of all treatments to anArrayList
with objects of classTreatment
.protected PreparedStatement
Generates aPreparedStatement
to query all treatments.protected PreparedStatement
getReadByIDStatement
(long tid) Generates aPreparedStatement
to query a treatment by a given treatment id (tid).protected PreparedStatement
getUpdateStatement
(Treatment treatment) Generates aPreparedStatement
to update the given treatment, identified by the id of the treatment (tid).readTreatmentsByPid
(long pid) Queries all treatments of a given patient id (pid) and maps the results to anArrayList
with objects of classTreatment
.
-
Constructor Details
-
TreatmentDao
The constructor initiates an object ofTreatmentDao
and passes the connection to its super class.- Parameters:
connection
- Object ofConnection
to execute the SQL-statements.
-
-
Method Details
-
getCreateStatement
Generates aPreparedStatement
to persist the given object ofTreatment
.- Specified by:
getCreateStatement
in classDaoImp<Treatment>
- Parameters:
treatment
- Object ofTreatment
to persist.- Returns:
PreparedStatement
to insert the given patient.
-
getReadByIDStatement
Generates aPreparedStatement
to query a treatment by a given treatment id (tid).- Specified by:
getReadByIDStatement
in classDaoImp<Treatment>
- Parameters:
tid
- Treatment id to query.- Returns:
PreparedStatement
to query the treatment.
-
getInstanceFromResultSet
Maps aResultSet
of one treatment to an object ofTreatment
.- Specified by:
getInstanceFromResultSet
in classDaoImp<Treatment>
- Parameters:
result
- ResultSet with a single row. Columns will be mapped to an object of classTreatment
.- Returns:
- Object of class
Treatment
with the data from the resultSet. - Throws:
SQLException
-
getReadAllStatement
Generates aPreparedStatement
to query all treatments.- Specified by:
getReadAllStatement
in classDaoImp<Treatment>
- Returns:
PreparedStatement
to query all treatments.
-
getListFromResultSet
Maps aResultSet
of all treatments to anArrayList
with objects of classTreatment
.- Specified by:
getListFromResultSet
in classDaoImp<Treatment>
- Parameters:
result
- ResultSet with all rows. The columns will be mapped to objects of classTreatment
.- Returns:
ArrayList
with objects of classTreatment
of all rows in theResultSet
.- Throws:
SQLException
-
readTreatmentsByPid
Queries all treatments of a given patient id (pid) and maps the results to anArrayList
with objects of classTreatment
.- Parameters:
pid
- Patient id to query all treatments referencing this id.- Returns:
ArrayList
with objects of classTreatment
of all rows in theResultSet
.- Throws:
SQLException
-
getUpdateStatement
Generates aPreparedStatement
to update the given treatment, identified by the id of the treatment (tid).- Specified by:
getUpdateStatement
in classDaoImp<Treatment>
- Parameters:
treatment
- Treatment object to update.- Returns:
PreparedStatement
to update the given treatment.
-
getDeleteStatement
Generates aPreparedStatement
to delete a treatment with the given id.- Specified by:
getDeleteStatement
in classDaoImp<Treatment>
- Parameters:
tid
- Id of the Treatment to delete.- Returns:
PreparedStatement
to delete treatment with the given id.
-