diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one')
5 files changed, 169 insertions, 0 deletions
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();
+}
|
