#32: Refactor Database Usage, to be more consistent and understandable #33
16 changed files with 121 additions and 134 deletions
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/patient/PatientDao.java" dialect="GenericSQL" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/TreatmentDao.java" dialect="GenericSQL" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/patient/database/PatientDao.java" dialect="GenericSQL" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java" dialect="GenericSQL" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/database/NurseDao.java" dialect="GenericSQL" />
|
||||
<file url="PROJECT" dialect="SQLite" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,8 +1,8 @@
|
|||
package de.hitec.nhplus.datastorage;
|
||||
|
||||
import de.hitec.nhplus.nurse.NurseDao;
|
||||
import de.hitec.nhplus.patient.PatientDao;
|
||||
import de.hitec.nhplus.treatment.TreatmentDao;
|
||||
import de.hitec.nhplus.nurse.database.NurseDao;
|
||||
import de.hitec.nhplus.patient.database.PatientDao;
|
||||
import de.hitec.nhplus.treatment.database.TreatmentDao;
|
||||
|
||||
public class DaoFactory {
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.Map;
|
|||
|
||||
public interface Fixture<T>
|
||||
{
|
||||
void dropTable(Connection connection);
|
||||
void setupTable(Connection connection);
|
||||
void dropTable(Connection connection) throws SQLException;
|
||||
void setupTable(Connection connection) throws SQLException;
|
||||
Map<String, T> load() throws SQLException;
|
||||
}
|
||||
|
|
|
@ -1,40 +1,27 @@
|
|||
package de.hitec.nhplus.fixtures;
|
||||
|
||||
import de.hitec.nhplus.Main;
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.nurse.NurseDao;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.nurse.database.NurseDao;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class NurseFixture implements Fixture<Nurse> {
|
||||
@Override
|
||||
public void dropTable(Connection connection) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute("DROP TABLE nurse");
|
||||
} catch (SQLException exception) {
|
||||
System.out.println(exception.getMessage());
|
||||
}
|
||||
public void dropTable(Connection connection) throws SQLException {
|
||||
connection.createStatement().execute("DROP TABLE nurse");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTable(Connection connection) {
|
||||
final String SQL = "CREATE TABLE IF NOT EXISTS nurse (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
"firstname TEXT NOT NULL, " +
|
||||
"surname TEXT NOT NULL, " +
|
||||
"phoneNumber TEXT NOT NULL" +
|
||||
");";
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute(SQL);
|
||||
} catch (SQLException exception) {
|
||||
System.out.println(exception.getMessage());
|
||||
}
|
||||
public void setupTable(Connection connection) throws SQLException {
|
||||
final InputStream schema = Main.class.getResourceAsStream("/de/hitec/nhplus/nurse/database/Nurse.sql");
|
||||
assert schema != null;
|
||||
final String SQL = new Scanner(schema, "UTF-8").useDelimiter("\\A").next();
|
||||
connection.createStatement().execute(SQL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,56 +1,34 @@
|
|||
package de.hitec.nhplus.fixtures;
|
||||
|
||||
import de.hitec.nhplus.Main;
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.patient.PatientDao;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.patient.database.PatientDao;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate;
|
||||
|
||||
public class PatientFixture implements Fixture<Patient>
|
||||
{
|
||||
public class PatientFixture implements Fixture<Patient> {
|
||||
@Override
|
||||
public void dropTable(Connection connection)
|
||||
{
|
||||
try (Statement statement = connection.createStatement())
|
||||
{
|
||||
statement.execute("DROP TABLE patient");
|
||||
} catch (SQLException exception)
|
||||
{
|
||||
System.out.println(exception.getMessage());
|
||||
}
|
||||
public void dropTable(Connection connection) throws SQLException {
|
||||
connection.createStatement().execute("DROP TABLE patient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTable(Connection connection)
|
||||
{
|
||||
final String SQL = "CREATE TABLE IF NOT EXISTS patient (" +
|
||||
" id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
" firstname TEXT NOT NULL, " +
|
||||
" surname TEXT NOT NULL, " +
|
||||
" dateOfBirth TEXT NOT NULL, " +
|
||||
" carelevel TEXT NOT NULL, " +
|
||||
" roomnumber TEXT NOT NULL" +
|
||||
");";
|
||||
try (Statement statement = connection.createStatement())
|
||||
{
|
||||
statement.execute(SQL);
|
||||
} catch (SQLException exception)
|
||||
{
|
||||
System.out.println(exception.getMessage());
|
||||
}
|
||||
public void setupTable(Connection connection) throws SQLException {
|
||||
// @SuppressWarnings("checkstyle:LineLength")
|
||||
final InputStream schema = Main.class.getResourceAsStream("/de/hitec/nhplus/patient/database/Patient.sql");
|
||||
assert schema != null;
|
||||
final String SQL = new Scanner(schema, "UTF-8").useDelimiter("\\A").next();
|
||||
connection.createStatement().execute(SQL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Patient> load() throws SQLException
|
||||
{
|
||||
public Map<String, Patient> load() throws SQLException {
|
||||
List<Patient> patients = new ArrayList<>();
|
||||
|
||||
patients.add(new Patient(
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package de.hitec.nhplus.fixtures;
|
||||
|
||||
import de.hitec.nhplus.Main;
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.treatment.TreatmentDao;
|
||||
import de.hitec.nhplus.treatment.database.TreatmentDao;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate;
|
||||
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalTime;
|
||||
|
@ -24,32 +22,16 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void dropTable(Connection connection) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute("DROP TABLE treatment");
|
||||
} catch (SQLException exception) {
|
||||
System.out.println(exception.getMessage());
|
||||
}
|
||||
public void dropTable(Connection connection) throws SQLException {
|
||||
connection.createStatement().execute("DROP TABLE treatment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTable(Connection connection) {
|
||||
final String SQL = "CREATE TABLE IF NOT EXISTS treatment (" +
|
||||
" id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
" patientId INTEGER NOT NULL, " +
|
||||
" treatment_date TEXT NOT NULL, " +
|
||||
" begin TEXT NOT NULL, " +
|
||||
" end TEXT NOT NULL, " +
|
||||
" description TEXT NOT NULL, " +
|
||||
" remark TEXT NOT NULL," +
|
||||
" FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE " +
|
||||
");";
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute(SQL);
|
||||
} catch (SQLException exception) {
|
||||
System.out.println(exception.getMessage());
|
||||
}
|
||||
public void setupTable(Connection connection) throws SQLException {
|
||||
final InputStream schema = Main.class.getResourceAsStream("/de/hitec/nhplus/treatment/database/Treatment.sql");
|
||||
assert schema != null;
|
||||
final String SQL = new Scanner(schema, "UTF-8").useDelimiter("\\A").next();
|
||||
connection.createStatement().execute(SQL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.hitec.nhplus.nurse;
|
|||
import static de.hitec.nhplus.utils.Validator.*;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.nurse.database.NurseDao;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.hitec.nhplus.nurse;
|
||||
package de.hitec.nhplus.nurse.database;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoImp;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
|
@ -1,6 +1,7 @@
|
|||
package de.hitec.nhplus.patient;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.patient.database.PatientDao;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.hitec.nhplus.patient;
|
||||
package de.hitec.nhplus.patient.database;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoImp;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
|
||||
import java.sql.Connection;
|
|
@ -3,7 +3,8 @@ package de.hitec.nhplus.treatment;
|
|||
import de.hitec.nhplus.Main;
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.patient.PatientDao;
|
||||
import de.hitec.nhplus.patient.database.PatientDao;
|
||||
import de.hitec.nhplus.treatment.database.TreatmentDao;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package de.hitec.nhplus.treatment;
|
||||
package de.hitec.nhplus.treatment.database;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.datastorage.DaoImp;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
|
||||
import java.sql.Connection;
|
|
@ -11,11 +11,17 @@ module de.hitec.nhplus {
|
|||
opens de.hitec.nhplus.main to javafx.base, javafx.fxml;
|
||||
|
||||
exports de.hitec.nhplus.patient;
|
||||
exports de.hitec.nhplus.patient.database;
|
||||
opens de.hitec.nhplus.patient.database to javafx.base, javafx.fxml;
|
||||
opens de.hitec.nhplus.patient to javafx.base, javafx.fxml;
|
||||
|
||||
exports de.hitec.nhplus.treatment;
|
||||
exports de.hitec.nhplus.treatment.database;
|
||||
opens de.hitec.nhplus.treatment to javafx.base, javafx.fxml;
|
||||
opens de.hitec.nhplus.treatment.database to javafx.base, javafx.fxml;
|
||||
|
||||
exports de.hitec.nhplus.nurse;
|
||||
exports de.hitec.nhplus.nurse.database;
|
||||
opens de.hitec.nhplus.nurse to javafx.base, javafx.fxml;
|
||||
opens de.hitec.nhplus.nurse.database to javafx.base, javafx.fxml;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE IF NOT EXISTS nurse
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
firstname TEXT NOT NULL,
|
||||
surname TEXT NOT NULL,
|
||||
phoneNumber TEXT NOT NULL
|
||||
)
|
|
@ -0,0 +1,9 @@
|
|||
CREATE TABLE patient
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
firstname TEXT NOT NULL,
|
||||
surname TEXT NOT NULL,
|
||||
dateOfBirth TEXT NOT NULL,
|
||||
carelevel TEXT NOT NULL,
|
||||
roomnumber TEXT NOT NULL
|
||||
);
|
|
@ -0,0 +1,11 @@
|
|||
CREATE TABLE IF NOT EXISTS treatment
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
patientId INTEGER NOT NULL,
|
||||
treatment_date TEXT NOT NULL,
|
||||
begin TEXT NOT NULL,
|
||||
end TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
remark TEXT NOT NULL,
|
||||
FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE
|
||||
)
|
Loading…
Reference in a new issue