Amod Pandey
Amod Pandey

Reputation: 1396

Using DAO calls inside another DAO - DAO dependency

I have a basic question.

I have been creating DAO with separation of concern. Each DAO concentrates on the BusinessObject in context. My question is on using one DAO method inside another DAO. I have assumed that is wrong but do not have enough data support.

Here is the situation.

EmpDAO:
   getEmp(empId)
   getEmps(deptId)
   getEmps(deptName)

What are the issues of having the below implementation

getEmps(deptName):
    // Assume this is cached and there is no question of two N/w calls and having any gain by joins
    DeptDAO.getId(deptName)
    getEmps(deptId)

What can go wrong with using DeptDAO inside EmpDAO? Or What are the points because of which I should not have a DAO call inside another DAO.

Regards Amod

Upvotes: 3

Views: 2856

Answers (2)

Mustafa Genç
Mustafa Genç

Reputation: 2579

Calling DAO inside another DAO is discouraged. Why doesn't your service do the work ? A service method like:

public void combinedServiceWork(String deptName) {
    long deptId = DeptDAO.getId(deptName);
    EmpDAO.getEmps(deptId);
}

And get rid of getEmps(deptName) in EmpDAO;

Upvotes: 3

duffymo
duffymo

Reputation: 308918

I don't know where you get your information. Can you provide a citation that told you this was so heinous an error? It could be a way to hand code one-to-many relationships.

I have more problem with making these static.

Upvotes: 0

Related Questions