summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Course.java48
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Student.java50
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/StudentCourseBidBean.java53
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/client/StudentCourseClient.java41
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/interfaces/StudentCourse.java14
5 files changed, 206 insertions, 0 deletions
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<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;
+ }
+
+ @ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER,mappedBy="courses")
+ 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/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<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="STUDENTBID_COURSEBID")
+ 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/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();
+}