summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Company.java48
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java29
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java81
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java53
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java44
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java16
6 files changed, 271 insertions, 0 deletions
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<Employee> employees = new ArrayList<Employee>();
+
+ 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<Employee> getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(Collection<Employee> 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<Employee> employees = new ArrayList<Employee>();
+ 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<Employee>();
+ 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();
+}