Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.pc.companyAnnotatedJPA » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software 
   12    * distributed under the License is distributed on an "AS IS" BASIS, 
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
   14    * See the License for the specific language governing permissions and 
   15    * limitations under the License.
   16    */
   17    
   18   package org.apache.jdo.tck.pc.companyAnnotatedJPA;
   19   
   20   import javax.persistence;
   21   
   22   import java.io.ObjectInputStream;
   23   import java.io.IOException;
   24   
   25   import java.util.Collections;
   26   import java.util.Date;
   27   import java.util.HashSet;
   28   import java.util.Set;
   29   import org.apache.jdo.tck.pc.company.IAddress;
   30   import org.apache.jdo.tck.pc.company.IDentalInsurance;
   31   import org.apache.jdo.tck.pc.company.IDepartment;
   32   
   33   import org.apache.jdo.tck.pc.company.IEmployee;
   34   import org.apache.jdo.tck.pc.company.IMedicalInsurance;
   35   import org.apache.jdo.tck.util.EqualityHelper;
   36   
   37   /**
   38    * This class represents an employee.
   39    */
   40   @Entity
   41   @Table(name="employees")
   42   public abstract class JPAAppEmployee extends JPAAppPerson implements IEmployee {
   43   
   44       @Column(name="HIREDATE")
   45       @Temporal(TemporalType.TIMESTAMP)
   46       private Date             hiredate;
   47       @Column(name="WEEKLYHOURS")
   48       private double           weeklyhours;
   49       @OneToOne(mappedBy="employee")
   50       private JPAAppDentalInsurance  dentalInsurance;
   51       @OneToOne(mappedBy="employee")
   52       private JPAAppMedicalInsurance medicalInsurance;
   53       @Column(name="DEPARTMENT")
   54       private JPAAppDepartment       department;
   55       @Column(name="FUNDINGDEPT")
   56       private JPAAppDepartment       fundingDept;
   57       @Column(name="MANAGER")
   58       private JPAAppEmployee         manager;
   59       @Column(name="MENTOR")
   60       private JPAAppEmployee         mentor;
   61       @OneToOne(mappedBy="mentor")
   62       private JPAAppEmployee         protege;
   63       @Column(name="HRADVISOR")
   64       private JPAAppEmployee         hradvisor;
   65       @ManyToMany(mappedBy="reviewers",
   66           targetEntity=org.apache.jdo.tck.pc.companyAnnotatedJPA.JPAAppProject.class)
   67       private Set reviewedProjects = new HashSet();
   68       @ManyToMany(mappedBy="members",
   69           targetEntity=org.apache.jdo.tck.pc.companyAnnotatedJPA.JPAAppProject.class)
   70       private Set projects = new HashSet();
   71       @OneToMany(mappedBy="manager",
   72           targetEntity=org.apache.jdo.tck.pc.companyAnnotatedJPA.JPAAppEmployee.class)
   73       private Set team = new HashSet();
   74       @OneToMany(mappedBy="hradvisor",
   75           targetEntity=org.apache.jdo.tck.pc.companyAnnotatedJPA.JPAAppEmployee.class)
   76       private Set hradvisees = new HashSet();
   77   
   78       /** This is the JDO-required no-args constructor */
   79       protected JPAAppEmployee() {}
   80   
   81       /**
   82        * Construct an <code>JPAAppEmployee</code> instance.
   83        * 
   84        * 
   85        * @param personid The identifier for the person.
   86        * @param firstname The first name of the employee.
   87        * @param lastname The last name of the employee.
   88        * @param middlename The middle name of the employee.
   89        * @param birthdate The birth date of the employee.
   90        * @param hiredate The date that the employee was hired.
   91        */
   92       public JPAAppEmployee(long personid, String firstname, String lastname, 
   93                       String middlename, Date birthdate,
   94                       Date hiredate) {
   95           super(personid, firstname, lastname, middlename, birthdate);
   96           this.hiredate = hiredate;
   97       }
   98   
   99       /**
  100        * Construct an <code>JPAAppEmployee</code> instance.
  101        * 
  102        * 
  103        * @param personid The identifier for the person.
  104        * @param firstname The first name of the employee.
  105        * @param lastname The last name of the employee.
  106        * @param middlename The middle name of the employee.
  107        * @param birthdate The birth date of the employee.
  108        * @param address The address of the employee.
  109        * @param hiredate The date that the employee was hired.
  110        */
  111       public JPAAppEmployee(long personid, String firstname, String lastname, 
  112                       String middlename, Date birthdate, IAddress address,
  113                       Date hiredate) {
  114           super(personid, firstname, lastname, middlename, birthdate,
  115                   (JPAAppAddress)address);
  116           this.hiredate = hiredate;
  117       }
  118   
  119       /**
  120        * Get the date that the employee was hired.
  121        * @return The date the employee was hired.
  122        */
  123       public Date getHiredate() {
  124           return hiredate;
  125       }
  126   
  127       /**
  128        * Set the date that the employee was hired.
  129        * @param hiredate The date the employee was hired.
  130        */
  131       public void setHiredate(Date hiredate) {
  132           this.hiredate = hiredate;
  133       }
  134   
  135       /**
  136        * Get the weekly hours of the employee.
  137        * @return The number of hours per week that the employee works.
  138        */
  139       public double getWeeklyhours() {
  140           return weeklyhours;
  141       }
  142   
  143       /**
  144        * Set the number of hours per week that the employee works.
  145        * @param weeklyhours The number of hours per week that the employee
  146        * works. 
  147        */
  148       public void setWeeklyhours(double weeklyhours) {
  149           this.weeklyhours = weeklyhours;
  150       }
  151   
  152       /**
  153        * Get the reviewed projects.
  154        * @return The reviewed projects as an unmodifiable set.
  155        */
  156       public Set getReviewedProjects() {
  157           return Collections.unmodifiableSet(reviewedProjects);
  158       }
  159   
  160       /**
  161        * Add a reviewed project.
  162        * @param project A reviewed project.
  163        */
  164       public void addReviewedProjects(JPAAppProject project) {
  165           reviewedProjects.add(project);
  166       }
  167   
  168       /**
  169        * Remove a reviewed project.
  170        * @param project A reviewed project.
  171        */
  172       public void removeReviewedProject(JPAAppProject project) {
  173           reviewedProjects.remove(project);
  174       }
  175   
  176       /**
  177        * Set the reviewed projects for the employee.
  178        * @param reviewedProjects The set of reviewed projects.
  179        */
  180       public void setReviewedProjects(Set reviewedProjects) {
  181           // workaround: create a new HashSet, because fostore does not
  182           // support LinkedHashSet
  183           this.reviewedProjects = 
  184               (reviewedProjects != null) ? new HashSet(reviewedProjects) : null;
  185       }
  186   
  187       /**
  188        * Get the employee's projects.
  189        * @return The employee's projects are returned as an unmodifiable
  190        * set. 
  191        */
  192       public Set getProjects() {
  193           return Collections.unmodifiableSet(projects);
  194       }
  195   
  196       /**
  197        * Add a project for the employee.
  198        * @param project The project.
  199        */
  200       public void addProject(JPAAppProject project) {
  201           projects.add(project);
  202       }
  203   
  204       /**
  205        * Remove a project from an employee's set of projects.
  206        * @param project The project.
  207        */
  208       public void removeProject(JPAAppProject project) {
  209           projects.remove(project);
  210       }
  211   
  212       /**
  213        * Set the projects for the employee.
  214        * @param projects The set of projects of the employee.
  215        */
  216       public void setProjects(Set projects) {
  217           // workaround: create a new HashSet, because fostore does not
  218           // support LinkedHashSet
  219           this.projects = (projects != null) ? new HashSet(projects) : null;
  220       }
  221       
  222       /**
  223        * Get the dental insurance of the employee.
  224        * @return The employee's dental insurance.
  225        */
  226       public IDentalInsurance getDentalInsurance() {
  227           return dentalInsurance;
  228       }
  229   
  230       /**
  231        * Set the dental insurance object for the employee.
  232        * @param dentalInsurance The dental insurance object to associate with
  233        * the employee. 
  234        */
  235       public void setDentalInsurance(IDentalInsurance dentalInsurance) {
  236           this.dentalInsurance = (JPAAppDentalInsurance)dentalInsurance;
  237       }
  238       /**
  239        * Get the medical insurance of the employee.
  240        * @return The employee's medical insurance.
  241        */
  242       public IMedicalInsurance getMedicalInsurance() {
  243           return medicalInsurance;
  244       }
  245   
  246       /**
  247        * Set the medical insurance object for the employee.
  248        * @param medicalInsurance The medical insurance object to associate
  249        * with the employee. 
  250        */
  251       public void setMedicalInsurance(IMedicalInsurance medicalInsurance) {
  252           this.medicalInsurance = (JPAAppMedicalInsurance)medicalInsurance;
  253       }
  254   
  255       /**
  256        * Get the employee's department.
  257        * @return The department associated with the employee.
  258        */
  259       public IDepartment getDepartment() {
  260           return department;
  261       }
  262   
  263       /**
  264        * Set the employee's department.
  265        * @param department The department.
  266        */
  267       public void setDepartment(IDepartment department) {
  268           this.department = (JPAAppDepartment)department;
  269       }
  270   
  271       /**
  272        * Get the employee's funding department.
  273        * @return The funding department associated with the employee.
  274        */
  275       public IDepartment getFundingDept() {
  276           return fundingDept;
  277       }
  278   
  279       /**
  280        * Set the employee's funding department.
  281        * @param department The funding department.
  282        */
  283       public void setFundingDept(IDepartment department) {
  284           this.fundingDept = (JPAAppDepartment)department;
  285       }
  286   
  287       /**
  288        * Get the employee's manager.
  289        * @return The employee's manager.
  290        */
  291       public IEmployee getManager() {
  292           return manager;
  293       }
  294   
  295       /**
  296        * Set the employee's manager.
  297        * @param manager The employee's manager.
  298        */
  299       public void setManager(IEmployee manager) {
  300           this.manager = (JPAAppEmployee)manager;
  301       }
  302   
  303       /**
  304        * Get the employee's team.
  305        * 
  306        * 
  307        * @return The set of <code>JPAAppEmployee</code>s on this employee's team,
  308        * returned as an unmodifiable set.
  309        */
  310       public Set getTeam() {
  311           return Collections.unmodifiableSet(team);
  312       }
  313   
  314       /**
  315        * Add an <code>JPAAppEmployee</code> to this employee's team.
  316        * This method sets both sides of the relationship, modifying
  317        * this employees team to include parameter emp and modifying
  318        * emp to set its manager attribute to this object.
  319        * 
  320        * 
  321        * @param emp The <code>JPAAppEmployee</code> to add to the team.
  322        */
  323       public void addToTeam(JPAAppEmployee emp) {
  324           team.add(emp);
  325           emp.manager = this;
  326       }
  327   
  328       /**
  329        * Remove an <code>JPAAppEmployee</code> from this employee's team.
  330        * This method will also set the <code>emp</code> manager to null.
  331        * 
  332        * 
  333        * @param emp The <code>JPAAppEmployee</code> to remove from the team.
  334        */
  335       public void removeFromTeam(JPAAppEmployee emp) {
  336           team.remove(emp);
  337           emp.manager = null;
  338       }
  339   
  340       /**
  341        * Set the employee's team.
  342        * 
  343        * 
  344        * @param team The set of <code>JPAAppEmployee</code>s.
  345        */
  346       public void setTeam(Set team) {
  347           // workaround: create a new HashSet, because fostore does not
  348           // support LinkedHashSet
  349           this.team = (team != null) ? new HashSet(team) : null;
  350       }
  351   
  352       /**
  353        * Set the mentor for this employee. 
  354        * @param mentor The mentor for this employee.
  355        */
  356       public void setMentor(IEmployee mentor) {
  357           this.mentor = (JPAAppEmployee)mentor;
  358       }
  359   
  360       /**
  361        * Get the mentor for this employee.
  362        * @return The mentor.
  363        */
  364       public IEmployee getMentor() {
  365           return mentor;
  366       }
  367   
  368       /**
  369        * Set the protege for this employee.
  370        * @param protege The protege for this employee.
  371        */
  372       public void setProtege(IEmployee protege) {
  373           this.protege = (JPAAppEmployee)protege;
  374       }
  375   
  376       /**
  377        * Get the protege of this employee.
  378        * @return The protege of this employee.
  379        */
  380       public IEmployee getProtege() {
  381           return protege;
  382       }
  383   
  384       /**
  385        * Set the HR advisor for this employee.
  386        * @param hradvisor The hradvisor for this employee.
  387        */
  388       public void setHradvisor(IEmployee hradvisor) {
  389           this.hradvisor = (JPAAppEmployee)hradvisor;
  390       }
  391   
  392       /**
  393        * Get the HR advisor for the employee.
  394        * @return The HR advisor.
  395        */
  396       public IEmployee getHradvisor() {
  397           return hradvisor;
  398       }
  399   
  400       /**
  401        * Get the HR advisees of this HR advisor.
  402        * 
  403        * 
  404        * @return An unmodifiable <code>Set</code> containing the
  405        * <code>JPAAppEmployee</code>s that are HR advisees of this employee.
  406        */
  407       public Set getHradvisees() {
  408           return Collections.unmodifiableSet(hradvisees);
  409       }
  410   
  411       /**
  412        * Add an <code>JPAAppEmployee</code> as an advisee of this HR advisor. 
  413        * This method also sets the <code>emp</code> hradvisor to reference
  414        * this object. In other words, both sides of the relationship are
  415        * set. 
  416        * 
  417        * 
  418        * @param emp The employee to add as an advisee.
  419        */
  420       public void addAdvisee(JPAAppEmployee emp) {
  421           hradvisees.add(emp);
  422           emp.hradvisor = this;
  423       }
  424   
  425       /**
  426        * Remove an <code>JPAAppEmployee</code> as an advisee of this HR advisor.
  427        * This method also sets the <code>emp</code> hradvisor to null.
  428        * In other words, both sides of the relationship are set.
  429        * 
  430        * 
  431        * @param emp The employee to add as an HR advisee.
  432        */
  433       public void removeAdvisee(JPAAppEmployee emp) {
  434           hradvisees.remove(emp);
  435           emp.hradvisor = null;
  436       }
  437   
  438       /**
  439        * Set the HR advisees of this HR advisor.
  440        * 
  441        * 
  442        * @param hradvisees The <code>JPAAppEmployee</code>s that are HR advisees of
  443        * this employee.
  444        */
  445       public void setHradvisees(Set hradvisees) {
  446           // workaround: create a new HashSet, because fostore does not
  447           // support LinkedHashSet
  448           this.hradvisees = (hradvisees != null) ? new HashSet(hradvisees) : null;
  449       }
  450   
  451       /** Serialization support: initialize transient fields. */
  452       private void readObject(ObjectInputStream in)
  453           throws IOException, ClassNotFoundException {
  454           in.defaultReadObject();
  455           reviewedProjects = new HashSet();
  456           projects = new HashSet();
  457           team = new HashSet();
  458           hradvisees = new HashSet();
  459       }
  460   
  461       /**
  462        * Return a String representation of a <code>JPAAppEmployee</code> object.
  463        * 
  464        * 
  465        * @return a String representation of a <code>JPAAppEmployee</code> object.
  466        */
  467       public String toString() {
  468           return "JPAAPPEmployee(" + getFieldRepr() + ")";
  469       }
  470   
  471       /**
  472        * Returns a String representation of the non-relationship fields.
  473        * @return a String representation of the non-relationship fields.
  474        */
  475       protected String getFieldRepr() {
  476           StringBuffer rc = new StringBuffer();
  477           rc.append(super.getFieldRepr());
  478           rc.append(", hired ").append(formatter.format(hiredate));
  479           rc.append(", weeklyhours ").append(weeklyhours);
  480           return rc.toString();
  481       }
  482   
  483       /**
  484        * 
  485        * Returns <code>true</code> if all the fields of this instance are
  486        * deep equal to the corresponding fields of the specified JPAAppEmployee.
  487        * 
  488        * 
  489        * @param other the object with which to compare.
  490        * @param helper EqualityHelper to keep track of instances that have
  491        * already been processed.
  492        * @return <code>true</code> if all the fields are deep equal;
  493        * <code>false</code> otherwise.
  494        * @throws ClassCastException if the specified instances' type prevents
  495        * it from being compared to this instance.
  496        */
  497       public boolean deepCompareFields(Object other, 
  498                                        EqualityHelper helper) {
  499           JPAAppEmployee otherEmp = (JPAAppEmployee)other;
  500           String where = "Employee<" + getPersonid() + ">";
  501           return super.deepCompareFields(otherEmp, helper) &
  502               helper.equals(hiredate, otherEmp.getHiredate(),  where + ".hiredate") &
  503               helper.closeEnough(weeklyhours, otherEmp.getWeeklyhours(), where + ".weeklyhours") &
  504               helper.deepEquals(dentalInsurance, otherEmp.getDentalInsurance(), where + ".dentalInsurance") &
  505               helper.deepEquals(medicalInsurance, otherEmp.getMedicalInsurance(), where + ".medicalInsurance") &
  506               helper.deepEquals(department, otherEmp.getDepartment(), where + ".department") &
  507               helper.deepEquals(fundingDept, otherEmp.getFundingDept(), where + ".fundingDept") &
  508               helper.deepEquals(manager, otherEmp.getManager(), where + ".manager") &
  509               helper.deepEquals(mentor, otherEmp.getMentor(), where + ".mentor") &
  510               helper.deepEquals(protege, otherEmp.getProtege(), where + ".protege") &
  511               helper.deepEquals(hradvisor, otherEmp.getHradvisor(), where + ".hradvisor") &
  512               helper.deepEquals(reviewedProjects, otherEmp.getReviewedProjects(), where + ".reviewedProjects") &
  513               helper.deepEquals(projects, otherEmp.getProjects(), where + ".projects") &
  514               helper.deepEquals(team, otherEmp.getTeam(), where + ".team") &
  515               helper.deepEquals(hradvisees, otherEmp.getHradvisees(), where + ".hradvisees");
  516       }
  517   
  518   }
  519   

Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.pc.companyAnnotatedJPA » [javadoc | source]