db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject svn commit: r348505 - in /incubator/jdo/trunk/tck20: ./ test/conf/ test/java/org/apache/jdo/tck/ test/java/org/apache/jdo/tck/query/ test/java/org/apache/jdo/tck/query/sql/ test/jdo/applicationidentity/ test/jdo/datastoreidentity/
Date Wed, 23 Nov 2005 17:57:39 GMT
Author: brazil
Date: Wed Nov 23 09:57:29 2005
New Revision: 348505

URL: http://svn.apache.org/viewcvs?rev=348505&view=rev
Log:
JDO-165: Implement new JDO 2 query tests cases concerning SQL queries.

Added:
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/CandidateClass.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/NewQuery.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java
Modified:
    incubator/jdo/trunk/tck20/maven.xml
    incubator/jdo/trunk/tck20/test/conf/alltests.conf
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/JDO_Test.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java
    incubator/jdo/trunk/tck20/test/jdo/applicationidentity/package.jdo
    incubator/jdo/trunk/tck20/test/jdo/datastoreidentity/package.jdo

Modified: incubator/jdo/trunk/tck20/maven.xml
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/maven.xml?rev=348505&r1=348504&r2=348505&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/maven.xml (original)
+++ incubator/jdo/trunk/tck20/maven.xml Wed Nov 23 09:57:29 2005
@@ -398,9 +398,7 @@
             <not>
                 <uptodate targetfile="${jdo.tck.enhanced.dir}/${jdo.tck.identitytype}.jar">
                     <srcfiles dir="${basedir}/test/jdo/${jdo.tck.identitytype}"
-                          includes="org/apache/jdo/tck/**/*.jdo, 
-                                    org/apache/jdo/tck/**/*.jdoquery,
-                                    org/apache/jdo/tck/**/jdoTest.properties"/>
+                          includes="**/*.jdo, **/*.jdoquery, **/*.jdoTest.properties"/>
                     <srcfiles dir="${basedir}/test/java"
                           includes="${jdo.tck.pcclasses.sources},
                                     ${jdo.tck.paclasses.sources}"/>

Modified: incubator/jdo/trunk/tck20/test/conf/alltests.conf
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/conf/alltests.conf?rev=348505&r1=348504&r2=348505&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/conf/alltests.conf (original)
+++ incubator/jdo/trunk/tck20/test/conf/alltests.conf Wed Nov 23 09:57:29 2005
@@ -391,6 +391,10 @@
 org.apache.jdo.tck.query.result.ShapeOfResult \
 org.apache.jdo.tck.query.result.Unique \
 org.apache.jdo.tck.query.result.VariableInResult \
+org.apache.jdo.tck.query.sql.ShapeOfResult \
+org.apache.jdo.tck.query.sql.CandidateClass \
+org.apache.jdo.tck.query.sql.AllowedAPIMethods \
+org.apache.jdo.tck.query.sql.NewQuery \
 org.apache.jdo.tck.transactions.AfterCompletionMethodCalledWhenCommitted \
 org.apache.jdo.tck.transactions.AfterCompletionMethodCalledWhenRolledback \
 org.apache.jdo.tck.transactions.AfterSetRollbackOnlyCommitFails \

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/JDO_Test.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/JDO_Test.java?rev=348505&r1=348504&r2=348505&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/JDO_Test.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/JDO_Test.java Wed Nov 23 09:57:29
2005
@@ -698,6 +698,13 @@
         return getPMF().supportedOptions().contains(
             "javax.jdo.option.UnconstrainedVariables");
     }
+    
+    /** Reports whether SQL queries are supported. */
+    public boolean isSQLSupported() {
+        return getPMF().supportedOptions().contains(
+            "javax.jdo.query.SQL");
+    }
+    
 
     /**
      * This utility method returns a <code>String</code> that indicates the
@@ -860,4 +867,13 @@
         }
     }
 
+    /**
+     * Returns the value of the PMF property 
+     * given by argument <code>key</code>.
+     * @param key the key
+     * @return the value
+     */
+    protected String getPMFProperty(String key) {
+        return PMFPropertiesObject.getProperty(key);
+    }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java?rev=348505&r1=348504&r2=348505&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/QueryTest.java Wed Nov 23
09:57:29 2005
@@ -18,6 +18,7 @@
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -764,7 +765,7 @@
      * Compiles the given query element holder instance 
      * as a JDO API query or single string query, 
      * depending on argument <code>asSingleString</code>.
