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 --- .../EJB 3.0 Code/Micah Examples/.classpath | 8 ++ .../EJB 3.0 Code/Micah Examples/.packaging | 24 +++++ .../EJB 3.0 Code/Micah Examples/.project | 18 ++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../EJB 3.0 Code/Micah Examples/.xdoclet | 59 ++++++++++++ .../EJB 3.0 Code/Micah Examples/README | 52 +++++++++++ .../Micah Examples/clientUtils/execClient.bat | 1 + .../Micah Examples/clientUtils/jndi.properties | 6 ++ .../Micah Examples/etc/common.properties | 32 +++++++ .../EJB 3.0 Code/Micah Examples/etc/common.xml | 100 +++++++++++++++++++++ .../Micah Examples/packaging-build.xml | 37 ++++++++ .../src/examples/entity/META-INF/application.xml | 11 +++ .../src/examples/entity/META-INF/persistence.xml | 13 +++ .../examples/entity/bid/many_to_many/Course.java | 48 ++++++++++ .../examples/entity/bid/many_to_many/Student.java | 50 +++++++++++ .../bid/many_to_many/StudentCourseBidBean.java | 53 +++++++++++ .../many_to_many/client/StudentCourseClient.java | 41 +++++++++ .../bid/many_to_many/interfaces/StudentCourse.java | 14 +++ .../examples/entity/bid/one_to_many/Company.java | 48 ++++++++++ .../bid/one_to_many/CompanyEmployeeInfo.java | 29 ++++++ .../bid/one_to_many/CompanyEmployeeOMBidBean.java | 81 +++++++++++++++++ .../examples/entity/bid/one_to_many/Employee.java | 53 +++++++++++ .../one_to_many/client/CompanyEmployeeClient.java | 44 +++++++++ .../one_to_many/interfaces/CompanyEmployeeOM.java | 16 ++++ .../src/examples/entity/bid/one_to_one/Order.java | 45 ++++++++++ .../bid/one_to_one/OrderShipmentBidBean.java | 40 +++++++++ .../examples/entity/bid/one_to_one/Shipment.java | 53 +++++++++++ .../bid/one_to_one/client/OrderShipmentClient.java | 39 ++++++++ .../bid/one_to_one/interfaces/OrderShipment.java | 14 +++ .../Micah Examples/src/examples/entity/build.xml | 83 +++++++++++++++++ .../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 +++ .../src/examples/entity/single_table/Car.java | 21 +++++ .../src/examples/entity/single_table/Coupe.java | 31 +++++++ .../examples/entity/single_table/Motorcycle.java | 22 +++++ .../examples/entity/single_table/RoadVehicle.java | 72 +++++++++++++++ .../single_table/RoadVehicleStatelessBean.java | 50 +++++++++++ .../src/examples/entity/single_table/Roadster.java | 31 +++++++ .../single_table/client/RoadVehicleClient.java | 54 +++++++++++ .../interfaces/RoadVehicleStateless.java | 16 ++++ .../examples/entity/uni/many_to_many/Course.java | 44 +++++++++ .../examples/entity/uni/many_to_many/Student.java | 50 +++++++++++ .../uni/many_to_many/StudentCourseUniBean.java | 48 ++++++++++ .../many_to_many/client/StudentCourseClient.java | 30 +++++++ .../uni/many_to_many/interfaces/StudentCourse.java | 14 +++ .../entity/uni/many_to_one/BusinessAddress.java | 42 +++++++++ .../examples/entity/uni/many_to_one/Employee.java | 45 ++++++++++ .../uni/many_to_one/EmployeeAddressMOUniBean.java | 42 +++++++++ .../many_to_one/client/EmployeeAddressClient.java | 28 ++++++ .../interfaces/EmployeeAddressMOUni.java | 12 +++ .../examples/entity/uni/one_to_many/Company.java | 47 ++++++++++ .../uni/one_to_many/CompanyEmployeeOMUniBean.java | 73 +++++++++++++++ .../examples/entity/uni/one_to_many/Employee.java | 42 +++++++++ .../one_to_many/client/CompanyEmployeeClient.java | 35 ++++++++ .../one_to_many/interfaces/CompanyEmployeeOM.java | 16 ++++ .../src/examples/entity/uni/one_to_one/Order.java | 45 ++++++++++ .../uni/one_to_one/OrderShipmentUniBean.java | 33 +++++++ .../examples/entity/uni/one_to_one/Shipment.java | 42 +++++++++ .../uni/one_to_one/client/OrderShipmentClient.java | 30 +++++++ .../uni/one_to_one/interfaces/OrderShipment.java | 12 +++ .../src/examples/stateful/CartBean.java | 39 ++++++++ .../src/examples/stateful/META-INF/application.xml | 11 +++ .../Micah Examples/src/examples/stateful/build.xml | 25 ++++++ .../src/examples/stateful/client/CartClient.java | 47 ++++++++++ .../src/examples/stateful/interfaces/Cart.java | 11 +++ .../src/examples/stateless/HelloWorldBean.java | 12 +++ .../examples/stateless/META-INF/application.xml | 17 ++++ .../src/examples/stateless/PricerBean.java | 66 ++++++++++++++ .../src/examples/stateless/TaxRateBean.java | 20 +++++ .../src/examples/stateless/WEB-INF/web.xml | 25 ++++++ .../src/examples/stateless/build.xml | 26 ++++++ .../examples/stateless/client/PricerClient.java | 36 ++++++++ .../stateless/container/HelloWorldServlet.java | 54 +++++++++++ .../stateless/container/PricerClientServlet.java | 84 +++++++++++++++++ .../stateless/interceptors/AuditorInterceptor.java | 18 ++++ .../stateless/interceptors/LoggerInterceptor.java | 16 ++++ .../examples/stateless/interfaces/HelloWorld.java | 8 ++ .../src/examples/stateless/interfaces/Pricer.java | 9 ++ .../stateless/interfaces/PricerInjection.java | 5 ++ .../stateless/interfaces/PricerLookup.java | 5 ++ .../src/examples/stateless/interfaces/TaxRate.java | 8 ++ .../Micah Examples/src/jndi.properties | 6 ++ .../EJB 3.0 Code/Micah Examples/xdoclet-build.xml | 77 ++++++++++++++++ 89 files changed, 3009 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.classpath create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.packaging create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.project create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.settings/org.eclipse.jdt.core.prefs create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.xdoclet create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/README create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/execClient.bat create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/jndi.properties create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.properties create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/packaging-build.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/application.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/persistence.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Course.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/Student.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/StudentCourseBidBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/client/StudentCourseClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/many_to_many/interfaces/StudentCourse.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Company.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/OrderShipmentBidBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/build.xml 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 create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Car.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Coupe.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Motorcycle.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/RoadVehicle.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/RoadVehicleStatelessBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Roadster.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/client/RoadVehicleClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/interfaces/RoadVehicleStateless.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Course.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Student.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/StudentCourseUniBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/client/StudentCourseClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/interfaces/StudentCourse.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/BusinessAddress.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/Employee.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/EmployeeAddressMOUniBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/client/EmployeeAddressClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_one/interfaces/EmployeeAddressMOUni.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Company.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/CompanyEmployeeOMUniBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Employee.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/client/CompanyEmployeeClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/interfaces/CompanyEmployeeOM.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Order.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/OrderShipmentUniBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Shipment.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/client/OrderShipmentClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/interfaces/OrderShipment.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/META-INF/application.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/build.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/client/CartClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/interfaces/Cart.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/HelloWorldBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/META-INF/application.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/TaxRateBean.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/WEB-INF/web.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/build.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/client/PricerClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/HelloWorldServlet.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/PricerClientServlet.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/HelloWorld.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/Pricer.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerInjection.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerLookup.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/TaxRate.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/jndi.properties create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/xdoclet-build.xml (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.classpath b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.classpath new file mode 100644 index 0000000..c04aa4e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.packaging b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.packaging new file mode 100644 index 0000000..756c5b8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.packaging @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.project b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.project new file mode 100644 index 0000000..195ed69 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.project @@ -0,0 +1,18 @@ + + + MasteringEJB + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.jboss.ide.eclipse.ejb3.wizards.core.EJB3ProjectNature + org.eclipse.jdt.core.javanature + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.settings/org.eclipse.jdt.core.prefs b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..94b500d --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Sun Jan 01 11:53:29 EST 2006 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.xdoclet b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.xdoclet new file mode 100644 index 0000000..08e9ae2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/.xdoclet @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/README b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/README new file mode 100644 index 0000000..1990c66 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/README @@ -0,0 +1,52 @@ +-------------------------------------------- +Building, deploying and running the examples +-------------------------------------------- +1) Make sure you have a JDK 1.5.x installed, + a GlassFish v1 b.48 (or greater) installed, + and ANT installed. + + See: https://glassfish.dev.java.net/ + http://java.sun.com + http://ant.apache.org/ + +2) Set the JAVA_HOME and GLASSFISH_HOME environment + appropriately. + +3) Setup Glassfish according to the installation + instructions. + +4) Start embedded Derby database and the Glassfish + app server. + + cd /bin + ./asadmin.bat start-database + ./asadmin.bat start-domain domain1 + +5) Executing the following will build and deploy the + sample applications. + + cd src/example/stateless + ant + + cd src/examples/stateful + ant + + cd src/examples/entity + ant + + In each case, watch the GlassFish log to see that the applications + are deployed properly. + +6) Executing the following will run each of the sample clients to + exercise the samples applications. + + cd src/examples/stateless + ant run + + cd src/examples/stateful + ant run + + cd src/examples/entity + ant run + +If you need help, please email Micah Silverman at: ejb3@MPowerIT.com diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/execClient.bat b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/execClient.bat new file mode 100644 index 0000000..a4d7ac1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/execClient.bat @@ -0,0 +1 @@ +java -cp .;..\..\..\glassfish.b48\lib\javaee.jar;..\..\..\glassfish.b48\lib\appserv-rt.jar;%* diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/jndi.properties b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/jndi.properties new file mode 100644 index 0000000..483fac9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/clientUtils/jndi.properties @@ -0,0 +1,6 @@ +#java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory +#java.naming.provider.url=corbaname:iiop:localhost:3700 +jndi.factory=com.sun.jndi.cosnaming.CNCtxFactory +jndi.factory=com.sun.jndi.fscontext.RefFSContextFactory +jndi.provider.url=corbaloc::localhost:3700/NameService +#jndi.provider.url=file:c: diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.properties b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.properties new file mode 100644 index 0000000..ddf8b69 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.properties @@ -0,0 +1,32 @@ +# +# Common properties, included by common.xml +# Edit this file to reflect your environment. + +# local configuration parameters +admin.password=adminadmin +admin.host=localhost +appserver.instance=server +appserver.instance.port=8080 +admin.user=admin +admin.port=4848 +domain.name=domain1 + +#jndi.port=3700 +#jndi.factory=com.sun.jndi.cosnaming.CNCtxFactory +#jndi.factory=com.sun.jndi.fscontext.RefFSContextFactory +#jndi.provider.url=corbaloc::${admin.host}:${jndi.port}/NameService +#jndi.provider.url=file:c: + + +# The path seperator for the platform +# Unix - : +# Note for windows add the drive after the seperator +# Windows - ;C: +pathsep=; + +# The directory seperator for the platform +# Unix - / +# Windows - \ +# +dirsep=/ + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.xml new file mode 100644 index 0000000..daf60ce --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/etc/common.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/packaging-build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/packaging-build.xml new file mode 100644 index 0000000..32df5d0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/packaging-build.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/application.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/application.xml new file mode 100644 index 0000000..68de436 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/application.xml @@ -0,0 +1,11 @@ + + + EntityExamples + + EntityExamplesEjb.jar + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/persistence.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/persistence.xml new file mode 100644 index 0000000..e5be93a --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/META-INF/persistence.xml @@ -0,0 +1,13 @@ + + + jdbc/__default + + + + + + + + + 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 students = new ArrayList(); + + 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 getStudents() { + return students; + } + + public void setStudents(Collection 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 courses = new ArrayList(); + + 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 getCourses() { + return courses; + } + + public void setCourses(Collection 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(); +} 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 employees = new ArrayList(); + + 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 getEmployees() { + return employees; + } + + public void setEmployees(Collection 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 employees = new ArrayList(); + 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(); + 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(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java new file mode 100644 index 0000000..6af54aa --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Order.java @@ -0,0 +1,45 @@ +package examples.entity.bid.one_to_one; + +import java.io.Serializable; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity(name="OrderBid") +public class Order implements Serializable { + private int id; + private String orderName; + private Shipment shipment; + + public Order() { + id = (int)System.nanoTime(); + } + + @Id + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getOrderName() { + return orderName; + } + + public void setOrderName(String orderName) { + this.orderName = orderName; + } + + @OneToOne(cascade={CascadeType.PERSIST}) + public Shipment getShipment() { + return shipment; + } + + public void setShipment(Shipment shipment) { + this.shipment = shipment; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/OrderShipmentBidBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/OrderShipmentBidBean.java new file mode 100644 index 0000000..792c2de --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/OrderShipmentBidBean.java @@ -0,0 +1,40 @@ +package examples.entity.bid.one_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.bid.one_to_one.interfaces.OrderShipment; + +@Stateless +public class OrderShipmentBidBean implements OrderShipment { + @PersistenceContext + EntityManager em; + + public void doSomeStuff() { + Shipment s = new Shipment(); + s.setCity("Austin"); + s.setZipcode("78727"); + + Order o = new Order(); + o.setOrderName("Software Order"); + o.setShipment(s); + + s.setOrder(o); + + em.persist(o); + } + + public List getOrders() { + Query q = em.createQuery("SELECT o FROM OrderBid o"); + return q.getResultList(); + } + + public List getShipments() { + Query q = em.createQuery("SELECT s FROM ShipmentBid s"); + return q.getResultList(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java new file mode 100644 index 0000000..c778ae2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/Shipment.java @@ -0,0 +1,53 @@ +package examples.entity.bid.one_to_one; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity(name="ShipmentBid") +public class Shipment implements Serializable { + private int id; + private String city; + private String zipcode; + private Order order; + + public Shipment() { + 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; + } + + @OneToOne(mappedBy="shipment") + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java new file mode 100644 index 0000000..d99444c --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/client/OrderShipmentClient.java @@ -0,0 +1,39 @@ +package examples.entity.bid.one_to_one.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.bid.one_to_one.Order; +import examples.entity.bid.one_to_one.Shipment; +import examples.entity.bid.one_to_one.interfaces.OrderShipment; + + +public class OrderShipmentClient { + public static void main(String[] args) { + try { + InitialContext ic = new InitialContext(); + OrderShipment os = (OrderShipment)ic.lookup(OrderShipment.class.getName()); + + os.doSomeStuff(); + + System.out.println("Bidirectional One-To-One client\n"); + + for (Object o : os.getOrders()) { + Order order = (Order)o; + System.out.println("Order "+order.getId()+": "+order.getOrderName()); + System.out.println("\tShipment details: "+order.getShipment().getCity()+" "+order.getShipment().getZipcode()); + } + + System.out.println(); + + for (Object o : os.getShipments()) { + Shipment shipment = (Shipment)o; + System.out.println("Shipment: "+shipment.getCity()+" "+shipment.getZipcode()); + System.out.println("\tOrder details: "+shipment.getOrder().getOrderName()); + } + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java new file mode 100644 index 0000000..cc4ae2b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_one/interfaces/OrderShipment.java @@ -0,0 +1,14 @@ +package examples.entity.bid.one_to_one.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface OrderShipment { + public void doSomeStuff(); + + public List getOrders(); + + public List getShipments(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/build.xml new file mode 100644 index 0000000..f73d142 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/build.xml @@ -0,0 +1,83 @@ + + ]> + + + + + + + + + + + + &include; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Car.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Car.java new file mode 100644 index 0000000..5c72d7f --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Car.java @@ -0,0 +1,21 @@ +package examples.entity.single_table; + +import java.io.Serializable; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity(name="CarSingle") +@DiscriminatorValue("CAR") +public class Car extends RoadVehicle implements Serializable { + public final AcceleratorType acceleratorType = AcceleratorType.PEDAL; + + public Car() { + super(); + numWheels = 4; + } + + public String toString() { + return "Car: "+super.toString(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Coupe.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Coupe.java new file mode 100644 index 0000000..31af7d5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Coupe.java @@ -0,0 +1,31 @@ +package examples.entity.single_table; + +import java.io.Serializable; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity(name="CoupeSingle") +@DiscriminatorValue("COUPE") +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; + } + + public String toString() { + return "Coupe: "+super.toString(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Motorcycle.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Motorcycle.java new file mode 100644 index 0000000..018cb5d --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Motorcycle.java @@ -0,0 +1,22 @@ +package examples.entity.single_table; + +import java.io.Serializable; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity(name="MotorcycleSingle") +@DiscriminatorValue("MOTORCYCLE") +public class Motorcycle extends RoadVehicle implements Serializable { + public final AcceleratorType acceleratorType = AcceleratorType.THROTTLE; + + public Motorcycle() { + super(); + numWheels = 2; + numPassengers = 2; + } + + public String toString() { + return "Motorcycle: "+super.toString(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/RoadVehicle.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/RoadVehicle.java new file mode 100644 index 0000000..75a258a --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/RoadVehicle.java @@ -0,0 +1,72 @@ +package examples.entity.single_table; + +import java.io.Serializable; + +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; + +@Entity(name="RoadVehicleSingle") +@Table(name="RoadVehicleSingle") +@Inheritance(strategy=InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name="DISC", discriminatorType=DiscriminatorType.STRING) +@DiscriminatorValue("ROADVEHICLE") +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/single_table/RoadVehicleStatelessBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/RoadVehicleStatelessBean.java new file mode 100644 index 0000000..94d27db --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/RoadVehicleStatelessBean.java @@ -0,0 +1,50 @@ +package examples.entity.single_table; + +import java.util.List; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +import examples.entity.single_table.Coupe.BoringFactor; +import examples.entity.single_table.Roadster.CoolFactor; +import examples.entity.single_table.interfaces.RoadVehicleStateless; + +@Stateless +public class RoadVehicleStatelessBean implements RoadVehicleStateless { + @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 getAllRoadVehicles() { + Query q = em.createQuery("SELECT r FROM RoadVehicleSingle r"); + return q.getResultList(); + } + + public void deleteAll(String type) { + Query q = em.createQuery("DELETE FROM "+type); + q.executeUpdate(); + } + + public void updateAll(String type) { + Query q = em.createQuery("UPDATE "+type+" r SET r.numPassengers = 1"); + q.executeUpdate(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Roadster.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Roadster.java new file mode 100644 index 0000000..ae308ac --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/Roadster.java @@ -0,0 +1,31 @@ +package examples.entity.single_table; + +import java.io.Serializable; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity(name="RaodsterSingle") +@DiscriminatorValue("ROADSTER") +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 "Roadster: "+super.toString(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/client/RoadVehicleClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/client/RoadVehicleClient.java new file mode 100644 index 0000000..6ef6ea6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/client/RoadVehicleClient.java @@ -0,0 +1,54 @@ +package examples.entity.single_table.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.single_table.interfaces.RoadVehicleStateless; + + +public class RoadVehicleClient { + public static void main(String[] args) { + String action = "insert"; + String type = "RoadVehicleSingle"; + + if (args.length>0) { + if (args[0].startsWith("update")) { + action="update"; + } + else if (args[0].startsWith("delete")) { + action="delete"; + } + + if (args.length == 2) { + type = args[1]; + } + } + + InitialContext ic; + try { + ic = new InitialContext(); + RoadVehicleStateless rvs = (RoadVehicleStateless)ic.lookup(RoadVehicleStateless.class.getName()); + + if (action.equals("insert")) { + System.out.println("Inserting..."); + rvs.doSomeStuff(); + } + else if (action.equals("update")) { + System.out.println("Updating "+type+"..."); + rvs.updateAll(type); + } + else if (action.equals("delete")) { + System.out.println("Deleting "+type+"..."); + rvs.deleteAll(type); + } + + System.out.println("Here is the list of all RoadVehicles:\n"); + for (Object o : rvs.getAllRoadVehicles()) { + System.out.println("RoadVehicle: "+o); + } + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/interfaces/RoadVehicleStateless.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/interfaces/RoadVehicleStateless.java new file mode 100644 index 0000000..c85da7e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/single_table/interfaces/RoadVehicleStateless.java @@ -0,0 +1,16 @@ +package examples.entity.single_table.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface RoadVehicleStateless { + public void doSomeStuff(); + + public List getAllRoadVehicles(); + + public void deleteAll(String type); + + public void updateAll(String type); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Course.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Course.java new file mode 100644 index 0000000..b922a7d --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Course.java @@ -0,0 +1,44 @@ +package examples.entity.uni.many_to_many; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity(name="CourseUni") +public class Course implements Serializable { + private int id; + private String courseName; + private Collection students = new ArrayList(); + + 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; + } + + public Collection getStudents() { + return students; + } + + public void setStudents(Collection students) { + this.students = students; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Student.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Student.java new file mode 100644 index 0000000..a6568b1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/Student.java @@ -0,0 +1,50 @@ +package examples.entity.uni.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="StudentUni") +public class Student implements Serializable { + private int id; + private String name; + private Collection courses = new ArrayList(); + + 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="STUDENTUNI_COURSEUNI") + public Collection getCourses() { + return courses; + } + + public void setCourses(Collection 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/uni/many_to_many/StudentCourseUniBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/StudentCourseUniBean.java new file mode 100644 index 0000000..653133b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/StudentCourseUniBean.java @@ -0,0 +1,48 @@ +package examples.entity.uni.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.uni.many_to_many.interfaces.StudentCourse; + +@Stateless +public class StudentCourseUniBean 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 StudentUni s"); + return q.getResultList(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/client/StudentCourseClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/client/StudentCourseClient.java new file mode 100644 index 0000000..d18aee2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/client/StudentCourseClient.java @@ -0,0 +1,30 @@ +package examples.entity.uni.many_to_many.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.uni.many_to_many.Course; +import examples.entity.uni.many_to_many.Student; +import examples.entity.uni.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 (Student s : sc.getAllStudents()) { + System.out.println("Student: "+s.getName()); + for (Course c : s.getCourses()) { + System.out.println("\tCourse: "+c.getCourseName()); + } + } + } + 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_many/interfaces/StudentCourse.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/interfaces/StudentCourse.java new file mode 100644 index 0000000..65e9cef --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/many_to_many/interfaces/StudentCourse.java @@ -0,0 +1,14 @@ +package examples.entity.uni.many_to_many.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +import examples.entity.uni.many_to_many.Student; + +@Remote +public interface StudentCourse { + public void doSomeStuff(); + + public List getAllStudents(); +} 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(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Company.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Company.java new file mode 100644 index 0000000..ad5554b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Company.java @@ -0,0 +1,47 @@ +package examples.entity.uni.one_to_many; + +import java.io.Serializable; +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="CompanyOMUni") +public class Company implements Serializable { + private int id; + private String name; + private Collection employees; + + 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) + public Collection getEmployees() { + return employees; + } + + public void setEmployees(Collection employees) { + this.employees = employees; + } +} \ No newline at end of file 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 employees = new ArrayList(); + 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(); + 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(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Employee.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Employee.java new file mode 100644 index 0000000..c849223 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/Employee.java @@ -0,0 +1,42 @@ +package examples.entity.uni.one_to_many; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity(name="EmployeeOMUni") +public class Employee implements Serializable { + private int id; + private String name; + private char sex; + + 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; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/client/CompanyEmployeeClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/client/CompanyEmployeeClient.java new file mode 100644 index 0000000..6077c1a --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/client/CompanyEmployeeClient.java @@ -0,0 +1,35 @@ +package examples.entity.uni.one_to_many.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.uni.one_to_many.Company; +import examples.entity.uni.one_to_many.Employee; +import examples.entity.uni.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.deleteCompanies(); + + ceom.doSomeStuff(); + + System.out.println("All Companies:"); + 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(); + } + } + 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/uni/one_to_many/interfaces/CompanyEmployeeOM.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/interfaces/CompanyEmployeeOM.java new file mode 100644 index 0000000..7da70f3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_many/interfaces/CompanyEmployeeOM.java @@ -0,0 +1,16 @@ +package examples.entity.uni.one_to_many.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface CompanyEmployeeOM { + public void doSomeStuff(); + + public List getCompanies(); + + public List getCompanies2(String query); + + public void deleteCompanies(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Order.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Order.java new file mode 100644 index 0000000..71adb1e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Order.java @@ -0,0 +1,45 @@ +package examples.entity.uni.one_to_one; + +import java.io.Serializable; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity(name="OrderUni") +public class Order implements Serializable { + private int id; + private String orderName; + private Shipment shipment; + + public Order() { + id = (int)System.nanoTime(); + } + + @Id + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getOrderName() { + return orderName; + } + + public void setOrderName(String orderName) { + this.orderName = orderName; + } + + @OneToOne(cascade={CascadeType.PERSIST}) + public Shipment getShipment() { + return shipment; + } + + public void setShipment(Shipment shipment) { + this.shipment = shipment; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/OrderShipmentUniBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/OrderShipmentUniBean.java new file mode 100644 index 0000000..9399996 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/OrderShipmentUniBean.java @@ -0,0 +1,33 @@ +package examples.entity.uni.one_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.one_to_one.interfaces.OrderShipment; + +@Stateless +public class OrderShipmentUniBean implements OrderShipment { + @PersistenceContext + EntityManager em; + + public void doSomeStuff() { + Shipment s = new Shipment(); + s.setCity("Austin"); + s.setZipcode("78727"); + + Order o = new Order(); + o.setOrderName("Software Order"); + o.setShipment(s); + + em.persist(o); + } + + public List getOrders() { + Query q = em.createQuery("SELECT o FROM OrderUni o"); + return q.getResultList(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Shipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Shipment.java new file mode 100644 index 0000000..4f16169 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/Shipment.java @@ -0,0 +1,42 @@ +package examples.entity.uni.one_to_one; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity(name="ShipmentUni") +public class Shipment implements Serializable { + private int id; + private String city; + private String zipcode; + + public Shipment() { + 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/one_to_one/client/OrderShipmentClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/client/OrderShipmentClient.java new file mode 100644 index 0000000..666fc5d --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/client/OrderShipmentClient.java @@ -0,0 +1,30 @@ +package examples.entity.uni.one_to_one.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.entity.uni.one_to_one.Order; +import examples.entity.uni.one_to_one.interfaces.OrderShipment; + + +public class OrderShipmentClient { + public static void main(String[] args) { + try { + InitialContext ic = new InitialContext(); + OrderShipment os = (OrderShipment)ic.lookup(OrderShipment.class.getName()); + + os.doSomeStuff(); + + System.out.println("Unidirectional One-To-One client\n"); + + for (Object o : os.getOrders()) { + Order order = (Order)o; + System.out.println("Order "+order.getId()+": "+order.getOrderName()); + System.out.println("\tShipment details: "+order.getShipment().getCity()+" "+order.getShipment().getZipcode()); + } + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/interfaces/OrderShipment.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/interfaces/OrderShipment.java new file mode 100644 index 0000000..c697a10 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/uni/one_to_one/interfaces/OrderShipment.java @@ -0,0 +1,12 @@ +package examples.entity.uni.one_to_one.interfaces; + +import java.util.List; + +import javax.ejb.Remote; + +@Remote +public interface OrderShipment { + public void doSomeStuff(); + + public List getOrders(); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java new file mode 100644 index 0000000..48688c0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/CartBean.java @@ -0,0 +1,39 @@ +package examples.stateful; + +import javax.annotation.Resource; +import javax.ejb.Remove; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; + +import examples.stateful.interfaces.Cart; + +@Stateful +public class CartBean implements Cart { + @Resource SessionContext context; + private int numItems; + + public void addItem() { + numItems++; + } + + public int getItems() { + return numItems; + } + + @Remove(retainIfException=false) + public void remove1() throws Exception { + doRemove(); + } + + @Remove(retainIfException=true) + public void remove2() throws Exception { + doRemove(); + } + + private void doRemove() throws Exception { + if (numItems > 1 && numItems < 4) { + throw new Exception("blah"); + } + System.out.println("Removing cart with: "+numItems+" items."); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/META-INF/application.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/META-INF/application.xml new file mode 100644 index 0000000..eb9ae84 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/META-INF/application.xml @@ -0,0 +1,11 @@ + + + StatefulExamples + + StatefulExamplesEjb.jar + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/build.xml new file mode 100644 index 0000000..51b1f71 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/build.xml @@ -0,0 +1,25 @@ + + ]> + + + + + + + + + + + + &include; + + + + + + + + + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/client/CartClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/client/CartClient.java new file mode 100644 index 0000000..abc2da2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/client/CartClient.java @@ -0,0 +1,47 @@ +package examples.stateful.client; + +import javax.ejb.NoSuchEJBException; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.stateful.interfaces.Cart; + +public class CartClient { + public static void main(String[] args) { + try { + InitialContext ic = new InitialContext(); + System.out.println("Adding items to cart, then removing..."); + for (int i=0;i<2;i++) { + Cart cart = (Cart)ic.lookup(Cart.class.getName()); + cart.addItem(); + cart.addItem(); + System.out.println("Number of items in the cart: "+cart.getItems()); + try { + try { + if (i==0) { + cart.remove1(); + } + else { + cart.remove2(); + } + } + catch (Exception e) { + ; + } + + cart.addItem(); + cart.addItem(); + cart.addItem(); + + System.out.println("Number of items in the cart: "+cart.getItems()); + } + catch (NoSuchEJBException nsee) { + System.out.println("Cart was already removed during iteration "+i); + } + } + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/interfaces/Cart.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/interfaces/Cart.java new file mode 100644 index 0000000..a55ebbe --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateful/interfaces/Cart.java @@ -0,0 +1,11 @@ +package examples.stateful.interfaces; + +import javax.ejb.Remote; + +@Remote +public interface Cart { + public void addItem(); + public int getItems(); + public void remove1() throws Exception; + public void remove2() throws Exception; +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/HelloWorldBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/HelloWorldBean.java new file mode 100644 index 0000000..289e962 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/HelloWorldBean.java @@ -0,0 +1,12 @@ +package examples.stateless; + +import javax.ejb.Stateless; + +import examples.stateless.interfaces.HelloWorld; + +@Stateless +public class HelloWorldBean implements HelloWorld { + public String hi() { + return "hi!"; + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/META-INF/application.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/META-INF/application.xml new file mode 100644 index 0000000..a7cc0e6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/META-INF/application.xml @@ -0,0 +1,17 @@ + + + StatelessExamples + + StatelessExamplesEjb.jar + + + + StatelessExamplesWeb.war + /StatelessExamples + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java new file mode 100644 index 0000000..58697d6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java @@ -0,0 +1,66 @@ +package examples.stateless; + +import javax.ejb.EJB; +import javax.ejb.Remote; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.ejb.Stateless; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptors; +import javax.interceptor.InvocationContext; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.stateless.interceptors.AuditorInterceptor; +import examples.stateless.interceptors.LoggerInterceptor; +import examples.stateless.interfaces.PricerInjection; +import examples.stateless.interfaces.PricerLookup; +import examples.stateless.interfaces.TaxRate; + +@Stateless +@Interceptors({LoggerInterceptor.class,AuditorInterceptor.class}) +@Remote({PricerInjection.class,PricerLookup.class}) +public class PricerBean implements PricerInjection, PricerLookup { + private TaxRate taxRate; + + @EJB + private TaxRate taxRate2; + + public double getTaxLookup(double cost, String state) { + double tax = -1; + tax = cost * taxRate.getTaxRate(state); + return tax; + } + + public double getTaxInjection(double cost, String state) { + double tax = -1; + tax = cost * taxRate2.getTaxRate(state); + return tax; + } + + @PostConstruct + public void postConstruct() { + try { + InitialContext ic = new InitialContext(); + taxRate = (TaxRate)ic.lookup(TaxRate.class.getName()); + } + catch (NamingException e) { + // some kind of appropriate handling here + } + } + + @PreDestroy + public void preDestroy() { + taxRate = null; + } + + @AroundInvoke + public Object logger(InvocationContext inv) throws Exception { + System.out.println("Intercepted call via internal method to: "+inv.getMethod().getName()); + Object[] params = inv.getParameters(); + for (int i=0;i + + + + + + PricerClient + PricerClient + examples.stateless.container.PricerClientServlet + + + HelloWorld + HelloWorld + examples.stateless.container.HelloWorldServlet + + + + PricerClient + /PricerClient + + + HelloWorld + /HelloWorld + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/build.xml new file mode 100644 index 0000000..389568b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/build.xml @@ -0,0 +1,26 @@ + + ]> + + + + + + + + + + + + + &include; + + + + + + + + + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/client/PricerClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/client/PricerClient.java new file mode 100644 index 0000000..5762ab0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/client/PricerClient.java @@ -0,0 +1,36 @@ +package examples.stateless.client; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import examples.stateless.interfaces.PricerInjection; +import examples.stateless.interfaces.PricerLookup; + +public class PricerClient { + public static void main(String[] args) { + try { + InitialContext ic = new InitialContext(); + + // Prefixing the name with the pound sign (#) is a convention of Glassfish + // when using multiple interfaces to make up the business interface. The + // specification is unclear on how clients should lookup beans that implement + // more than one interface. + + PricerLookup pricerLookup = (PricerLookup)ic.lookup("#"+PricerLookup.class.getName()); + PricerInjection pricerInjection = (PricerInjection)ic.lookup("#"+PricerInjection.class.getName()); + //PricerLookup pricerLookup = (PricerLookup)ic.lookup(PricerLookup.class.getName()); + //PricerInjection pricerInjection = (PricerInjection)ic.lookup(PricerInjection.class.getName()); + //Pricer pricerLookup = (Pricer)ic.lookup(Pricer.class.getName()); + //Pricer pricerInjection = pricerLookup; + + System.out.println("Tax (using lookup) on: 8.5 for State: ny is: "+ + pricerLookup.getTaxLookup(8.5,"ny")); + + System.out.println("Tax (using injection) on: 8.5 for State: ny is: "+ + pricerInjection.getTaxInjection(8.5,"ny")); + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/HelloWorldServlet.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/HelloWorldServlet.java new file mode 100644 index 0000000..61c78a6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/HelloWorldServlet.java @@ -0,0 +1,54 @@ +package examples.stateless.container; + +import javax.ejb.EJB; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.http.HttpServlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import examples.stateless.interfaces.HelloWorld; + +/** + * Servlet Class + * + * @web.servlet name="HelloWorld" + * display-name="Name for HelloWorld" + * description="Description for HelloWorld" + * @web.servlet-mapping url-pattern="/HelloWorld" + * @web.servlet-init-param name="A parameter" + * value="A value" + */ +public class HelloWorldServlet extends HttpServlet { + @EJB HelloWorld hwInjected; + + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, + IOException { + + doPost(req,resp); + } + + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, + IOException { + + try { + InitialContext ic = new InitialContext(); + HelloWorld hw = (HelloWorld)ic.lookup(HelloWorld.class.getName()); + + PrintWriter pw = resp.getWriter(); + resp.setContentType("text/html"); + pw.println("

