From 9353c9990ebae9c107f71f02f342fce7c3fd3211 Mon Sep 17 00:00:00 2001 From: arminribic Date: Tue, 14 May 2024 14:19:43 +0200 Subject: [PATCH] #10: Modify Model, Dao and Fixtures --- db/nursingHome.db | Bin 28672 -> 20480 bytes .../hitec/nhplus/fixtures/NurseFixture.java | 8 +++++ .../java/de/hitec/nhplus/nurse/Nurse.java | 31 +++++++++++++++++- .../hitec/nhplus/nurse/database/NurseDao.java | 26 ++++++++++++--- .../de/hitec/nhplus/nurse/database/Nurse.sql | 3 +- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/db/nursingHome.db b/db/nursingHome.db index e05cb45f7f42374a9e0679c17dac84b9d5231516..e381a1f87f2d2e69154d7668a6e22ccb3f3c8bb7 100644 GIT binary patch delta 559 zcmZp8z}T>Wae|Z(lRN_h11k{2KofF7X6c<--bY+|DCtb^`!@&WRx+ty5lgAE` z(rgrDoy;MV!WGR1lme=iuAW>W6T-sI%E>VKqD(7SGz$j$LhOEZE)EU#qqH+?< delta 2124 zcmb_dTWl0n7@jk;JKLSznbXoPLvQS?4bTlOS`dnn#I$87mF<>v7aKst)0wlo!_J=B z%*>Wjg3AKNH=$0VFUCkB!~|coA^1Riu<}%mm&9lYG4i4@#0MY5#Kgoi+p7&E#yHuX z%(?vE|9$`W&zbY@g7ZIuD{UJBQw+m|=zr+~aJFY>8=c)@UloN<8NT5zBi#_+kN(nd zH}V!teptH|5-#GIkQ|SL*IK=iNZgx^6ceOkJ9tD_{A(ngRfpAaB|VnCh^y;%c0OjO zl0K43Dc-}#Z`B^bM>#Myu8s_+l|$-LrF$tTsf?=!)NwUEq-K=*oYHORNo6dp>{nB2 zR#h@;wvHqurN5YO<^FzfL3PojiAz{FG~^l)#)RZV0$j?k)3F-+ zIKp+7qN3Dk`ZZM)Z?o7Z`qUPO^!`S4vsgl;l0%wXv9aw>G?y*MF=*8?hK|)-4r{LC zy&m1vg7lI>49B(Wl^n%x!P33UQF*&ov29w=jB9Dd73lSq5t6liuY|l`qjQmEmo6~p z=5B~b0O;{P5VuupwM-3!{*!I||KJ+0D9g5O{dcx`UqxFxMCz0v+-G2uv{k$*z7SoA znvp*v3z6r9`*VrLI|BcrATS{8{oZy|3Ww<D641NhegE!%|xhCZ@oDdIkao|dbOMunR;>DN! zSsNqzt`JuUpX6jvfAQGJOI$lB(>|c{eyhUpnlOQ9mws~(pOhLKSh&EzpWy;cbsf%L zX$`fpK}K#(cwdjj#$*s=n&rfpi4V=+){0N{?cDYB?mhi`pYiJ|ONfC#!SCVc@D_Xr zUV&#JhFLfa_rfQjApIddkiL=bNFPhrrCI5cbXr0*#}=u&hYvBGT`e*Pdihb5C)hD6 zCC9~xwr*r22ip0JJO7?t#F3akNTH%@Ik>rn1KartWap4=5Q1ErMm08bU`ueIh-RqP ze5F(}A{%H-a2cS+X91_%$zZi zS+ok4xl!amUqB_+G%EYKd((@_TcT6}w_br5;Xs@l!lqd52Gb_kgo)mScAPPu^GD9?dTx|I;awM;ok)vzhUF^E;R4YPN@ zQ8=U13N{D0aPN9Rf#bsMhpj0?x5&OI%Z1}B1UCUL+)s~-oMqDk#K*9-f@#@??t9Ej z#~Jt$JO#H(Ur3&GoH{tX?BKI8ux!Ub*>dr;GD5T+gJ#98kUSj*wHhKIPE%RpOqYB#2G+PT zO1&qe6{mr{CrSx_W#nu>-#ZyQ*TtIdS zX_zL|km+Q!!fAu(*z8eUTIM1ql;c6F5fdMVc{2q { "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