-     * Argument <code>singleStringQuery</code> exists to support queries
+     * Argument <code>singleStringQuery</code> is used to support queries
      * which cannot be expressed as query element holder instances.
      * That argument is ignored if argument <code>queryElementHolder</code> 
      * is set.
@@ -788,33 +789,49 @@
             QueryElementHolder queryElementHolder, boolean asSingleString,  
             String singleStringQuery, boolean positive) {
         PersistenceManager pm = getPM();
+        Query query;
+        if (queryElementHolder != null) {
+            if (asSingleString) {
+                query = queryElementHolder.getSingleStringQuery(pm);
+            } else {
+                query = queryElementHolder.getAPIQuery(pm);
+            }
+        } else {
+            query = getPM().newQuery(singleStringQuery);
+        }
+        compile(assertion, query, singleStringQuery, positive);
+    }
+    
+    /**
+     * Compiles the given query instance.
+     * Argument <code>positive</code> determines if the compilation is supposed
+     * to succeed or to fail. 
+     * If <code>true</code> and the compilation fails,
+     * then the test case fails prompting arguments <code>assertion</code>
+     * and <code>queryText</code>. 
+     * If <code>false</code> and the compilation succeeds,
+     * then the test case fails prompting argument <code>assertion</code>
+     * and <code>queryText</code>. 
+     * Otherwise the test case succeeds. 
+     * @param assertion
+     * @param query
+     * @param queryText
+     * @param positive
+     */
+    protected void compile(String assertion, 
+            Query query, String queryText, boolean positive) {
+        PersistenceManager pm = getPM();
         Transaction tx = pm.currentTransaction();
         tx.begin();
         try {
-            Query query;
-            if (queryElementHolder != null) {
-                if (asSingleString) {
-                    query = queryElementHolder.getSingleStringQuery(pm);
-                } else {
-                    query = queryElementHolder.getAPIQuery(pm);
-                }
-            } else {
-                query = getPM().newQuery(singleStringQuery);
-            }
             query.compile();
             if (!positive) {
-                String queryText = queryElementHolder != null ? 
-                        queryElementHolder.toString() :
-                        singleStringQuery;
                 fail(assertion + 
                         "Query compilation must throw JDOUserException: " + 
                         queryText);
             }
         } catch (JDOUserException e) {
             if (positive) {
-                String queryText = queryElementHolder != null ? 
-                        queryElementHolder.toString() :
-                        singleStringQuery;
                 fail(assertion + "Query '" + queryText +
                         "' must be compilable. The exception message is: " + 
                         e.getMessage());
@@ -975,7 +992,7 @@
         execute(assertion, queryElementHolder, true, 
                 parameters, expectedResult);
     }
-    
+
     /**
      * Converts the given query element holder instance 
      * to a JDO query instance,
@@ -1026,6 +1043,47 @@
         }
         return execute(assertion, query, singleStringQuery, hasOrdering,
                 parameters, expectedResult, positive);
+    }
+
+    /**
+     * Executes the given SQL string as a JDO SQL query.
+     * The result of that query is compared against the given argument 
+     * <code>expectedResult</code>. 
+     * If the expected result does not match the returned query result,
+     * then the test case fails prompting argument <code>assertion</code>.
+     * Argument <code>unique</code> indicates, if the query is supposed
+     * to return a single result.
+     * Argument <code>sql</code> may contain the substring <code>"{0}"</code>.
+     * All occurences of this substring are replaced 
+     * by the value of PMF property <code>"javax.jdo.mapping.Schema"</code>.
+     * @param assertion the assertion to prompt if the test case fails.
+     * @param sql the SQL string.
+     * @param candidateClass the candidate class.
+     * @param resultClass the result class.
+     * @param parameters the parameters of the query.
+     * @param expectedResult the expected query result.
+     * @param unique indicates, if the query is supposed 
+     * to return a single result.
+     */
+    protected void executeSQLQuery(String assertion, String sql, 
+            Class candidateClass, Class resultClass, 
+            Object[] parameters, Object expectedResult, boolean unique) {
+        String schema = getPMFProperty("javax.jdo.mapping.Schema");
+        sql = MessageFormat.format(sql, new Object[]{schema});
+        if (logger.isDebugEnabled())
+            logger.debug("Executing SQL query: " + sql);
+        Query query = getPM().newQuery("javax.jdo.query.SQL", sql);
+        if (unique) {
+            query.setUnique(unique);
+        }
+        if (candidateClass != null) {
+            query.setClass(candidateClass);
+        }
+        if (resultClass != null) {
+            query.setResultClass(resultClass);
+        }
+        execute(assertion, query, sql, false, 
+                parameters, expectedResult, true);
     }
 
     /**

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java?rev=348505&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java
Wed Nov 23 09:57:29 2005
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.sql;
+
+import java.text.MessageFormat;
+import java.util.Arrays;
+
+import javax.jdo.JDOUserException;
+import javax.jdo.Query;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Department;
+import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.pc.mylib.MylibReader;
+import org.apache.jdo.tck.pc.mylib.PrimitiveTypes;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.query.result.classes.FullName;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Allowed API Methods.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.7-2.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * The only methods that can be used are setClass 
+ * to establish the candidate class, 
+ * setUnique to declare that there is only one result row, 
+ * and setResultClass to establish the result class.
+ */
+public class AllowedAPIMethods extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.7-2 (AllowedAPIMethods) failed: ";
+    
+    /**
+     * The <code>main</code> is called when the class
+     * is directly executed from the command line.
+     * @param args The arguments passed to the program.
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(AllowedAPIMethods.class);
+    }
+    
+    /** The array of valid SQL queries. */
+    private static final String[] VALID_SQL_QUERIES = {
+        "SELECT * FROM {0}.PrimitiveTypes",
+        "SELECT * FROM {0}.departments",
+        "SELECT * FROM {0}.persons",
+        "SELECT FIRSTNAME, LASTNAME FROM {0}.persons WHERE PERSONID = 1",
+        "SELECT FIRSTNAME, LASTNAME FROM {0}.persons"
+    };
+    
+    /** 
+     * The expected results of valid SQL queries.
+     */
+    private Object[] expectedResult = {
+        getMylibInstancesAsList(new String[]{
+                "primitiveTypesPositive", 
+                "primitiveTypesNegative",
+                "primitiveTypesCharacterStringLiterals"}),
+        getCompanyModelInstancesAsList(new String[]{"dept1", "dept2"}),
+        getCompanyModelInstancesAsList(new String[]{
+                "emp1", "emp2", "emp3", "emp4", "emp5"}),
+        new Object[]{"emp1First", "emp1Last"},
+        Arrays.asList(new Object[]{
+                new FullName("emp1First", "emp1Last"),
+                new FullName("emp2First", "emp2Last"),
+                new FullName("emp3First", "emp3Last"),
+                new FullName("emp4First", "emp4Last"),
+                new FullName("emp5First", "emp5Last")})
+    };
+            
+    /** */
+    public void testSetClass() {
+        if (isSQLSupported()) {
+            int index = 0;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    PrimitiveTypes.class, null, null, 
+                    expectedResult[index], false);
+
+            index = 1;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    Department.class, null, null, 
+                    expectedResult[index], false);
+
+            index = 2;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    Person.class, null, null, 
+                    expectedResult[index], false);
+        }
+    }
+
+    /** */
+    public void testSetUnique() {
+        if (isSQLSupported()) {
+            int index = 3;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, null, null, expectedResult[index], true);
+        }
+    }
+
+    /** */
+    public void testSetResultClass() {
+        if (isSQLSupported()) {
+            int index = 4;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, FullName.class, null, expectedResult[index], false);
+        }
+    }
+
+    /** */
+    public void testNegative() {
+        if (isSQLSupported()) {
+            String schema = getPMFProperty("javax.jdo.mapping.Schema");
+            // Note that the SQL query below is valid. 
+            // The query is not executed.
+            // Instead, the method uses a query instance 
+            // to check prohibited setters.
+            String sql = "SELECT PERSONID FROM {0}.persons";
+            sql = MessageFormat.format(sql, new Object[]{schema});
+            Query query = getPM().newQuery("javax.jdo.query.SQL", sql);
+            checkProhibitedSetters(query);
+        }
+    }
+    
+    private void checkProhibitedSetters(Query query) {
+        checkSetResult(query);
+        checkSetFilter(query);
+        checkDeclareVariables(query);
+        checkDeclareParameters(query);
+        checkDeclareImports(query);
+        checkSetGrouping(query);
+        checkSetOrdering(query);
+    }
+        
+    private void checkSetResult(Query query) {
+        try {
+            query.setResult("firstname, lastname");
+            methodFailed("setResult()");
+        } catch (JDOUserException e) {
+        }
+    }
+    
+    private void checkSetFilter(Query query) {
+        try {
+            query.setFilter("WHERE personid = 1");
+            methodFailed("setFilter()");
+        } catch (JDOUserException e) {
+        }
+    }
+    
+    private void checkDeclareVariables(Query query) {
+        try {
+            query.declareVariables("Employee emp");
+            methodFailed("declareVariables()");
+        } catch (JDOUserException e) {
+        }
+    }
+    
+    private void checkDeclareParameters(Query query) {
+        try {
+            query.declareParameters("Employee emp");
+            methodFailed("declareParameters()");
+        } catch (JDOUserException e) {
+        }
+    }
+    
+    private void checkDeclareImports(Query query) {
+        try {
+            query.declareImports("import org.apache.jdo.tck.pc.company.Employee");
+            methodFailed("declareImports()");
+        } catch (JDOUserException e) {
+        }
+    }
+    
+    private void checkSetGrouping(Query query) {
+        try {
+            query.setGrouping("firstname");
+            methodFailed("setGrouping()");
+        } catch (JDOUserException e) {
+        }
+    }
+    
+    private void checkSetOrdering(Query query) {
+        try {
+            query.setOrdering("firstname ASCENDING");
+            methodFailed("setOrdering()");
+        } catch (JDOUserException e) {
+        }
+    }
+    
+    private void methodFailed(String method) {
+        fail(ASSERTION_FAILED + method + 
+                " on a SQL query must throw JDOUserException." );
+    }
+    
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
+        loadMylib(getPM(), MYLIB_TESTDATA);
+        addTearDownClass(MylibReader.getTearDownClasses());
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/CandidateClass.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/CandidateClass.java?rev=348505&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/CandidateClass.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/CandidateClass.java Wed
Nov 23 09:57:29 2005
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.sql;
+
+import java.util.Arrays;
+
+import javax.jdo.Query;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Candidate Class.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.7-3.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * SQL queries can be defined without a candidate class. 
+ * These queries can be found by name using the factory method newNamedQuery, 
+ * specifying the class as null, 
+ * or can be constructed without a candidate class.
+ */
+public class CandidateClass extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.7-3 (CandidateClass) failed: ";
+    
+    /**
+     * The <code>main</code> is called when the class
+     * is directly executed from the command line.
+     * @param args The arguments passed to the program.
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(CandidateClass.class);
+    }
+    
+    /** The array of valid SQL queries. */
+    private static final String[] VALID_SQL_QUERIES = {
+        "SELECT firstname, lastname FROM {0}.persons"
+    };
+    
+    /** 
+     * The expected results of valid SQL queries.
+     */
+    private Object[] expectedResult = {
+        Arrays.asList(new Object[]{
+                new Object[]{"emp1First", "emp1Last"},
+                new Object[]{"emp2First", "emp2Last"},
+                new Object[]{"emp3First", "emp3Last"},
+                new Object[]{"emp4First", "emp4Last"},
+                new Object[]{"emp5First", "emp5Last"}})
+    };
+            
+    /** */
+    public void testNamedQuery() {
+        if (isSQLSupported()) {
+            int index = 0;
+            Query query = getPM().newNamedQuery(null, "SQLQuery");
+            executeJDOQuery(ASSERTION_FAILED, query, "Named SQL query", 
+                    false, null, expectedResult[index], true);
+        }
+    }
+
+    /** */
+    public void testNoCandidateClass() {
+        if (isSQLSupported()) {
+            int index = 0;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, null, null, expectedResult[index], false);
+        }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/NewQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/NewQuery.java?rev=348505&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/NewQuery.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/NewQuery.java Wed Nov
23 09:57:29 2005
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.sql;
+
+import java.util.Arrays;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> New SQL Query.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.7-1.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * In this case, the factory method that takes the language string and 
+ * Object is used: newQuery (String language, Object query). 
+ * The language parameter is javax.jdo.query.SQL and 
+ * the query parameter is the SQL query string.
+ */
+public class NewQuery extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.7-1 (NewQuery) failed: ";
+    
+    /**
+     * The <code>main</code> is called when the class
+     * is directly executed from the command line.
+     * @param args The arguments passed to the program.
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(NewQuery.class);
+    }
+    
+    /** The array of valid SQL queries. */
+    private static final String[] VALID_SQL_QUERIES = {
+        "SELECT firstname, lastname FROM {0}.persons WHERE personid = ?"
+    };
+    
+    /** 
+     * The expected results of valid SQL queries.
+     */
+    private Object[] expectedResult = {
+        Arrays.asList(new Object[]{
+                new Object[]{"emp1First", "emp1Last"}})
+    };
+            
+    /** Parameters of valid SQL queries. */
+    private static Object[][] parameters = {
+        {new Integer(1)}
+    };
+            
+    /** */
+    public void testPositive() {
+        if (isSQLSupported()) {
+            for (int i = 0; i < VALID_SQL_QUERIES.length; i++) {
+                executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[i],
+                        null, null, parameters[i], expectedResult[i], false);
+            }
+        }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java?rev=348505&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java Wed
Nov 23 09:57:29 2005
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.sql;
+
+import java.text.MessageFormat;
+import java.util.Arrays;
+
+import javax.jdo.Query;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.mylib.MylibReader;
+import org.apache.jdo.tck.pc.mylib.PrimitiveTypes;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.query.result.classes.FullName;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Shape of Result.
+ *<BR>
+ *<B>Keywords:</B> query
+ *<BR>
+ *<B>Assertion ID:</B> A14.7-4.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Table 7: Shape of Result of SQL Query
+ */
+public class ShapeOfResult extends QueryTest {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A14.7-4 (ShapeOfResult) failed: ";
+    
+    /**
+     * The <code>main</code> is called when the class
+     * is directly executed from the command line.
+     * @param args The arguments passed to the program.
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(ShapeOfResult.class);
+    }
+    
+    /** The array of valid SQL queries. */
+    private static final String[] VALID_SQL_QUERIES = {
+        // candidate class
+        "SELECT * FROM {0}.PrimitiveTypes",
+        // candidate class, unique
+        "SELECT * FROM {0}.PrimitiveTypes where id = 1",
+        // single column
+        "SELECT firstname FROM {0}.persons",
+        // single column, unique
+        "SELECT firstname FROM {0}.persons WHERE personid = 1",
+        // mutiple columns
+        "SELECT firstname, lastname FROM {0}.persons",
+        // mutiple columns, unique
+        "SELECT firstname, lastname FROM {0}.persons WHERE personid = 1",
+        // result class
+        "SELECT firstname, lastname FROM {0}.persons",
+        // result class, unique
+        "SELECT firstname, lastname FROM {0}.persons WHERE personid = 1"
+    };
+    
+    /** 
+     * The expected results of valid SQL queries.
+     */
+    private Object[] expectedResult = {
+        // candidate class
+        getMylibInstancesAsList(new String[]{
+                "primitiveTypesPositive", "primitiveTypesNegative",
+                "primitiveTypesCharacterStringLiterals"}),
+        // candidate class, unique
+        getMylibInstance("primitiveTypesPositive"),
+        // single column
+        Arrays.asList(new Object[]{"emp1First", "emp2First", "emp3First", 
+            "emp4First", "emp5First"}),
+        // single column, unique
+        "emp1First",
+        // mutiple columns
+        Arrays.asList(new Object[]{
+            new Object[]{"emp1First", "emp1Last"},
+            new Object[]{"emp2First", "emp2Last"},
+            new Object[]{"emp3First", "emp3Last"},
+            new Object[]{"emp4First", "emp4Last"},
+            new Object[]{"emp5First", "emp5Last"}}),
+        // mutiple columns, unique
+        new Object[]{"emp1First", "emp1Last"},
+        // result class
+        Arrays.asList(new Object[]{
+            new FullName("emp1First", "emp1Last"),
+            new FullName("emp2First", "emp2Last"),
+            new FullName("emp3First", "emp3Last"),
+            new FullName("emp4First", "emp4Last"),
+            new FullName("emp5First", "emp5Last")}),
+        // result class, unique
+        new FullName("emp1First", "emp1Last")
+    };
+    
+    /** */
+    public void testCanidateClass() {
+        if (isSQLSupported()) {
+            int index = 0;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    PrimitiveTypes.class, null, null, 
+                    expectedResult[index], false);
+            index++;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    PrimitiveTypes.class, null, null, 
+                    expectedResult[index], true);
+        }
+    }
+
+    /** */
+    public void testSingleColumn() {
+        if (isSQLSupported()) {
+            int index = 2;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, null, null, expectedResult[index], false);
+            index++;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, null, null, expectedResult[index], true);
+        }
+    }
+    
+    /** */
+    public void testMultipleColumn() {
+        if (isSQLSupported()) {
+            int index = 4;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, null, null, expectedResult[index], false);
+            index++;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, null, null, expectedResult[index], true);
+        }
+    }
+    
+    /** */
+    public void testResultClass() {
+        if (isSQLSupported()) {
+            int index = 6;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, FullName.class, null, expectedResult[index], false);
+            index++;
+            executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+                    null, FullName.class, null, expectedResult[index], true);
+        }
+    }
+    
+    /** */
+    public void testNegative() {
+        if (isSQLSupported()) {
+            String schema = getPMFProperty("javax.jdo.mapping.Schema");
+            String sql = MessageFormat.format(
+                    "SELECT stringNull FROM {0}.PrimitiveTypes", 
+                    new Object[]{schema});
+            Query query = getPM().newQuery("javax.jdo.query.SQL", sql);
+            query.setClass(PrimitiveTypes.class);
+            compile(ASSERTION_FAILED, query, sql, false);
+        }
+    }
+    
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
+        loadMylib(getPM(), MYLIB_TESTDATA);
+        addTearDownClass(MylibReader.getTearDownClasses());
+    }
+}

Modified: incubator/jdo/trunk/tck20/test/jdo/applicationidentity/package.jdo
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/jdo/applicationidentity/package.jdo?rev=348505&r1=348504&r2=348505&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/jdo/applicationidentity/package.jdo (original)
+++ incubator/jdo/trunk/tck20/test/jdo/applicationidentity/package.jdo Wed Nov 23 09:57:29
2005
@@ -8,4 +8,7 @@
     <query name="packageJDOInDefaultPackage">
         SELECT FROM org.apache.jdo.tck.pc.company.Person
     </query>
+    <query name="SQLQuery" language="javax.jdo.query.SQL">
+        SELECT FIRSTNAME, LASTNAME FROM applicationidentity0.persons
+    </query>
 </jdo>

Modified: incubator/jdo/trunk/tck20/test/jdo/datastoreidentity/package.jdo
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/jdo/datastoreidentity/package.jdo?rev=348505&r1=348504&r2=348505&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/jdo/datastoreidentity/package.jdo (original)
+++ incubator/jdo/trunk/tck20/test/jdo/datastoreidentity/package.jdo Wed Nov 23 09:57:29 2005
@@ -8,4 +8,7 @@
     <query name="packageJDOInDefaultPackage">
         SELECT FROM org.apache.jdo.tck.pc.company.Person
     </query>
+    <query name="SQLQuery" language="javax.jdo.query.SQL">
+        SELECT FIRSTNAME, LASTNAME FROM datastoreidentity0.persons
+    </query>
 </jdo>



Mime
View raw message