#32: Cleanup Useless Lines
All checks were successful
Quality Check / Qualty Check (push) Successful in 9s

Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
Dominik Säume 2024-05-05 11:59:15 +02:00
parent c71d3e128b
commit 7898442c2d
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
4 changed files with 120 additions and 208 deletions

View file

@ -1,7 +1,9 @@
package de.hitec.nhplus.datastorage; package de.hitec.nhplus.datastorage;
import java.sql.*; import java.sql.Connection;
import java.util.ArrayList; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List; import java.util.List;
public abstract class DaoImp<T> implements Dao<T> { public abstract class DaoImp<T> implements Dao<T> {
@ -45,13 +47,13 @@ public abstract class DaoImp<T> implements Dao<T> {
protected abstract List<T> getListFromResultSet(ResultSet result) throws SQLException; protected abstract List<T> getListFromResultSet(ResultSet result) throws SQLException;
protected abstract PreparedStatement getCreateStatement(T t); protected abstract PreparedStatement getCreateStatement(T t) throws SQLException;
protected abstract PreparedStatement getReadByIDStatement(int id); protected abstract PreparedStatement getReadByIDStatement(int id) throws SQLException;
protected abstract PreparedStatement getReadAllStatement(); protected abstract PreparedStatement getReadAllStatement() throws SQLException;
protected abstract PreparedStatement getUpdateStatement(T t); protected abstract PreparedStatement getUpdateStatement(T t) throws SQLException;
protected abstract PreparedStatement getDeleteStatement(int id); protected abstract PreparedStatement getDeleteStatement(int id) throws SQLException;
} }

View file

@ -15,31 +15,21 @@ public class NurseDao extends DaoImp<Nurse> {
} }
@Override @Override
protected PreparedStatement getCreateStatement(Nurse nurse) { protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "INSERT INTO nurse (firstname, surname, phoneNumber)" +
try { "VALUES (?, ?, ?)";
final String SQL = "INSERT INTO nurse (firstname, surname, phoneNumber)" + PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
"VALUES (?, ?, ?)"; preparedStatement.setString(1, nurse.getFirstName());
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement.setString(2, nurse.getSurname());
preparedStatement.setString(1, nurse.getFirstName()); preparedStatement.setString(3, nurse.getPhoneNumber());
preparedStatement.setString(2, nurse.getSurname());
preparedStatement.setString(3, nurse.getPhoneNumber());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@Override @Override
protected PreparedStatement getReadByIDStatement(int id) { protected PreparedStatement getReadByIDStatement(int id) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "SELECT * FROM nurse WHERE id = ?";
try { PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
final String SQL = "SELECT * FROM nurse WHERE id = ?"; preparedStatement.setInt(1, id);
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@ -54,15 +44,9 @@ public class NurseDao extends DaoImp<Nurse> {
} }
@Override @Override
protected PreparedStatement getReadAllStatement() { protected PreparedStatement getReadAllStatement() throws SQLException {
PreparedStatement statement = null; final String SQL = "SELECT * FROM nurse";
try { return this.connection.prepareStatement(SQL);
final String SQL = "SELECT * FROM nurse";
statement = this.connection.prepareStatement(SQL);
} catch (SQLException exception) {
exception.printStackTrace();
}
return statement;
} }
@Override @Override
@ -81,36 +65,26 @@ public class NurseDao extends DaoImp<Nurse> {
@Override @Override
protected PreparedStatement getUpdateStatement(Nurse nurse) { protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL =
try { "UPDATE nurse SET " +
final String SQL = "firstname = ?, " +
"UPDATE nurse SET " + "surname = ?, " +
"firstname = ?, " + "phoneNumber = ? " +
"surname = ?, " + "WHERE id = ?";
"phoneNumber = ?, " + PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
"WHERE id = ?"; preparedStatement.setString(1, nurse.getFirstName());
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement.setString(2, nurse.getSurname());
preparedStatement.setString(1, nurse.getFirstName()); preparedStatement.setString(3, nurse.getPhoneNumber());
preparedStatement.setString(2, nurse.getSurname()); preparedStatement.setInt(4, nurse.getId());
preparedStatement.setString(3, nurse.getPhoneNumber());
preparedStatement.setInt(4, nurse.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@Override @Override
protected PreparedStatement getDeleteStatement(int id) { protected PreparedStatement getDeleteStatement(int id) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "DELETE FROM nurse WHERE id = ?";
try { PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
final String SQL = "DELETE FROM nurse WHERE id = ?"; preparedStatement.setInt(1, id);
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
} }

View file

@ -17,33 +17,23 @@ public class PatientDao extends DaoImp<Patient> {
} }
@Override @Override
protected PreparedStatement getCreateStatement(Patient patient) { protected PreparedStatement getCreateStatement(Patient patient) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber) " +
try { "VALUES (?, ?, ?, ?, ?)";
final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber) " + PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
"VALUES (?, ?, ?, ?, ?)"; preparedStatement.setString(1, patient.getFirstName());
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement.setString(2, patient.getSurname());
preparedStatement.setString(1, patient.getFirstName()); preparedStatement.setString(3, patient.getDateOfBirth());
preparedStatement.setString(2, patient.getSurname()); preparedStatement.setString(4, patient.getCareLevel());
preparedStatement.setString(3, patient.getDateOfBirth()); preparedStatement.setString(5, patient.getRoomNumber());
preparedStatement.setString(4, patient.getCareLevel());
preparedStatement.setString(5, patient.getRoomNumber());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@Override @Override
protected PreparedStatement getReadByIDStatement(int id) { protected PreparedStatement getReadByIDStatement(int id) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "SELECT * FROM patient WHERE id = ?";
try { PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
final String SQL = "SELECT * FROM patient WHERE id = ?"; preparedStatement.setInt(1, id);
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@ -59,68 +49,45 @@ public class PatientDao extends DaoImp<Patient> {
} }
@Override @Override
protected PreparedStatement getReadAllStatement() { protected PreparedStatement getReadAllStatement() throws SQLException {
PreparedStatement statement = null; final String SQL = "SELECT * FROM patient";
try { return this.connection.prepareStatement(SQL);
final String SQL = "SELECT * FROM patient";
statement = this.connection.prepareStatement(SQL);
} catch (SQLException exception) {
exception.printStackTrace();
}
return statement;
} }
@Override @Override
protected List<Patient> getListFromResultSet(ResultSet result) throws SQLException { protected List<Patient> getListFromResultSet(ResultSet result) throws SQLException {
ArrayList<Patient> list = new ArrayList<>(); ArrayList<Patient> list = new ArrayList<>();
while (result.next()) { while (result.next()) {
Patient patient = new Patient( list.add(getInstanceFromResultSet(result));
result.getInt(1),
result.getString(2),
result.getString(3),
DateConverter.convertStringToLocalDate(result.getString(4)),
result.getString(5),
result.getString(6));
list.add(patient);
} }
return list; return list;
} }
@Override @Override
protected PreparedStatement getUpdateStatement(Patient patient) { protected PreparedStatement getUpdateStatement(Patient patient) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL =
try { "UPDATE patient SET " +
final String SQL = "firstname = ?, " +
"UPDATE patient SET " + "surname = ?, " +
"firstname = ?, " + "dateOfBirth = ?, " +
"surname = ?, " + "carelevel = ?, " +
"dateOfBirth = ?, " + "roomnumber = ?, " +
"carelevel = ?, " + "WHERE id = ?";
"roomnumber = ?, " + PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
"WHERE id = ?"; preparedStatement.setString(1, patient.getFirstName());
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement.setString(2, patient.getSurname());
preparedStatement.setString(1, patient.getFirstName()); preparedStatement.setString(3, patient.getDateOfBirth());
preparedStatement.setString(2, patient.getSurname()); preparedStatement.setString(4, patient.getCareLevel());
preparedStatement.setString(3, patient.getDateOfBirth()); preparedStatement.setString(5, patient.getRoomNumber());
preparedStatement.setString(4, patient.getCareLevel()); preparedStatement.setInt(6, patient.getId());
preparedStatement.setString(5, patient.getRoomNumber());
preparedStatement.setInt(6, patient.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@Override @Override
protected PreparedStatement getDeleteStatement(int id) { protected PreparedStatement getDeleteStatement(int id) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "DELETE FROM patient WHERE id = ?";
try { PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
final String SQL = "DELETE FROM patient WHERE id = ?"; preparedStatement.setInt(1, id);
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
} }

View file

@ -18,34 +18,24 @@ public class TreatmentDao extends DaoImp<Treatment> {
} }
@Override @Override
protected PreparedStatement getCreateStatement(Treatment treatment) { protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "INSERT INTO treatment (patientId, treatment_date, begin, end, description, remark) " +
try { "VALUES (?, ?, ?, ?, ?, ?)";
final String SQL = "INSERT INTO treatment (patientId, treatment_date, begin, end, description, remark) " + PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
"VALUES (?, ?, ?, ?, ?, ?)"; preparedStatement.setInt(1, treatment.getPatient().getId());
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement.setString(2, treatment.getDate());
preparedStatement.setInt(1, treatment.getPatient().getId()); preparedStatement.setString(3, treatment.getBegin());
preparedStatement.setString(2, treatment.getDate()); preparedStatement.setString(4, treatment.getEnd());
preparedStatement.setString(3, treatment.getBegin()); preparedStatement.setString(5, treatment.getDescription());
preparedStatement.setString(4, treatment.getEnd()); preparedStatement.setString(6, treatment.getRemarks());
preparedStatement.setString(5, treatment.getDescription());
preparedStatement.setString(6, treatment.getRemarks());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@Override @Override
protected PreparedStatement getReadByIDStatement(int id) { protected PreparedStatement getReadByIDStatement(int id) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "SELECT * FROM treatment WHERE id = ?";
try { PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
final String SQL = "SELECT * FROM treatment WHERE id = ?"; preparedStatement.setInt(1, id);
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@ -63,15 +53,9 @@ public class TreatmentDao extends DaoImp<Treatment> {
} }
@Override @Override
protected PreparedStatement getReadAllStatement() { protected PreparedStatement getReadAllStatement() throws SQLException {
PreparedStatement statement = null; final String SQL = "SELECT * FROM treatment";
try { return this.connection.prepareStatement(SQL);
final String SQL = "SELECT * FROM treatment";
statement = this.connection.prepareStatement(SQL);
} catch (SQLException exception) {
exception.printStackTrace();
}
return statement;
} }
@Override @Override
@ -83,15 +67,10 @@ public class TreatmentDao extends DaoImp<Treatment> {
return list; return list;
} }
private PreparedStatement getReadAllTreatmentsOfOnePatientByPid(int patientId) { private PreparedStatement getReadAllTreatmentsOfOnePatientByPid(int patientId) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL = "SELECT * FROM treatment WHERE patientId = ?";
try { PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
final String SQL = "SELECT * FROM treatment WHERE patientId = ?"; preparedStatement.setInt(1, patientId);
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, patientId);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@ -101,43 +80,33 @@ public class TreatmentDao extends DaoImp<Treatment> {
} }
@Override @Override
protected PreparedStatement getUpdateStatement(Treatment treatment) { protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL =
try { "UPDATE treatment SET " +
final String SQL = "patientId = ?, " +
"UPDATE treatment SET " + "treatment_date = ?, " +
"patientId = ?, " + "begin = ?, " +
"treatment_date = ?, " + "end = ?, " +
"begin = ?, " + "description = ?, " +
"end = ?, " + "remark = ? " +
"description = ?, " + "WHERE id = ?";
"remark = ? " + PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
"WHERE id = ?"; preparedStatement.setInt(1, treatment.getPatient().getId());
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement.setString(2, treatment.getDate());
preparedStatement.setInt(1, treatment.getPatient().getId()); preparedStatement.setString(3, treatment.getBegin());
preparedStatement.setString(2, treatment.getDate()); preparedStatement.setString(4, treatment.getEnd());
preparedStatement.setString(3, treatment.getBegin()); preparedStatement.setString(5, treatment.getDescription());
preparedStatement.setString(4, treatment.getEnd()); preparedStatement.setString(6, treatment.getRemarks());
preparedStatement.setString(5, treatment.getDescription()); preparedStatement.setInt(7, treatment.getId());
preparedStatement.setString(6, treatment.getRemarks());
preparedStatement.setInt(7, treatment.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
@Override @Override
protected PreparedStatement getDeleteStatement(int id) { protected PreparedStatement getDeleteStatement(int id) throws SQLException {
PreparedStatement preparedStatement = null; final String SQL =
try { "DELETE FROM treatment WHERE id = ?";
final String SQL = PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
"DELETE FROM treatment WHERE id = ?"; preparedStatement.setInt(1, id);
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement; return preparedStatement;
} }
} }