Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencecapable » [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.api.persistencecapable;
   19   
   20   import javax.jdo.identity.ByteIdentity;
   21   import javax.jdo.identity.CharIdentity;
   22   import javax.jdo.identity.IntIdentity;
   23   import javax.jdo.identity.LongIdentity;
   24   import javax.jdo.identity.ObjectIdentity;
   25   import javax.jdo.identity.ShortIdentity;
   26   import javax.jdo.identity.SingleFieldIdentity;
   27   import javax.jdo.identity.StringIdentity;
   28   import javax.jdo.spi.PersistenceCapable;
   29   
   30   import org.apache.jdo.tck.pc.singlefieldidentity.AbstractPCPointSingleField;
   31   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldByte;
   32   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldCharacter;
   33   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldDate;
   34   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldInteger;
   35   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldLong;
   36   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitivebyte;
   37   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitivechar;
   38   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitiveint;
   39   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitivelong;
   40   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitiveshort;
   41   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldShort;
   42   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldString;
   43   import org.apache.jdo.tck.util.BatchTestRunner;
   44   
   45   /**
   46    *<B>Title:</B>CopyKeyFieldsFromObjectId of PersistenceCapable
   47    *<BR>
   48    *<B>Keywords:</B> persistencecapable
   49    *<BR>
   50    *<B>Assertion IDs:</B> A7.12-25
   51    *<BR>
   52    *<B>Assertion Description: </B>
   53    *<p>
   54    * A7.12-25<br>
   55    * public void jdoCopyKeyFieldsFromObjectId(ObjectIdFieldConsumer fc, Object oid);
   56    * This method copies fields to the field manager instance 
   57    * from the second parameter instance.
   58    * 
   59    * @author Michael Watzek
   60    */
   61   public class CopyKeyFieldsFromObjectId  extends AbstractPersistenceCapableTest {
   62   
   63       /** */
   64       private static final String ASSERTION_FAILED = 
   65           "Assertion A7.12-25 (jdoCopyKeyFieldsFromObjectId) failed: ";
   66   
   67       /**
   68        * The <code>main</code> is called when the class
   69        * is directly executed from the command line.
   70        * @param args The arguments passed to the program.
   71        */
   72       public static void main(String[] args) {
   73           BatchTestRunner.run(CopyKeyFieldsFromObjectId .class);
   74       }
   75   
   76       public void testSingleFieldIdentitybyte() {
   77           if (isTestToBePerformed()) {
   78               singleFieldIdentity(new PCPointSingleFieldPrimitivebyte(1, 2));
   79           }
   80       }
   81       
   82       public void testSingleFieldIdentityByte() {
   83           if (isTestToBePerformed()) {
   84               singleFieldIdentity(new PCPointSingleFieldByte(1, 2));
   85           }
   86       }
   87       
   88       public void testSingleFieldIdentitychar() {
   89           if (isTestToBePerformed()) {
   90               singleFieldIdentity(new PCPointSingleFieldPrimitivechar(1, 2));
   91           }
   92       }
   93       
   94       public void testSingleFieldIdentityCharacter() {
   95           if (isTestToBePerformed()) {
   96               singleFieldIdentity(new PCPointSingleFieldCharacter(1, 2));
   97           }
   98       }
   99       
  100       public void testSingleFieldIdentityint() {
  101           if (isTestToBePerformed()) {
  102               singleFieldIdentity(new PCPointSingleFieldPrimitiveint(1, 2));
  103           }
  104       }
  105       
  106       public void testSingleFieldIdentityInteger() {
  107           if (isTestToBePerformed()) {
  108               singleFieldIdentity(new PCPointSingleFieldInteger(1, 2));
  109           }
  110       }
  111       
  112       public void testSingleFieldIdentitylong() {
  113           if (isTestToBePerformed()) {
  114               singleFieldIdentity(new PCPointSingleFieldPrimitivelong(1, 2));
  115           }
  116       }
  117       
  118       public void testSingleFieldIdentityLong() {
  119           if (isTestToBePerformed()) {
  120               singleFieldIdentity(new PCPointSingleFieldLong(1, 2));
  121           }
  122       }
  123       
  124       public void testSingleFieldIdentityshort() {
  125           if (isTestToBePerformed()) {
  126               singleFieldIdentity(new PCPointSingleFieldPrimitiveshort(1, 2));
  127           }
  128       }
  129       
  130       public void testSingleFieldIdentityShort() {
  131           if (isTestToBePerformed()) {
  132               singleFieldIdentity(new PCPointSingleFieldShort(1, 2));
  133           }
  134       }
  135       
  136       public void testSingleFieldIdentityString() {
  137           if (isTestToBePerformed()) {
  138               singleFieldIdentity(new PCPointSingleFieldString(1, 2));
  139           }
  140       }
  141       
  142       public void testSingleFieldIdentityDate() {
  143           if (isTestToBePerformed()) {
  144               singleFieldIdentity(new PCPointSingleFieldDate(1, 2));
  145           }
  146       }
  147       
  148       /**
  149        * The common method for test cases checking for assertion A7.12-25:<br>
  150        * public void jdoCopyKeyFieldsFromObjectId(ObjectIdFieldConsumer fc, Object oid);
  151        * This method copies fields to the field manager instance 
  152        * from the second parameter instance.
  153        * @param o the object to check
  154        */
  155       private void singleFieldIdentity(AbstractPCPointSingleField o) {
  156           assertPersistenceCapable(o);
  157           SingleFieldIdentity sfi = (SingleFieldIdentity) makePersistent(o);
  158           PersistenceCapable pc = (PersistenceCapable) o;
  159           ObjectIdFieldConsumer objectIdFieldConsumer = 
  160               new ObjectIdFieldConsumer();
  161           pc.jdoCopyKeyFieldsFromObjectId(objectIdFieldConsumer, sfi);
  162           if (!objectIdFieldConsumer.equals(sfi)) {
  163               fail(ASSERTION_FAILED + 
  164                       "pc.jdoCopyKeyFieldsFromObjectId copies unexpected " +
  165                       "fields into an object id field consumer using a " +
  166                       "single field indentity object id.");
  167           }
  168       }
  169   
  170       private static class ObjectIdFieldConsumer 
  171           implements PersistenceCapable.ObjectIdFieldConsumer {
  172           
  173           private boolean booleanField;
  174           private byte byteField;
  175           private char charField;
  176           private double doubleField;
  177           private float floatField;
  178           private int intField;
  179           private long longField;
  180           private short shortField;
  181           private String stringField;
  182           private Object objectField;
  183   
  184           /*
  185            * @see PersistenceCapable.ObjectIdFieldConsumer#storeBooleanField(int, boolean)
  186            */
  187           public void storeBooleanField(int fieldNumber, boolean value) {
  188               this.booleanField = value;
  189           }
  190   
  191           /*
  192            * @see PersistenceCapable.ObjectIdFieldConsumer#storeCharField(int, char)
  193            */
  194           public void storeCharField(int fieldNumber, char value) {
  195               this.charField = value;
  196           }
  197   
  198           /*
  199            * @see PersistenceCapable.ObjectIdFieldConsumer#storeByteField(int, byte)
  200            */
  201           public void storeByteField(int fieldNumber, byte value) {
  202               this.byteField = value;
  203           }
  204   
  205           /*
  206            * @see PersistenceCapable.ObjectIdFieldConsumer#storeShortField(int, short)
  207            */
  208           public void storeShortField(int fieldNumber, short value) {
  209               this.shortField = value;
  210           }
  211   
  212           /*
  213            * @see PersistenceCapable.ObjectIdFieldConsumer#storeIntField(int, int)
  214            */
  215           public void storeIntField(int fieldNumber, int value) {
  216               this.intField = value;
  217           }
  218   
  219           /*
  220            * @see PersistenceCapable.ObjectIdFieldConsumer#storeLongField(int, long)
  221            */
  222           public void storeLongField(int fieldNumber, long value) {
  223               this.longField = value;
  224           }
  225   
  226           /*
  227            * @see PersistenceCapable.ObjectIdFieldConsumer#storeFloatField(int, float)
  228            */
  229           public void storeFloatField(int fieldNumber, float value) {
  230               this.floatField = value;
  231           }
  232   
  233           /*
  234            * @see PersistenceCapable.ObjectIdFieldConsumer#storeDoubleField(int, double)
  235            */
  236           public void storeDoubleField(int fieldNumber, double value) {
  237               this.doubleField = value;
  238           }
  239   
  240           /*
  241            * @see PersistenceCapable.ObjectIdFieldConsumer#storeStringField(int, java.lang.String)
  242            */
  243           public void storeStringField(int fieldNumber, String value) {
  244               this.stringField = value;
  245           }
  246   
  247           /*
  248            * @see PersistenceCapable.ObjectIdFieldConsumer#storeObjectField(int, java.lang.Object)
  249            */
  250           public void storeObjectField(int fieldNumber, Object value) {
  251               if (value instanceof Boolean)
  252                   this.booleanField = ((Boolean)value).booleanValue();
  253               else if (value instanceof Boolean)
  254                   this.booleanField = ((Boolean)value).booleanValue();
  255               else if (value instanceof Byte)
  256                   this.byteField = ((Byte)value).byteValue();
  257               else if (value instanceof Character)
  258                   this.charField = ((Character)value).charValue();
  259               else if (value instanceof Double)
  260                   this.doubleField = ((Double)value).doubleValue();
  261               else if (value instanceof Float)
  262                   this.floatField = ((Float)value).floatValue();
  263               else if (value instanceof Integer)
  264                   this.intField = ((Integer)value).intValue();
  265               else if (value instanceof Long)
  266                   this.longField = ((Long)value).longValue();
  267               else if (value instanceof Short)
  268                   this.shortField = ((Short)value).shortValue();
  269               else if (value instanceof String)
  270                   this.stringField = (String)value;
  271               else
  272                   this.objectField = value;
  273           }
  274           
  275           public boolean equals(SingleFieldIdentity sfi) {
  276               if (sfi==null)
  277                   throw new IllegalArgumentException ("Argument sfi must not be null");
  278               boolean result = false;
  279               if (sfi instanceof ByteIdentity) 
  280                   result = ((ByteIdentity)sfi).getKey()==this.byteField;
  281               else if (sfi instanceof CharIdentity) 
  282                   result = ((CharIdentity)sfi).getKey()==this.charField;
  283               else if (sfi instanceof IntIdentity) 
  284                   result = ((IntIdentity)sfi).getKey()==this.intField;
  285               else if (sfi instanceof LongIdentity) 
  286                   result = ((LongIdentity)sfi).getKey()==this.longField;
  287               else if (sfi instanceof ShortIdentity) 
  288                   result = ((ShortIdentity)sfi).getKey()==this.shortField;
  289               else if (sfi instanceof StringIdentity) 
  290                   result = ((StringIdentity)sfi).getKey().equals(this.stringField);
  291               else 
  292                   result = ((ObjectIdentity)sfi).getKey().equals(this.objectField);
  293               return result;
  294           }
  295       }
  296   }

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