[jboss-cvs] JBossAS SVN: r105069 - in projects/ejb-book/trunk/chxx-employeeregistry/src: main/java/org/jboss/ejb3/examples/employeeregistry/chxx and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 20 13:26:52 EDT 2010
Author: ALRubinger
Date: 2010-05-20 13:26:51 -0400 (Thu, 20 May 2010)
New Revision: 105069
Added:
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/SimpleEmployee.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Address.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Computer.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Customer.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Employee.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Phone.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/PhoneType.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Task.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Team.java
Removed:
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/Employee.java
projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/entity/
Modified:
projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java
Log:
[EJBBOOK-27] Add relationship mapping entities for the examples
Deleted: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/Employee.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/Employee.java 2010-05-20 17:22:47 UTC (rev 105068)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/Employee.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.examples.employeeregistry.chxx.entitymanager;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-/**
- * Represents an Employee in the system. Modeled as a simple
- * value object with some additional EJB and JPA annotations.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
- at Entity
-// Mark that we're an Entity Bean, EJB's integration point
-// with Java Persistence
-public class Employee
-{
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Primary key of this entity
- */
- @Id
- // Mark that this field is the primary key
- private Long id;
-
- /**
- * Name of the employee
- */
- private String name;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Default constructor, required by JPA
- */
- public Employee()
- {
-
- }
-
- /**
- * Convenience constructor
- */
- public Employee(final long id, final String name)
- {
- // Set
- this.id = id;
- this.name = name;
- }
-
- //-------------------------------------------------------------------------------------||
- // Accessors / Mutators ---------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @return the id
- */
- public Long getId()
- {
- return id;
- }
-
- /**
- * @param id the id to set
- */
- public void setId(final Long id)
- {
- this.id = id;
- }
-
- /**
- * @return the name
- */
- public String getName()
- {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(final String name)
- {
- this.name = name;
- }
-
- /**
- * {@inheritDoc}
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return Employee.class.getSimpleName() + " [id=" + id + ", name=" + name + "]";
- }
-}
Copied: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/SimpleEmployee.java (from rev 105004, projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/Employee.java)
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/SimpleEmployee.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/entitymanager/SimpleEmployee.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.entitymanager;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * Represents an Employee in the system. Modeled as a simple
+ * value object with some additional EJB and JPA annotations.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+// Mark that we're an Entity Bean, EJB's integration point
+// with Java Persistence
+public class SimpleEmployee
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Primary key of this entity
+ */
+ @Id
+ // Mark that this field is the primary key
+ private Long id;
+
+ /**
+ * Name of the employee
+ */
+ private String name;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Default constructor, required by JPA
+ */
+ public SimpleEmployee()
+ {
+
+ }
+
+ /**
+ * Convenience constructor
+ */
+ public SimpleEmployee(final long id, final String name)
+ {
+ // Set
+ this.id = id;
+ this.name = name;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the id
+ */
+ public Long getId()
+ {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(final Long id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return SimpleEmployee.class.getSimpleName() + " [id=" + id + ", name=" + name + "]";
+ }
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Address.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Address.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Address.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
+
+/**
+ * Represents a simple Address. Each {@link Employee} will
+ * have one, though the relationship is not bidirectional.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+// Mark that we're an Entity Bean, EJB's integration point
+// with Java Persistence
+public class Address extends AutogenIdentityBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Street Address
+ */
+ @Column(length = 100)
+ // Length of VARCHAR
+ private String street;
+
+ /**
+ * City
+ */
+ @Column(length = 100)
+ // Length of VARCHAR
+ private String city;
+
+ /**
+ * Postal code of the state
+ */
+ @Column(length = 2)
+ // Length of VARCHAR
+ private String state;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Default constructor, required by JPA
+ */
+ public Address()
+ {
+
+ }
+
+ /**
+ * Convenience constructor
+ */
+ public Address(final String street, final String city, final String state)
+ {
+ // Set
+ this.setStreet(street);
+ this.setCity(city);
+ this.setState(state);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the street
+ */
+ public String getStreet()
+ {
+ return street;
+ }
+
+ /**
+ * @param street the street to set
+ */
+ public void setStreet(String street)
+ {
+ this.street = street;
+ }
+
+ /**
+ * @return the city
+ */
+ public String getCity()
+ {
+ return city;
+ }
+
+ /**
+ * @param city the city to set
+ */
+ public void setCity(String city)
+ {
+ this.city = city;
+ }
+
+ /**
+ * @return the state
+ */
+ public String getState()
+ {
+ return state;
+ }
+
+ /**
+ * @param state the state to set
+ */
+ public void setState(String state)
+ {
+ this.state = state;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return Address.class.getSimpleName() + " [city=" + city + ", state=" + state + ", street=" + street + "]";
+ }
+
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Computer.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Computer.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Computer.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.OneToOne;
+
+import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
+
+/**
+ * Represents an {@link Employee}'s computer. The
+ * relationship is bidirectional in the case the computer
+ * is lost or in for servicing and needs to be returned.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Computer extends AutogenIdentityBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Manufacturer of the computer
+ */
+ @Column(length = 100)
+ // Length of VARCHAR
+ private String make;
+
+ /**
+ * Model of the computer
+ */
+ @Column(length = 100)
+ // Length of VARCHAR
+ private String model;
+
+ @OneToOne
+ // Bidirectional relationship, mappedBy
+ // is declared on the non-owning side
+ private Employee owner;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the make
+ */
+ public String getMake()
+ {
+ return make;
+ }
+
+ /**
+ * @param make the make to set
+ */
+ public void setMake(String make)
+ {
+ this.make = make;
+ }
+
+ /**
+ * @return the model
+ */
+ public String getModel()
+ {
+ return model;
+ }
+
+ /**
+ * @param model the model to set
+ */
+ public void setModel(String model)
+ {
+ this.model = model;
+ }
+
+ /**
+ * @return the owner
+ */
+ public Employee getOwner()
+ {
+ return owner;
+ }
+
+ /**
+ * @param owner the owner to set
+ */
+ public void setOwner(final Employee owner)
+ {
+ this.owner = owner;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return Computer.class.getSimpleName() + " [make=" + make + ", model=" + model + "]";
+ }
+
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Customer.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Customer.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Customer.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+
+import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
+
+/**
+ * Represents a Customer. Each customer may have an {@link Employee}
+ * which is the primary contact for the account, but the relationship
+ * is unidirectional
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Customer extends AutogenIdentityBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Name
+ */
+ private String name;
+
+ /**
+ * The primary {@link Employee} contact for this {@link Customer}
+ */
+ @ManyToOne
+ // Unidirectional
+ private Employee primaryContact;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Default constructor, required by JPA
+ */
+ public Customer()
+ {
+
+ }
+
+ /**
+ * Convenience constructor
+ */
+ public Customer(final String name)
+ {
+ // Set
+ this.name = name;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * @return the primaryContact
+ */
+ public Employee getPrimaryContact()
+ {
+ return primaryContact;
+ }
+
+ /**
+ * @param primaryContact the primaryContact to set
+ */
+ public void setPrimaryContact(final Employee primaryContact)
+ {
+ this.primaryContact = primaryContact;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Overridden Implementations ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return Customer.class.getSimpleName() + " [name=" + name + "]";
+ }
+
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Employee.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Employee.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Employee.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,250 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+
+import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
+
+/**
+ * Represents an Employee in the system. Modeled as a simple
+ * value object with some additional EJB and JPA annotations.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+// Mark that we're an Entity Bean, EJB's integration point
+// with Java Persistence
+public class Employee extends AutogenIdentityBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Name
+ */
+ private String name;
+
+ /**
+ * The employee's address
+ */
+ @OneToOne
+ // Unidirectional relationship
+ private Address address;
+
+ /**
+ * The employee's computer
+ */
+ @OneToOne(mappedBy = "owner")
+ // Bidirectional relationship
+ private Computer computer;
+
+ /**
+ * Manager of the {@link Employee}
+ */
+ @ManyToOne
+ private Employee manager;
+
+ /**
+ * {@link Employee}s reporting to this {@link Employee}
+ */
+ @OneToMany(mappedBy = "peons")
+ private Collection<Employee> peons;
+
+ /**
+ * All {@link Phone}s for this {@link Employee}
+ */
+ @OneToMany
+ // Unidirectional relationship
+ private Collection<Phone> phones;
+
+ /**
+ * Other {@link Employee}s on this {@link Employee}'s team
+ */
+ @ManyToMany(mappedBy = "members")
+ private Collection<Team> teams;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Default constructor, required by JPA
+ */
+ public Employee()
+ {
+ peons = new ArrayList<Employee>();
+ phones = new ArrayList<Phone>();
+ teams = new ArrayList<Team>();
+ }
+
+ /**
+ * Convenience constructor
+ */
+ public Employee(final String name)
+ {
+ this();
+ // Set
+ this.name = name;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * @return the address
+ */
+ public Address getAddress()
+ {
+ return address;
+ }
+
+ /**
+ * @param address the address to set
+ */
+ public void setAddress(final Address address)
+ {
+ this.address = address;
+ }
+
+ /**
+ * @return the computer
+ */
+ public Computer getComputer()
+ {
+ return computer;
+ }
+
+ /**
+ * @param computer the computer to set
+ */
+ public void setComputer(final Computer computer)
+ {
+ this.computer = computer;
+ }
+
+ /**
+ * @return the manager
+ */
+ public Employee getManager()
+ {
+ return manager;
+ }
+
+ /**
+ * @param manager the manager to set
+ */
+ public void setManager(final Employee manager)
+ {
+ this.manager = manager;
+ }
+
+ /**
+ * @return the peons
+ */
+ public Collection<Employee> getPeons()
+ {
+ return peons;
+ }
+
+ /**
+ * @param peons the peons to set
+ */
+ public void setPeons(final Collection<Employee> peons)
+ {
+ this.peons = peons;
+ }
+
+ /**
+ * @return the teams
+ */
+ public Collection<Team> getTeams()
+ {
+ return teams;
+ }
+
+ /**
+ * @param teams the teams to set
+ */
+ public void setTeams(final Collection<Team> teams)
+ {
+ this.teams = teams;
+ }
+
+ /**
+ * @return the phones
+ */
+ public Collection<Phone> getPhones()
+ {
+ return phones;
+ }
+
+ /**
+ * @param phones the phones to set
+ */
+ public void setPhones(final Collection<Phone> phones)
+ {
+ this.phones = phones;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Overridden Implementations ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return Employee.class.getSimpleName() + " [name=" + name + "]";
+ }
+
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Phone.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Phone.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Phone.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+
+import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
+
+/**
+ * Represents a Phone number. An {@link Employee}
+ * may have many, but the relationship is unidirectional.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+// Mark that we're an Entity Bean, EJB's integration point
+// with Java Persistence
+public class Phone extends AutogenIdentityBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Phone number
+ */
+ private String number;
+
+ /**
+ * Type
+ */
+ @Enumerated(EnumType.STRING)
+ private PhoneType type;
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the number
+ */
+ public String getNumber()
+ {
+ return number;
+ }
+
+ /**
+ * @param number the number to set
+ */
+ public void setNumber(String number)
+ {
+ this.number = number;
+ }
+
+ /**
+ * @return the type
+ */
+ public PhoneType getType()
+ {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(PhoneType type)
+ {
+ this.type = type;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return Phone.class.getSimpleName() + " [number=" + number + ", type=" + type + "]";
+ }
+
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/PhoneType.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/PhoneType.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/PhoneType.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+/**
+ * Type of number associated with a {@link Phone}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public enum PhoneType {
+ MOBILE, HOME, WORK
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Task.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Task.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Task.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+
+import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
+
+/**
+ * Represents a task to be completed or tracked as an issue.
+ * These may be assigned to any number of {@link Employee}s,
+ * and {@link Employee}s may have any number of issues. However
+ * the relationship is unidirectional from task to employee.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Task extends AutogenIdentityBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Name
+ */
+ private String description;
+
+ /**
+ * {@link Employee} in charge of this {@link Task}
+ */
+ @ManyToMany
+ private Collection<Employee> owners;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Default constructor, required by JPA
+ */
+ public Task()
+ {
+ owners = new ArrayList<Employee>();
+ }
+
+ /**
+ * Convenience constructor
+ */
+ public Task(final String description)
+ {
+ this();
+ // Set
+ this.description = description;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the description
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /**
+ * @param description the description to set
+ */
+ public void setDescription(final String description)
+ {
+ this.description = description;
+ }
+
+ /**
+ * @return the owners
+ */
+ public Collection<Employee> getOwners()
+ {
+ return owners;
+ }
+
+ /**
+ * @param owners the owners to set
+ */
+ public void setOwners(final Collection<Employee> owners)
+ {
+ this.owners = owners;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return Task.class.getSimpleName() + " [description=" + description + "]";
+ }
+}
Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Team.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Team.java (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chxx/relationships/Team.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chxx.relationships;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+
+import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
+
+/**
+ * Represents a team of {@link Employee}s who typically
+ * work in the same area. Employees may be a part of many teams.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Team extends AutogenIdentityBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Name of the Team
+ */
+ private String name;
+
+ /**
+ * {@link Employee}s on this {@link Task}.
+ */
+ @ManyToMany
+ private Collection<Employee> members;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Default constructor, required by JPA
+ */
+ public Team()
+ {
+ members = new ArrayList<Employee>();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the members
+ */
+ public Collection<Employee> getMembers()
+ {
+ return members;
+ }
+
+ /**
+ * @param members the members to set
+ */
+ public void setMembers(final Collection<Employee> members)
+ {
+ this.members = members;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return Team.class.getSimpleName() + " [name=" + name + "]";
+ }
+}
Modified: projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java 2010-05-20 17:22:47 UTC (rev 105068)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java 2010-05-20 17:26:51 UTC (rev 105069)
@@ -37,7 +37,14 @@
import org.jboss.arquillian.api.RunMode;
import org.jboss.arquillian.api.RunModeType;
import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.ejb3.examples.employeeregistry.chxx.entitymanager.Employee;
+import org.jboss.ejb3.examples.employeeregistry.chxx.entitymanager.SimpleEmployee;
+import org.jboss.ejb3.examples.employeeregistry.chxx.relationships.Address;
+import org.jboss.ejb3.examples.employeeregistry.chxx.relationships.Computer;
+import org.jboss.ejb3.examples.employeeregistry.chxx.relationships.Customer;
+import org.jboss.ejb3.examples.employeeregistry.chxx.relationships.Employee;
+import org.jboss.ejb3.examples.employeeregistry.chxx.relationships.Phone;
+import org.jboss.ejb3.examples.employeeregistry.chxx.relationships.Task;
+import org.jboss.ejb3.examples.employeeregistry.chxx.relationships.Team;
import org.jboss.ejb3.examples.employeeregistry.chyy.mapping.EmbeddedEmployeePK;
import org.jboss.ejb3.examples.employeeregistry.chyy.mapping.EmployeeType;
import org.jboss.ejb3.examples.employeeregistry.chyy.mapping.EmployeeWithEmbeddedPK;
@@ -94,10 +101,10 @@
@Deployment
public static JavaArchive getDeployment()
{
- final JavaArchive archive = ShrinkWrap.create("test.jar", JavaArchive.class).addPackages(true,
- Employee.class.getPackage(), EmployeeWithMappedSuperClassId.class.getPackage()).addManifestResource(
- "persistence.xml").addPackages(false, TxWrappingLocalBusiness.class.getPackage(),
- EntityManagerExposingBean.class.getPackage());
+ final JavaArchive archive = ShrinkWrap.create("entities.jar", JavaArchive.class).addPackages(false,
+ SimpleEmployee.class.getPackage(), EmployeeWithMappedSuperClassId.class.getPackage(),
+ Employee.class.getPackage(), TxWrappingLocalBusiness.class.getPackage(),
+ EntityManagerExposingBean.class.getPackage()).addManifestResource("persistence.xml");
log.info(archive.toString(true));
return archive;
}
@@ -183,15 +190,20 @@
@Override
public Void call() throws Exception
{
- // JPA QL String to remove all Employees
+
final EntityManager em = emHook.getEntityManager();
- em.createQuery("DELETE FROM " + Employee.class.getSimpleName() + " o").executeUpdate();
- em.createQuery("DELETE FROM " + EmployeeWithMappedSuperClassId.class.getSimpleName() + " o")
- .executeUpdate();
- em.createQuery("DELETE FROM " + EmployeeWithExternalCompositePK.class.getSimpleName() + " o");
- em.createQuery("DELETE FROM " + EmployeeWithProperties.class.getSimpleName() + " o")
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(SimpleEmployee.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(EmployeeWithMappedSuperClassId.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(EmployeeWithExternalCompositePK.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(EmployeeWithProperties.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(Address.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(Phone.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(Computer.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(Customer.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(Task.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(Team.class, em);
+ EmployeeIntegrationTest.this.deleteAllEntitiesOfType(Employee.class, em);
- .executeUpdate();
return null;
}
@@ -228,17 +240,17 @@
public Void call() throws Exception
{
// Create a few plain instances
- final Employee josh = new Employee(ID_DAVE, NAME_DAVE);
- final Employee dave = new Employee(ID_JOSH, NAME_JOSH);
- final Employee rick = new Employee(ID_RICK, NAME_RICK);
+ final SimpleEmployee josh = new SimpleEmployee(ID_DAVE, NAME_DAVE);
+ final SimpleEmployee dave = new SimpleEmployee(ID_JOSH, NAME_JOSH);
+ final SimpleEmployee rick = new SimpleEmployee(ID_RICK, NAME_RICK);
// Get the EntityManager from our test hook
final EntityManager em = emHook.getEntityManager();
// Now first check if any employees are found in the underlying persistent
// storage (shouldn't be)
- Assert
- .assertNull("Employees should not have been added to the EM yet", em.find(Employee.class, ID_DAVE));
+ Assert.assertNull("Employees should not have been added to the EM yet", em.find(SimpleEmployee.class,
+ ID_DAVE));
// Check if the object is managed (shouldn't be)
Assert.assertFalse("Employee should not be managed yet", em.contains(josh));
@@ -268,7 +280,7 @@
final EntityManager em = emHook.getEntityManager();
// Look up "Dave" by ID from the EM
- final Employee dave = em.find(Employee.class, ID_DAVE);
+ final SimpleEmployee dave = em.find(SimpleEmployee.class, ID_DAVE);
// Change Dave's name
dave.setName(NAME_DAVE_NEW);
@@ -291,7 +303,7 @@
final EntityManager em = emHook.getEntityManager();
// Make a new "Dave" as a detached object with same primary key, but a different name
- final Employee dave = new Employee(ID_DAVE, NAME_DAVE_NEW);
+ final SimpleEmployee dave = new SimpleEmployee(ID_DAVE, NAME_DAVE_NEW);
// Merge these changes on the detached instance with the DB
em.merge(dave);
@@ -326,7 +338,7 @@
final EntityManager em = emHook.getEntityManager();
// Make a new "Dave" instance
- final Employee dave = em.find(Employee.class, ID_DAVE);
+ final SimpleEmployee dave = em.find(SimpleEmployee.class, ID_DAVE);
log.info("Lookup of Dave after we changed his name on a detached instance: " + dave);
// Ensure that the last name change we gave to Dave did not take affect
@@ -350,7 +362,7 @@
final EntityManager em = emHook.getEntityManager();
// Look up Rick
- final Employee rick = em.find(Employee.class, ID_RICK);
+ final SimpleEmployee rick = em.find(SimpleEmployee.class, ID_RICK);
// Remove
em.remove(rick);
@@ -373,7 +385,7 @@
final EntityManager em = emHook.getEntityManager();
// Look up Rick
- final Employee rick = em.find(Employee.class, ID_RICK);
+ final SimpleEmployee rick = em.find(SimpleEmployee.class, ID_RICK);
// Assert
Assert.assertNull("Rick should have been removed from the DB", rick);
@@ -650,4 +662,22 @@
throw tee.getCause();
}
}
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Issues a JPA QL Update to remove all entities of the specified type
+ * @param type
+ * @param em
+ */
+ private void deleteAllEntitiesOfType(final Class<?> type, final EntityManager em)
+ {
+ assert em != null : EntityManager.class.getSimpleName() + " must be specified";
+ assert type != null : "type to be removed must be specified";
+ // JPA QL String to remove all of the specified type
+ log.info("Removed: " + em.createQuery("DELETE FROM " + type.getSimpleName() + " o").executeUpdate()
+ + " entities of type " + type);
+ }
}
More information about the jboss-cvs-commits
mailing list