Migrate the CLI and DB configuration modules.

This commit is contained in:
2023-11-06 21:34:11 +02:00
parent 3be3f138c4
commit 5335635d7d
18 changed files with 62 additions and 63 deletions
@@ -1,22 +1,23 @@
package space.kklochko.jdbc_hospital_example.cli;
package space.kklochko.jpa_hospital_example.cli;
import jakarta.persistence.EntityManager;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandData;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandEntities;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandEntity;
import space.kklochko.jdbc_hospital_example.cli.commands.factories.CommandFactory;
import space.kklochko.jdbc_hospital_example.cli.commands.factories.ReadAllFactory;
import space.kklochko.jdbc_hospital_example.cli.parsers.CommandParser;
import space.kklochko.jdbc_hospital_example.cli.validators.CommandValidator;
import space.kklochko.jdbc_hospital_example.cli.validators.InputStringFormatValidator;
import space.kklochko.jdbc_hospital_example.cli.validators.Validator;
import space.kklochko.jdbc_hospital_example.db.factories.DataBaseConnection;
import space.kklochko.jdbc_hospital_example.db.repositories.AbstractRepository;
import space.kklochko.jdbc_hospital_example.db.repositories.DepartmentRepository;
import space.kklochko.jdbc_hospital_example.db.repositories.IndicatorRepository;
import space.kklochko.jdbc_hospital_example.db.repositories.PatientRepository;
import space.kklochko.jpa_hospital_example.cli.commands.CommandData;
import space.kklochko.jpa_hospital_example.cli.commands.CommandEntities;
import space.kklochko.jpa_hospital_example.cli.commands.CommandEntity;
import space.kklochko.jpa_hospital_example.cli.commands.factories.CommandFactory;
import space.kklochko.jpa_hospital_example.cli.commands.factories.ReadAllFactory;
import space.kklochko.jpa_hospital_example.cli.parsers.CommandParser;
import space.kklochko.jpa_hospital_example.cli.validators.CommandValidator;
import space.kklochko.jpa_hospital_example.cli.validators.InputStringFormatValidator;
import space.kklochko.jpa_hospital_example.cli.validators.Validator;
import space.kklochko.jpa_hospital_example.db.factories.DataBaseConnection;
import space.kklochko.jpa_hospital_example.db.repositories.AbstractRepository;
import space.kklochko.jpa_hospital_example.db.repositories.DepartmentRepository;
import space.kklochko.jpa_hospital_example.db.repositories.IndicatorRepository;
import space.kklochko.jpa_hospital_example.db.repositories.PatientRepository;
import java.util.ArrayList;
import java.util.Iterator;
@@ -58,10 +59,10 @@ public class CLI {
"\treadAll indicator()\n" +
"\tremove indicator(id='07c6e39e-727a-11ee-8e7b-c0e4349366ab')\n";
DataBaseConnection dbc;
EntityManager manager;
public CLI(DataBaseConnection dbc) {
this.dbc = dbc;
public CLI(EntityManager manager) {
this.manager = manager;
}
public void run() {
@@ -125,11 +126,11 @@ public class CLI {
public AbstractRepository getRepository(@NonNull CommandData commandData) {
if(commandData.getDatatype().equals("indicator")) {
return new IndicatorRepository(dbc);
return new IndicatorRepository(manager);
}else if(commandData.getDatatype().equals("patient")) {
return new PatientRepository(dbc);
return new PatientRepository(manager);
}else {
return new DepartmentRepository(dbc);
return new DepartmentRepository(manager);
}
}
}
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.cli.commands;
package space.kklochko.jpa_hospital_example.cli.commands;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -1,8 +1,8 @@
package space.kklochko.jdbc_hospital_example.cli.commands;
package space.kklochko.jpa_hospital_example.cli.commands;
import lombok.AllArgsConstructor;
import lombok.Data;
import space.kklochko.jdbc_hospital_example.db.repositories.AbstractRepository;
import space.kklochko.jpa_hospital_example.db.repositories.AbstractRepository;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -1,7 +1,7 @@
package space.kklochko.jdbc_hospital_example.cli.commands;
package space.kklochko.jpa_hospital_example.cli.commands;
import lombok.Data;
import space.kklochko.jdbc_hospital_example.db.repositories.AbstractRepository;
import space.kklochko.jpa_hospital_example.db.repositories.AbstractRepository;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -1,12 +1,12 @@
package space.kklochko.jdbc_hospital_example.cli.commands.factories;
package space.kklochko.jpa_hospital_example.cli.commands.factories;
import lombok.NonNull;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandData;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandEntity;
import space.kklochko.jdbc_hospital_example.db.repositories.AbstractRepository;
import space.kklochko.jdbc_hospital_example.models.Department;
import space.kklochko.jdbc_hospital_example.models.Indicator;
import space.kklochko.jdbc_hospital_example.models.Patient;
import space.kklochko.jpa_hospital_example.cli.commands.CommandData;
import space.kklochko.jpa_hospital_example.cli.commands.CommandEntity;
import space.kklochko.jpa_hospital_example.db.repositories.AbstractRepository;
import space.kklochko.jpa_hospital_example.models.Department;
import space.kklochko.jpa_hospital_example.models.Indicator;
import space.kklochko.jpa_hospital_example.models.Patient;
import java.lang.reflect.Method;
import java.util.UUID;
@@ -1,10 +1,10 @@
package space.kklochko.jdbc_hospital_example.cli.commands.factories;
package space.kklochko.jpa_hospital_example.cli.commands.factories;
import lombok.NonNull;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandData;
import space.kklochko.jdbc_hospital_example.models.Department;
import space.kklochko.jdbc_hospital_example.models.Indicator;
import space.kklochko.jdbc_hospital_example.models.Patient;
import space.kklochko.jpa_hospital_example.cli.commands.CommandData;
import space.kklochko.jpa_hospital_example.models.Department;
import space.kklochko.jpa_hospital_example.models.Indicator;
import space.kklochko.jpa_hospital_example.models.Patient;
import java.sql.Timestamp;
import java.util.Map;
@@ -1,9 +1,9 @@
package space.kklochko.jdbc_hospital_example.cli.commands.factories;
package space.kklochko.jpa_hospital_example.cli.commands.factories;
import lombok.NonNull;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandData;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandEntities;
import space.kklochko.jdbc_hospital_example.db.repositories.AbstractRepository;
import space.kklochko.jpa_hospital_example.cli.commands.CommandData;
import space.kklochko.jpa_hospital_example.cli.commands.CommandEntities;
import space.kklochko.jpa_hospital_example.db.repositories.AbstractRepository;
import java.lang.reflect.Method;
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.cli.parsers;
package space.kklochko.jpa_hospital_example.cli.parsers;
import lombok.NonNull;
@@ -1,8 +1,8 @@
package space.kklochko.jdbc_hospital_example.cli.parsers;
package space.kklochko.jpa_hospital_example.cli.parsers;
import lombok.NonNull;
import lombok.ToString;
import space.kklochko.jdbc_hospital_example.cli.commands.CommandData;
import space.kklochko.jpa_hospital_example.cli.commands.CommandData;
@ToString
public class CommandParser {
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.cli.validators;
package space.kklochko.jpa_hospital_example.cli.validators;
import java.util.regex.Pattern;
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.cli.validators;
package space.kklochko.jpa_hospital_example.cli.validators;
import java.util.regex.Pattern;
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.cli.validators;
package space.kklochko.jpa_hospital_example.cli.validators;
import java.util.regex.Pattern;
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.config.env;
package space.kklochko.jpa_hospital_example.config.env;
import io.github.cdimascio.dotenv.Dotenv;
import lombok.Getter;
@@ -1,8 +1,8 @@
package space.kklochko.jdbc_hospital_example.config.factories;
package space.kklochko.jpa_hospital_example.config.factories;
import lombok.NonNull;
import space.kklochko.jdbc_hospital_example.config.env.DataBaseEnvConfig;
import space.kklochko.jdbc_hospital_example.config.models.DataBaseConfig;
import space.kklochko.jpa_hospital_example.config.env.DataBaseEnvConfig;
import space.kklochko.jpa_hospital_example.config.models.DataBaseConfig;
public class LoadDataBaseConfigFromEnvFile {
public DataBaseConfig load(@NonNull String filename) {
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.config.models;
package space.kklochko.jpa_hospital_example.config.models;
import lombok.Data;
import java.util.Properties;
@@ -1,7 +1,7 @@
package space.kklochko.jdbc_hospital_example.db.factories;
package space.kklochko.jpa_hospital_example.db.factories;
import lombok.Setter;
import space.kklochko.jdbc_hospital_example.config.models.DataBaseConfig;
import space.kklochko.jpa_hospital_example.config.models.DataBaseConfig;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -1,4 +1,4 @@
package space.kklochko.jdbc_hospital_example.db.factories;
package space.kklochko.jpa_hospital_example.db.factories;
import java.sql.Connection;
import java.sql.SQLException;
@@ -1,21 +1,19 @@
package space.kklochko.jdbc_hospital_example.db.repositories;
package space.kklochko.jpa_hospital_example.db.repositories;
import jakarta.persistence.EntityManager;
import lombok.Setter;
import space.kklochko.jdbc_hospital_example.db.factories.DataBaseConnection;
import java.util.ArrayList;
import java.util.UUID;
@Setter
public abstract class AbstractRepository<T> {
DataBaseConnection db;
EntityManager manager;
public AbstractRepository(DataBaseConnection db){
setDb(db);
public AbstractRepository(EntityManager manager){
setManager(manager);
}
public abstract boolean createTable();
public abstract boolean create(T object);
public abstract T read(UUID id);