Lookup output: "+hw.hi()+"

"); + pw.println("

Injection output: "+hwInjected.hi()+"

"); + } + catch (NamingException e) { + e.printStackTrace(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/PricerClientServlet.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/PricerClientServlet.java new file mode 100644 index 0000000..09b59d6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/container/PricerClientServlet.java @@ -0,0 +1,84 @@ +package examples.stateless.container; + +import javax.ejb.EJB; +import javax.naming.InitialContext; +import javax.naming.NameClassPair; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.servlet.http.HttpServlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import examples.stateless.interfaces.PricerInjection; +import examples.stateless.interfaces.PricerLookup; + +/** + * Servlet Class + * + * @web.servlet name="PricerClient" display-name="Name for PricerClient" + * description="Description for PricerClient" + * @web.servlet-mapping url-pattern="/PricerClient" + * @web.servlet-init-param name="A parameter" value="A value" + */ +public class PricerClientServlet extends HttpServlet { + @EJB PricerInjection pi2; + @EJB PricerLookup pl2; + + + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + doPost(req, resp); + } + + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + double price = 85.0; + String state = "ny"; + + PrintWriter pw = resp.getWriter(); + resp.setContentType("text/html"); + pw.println("\n\t"); + + try { + InitialContext ic = new InitialContext(); + pw.println("

