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   
   19   package org.apache.jdo.tck.pc.companyAnnotatedJPA;
   20   
   21   import javax.persistence;
   22   
   23   import java.io.Serializable;
   24   
   25   /**
   26    * This class represents a person.
   27    */
   28   @Entity
   29   @IdClass(org.apache.jdo.tck.pc.companyAnnotatedJPA.JPAAppPhoneNumber.Oid.class)
   30   @Table(name="employee_phoneno_type")
   31   @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
   32   //@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING,
   33   //        name="DISCRIMINATOR")
   34   public class JPAAppPhoneNumber implements Serializable {
   35   
   36       @Id
   37       @ManyToOne
   38       @Column(name="EMPID")
   39       private JPAAppPerson person;
   40       @Id
   41       @Column(name="TYPE")
   42       private String  type;
   43       @Column(name="PHONENO")
   44       private String  phoneNumber;
   45       
   46       /** This is the JDO-required no-args constructor. */
   47       protected JPAAppPhoneNumber() {}
   48   
   49       /**
   50        * Construct a <code>JPAAppPhoneNumber</code> instance.
   51        * 
   52        * @param person The person instance
   53        * @param type The type of the phone for this number
   54        * @param phoneNumber The phone number
   55        */
   56       public JPAAppPhoneNumber(JPAAppPerson person, String type,
   57               String phoneNumber) {
   58           this.person = person;
   59           this.type = type;
   60           this.phoneNumber = phoneNumber;
   61       }
   62   
   63       /**
   64        * Set the id associated with this object.
   65        * @param id the id.
   66        */
   67       public void setPerson(JPAAppPerson id) {
   68           if (this.person != null)
   69               throw new IllegalStateException("Id is already set.");
   70           this.person = id;
   71       }
   72   
   73       /**
   74        * Get the person's id.
   75        * @return The person.
   76        */
   77       public JPAAppPerson getPerson() {
   78           return person;
   79       }
   80   
   81       /**
   82        * Get the person's last name.
   83        * @return The last name.
   84        */
   85   
   86       public String getType() {
   87           return type;
   88       }
   89   
   90       /**
   91        * Set the phone number type
   92        * @param type The phone number type
   93        */
   94       public void setType(String type) {
   95           this.type = type;
   96       }
   97   
   98       /**
   99        * Get the phone number.
  100        * @return The phone number.
  101        */
  102       public String getPhoneNumber() {
  103           return phoneNumber;
  104       }
  105   
  106       /**
  107        * Set the phone number.
  108        * @param phoneNumber The phone number.
  109        */
  110       public void setPhoneNumber(String phoneNumber) {
  111           this.phoneNumber = phoneNumber;
  112       }
  113   
  114       /**
  115        * Returns a String representation of a <code>JPAAppPhoneNumber</code> object.
  116        * 
  117        * @return a string representation of a <code>JPAAppPhoneNumber</code> object.
  118        */
  119       public String toString() {
  120           return "JPAAppPhoneNumber(" + getFieldRepr() + ")";
  121       }
  122       
  123       /**
  124        * Returns a String representation of the non-relationship fields.
  125        * @return a String representation of the non-relationship fields.
  126        */
  127       protected String getFieldRepr() {
  128           StringBuffer rc = new StringBuffer();
  129           rc.append(person.getPersonid());
  130           rc.append(", ").append(type);
  131           rc.append(", phone ").append(phoneNumber);
  132           return rc.toString();
  133       }
  134   
  135       /**
  136        * This class is used to represent the application identifier
  137        * for the <code>Person</code> class.
  138        */
  139       public static class Oid implements Serializable, Comparable {
  140   
  141           /**
  142            * This field represents the identifier for the <code>Person</code>
  143            * class. It must match a field in the <code>Person</code> class in
  144            * both name and type. 
  145            */
  146           public JPAAppPerson.Oid person;
  147   
  148           public String type;
  149   
  150           /**
  151            * The required public no-arg constructor.
  152            */
  153           public Oid() { }
  154   
  155           /**
  156            * Initialize the identifier.
  157            * @param person The person identifier.
  158            */
  159           public Oid(JPAAppPerson.Oid person, String type) {
  160               this.person = person;
  161               this.type = type;
  162           }
  163           
  164           public Oid(String s) {
  165               person = new JPAAppPerson.Oid(justTheOid(s));
  166               type = justTheType(s);
  167           }
  168   
  169           public String toString() {
  170               return this.getClass().getName() + ": "  + person + " + " + type;
  171           }
  172   
  173           /** */
  174           public boolean equals(java.lang.Object obj) {
  175               if( obj==null ||
  176                   !this.getClass().equals(obj.getClass()) ) return( false );
  177               Oid o = (Oid) obj;
  178               if( !this.person.equals(o.person) ) return( false );
  179               if( !this.type.equals(o.type) ) return( false );
  180               return( true );
  181           }
  182   
  183           /** */
  184           public int hashCode() {
  185               return( (int) person.hashCode() + type.hashCode() );
  186           }
  187           
  188           protected static String justTheOid(String str) {
  189               return str.substring(str.indexOf(':') + 1, str.indexOf('+') - 1);
  190           }
  191           
  192           protected static String justTheType(String str) {
  193               return str.substring(str.indexOf('+') + 1);
  194           }
  195   
  196           /** */
  197           public int compareTo(Object obj) {
  198               // may throw ClassCastException which the user must handle
  199               Oid other = (Oid) obj;
  200               int comparison = person.compareTo(other.person);
  201               if( comparison != 0 ) {
  202                   return comparison;
  203               } else { 
  204                   return type.compareTo(other.type);
  205               }
  206           }
  207   
  208       }
  209   
  210   }

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