NOTICKET: Update Nurse Model, Dao and Controller to Reflect privous Cleanup
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
77e227c51e
commit
9ad92c1eac
5 changed files with 33 additions and 22 deletions
Binary file not shown.
|
@ -25,7 +25,7 @@ public class NurseFixture implements Fixture<Nurse> {
|
||||||
@Override
|
@Override
|
||||||
public void setupTable(Connection connection) {
|
public void setupTable(Connection connection) {
|
||||||
final String SQL = "CREATE TABLE IF NOT EXISTS nurse (" +
|
final String SQL = "CREATE TABLE IF NOT EXISTS nurse (" +
|
||||||
"tid 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" +
|
||||||
|
|
|
@ -28,9 +28,9 @@ public class AllNurseController {
|
||||||
private NurseDao dao;
|
private NurseDao dao;
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
this.readAllAndSHowInTableView();
|
this.readAllAndShowInTableView();
|
||||||
|
|
||||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("nid"));
|
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||||
|
|
||||||
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
|
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
|
||||||
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
|
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||||
|
@ -45,7 +45,7 @@ public class AllNurseController {
|
||||||
this.tableView.setItems(this.nurses);
|
this.tableView.setItems(this.nurses);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readAllAndSHowInTableView(){
|
private void readAllAndShowInTableView(){
|
||||||
this.nurses.clear();
|
this.nurses.clear();
|
||||||
this.dao = DaoFactory.getDaoFactory().createNurseDAO();
|
this.dao = DaoFactory.getDaoFactory().createNurseDAO();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
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.SimpleLongProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
public class Nurse extends Person {
|
public class Nurse extends Person {
|
||||||
private SimpleLongProperty nid;
|
private SimpleIntegerProperty id;
|
||||||
private final SimpleStringProperty phoneNumber;
|
private final SimpleStringProperty phoneNumber;
|
||||||
|
|
||||||
public Nurse(
|
public Nurse(
|
||||||
|
@ -18,13 +18,13 @@ public class Nurse extends Person {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Nurse(
|
public Nurse(
|
||||||
long nid,
|
int id,
|
||||||
String firstName,
|
String firstName,
|
||||||
String surname,
|
String surname,
|
||||||
String phoneNumber
|
String phoneNumber
|
||||||
) {
|
) {
|
||||||
super(firstName, surname);
|
super(firstName, surname);
|
||||||
this.nid = new SimpleLongProperty(nid);
|
this.id = new SimpleIntegerProperty(id);
|
||||||
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,12 +32,12 @@ public class Nurse extends Person {
|
||||||
this.phoneNumber.set(phoneNumber);
|
this.phoneNumber.set(phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getNid() {
|
public int getId() {
|
||||||
return nid.get();
|
return id.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleLongProperty nidProperty() {
|
public SimpleIntegerProperty idProperty() {
|
||||||
return nid;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPhoneNumber() {
|
public String getPhoneNumber() {
|
||||||
|
@ -47,4 +47,15 @@ public class Nurse extends Person {
|
||||||
public SimpleStringProperty phoneNumberProperty() {
|
public SimpleStringProperty phoneNumberProperty() {
|
||||||
return phoneNumber;
|
return phoneNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new StringBuilder()
|
||||||
|
.append("Nurse").append(System.lineSeparator())
|
||||||
|
.append("Firstname: ").append(this.getFirstName()).append(System.lineSeparator())
|
||||||
|
.append("Surname: ").append(this.getSurname()).append(System.lineSeparator())
|
||||||
|
.append("PhoneNumber: ").append(this.getPhoneNumber()).append(System.lineSeparator())
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,12 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PreparedStatement getReadByIDStatement(int nid) {
|
protected PreparedStatement getReadByIDStatement(int id) {
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
try {
|
try {
|
||||||
final String SQL = "SELECT * FROM nurse WHERE nid = ?";
|
final String SQL = "SELECT * FROM nurse WHERE id = ?";
|
||||||
preparedStatement = this.connection.prepareStatement(SQL);
|
preparedStatement = this.connection.prepareStatement(SQL);
|
||||||
preparedStatement.setInt(1, nid);
|
preparedStatement.setInt(1, id);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
@Override
|
@Override
|
||||||
protected Nurse getInstanceFromResultSet(ResultSet result) throws SQLException {
|
protected Nurse getInstanceFromResultSet(ResultSet result) throws SQLException {
|
||||||
return new Nurse(
|
return new Nurse(
|
||||||
result.getLong(1),
|
result.getInt(1),
|
||||||
result.getString(2),
|
result.getString(2),
|
||||||
result.getString(3),
|
result.getString(3),
|
||||||
result.getString(4)
|
result.getString(4)
|
||||||
|
@ -69,7 +69,7 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
ArrayList<Nurse> list = new ArrayList<>();
|
ArrayList<Nurse> list = new ArrayList<>();
|
||||||
while (result.next()) {
|
while (result.next()) {
|
||||||
list.add(new Nurse(
|
list.add(new Nurse(
|
||||||
result.getLong(1),
|
result.getInt(1),
|
||||||
result.getString(2),
|
result.getString(2),
|
||||||
result.getString(3),
|
result.getString(3),
|
||||||
result.getString(4)
|
result.getString(4)
|
||||||
|
@ -88,12 +88,12 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
"firstname = ?, " +
|
"firstname = ?, " +
|
||||||
"surname = ?, " +
|
"surname = ?, " +
|
||||||
"phoneNumber = ?, " +
|
"phoneNumber = ?, " +
|
||||||
"WHERE nid = ?";
|
"WHERE id = ?";
|
||||||
preparedStatement = this.connection.prepareStatement(SQL);
|
preparedStatement = this.connection.prepareStatement(SQL);
|
||||||
preparedStatement.setString(1, nurse.getFirstName());
|
preparedStatement.setString(1, nurse.getFirstName());
|
||||||
preparedStatement.setString(2, nurse.getSurname());
|
preparedStatement.setString(2, nurse.getSurname());
|
||||||
preparedStatement.setString(3, nurse.getPhoneNumber());
|
preparedStatement.setString(3, nurse.getPhoneNumber());
|
||||||
preparedStatement.setLong(4, nurse.getNid());
|
preparedStatement.setInt(4, nurse.getId());
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -101,12 +101,12 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PreparedStatement getDeleteStatement(int nid) {
|
protected PreparedStatement getDeleteStatement(int id) {
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
try {
|
try {
|
||||||
final String SQL = "DELETE FROM nurse WHERE nid = ?";
|
final String SQL = "DELETE FROM nurse WHERE id = ?";
|
||||||
preparedStatement = this.connection.prepareStatement(SQL);
|
preparedStatement = this.connection.prepareStatement(SQL);
|
||||||
preparedStatement.setInt(1, nid);
|
preparedStatement.setInt(1, id);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue