Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencemanager.cache » [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.api.persistencemanager.cache;
   20   
   21   import javax.jdo.PersistenceManager;
   22   import javax.jdo.Transaction;
   23   
   24   import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
   25   import org.apache.jdo.tck.pc.mylib.PCPoint;
   26   import org.apache.jdo.tck.util.BatchTestRunner;
   27   
   28   /**
   29    *<B>Title:</B> Refresh All With No Parameters
   30    *<BR>
   31    *<B>Keywords:</B> cache
   32    *<BR>
   33    *<B>Assertion ID:</B> A12.5.1-6.
   34    *<BR>
   35    *<B>Assertion Description: </B>
   36    The <code>PersistenceManager.refreshAll</code> method with no parameters
   37    causes all transactional instances to be refreshed. Note that this method
   38    will cause loss of changes made to affected instances by the application
   39    due to refreshing the contents from the data store.
   40    The JDO <code>PersistenceManager</code>:
   41    <UL>
   42    <LI>loads persistent values from the data store;</LI>
   43    <LI>loads persistent fields into the instance;</LI>
   44    <LI>calls the <code>jdoPostLoad</code> method on each persistent instance,
   45    if the class of the instance implements <code>InstanceCallbacks</code>; and</LI>
   46    <LI>changes the state of persistent-dirty instances to persistent-clean.</LI>
   47    </UL>
   48   
   49    */
   50   
   51   public class RefreshAllWithNoParameters extends PersistenceManagerTest {
   52       
   53       /** */
   54       private static final String ASSERTION_FAILED = 
   55           "Assertion A12.5.1-6 (RefreshAllWithNoParameters) failed: ";
   56       
   57       /**
   58        * The <code>main</code> is called when the class
   59        * is directly executed from the command line.
   60        * @param args The arguments passed to the program.
   61        */
   62       public static void main(String[] args) {
   63           BatchTestRunner.run(RefreshAllWithNoParameters.class);
   64       }
   65   
   66       /** */
   67       public void test() {
   68           pm = getPM();
   69   
   70           runTestRefreshAll(pm);
   71   
   72           pm.close();
   73           pm = null;
   74       }
   75       
   76       /** */
   77       private void runTestRefreshAll(PersistenceManager pm) {
   78           Transaction tx = pm.currentTransaction();
   79           try {
   80               tx.begin();
   81               PCPoint p = new PCPoint (100, 200);
   82               pm.makePersistent(p);
   83               tx.commit();
   84               
   85               tx.begin();
   86               p.setX(500);
   87               p.setY(new Integer(800));
   88               pm.refreshAll();
   89               int currentX = p.getX();
   90               Integer currentY = p.getY();
   91               if ((currentX != 100) || !currentY.equals(new Integer(200))) {
   92                   fail(ASSERTION_FAILED,
   93                        "RefreshAll expected 100, 200; got " + currentX + ", " + currentY);
   94               }
   95               tx.commit();
   96               tx = null;
   97           }
   98           finally {
   99               if ((tx != null) && tx.isActive())
  100                   tx.rollback();
  101           }
  102       }
  103   }

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