Here are the JNDI names bound for beans in this example:

"); + pw.println("
    "); + NamingEnumeration ne = ic.list(""); + while (ne.hasMore()) { + NameClassPair ncp = (NameClassPair) ne.next(); + pw.println("
  1. " + ncp.getName()); + } + pw.println("
"); + + // Pricer pricer = (Pricer)ic.lookup(Pricer.class.getName()); + PricerInjection pi = (PricerInjection)ic.lookup("#"+PricerInjection.class.getName()); + PricerLookup pl = (PricerLookup)ic.lookup("#"+PricerLookup.class.getName()); + + pw.println("Tax (using lookup) on: " + price + " for State: " + + state + " is: " + pl.getTaxLookup(price, state) + "
"); + + pw.println("Tax (using injection) on: " + price + " for State: " + + state + " is: " + pi.getTaxInjection(price, state) + + "
"); + + pw.println("Tax (using lookup from @EJB) on: " + price + " for State: " + + state + " is: " + pl2.getTaxLookup(price, state) + "
"); + + pw.println("Tax (using injection @EJB) on: " + price + " for State: " + + state + " is: " + pi2.getTaxInjection(price, state) + + "
"); + } + catch (NamingException e) { + e.printStackTrace(); + } + + pw.println("\t\n"); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java new file mode 100644 index 0000000..853a891 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java @@ -0,0 +1,18 @@ +package examples.stateless.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +public class AuditorInterceptor { + @AroundInvoke + public Object checkCost(InvocationContext inv) throws Exception { + if (inv.getMethod().getName().startsWith("getTax")) { + Object[] o = inv.getParameters(); + double cost = ((Double)o[0]).doubleValue(); + if (cost > 50) { + System.out.println("Cost is > 50!"); + } + } + return inv.proceed(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java new file mode 100644 index 0000000..ee37d23 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java @@ -0,0 +1,16 @@ +package examples.stateless.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +public class LoggerInterceptor { + @AroundInvoke + public Object logger(InvocationContext inv) throws Exception { + System.out.println("Intercepted call via external class to: "+inv.getMethod().getName()); + Object[] params = inv.getParameters(); + for (int i=0;i + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3