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/one_to_many/CompanyEmployeeOMUniBean.java | |
| 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/one_to_many/CompanyEmployeeOMUniBean.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/CompanyEmployeeOMUniBean.java | 73 |
1 files changed, 73 insertions, 0 deletions
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();
+ }
+}
|
