From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../examples/entity/bid/many_to_many/Course.java | 48 +++++++++++++ .../examples/entity/bid/many_to_many/Student.java | 50 +++++++++++++ .../bid/many_to_many/StudentCourseBidBean.java | 53 ++++++++++++++ .../many_to_many/client/StudentCourseClient.java | 41 +++++++++++ .../bid/many_to_many/interfaces/StudentCourse.java | 14 ++++ .../examples/entity/bid/one_to_many/Company.java | 48 +++++++++++++ .../bid/one_to_many/CompanyEmployeeInfo.java | 29 ++++++++ .../bid/one_to_many/CompanyEmployeeOMBidBean.java | 81 ++++++++++++++++++++++ .../examples/entity/bid/one_to_many/Employee.java | 53 ++++++++++++++ .../one_to_many/client/CompanyEmployeeClient.java | 44 ++++++++++++ .../one_to_many/interfaces/CompanyEmployeeOM.java | 16 +++++ .../src/examples/entity/bid/one_to_one/Order.java | 45 ++++++++++++ .../bid/one_to_one/OrderShipmentBidBean.java | 40 +++++++++++ .../examples/entity/bid/one_to_one/Shipment.java | 53 ++++++++++++++ .../bid/one_to_one/client/OrderShipmentClient.java | 39 +++++++++++ .../bid/one_to_one/interfaces/OrderShipment.java | 14 ++++ 16 files changed, 668 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Course.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Student.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/StudentCourseBidBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/client/StudentCourseClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/interfaces/StudentCourse.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Company.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/OrderShipmentBidBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Course.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Course.java new file mode 100644 index 0000000..2d6a18c --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Course.java @@ -0,0 +1,48 @@ +package examples.entity.bid.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.ManyToMany; + +@Entity(name="CourseBid") +public class Course implements Serializable { + private int id; + private String courseName; + private Collection students = new ArrayList(); + + 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; + } + + @ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER,mappedBy="courses") + public Collection getStudents() { + return students; + } + + public void setStudents(Collection students) { + this.students = students; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Student.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Student.java new file mode 100644 index 0000000..fc40746 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Student.java @@ -0,0 +1,50 @@ +package examples.entity.bid.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="StudentBid") +public class Student implements Serializable { + private int id; + private String name; + private Collection courses = new ArrayList(); + + 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="STUDENTBID_COURSEBID") + public Collection getCourses() { + return courses; + } + + public void setCourses(Collection 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/bid/many_to_many/StudentCourseBidBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/StudentCourseBidBean.java new file mode 100644 index 0000000..919f9ce --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/StudentCourseBidBean.java @@ -0,0 +1,53 @@ +package examples.entity.bid.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.bid.many_to_many.interfaces.StudentCourse; + +@Stateless +public class StudentCourseBidBean 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 getAllStudents() { + Query q = em.createQuery("SELECT s FROM StudentBid s"); + return q.getResultList(); + } + + public List getAllCourses() { + Query q = em.createQuery("SELECT c FROM CourseBid c"); + return q.getResultList(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/client/StudentCourseClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/client/StudentCourseClient.java new file mode 100644 index 0000000..4537ad1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/client/StudentCourseClient.java @@ -0,0 +1,41 @@ +package examples.entity.bid.many_to_many.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.bid.many_to_many.Course; +import examples.entity.bid.many_to_many.Student; +import examples.entity.bid.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 (Object o : sc.getAllStudents()) { + Student s = (Student)o; + System.out.println("Student: "+s.getName()); + for (Object o1 : s.getCourses()) { + Course c = (Course)o1; + System.out.println("\tCourse: "+c.getCourseName()); + } + } + System.out.println(); + for (Object o : sc.getAllCourses()) { + Course c = (Course)o; + System.out.println("Course: "+c.getCourseName()); + for (Object o1 : c.getStudents()) { + Student s = (Student)o1; + System.out.println("\tStudent: "+s.getName()); + } + } + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/interfaces/StudentCourse.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/interfaces/StudentCourse.java new file mode 100644 index 0000000..90328e4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/interfaces/StudentCourse.java @@ -0,0 +1,14 @@ +package examples.entity.bid.many_to_many.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface StudentCourse { + public void doSomeStuff(); + + public List getAllStudents(); + + public List getAllCourses(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Company.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Company.java new file mode 100644 index 0000000..0183e18 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Company.java @@ -0,0 +1,48 @@ +package examples.entity.bid.one_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.OneToMany; + +@Entity(name="CompanyOMBid") +public class Company implements Serializable { + private int id; + private String name; + private Collection employees = new ArrayList(); + + 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,mappedBy="company") + public Collection getEmployees() { + return employees; + } + + public void setEmployees(Collection employees) { + this.employees = employees; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java new file mode 100644 index 0000000..02fbbb7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java @@ -0,0 +1,29 @@ +package examples.entity.bid.one_to_many; + +import java.io.Serializable; + +public class CompanyEmployeeInfo implements Serializable { + private String cName; + private String eName; + + public CompanyEmployeeInfo(String c, String e) { + cName = c; + eName = e; + } + + public String getCName() { + return cName; + } + + public void setCName(String name) { + cName = name; + } + + public String getEName() { + return eName; + } + + public void setEName(String name) { + eName = name; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java new file mode 100644 index 0000000..77b763a --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java @@ -0,0 +1,81 @@ +package examples.entity.bid.one_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.bid.one_to_many.interfaces.CompanyEmployeeOM; + +@Stateless +public class CompanyEmployeeOMBidBean implements CompanyEmployeeOM { + @PersistenceContext + EntityManager em; + + public void doSomeStuff() { + Company c = new Company(); + c.setName("M*Power Internet Services, Inc."); + + //Collection employees = new ArrayList(); + Employee e = new Employee(); + e.setName("Micah Silverman"); + e.setSex('M'); + e.setCompany(c); + //employees.add(e); + c.getEmployees().add(e); + + e = new Employee(); + e.setName("Tes Silverman"); + e.setSex('F'); + e.setCompany(c); + //employees.add(e); + c.getEmployees().add(e); + + //c.setEmployees(employees); + em.persist(c); + + c = new Company(); + c.setName("Sun Microsystems"); + + //employees = new ArrayList(); + e = new Employee(); + e.setName("Rima Patel"); + e.setSex('F'); + e.setCompany(c); + //employees.add(e); + c.getEmployees().add(e); + + e = new Employee(); + e.setName("James Gosling"); + e.setSex('M'); + e.setCompany(c); + //employees.add(e); + c.getEmployees().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 CompanyOMBid c"); + return q.getResultList(); + } + + public List getEmployees() { + Query q = em.createQuery("SELECT e FROM EmployeeOMBid e"); + return q.getResultList(); + } + + public void deleteAll() { + Query q = em.createQuery("DELETE FROM EmployeeOMBid"); + q.executeUpdate(); + q = em.createQuery("DELETE FROM CompanyOMBid"); + q.executeUpdate(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java new file mode 100644 index 0000000..c0e85ec --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java @@ -0,0 +1,53 @@ +package examples.entity.bid.one_to_many; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity(name="EmployeeOMBid") +public class Employee implements Serializable { + private int id; + private String name; + private char sex; + private Company company; + + 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; + } + + @ManyToOne + public Company getCompany() { + return company; + } + + public void setCompany(Company company) { + this.company = company; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java new file mode 100644 index 0000000..8959f37 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java @@ -0,0 +1,44 @@ +package examples.entity.bid.one_to_many.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.bid.one_to_many.Company; +import examples.entity.bid.one_to_many.Employee; +import examples.entity.bid.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.deleteAll(); + + ceom.doSomeStuff(); + + 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(); + } + System.out.println(); + + for (Object o : ceom.getEmployees()) { + Employee e = (Employee)o; + Company c = e.getCompany(); + + System.out.println("Employee: "+e.getName()+" works for: "+c.getName()); + + 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/bid/one_to_many/interfaces/CompanyEmployeeOM.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java new file mode 100644 index 0000000..e79f59f --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java @@ -0,0 +1,16 @@ +package examples.entity.bid.one_to_many.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface CompanyEmployeeOM { + public void doSomeStuff(); + + public List getCompanies(); + + public List getEmployees(); + + public void deleteAll(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java new file mode 100644 index 0000000..6af54aa --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java @@ -0,0 +1,45 @@ +package examples.entity.bid.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="OrderBid") +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/bid/one_to_one/OrderShipmentBidBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/OrderShipmentBidBean.java new file mode 100644 index 0000000..792c2de --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/OrderShipmentBidBean.java @@ -0,0 +1,40 @@ +package examples.entity.bid.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.bid.one_to_one.interfaces.OrderShipment; + +@Stateless +public class OrderShipmentBidBean 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); + + s.setOrder(o); + + em.persist(o); + } + + public List getOrders() { + Query q = em.createQuery("SELECT o FROM OrderBid o"); + return q.getResultList(); + } + + public List getShipments() { + Query q = em.createQuery("SELECT s FROM ShipmentBid s"); + return q.getResultList(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java new file mode 100644 index 0000000..c778ae2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java @@ -0,0 +1,53 @@ +package examples.entity.bid.one_to_one; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity(name="ShipmentBid") +public class Shipment implements Serializable { + private int id; + private String city; + private String zipcode; + private Order order; + + 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; + } + + @OneToOne(mappedBy="shipment") + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java new file mode 100644 index 0000000..d99444c --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java @@ -0,0 +1,39 @@ +package examples.entity.bid.one_to_one.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.bid.one_to_one.Order; +import examples.entity.bid.one_to_one.Shipment; +import examples.entity.bid.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("Bidirectional 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()); + } + + System.out.println(); + + for (Object o : os.getShipments()) { + Shipment shipment = (Shipment)o; + System.out.println("Shipment: "+shipment.getCity()+" "+shipment.getZipcode()); + System.out.println("\tOrder details: "+shipment.getOrder().getOrderName()); + } + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java new file mode 100644 index 0000000..cc4ae2b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java @@ -0,0 +1,14 @@ +package examples.entity.bid.one_to_one.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface OrderShipment { + public void doSomeStuff(); + + public List getOrders(); + + public List getShipments(); +} -- cgit v1.2.3