#10 story/pfleger-modul-sperren-und-loschen-von-pflegern #37
5 changed files with 61 additions and 7 deletions
Binary file not shown.
|
@ -46,6 +46,14 @@ public class NurseFixture implements Fixture<Nurse> {
|
||||||
"Armout",
|
"Armout",
|
||||||
"9876543210"
|
"9876543210"
|
||||||
));
|
));
|
||||||
|
|
||||||
|
nurses.add(new Nurse(
|
||||||
|
"Björnd",
|
||||||
|
"Heideberger",
|
||||||
|
"69420",
|
||||||
|
true
|
||||||
|
));
|
||||||
|
|
||||||
NurseDao dao = DaoFactory.getInstance().createNurseDAO();
|
NurseDao dao = DaoFactory.getInstance().createNurseDAO();
|
||||||
for (Nurse nurse : nurses) {
|
for (Nurse nurse : nurses) {
|
||||||
dao.create(nurse);
|
dao.create(nurse);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package de.hitec.nhplus.nurse;
|
package de.hitec.nhplus.nurse;
|
||||||
|
|
||||||
import de.hitec.nhplus.main.Person;
|
import de.hitec.nhplus.main.Person;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
|
@ -14,6 +15,8 @@ import java.util.StringJoiner;
|
||||||
public class Nurse extends Person {
|
public class Nurse extends Person {
|
||||||
private SimpleIntegerProperty id;
|
private SimpleIntegerProperty id;
|
||||||
private final SimpleStringProperty phoneNumber;
|
private final SimpleStringProperty phoneNumber;
|
||||||
|
private final SimpleBooleanProperty locked;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor allows instantiating a {@link Nurse} object,
|
* This constructor allows instantiating a {@link Nurse} object,
|
||||||
SZUT-Dominik marked this conversation as resolved
Outdated
|
|||||||
|
@ -29,6 +32,17 @@ public class Nurse extends Person {
|
||||||
) {
|
) {
|
||||||
super(firstName, surName);
|
super(firstName, surName);
|
||||||
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
SZUT-Dominik marked this conversation as resolved
SZUT-Dominik
commented
- [ ] zu ungenau, mein Vorschlag:
```java
/**
* This constructor allows instantiating a {@link Nurse} object,
* before it is stored in the database, by omitting the {@link Nurse#id ID} value.
*It includes the locked Property.
* @implSpec This was added for usage in the {@link de.hitec.nhplus.fixtures.NurseFixture NurseFixture}.
*/
```
|
|||||||
/**
|
/**
|
||||||
|
@ -38,11 +52,13 @@ public class Nurse extends Person {
|
||||||
int id,
|
int id,
|
||||||
String firstName,
|
String firstName,
|
||||||
String surName,
|
String surName,
|
||||||
String phoneNumber
|
String phoneNumber,
|
||||||
|
Boolean isLocked
|
||||||
) {
|
) {
|
||||||
super(firstName, surName);
|
super(firstName, surName);
|
||||||
this.id = new SimpleIntegerProperty(id);
|
this.id = new SimpleIntegerProperty(id);
|
||||||
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
||||||
|
this.locked = new SimpleBooleanProperty(isLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhoneNumber(String phoneNumber) {
|
public void setPhoneNumber(String phoneNumber) {
|
||||||
|
@ -65,6 +81,19 @@ public class Nurse extends Person {
|
||||||
return phoneNumber;
|
return phoneNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isLocked() {
|
||||||
|
return locked.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleBooleanProperty lockedProperty() {
|
||||||
|
return locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocked(boolean locked) {
|
||||||
|
this.locked.set(locked);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringJoiner(System.lineSeparator())
|
return new StringJoiner(System.lineSeparator())
|
||||||
|
|
|
@ -25,13 +25,14 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException {
|
protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException {
|
||||||
final String SQL = """
|
final String SQL = """
|
||||||
INSERT INTO nurse
|
INSERT INTO nurse
|
||||||
(firstName, surName, phoneNumber)
|
(firstName, surName, phoneNumber, isLocked)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
""";
|
""";
|
||||||
SZUT-Dominik marked this conversation as resolved
Outdated
SZUT-Dominik
commented
- [x] Javadoc ist bereits im `DaoImp<T>` und wird vererbt, bitte hier weglassen
|
|||||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||||
statement.setString(1, nurse.getFirstName());
|
statement.setString(1, nurse.getFirstName());
|
||||||
statement.setString(2, nurse.getSurName());
|
statement.setString(2, nurse.getSurName());
|
||||||
statement.setString(3, nurse.getPhoneNumber());
|
statement.setString(3, nurse.getPhoneNumber());
|
||||||
|
statement.setBoolean(4, nurse.isLocked());
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,8 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
result.getInt(1),
|
result.getInt(1),
|
||||||
result.getString(2),
|
result.getString(2),
|
||||||
result.getString(3),
|
result.getString(3),
|
||||||
result.getString(4)
|
result.getString(4),
|
||||||
|
result.getBoolean(5)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,20 +70,32 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
SZUT-Dominik marked this conversation as resolved
Outdated
SZUT-Dominik
commented
- [x] Javadoc ist bereits im `DaoImp<T>` und wird vererbt, bitte hier weglassen
|
|||||||
|
|
||||||
|
public List<Nurse> readAllActive() throws SQLException {
|
||||||
|
final String SQL = "SELECT * FROM nurse WHERE isLocked=false";
|
||||||
SZUT-Dominik marked this conversation as resolved
Outdated
SZUT-Dominik
commented
- [x] `Read all database entries of active {@link Nurse}s into a {@link List} of model instances.`
|
|||||||
|
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Nurse> readAllLocked() throws SQLException {
|
||||||
|
final String SQL = "SELECT * FROM nurse WHERE isLocked=true";
|
||||||
|
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
|
||||||
|
}
|
||||||
SZUT-Dominik marked this conversation as resolved
SZUT-Dominik
commented
- [ ] Javadoc ist bereits im `DaoImp<T>` und wird vererbt, bitte hier weglassen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException {
|
protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException {
|
||||||
final String SQL = """
|
final String SQL = """
|
||||||
UPDATE nurse SET
|
UPDATE nurse SET
|
||||||
firstName = ?,
|
firstName = ?,
|
||||||
surName = ?,
|
surName = ?,
|
||||||
phoneNumber = ?
|
phoneNumber = ?,
|
||||||
|
isLocked = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
""";
|
""";
|
||||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||||
statement.setString(1, nurse.getFirstName());
|
statement.setString(1, nurse.getFirstName());
|
||||||
statement.setString(2, nurse.getSurName());
|
statement.setString(2, nurse.getSurName());
|
||||||
statement.setString(3, nurse.getPhoneNumber());
|
statement.setString(3, nurse.getPhoneNumber());
|
||||||
statement.setInt(4, nurse.getId());
|
statement.setBoolean(4, nurse.isLocked());
|
||||||
|
statement.setInt(5, nurse.getId());
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,4 +106,6 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
statement.setInt(1, id);
|
statement.setInt(1, id);
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
SZUT-Dominik marked this conversation as resolved
Outdated
SZUT-Dominik
commented
- [ ] Javadoc ist bereits im `DaoImp<T>` und wird vererbt, bitte hier weglassen
|
|||||||
|
|
|
@ -3,5 +3,6 @@ CREATE TABLE nurse
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
firstName TEXT NOT NULL,
|
firstName TEXT NOT NULL,
|
||||||
surName TEXT NOT NULL,
|
surName TEXT NOT NULL,
|
||||||
phoneNumber TEXT NOT NULL
|
phoneNumber TEXT NOT NULL,
|
||||||
|
isLocked BOOLEAN NOT NULL DEFAULT false
|
||||||
)
|
)
|
Loading…
Reference in a new issue
@author
Tagfügt euch bitte, sobald ihr was anpasst in einer Klasse selber als Autoren Hinzu