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.Serializable;
   23   
   24   import java.util.Comparator;
   25   import org.apache.jdo.tck.pc.company.IEmployee;
   26   
   27   import org.apache.jdo.tck.pc.company.IInsurance;
   28   import org.apache.jdo.tck.util.DeepEquality;
   29   import org.apache.jdo.tck.util.EqualityHelper;
   30   
   31   /**
   32    * This class represents an insurance carrier selection for a particular
   33    * <code>JPAAppEmployee</code>.
   34    */
   35   @Entity
   36   @Table(name="insuranceplans")
   37   @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
   38   @DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING,
   39           name="DISCRIMINATOR")
   40   public class JPAAppInsurance 
   41       implements IInsurance, Serializable, Comparable, Comparator, DeepEquality  {
   42   
   43       @Id
   44       @Column(name="INSID")
   45       private long     insid;
   46       @Column(name="CARRIER")
   47       private String   carrier;
   48       @Column(name="EMPLOYEE")
   49       private JPAAppEmployee employee;
   50   
   51       /** This is the JDO-required no-args constructor. */
   52       protected JPAAppInsurance() {}
   53   
   54       /**
   55        * Construct an <code>JPAAppInsurance</code> instance.
   56        * 
   57        * 
   58        * @param insid The insurance instance identifier.
   59        * @param carrier The insurance carrier.
   60        */
   61       protected JPAAppInsurance(long insid, String carrier) {
   62           this.insid = insid;
   63           this.carrier = carrier;
   64       }
   65   
   66       /**
   67        * Construct an <code>JPAAppInsurance</code> instance.
   68        * 
   69        * 
   70        * @param insid The insurance instance identifier.
   71        * @param carrier The insurance carrier.
   72        * @param employee The employee associated with this insurance.
   73        */
   74       protected JPAAppInsurance(long insid, String carrier, IEmployee employee) {
   75           this.insid = insid;
   76           this.carrier = carrier;
   77           this.employee = (JPAAppEmployee)employee;
   78       }
   79   
   80       /**
   81        * Get the insurance ID.
   82        * @return the insurance ID.
   83        */
   84       public long getInsid() {
   85           return insid;
   86       }
   87   
   88       /**
   89        * Set the insurance ID.
   90        * @param id The insurance ID value.
   91        */
   92       public void setInsid(long id) {
   93           if (this.insid != 0) 
   94               throw new IllegalStateException("Id is already set.");
   95           this.insid = id;
   96       }
   97   
   98       /**
   99        * Get the insurance carrier.
  100        * @return The insurance carrier.
  101        */
  102       public String getCarrier() {
  103           return carrier;
  104       }
  105   
  106       /**
  107        * Set the insurance carrier.
  108        * @param carrier The insurance carrier.
  109        */
  110       public void setCarrier(String carrier) {
  111           this.carrier = carrier;
  112       }
  113       
  114       /**
  115        * Get the associated employee.
  116        * @return The employee for this insurance.
  117        */
  118       public IEmployee getEmployee() {
  119           return employee;
  120       }
  121   
  122       /**
  123        * Set the associated employee.
  124        * @param employee The associated employee.
  125        */
  126       public void setEmployee(IEmployee employee) {
  127           this.employee = (JPAAppEmployee)employee;
  128       }
  129   
  130       /**
  131        * Returns a String representation of a <code>JPAAppInsurance</code> object.
  132        * 
  133        * 
  134        * @return a String representation of a <code>JPAAppInsurance</code> object.
  135        */
  136       public String toString() {
  137           return "JPAAppInsurance(" + getFieldRepr() + ")";
  138       }
  139   
  140       /**
  141        * Returns a String representation of the non-relationship fields.
  142        * @return a String representation of the non-relationship fields.
  143        */
  144       protected String getFieldRepr() {
  145           StringBuffer rc = new StringBuffer();
  146           rc.append(insid);
  147           rc.append(", carrier ").append(carrier);
  148           return rc.toString();
  149       }
  150   
  151       /** 
  152        * Returns <code>true</code> if all the fields of this instance are
  153        * deep equal to the coresponding fields of the other Object.
  154        * @param other the object with which to compare.
  155        * @param helper EqualityHelper to keep track of instances that have
  156        * already been processed. 
  157        * @return <code>true</code> if all the fields are deep equal;
  158        * <code>false</code> otherwise.  
  159        * @throws ClassCastException if the specified instances' type prevents
  160        * it from being compared to this instance. 
  161        */
  162       public boolean deepCompareFields(Object other, 
  163                                        EqualityHelper helper) {
  164           JPAAppInsurance otherIns = (JPAAppInsurance)other;
  165           String where = "JPAAppInsurance<" + insid + ">";
  166           return
  167               helper.equals(insid, otherIns.getInsid(), where + ".insid") &
  168               helper.equals(carrier, otherIns.getCarrier(), where + ".carrier") &
  169               helper.deepEquals(employee, otherIns.getEmployee(), where + ".employee");
  170       }
  171       
  172       /** 
  173        * Compares this object with the specified object for order. Returns a
  174        * negative integer, zero, or a positive integer as this object is less
  175        * than, equal to, or greater than the specified object. 
  176        * @param o The Object to be compared. 
  177        * @return a negative integer, zero, or a positive integer as this 
  178        * object is less than, equal to, or greater than the specified object. 
  179        * @throws ClassCastException - if the specified object's type prevents
  180        * it from being compared to this Object. 
  181        */
  182       public int compareTo(Object o) {
  183           return compareTo((JPAAppInsurance)o);
  184       }
  185   
  186       /** 
  187        * Compare two instances. This is a method in Comparator.
  188        */
  189       public int compare(Object o1, Object o2) {
  190           return compare((JPAAppInsurance)o1, (JPAAppInsurance)o2);
  191       }
  192   
  193       /** 
  194        * Compares this object with the specified Insurance object for
  195        * order. Returns a negative integer, zero, or a positive integer as
  196        * this object is less than, equal to, or greater than the specified
  197        * object.  
  198        * @param other The Insurance object to be compared. 
  199        * @return a negative integer, zero, or a positive integer as this
  200        * object is less than, equal to, or greater than the specified
  201        * Insurance object. 
  202        */
  203       public int compareTo(JPAAppInsurance other) {
  204           return compare(this, other);
  205       }
  206   
  207       /**
  208        * Compares its two IInsurance arguments for order. Returns a negative
  209        * integer, zero, or a positive integer as the first argument is less
  210        * than, equal to, or greater than the second. 
  211        * @param o1 the first IInsurance object to be compared. 
  212        * @param o2 the second IInsurance object to be compared. 
  213        * @return a negative integer, zero, or a positive integer as the first
  214        * object is less than, equal to, or greater than the second object. 
  215        */
  216       public static int compare(JPAAppInsurance o1, JPAAppInsurance o2) {
  217           return EqualityHelper.compare(o1.getInsid(), o2.getInsid());
  218       }
  219       
  220       /** 
  221        * Indicates whether some other object is "equal to" this one.
  222        * @param obj the object with which to compare.
  223        * @return <code>true</code> if this object is the same as the obj
  224        * argument; <code>false</code> otherwise. 
  225        */
  226       public boolean equals(Object obj) {
  227           if (obj instanceof JPAAppInsurance) {
  228               return compareTo((JPAAppInsurance)obj) == 0;
  229           }
  230           return false;
  231       }
  232           
  233       /**
  234        * Returns a hash code value for the object. 
  235        * @return a hash code value for this object.
  236        */
  237       public int hashCode() {
  238           return (int)insid;
  239       }
  240   
  241       /**
  242        * This class is used to represent the application
  243        * identifier for the <code>Insurance</code> class.
  244        */
  245       public static class Oid implements Serializable, Comparable 
  246       {
  247           /**
  248            * This field represents the application identifier for the
  249            * <code>Insurance</code> class. It must match the field in the
  250            * <code>Insurance</code> class in both name and type. 
  251            */
  252           public long insid;
  253           
  254           /**
  255            * The required public no-args constructor.
  256            */
  257           public Oid() { }
  258   
  259           /**
  260            * Initialize with an insurance identifier.
  261            * @param insid the insurance ID.
  262            */
  263           public Oid(long insid) {
  264               this.insid = insid;
  265           }
  266           
  267           public Oid(String s) { insid = Long.parseLong(justTheId(s)); }
  268   
  269           public String toString() { return this.getClass().getName() + ": "  + insid;}
  270   
  271   
  272           /** */
  273           public boolean equals(java.lang.Object obj) {
  274               if( obj==null || !this.getClass().equals(obj.getClass()) )
  275                   return( false );
  276               Oid o=(Oid) obj;
  277               if( this.insid!=o.insid ) return( false );
  278               return( true );
  279           }
  280   
  281           /** */
  282           public int hashCode() {
  283               return( (int) insid );
  284           }
  285           
  286           protected static String justTheId(String str) {
  287               return str.substring(str.indexOf(':') + 1);
  288           }
  289   
  290           /** */
  291           public int compareTo(Object obj) {
  292               // may throw ClassCastException which the user must handle
  293               Oid other = (Oid) obj;
  294               if( insid < other.insid ) return -1;
  295               if( insid > other.insid ) return 1;
  296               return 0;
  297           }
  298   
  299       }
  300   
  301   }
  302   

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