Generify Dao hierarchy
This commit is contained in:
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class DisciplineDao extends Dao<Discipline> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Discipline> findAll(Discipline obj) {
|
||||
public List<Discipline> findAll() {
|
||||
return DISCIPLINES;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class StudentDao extends Dao<Student> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Student> findAll(Student obj) {
|
||||
public List<Student> findAll() {
|
||||
return students;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class TeacherDao extends Dao<Teacher> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Teacher> findAll(Teacher obj) {
|
||||
public List<Teacher> findAll() {
|
||||
return teachers;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user