Index: src/conf/query.conf
===================================================================
--- src/conf/query.conf (revision 497503)
+++ src/conf/query.conf (working copy)
@@ -84,4 +84,5 @@
org.apache.jdo.tck.query.sql.ShapeOfResult \
org.apache.jdo.tck.query.sql.NoCandidateClass \
org.apache.jdo.tck.query.sql.AllowedAPIMethods \
-org.apache.jdo.tck.query.sql.NewQuery
+org.apache.jdo.tck.query.sql.NewQuery \
+org.apache.jdo.tck.query.sql.ExecuteWithMap
Index: src/java/org/apache/jdo/tck/query/QueryTest.java
===================================================================
--- src/java/org/apache/jdo/tck/query/QueryTest.java (revision 497503)
+++ src/java/org/apache/jdo/tck/query/QueryTest.java (working copy)
@@ -1173,8 +1173,8 @@
* to return a single result.
*/
protected void executeSQLQuery(String assertion, String sql,
- Class candidateClass, Class resultClass,
- Object[] parameters, Object expectedResult, boolean unique) {
+ Class candidateClass, Class resultClass, boolean positive,
+ Object parameters, Object expectedResult, boolean unique) {
String schema = getPMFProperty("javax.jdo.mapping.Schema");
sql = MessageFormat.format(sql, new Object[]{schema});
if (logger.isDebugEnabled())
@@ -1190,7 +1190,7 @@
query.setResultClass(resultClass);
}
execute(assertion, query, sql, false,
- parameters, expectedResult, true);
+ parameters, expectedResult, positive);
}
/**
Index: src/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java
===================================================================
--- src/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java (revision 497503)
+++ src/java/org/apache/jdo/tck/query/sql/AllowedAPIMethods.java (working copy)
@@ -95,17 +95,17 @@
if (isSQLSupported()) {
int index = 0;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- PrimitiveTypes.class, null, null,
+ PrimitiveTypes.class, null, true, null,
expectedResult[index], false);
index = 1;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- Department.class, null, null,
+ Department.class, null, true, null,
expectedResult[index], false);
index = 2;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- Person.class, null, null,
+ Person.class, null, true, null,
expectedResult[index], false);
}
}
@@ -115,7 +115,7 @@
if (isSQLSupported()) {
int index = 3;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, null, null, expectedResult[index], true);
+ null, null, true, null, expectedResult[index], true);
}
}
@@ -124,7 +124,8 @@
if (isSQLSupported()) {
int index = 4;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, FullName.class, null, expectedResult[index], false);
+ null, FullName.class, true, null, expectedResult[index],
+ false);
}
}
Index: src/java/org/apache/jdo/tck/query/sql/ExecuteWithMap.java
===================================================================
--- src/java/org/apache/jdo/tck/query/sql/ExecuteWithMap.java (revision 0)
+++ src/java/org/apache/jdo/tck/query/sql/ExecuteWithMap.java (revision 0)
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.HashMap;
+
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+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.util.BatchTestRunner;
+
+/**
+ *Title: ExecuteWithMap
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.7-5.
+ *
+ *Assertion Description:
+ * If the parameter list is a Map, then the keys of the Map
+ * must be instances of Integer whose intValue is 1..n.
+ * The value in the Map corresponding to the key whose intValue is 1
+ * is bound to the first ? in the SQL statement, and so forth.
+ */
+public class ExecuteWithMap extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.7-5 (ExecuteWithMap)";
+
+ /**
+ * The main 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(ExecuteWithMap.class);
+ }
+
+ /** The array of valid SQL queries. */
+ private static final String[] VALID_SQL_QUERIES = {
+ "SELECT * FROM {0}.PrimitiveTypes WHERE intNotNull = ? "
+ + "OR stringNull = ?",
+ "SELECT * FROM {0}.persons WHERE FIRSTNAME = ? AND LASTNAME = ?"
+ + " AND MIDDLENAME = ? AND CITY = ?",
+ "SELECT * FROM {0}.persons WHERE FIRSTNAME = ? AND LASTNAME = ?"
+ + " AND MIDDLENAME = ? AND CITY = ?"
+ };
+
+ /**
+ * The expected results of valid SQL queries.
+ */
+ private Object[] expectedResult = {
+ getTransientMylibInstancesAsList(new String[]{
+ "primitiveTypesPositive",
+ "primitiveTypesCharacterStringLiterals"}),
+ getTransientCompanyModelInstancesAsList(new String[]{"emp2"}),
+ getTransientCompanyModelInstancesAsList(new String[]{"emp2"})
+ };
+
+ /**
+ * Maps of parameter values
+ */
+ private static HashMap hm1 = new HashMap();
+ private static HashMap hm2 = new HashMap();
+ private static HashMap hm3 = new HashMap();
+ private static HashMap hm4 = new HashMap();
+ private static HashMap illegalMapMissingKeyTwo = new HashMap();
+ private static HashMap illegalMapStartsWithZero = new HashMap();
+ private static HashMap illegalMapStringKeys = new HashMap();
+ static {
+ // valid parameter values
+ hm1.put(new Integer(1), new Integer(4));
+ hm1.put(new Integer(2), "Even");
+
+ hm2.put(new Integer(1), "emp2First");
+ hm2.put(new Integer(2), "emp2Last");
+ hm2.put(new Integer(3), "emp2Middle");
+ hm2.put(new Integer(4), "New York");
+
+ hm3 = (HashMap) hm2.clone();
+ // extra entry okay, should be ignored by impl
+ hm3.put(new Integer(0), "emp2First");
+
+ hm4 = (HashMap) hm2.clone();
+ // extra entry okay, should be ignored by impl
+ hm4.put(new Integer(5), "New York");
+
+ // invalid parameter values
+ illegalMapMissingKeyTwo.put(new Integer(1), "emp2First");
+ illegalMapMissingKeyTwo.put(new Integer(3), "emp2Last");
+ illegalMapMissingKeyTwo.put(new Integer(4), "emp2Middle");
+ illegalMapMissingKeyTwo.put(new Integer(5), "New York");
+
+ illegalMapStartsWithZero.put(new Integer(0), "emp2First");
+ illegalMapStartsWithZero.put(new Integer(1), "emp2Last");
+ illegalMapStartsWithZero.put(new Integer(2), "emp2Middle");
+ illegalMapStartsWithZero.put(new Integer(3), "New York");
+
+ illegalMapStringKeys = new HashMap();
+ illegalMapStringKeys.put(new String("1dog"), "emp2First");
+ illegalMapStringKeys.put(new String("2dog"), "emp2Last");
+ illegalMapStringKeys.put(new String("3dog"), "emp2Middle");
+ illegalMapStringKeys.put(new String("4dog"), "New York");
+ };
+ private static HashMap[] parameterMap = new HashMap[]{hm1, hm2, hm3};
+
+ /** */
+ public void testSetClass() {
+ boolean unique = false;
+ boolean positive = true;
+ if (isSQLSupported()) {
+ int index = 0;
+ executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+ PrimitiveTypes.class, null, positive,
+ parameterMap[index], expectedResult[index], unique);
+
+ index = 1;
+ executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+ Person.class, null, positive,
+ parameterMap[index], expectedResult[index], unique);
+
+ index = 2;
+ executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+ Person.class, null, positive,
+ parameterMap[index], expectedResult[index], unique);
+
+ index = 3;
+ executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
+ Person.class, null, positive,
+ parameterMap[index], expectedResult[index], unique);
+ }
+ }
+
+ /** */
+ public void testNegative() {
+ if (isSQLSupported()) {
+ String query = "SELECT * FROM {0}.persons WHERE FIRSTNAME = ? "
+ + "AND LASTNAME = ? AND MIDDLENAME = ? AND CITY = ? "
+ + "AND FUNDINGDEPT = ?";
+ String singleStringQuery = query;
+ boolean unique = false;
+ boolean positive = false;
+ executeSQLQuery(ASSERTION_FAILED, query, Person.class, null,
+ positive, illegalMapMissingKeyTwo, null, unique);
+ executeSQLQuery(ASSERTION_FAILED, query, Person.class, null,
+ positive, illegalMapStartsWithZero, null, unique);
+ executeSQLQuery(ASSERTION_FAILED, query, Person.class, null,
+ positive, illegalMapStringKeys, null, unique);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ addTearDownClass(MylibReader.getTearDownClasses());
+ loadAndPersistCompanyModel(getPM());
+ loadAndPersistMylib(getPM());
+ }
+}
Index: src/java/org/apache/jdo/tck/query/sql/NewQuery.java
===================================================================
--- src/java/org/apache/jdo/tck/query/sql/NewQuery.java (revision 497503)
+++ src/java/org/apache/jdo/tck/query/sql/NewQuery.java (working copy)
@@ -75,7 +75,8 @@
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);
+ null, null, true, parameters[i], expectedResult[i],
+ false);
}
}
}
Index: src/java/org/apache/jdo/tck/query/sql/NoCandidateClass.java
===================================================================
--- src/java/org/apache/jdo/tck/query/sql/NoCandidateClass.java (revision 497503)
+++ src/java/org/apache/jdo/tck/query/sql/NoCandidateClass.java (working copy)
@@ -86,7 +86,7 @@
if (isSQLSupported()) {
int index = 0;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, null, null, expectedResult[index], false);
+ null, null, true, null, expectedResult[index], false);
}
}
Index: src/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java
===================================================================
--- src/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java (revision 497503)
+++ src/java/org/apache/jdo/tck/query/sql/ShapeOfResult.java (working copy)
@@ -115,11 +115,11 @@
if (isSQLSupported()) {
int index = 0;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- PrimitiveTypes.class, null, null,
+ PrimitiveTypes.class, null, true, null,
expectedResult[index], false);
index++;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- PrimitiveTypes.class, null, null,
+ PrimitiveTypes.class, null, true, null,
expectedResult[index], true);
}
}
@@ -129,10 +129,10 @@
if (isSQLSupported()) {
int index = 2;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, null, null, expectedResult[index], false);
+ null, null, true, null, expectedResult[index], false);
index++;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, null, null, expectedResult[index], true);
+ null, null, true, null, expectedResult[index], true);
}
}
@@ -141,10 +141,10 @@
if (isSQLSupported()) {
int index = 4;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, null, null, expectedResult[index], false);
+ null, null, true, null, expectedResult[index], false);
index++;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, null, null, expectedResult[index], true);
+ null, null, true, null, expectedResult[index], true);
}
}
@@ -153,10 +153,10 @@
if (isSQLSupported()) {
int index = 6;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, FullName.class, null, expectedResult[index], false);
+ null, FullName.class, true, null, expectedResult[index], false);
index++;
executeSQLQuery(ASSERTION_FAILED, VALID_SQL_QUERIES[index],
- null, FullName.class, null, expectedResult[index], true);
+ null, FullName.class, true, null, expectedResult[index], true);
}
}