Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.pc.mylib » [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.mylib;
   19   
   20   import java.io.Serializable;
   21   
   22   import javax.jdo.listener.LoadCallback;
   23   
   24   public class PCClass implements LoadCallback {
   25   
   26       private long id;
   27       private int number1;
   28       private int number2;
   29       
   30       private int transientNumber1;
   31       private int transientNumber2;
   32   
   33       public PCClass() {
   34       }
   35   
   36       /**
   37        * @see LoadCallback#jdoPostLoad()
   38        */
   39       public void jdoPostLoad() {
   40           transientNumber1 = number1;
   41           transientNumber2 = number2;
   42       }
   43   
   44       /**
   45        * @see Object#toString()
   46        */
   47       public String toString() { 
   48           return "PCClass(" + id + ")";
   49       }
   50   
   51       /**
   52        * @see Object#hashCode()
   53        */
   54       public int hashCode() { return (int)id ; }
   55   
   56       /**
   57        * @see Object#equals(java.lang.Object)
   58        */
   59       public boolean equals(Object other) {
   60           if (other != null && (other instanceof PCClass)) {
   61               PCClass k = (PCClass)other;
   62               return k.id == this.id;
   63           }
   64           return false;
   65       }
   66       
   67       /**
   68        * @return Returns the id.
   69        */
   70       public long getId() {
   71           return id;
   72       }
   73   
   74       /**
   75        * @param id The id to set.
   76        */
   77       public void setId(long id) {
   78           this.id = id;
   79       }
   80   
   81       /**
   82        * @return Returns the number.
   83        */
   84       public int getNumber1() {
   85           return number1;
   86       }
   87   
   88       /**
   89        * @param number The number to set.
   90        */
   91       public void setNumber1(int number) {
   92           this.number1 = number;
   93       }
   94   
   95       /**
   96        * @return Returns the number2.
   97        */
   98       public int getNumber2() {
   99           return number2;
  100       }
  101   
  102       /**
  103        * @param number2 The number2 to set.
  104        */
  105       public void setNumber2(int number2) {
  106           this.number2 = number2;
  107       }
  108   
  109       /**
  110        * @return Returns the transientNumber1.
  111        */
  112       public int getTransientNumber1() {
  113           return transientNumber1;
  114       }
  115   
  116       /**
  117        * @param transientNumber1 The transientNumber1 to set.
  118        */
  119       public void setTransientNumber1(int transientNumber1) {
  120           this.transientNumber1 = transientNumber1;
  121       }
  122   
  123       /**
  124        * @return Returns the transientNumber2.
  125        */
  126       public int getTransientNumber2() {
  127           return transientNumber2;
  128       }
  129   
  130       /**
  131        * @param transientNumber2 The transientNumber2 to set.
  132        */
  133       public void setTransientNumber2(int transientNumber2) {
  134           this.transientNumber2 = transientNumber2;
  135       }
  136   
  137       /**
  138        * The objectid class for this class in case of application identity. 
  139        */
  140       public static class Oid implements Serializable, Comparable {
  141   
  142           public long id;
  143   
  144           public Oid() {
  145           }
  146   
  147           public Oid(String s) { id = Long.parseLong(justTheId(s)); }
  148   
  149           public String toString() { return this.getClass().getName() + ": "  + id;}
  150   
  151           public int hashCode() { return (int)id ; }
  152   
  153           public boolean equals(Object other) {
  154               if (other != null && (other instanceof Oid)) {
  155                   Oid k = (Oid)other;
  156                   return k.id == this.id;
  157               }
  158               return false;
  159           }
  160           
  161           protected static String justTheId(String str) {
  162               return str.substring(str.indexOf(':') + 1);
  163           }
  164   
  165           public int compareTo(Object o) {
  166               if (o == null)
  167                   throw new ClassCastException();
  168               if (o == this)
  169                   return 0;
  170               long otherId = ((Oid)o).id;
  171               if (id == otherId)
  172                   return 0;
  173               else if (id < otherId)
  174                   return -1;
  175               return 1;
  176           }
  177       }
  178   }
  179   

Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.pc.mylib » [javadoc | source]