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.util.Date;
   23   import org.apache.jdo.tck.pc.company.IAddress;
   24   
   25   import org.apache.jdo.tck.pc.company.IFullTimeEmployee;
   26   import org.apache.jdo.tck.util.EqualityHelper;
   27   
   28   /**
   29    * This class represents a full-time employee.
   30    */
   31   @Entity
   32   public class JPAAppFullTimeEmployee extends JPAAppEmployee
   33           implements IFullTimeEmployee {
   34   
   35       @Column(name="SALARY")
   36       private double salary;
   37   
   38       /** This is the JDO-required no-args constructor. The TCK relies on
   39        * this constructor for testing PersistenceManager.newInstance(PCClass).
   40        */
   41       public JPAAppFullTimeEmployee() {}
   42   
   43       /**
   44        * Construct a full-time employee.
   45        * @param personid The person identifier.
   46        * @param first The person's first name.
   47        * @param last The person's last name.
   48        * @param middle The person's middle name.
   49        * @param born The person's birthdate.
   50        * @param hired The date that the person was hired.
   51        * @param sal The salary of the full-time employee.
   52        */
   53       public JPAAppFullTimeEmployee(long personid, String first, String last,
   54                               String middle, Date born,
   55                               Date hired, double sal) {
   56           super(personid, first, last, middle, born, hired);
   57           salary = sal;
   58       }
   59   
   60       /**
   61        * Construct a full-time employee.
   62        * @param personid The person identifier.
   63        * @param first The person's first name.
   64        * @param last The person's last name.
   65        * @param middle The person's middle name.
   66        * @param born The person's birthdate.
   67        * @param addr The person's address.
   68        * @param hired The date that the person was hired.
   69        * @param sal The salary of the full-time employee.
   70        */
   71       public JPAAppFullTimeEmployee(long personid, String first, String last,
   72                               String middle, Date born, IAddress addr, 
   73                               Date hired, double sal) {
   74           super(personid, first, last, middle, born, (JPAAppAddress)addr, hired);
   75           salary = sal;
   76       }
   77   
   78       /**
   79        * Get the salary of the full time employee.
   80        * @return The salary of the full time employee.
   81        */
   82       public double getSalary() {
   83           return salary;
   84       }
   85       
   86       /**
   87        * Set the salary for the full-time employee.
   88        * @param salary The salary to set for the full-time employee.
   89        */
   90       public void setSalary(double salary) {
   91           this.salary = salary;
   92       }
   93       
   94       /**
   95        * Return a String representation of a <code>JPAAppFullTimeEmployee</code> object.
   96        * 
   97        * 
   98        * @return a String representation of a <code>JPAAppFullTimeEmployee</code> object.
   99        */
  100       public String toString() {
  101           return "JPAAppFullTimeEmployee(" + getFieldRepr() + ")";
  102       }
  103   
  104       /**
  105        * Returns a String representation of the non-relationship fields.
  106        * @return a String representation of the non-relationship fields.
  107        */
  108       public String getFieldRepr() {
  109           StringBuffer rc = new StringBuffer();
  110           rc.append(super.getFieldRepr());
  111           rc.append(", $").append(salary);
  112           return rc.toString();
  113       }
  114   
  115       /**
  116        * 
  117        * Returns <code>true</code> if all the fields of this instance are
  118        * deep equal to the coresponding fields of the specified
  119        * JPAAppFullTimeEmployee. 
  120        * 
  121        * 
  122        * @param other the object with which to compare.
  123        * @param helper EqualityHelper to keep track of instances that have
  124        * already been processed.
  125        * @return <code>true</code> if all the fields are deep equal;
  126        * <code>false</code> otherwise.
  127        * @throws ClassCastException if the specified instances' type prevents
  128        * it from being compared to this instance.
  129        */
  130       public boolean deepCompareFields(Object other, 
  131                                        EqualityHelper helper) {
  132           JPAAppFullTimeEmployee otherEmp = (JPAAppFullTimeEmployee)other;
  133           String where = "JPAAppFullTimeEmployee<" + getPersonid() + ">";
  134           return super.deepCompareFields(otherEmp, helper) &
  135               helper.closeEnough(salary, otherEmp.getSalary(), where + ".salary");
  136       }
  137       
  138   }

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