在弹簧上设计不同的2 DAO或单DAO

时间:2012-12-18 07:37:10

标签: spring

我想设计DAO界面我有部门表与dept_id,员工表与dept_id和employee_id,项目表与employee_id和报告表与employee_id。现在的要求是我想在spring中做这件事所以我很困惑我应该为每个表或一个包含所有表的所有实现逻辑的通用DAO制作不同的DAO,如果它的泛型我应该给出什么方法请帮我设计界面

我已经制作了EmployeeDAO界面但是我必须使项目和报告以及部门表都松散耦合我已经完成了EmployeeDAO我在这里展示了我的EmployeeDAO界面

 package com.ankur.tutorial.dao;

import java.util.List;

import com.ankur.tutorial.employee.model.Employee;

/**
 * The employee DAO is the main Data Access Object that will allow to retrieve
 * and update the employee objects from and to the database. The retrieve and
 * update is done in a manner that employee, the projects and reporting
 * associated are updated
 * 
 * 
 */

public interface EmployeeDAO {
    /**
     * @throws EmployeeDAOException
     * 
     *             Returns all the employees from the database along with
     *             projects and reportigns.
     * 
     * @return List of all employees.
     * @throws
     */
    List<Employee> getAllEmployees();

    /**
     * Search for an employee by name. The name will match either the first name
     * or the last name. The matching is done using the SQL expression LIKE
     * %name%
     * 
     * @param name
     *            The name to search for
     * @return The list of employees with matching name.
     * @throws EmployeeDAOException
     */
    List<Employee> findEmployees(String name);

    /**
     * Select employee by ID.
     * 
     * @param id
     *            The ID (Number) of the employee
     * @return The employee with employee number matching the id
     * @throws EmployeeDAOException
     */
    Employee getEmployee(long id);

    /**
     * Update the employee and the associated project and reporting to the
     * database.
     * 
     * @param employee
     *            The employee to update
     * @return true if the employee record is updated
     * @throws EmployeeDAOException
     */
    boolean updateEmployee(Employee employee);

    /**
     * Delete the employee and the associated projects and reportings.
     * 
     * @param employee
     *            The employee to be deleted.
     * @return true if the employee record is deleted
     * @throws EmployeeDAOException
     */
    boolean deleteEmployee(Employee employee);

    /**
     * Create employee, project and reporting records in the database.
     * 
     * @param The
     *            employee to be created
     * @return true if the creation is successful
     * @throws EmployeeDAOException
     */

}

1 个答案:

答案 0 :(得分:0)

不要制作一个操纵所有表格的DAO。周期。

好的,还有一句话。如果您正在增强系统并添加越来越多的表,那么您认为如何维护?你的超级一体化DAO将是巨大的。