通過Accessor來取得相關的實體

來源:互聯網
上載者:User
  1. 概述
    1. 通過主實體取得多個從實體
    2. 通過從實體取得對應的主實體
    3. 在Departments和Employees實體關聯中通過員工取得對應的部門和通過部門取得部門下的所有員工
  2. 實現
    1. 通過員工取得部門名稱的代碼如下:public String findEmpDepartment(long employeeId) {<br /> EmployeesImpl employee = retrieveEmployeeById(employeeId);<br /> if (employee != null) {<br /> DepartmentsImpl department = employee.getDepartments();<br /> if (department != null) {<br /> return department.getDepartmentName();<br /> } else {<br /> return "Unassigned";<br /> } else {<br /> return null;<br /> }<br /> }<br />}
    2. 通過部門取得部門下的員工數代碼如下:/* Access an associated Employees entity from the Department entity */<br />public int findDeptEmployees(long departmentId) {<br /> DepartmentsImpl department = retrieveDepartmentById(departmentId);<br /> if (department != null) {<br /> RowIterator employees = department.getEmployees();<br /> return (employees.getRowCount());<br /> Row row ;<br /> while((row = employees.next())!= null){<br /> EmployeesImpl emp = (EmployeesImpl)row;<br /> System.out.println(emp.getFirstName() + " " + emp.getLastName());<br /> }<br /> } else {<br /> return 0;<br /> }<br />}

本文轉自Oracle Seeker:http://oracleseeker.com/2008/11/06/access_associated_entity_by_accessor_attribute/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.