diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni')
20 files changed, 730 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Course.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Course.java new file mode 100644 index 0000000..b922a7d --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Course.java @@ -0,0 +1,44 @@ +package examples.entity.uni.many_to_many;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity(name="CourseUni")
+public class Course implements Serializable {
+ private int id;
+ private String courseName;
+ private Collection<Student> students = new ArrayList<Student>();
+
+ public Course() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getCourseName() {
+ return courseName;
+ }
+
+ public void setCourseName(String courseName) {
+ this.courseName = courseName;
+ }
+
+ public Collection<Student> getStudents() {
+ return students;
+ }
+
+ public void setStudents(Collection<Student> students) {
+ this.students = students;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Student.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Student.java new file mode 100644 index 0000000..a6568b1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Student.java @@ -0,0 +1,50 @@ +package examples.entity.uni.many_to_many;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+
+@Entity(name="StudentUni")
+public class Student implements Serializable {
+ private int id;
+ private String name;
+ private Collection<Course> courses = new ArrayList<Course>();
+
+ public Student() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
+ @JoinTable(name="STUDENTUNI_COURSEUNI")
+ public Collection<Course> getCourses() {
+ return courses;
+ }
+
+ public void setCourses(Collection<Course> courses) {
+ this.courses = courses;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/StudentCourseUniBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/StudentCourseUniBean.java new file mode 100644 index 0000000..653133b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/StudentCourseUniBean.java @@ -0,0 +1,48 @@ +package examples.entity.uni.many_to_many;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import examples.entity.uni.many_to_many.interfaces.StudentCourse;
+
+@Stateless
+public class StudentCourseUniBean implements StudentCourse {
+ @PersistenceContext
+ EntityManager em;
+
+ public void doSomeStuff() {
+ Course c1 = new Course();
+ c1.setCourseName("EJB 3.0 101");
+
+ Course c2 = new Course();
+ c2.setCourseName("EJB 3.0 202");
+
+ Student s1 = new Student();
+ s1.setName("Micah");
+
+ s1.getCourses().add(c1);
+
+ c1.getStudents().add(s1);
+
+ Student s2 = new Student();
+ s2.setName("Tes");
+
+ s2.getCourses().add(c1);
+ s2.getCourses().add(c2);
+
+ c1.getStudents().add(s2);
+ c2.getStudents().add(s2);
+
+ em.persist(s1);
+ em.persist(s2);
+ }
+
+ public List<Student> getAllStudents() {
+ Query q = em.createQuery("SELECT s FROM StudentUni s");
+ return q.getResultList();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/client/StudentCourseClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/client/StudentCourseClient.java new file mode 100644 index 0000000..d18aee2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/client/StudentCourseClient.java @@ -0,0 +1,30 @@ +package examples.entity.uni.many_to_many.client;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import examples.entity.uni.many_to_many.Course;
+import examples.entity.uni.many_to_many.Student;
+import examples.entity.uni.many_to_many.interfaces.StudentCourse;
+
+
+public class StudentCourseClient {
+ public static void main(String[] args) {
+ try {
+ InitialContext ic = new InitialContext();
+ StudentCourse sc = (StudentCourse)ic.lookup(StudentCourse.class.getName());
+
+ sc.doSomeStuff();
+
+ for (Student s : sc.getAllStudents()) {
+ System.out.println("Student: "+s.getName());
+ for (Course c : s.getCourses()) {
+ System.out.println("\tCourse: "+c.getCourseName());
+ }
+ }
+ }
+ catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/interfaces/StudentCourse.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/interfaces/StudentCourse.java new file mode 100644 index 0000000..65e9cef --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/interfaces/StudentCourse.java @@ -0,0 +1,14 @@ +package examples.entity.uni.many_to_many.interfaces;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+
+import examples.entity.uni.many_to_many.Student;
+
+@Remote
+public interface StudentCourse {
+ public void doSomeStuff();
+
+ public List<Student> getAllStudents();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/BusinessAddress.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/BusinessAddress.java new file mode 100644 index 0000000..755cd6c --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/BusinessAddress.java @@ -0,0 +1,42 @@ +package examples.entity.uni.many_to_one;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class BusinessAddress implements Serializable {
+ private int id;
+ private String city;
+ private String zipcode;
+
+ public BusinessAddress() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getZipcode() {
+ return zipcode;
+ }
+
+ public void setZipcode(String zipcode) {
+ this.zipcode = zipcode;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/Employee.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/Employee.java new file mode 100644 index 0000000..f14104f --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/Employee.java @@ -0,0 +1,45 @@ +package examples.entity.uni.many_to_one;
+
+import java.io.Serializable;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class Employee implements Serializable {
+ private int id;
+ private String name;
+ private BusinessAddress address;
+
+ public Employee() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @ManyToOne(cascade={CascadeType.ALL})
+ public BusinessAddress getAddress() {
+ return address;
+ }
+
+ public void setAddress(BusinessAddress address) {
+ this.address = address;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/EmployeeAddressMOUniBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/EmployeeAddressMOUniBean.java new file mode 100644 index 0000000..be74d18 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/EmployeeAddressMOUniBean.java @@ -0,0 +1,42 @@ +package examples.entity.uni.many_to_one;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import examples.entity.uni.many_to_one.interfaces.EmployeeAddressMOUni;
+
+@Stateless
+public class EmployeeAddressMOUniBean implements EmployeeAddressMOUni {
+ @PersistenceContext
+ EntityManager em;
+
+ public void doSomeStuff() {
+ BusinessAddress a = new BusinessAddress();
+ a.setCity("Huntington Station");
+ a.setZipcode("11746");
+
+ Employee e = new Employee();
+ e.setName("Micah Silverman");
+ e.setAddress(a);
+ em.persist(e);
+
+ e = new Employee();
+ e.setName("Tes Silverman");
+ e.setAddress(a);
+ em.persist(e);
+
+ e = new Employee();
+ e.setName("Shaina Silverman");
+ e.setAddress(a);
+ em.persist(e);
+ }
+
+ public List getEmployees() {
+ Query q = em.createQuery("SELECT e FROM Employee e");
+ return q.getResultList();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/client/EmployeeAddressClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/client/EmployeeAddressClient.java new file mode 100644 index 0000000..efabba5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/client/EmployeeAddressClient.java @@ -0,0 +1,28 @@ +package examples.entity.uni.many_to_one.client;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import examples.entity.uni.many_to_one.Employee;
+import examples.entity.uni.many_to_one.interfaces.EmployeeAddressMOUni;
+
+
+public class EmployeeAddressClient {
+ public static void main(String[] args) {
+ try {
+ InitialContext ic = new InitialContext();
+ EmployeeAddressMOUni ea = (EmployeeAddressMOUni)ic.lookup(EmployeeAddressMOUni.class.getName());
+
+ ea.doSomeStuff();
+
+ for (Object o : ea.getEmployees()) {
+ Employee e = (Employee)o;
+ System.out.println("Name: "+e.getName()+", Business Address: "+
+ e.getAddress().getCity()+", "+e.getAddress().getZipcode());
+ }
+ }
+ catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/interfaces/EmployeeAddressMOUni.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/interfaces/EmployeeAddressMOUni.java new file mode 100644 index 0000000..904a3be --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/interfaces/EmployeeAddressMOUni.java @@ -0,0 +1,12 @@ +package examples.entity.uni.many_to_one.interfaces;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface EmployeeAddressMOUni {
+ public void doSomeStuff();
+
+ public List getEmployees();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Company.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Company.java new file mode 100644 index 0000000..ad5554b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Company.java @@ -0,0 +1,47 @@ +package examples.entity.uni.one_to_many;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity(name="CompanyOMUni")
+public class Company implements Serializable {
+ private int id;
+ private String name;
+ private Collection<Employee> employees;
+
+ public Company() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @OneToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
+ public Collection<Employee> getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(Collection<Employee> employees) {
+ this.employees = employees;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/CompanyEmployeeOMUniBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/CompanyEmployeeOMUniBean.java new file mode 100644 index 0000000..a7e5ffa --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/CompanyEmployeeOMUniBean.java @@ -0,0 +1,73 @@ +package examples.entity.uni.one_to_many;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import examples.entity.uni.one_to_many.interfaces.CompanyEmployeeOM;
+
+@Stateless
+public class CompanyEmployeeOMUniBean implements CompanyEmployeeOM {
+ @PersistenceContext
+ EntityManager em;
+
+ public void doSomeStuff() {
+ Company c = new Company();
+ c.setName("M*Power Internet Services, Inc.");
+
+ Collection<Employee> employees = new ArrayList<Employee>();
+ Employee e = new Employee();
+ e.setName("Micah Silverman");
+ e.setSex('M');
+ employees.add(e);
+
+ e = new Employee();
+ e.setName("Tes Silverman");
+ e.setSex('F');
+ employees.add(e);
+
+ c.setEmployees(employees);
+ em.persist(c);
+
+ c = new Company();
+ c.setName("Sun Microsystems");
+
+ employees = new ArrayList<Employee>();
+ e = new Employee();
+ e.setName("Rima Patel");
+ e.setSex('F');
+ employees.add(e);
+
+ e = new Employee();
+ e.setName("James Gosling");
+ e.setSex('M');
+ employees.add(e);
+
+ c.setEmployees(employees);
+ em.persist(c);
+
+ c = new Company();
+ c.setName("Bob's Bait & Tackle");
+ em.persist(c);
+ }
+
+ public List getCompanies() {
+ Query q = em.createQuery("SELECT c FROM CompanyOMUni c");
+ return q.getResultList();
+ }
+
+ public List getCompanies2(String query) {
+ Query q = em.createQuery(query);
+ return q.getResultList();
+ }
+
+ public void deleteCompanies() {
+ Query q = em.createQuery("DELETE FROM CompanyOMUni");
+ q.executeUpdate();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Employee.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Employee.java new file mode 100644 index 0000000..c849223 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Employee.java @@ -0,0 +1,42 @@ +package examples.entity.uni.one_to_many;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity(name="EmployeeOMUni")
+public class Employee implements Serializable {
+ private int id;
+ private String name;
+ private char sex;
+
+ public Employee() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public char getSex() {
+ return sex;
+ }
+
+ public void setSex(char sex) {
+ this.sex = sex;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/client/CompanyEmployeeClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/client/CompanyEmployeeClient.java new file mode 100644 index 0000000..6077c1a --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/client/CompanyEmployeeClient.java @@ -0,0 +1,35 @@ +package examples.entity.uni.one_to_many.client;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import examples.entity.uni.one_to_many.Company;
+import examples.entity.uni.one_to_many.Employee;
+import examples.entity.uni.one_to_many.interfaces.CompanyEmployeeOM;
+
+
+public class CompanyEmployeeClient {
+ public static void main(String[] args) {
+ try {
+ InitialContext ic = new InitialContext();
+ CompanyEmployeeOM ceom = (CompanyEmployeeOM)ic.lookup(CompanyEmployeeOM.class.getName());
+
+ ceom.deleteCompanies();
+
+ ceom.doSomeStuff();
+
+ System.out.println("All Companies:");
+ for (Object o : ceom.getCompanies()) {
+ Company c = (Company)o;
+ System.out.println("Here are the employees for company: "+c.getName());
+ for (Employee e : c.getEmployees()) {
+ System.out.println("\tName: "+e.getName()+", Sex: "+e.getSex());
+ }
+ System.out.println();
+ }
+ }
+ catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/interfaces/CompanyEmployeeOM.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/interfaces/CompanyEmployeeOM.java new file mode 100644 index 0000000..7da70f3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/interfaces/CompanyEmployeeOM.java @@ -0,0 +1,16 @@ +package examples.entity.uni.one_to_many.interfaces;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface CompanyEmployeeOM {
+ public void doSomeStuff();
+
+ public List getCompanies();
+
+ public List getCompanies2(String query);
+
+ public void deleteCompanies();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Order.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Order.java new file mode 100644 index 0000000..71adb1e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Order.java @@ -0,0 +1,45 @@ +package examples.entity.uni.one_to_one;
+
+import java.io.Serializable;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+@Entity(name="OrderUni")
+public class Order implements Serializable {
+ private int id;
+ private String orderName;
+ private Shipment shipment;
+
+ public Order() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getOrderName() {
+ return orderName;
+ }
+
+ public void setOrderName(String orderName) {
+ this.orderName = orderName;
+ }
+
+ @OneToOne(cascade={CascadeType.PERSIST})
+ public Shipment getShipment() {
+ return shipment;
+ }
+
+ public void setShipment(Shipment shipment) {
+ this.shipment = shipment;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/OrderShipmentUniBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/OrderShipmentUniBean.java new file mode 100644 index 0000000..9399996 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/OrderShipmentUniBean.java @@ -0,0 +1,33 @@ +package examples.entity.uni.one_to_one;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import examples.entity.uni.one_to_one.interfaces.OrderShipment;
+
+@Stateless
+public class OrderShipmentUniBean implements OrderShipment {
+ @PersistenceContext
+ EntityManager em;
+
+ public void doSomeStuff() {
+ Shipment s = new Shipment();
+ s.setCity("Austin");
+ s.setZipcode("78727");
+
+ Order o = new Order();
+ o.setOrderName("Software Order");
+ o.setShipment(s);
+
+ em.persist(o);
+ }
+
+ public List getOrders() {
+ Query q = em.createQuery("SELECT o FROM OrderUni o");
+ return q.getResultList();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Shipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Shipment.java new file mode 100644 index 0000000..4f16169 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Shipment.java @@ -0,0 +1,42 @@ +package examples.entity.uni.one_to_one;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity(name="ShipmentUni")
+public class Shipment implements Serializable {
+ private int id;
+ private String city;
+ private String zipcode;
+
+ public Shipment() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getZipcode() {
+ return zipcode;
+ }
+
+ public void setZipcode(String zipcode) {
+ this.zipcode = zipcode;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/client/OrderShipmentClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/client/OrderShipmentClient.java new file mode 100644 index 0000000..666fc5d --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/client/OrderShipmentClient.java @@ -0,0 +1,30 @@ +package examples.entity.uni.one_to_one.client;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import examples.entity.uni.one_to_one.Order;
+import examples.entity.uni.one_to_one.interfaces.OrderShipment;
+
+
+public class OrderShipmentClient {
+ public static void main(String[] args) {
+ try {
+ InitialContext ic = new InitialContext();
+ OrderShipment os = (OrderShipment)ic.lookup(OrderShipment.class.getName());
+
+ os.doSomeStuff();
+
+ System.out.println("Unidirectional One-To-One client\n");
+
+ for (Object o : os.getOrders()) {
+ Order order = (Order)o;
+ System.out.println("Order "+order.getId()+": "+order.getOrderName());
+ System.out.println("\tShipment details: "+order.getShipment().getCity()+" "+order.getShipment().getZipcode());
+ }
+ }
+ catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/interfaces/OrderShipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/interfaces/OrderShipment.java new file mode 100644 index 0000000..c697a10 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/interfaces/OrderShipment.java @@ -0,0 +1,12 @@ +package examples.entity.uni.one_to_one.interfaces;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface OrderShipment {
+ public void doSomeStuff();
+
+ public List getOrders();
+}
|
