Refactor code
This commit is contained in:
parent
f1f6c77870
commit
2013e2e517
@ -1,5 +0,0 @@
|
||||
package fr.gasser.daoexample;
|
||||
|
||||
public class DummyConnection {
|
||||
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
package fr.gasser.daoexample.dao;
|
||||
|
||||
import fr.gasser.daoexample.DummyConnection;
|
||||
import fr.gasser.daoexample.model.Entity;
|
||||
import fr.gasser.daoexample.sql.Connection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Dao<T extends Entity> {
|
||||
|
||||
protected DummyConnection connection;
|
||||
protected Connection connection;
|
||||
|
||||
public Dao(DummyConnection connection) {
|
||||
public Dao(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
package fr.gasser.daoexample.dao;
|
||||
|
||||
import fr.gasser.daoexample.DummyConnection;
|
||||
import fr.gasser.daoexample.sql.Connection;
|
||||
import fr.gasser.daoexample.sql.DummyConnection;
|
||||
|
||||
public class DaoFactory implements DaoAbstractFactory {
|
||||
private static DummyConnection connection = new DummyConnection();
|
||||
private static Connection connection = new DummyConnection();
|
||||
|
||||
@Override
|
||||
public StudentDao createStudentDao() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.gasser.daoexample.dao;
|
||||
|
||||
import fr.gasser.daoexample.DummyConnection;
|
||||
import fr.gasser.daoexample.model.Discipline;
|
||||
import fr.gasser.daoexample.sql.Connection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -16,7 +16,7 @@ public class DisciplineDao extends Dao<Discipline> {
|
||||
new Discipline(2, "Qsdf")
|
||||
));
|
||||
|
||||
public DisciplineDao(DummyConnection connection) {
|
||||
public DisciplineDao(Connection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.gasser.daoexample.dao;
|
||||
|
||||
import fr.gasser.daoexample.DummyConnection;
|
||||
import fr.gasser.daoexample.model.Student;
|
||||
import fr.gasser.daoexample.sql.Connection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -16,7 +16,7 @@ public class StudentDao extends Dao<Student> {
|
||||
new Student(2, "Qsdf", "Jklm"))
|
||||
);
|
||||
|
||||
StudentDao(DummyConnection connection) {
|
||||
StudentDao(Connection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.gasser.daoexample.dao;
|
||||
|
||||
import fr.gasser.daoexample.DummyConnection;
|
||||
import fr.gasser.daoexample.model.Teacher;
|
||||
import fr.gasser.daoexample.sql.Connection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -16,7 +16,7 @@ public class TeacherDao extends Dao<Teacher> {
|
||||
new Teacher(2, "Sit", "Amet"))
|
||||
);
|
||||
|
||||
TeacherDao(DummyConnection connection) {
|
||||
TeacherDao(Connection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package fr.gasser.daoexample.sql;
|
||||
|
||||
public interface Connection {
|
||||
void connect();
|
||||
|
||||
void close();
|
||||
|
||||
java.sql.Connection getConnection();
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package fr.gasser.daoexample.sql;
|
||||
|
||||
public class DummyConnection implements Connection {
|
||||
@Override
|
||||
public void connect() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.sql.Connection getConnection() {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user