#16: Setup Nurse Model & DAO
All checks were successful
Quality Check / Qualty Check (push) Successful in 8s
All checks were successful
Quality Check / Qualty Check (push) Successful in 8s
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
ec449a8c45
commit
903678abdc
2 changed files with 155 additions and 0 deletions
115
src/main/java/de/hitec/nhplus/datastorage/NurseDao.java
Normal file
115
src/main/java/de/hitec/nhplus/datastorage/NurseDao.java
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
package de.hitec.nhplus.datastorage;
|
||||||
|
|
||||||
|
import de.hitec.nhplus.model.Nurse;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class NurseDao extends DaoImp<Nurse> {
|
||||||
|
public NurseDao(Connection connection) {
|
||||||
|
super(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PreparedStatement getCreateStatement(Nurse nurse) {
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
final String SQL = "INSERT INTO patient (firstname, surname, phoneNumber)" +
|
||||||
|
"VALUES (?, ?, ?)";
|
||||||
|
preparedStatement = this.connection.prepareStatement(SQL);
|
||||||
|
preparedStatement.setString(1, nurse.getFirstName());
|
||||||
|
preparedStatement.setString(2, nurse.getSurname());
|
||||||
|
preparedStatement.setString(3, nurse.getPhoneNumber());
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
return preparedStatement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PreparedStatement getReadByIDStatement(long nid) {
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
final String SQL = "SELECT * FROM nurse WHERE nid = ?";
|
||||||
|
preparedStatement = this.connection.prepareStatement(SQL);
|
||||||
|
preparedStatement.setLong(1, nid);
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
return preparedStatement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Nurse getInstanceFromResultSet(ResultSet result) throws SQLException {
|
||||||
|
return new Nurse(
|
||||||
|
result.getLong(1),
|
||||||
|
result.getString(2),
|
||||||
|
result.getString(3),
|
||||||
|
result.getString(4)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PreparedStatement getReadAllStatement() {
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
try {
|
||||||
|
final String SQL = "SELECT * FROM nurse";
|
||||||
|
statement = this.connection.prepareStatement(SQL);
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
return statement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ArrayList<Nurse> getListFromResultSet(ResultSet result) throws SQLException {
|
||||||
|
ArrayList<Nurse> list = new ArrayList<>();
|
||||||
|
while (result.next()) {
|
||||||
|
list.add(new Nurse(
|
||||||
|
result.getLong(1),
|
||||||
|
result.getString(2),
|
||||||
|
result.getString(3),
|
||||||
|
result.getString(4)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PreparedStatement getUpdateStatement(Nurse nurse) {
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
final String SQL =
|
||||||
|
"UPDATE nurse SET " +
|
||||||
|
"firstname = ?, " +
|
||||||
|
"surname = ?, " +
|
||||||
|
"phoneNumber = ?, " +
|
||||||
|
"WHERE nid = ?";
|
||||||
|
preparedStatement = this.connection.prepareStatement(SQL);
|
||||||
|
preparedStatement.setString(1, nurse.getFirstName());
|
||||||
|
preparedStatement.setString(2, nurse.getSurname());
|
||||||
|
preparedStatement.setString(3, nurse.getPhoneNumber());
|
||||||
|
preparedStatement.setLong(4, nurse.getNid());
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
return preparedStatement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PreparedStatement getDeleteStatement(long nid) {
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
final String SQL = "DELETE FROM nurse WHERE nid = ?";
|
||||||
|
preparedStatement = this.connection.prepareStatement(SQL);
|
||||||
|
preparedStatement.setLong(1, nid);
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
return preparedStatement;
|
||||||
|
}
|
||||||
|
}
|
40
src/main/java/de/hitec/nhplus/model/Nurse.java
Normal file
40
src/main/java/de/hitec/nhplus/model/Nurse.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package de.hitec.nhplus.model;
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleLongProperty;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
|
public class Nurse extends Person {
|
||||||
|
private SimpleLongProperty nid;
|
||||||
|
private SimpleStringProperty phoneNumber;
|
||||||
|
|
||||||
|
public Nurse(
|
||||||
|
long nid,
|
||||||
|
String firstName,
|
||||||
|
String surname,
|
||||||
|
String phoneNumber
|
||||||
|
) {
|
||||||
|
super(firstName, surname);
|
||||||
|
this.nid = new SimpleLongProperty(nid);
|
||||||
|
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhoneNumber(String phoneNumber) {
|
||||||
|
this.phoneNumber.set(phoneNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getNid() {
|
||||||
|
return nid.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleLongProperty nidProperty() {
|
||||||
|
return nid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhoneNumber() {
|
||||||
|
return phoneNumber.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty phoneNumberProperty() {
|
||||||
|
return phoneNumber;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue