diff --git a/db/nursingHome.db b/db/nursingHome.db index e05cb45..e381a1f 100644 Binary files a/db/nursingHome.db and b/db/nursingHome.db differ diff --git a/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java b/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java index 3ef6972..c5d0c0f 100644 --- a/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java +++ b/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java @@ -46,6 +46,14 @@ public class NurseFixture implements Fixture { "Armout", "9876543210" )); + + nurses.add(new Nurse( + "Björnd", + "Heideberger", + "69420", + true + )); + NurseDao dao = DaoFactory.getInstance().createNurseDAO(); for (Nurse nurse : nurses) { dao.create(nurse); diff --git a/src/main/java/de/hitec/nhplus/nurse/Nurse.java b/src/main/java/de/hitec/nhplus/nurse/Nurse.java index 9afab12..9b488af 100644 --- a/src/main/java/de/hitec/nhplus/nurse/Nurse.java +++ b/src/main/java/de/hitec/nhplus/nurse/Nurse.java @@ -1,6 +1,7 @@ package de.hitec.nhplus.nurse; import de.hitec.nhplus.main.Person; +import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; @@ -14,6 +15,8 @@ import java.util.StringJoiner; public class Nurse extends Person { private SimpleIntegerProperty id; private final SimpleStringProperty phoneNumber; + private final SimpleBooleanProperty locked; + /** * This constructor allows instantiating a {@link Nurse} object, @@ -29,6 +32,17 @@ public class Nurse extends Person { ) { super(firstName, surName); this.phoneNumber = new SimpleStringProperty(phoneNumber); + this.locked = new SimpleBooleanProperty(false); + } + public Nurse( + String firstName, + String surName, + String phoneNumber, + Boolean isLocked + ) { + super(firstName, surName); + this.phoneNumber = new SimpleStringProperty(phoneNumber); + this.locked = new SimpleBooleanProperty(isLocked); } /** @@ -38,11 +52,13 @@ public class Nurse extends Person { int id, String firstName, String surName, - String phoneNumber + String phoneNumber, + Boolean isLocked ) { super(firstName, surName); this.id = new SimpleIntegerProperty(id); this.phoneNumber = new SimpleStringProperty(phoneNumber); + this.locked = new SimpleBooleanProperty(isLocked); } public void setPhoneNumber(String phoneNumber) { @@ -65,6 +81,19 @@ public class Nurse extends Person { return phoneNumber; } + + public boolean isLocked() { + return locked.get(); + } + + public SimpleBooleanProperty lockedProperty() { + return locked; + } + + public void setLocked(boolean locked) { + this.locked.set(locked); + } + @Override public String toString() { return new StringJoiner(System.lineSeparator()) diff --git a/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java b/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java index 1d1a0e5..6c7f7da 100644 --- a/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java +++ b/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java @@ -25,13 +25,14 @@ public class NurseDao extends DaoImp { protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException { final String SQL = """ INSERT INTO nurse - (firstName, surName, phoneNumber) - VALUES (?, ?, ?) + (firstName, surName, phoneNumber, isLocked) + VALUES (?, ?, ?, ?) """; PreparedStatement statement = this.connection.prepareStatement(SQL); statement.setString(1, nurse.getFirstName()); statement.setString(2, nurse.getSurName()); statement.setString(3, nurse.getPhoneNumber()); + statement.setBoolean(4, nurse.isLocked()); return statement; } @@ -49,7 +50,8 @@ public class NurseDao extends DaoImp { result.getInt(1), result.getString(2), result.getString(3), - result.getString(4) + result.getString(4), + result.getBoolean(5) ); } @@ -68,20 +70,32 @@ public class NurseDao extends DaoImp { return list; } + public List readAllActive() throws SQLException { + final String SQL = "SELECT * FROM nurse WHERE isLocked=false"; + return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery()); + } + + public List readAllLocked() throws SQLException { + final String SQL = "SELECT * FROM nurse WHERE isLocked=true"; + return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery()); + } + @Override protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException { final String SQL = """ UPDATE nurse SET firstName = ?, surName = ?, - phoneNumber = ? + phoneNumber = ?, + isLocked = ? WHERE id = ? """; PreparedStatement statement = this.connection.prepareStatement(SQL); statement.setString(1, nurse.getFirstName()); statement.setString(2, nurse.getSurName()); statement.setString(3, nurse.getPhoneNumber()); - statement.setInt(4, nurse.getId()); + statement.setBoolean(4, nurse.isLocked()); + statement.setInt(5, nurse.getId()); return statement; } @@ -92,4 +106,6 @@ public class NurseDao extends DaoImp { statement.setInt(1, id); return statement; } + + } diff --git a/src/main/resources/de/hitec/nhplus/nurse/database/Nurse.sql b/src/main/resources/de/hitec/nhplus/nurse/database/Nurse.sql index 000823e..3a37006 100644 --- a/src/main/resources/de/hitec/nhplus/nurse/database/Nurse.sql +++ b/src/main/resources/de/hitec/nhplus/nurse/database/Nurse.sql @@ -3,5 +3,6 @@ CREATE TABLE nurse id INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT NOT NULL, surName TEXT NOT NULL, - phoneNumber TEXT NOT NULL + phoneNumber TEXT NOT NULL, + isLocked BOOLEAN NOT NULL DEFAULT false ) \ No newline at end of file