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 --- .../src/examples/entity/joined/Car.java | 15 +++++ .../src/examples/entity/joined/Coupe.java | 25 ++++++++ .../src/examples/entity/joined/Motorcycle.java | 16 ++++++ .../src/examples/entity/joined/RoadVehicle.java | 67 ++++++++++++++++++++++ .../joined/RoadVehicleStatelessJoinedBean.java | 46 +++++++++++++++ .../src/examples/entity/joined/Roadster.java | 29 ++++++++++ .../entity/joined/client/RoadVehicleClient.java | 28 +++++++++ .../interfaces/RoadVehicleStatelessJoined.java | 12 ++++ 8 files changed, 238 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Car.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Coupe.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Motorcycle.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicle.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicleStatelessJoinedBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Roadster.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/client/RoadVehicleClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/interfaces/RoadVehicleStatelessJoined.java (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Car.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Car.java new file mode 100644 index 0000000..38cbda0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Car.java @@ -0,0 +1,15 @@ +package examples.entity.joined; + +import java.io.Serializable; + +import javax.persistence.Entity; + +@Entity(name="CarJoined") +public class Car extends RoadVehicle implements Serializable { + public final AcceleratorType acceleratorType = AcceleratorType.PEDAL; + + public Car() { + super(); + numWheels = 4; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Coupe.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Coupe.java new file mode 100644 index 0000000..59df47b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Coupe.java @@ -0,0 +1,25 @@ +package examples.entity.joined; + +import java.io.Serializable; + +import javax.persistence.Entity; + +@Entity(name="CoupeJoined") +public class Coupe extends Car implements Serializable { + public enum BoringFactor {BORING,BORINGER,BORINGEST}; + + private BoringFactor boringFactor; + + public Coupe() { + super(); + numPassengers = 5; + } + + public BoringFactor getBoringFactor() { + return boringFactor; + } + + public void setBoringFactor(BoringFactor boringFactor) { + this.boringFactor = boringFactor; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Motorcycle.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Motorcycle.java new file mode 100644 index 0000000..14c83ec --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Motorcycle.java @@ -0,0 +1,16 @@ +package examples.entity.joined; + +import java.io.Serializable; + +import javax.persistence.Entity; + +@Entity(name="MotorcycleJoined") +public class Motorcycle extends RoadVehicle implements Serializable { + public final AcceleratorType acceleratorType = AcceleratorType.THROTTLE; + + public Motorcycle() { + super(); + numWheels = 2; + numPassengers = 2; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicle.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicle.java new file mode 100644 index 0000000..9fe8c3e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicle.java @@ -0,0 +1,67 @@ +package examples.entity.joined; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; + +@Entity(name="RoadVehicleJoined") +@Table(name="RoadVehicleJoined") +@Inheritance(strategy=InheritanceType.JOINED) +public class RoadVehicle implements Serializable { + public enum AcceleratorType {PEDAL,THROTTLE}; + + @Id + protected int id; + protected int numPassengers; + protected int numWheels; + protected String make; + protected String model; + + public RoadVehicle() { + id = (int) System.nanoTime(); + } + + public int getNumPassengers() { + return numPassengers; + } + + public void setNumPassengers(int numPassengers) { + this.numPassengers = numPassengers; + } + + public int getNumWheels() { + return numWheels; + } + + public void setNumWheels(int numWheels) { + this.numWheels = numWheels; + } + + public int getId() { + return id; + } + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String toString() { + return "Make: "+make+", Model: "+model+", Number of passengers: "+numPassengers; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicleStatelessJoinedBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicleStatelessJoinedBean.java new file mode 100644 index 0000000..9b46869 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/RoadVehicleStatelessJoinedBean.java @@ -0,0 +1,46 @@ +package examples.entity.joined; + +import java.util.ArrayList; +import java.util.List; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +import examples.entity.joined.Coupe.BoringFactor; +import examples.entity.joined.Roadster.CoolFactor; +import examples.entity.joined.interfaces.RoadVehicleStatelessJoined; + +@Stateless +public class RoadVehicleStatelessJoinedBean implements RoadVehicleStatelessJoined { + @PersistenceContext(unitName="pu1") + EntityManager em; + + public void doSomeStuff() { + Coupe c = new Coupe(); + c.setMake("Bob"); + c.setModel("E400"); + c.setBoringFactor(BoringFactor.BORING); + em.persist(c); + + Roadster r = new Roadster(); + r.setMake("Mini"); + r.setModel("Cooper S"); + r.setCoolFactor(CoolFactor.COOLEST); + em.persist(r); + + Motorcycle m = new Motorcycle(); + em.persist(m); + } + + public List getAllCars() { + Query q = em.createQuery("SELECT c.id FROM CarJoined c"); + List ids = q.getResultList(); + ArrayList al = new ArrayList(); + for (Object o : ids) { + al.add(em.find(Car.class,(Integer)o)); + } + return al; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Roadster.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Roadster.java new file mode 100644 index 0000000..b93dbf5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/Roadster.java @@ -0,0 +1,29 @@ +package examples.entity.joined; + +import java.io.Serializable; + +import javax.persistence.Entity; + +@Entity(name="RoadsterJoined") +public class Roadster extends Car implements Serializable { + public enum CoolFactor {COOL,COOLER,COOLEST}; + + private CoolFactor coolFactor; + + public Roadster() { + super(); + numPassengers = 2; + } + + public CoolFactor getCoolFactor() { + return coolFactor; + } + + public void setCoolFactor(CoolFactor coolFactor) { + this.coolFactor = coolFactor; + } + + public String toString() { + return super.toString()+", CoolFactor: "+coolFactor; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/client/RoadVehicleClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/client/RoadVehicleClient.java new file mode 100644 index 0000000..64cf21e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/client/RoadVehicleClient.java @@ -0,0 +1,28 @@ +package examples.entity.joined.client; + +import java.util.List; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.joined.interfaces.RoadVehicleStatelessJoined; + + +public class RoadVehicleClient { + public static void main(String[] args) { + InitialContext ic; + try { + ic = new InitialContext(); + RoadVehicleStatelessJoined rvs = (RoadVehicleStatelessJoined)ic.lookup(RoadVehicleStatelessJoined.class.getName()); + rvs.doSomeStuff(); + + List l = rvs.getAllCars(); + for (Object o : l) { + System.out.println("Car: "+o); + } + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/interfaces/RoadVehicleStatelessJoined.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/interfaces/RoadVehicleStatelessJoined.java new file mode 100644 index 0000000..b205c01 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/joined/interfaces/RoadVehicleStatelessJoined.java @@ -0,0 +1,12 @@ +package examples.entity.joined.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface RoadVehicleStatelessJoined { + public void doSomeStuff(); + + public List getAllCars(); +} -- cgit v1.2.3