Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java Mon Apr 4 12:41:23 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()); + } + } +}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java Mon Apr 4 12:41:23 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()); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java Mon Apr 4 12:41:23 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()); + } + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java Mon Apr 4 12:41:23 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()); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java Mon Apr 4 12:41:23 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()); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TestParts.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TestParts.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TestParts.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TestParts.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,125 @@ +/* + * 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 org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.inheritance.Constants; + +/** + * The test data is in arrays, making it easy to change values. The Inheritance test classes refer to the + * data via array index and the checkXXXX() routines carry an index value--indicating the expected value. + * If those attributes are references and should be other than null, as is the case with thirdObj, then the + * test code inserts the reference into the data array. + * + * Each test class follows the same pattern: + * 1. Persistent and transient object are created in the first transaction. + * 2. A second transaction is started, the first persistent object retrieved and checking is done on + * its attribute values. + * 3. A rollback is performed and value comparisions are made on the transient instances that were created. + * 4. A third transation is started and the first persistent object again retrieved and checking is done on + * its attribute values. + */ +public abstract class TestParts extends JDO_Test { + + // 0 1 2 3 4 5 6 7 8 9 10 11 + static final Object[] secondObj_V = { null, null, null, null, null, null, null, null, null, null, null, null}; + static final Object[] thirdObj_V = { null, null, null, null, null, null, null, null, null, null, null, null}; + static final Object[] fourthObj_V = { null, null, null, null, null, null, null, null, null, null, null, null}; + + static String persistentAfterCommit = "Read object back after committed to Database. "; + static String persistentAfterRollback = "Read object back after rollback. "; + static String transientAfterRollback = "Object reverted to transient after rollback. "; + + /** */ + void checkPersistentAreCorrect(String assertion, String title, int index, + double doubleB, int intB, short shortF, + Object thirdObj, int intH) { + if(doubleB != Constants.doubleB_V[index]) { + fail(assertion, + title + "Persistent attribute doubleB is " + doubleB + + ", it should be " + Constants.doubleB_V[index]); + } + if(intB != Constants.intB_V[index]) { + fail(assertion, + title + "Persistent attribute intB is " + intB + + ", it should be " + Constants.intB_V[index]); + } + if(shortF != Constants.shortF_V[index]) { + fail(assertion, + title + "Persistent attribute shortF is " + shortF + + ", it should be " + Constants.shortF_V[index]); + } + if(thirdObj != TestParts.thirdObj_V[index]) { + fail(assertion, + title + "Persistent attribute thirdObj is " + thirdObj + + ", it should be " + TestParts.thirdObj_V[index]); + } + if(intH != Constants.intH_V[index]) { + fail(assertion, + title + "Persistent attribute intH is " + intH + + ", it should be " + Constants.intH_V[index]); + } + } + + /** */ + void checkTransactionalAreCorrect(String assertion, String title, int index, + float floatE, Object secondObj) { + + if(floatE != Constants.floatE_V[index]) { + fail(assertion, + title + "Transactional attribute floatE is " + floatE + + ", it should be " + Constants.floatE_V[index]); + } + if(secondObj != TestParts.secondObj_V[index]) { + fail(assertion, + title + "Transactional attribute secondObj is " + secondObj + + ", it should be " + TestParts.secondObj_V[index]); + } + } + + /** */ + void checkNonpersistentAreCorrect(String assertion, String title, int index, + int intA, char charC, boolean booleanD, + short shortG, Object fourthObj) { + if(intA != Constants.intA_V[index]) { + fail(assertion, + title + "In non-persistent class, attribute intA is " + intA + + ", it should be " + Constants.intA_V[index]); + } + if(charC != Constants.charC_V[index]) { + fail(assertion, + title + "In non-persistent class, attribute charC is " + charC + + ", it should be " + Constants.charC_V[index]); + } + if(booleanD != Constants.booleanD_V[index]) { + fail(assertion, + title + "In non-persistent class, attribute booleanD is " + booleanD + + ", it should be " + Constants.booleanD_V[index]); + } + if(shortG != Constants.shortG_V[index]) { + fail(assertion, + title + "In non-persistent class, attribute shortG is " + shortG + + ", it should be " + Constants.shortG_V[index]); + } + if(fourthObj != TestParts.fourthObj_V[index]) { + fail(assertion, + title + "In non-persistent class, attribute fourthObj is " + fourthObj + + ", it should be " + TestParts.fourthObj_V[index]); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TestParts.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TransactionalFieldsAreTransactionalInSubclasses.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TransactionalFieldsAreTransactionalInSubclasses.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TransactionalFieldsAreTransactionalInSubclasses.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TransactionalFieldsAreTransactionalInSubclasses.java Mon Apr 4 12:41:23 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> Transactional Fields are Transactional in Subclasses + *<BR> + *<B>Keywords:</B> inheritance + *<BR> + *<B>Assertion ID:</B> A6.5-5. + *<BR> + *<B>Assertion Description: </B> +Fields marked as transactional in persistence-capable classes +will be transactional in subclasses. + + */ + +public class TransactionalFieldsAreTransactionalInSubclasses extends TestParts { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.5-5 (TransactionalFieldsAreTransactionalInSubclasses) 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(TransactionalFieldsAreTransactionalInSubclasses.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 = d; + 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 + checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterRollback, 8, c.floatE, c.secondObj); + } + 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()); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritance/TransactionalFieldsAreTransactionalInSubclasses.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Address.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Address.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Address.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Address.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,281 @@ +/* + * 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.pc.company; + +import java.io.Serializable; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a postal address. + */ +public class Address + implements Serializable, Comparable, DeepEquality { + + private long addrid; + private String street; + private String city; + private String state; + private String zipcode; + private String country; + + /** This is the JDO-required no-args constructor */ + protected Address() {} + + /** + * This constructor initializes the <code>Address</code> components. + * @param addrid The address ID. + * @param street The street address. + * @param city The city. + * @param state The state. + * @param zipcode The zip code. + * @param country The zip country. + */ + public Address(long addrid, String street, String city, + String state, String zipcode, String country) + { + this.addrid = addrid; + this.street = street; + this.city = city; + this.state = state; + this.zipcode = zipcode; + this.country = country; + } + + /** + * Get the addrid associated with this object. + * @return the addrid. + */ + public long getAddrid() { + return addrid; + } + + /** + * Get the street component of the address. + * @return The street component of the address. + */ + public String getStreet() { + return street; + } + + /** + * Set the street component of the address. + * @param street The street component. + */ + public void setStreet(String street) { + this.street = street; + } + + /** + * Get the city. + * @return The city component of the address. + */ + public String getCity(String city) { + return city; + } + + /** + * Set the city component of the address. + * @param city The city. + */ + public void setCity(String city) { + this.city = city; + } + + /** + * Get the state component of the address. + * @return The state. + */ + public String getState() { + return state; + } + + /** + * Set the state component of the address. + * @param state The state. + */ + public void setState(String state) { + this.state = state; + } + + /** + * Get the zipcode component of the address. + * @return The zipcode. + */ + public String getZipcode() { + return zipcode; + } + + /** + * Set the zip code component of the address. + * @param zipcode The zipcode. + */ + public void setZipcode(String zipcode) { + this.zipcode = zipcode; + } + + /** + * Get the country component of the address. + * @return The country. + */ + public String getCountry() { + return country; + } + + /** + * Set the country component of the address. + * @param country The country. + */ + public void setCountry(String country) { + this.country = country; + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + Address otherAddress = (Address)other; + return (addrid == otherAddress.addrid) && + helper.equals(street, otherAddress.street) && + helper.equals(city, otherAddress.city) && + helper.equals(state, otherAddress.state) && + helper.equals(zipcode, otherAddress.zipcode) && + helper.equals(country, otherAddress.country); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((Address)o); + } + + /** + * Compares this object with the specified Address object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Address object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Address + * object. + */ + public int compareTo(Address other) { + long otherId = other.addrid; + return (addrid < otherId ? -1 : (addrid == otherId ? 0 : 1)); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return <code>true</code> if this object is the same as the obj + * argument; <code>false</code> otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof Address) { + return compareTo((Address)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)addrid; + } + + /** + * This class is used to represent the application identifier + * for the <code>Address</code> class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This is the identifier field for <code>Address</code> and must + * correspond in type and name to the field in + * <code>Address</code>. + */ + public long addrid; + + /** The required public, no-arg constructor. */ + public Oid() + { + addrid = 0; + } + + /** + * A constructor to initialize the identifier field. + * @param addrid the id of the Adress. + */ + public Oid(long addrid) { + this.addrid = addrid; + } + + public Oid(String s) { addrid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + addrid;} + + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o = (Oid) obj; + if( this.addrid != o.addrid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) addrid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( addrid < other.addrid ) return -1; + if( addrid > other.addrid ) return 1; + return 0; + } + + } + +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Address.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Company.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Company.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Company.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Company.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,292 @@ +/* + * 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.pc.company; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Set; +import java.util.HashSet; +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents information about a company. + */ +public class Company + implements Serializable, Comparable, DeepEquality { + + private long companyid; + private String name; + private Date founded; + private Address address; + private transient Set departments = new HashSet(); // element type is Department + + /** This is the JDO-required no-args constructor */ + protected Company() {} + + /** + * Initialize the <code>Company</code> instance. + * @param companyid The company id. + * @param name The company name. + * @param founded The date the company was founded. + * @param addr The company's address. + */ + public Company(long companyid, String name, Date founded, Address addr) { + this.companyid = companyid; + this.name = name; + this.founded = founded; + this.address = addr; + } + + /** + * Get the company id. + * @return The company id. + */ + public long getCompanyid() { + return companyid; + } + + /** + * Get the name of the company. + * @return The name of the company. + */ + public String getName() { + return name; + } + + /** + * Set the name of the company. + * @param name The value to use for the name of the company. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the date that the company was founded. + * @return The date the company was founded. + */ + public Date getFounded() { + return founded; + } + + /** + * Set the date that the company was founded. + * @param founded The date to set that the company was founded. + */ + public void setFounded(Date founded) { + this.founded = founded; + } + + /** + * Get the address of the company. + * @return The primary address of the company. + */ + public Address getAddress() { + return address; + } + + /** + * Set the primary address for the company. + * @param address The address to set for the company. + */ + public void setAddress(Address address) { + this.address = address; + } + + /** + * Get the departments contained in the company. + * @return An unmodifiable <code>Set</code> that contains all the + * <code>Department</code>s of the company. + */ + public Set getDepartments() { + return Collections.unmodifiableSet(departments); + } + + /** + * Add a <code>Department</code> instance to the company. + * @param dept The <code>Department</code> instance to add. + */ + public void addDepartment(Department dept) { + departments.add(dept); + } + + /** + * Remove a <code>Department</code> instance from the company. + * @param dept The <code>Department</code> instance to remove. + */ + public void removeDepartment(Department dept) { + departments.remove(dept); + } + + /** + * Initialize the set of <code>Department</code>s in the company to the + * parameter. + * @param departments The set of <code>Department</code>s for the + * company. + */ + public void setDepartments(Set departments) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.departments = + (departments != null) ? new HashSet(departments) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + departments = new HashSet(); + } + + /** + * Returns <code>true</code> if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return <code>true</code> if all the fields are deep equal; + * <code>false</code> otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(DeepEquality other, + EqualityHelper helper) { + Company otherCompany = (Company)other; + return (companyid == otherCompany.companyid) && + helper.equals(name, otherCompany.name) && + helper.equals(founded, otherCompany.founded) && + helper.deepEquals(address, otherCompany.address) && + helper.deepEquals(departments, otherCompany.departments); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((Company)o); + } + + /** + * Compares this object with the specified Company object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Company object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Company + * object. + */ + public int compareTo(Company other) { + long otherId = other.companyid; + return (companyid < otherId ? -1 : (companyid == otherId ? 0 : 1)); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return <code>true</code> if this object is the same as the obj + * argument; <code>false</code> otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof Company) { + return compareTo((Company)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)companyid; + } + + /** + * The class to be used as the application identifier + * for the <code>Company</code> class. It consists of both the company + * name and the date that the company was founded. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field is part of the identifier and should match in name + * and type with a field in the <code>Company</code> class. + */ + public long companyid; + + /** The required public no-arg constructor. */ + public Oid() { } + + /** + * Initialize the identifier. + * @param companyid The id of the company. + */ + public Oid(long companyid) { + this.companyid = companyid; + } + + public Oid(String s) { companyid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + companyid;} + + + /** */ + public boolean equals(Object obj) { + if (obj==null || !this.getClass().equals(obj.getClass())) + return false; + Oid o = (Oid) obj; + if (this.companyid != o.companyid) + return false; + return true; + } + + /** */ + public int hashCode() { + return (int)companyid; + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( companyid < other.companyid ) return -1; + if( companyid > other.companyid ) return 1; + return 0; + } + + } + +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Company.java ------------------------------------------------------------------------------ svn:executable = *