COMP424 Java Project: DAO Implementation

Verified

Added on  2019/09/22

|5
|775
|296
Project
AI Summary
This project involves implementing a Data Access Object (DAO) pattern in Java using generics, interfaces, and abstract factories. The project requires refactoring existing classes, creating new interfaces and implementations for data persistence, and writing JUnit test cases. The project covers topics such as enums, generics, interfaces, abstract classes, singleton pattern, and JUnit testing. The goal is to create a robust and testable data access layer for a hypothetical application.
Document Page
Send the exported eclipse project by end of Friday, June 24,
2016.
1. Create a Category enum with Computer, Language, Math, Science,
Engineering in package com.comp424.enumdef
2. Use Java Generics to create IPersistentObject interface in the
package.com.comp424.intf.dao.
Contains parameter ID
Extends from Serializable
void : setID(ID)
ID : getID()
3. Refactor Course class
Category : category.
Boolean : isExpired
Course : replacementCourse
4. Refactor Book class
Category : category.
5. Refactor Person class.
Extract Address class to its own file. Address class remains in
the same package.
Remove name attribute and its getter and setter.
Add attribute lastName and FirstName and their
corresponding getters and setters
Remove phoneNumber;
Add attribute mobile and homePhone and their corresponding
getters and setters
6. Refactor Location.
Rename Location to LabRoom
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Remove all attributes and their getters and setters except
roomNumber
Extends from Address class
Add Integer : capacity
7. Remove EnrollmentPolicy class and from Person class.
8. Refactor Book, Course, LabRoom, Person to implement
IPersistentObject with Long parameter.
9. Use Java Generics to create base DAO interface in the package
com.comp424.intf.dao
Interface Name is IBaseDao
Contains parameters T and ID.
Contains the following methods:
getAll() - return a list of object of specific type
findByID(ID id) - return an object of specific type
persist(T t) – persist a new object.
update(T t) – update an existing object in persistent store
deleteByID(ID id) – delete an object
delete(T t)
All methods can throw Exception
10. Using IBaseDao to create the DAO interface for the specific type
Course, Book, LabRoom, Person in the package
com.comp424.intf.dao. All interfaces use Long as ID. Name each
file as I<Type>Dao. For eg., ICourseDao. Refer to the following
steps for further instructions
11. ICourseDao contains the following methods:
Course : findByName(String)
Course : findByCode(String)
Document Page
Courses : getAllExpiredCourses()
Courses : getAllCertificateCourses()
Courses : findCoursesBeforeDate(Date)
Courses : findByCategory(Category)
All methods can throw Exception
12. IBookDao contains the following methods:
Book : findByTitle (String)
Book : findByISBN (String)
Books : findByAuthor(String)
Books : findByCategory(Category)
All methods can throw Exception
13. ILabRoomDao contains the following methods:
LabRooms : findByMinimumCapacity(Integer)
LabRoom : findByRoomNumber(Integer)
All methods can throw Exception
14. IPersonDao contains the following methods:
Persons : findByFirstName(String)
Persons : findByLastName(String)
Persons : findByBirthDate(Date)
Persons : findByPhoneNumber(String)
Persons : findByAddress(Address)
Person : findByEmailAddress(String)
All methods can throw Exception
Document Page
15. Implement the DAO class for the types defined in the previous
steps in the package com.comp424.impl.dao. Name each file as
<Type>DaoImpl. For eg., CourseDaoImpl
16. Use Java Interface and Abstract Factory pattern to create the
factory interface for obtaining the DAO implementation Course,
Book, LabRoom, Person. The interface should be named as
IDaoFactory in the package com.comp424.intf.dao. The methods
of the interface should be get<Type>Dao() and the return type
would be ICourseDao. Eg., for Course, the method signature would
be ICourseDao getCourseDao().
17. Create Abstract factory implementation in
com.comp424.impl.dao. The file should be named as
JavaSerializationDaoFactoryImpl.
18. Use Singleton pattern to create the Abstract Factory developed.
The singleton file should be named as DaoFactory in the package
com.comp424.impl.dao
19. Add JUnit test cases
Create a new Java Project. The project name should be
prefixed with your FirstName and appended with JUnitTest
Add the online project as a dependency. Right click on
project, Build Path->Configure Build Path -> Projects Tab.
Add online project. Click ok.
Create package com.comp424.testcase.dao
In the package, create Junit test case: File->New->JUnit Test
Case.
Select New JUnit4 radio button
Fill up name with the test case name. Eg.
DaoFactoryTestCase
Check all boxes: setupBeforeClass,
tearDownAfterClass, setup, teardown. A quick
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
reference of these methods:
https://en.wikipedia.org/wiki/JUnit
If you know the class under test, you can browse it.
20. You can run the JUnit test case by Right Click on the class. Select
Run As -> JUnit Test.
21. Experiment with adding JUnit test suite.
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]