Generify Dao hierarchy

This commit is contained in:
2019-01-02 23:57:25 +01:00
parent 4cc19191c0
commit 0d9692992b
8 changed files with 41 additions and 24 deletions

View File

@ -17,7 +17,7 @@ public abstract class Dao<T extends Entity> {
public abstract T find(int id);
public abstract List<T> findAll(T obj);
public abstract List<T> findAll();
public abstract boolean update(T obj);

View File

@ -1,5 +1,9 @@
package fr.gasser.daoexample.dao;
import fr.gasser.daoexample.model.Discipline;
import fr.gasser.daoexample.model.Student;
import fr.gasser.daoexample.model.Teacher;
public interface DaoAbstractFactory {
static DaoAbstractFactory createFactory(FactoryType type) {
@ -18,10 +22,10 @@ public interface DaoAbstractFactory {
return createFactory(FactoryType.DaoFactory);
}
StudentDao createStudentDao();
Dao<Student> createStudentDao();
TeacherDao createTeacherDao();
Dao<Teacher> createTeacherDao();
DisciplineDao createDisciplineDao();
Dao<Discipline> createDisciplineDao();
}

View File

@ -1,5 +1,8 @@
package fr.gasser.daoexample.dao;
import fr.gasser.daoexample.model.Discipline;
import fr.gasser.daoexample.model.Student;
import fr.gasser.daoexample.model.Teacher;
import fr.gasser.daoexample.sql.Connection;
import fr.gasser.daoexample.sql.DummyConnection;
@ -7,17 +10,17 @@ public class DaoFactory implements DaoAbstractFactory {
private static Connection connection = new DummyConnection();
@Override
public StudentDao createStudentDao() {
public Dao<Student> createStudentDao() {
return new StudentDao(DaoFactory.connection);
}
@Override
public TeacherDao createTeacherDao() {
public Dao<Teacher> createTeacherDao() {
return new TeacherDao(DaoFactory.connection);
}
@Override
public DisciplineDao createDisciplineDao() {
public Dao<Discipline> createDisciplineDao() {
return new DisciplineDao(DaoFactory.connection);
}
}

View File

@ -31,7 +31,7 @@ public class DisciplineDao extends Dao<Discipline> {
}
@Override
public List<Discipline> findAll(Discipline obj) {
public List<Discipline> findAll() {
return DISCIPLINES;
}

View File

@ -32,7 +32,7 @@ public class StudentDao extends Dao<Student> {
}
@Override
public List<Student> findAll(Student obj) {
public List<Student> findAll() {
return students;
}

View File

@ -31,7 +31,7 @@ public class TeacherDao extends Dao<Teacher> {
}
@Override
public List<Teacher> findAll(Teacher obj) {
public List<Teacher> findAll() {
return teachers;
}