Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.query.jdoql.parameters » [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.query.jdoql.parameters;
   19   
   20   
   21   import javax.jdo.JDOUserException;
   22   import javax.jdo.PersistenceManager;
   23   import javax.jdo.Query;
   24   import javax.jdo.Transaction;
   25   
   26   import org.apache.jdo.tck.pc.mylib.PCPoint;
   27   import org.apache.jdo.tck.query.QueryTest;
   28   import org.apache.jdo.tck.util.BatchTestRunner;
   29   
   30   /**
   31    *<B>Title:</B> Each parameter named in the parameter declaration must be bound
   32    *to a value when executing the query.
   33    *<BR>
   34    *<B>Keywords:</B> query parameter check
   35    *<BR>
   36    *<B>Assertion ID:</B> A14.3-3.
   37    *<BR>
   38    *<B>Assertion Description: </B> Each parameter named in the parameter
   39    *declaration must be bound to a value when executing the query.
   40    */
   41   
   42   public class BoundParameterCheck extends QueryTest {
   43   
   44       /** */
   45       private static final String ASSERTION_FAILED = 
   46           "Assertion A14.3-3 (BoundParameterCheck) failed: ";
   47       
   48       /**
   49        * The <code>main</code> is called when the class
   50        * is directly executed from the command line.
   51        * @param args The arguments passed to the program.
   52        */
   53       public static void main(String[] args) {
   54           BatchTestRunner.run(BoundParameterCheck.class);
   55       }
   56   
   57       /** */
   58       public void test() {
   59           pm = getPM();
   60           checkQueryParameters(pm);
   61           pm.close();
   62           pm = null;
   63       }
   64   
   65       /** */
   66       void checkQueryParameters(PersistenceManager pm) {
   67           Transaction tx = pm.currentTransaction();
   68           try {
   69               tx.begin();
   70               Query query = pm.newQuery();
   71               query.setClass(PCPoint.class);
   72               query.setCandidates(pm.getExtent(PCPoint.class, false));
   73               query.declareParameters( "int a" );
   74               query.setFilter( "x == 0" );
   75               try {
   76                   Object results = query.execute();
   77                   fail(ASSERTION_FAILED,
   78                        "Query.execute with unbound parameter should throw JDOUserExecption.");
   79               }
   80               catch (JDOUserException ex) {
   81                   // expected exception
   82                   if (debug) {
   83                       logger.debug("expected exception: " + ex);
   84                   }
   85               }
   86               tx.rollback();
   87               tx = null;
   88           }
   89           finally {
   90               if ((tx != null) && tx.isActive())
   91                   tx.rollback();
   92           }
   93       }
   94   }
   95   

Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.query.jdoql.parameters » [javadoc | source]