You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2005/03/19 02:09:46 UTC
svn commit: r158179 [16/61] - in incubator/jdo/trunk/tck11: ./ assertions/
iut_jars/ test/ test/conf/ test/java/ test/java/org/ test/java/org/apache/
test/java/org/apache/jdo/ test/java/org/apache/jdo/tck/
test/java/org/apache/jdo/tck/api/
test/java/org/apache/jdo/tck/api/instancecallbacks/
test/java/org/apache/jdo/tck/api/jdohelper/
test/java/org/apache/jdo/tck/api/persistencemanager/
test/java/org/apache/jdo/tck/api/persistencemanagerfactory/
test/java/org/apache/jdo/tck/enhancement/
test/java/org/apache/jdo/tck/extents/ test/java/org/apache/jdo/tck/lifecycle/
test/java/org/apache/jdo/tck/lifecycle/nontransactional/
test/java/org/apache/jdo/tck/models/
test/java/org/apache/jdo/tck/models/embedded/
test/java/org/apache/jdo/tck/models/fieldtypes/
test/java/org/apache/jdo/tck/models/inheritance/
test/java/org/apache/jdo/tck/pc/ test/java/org/apache/jdo/tck/pc/company/
test/java/org/apache/jdo/tck/pc/fieldtypes/
test/java/org/apache/jdo/tck/pc/inheritance/
test/java/org/apache/jdo/tck/pc/instancecallbacks/
test/java/org/apache/jdo/tck/pc/lifecycle/
test/java/org/apache/jdo/tck/pc/mylib/ test/java/org/apache/jdo/tck/query/
test/java/org/apache/jdo/tck/query/operators/
test/java/org/apache/jdo/tck/transactions/
test/java/org/apache/jdo/tck/util/ test/jdo/ test/jdo/applicationidentity/
test/jdo/applicationidentity/org/ test/jdo/applicationidentity/org/apache/
test/jdo/applicationidentity/org/apache/jdo/
test/jdo/applicationidentity/org/apache/jdo/tck/
test/jdo/applicationidentity/org/apache/jdo/tck/pc/
test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/
test/jdo/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/
test/jdo/applicationidentity/org/apache/jdo/tck/pc/inheritance/
test/jdo/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/
test/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/
test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/
test/jdo/datastoreidentity/ test/jdo/datastoreidentity/org/
test/jdo/datastoreidentity/org/apache/
test/jdo/datastoreidentity/org/apache/jdo/
test/jdo/datastoreidentity/org/apache/jdo/tck/
test/jdo/datastoreidentity/org/apache/jdo/tck/pc/
test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/
test/jdo/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/
test/jdo/datastoreidentity/org/apache/jdo/tck/pc/inheritance/
test/jdo/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/
test/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/
test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,143 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.SetCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Set.
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-34.
+ *<BR>
+ *<B>Assertion Description: </B>
+JDO implementations must support fields of the interface type
+<code>java.util.Set</code>, and may choose to support them
+as Second Class Objects or First Class Objects.
+ */
+
+public class TestSetCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-34 (TestSetCollections) 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(TestSetCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ try {
+ int i, n;
+ FirstSetOfTestValuesForCollection firstValue = new FirstSetOfTestValuesForCollection();
+ SecondSetOfTestValuesForCollection secondValue = new SecondSetOfTestValuesForCollection();
+
+ int ret = 0;
+ // turn on datastore transactions
+ tx.setOptimistic(false);
+ tx.begin();
+ SetCollections pi = new SetCollections();
+ pi.identifier = 1;
+ pm.makePersistent(pi);
+ Object oid = pm.getObjectId(pi);
+ n = pi.getLength();
+ // Provide initial set of values
+ for(i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(SetCollections.fieldSpecs[i]);
+ pi.set( i, new HashSet((Collection)firstValue.get(valueType)));
+ }
+ tx.commit();
+ // cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+
+ checkValues(oid, firstValue); // check if persistent fields have values set
+ pi = (SetCollections) pm.getObjectById(oid, true);
+
+ // Provide new set of values
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(SetCollections.fieldSpecs[i]);
+ pi.set( i, new HashSet((Collection)secondValue.get(valueType)));
+ }
+ tx.commit();
+ // cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+ // check new values
+ checkValues(oid, secondValue);
+ pi = (SetCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+
+ SetCollections pi = (SetCollections) pm.getObjectById(oid, true);
+ int n = pi.getLength();
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(SetCollections.fieldSpecs[i]);
+ Set compareWith = new HashSet((Collection)startValue.get(valueType));
+
+ Set val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + SetCollections.fieldSpecs[i]);
+ }
+ }
+ }
+
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,191 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.TreeMapStringKeyCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type TreeMap, varying value type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-27.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the TreeMap optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>TreeMap</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestTreeMapStringKeyCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-27 (TestTreeMapStringKeyCollections) 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(TestTreeMapStringKeyCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isTreeMapSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature TreeMap");
+ return;
+ }
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ int i, j, n;
+ FirstSetOfTestValuesForCollection firstValue =
+ new FirstSetOfTestValuesForCollection();
+ SecondSetOfTestValuesForCollection secondValue =
+ new SecondSetOfTestValuesForCollection();
+
+ // turn on datastore transactions
+ tx.setOptimistic(false);
+ tx.begin();
+ TreeMapStringKeyCollections pi = new TreeMapStringKeyCollections();
+ pi.identifier = 1;
+ pm.makePersistent(pi);
+ Object oid = pm.getObjectId(pi);
+ n = pi.getLength();
+ // Provide initial set of values
+ for(i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringKeyCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ TreeMap map = new TreeMap();
+ Vector keys = (Vector) firstValue.get(fieldType);
+ Vector values = (Vector) secondValue.get(valueType);
+
+ for (j = 0; j< keys.size(); j++) {
+ map.put(keys.get(j), values.get(j));
+ }
+
+ pi.set(i, map);
+ }
+ tx.commit();
+ // cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+
+ Hashtable firstSet = new Hashtable();
+ firstSet.put("keys", firstValue);
+ firstSet.put("values", secondValue);
+
+ checkValues(oid, firstSet); // check if persistent fields have values set
+ pi = (TreeMapStringKeyCollections) pm.getObjectById(oid, true);
+
+ // Provide new set of values -- reverse the keys and values
+ for(i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringKeyCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ TreeMap map = new TreeMap();
+ Vector keys = (Vector) secondValue.get(fieldType);
+ Vector values = (Vector) firstValue.get(valueType);
+
+ for (j = 0; j< keys.size(); j++) {
+ map.put(keys.get(j), values.get(j));
+ }
+
+ pi.set(i, map);
+ }
+
+ tx.commit();
+ // cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+ // check new values
+ Hashtable secondSet = new Hashtable();
+ secondSet.put("keys", secondValue);
+ secondSet.put("values", firstValue);
+
+ checkValues(oid, secondSet);
+ pi = (TreeMapStringKeyCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue){
+ int i, j;
+
+ TreeMapStringKeyCollections pi = (TreeMapStringKeyCollections) pm.getObjectById(oid, true);
+ int n = pi.getLength();
+
+ Hashtable keySet = (Hashtable) startValue.get("keys");
+ Hashtable valueSet = (Hashtable) startValue.get("values");
+
+ for( i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringKeyCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ TreeMap compareWith = new TreeMap();
+
+ Vector keys = (Vector) keySet.get(fieldType);
+ Vector values = (Vector) valueSet.get(valueType);
+
+ for (j = 0; j< keys.size(); j++) {
+ compareWith.put(keys.get(j), values.get(j));
+ }
+
+ TreeMap val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + TreeMapStringKeyCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,191 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.TreeMapStringValueCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type TreeMap, varying key type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-27.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the TreeMap optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>TreeMap</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+public class TestTreeMapStringValueCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-27 (TestTreeMapStringValueCollections) 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(TestTreeMapStringValueCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isTreeMapSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature TreeMap");
+ return;
+ }
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ int i, j, n;
+ FirstSetOfTestValuesForCollection firstValue =
+ new FirstSetOfTestValuesForCollection();
+ SecondSetOfTestValuesForCollection secondValue =
+ new SecondSetOfTestValuesForCollection();
+
+ // turn on datastore transactions
+ tx.setOptimistic(false);
+ tx.begin();
+ TreeMapStringValueCollections pi = new TreeMapStringValueCollections();
+ pi.identifier = 1;
+ pm.makePersistent(pi);
+ Object oid = pm.getObjectId(pi);
+ n = pi.getLength();
+// Provide initial set of values
+ for(i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringValueCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ TreeMap map = new TreeMap();
+ Vector keys = (Vector) firstValue.get(fieldType);
+ Vector values = (Vector) secondValue.get(valueType);
+
+ for (j = 0; j< keys.size(); j++) {
+ map.put(keys.get(j), values.get(j));
+ }
+
+ pi.set(i, map);
+ }
+ tx.commit();
+// cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+
+ Hashtable firstSet = new Hashtable();
+ firstSet.put("keys", firstValue);
+ firstSet.put("values", secondValue);
+
+ checkValues(oid, firstSet); // check if persistent fields have values set
+ pi = (TreeMapStringValueCollections) pm.getObjectById(oid, true);
+
+// Provide new set of values -- reverse the keys and values
+ for(i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringValueCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ TreeMap map = new TreeMap();
+ Vector keys = (Vector) secondValue.get(fieldType);
+ Vector values = (Vector) firstValue.get(valueType);
+
+ for (j = 0; j< keys.size(); j++) {
+ map.put(keys.get(j), values.get(j));
+ }
+
+ pi.set(i, map);
+ }
+
+ tx.commit();
+// cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+// check new values
+ Hashtable secondSet = new Hashtable();
+ secondSet.put("keys", secondValue);
+ secondSet.put("values", firstValue);
+
+ checkValues(oid, secondSet);
+ pi = (TreeMapStringValueCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i, j;
+
+ TreeMapStringValueCollections pi = (TreeMapStringValueCollections) pm.getObjectById(oid, true);
+ int n = pi.getLength();
+
+ Hashtable keySet = (Hashtable) startValue.get("keys");
+ Hashtable valueSet = (Hashtable) startValue.get("values");
+
+ for( i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringValueCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ TreeMap compareWith = new TreeMap();
+
+ Vector keys = (Vector) keySet.get(fieldType);
+ Vector values = (Vector) valueSet.get(valueType);
+
+ for (j = 0; j< keys.size(); j++) {
+ compareWith.put(keys.get(j), values.get(j));
+ }
+
+ TreeMap val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + TreeMapStringValueCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,157 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.TreeSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.TreeSetCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type TreeSet.
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-28.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the TreeSet optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>TreeSet</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestTreeSetCollections extends JDO_Test {
+ private PersistenceManager pm;
+ private Transaction tx;
+ private static String prefix = "TestTreeSetCollections: ";
+ private TreeSet defaultValue; // do not initialize, should be 0 for int
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-28 (TestTreeSetCollections) 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(TestTreeSetCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isTreeSetSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature TreeSet");
+ return;
+ }
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ int i, n;
+ FirstSetOfTestValuesForCollection firstValue =
+ new FirstSetOfTestValuesForCollection();
+ SecondSetOfTestValuesForCollection secondValue =
+ new SecondSetOfTestValuesForCollection();
+
+ // turn on datastore transactions
+ tx.setOptimistic(false);
+ tx.begin();
+ TreeSetCollections pi = new TreeSetCollections();
+ pi.identifier = 1;
+ pm.makePersistent(pi);
+ Object oid = pm.getObjectId(pi);
+ n = pi.getLength();
+// Provide initial set of values
+ for(i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(
+ TreeSetCollections.fieldSpecs[i]);
+ pi.set( i, new TreeSet((Collection)firstValue.get(valueType)));
+ }
+ tx.commit();
+// cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+
+ checkValues(oid, firstValue); // check if persistent fields have values set
+ pi = (TreeSetCollections) pm.getObjectById(oid, true);
+
+// Provide new set of values
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(
+ TreeSetCollections.fieldSpecs[i]);
+ pi.set( i, new TreeSet((Collection)secondValue.get(valueType)));
+ }
+ tx.commit();
+// cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+// check new values
+ checkValues(oid, secondValue);
+ pi = (TreeSetCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+
+ TreeSetCollections pi = (TreeSetCollections) pm.getObjectById(oid, true);
+ int n = pi.getLength();
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(
+ TreeSetCollections.fieldSpecs[i]);
+ TreeSet compareWith = new TreeSet((Collection)startValue.get(valueType));
+
+ TreeSet val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + TreeSetCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,88 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Vector;
+
+public class TestUtil {
+
+ public TestUtil() {
+ }
+
+ //gets the value type for fields of a collection class
+ public static String getFieldSpecs(String field) {
+ //sample field =public Collection CollectionOfObject0
+ //look for last space and get the String before the numbers
+ String valueType = "";
+
+ int indexOfLastSpace = field.lastIndexOf(" ");
+ String fieldName = field.substring(indexOfLastSpace);
+ int indexOfValueType = fieldName.indexOf("Of") + 2;
+ String valueTypeWithNumber = fieldName.substring(indexOfValueType);
+ int lastIndexOfValueType = 0;
+ for (int i=valueTypeWithNumber.length() -1; i>=0; i--) {
+ if (Character.isDigit(valueTypeWithNumber.charAt(i))) {
+ continue;
+ } else {
+ lastIndexOfValueType = i;
+ break;
+ }
+ }
+ valueType = valueTypeWithNumber.substring(0, lastIndexOfValueType+1);
+
+ return valueType;
+ }
+
+
+ //gets the key type and value type for fields of a Map class
+ public static Vector getFieldSpecsForMap(String field) {
+ //sample field =public HashMap HashMapOfObject_Object0
+ //fieldType -- look for the last space and get the value between Of and _
+ //valueType -- look for last _ and get the String before the numbers
+ String fieldType = "";
+ String valueType = "";
+
+ int indexOfLastSpace = field.lastIndexOf(" ");
+ String fieldName = field.substring(indexOfLastSpace);
+ int indexOfFieldType = fieldName.indexOf("Of") + 2;
+ String fieldTypeWithValueType = fieldName.substring(indexOfFieldType);
+ int indexOfUnderScore = fieldTypeWithValueType.indexOf("_");
+ fieldType = fieldTypeWithValueType.substring(0, indexOfUnderScore);
+
+ String valueTypeWithNumber = fieldTypeWithValueType.substring(indexOfUnderScore + 1);
+ int lastIndexOfValueType = 0;
+ for (int i=valueTypeWithNumber.length() -1; i>=0; i--) {
+ if (Character.isDigit(valueTypeWithNumber.charAt(i))) {
+ continue;
+ } else {
+ lastIndexOfValueType = i;
+ break;
+ }
+ }
+ valueType = valueTypeWithNumber.substring(0, lastIndexOfValueType+1);
+
+ Vector fieldSpecs = new Vector();
+ fieldSpecs.add(fieldType);
+ fieldSpecs.add(valueType);
+
+ return fieldSpecs;
+ }
+
+
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,149 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.VectorCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Vector.
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-29.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the Vector optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>Vector</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestVectorCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-29 (TestVectorCollections) 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(TestVectorCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ if (!isVectorSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature Vector");
+ return;
+ }
+
+ Transaction tx = pm.currentTransaction();
+ try {
+ int i, n;
+ FirstSetOfTestValuesForCollection firstValue =
+ new FirstSetOfTestValuesForCollection();
+ SecondSetOfTestValuesForCollection secondValue =
+ new SecondSetOfTestValuesForCollection();
+
+ // turn on datastore transactions
+ tx.setOptimistic(false);
+ tx.begin();
+ VectorCollections pi = new VectorCollections();
+ pi.identifier = 1;
+ pm.makePersistent(pi);
+ Object oid = pm.getObjectId(pi);
+ n = pi.getLength();
+// Provide initial set of values
+ for(i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(VectorCollections.fieldSpecs[i]);
+ pi.set( i, (Vector)firstValue.get(valueType));
+ }
+ tx.commit();
+// cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+
+ checkValues(oid, firstValue); // check if persistent fields have values set
+ pi = (VectorCollections) pm.getObjectById(oid, true);
+
+// Provide new set of values
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(VectorCollections.fieldSpecs[i]);
+ pi.set( i, (Vector)secondValue.get(valueType));
+ }
+ tx.commit();
+// cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+// check new values
+ checkValues(oid, secondValue);
+ pi = (VectorCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+ VectorCollections pi = (VectorCollections) pm.getObjectById(oid, true);
+ int n = pi.getLength();
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(VectorCollections.fieldSpecs[i]);
+ Vector compareWith = (Vector)startValue.get(valueType);
+
+ Vector val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + VectorCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,235 @@
+/*
+ * 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.models.inheritance;
+
+import java.util.Iterator;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOException;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.inheritance.Constants;
+import org.apache.jdo.tck.pc.inheritance.FieldSameName4;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Field With the Same Name as a Field in a Superclass
+ *<BR>
+ *<B>Keywords:</B> inheritance
+ *<BR>
+ *<B>Assertion ID:</B> A6.5-7.
+ *<BR>
+ *<B>Assertion Description: </B>
+A class might define a new field with the same name as the field declared
+in the superclass, and might define it to be different (persistent or not)
+from the inherited field. But Java treats the declared field as a different
+field from the inherited field, so there is no conflict.
+
+ */
+
+public class FieldWithSameNameInSuperclass extends TestParts {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.5-7 (FieldWithSameNameInSuperclass) 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(FieldWithSameNameInSuperclass.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ Transaction t = pm.currentTransaction();
+ try {
+ t.setRestoreValues(true);
+
+ t.begin();
+ removeAllInstances(pm); // always start fresh with no instances
+ t.commit();
+ t.begin();
+ FieldSameName4 refa = new FieldSameName4(Constants.intA_V[1], Constants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Constants.booleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.shortG_V[1], Constants.intH_V[1]);
+ pm.makePersistent(refa);
+ Object objPtrA = pm.getObjectId (refa);
+
+ refa.setSecondObj(new FieldSameName4(Constants.intA_V[2], Constants.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.booleanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.shortG_V[2], Constants.intH_V[2]));
+ TestParts.secondObj_V[1] = refa.getSecondObj();
+ refa.setThirdObj(new FieldSameName4(Constants.intA_V[3], Constants.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.booleanD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG_V[3], Constants.intH_V[3]));
+ TestParts.thirdObj_V[1] = refa.getThirdObj();
+ pm.makePersistent(TestParts.thirdObj_V[1]);
+ Object objPtrB = pm.getObjectId(TestParts.thirdObj_V[1]);
+ refa.setFourthObj(new FieldSameName4(Constants.intA_V[4], Constants.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.booleanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.shortG_V[4], Constants.intH_V[4]));
+ TestParts.fourthObj_V[1] = refa.getFourthObj();
+ try {
+ t.commit();
+ } catch(JDOException e) {
+ Object o = e.getFailedObject();
+ String cname = o == null ? "null" : o.getClass().getName();
+ fail(ASSERTION_FAILED,
+ "Exception thrown, failed object class is " + cname + " exception is " + e);
+ }
+
+ t.begin();
+ FieldSameName4 a = null;
+ FieldSameName4 b = null;
+
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (FieldSameName4) pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous
+ // transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (FieldSameName4) pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 1, a.getDoubleB(), a.getIntB(), a.getShortF(), a.getThirdObj(), a.getIntH());
+
+ // verify referenced persistent object contains correct values
+ b = a.getThirdObj();
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 3, b.getDoubleB(), b.getIntB(), b.getShortF(), b.getThirdObj(), b.getIntH());
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ // set in new values
+ a.setIntA(Constants.intA_V[5]);
+ a.setCharC(Constants.charC_V[5]);
+ a.setBooleanD(Constants.booleanD_V[5]);
+ a.setShortG(Constants.shortG_V[5]);
+ FieldSameName4 fourth = new FieldSameName4(Constants.intA_V[6], Constants.doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Constants.booleanD_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constants.shortG_V[6], Constants.intH_V[6]);
+ a.setFourthObj(fourth);
+ a.setFloatE(Constants.floatE_V[5]);
+ a.setSecondObj(null);
+ a.setDoubleB(Constants.doubleB_V[5]);
+ a.setIntB(Constants.intB_V[5]);
+ a.setShortF(Constants.shortF_V[5]);
+ a.setThirdObj(null);
+ a.setIntH(Constants.intH_V[5]);
+
+ b.setIntA(Constants.intA_V[7]);
+ b.setCharC(Constants.charC_V[7]);
+ b.setBooleanD(Constants.booleanD_V[7]);
+ b.setShortG(Constants.shortG_V[7]);
+ b.setFourthObj(null);
+ b.setFloatE(Constants.floatE_V[7]);
+ b.setSecondObj(null);
+ b.setDoubleB(Constants.doubleB_V[7]);
+ b.setIntB(Constants.intB_V[7]);
+ b.setShortF(Constants.shortF_V[7]);
+ b.setThirdObj(null);
+ b.setIntH(Constants.intH_V[7]);
+
+ // create new objects and make persistent
+ FieldSameName4 c = new FieldSameName4(Constants.intA_V[8], Constants.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.booleanD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[8], Constants.intH_V[8]);
+ FieldSameName4 d = new FieldSameName4(Constants.intA_V[9], Constants.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.booleanD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[9], Constants.intH_V[9]);
+ c.setThirdObj(d);
+ c.setFourthObj(d);
+ TestParts.thirdObj_V[8] = d;
+ TestParts.fourthObj_V[8] = d;
+ pm.makePersistent(c);
+
+ // change values of newly persistent object
+ c.setIntA(Constants.intA_V[10]);
+ c.setCharC(Constants.charC_V[10]);
+ c.setBooleanD(Constants.booleanD_V[10]);
+ c.setShortG(Constants.shortG_V[10]);
+ c.setFourthObj(null);
+ c.setFloatE(Constants.floatE_V[10]);
+ c.setSecondObj(null);
+ c.setDoubleB(Constants.doubleB_V[10]);
+ c.setIntB(Constants.intB_V[10]);
+ c.setShortF(Constants.shortF_V[10]);
+ c.setThirdObj(null);
+ c.setIntH(Constants.intH_V[10]);
+
+ t.rollback();
+
+ // verify objects revert back to transient after rollback
+ checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.getDoubleB(), c.getIntB(), c.getShortF(), c.getThirdObj(), c.getIntH());
+ checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.getFloatE(), c.getSecondObj());
+ checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 10, c.getIntA(), c.getCharC(), c.getBooleanD(), c.getShortG(), c.getFourthObj());
+
+ t.begin();
+
+ // verify rollback lost all persistent changes.
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (FieldSameName4) pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (FieldSameName4) pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 1, a.getDoubleB(), a.getIntB(), a.getShortF(), a.getThirdObj(), a.getIntH());
+ b = a.getThirdObj();
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 3, b.getDoubleB(), b.getIntB(), b.getShortF(), b.getThirdObj(), b.getIntH());
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ t.rollback();
+ t = null;
+ }
+ finally {
+ if ((t != null) && t.isActive())
+ t.rollback();
+ }
+ }
+
+ void removeAllInstances(PersistenceManager pm)
+ {
+ Extent e = pm.getExtent(FieldSameName4.class, true);
+ Iterator i = e.iterator();
+ while( i.hasNext() ){
+ pm.deletePersistent(i.next());
+ }
+ }
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.models.inheritance;
+
+import java.util.Iterator;
+
+import javax.jdo.Extent;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.inheritance.AllPersist4;
+import org.apache.jdo.tck.pc.inheritance.Constants;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Non-Persistent Fields Are Non-Persistent in Subclasses
+ *<BR>
+ *<B>Keywords:</B> inheritance
+ *<BR>
+ *<B>Assertion ID:</B> A6.5-6.
+ *<BR>
+ *<B>Assertion Description: </B>
+Fields marked as non-persistent in persistence-capable classes
+will be non-persistent in subclasses.
+
+ */
+
+public class NonPersistentFieldsAreNonPersistentInSubclasses extends TestParts {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.5-6 (NonPersistentFieldsAreNonPersistentInSubclasses) 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(NonPersistentFieldsAreNonPersistentInSubclasses.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ Transaction t = pm.currentTransaction();
+ try {
+ t.setRestoreValues(true);
+
+ t.begin();
+ removeAllInstances(pm); // always start fresh with no instances
+ t.commit();
+ t.begin();
+ // create new objects and make persistent
+ AllPersist4 c = new AllPersist4(Constants.intA_V[8], Constants.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.booleanD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[8], Constants.intH_V[8]);
+ AllPersist4 d = new AllPersist4(Constants.intA_V[9], Constants.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.booleanD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[9], Constants.intH_V[9]);
+ c.thirdObj = d;
+ c.fourthObj = d;
+ TestParts.thirdObj_V[8] = d;
+ TestParts.fourthObj_V[8] = d;
+ pm.makePersistent(c);
+
+ // change values of newly persistent object
+ c.intA = Constants.intA_V[10];
+ c.charC = Constants.charC_V[10];
+ c.booleanD = Constants.booleanD_V[10];
+ c.shortG = Constants.shortG_V[10];
+ c.fourthObj = null;
+ c.floatE = Constants.floatE_V[10];
+ c.secondObj = null;
+ c.doubleB = Constants.doubleB_V[10];
+ c.intB = Constants.intB_V[10];
+ c.shortF = Constants.shortF_V[10];
+ c.thirdObj = null;
+ c.intH = Constants.intH_V[10];
+
+ t.rollback();
+ t = null;
+
+ // verify objects revert back to transient after rollback
+ checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 10, c.intA, c.charC, c.booleanD, c.shortG, c.fourthObj);
+ }
+ finally {
+ if ((t != null) && t.isActive())
+ t.rollback();
+ }
+ }
+
+ void removeAllInstances(PersistenceManager pm)
+ {
+ AllPersist4 a = new AllPersist4(0, 0.0, 0, '0', false, 0.0f, (short)0, (short)0, 0);
+ pm.makePersistent(a); // guarantee the class is registered; this will be removed
+ Extent e = pm.getExtent(AllPersist4.class, true);
+ Iterator i = e.iterator();
+ while( i.hasNext() ){
+ pm.deletePersistent(i.next());
+ }
+ }
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,224 @@
+/*
+ * 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.models.inheritance;
+
+import java.util.Iterator;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.inheritance.Constants;
+import org.apache.jdo.tck.pc.inheritance.TopNonPersistH;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Non-persistent Super Class
+ *<BR>
+ *<B>Keywords:</B> inheritance
+ *<BR>
+ *<B>Assertion ID:</B> A6.5-1.
+ *<BR>
+ *<B>Assertion Description: </B>
+A class might be persistence-capable even if its superclass is not persistence-capable.
+
+ */
+
+public class NonpersistentSuperClass extends TestParts {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.5-1 (NonpersistentSuperClass) 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(NonpersistentSuperClass.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ Transaction t = pm.currentTransaction();
+ try {
+ t.setRestoreValues(true);
+
+ t.begin();
+ removeAllInstances(pm); // always start fresh with no instances
+ t.commit();
+ t.begin();
+ TopNonPersistH refa = new TopNonPersistH(Constants.intA_V[1], Constants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Constants.booleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.shortG_V[1], Constants.intH_V[1]);
+ pm.makePersistent(refa);
+ Object objPtrA = pm.getObjectId(refa);
+
+ refa.secondObj = new TopNonPersistH(Constants.intA_V[2], Constants.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.booleanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.shortG_V[2], Constants.intH_V[2]);
+ TestParts.secondObj_V[1] = refa.secondObj;
+ refa.thirdObj = new TopNonPersistH(Constants.intA_V[3], Constants.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.booleanD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG_V[3], Constants.intH_V[3]);
+ TestParts.thirdObj_V[1] = refa.thirdObj;
+ pm.makePersistent(refa.thirdObj);
+ Object objPtrB = pm.getObjectId(refa.thirdObj);
+ refa.fourthObj = new TopNonPersistH(Constants.intA_V[4], Constants.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.booleanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.shortG_V[4], Constants.intH_V[4]);
+ TestParts.fourthObj_V[1] = refa.fourthObj;
+ t.commit();
+
+ t.begin();
+ TopNonPersistH a = null;
+ TopNonPersistH b = null;
+
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (TopNonPersistH)pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (TopNonPersistH)pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH);
+
+ // verify referenced persistent object contains correct values
+ b = a.thirdObj;
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 3, b.doubleB, b.intB, b.shortF, b.thirdObj, b.intH);
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ // set in new values
+ a.intA = Constants.intA_V[5];
+ a.charC = Constants.charC_V[5];
+ a.booleanD = Constants.booleanD_V[5];
+ a.shortG = Constants.shortG_V[5];
+ a.fourthObj = new TopNonPersistH(Constants.intA_V[6], Constants.doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Constants.booleanD_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constants.shortG_V[6], Constants.intH_V[6]);
+ TestParts.fourthObj_V[5] = a.fourthObj;
+ a.floatE = Constants.floatE_V[5];
+ a.secondObj = null;
+ a.doubleB = Constants.doubleB_V[5];
+ a.intB = Constants.intB_V[5];
+ a.shortF = Constants.shortF_V[5];
+ a.thirdObj = null;
+ a.intH = Constants.intH_V[5];
+
+ b.intA = Constants.intA_V[7];
+ b.charC = Constants.charC_V[7];
+ b.booleanD = Constants.booleanD_V[7];
+ b.shortG = Constants.shortG_V[7];
+ b.fourthObj = null;
+ b.floatE = Constants.floatE_V[7];
+ b.secondObj = null;
+ b.doubleB = Constants.doubleB_V[7];
+ b.intB = Constants.intB_V[7];
+ b.shortF = Constants.shortF_V[7];
+ b.thirdObj = null;
+ b.intH = Constants.intH_V[7];
+
+ // create new objects and make persistent
+ TopNonPersistH c = new TopNonPersistH(Constants.intA_V[8], Constants.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.booleanD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[8], Constants.intH_V[8]);
+ TopNonPersistH d = new TopNonPersistH(Constants.intA_V[9], Constants.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.booleanD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[9], Constants.intH_V[9]);
+ c.thirdObj = d;
+ c.fourthObj = d;
+ TestParts.thirdObj_V[8] = d;
+ TestParts.fourthObj_V[8] = d;
+ pm.makePersistent(c);
+
+ // change values of newly persistent object
+ c.intA = Constants.intA_V[10];
+ c.charC = Constants.charC_V[10];
+ c.booleanD = Constants.booleanD_V[10];
+ c.shortG = Constants.shortG_V[10];
+ c.fourthObj = null;
+ c.floatE = Constants.floatE_V[10];
+ c.secondObj = null;
+ c.doubleB = Constants.doubleB_V[10];
+ c.intB = Constants.intB_V[10];
+ c.shortF = Constants.shortF_V[10];
+ c.thirdObj = null;
+ c.intH = Constants.intH_V[10];
+
+ t.rollback();
+
+ // verify objects revert back to transient after rollback
+ checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.doubleB, c.intB, c.shortF, c.thirdObj, c.intH);
+ checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.floatE, c.secondObj);
+ checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 10, c.intA, c.charC, c.booleanD, c.shortG, c.fourthObj);
+
+ t.begin();
+
+ // verify rollback lost all persistent changes.
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (TopNonPersistH)pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (TopNonPersistH)pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH);
+ b = a.thirdObj;
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 3, b.doubleB, b.intB, b.shortF, b.thirdObj, b.intH);
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ t.rollback();
+ t = null;
+ }
+ finally {
+ if ((t != null) && t.isActive())
+ t.rollback();
+ }
+ }
+
+ void removeAllInstances(PersistenceManager pm)
+ {
+ Extent e = pm.getExtent(TopNonPersistH.class, true);
+ Iterator i = e.iterator();
+ while( i.hasNext() ){
+ pm.deletePersistent(i.next());
+ }
+ }
+}
+
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,227 @@
+/*
+ * 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.models.inheritance;
+
+import java.util.Iterator;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.inheritance.Constants;
+import org.apache.jdo.tck.pc.inheritance.TopNonPersistH;
+import org.apache.jdo.tck.pc.inheritance.TopPersistH;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Persistence Capable Flexibility in Inheritance Hierarchy
+ *<BR>
+ *<B>Keywords:</B> inheritance
+ *<BR>
+ *<B>Assertion ID:</B> A6.5-3.
+ *<BR>
+ *<B>Assertion Description: </B>
+Subclasses of such classes that are not persistence-capable,
+but have a superclass that is persistence-capable might be persistence-capable.
+That is, it is possible for classes in the inheritance hierarchy to be
+alternately persistence-capable and not persistence-capable.
+
+ */
+
+public class PersistenceCapableFlexibilityInInheritanceHierarchy extends TestParts {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.5-3 (PersistenceCapableFlexibilityInInheritanceHierarchy) 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(PersistenceCapableFlexibilityInInheritanceHierarchy.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ Transaction t = pm.currentTransaction();
+ try {
+ t.setRestoreValues(true);
+
+ t.begin();
+ removeAllInstances(pm); // always start fresh with no instances
+ t.commit();
+ t.begin();
+ TopPersistH refa = new TopPersistH(Constants.intA_V[1], Constants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Constants.booleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.shortG_V[1], Constants.intH_V[1]);
+ pm.makePersistent(refa);
+ Object objPtrA = pm.getObjectId(refa);
+
+ refa.secondObj = new TopPersistH(Constants.intA_V[2], Constants.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.booleanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.shortG_V[2], Constants.intH_V[2]);
+ TestParts.secondObj_V[1] = refa.secondObj;
+ refa.thirdObj = new TopPersistH(Constants.intA_V[3], Constants.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.booleanD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG_V[3], Constants.intH_V[3]);
+ TestParts.thirdObj_V[1] = refa.thirdObj;
+ pm.makePersistent(refa.thirdObj);
+ Object objPtrB = pm.getObjectId(refa.thirdObj);
+ refa.fourthObj = new TopPersistH(Constants.intA_V[4], Constants.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.booleanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.shortG_V[4], Constants.intH_V[4]);
+ TestParts.fourthObj_V[1] = refa.fourthObj;
+ t.commit();
+
+ t.begin();
+ TopPersistH a = null;
+ TopPersistH b = null;
+
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (TopPersistH)pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (TopPersistH)pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH);
+
+ // verify referenced persistent object contains correct values
+ b = a.thirdObj;
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 3, b.doubleB, b.intB, b.shortF, b.thirdObj, b.intH);
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ // set in new values
+ a.intA = Constants.intA_V[5];
+ a.charC = Constants.charC_V[5];
+ a.booleanD = Constants.booleanD_V[5];
+ a.shortG = Constants.shortG_V[5];
+ a.fourthObj = new TopPersistH(Constants.intA_V[6], Constants.doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Constants.booleanD_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constants.shortG_V[6], Constants.intH_V[6]);
+ TestParts.fourthObj_V[5] = a.fourthObj;
+ a.floatE = Constants.floatE_V[5];
+ a.secondObj = null;
+ a.doubleB = Constants.doubleB_V[5];
+ a.intB = Constants.intB_V[5];
+ a.shortF = Constants.shortF_V[5];
+ a.thirdObj = null;
+ a.intH = Constants.intH_V[5];
+
+ b.intA = Constants.intA_V[7];
+ b.charC = Constants.charC_V[7];
+ b.booleanD = Constants.booleanD_V[7];
+ b.shortG = Constants.shortG_V[7];
+ b.fourthObj = null;
+ b.floatE = Constants.floatE_V[7];
+ b.secondObj = null;
+ b.doubleB = Constants.doubleB_V[7];
+ b.intB = Constants.intB_V[7];
+ b.shortF = Constants.shortF_V[7];
+ b.thirdObj = null;
+ b.intH = Constants.intH_V[7];
+
+ // create new objects and make persistent
+ TopPersistH c = new TopPersistH(Constants.intA_V[8], Constants.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.booleanD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[8], Constants.intH_V[8]);
+ TopPersistH d = new TopPersistH(Constants.intA_V[9], Constants.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.booleanD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[9], Constants.intH_V[9]);
+ c.thirdObj = d;
+ c.fourthObj = d;
+ TestParts.thirdObj_V[8] = d;
+ TestParts.fourthObj_V[8] = d;
+ pm.makePersistent(c);
+
+ // change values of newly persistent object
+ c.intA = Constants.intA_V[10];
+ c.charC = Constants.charC_V[10];
+ c.booleanD = Constants.booleanD_V[10];
+ c.shortG = Constants.shortG_V[10];
+ c.fourthObj = null;
+ c.floatE = Constants.floatE_V[10];
+ c.secondObj = null;
+ c.doubleB = Constants.doubleB_V[10];
+ c.intB = Constants.intB_V[10];
+ c.shortF = Constants.shortF_V[10];
+ c.thirdObj = null;
+ c.intH = Constants.intH_V[10];
+
+ t.rollback();
+
+ // verify objects revert back to transient after rollback
+ checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.doubleB, c.intB, c.shortF, c.thirdObj, c.intH);
+ checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.floatE, c.secondObj);
+ checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 10, c.intA, c.charC, c.booleanD, c.shortG, c.fourthObj);
+
+ t.begin();
+
+ // verify rollback lost all persistent changes.
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (TopPersistH)pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (TopPersistH)pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH);
+ b = a.thirdObj;
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 3, b.doubleB, b.intB, b.shortF, b.thirdObj, b.intH);
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ t.rollback();
+ t = null;
+ }
+ finally {
+ if ((t != null) && t.isActive())
+ t.rollback();
+ }
+ }
+
+ void removeAllInstances(PersistenceManager pm)
+ {
+ Extent e = pm.getExtent(TopNonPersistH.class, true);
+ Iterator i = e.iterator();
+ while( i.hasNext() ){
+ pm.deletePersistent(i.next());
+ }
+ }
+}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java?view=auto&rev=158179
==============================================================================
--- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java (added)
+++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java Fri Mar 18 17:07:39 2005
@@ -0,0 +1,224 @@
+/*
+ * 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.models.inheritance;
+
+import java.util.Iterator;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.inheritance.AllPersist4;
+import org.apache.jdo.tck.pc.inheritance.Constants;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Persistent Fields Are Persistent in SubClasses
+ *<BR>
+ *<B>Keywords:</B> inheritance
+ *<BR>
+ *<B>Assertion ID:</B> A6.5-4.
+ *<BR>
+ *<B>Assertion Description: </B>
+Fields identified as persistent in persistence-capable classes
+will be persistent in subclasses.
+
+ */
+
+public class PersistentFieldsArePersistentInSubClasses extends TestParts {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.5-4 (PersistentFieldsArePersistentInSubClasses) 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(PersistentFieldsArePersistentInSubClasses.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ Transaction t = pm.currentTransaction();
+ try {
+ t.setRestoreValues(true);
+
+ t.begin();
+ removeAllInstances(pm); // always start fresh with no instances
+ t.commit();
+ t.begin();
+ AllPersist4 refa = new AllPersist4(Constants.intA_V[1], Constants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Constants.booleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.shortG_V[1], Constants.intH_V[1]);
+ pm.makePersistent(refa);
+ Object objPtrA = pm.getObjectId (refa);
+
+ refa.secondObj = new AllPersist4(Constants.intA_V[2], Constants.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.booleanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.shortG_V[2], Constants.intH_V[2]);
+ TestParts.secondObj_V[1] = refa.secondObj;
+ refa.thirdObj = new AllPersist4(Constants.intA_V[3], Constants.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.booleanD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG_V[3], Constants.intH_V[3]);
+ TestParts.thirdObj_V[1] = refa.thirdObj;
+ pm.makePersistent(refa.thirdObj);
+ Object objPtrB = pm.getObjectId (refa.thirdObj);
+ refa.fourthObj = new AllPersist4(Constants.intA_V[4], Constants.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.booleanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.shortG_V[4], Constants.intH_V[4]);
+ TestParts.fourthObj_V[1] = refa.fourthObj;
+ t.commit();
+
+ t.begin();
+ AllPersist4 a = null;
+ AllPersist4 b = null;
+
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (AllPersist4)pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (AllPersist4)pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH);
+
+ // verify referenced persistent object contains correct values
+ b = a.thirdObj;
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterCommit, 3, b.doubleB, b.intB, b.shortF, b.thirdObj, b.intH);
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ // set in new values
+ a.intA = Constants.intA_V[5];
+ a.charC = Constants.charC_V[5];
+ a.booleanD = Constants.booleanD_V[5];
+ a.shortG = Constants.shortG_V[5];
+ a.fourthObj = new AllPersist4(Constants.intA_V[6], Constants.doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Constants.booleanD_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constants.shortG_V[6], Constants.intH_V[6]);
+ TestParts.fourthObj_V[5] = a.fourthObj;
+ a.floatE = Constants.floatE_V[5];
+ a.secondObj = null;
+ a.doubleB = Constants.doubleB_V[5];
+ a.intB = Constants.intB_V[5];
+ a.shortF = Constants.shortF_V[5];
+ a.thirdObj = null;
+ a.intH = Constants.intH_V[5];
+
+ b.intA = Constants.intA_V[7];
+ b.charC = Constants.charC_V[7];
+ b.booleanD = Constants.booleanD_V[7];
+ b.shortG = Constants.shortG_V[7];
+ b.fourthObj = null;
+ b.floatE = Constants.floatE_V[7];
+ b.secondObj = null;
+ b.doubleB = Constants.doubleB_V[7];
+ b.intB = Constants.intB_V[7];
+ b.shortF = Constants.shortF_V[7];
+ b.thirdObj = null;
+ b.intH = Constants.intH_V[7];
+
+ // create new objects and make persistent
+ AllPersist4 c = new AllPersist4(Constants.intA_V[8], Constants.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.booleanD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[8], Constants.intH_V[8]);
+ AllPersist4 d = new AllPersist4(Constants.intA_V[9], Constants.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.booleanD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[9], Constants.intH_V[9]);
+ c.thirdObj = d;
+ c.fourthObj = d;
+ TestParts.thirdObj_V[8] = d;
+ TestParts.fourthObj_V[8] = d;
+ pm.makePersistent(c);
+
+ // change values of newly persistent object
+ c.intA = Constants.intA_V[10];
+ c.charC = Constants.charC_V[10];
+ c.booleanD = Constants.booleanD_V[10];
+ c.shortG = Constants.shortG_V[10];
+ c.fourthObj = null;
+ c.floatE = Constants.floatE_V[10];
+ c.secondObj = null;
+ c.doubleB = Constants.doubleB_V[10];
+ c.intB = Constants.intB_V[10];
+ c.shortF = Constants.shortF_V[10];
+ c.thirdObj = null;
+ c.intH = Constants.intH_V[10];
+
+ t.rollback();
+
+ // verify objects revert back to transient after rollback
+ checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.doubleB, c.intB, c.shortF, c.thirdObj, c.intH);
+
+ t.begin();
+
+ // verify rollback lost all persistent changes.
+ try { // retrieve object created in previous transaction & store in value array for later comparison
+ TestParts.thirdObj_V[1] = (AllPersist4)pm.getObjectById(objPtrB, true);
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference thirdObj.");
+ }
+
+ try { // retrieve object created in previous transaction
+ a = (AllPersist4)pm.getObjectById(objPtrA, true);
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH);
+ b = a.thirdObj;
+ if(b != null) { // if previous error caused b to be null, then these tests cannot be performed.
+ checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfterRollback, 3, b.doubleB, b.intB, b.shortF, b.thirdObj, b.intH);
+ }
+ }
+ catch (JDOUserException e) {
+ // could not locate persistent object created in previous transaction
+ fail(ASSERTION_FAILED,
+ "JDOUserException " + e + " could not reference previously created object.");
+ }
+
+ t.rollback();
+ t = null;
+ }
+ finally {
+ if ((t != null) && t.isActive())
+ t.rollback();
+ }
+ }
+
+ void removeAllInstances(PersistenceManager pm)
+ {
+ AllPersist4 a = new AllPersist4(0, 0.0, 0, '0', false, 0.0f, (short)0, (short)0, 0);
+ pm.makePersistent(a); // guarantee the class is registered; this will be removed
+ Extent e = pm.getExtent(AllPersist4.class, true);
+ Iterator i = e.iterator();
+ while( i.hasNext() ){
+ pm.deletePersistent(i.next());
+ }
+ }
+}