diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples')
89 files changed, 3009 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="C:/Java/glassfish.b48/lib/javaee.jar"/>
+ <classpathentry kind="lib" path="C:/Java/glassfish.b48/lib/appserv-rt.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<configurations>
+<archive destination="" exploded="false" name="MasteringEJB.ejb3" used="true">
+<folder excludes="**/container/*Servlet.class" includes="**/container/*, **/interfaces/*, **/entity/**/*" location="bin" name="bin" prefix="" project="" projectLocation="bin" used="true"/>
+<file location="SupportFiles/persistence.xml" name="persistence.xml" prefix="META-INF" project="" projectLocation="SupportFiles/persistence.xml" used="true"/>
+</archive>
+<archive destination="" exploded="false" name="MasteringEJB.war" used="true">
+<file location="SupportFiles/web.xml" name="web.xml" prefix="WEB-INF" project="" projectLocation="SupportFiles/web.xml" used="true"/>
+<folder excludes="" includes="**/container/*Servlet.class" location="bin" name="bin" prefix="WEB-INF/classes" project="" projectLocation="bin" used="true"/>
+</archive>
+<archive destination="" exploded="false" name="PricerClient.jar" used="false">
+<file location="SupportFiles/PricerClient/MANIFEST.MF" name="MANIFEST.MF" prefix="META-INF" project="" projectLocation="SupportFiles/PricerClient/MANIFEST.MF" used="true"/>
+<folder excludes="" includes="**/PricerClient.class,**/interfaces/*" location="bin" name="bin" prefix="" project="" projectLocation="bin" used="true"/>
+<file location="SupportFiles/PricerClient/application-client.xml" name="application-client.xml" prefix="META-INF" project="" projectLocation="SupportFiles/PricerClient/application-client.xml" used="true"/>
+</archive>
+<archive destination="" exploded="false" name="MasteringEJB.ear" used="true">
+<file location="MasteringEJB.ejb3" name="MasteringEJB.ejb3" prefix="" project="" projectLocation="MasteringEJB.ejb3" used="true"/>
+<file location="SupportFiles/application.xml" name="application.xml" prefix="META-INF" project="" projectLocation="SupportFiles/application.xml" used="true"/>
+<file location="MasteringEJB.war" name="MasteringEJB.war" prefix="" project="" projectLocation="MasteringEJB.war" used="true"/>
+<file location="SupportFiles/sun-application.xml" name="sun-application.xml" prefix="META-INF" project="" projectLocation="SupportFiles/sun-application.xml" used="true"/>
+<file location="PricerClient.jar" name="PricerClient.jar" prefix="" project="" projectLocation="PricerClient.jar" used="false"/>
+<file location="SecurityExampleClient.jar" name="SecurityExampleClient.jar" prefix="" project="" projectLocation="SecurityExampleClient.jar" used="false"/>
+</archive>
+</configurations>
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MasteringEJB</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.jboss.ide.eclipse.ejb3.wizards.core.EJB3ProjectNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<configurations>
+<configuration name="web" used="true">
+<task name="webdoclet" used="true" className="xdoclet.modules.web.WebDocletTask">
+<attribute name="excludedTags" value="@version,@author,@todo" used="true"/>
+<attribute name="destDir" value="src" used="true"/>
+<attribute name="mergeDir" value="" used="false"/>
+<attribute name="force" value="" used="false"/>
+<attribute name="verbose" value="true" used="true"/>
+<attribute name="addedTags" value="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}" used="true"/>
+<attribute name="ignoredtags" value="" used="false"/>
+<attribute name="validating" value="" used="false"/>
+<element name="fileset" used="true">
+<attribute name="dir" value="src" used="true"/>
+<attribute name="includes" value="**/*.java" used="true"/>
+<attribute name="excludes" value="" used="false"/>
+</element>
+<element name="deploymentdescriptor" used="true">
+<attribute name="Servletspec" value="2.4" used="true"/>
+<attribute name="smallicon" value="" used="false"/>
+<attribute name="largeicon" value="" used="false"/>
+<attribute name="displayname" value="" used="false"/>
+<attribute name="description" value="" used="false"/>
+<attribute name="distributable" value="" used="false"/>
+<attribute name="sessiontimeout" value="" used="false"/>
+<attribute name="tagLibs" value="" used="false"/>
+<attribute name="welcomeFiles" value="" used="false"/>
+<attribute name="contextParams" value="" used="false"/>
+<attribute name="useIds" value="" used="false"/>
+<attribute name="xmlencoding" value="" used="false"/>
+<attribute name="schema" value="" used="false"/>
+<attribute name="validateXML" value="" used="false"/>
+<attribute name="acceptInterfaces" value="" used="false"/>
+<attribute name="acceptAbstractClasses" value="" used="false"/>
+<attribute name="packageSubstitutions" value="" used="false"/>
+<attribute name="packageSubstitutionInheritanceSupported" value="" used="false"/>
+<attribute name="subTaskClassName" value="" used="false"/>
+<attribute name="prefixWithPackageStructure" value="" used="false"/>
+<attribute name="destinationFile" value="" used="false"/>
+<attribute name="templateURL" value="" used="false"/>
+<attribute name="templateFile" value="" used="false"/>
+<attribute name="Extent" value="" used="false"/>
+<attribute name="havingClassTag" value="" used="false"/>
+<attribute name="ofType" value="" used="false"/>
+<attribute name="subTaskName" value="" used="false"/>
+<attribute name="destDir" value="SupportFiles" used="true"/>
+<attribute name="mergeDir" value="" used="false"/>
+<attribute name="currentMethodTag" value="" used="false"/>
+<attribute name="currentClassTag" value="" used="false"/>
+<attribute name="currentFieldTag" value="" used="false"/>
+<attribute name="currentPackage" value="" used="false"/>
+<attribute name="currentMethod" value="" used="false"/>
+<attribute name="currentConstructor" value="" used="false"/>
+<attribute name="currentField" value="" used="false"/>
+<attribute name="currentClass" value="" used="false"/>
+</element>
+</task>
+</configuration>
+</configurations>
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 <GLASSFISH_HOME>/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 @@ +<property file="${basedir}/etc/common.properties"/>
+<property environment="env"/>
+<property name="appserver.home" value="${env.GLASSFISH_HOME}"/>
+<property name="src.dir" value="${basedir}/src"/>
+<property name="build.dir" value="${basedir}/build"/>
+<property name="package.dir" value="${basedir}/package"/>
+<property name="support.dir" value="${basedir}/SupportFiles"/>
+<property name="temp.dir" value="${basedir}/temp"/>
+<property name="app.src.dir" value="${src.dir}/${app.pkg}"/>
+
+<target name="build.cpath">
+ <path id="appserver.lib">
+ <fileset dir="${appserver.home}/lib" includes="*.jar" />
+ </path>
+ <pathconvert pathsep=";" property="appserver.cpath" refid="appserver.lib"/>
+</target>
+
+<target name="init.common" depends="build.cpath">
+ <property name="build.classpath" value="${appserver.cpath}:${java.home}/../lib/tools.jar"/>
+</target>
+
+<target name="compile.common" depends="init.common">
+ <mkdir dir="${build.dir}/${app.name}"/>
+ <javac srcdir="${app.src.dir}" destdir="${build.dir}/${app.name}" classpath="${build.classpath}"/>
+</target>
+
+<target name="package.client" if="create.client">
+ <mkdir dir="${package.dir}/${app.name}"/>
+ <jar destfile="${package.dir}/${app.name}/${app.name}Client.jar">
+ <fileset dir="${build.dir}/${app.name}/">
+ <include name="**/client/**"/>
+ <include name="**/*.class"/>
+ <include name="**/interfaces/**"/>
+ <exclude name="**/*Bean.class"/>
+ <exclude name="**/container/**"/>
+ </fileset>
+ </jar>
+</target>
+
+<target name="package.ejb" if="create.ejb">
+ <mkdir dir="${package.dir}/${app.name}"/>
+ <jar destfile="${package.dir}/${app.name}/${app.name}EJB.jar">
+ <metainf file="${app.src.dir}/META-INF/persistence.xml"/>
+ <fileset dir="${build.dir}/${app.name}/">
+ <exclude name="**/client/**"/>
+ <exclude name="**/container/**"/>
+ <exclude name="**/WEB-INF/**"/>
+ <include name="**/*.class"/>
+ <include name="**/interfaces/**"/>
+ </fileset>
+ </jar>
+</target>
+
+<target name="package.war" if="create.war">
+ <mkdir dir="${package.dir}/${app.name}"/>
+
+ <!-- Setup temporary staging area with proper structure -->
+ <mkdir dir="${temp.dir}/${app.name}/WEB-INF/classes"/>
+
+ <!-- Copy over files -->
+ <copy todir="${temp.dir}/${app.name}/WEB-INF/classes">
+ <fileset dir="${build.dir}/${app.name}">
+ <include name="**/container/**"/>
+ </fileset>
+ </copy>
+
+ <copy todir="${temp.dir}/${app.name}/WEB-INF" file="${app.src.dir}/WEB-INF/web.xml"/>
+
+ <jar destfile="${package.dir}/${app.name}/${app.name}Web.war">
+ <fileset dir="${temp.dir}/${app.name}"/>
+ </jar>
+
+ <!-- Remove temp staging area -->
+ <delete dir="${temp.dir}/${app.name}"/>
+</target>
+
+<target name="package.ear" if="create.ear">
+ <mkdir dir="${package.dir}/${app.name}"/>
+
+ <!-- Setup temporary staging area with proper structure -->
+ <mkdir dir="${temp.dir}/${app.name}/ear"/>
+
+ <!-- Copy over files -->
+
+ <jar destfile="${package.dir}/${app.name}/${app.name}.ear">
+ <metainf file="${app.src.dir}/META-INF/application.xml"/>
+ <fileset file="${package.dir}/${app.name}/${app.name}Web.war"/>
+ <fileset file="${package.dir}/${app.name}/${app.name}EJB.jar"/>
+ </jar>
+</target>
+
+<target name="package.common" depends="package.client,package.ejb,package.war,package.ear"/>
+
+<target name="deploy.common" if="deploy">
+ <copy todir="${appserver.home}/domains/domain1/autodeploy" file="${package.dir}/${app.name}/${app.name}.ear"/>
+</target>
+
+<target name="execClient" depends="init.common">
+ <java fork="true" classname="${client.class}" classpath="${build.classpath}:${java.home}/lib/jsse.jar:${package.dir}/${app.name}/${app.name}Client.jar"/>
+</target>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<project name="Packaging Generator" default="_packaging_generation_">
+<target name="_packaging_generation_" depends="N65540,N65565,N65590,N65623"/>
+<target name="N65540" description="MasteringEJB.ejb3">
+<jar destfile="MasteringEJB.ejb3">
+<zipfileset dir="SupportFiles" prefix="META-INF">
+<include name="persistence.xml"/>
+</zipfileset>
+<zipfileset dir="bin" includes="**/container/*, **/interfaces/*, **/entity/**/*" excludes="**/container/*Servlet.class"/>
+</jar>
+</target>
+<target name="N65565" description="MasteringEJB.war">
+<jar destfile="MasteringEJB.war">
+<zipfileset dir="SupportFiles" prefix="WEB-INF">
+<include name="web.xml"/>
+</zipfileset>
+<zipfileset dir="bin" prefix="WEB-INF/classes" includes="**/container/*Servlet.class"/>
+</jar>
+</target>
+<target name="N65590" description="PricerClient.jar"/>
+<target name="N65623" description="MasteringEJB.ear">
+<jar destfile="MasteringEJB.ear">
+<zipfileset dir=".">
+<include name="MasteringEJB.ejb3"/>
+</zipfileset>
+<zipfileset dir="SupportFiles" prefix="META-INF">
+<include name="application.xml"/>
+</zipfileset>
+<zipfileset dir=".">
+<include name="MasteringEJB.war"/>
+</zipfileset>
+<zipfileset dir="SupportFiles" prefix="META-INF">
+<include name="sun-application.xml"/>
+</zipfileset>
+</jar>
+</target>
+</project>
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<application version="1.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
+ <display-name>EntityExamples</display-name>
+ <module>
+ <ejb>EntityExamplesEjb.jar</ejb>
+ </module>
+</application>
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 @@ +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence-unit name="pu1" transaction-type="JTA">
+ <jta-data-source>jdbc/__default</jta-data-source>
+ <properties>
+ <!--Use the java2db feature -->
+ <!-- <property name="ddl-generation" value="dropandcreate"/> -->
+ <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
+ <!-- Generate the sql specific to Derby database -->
+ <property name="toplink.platform.class.name"
+ value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
+ </properties>
+ </persistence-unit>
+</persistence>
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<Student> students = new ArrayList<Student>();
+
+ 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<Student> getStudents() {
+ return students;
+ }
+
+ public void setStudents(Collection<Student> 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<Course> courses = new ArrayList<Course>();
+
+ 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<Course> getCourses() {
+ return courses;
+ }
+
+ public void setCourses(Collection<Course> 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<Employee> employees = new ArrayList<Employee>();
+
+ public Company() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @OneToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER,mappedBy="company")
+ public Collection<Employee> getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(Collection<Employee> employees) {
+ this.employees = employees;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java new file mode 100644 index 0000000..02fbbb7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeInfo.java @@ -0,0 +1,29 @@ +package examples.entity.bid.one_to_many;
+
+import java.io.Serializable;
+
+public class CompanyEmployeeInfo implements Serializable {
+ private String cName;
+ private String eName;
+
+ public CompanyEmployeeInfo(String c, String e) {
+ cName = c;
+ eName = e;
+ }
+
+ public String getCName() {
+ return cName;
+ }
+
+ public void setCName(String name) {
+ cName = name;
+ }
+
+ public String getEName() {
+ return eName;
+ }
+
+ public void setEName(String name) {
+ eName = name;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java new file mode 100644 index 0000000..77b763a --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/CompanyEmployeeOMBidBean.java @@ -0,0 +1,81 @@ +package examples.entity.bid.one_to_many;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import examples.entity.bid.one_to_many.interfaces.CompanyEmployeeOM;
+
+@Stateless
+public class CompanyEmployeeOMBidBean implements CompanyEmployeeOM {
+ @PersistenceContext
+ EntityManager em;
+
+ public void doSomeStuff() {
+ Company c = new Company();
+ c.setName("M*Power Internet Services, Inc.");
+
+ //Collection<Employee> employees = new ArrayList<Employee>();
+ Employee e = new Employee();
+ e.setName("Micah Silverman");
+ e.setSex('M');
+ e.setCompany(c);
+ //employees.add(e);
+ c.getEmployees().add(e);
+
+ e = new Employee();
+ e.setName("Tes Silverman");
+ e.setSex('F');
+ e.setCompany(c);
+ //employees.add(e);
+ c.getEmployees().add(e);
+
+ //c.setEmployees(employees);
+ em.persist(c);
+
+ c = new Company();
+ c.setName("Sun Microsystems");
+
+ //employees = new ArrayList<Employee>();
+ e = new Employee();
+ e.setName("Rima Patel");
+ e.setSex('F');
+ e.setCompany(c);
+ //employees.add(e);
+ c.getEmployees().add(e);
+
+ e = new Employee();
+ e.setName("James Gosling");
+ e.setSex('M');
+ e.setCompany(c);
+ //employees.add(e);
+ c.getEmployees().add(e);
+
+ //c.setEmployees(employees);
+ em.persist(c);
+
+ c = new Company();
+ c.setName("Bob's Bait & Tackle");
+ em.persist(c);
+ }
+
+ public List getCompanies() {
+ Query q = em.createQuery("SELECT c FROM CompanyOMBid c");
+ return q.getResultList();
+ }
+
+ public List getEmployees() {
+ Query q = em.createQuery("SELECT e FROM EmployeeOMBid e");
+ return q.getResultList();
+ }
+
+ public void deleteAll() {
+ Query q = em.createQuery("DELETE FROM EmployeeOMBid");
+ q.executeUpdate();
+ q = em.createQuery("DELETE FROM CompanyOMBid");
+ q.executeUpdate();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java new file mode 100644 index 0000000..c0e85ec --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/Employee.java @@ -0,0 +1,53 @@ +package examples.entity.bid.one_to_many;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity(name="EmployeeOMBid")
+public class Employee implements Serializable {
+ private int id;
+ private String name;
+ private char sex;
+ private Company company;
+
+ public Employee() {
+ id = (int)System.nanoTime();
+ }
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public char getSex() {
+ return sex;
+ }
+
+ public void setSex(char sex) {
+ this.sex = sex;
+ }
+
+ @ManyToOne
+ public Company getCompany() {
+ return company;
+ }
+
+ public void setCompany(Company company) {
+ this.company = company;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java new file mode 100644 index 0000000..8959f37 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/client/CompanyEmployeeClient.java @@ -0,0 +1,44 @@ +package examples.entity.bid.one_to_many.client;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import examples.entity.bid.one_to_many.Company;
+import examples.entity.bid.one_to_many.Employee;
+import examples.entity.bid.one_to_many.interfaces.CompanyEmployeeOM;
+
+
+public class CompanyEmployeeClient {
+ public static void main(String[] args) {
+ try {
+ InitialContext ic = new InitialContext();
+ CompanyEmployeeOM ceom = (CompanyEmployeeOM)ic.lookup(CompanyEmployeeOM.class.getName());
+
+ ceom.deleteAll();
+
+ ceom.doSomeStuff();
+
+ for (Object o : ceom.getCompanies()) {
+ Company c = (Company)o;
+ System.out.println("Here are the employees for company: "+c.getName());
+ for (Employee e : c.getEmployees()) {
+ System.out.println("\tName: "+e.getName()+", Sex: "+e.getSex());
+ }
+ System.out.println();
+ }
+ System.out.println();
+
+ for (Object o : ceom.getEmployees()) {
+ Employee e = (Employee)o;
+ Company c = e.getCompany();
+
+ System.out.println("Employee: "+e.getName()+" works for: "+c.getName());
+
+ System.out.println();
+ }
+ }
+ catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java new file mode 100644 index 0000000..e79f59f --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/entity/bid/one_to_many/interfaces/CompanyEmployeeOM.java @@ -0,0 +1,16 @@ +package examples.entity.bid.one_to_many.interfaces;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface CompanyEmployeeOM {
+ public void doSomeStuff();
+
+ public List getCompanies();
+
+ public List getEmployees();
+
+ public void deleteAll();
+}
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 @@ +<?xml version="1.0"?> +<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]> + +<project name="ejb3-examples-entity" default="main" basedir="../../.."> + <!-- basic settings --> + <property name="app.pkg" value="examples/entity"/> + <property name="app.name" value="EntityExamples"/> + <property name="create.client" value="true"/> + <property name="create.ejb" value="true"/> + <property name="create.ear" value="true"/> + <property name="deploy" value="true"/> + + <!-- Include common.xml --> + &include; + + <target name="main" depends="compile.common,package.common,deploy.common"/> + + <target name="single_table"> + <echo message="Executing examples.entity.single_table.client.RoadVehicleClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.single_table.client.RoadVehicleClient"/> + </antcall> + </target> + + <target name="joined"> + <echo message="Executing examples.entity.joined.client.RoadVehicleClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.joined.client.RoadVehicleClient"/> + </antcall> + </target> + + <target name="uni.one_to_one"> + <echo message="Executing examples.entity.uni.one_to_one.client.OrderShipmentClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.uni.one_to_one.client.OrderShipmentClient"/> + </antcall> + </target> + + <target name="uni.one_to_many"> + <echo message="Executing examples.entity.uni.one_to_many.client.CompanyEmployeeClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.uni.one_to_many.client.CompanyEmployeeClient"/> + </antcall> + </target> + + <target name="uni.many_to_one"> + <echo message="Executing examples.entity.uni.many_to_one.client.EmployeeAddressClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.uni.many_to_one.client.EmployeeAddressClient"/> + </antcall> + </target> + + <target name="uni.many_to_many"> + <echo message="Executing examples.entity.uni.many_to_many.client.StudentCourseClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.uni.many_to_many.client.StudentCourseClient"/> + </antcall> + </target> + + <target name="bid.one_to_one"> + <echo message="Executing examples.entity.bid.one_to_one.client.OrderShipmentClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.bid.one_to_one.client.OrderShipmentClient"/> + </antcall> + </target> + + <target name="bid.one_to_many"> + <echo message="Executing examples.entity.bid.one_to_many.client.CompanyEmployeeClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.bid.one_to_many.client.CompanyEmployeeClient"/> + </antcall> + </target> + + <target name="bid.many_to_many"> + <echo message="Executing examples.entity.bid.many_to_many.client.StudentCourseClient"/> + <antcall target="execClient"> + <param name="client.class" value="examples.entity.bid.many_to_many.client.StudentCourseClient"/> + </antcall> + </target> + + <target name="run" depends="single_table,joined,uni.one_to_one,uni.one_to_many,uni.many_to_one,uni.many_to_many,bid.one_to_one,bid.one_to_many,bid.many_to_many"/> + <!-- target name="run" depends="uni.one_to_one,uni.one_to_many"/ --> +</project>
\ 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<Car> al = new ArrayList<Car>();
+ 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<Student> students = new ArrayList<Student>();
+
+ 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<Student> getStudents() {
+ return students;
+ }
+
+ public void setStudents(Collection<Student> 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<Course> courses = new ArrayList<Course>();
+
+ 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<Course> getCourses() {
+ return courses;
+ }
+
+ public void setCourses(Collection<Course> 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<Student> 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<Student> 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<Employee> 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<Employee> getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(Collection<Employee> 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<Employee> employees = new ArrayList<Employee>();
+ Employee e = new Employee();
+ e.setName("Micah Silverman");
+ e.setSex('M');
+ employees.add(e);
+
+ e = new Employee();
+ e.setName("Tes Silverman");
+ e.setSex('F');
+ employees.add(e);
+
+ c.setEmployees(employees);
+ em.persist(c);
+
+ c = new Company();
+ c.setName("Sun Microsystems");
+
+ employees = new ArrayList<Employee>();
+ e = new Employee();
+ e.setName("Rima Patel");
+ e.setSex('F');
+ employees.add(e);
+
+ e = new Employee();
+ e.setName("James Gosling");
+ e.setSex('M');
+ employees.add(e);
+
+ c.setEmployees(employees);
+ em.persist(c);
+
+ c = new Company();
+ c.setName("Bob's Bait & Tackle");
+ em.persist(c);
+ }
+
+ public List getCompanies() {
+ Query q = em.createQuery("SELECT c FROM CompanyOMUni c");
+ return q.getResultList();
+ }
+
+ public List getCompanies2(String query) {
+ Query q = em.createQuery(query);
+ return q.getResultList();
+ }
+
+ public void deleteCompanies() {
+ Query q = em.createQuery("DELETE FROM CompanyOMUni");
+ q.executeUpdate();
+ }
+}
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<application version="1.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
+ <display-name>StatefulExamples</display-name>
+ <module>
+ <ejb>StatefulExamplesEjb.jar</ejb>
+ </module>
+</application>
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 @@ +<?xml version="1.0"?> +<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]> + +<project name="ejb3-examples-stateful" default="main" basedir="../../.."> + <!-- basic settings --> + <property name="app.pkg" value="examples/stateful"/> + <property name="app.name" value="StatefulExamples"/> + <property name="create.client" value="true"/> + <property name="create.ejb" value="true"/> + <property name="create.ear" value="true"/> + <property name="deploy" value="true"/> + + <!-- Include common.xml --> + &include; + + <target name="main" depends="compile.common,package.common,deploy.common"/> + + <target name="run"> + <antcall target="execClient"> + <param name="client.class" value="examples.stateful.client.CartClient"/> + </antcall> + </target> +</project> + + 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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<application version="1.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
+ <display-name>StatelessExamples</display-name>
+ <module>
+ <ejb>StatelessExamplesEjb.jar</ejb>
+ </module>
+ <module>
+ <web>
+ <web-uri>StatelessExamplesWeb.war</web-uri>
+ <context-root>/StatelessExamples</context-root>
+ </web>
+ </module>
+</application>
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<params.length;i++) {
+ System.out.println("\tparam: "+params[i]);
+ }
+ return inv.proceed();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/TaxRateBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/TaxRateBean.java new file mode 100644 index 0000000..fb51d29 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/TaxRateBean.java @@ -0,0 +1,20 @@ +package examples.stateless;
+
+import javax.ejb.Stateless;
+
+import examples.stateless.interfaces.TaxRate;
+
+@Stateless
+public class TaxRateBean implements TaxRate {
+ public double getTaxRate(String state) {
+ if (state.equalsIgnoreCase("ny")) {
+ return 0.0875;
+ }
+ else if (state.equalsIgnoreCase("nj")) {
+ return 0.03;
+ }
+ else {
+ return 0.0;
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/WEB-INF/web.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/WEB-INF/web.xml new file mode 100644 index 0000000..0100696 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/WEB-INF/web.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> + <distributable/> + + <servlet> + <display-name>PricerClient</display-name> + <servlet-name>PricerClient</servlet-name> + <servlet-class>examples.stateless.container.PricerClientServlet</servlet-class> + </servlet> + <servlet> + <display-name>HelloWorld</display-name> + <servlet-name>HelloWorld</servlet-name> + <servlet-class>examples.stateless.container.HelloWorldServlet</servlet-class> + </servlet> +
+ <servlet-mapping> + <servlet-name>PricerClient</servlet-name> + <url-pattern>/PricerClient</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>HelloWorld</servlet-name> + <url-pattern>/HelloWorld</url-pattern> + </servlet-mapping> +</web-app> 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 @@ +<?xml version="1.0"?> +<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]> + +<project name="ejb3-examples-stateless" default="main" basedir="../../.."> + <!-- basic settings --> + <property name="app.pkg" value="examples/stateless"/> + <property name="app.name" value="StatelessExamples"/> + <property name="create.client" value="true"/> + <property name="create.ejb" value="true"/> + <property name="create.war" value="true"/> + <property name="create.ear" value="true"/> + <property name="deploy" value="true"/> + + <!-- Include common.xml --> + &include; + + <target name="main" depends="compile.common,package.common,deploy.common"/> + + <target name="run"> + <antcall target="execClient"> + <param name="client.class" value="examples.stateless.client.PricerClient"/> + </antcall> + </target> +</project> + + 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("<h4>Lookup output: "+hw.hi()+"</h4>");
+ pw.println("<h4>Injection output: "+hwInjected.hi()+"</h4>");
+ }
+ 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("<HTML>\n\t<BODY>");
+
+ try {
+ InitialContext ic = new InitialContext();
+ pw.println("<h3>Here are the JNDI names bound for beans in this example:</h3>");
+ pw.println("<ol>");
+ NamingEnumeration ne = ic.list("");
+ while (ne.hasMore()) {
+ NameClassPair ncp = (NameClassPair) ne.next();
+ pw.println("<li>" + ncp.getName());
+ }
+ pw.println("</ol>");
+
+ // 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) + "<br>");
+
+ pw.println("Tax (using injection) on: " + price + " for State: "
+ + state + " is: " + pi.getTaxInjection(price, state)
+ + "<br>");
+
+ pw.println("Tax (using lookup from @EJB) on: " + price + " for State: "
+ + state + " is: " + pl2.getTaxLookup(price, state) + "<br>");
+
+ pw.println("Tax (using injection @EJB) on: " + price + " for State: "
+ + state + " is: " + pi2.getTaxInjection(price, state)
+ + "<br>");
+ }
+ catch (NamingException e) {
+ e.printStackTrace();
+ }
+
+ pw.println("\t</BODY>\n</HTML>");
+ }
+}
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<params.length;i++) {
+ System.out.println("\tparam: "+params[i]);
+ }
+ return inv.proceed();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/HelloWorld.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/HelloWorld.java new file mode 100644 index 0000000..5d99f5b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/HelloWorld.java @@ -0,0 +1,8 @@ +package examples.stateless.interfaces;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface HelloWorld {
+ public String hi();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/Pricer.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/Pricer.java new file mode 100644 index 0000000..9f74419 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/Pricer.java @@ -0,0 +1,9 @@ +package examples.stateless.interfaces; + +import javax.ejb.Remote; + +@Remote +public interface Pricer { + public double getTaxLookup(double cost, String state); + public double getTaxInjection(double cost, String state); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerInjection.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerInjection.java new file mode 100644 index 0000000..4fcecb5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerInjection.java @@ -0,0 +1,5 @@ +package examples.stateless.interfaces; + +public interface PricerInjection { + public double getTaxInjection(double cost, String state); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerLookup.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerLookup.java new file mode 100644 index 0000000..76996c6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/PricerLookup.java @@ -0,0 +1,5 @@ +package examples.stateless.interfaces; + +public interface PricerLookup { + public double getTaxLookup(double cost, String state); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/TaxRate.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/TaxRate.java new file mode 100644 index 0000000..9ab2b8f --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interfaces/TaxRate.java @@ -0,0 +1,8 @@ +package examples.stateless.interfaces; + +import javax.ejb.Remote; + +@Remote +public interface TaxRate { + public double getTaxRate(String state); +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/jndi.properties b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/jndi.properties new file mode 100644 index 0000000..483fac9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/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/xdoclet-build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/xdoclet-build.xml new file mode 100644 index 0000000..2d777d1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/xdoclet-build.xml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<project default="_xdoclet_generation_" name="XDoclet Generator">
+<property file="xdoclet-build.properties"/>
+<property name="eclipse.home" value="C:/Java/eclipse"/>
+<property name="xdoclet.basedir" value="${eclipse.home}/plugins/org.jboss.ide.eclipse.xdoclet.core_1.5.0.RC1"/>
+<property name="jboss.net.version" value="4.0"/>
+<path id="project.classpath"><pathelement location="bin"/> +<pathelement location="C:/Java/glassfish/lib/javaee.jar"/> +<pathelement location="C:/Java/glassfish/lib/appserv-rt.jar"/> +</path>
+<path id="xdoclet.classpath">
+<path refid="project.classpath"/>
+<fileset dir="${xdoclet.basedir}">
+<include name="*.jar"/>
+<exclude name="xdoclet-module-jboss-net-*.jar"/>
+</fileset>
+<fileset dir="${xdoclet.basedir}">
+<include name="xdoclet-module-jboss-net-${jboss.net.version}*.jar"/>
+</fileset>
+</path>
+<target name="_xdoclet_generation_" depends="N10004"/>
+<target name="N10004" description="web">
+<taskdef classpathref="xdoclet.classpath" classname="xdoclet.modules.web.WebDocletTask" name="webdoclet"/><webdoclet excludedTags="@version,@author,@todo" destDir="src" verbose="true" addedTags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}" >
+
+
+
+
+
+
+
+
+<fileset dir="src" includes="**/*.java" >
+
+
+
+</fileset>
+<deploymentdescriptor Servletspec="2.4" destDir="SupportFiles" >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</deploymentdescriptor>
+</webdoclet></target>
+</project>
|
