BAEL-3091: The Prototype Pattern in Java (changed code based on valid comments from a reader)

This commit is contained in:
Vivek Balasubramaniam
2019-10-29 22:27:15 +05:30
parent db85c8f275
commit d3d5b060e7
20517 changed files with 1642290 additions and 0 deletions
@@ -0,0 +1,9 @@
package com.baeldung.cayenne;
import com.baeldung.cayenne.auto._Department;
public class Department extends _Department {
private static final long serialVersionUID = 1L;
}
@@ -0,0 +1,9 @@
package com.baeldung.cayenne;
import com.baeldung.cayenne.auto._Employee;
public class Employee extends _Employee {
private static final long serialVersionUID = 1L;
}
@@ -0,0 +1,44 @@
package com.baeldung.cayenne.auto;
import java.util.List;
import org.apache.cayenne.CayenneDataObject;
import org.apache.cayenne.exp.Property;
import com.baeldung.cayenne.Employee;
/**
* Class _Department was generated by Cayenne.
* It is probably a good idea to avoid changing this class manually,
* since it may be overwritten next time code is regenerated.
* If you need to make any customizations, please use subclass.
*/
public abstract class _Department extends CayenneDataObject {
private static final long serialVersionUID = 1L;
public static final String DEP_ID_PK_COLUMN = "dep_id";
public static final Property<String> NAME = Property.create("name", String.class);
public static final Property<List<Employee>> EMPLOYEES = Property.create("employees", List.class);
public void setName(String name) {
writeProperty("name", name);
}
public String getName() {
return (String)readProperty("name");
}
public void addToEmployees(Employee obj) {
addToManyTarget("employees", obj, true);
}
public void removeFromEmployees(Employee obj) {
removeToManyTarget("employees", obj, true);
}
@SuppressWarnings("unchecked")
public List<Employee> getEmployees() {
return (List<Employee>)readProperty("employees");
}
}
@@ -0,0 +1,39 @@
package com.baeldung.cayenne.auto;
import org.apache.cayenne.CayenneDataObject;
import org.apache.cayenne.exp.Property;
import com.baeldung.cayenne.Department;
/**
* Class _Employee was generated by Cayenne.
* It is probably a good idea to avoid changing this class manually,
* since it may be overwritten next time code is regenerated.
* If you need to make any customizations, please use subclass.
*/
public abstract class _Employee extends CayenneDataObject {
private static final long serialVersionUID = 1L;
public static final String EMP_ID_PK_COLUMN = "emp_id";
public static final Property<String> NAME = Property.create("name", String.class);
public static final Property<Department> DEPARTMENT = Property.create("department", Department.class);
public void setName(String name) {
writeProperty("name", name);
}
public String getName() {
return (String)readProperty("name");
}
public void setDepartment(Department department) {
setToOneTarget("department", department, true);
}
public Department getDepartment() {
return (Department)readProperty("department");
}
}