Simple value-holder classes -- popularly called value classes -- encapsulate functional data in Java. Typically, such classes
are made up of one or more private fields and their get() and set() accessor methods. Each field maps to one of the data entities in the database. A simple data retrieval will involve:
ResultSetAlthough the JDBC API provides powerful support for each of the above steps, it cannot completely eliminate them. Hence, developers end up writing repetitious and functionally similar pieces of code; writing the SQL is the only imaginative part of data retrieval. By purging this task's mundane code, object-relational mapping tools can keep programming somewhat interesting. But, for simple data retrieval, the same benefits can be realized using XML and Reflection.
Let's assume this standard example: Our employee database features columns such as EMPLOYEE_FIRST_NAME, EMPLOYEE_LAST_NAME, EMPLOYEE_NUMBER, and so on. An EmployeeInfo class with the corresponding fields below encapsulates the employee information:
public class EmployeeInfo
{
private String employeeNumber;
private String employeeFirstName;
private String employeeLastName;
private int employeeExperience;
private Timestamp employeeDOB;
private String employeeEmail;
private Timestamp employeeDOJ;
public String getEmployeeNumber()
{
return this.employeeNumber;
}
.
.
public void setEmployeeNumber(String employeeNumber)
{
this.employeeNumber=employeeNumber;
}
.
.
.
.
}
Now, let's assume that some business functionality requires employee objects to be fetched from the relational database. Typical
code that creates the EmployeeInfo objects from the data in the database would look like this: