Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 67731 invoked from network); 4 Apr 2005 19:43:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 Apr 2005 19:43:57 -0000 Received: (qmail 81640 invoked by uid 500); 4 Apr 2005 19:43:56 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Received: (qmail 81560 invoked by uid 99); 4 Apr 2005 19:43:56 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 04 Apr 2005 12:43:53 -0700 Received: (qmail 67544 invoked by uid 65534); 4 Apr 2005 19:43:48 -0000 Message-ID: <20050404194348.67543.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Mon, 04 Apr 2005 19:43:48 -0000 Subject: svn commit: r160090 [17/63] - in incubator/jdo/trunk: ./ tck20/ tck20/assertions/ tck20/iut_jars/ tck20/test/ tck20/test/conf/ tck20/test/java/ tck20/test/java/org/ tck20/test/java/org/apache/ tck20/test/java/org/apache/jdo/ tck20/test/java/org/apache/jdo/tck/ tck20/test/java/org/apache/jdo/tck/api/ tck20/test/java/org/apache/jdo/tck/api/instancecallbacks/ tck20/test/java/org/apache/jdo/tck/api/jdohelper/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/close/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/extent/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/flags/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/getobject/ tck20/test/java/org/apache/jdo/tck/api/persistencemanager/lifecycle/ tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/ tck20/test/java/org/apache/jdo/tck/enhancement/ tck20/test/java/org/apache/jdo/tck/extents/ tck20/test/java/org/apache/jdo/tck/lifecycle/ tck20/test/java/org/apache/jdo/tck/lifecycle/nontransactional/ tck20/test/java/org/apache/jdo/tck/models/ tck20/test/java/org/apache/jdo/tck/models/embedded/ tck20/test/java/org/apache/jdo/tck/models/fieldtypes/ tck20/test/java/org/apache/jdo/tck/models/inheritance/ tck20/test/java/org/apache/jdo/tck/pc/ tck20/test/java/org/apache/jdo/tck/pc/company/ tck20/test/java/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/java/org/apache/jdo/tck/pc/inheritance/ tck20/test/java/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/java/org/apache/jdo/tck/pc/lifecycle/ tck20/test/java/org/apache/jdo/tck/pc/mylib/ tck20/test/java/org/apache/jdo/tck/query/ tck20/test/java/org/apache/jdo/tck/query/operators/ tck20/test/java/org/apache/jdo/tck/transactions/ tck20/test/java/org/apache/jdo/tck/util/ tck20/test/jdo/ tck20/test/jdo/applicationidentity/ tck20/test/jdo/applicationidentity/org/ tck20/test/jdo/applicationidentity/org/apache/ tck20/test/jdo/applicationidentity/org/apache/jdo/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/jdo/datastoreidentity/ tck20/test/jdo/datastoreidentity/org/ tck20/test/jdo/datastoreidentity/org/apache/ tck20/test/jdo/datastoreidentity/org/apache/jdo/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/orm/ tck20/test/orm/applicationidentity/ tck20/test/orm/applicationidentity/org/ tck20/test/orm/applicationidentity/org/apache/ tck20/test/orm/applicationidentity/org/apache/jdo/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/company/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/orm/datastoreidentity/ tck20/test/orm/datastoreidentity/org/ tck20/test/orm/datastoreidentity/org/apache/ tck20/test/orm/datastoreidentity/org/apache/jdo/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/company/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/inheritance/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/ tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/mylib/ tck20/test/sql/ tck20/test/sql/derby/ To: jdo-commits@db.apache.org From: mcaisse@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheri= tance/FieldWithSameNameInSuperclass.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/models/inheritance/FieldWithSameNameInSuperclass.java?view= =3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/FieldWithSameNameInSuperclass.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/FieldWithSameNameInSuperclass.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,235 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +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; + +/** + *Title: Field With the Same Name as a Field in a Superclass + *
+ *Keywords: inheritance + *
+ *Assertion ID: A6.5-7. + *
+ *Assertion Description: +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 { + =20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A6.5-7 (FieldWithSameNameInSuperclass) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(FieldWithSameNameInSuperclass.class); + } + =20 + /** */ + public void test() { + pm =3D getPM(); + =20 + runTest(pm); + + pm.close(); + pm =3D null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction t =3D pm.currentTransaction(); + try { + t.setRestoreValues(true); + + t.begin(); + removeAllInstances(pm); // always start fresh with no instances + t.commit(); + t.begin(); + FieldSameName4 refa =3D new FieldSameName4(Constants.intA_V[1]= , Constants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Consta= nts.booleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.= shortG_V[1], Constants.intH_V[1]); + pm.makePersistent(refa); + Object objPtrA =3D pm.getObjectId (refa); + =20 + refa.setSecondObj(new FieldSameName4(Constants.intA_V[2], Cons= tants.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.bo= oleanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.shortG= _V[2], Constants.intH_V[2])); + TestParts.secondObj_V[1] =3D refa.getSecondObj(); + refa.setThirdObj(new FieldSameName4(Constants.intA_V[3], Const= ants.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.boo= leanD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG_= V[3], Constants.intH_V[3])); + TestParts.thirdObj_V[1] =3D refa.getThirdObj(); + pm.makePersistent(TestParts.thirdObj_V[1]); + Object objPtrB =3D pm.getObjectId(TestParts.thirdObj_V[1]); + refa.setFourthObj(new FieldSameName4(Constants.intA_V[4], Cons= tants.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.bo= oleanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.shortG= _V[4], Constants.intH_V[4])); + TestParts.fourthObj_V[1] =3D refa.getFourthObj(); + try { + t.commit(); + } catch(JDOException e) { + Object o =3D e.getFailedObject(); + String cname =3D o =3D=3D null ? "null" : o.getClass().get= Name(); + fail(ASSERTION_FAILED, + "Exception thrown, failed object class is " + cname += " exception is " + e); + } + + t.begin(); + FieldSameName4 a =3D null; + FieldSameName4 b =3D null; + =20 + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (FieldSameName4) pm.getObjectB= yId(objPtrB, true); + } + catch (JDOUserException e) { + // could not locate persistent object created in previous + // transaction + fail(ASSERTION_FAILED, + "JDOUserException " + e + " could not reference third= Obj."); + } + + try { // retrieve object created in previous transaction + a =3D (FieldSameName4) pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rCommit, 1, a.getDoubleB(), a.getIntB(), a.getShortF(), a.getThirdObj(), a.= getIntH()); + =20 + // verify referenced persistent object contains correct va= lues + b =3D a.getThirdObj(); + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterCommit, 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 previ= ously created object."); + } + =20 + // 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 =3D new FieldSameName4(Constants.intA_V[= 6], Constants.doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Cons= tants.booleanD_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constant= s=2EshortG_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]); + =20 + // create new objects and make persistent + FieldSameName4 c =3D new FieldSameName4(Constants.intA_V[8], C= onstants.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants= .booleanD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.sho= rtG_V[8], Constants.intH_V[8]); + FieldSameName4 d =3D new FieldSameName4(Constants.intA_V[9], C= onstants.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants= .booleanD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.sho= rtG_V[9], Constants.intH_V[9]); + c.setThirdObj(d); + c.setFourthObj(d); + TestParts.thirdObj_V[8] =3D d; + TestParts.fourthObj_V[8] =3D d; + pm.makePersistent(c); + =20 + // 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]); + =20 + t.rollback(); + =20 + // verify objects revert back to transient after rollback + checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRoll= back, 8, c.getDoubleB(), c.getIntB(), c.getShortF(), c.getThirdObj(), c.get= IntH()); + checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 8, c.getFloatE(), c.getSecondObj()); + checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 10, c.getIntA(), c.getCharC(), c.getBooleanD(), c.getShortG(), c.g= etFourthObj()); + =20 + t.begin(); + =20 + // verify rollback lost all persistent changes. + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (FieldSameName4) pm.getObjectB= yId(objPtrB, true); + } + catch (JDOUserException e) { + // could not locate persistent object created in previous = transaction + fail(ASSERTION_FAILED, + "JDOUserException " + e + " could not reference third= Obj."); + } + =20 + try { // retrieve object created in previous transaction + a =3D (FieldSameName4) pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rRollback, 1, a.getDoubleB(), a.getIntB(), a.getShortF(), a.getThirdObj(), = a=2EgetIntH()); + b =3D a.getThirdObj(); + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterRollback, 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 previ= ously created object."); + } + =20 + t.rollback(); + t =3D null; + } + finally { + if ((t !=3D null) && t.isActive()) + t.rollback(); + } + } + + void removeAllInstances(PersistenceManager pm) + { + Extent e =3D pm.getExtent(FieldSameName4.class, true); + Iterator i =3D e.iterator(); + while( i.hasNext() ){ + pm.deletePersistent(i.next()); + } =20 + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/i= nheritance/FieldWithSameNameInSuperclass.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheri= tance/NonPersistentFieldsAreNonPersistentInSubclasses.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/models/inheritance/NonPersistentFieldsAreNonPersistentInSubc= lasses.java?view=3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/NonPersistentFieldsAreNonPersistentInSubclasses.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/NonPersistentFieldsAreNonPersistentInSubclasses.java Mon Apr 4 12:41:23= 2005 @@ -0,0 +1,124 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +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; + +/** + *Title: Non-Persistent Fields Are Non-Persistent in Subclasses + *
+ *Keywords: inheritance + *
+ *Assertion ID: A6.5-6. + *
+ *Assertion Description: +Fields marked as non-persistent in persistence-capable classes +will be non-persistent in subclasses. + + */ + +public class NonPersistentFieldsAreNonPersistentInSubclasses extends TestP= arts { + =20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A6.5-6 (NonPersistentFieldsAreNonPersistentInSubclasses= ) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(NonPersistentFieldsAreNonPersistentInSubclasse= s=2Eclass); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTest(pm); + + pm.close(); + pm =3D null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction t =3D pm.currentTransaction(); + try { + t.setRestoreValues(true); + =20 + t.begin(); + removeAllInstances(pm); // always start fresh with no instances + t.commit(); + t.begin(); + // create new objects and make persistent + AllPersist4 c =3D new AllPersist4(Constants.intA_V[8], Constan= ts.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.boole= anD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[= 8], Constants.intH_V[8]); + AllPersist4 d =3D new AllPersist4(Constants.intA_V[9], Constan= ts.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.boole= anD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[= 9], Constants.intH_V[9]); + c.thirdObj =3D d; + c.fourthObj =3D d; + TestParts.thirdObj_V[8] =3D d; + TestParts.fourthObj_V[8] =3D d; + pm.makePersistent(c); + =20 + // change values of newly persistent object + c.intA =3D Constants.intA_V[10]; + c.charC =3D Constants.charC_V[10]; + c.booleanD =3D Constants.booleanD_V[10]; + c.shortG =3D Constants.shortG_V[10]; + c.fourthObj =3D null; + c.floatE =3D Constants.floatE_V[10]; + c.secondObj =3D null; + c.doubleB =3D Constants.doubleB_V[10]; + c.intB =3D Constants.intB_V[10]; + c.shortF =3D Constants.shortF_V[10]; + c.thirdObj =3D null; + c.intH =3D Constants.intH_V[10]; + =20 + t.rollback(); + t =3D null; + =20 + // verify objects revert back to transient after rollback + checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 10, c.intA, c.charC, c.booleanD, c.shortG, c.fourthObj); + } + finally { + if ((t !=3D null) && t.isActive()) + t.rollback(); + } + } + + void removeAllInstances(PersistenceManager pm) + { + AllPersist4 a =3D new AllPersist4(0, 0.0, 0, '0', false, 0.0f, (sh= ort)0, (short)0, 0); + pm.makePersistent(a); // guarantee the class is registered; this w= ill be removed + Extent e =3D pm.getExtent(AllPersist4.class, true); + Iterator i =3D e.iterator(); + while( i.hasNext() ){ + pm.deletePersistent(i.next()); + } =20 + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/i= nheritance/NonPersistentFieldsAreNonPersistentInSubclasses.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheri= tance/NonpersistentSuperClass.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/models/inheritance/NonpersistentSuperClass.java?view=3Dauto&= rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/NonpersistentSuperClass.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/NonpersistentSuperClass.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,224 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +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; + +/** + *Title: Non-persistent Super Class + *
+ *Keywords: inheritance + *
+ *Assertion ID: A6.5-1. + *
+ *Assertion Description: +A class might be persistence-capable even if its superclass is not persist= ence-capable. + + */ + +public class NonpersistentSuperClass extends TestParts { + =20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A6.5-1 (NonpersistentSuperClass) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(NonpersistentSuperClass.class); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTest(pm); + + pm.close(); + pm =3D null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction t =3D pm.currentTransaction(); + try { + t.setRestoreValues(true); + =20 + t.begin(); + removeAllInstances(pm); // always start fresh with no instances + t.commit(); + t.begin(); + TopNonPersistH refa =3D new TopNonPersistH(Constants.intA_V[1]= , Constants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Consta= nts.booleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.= shortG_V[1], Constants.intH_V[1]); + pm.makePersistent(refa); + Object objPtrA =3D pm.getObjectId(refa); + =20 + refa.secondObj =3D new TopNonPersistH(Constants.intA_V[2], Con= stants.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.b= ooleanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.short= G_V[2], Constants.intH_V[2]); + TestParts.secondObj_V[1] =3D refa.secondObj; + refa.thirdObj =3D new TopNonPersistH(Constants.intA_V[3], Cons= tants.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.bo= oleanD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG= _V[3], Constants.intH_V[3]); + TestParts.thirdObj_V[1] =3D refa.thirdObj; + pm.makePersistent(refa.thirdObj); + Object objPtrB =3D pm.getObjectId(refa.thirdObj); + refa.fourthObj =3D new TopNonPersistH(Constants.intA_V[4], Con= stants.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.b= ooleanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.short= G_V[4], Constants.intH_V[4]); + TestParts.fourthObj_V[1] =3D refa.fourthObj; + t.commit(); + + t.begin(); + TopNonPersistH a =3D null; + TopNonPersistH b =3D null; + =20 + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (TopNonPersistH)pm.getObjectBy= Id(objPtrB, true); + } + catch (JDOUserException e) { + // could not locate persistent object created in previous = transaction + fail(ASSERTION_FAILED, + "JDOUserException " + e + " could not reference third= Obj."); + } + =20 + try { // retrieve object created in previous transaction + a =3D (TopNonPersistH)pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rCommit, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH); + =20 + // verify referenced persistent object contains correct va= lues + b =3D a.thirdObj; + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterCommit, 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 previ= ously created object."); + } + =20 + // set in new values + a.intA =3D Constants.intA_V[5]; + a.charC =3D Constants.charC_V[5]; + a.booleanD =3D Constants.booleanD_V[5]; + a.shortG =3D Constants.shortG_V[5]; + a.fourthObj =3D new TopNonPersistH(Constants.intA_V[6], Consta= nts.doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Constants.bool= eanD_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constants.shortG_V= [6], Constants.intH_V[6]); + TestParts.fourthObj_V[5] =3D a.fourthObj; + a.floatE =3D Constants.floatE_V[5]; + a.secondObj =3D null; + a.doubleB =3D Constants.doubleB_V[5]; + a.intB =3D Constants.intB_V[5]; + a.shortF =3D Constants.shortF_V[5]; + a.thirdObj =3D null; + a.intH =3D Constants.intH_V[5]; + + b.intA =3D Constants.intA_V[7]; + b.charC =3D Constants.charC_V[7]; + b.booleanD =3D Constants.booleanD_V[7]; + b.shortG =3D Constants.shortG_V[7]; + b.fourthObj =3D null; + b.floatE =3D Constants.floatE_V[7]; + b.secondObj =3D null; + b.doubleB =3D Constants.doubleB_V[7]; + b.intB =3D Constants.intB_V[7]; + b.shortF =3D Constants.shortF_V[7]; + b.thirdObj =3D null; + b.intH =3D Constants.intH_V[7]; + =20 + // create new objects and make persistent + TopNonPersistH c =3D new TopNonPersistH(Constants.intA_V[8], C= onstants.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants= .booleanD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.sho= rtG_V[8], Constants.intH_V[8]); + TopNonPersistH d =3D new TopNonPersistH(Constants.intA_V[9], C= onstants.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants= .booleanD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.sho= rtG_V[9], Constants.intH_V[9]); + c.thirdObj =3D d; + c.fourthObj =3D d; + TestParts.thirdObj_V[8] =3D d; + TestParts.fourthObj_V[8] =3D d; + pm.makePersistent(c); + =20 + // change values of newly persistent object + c.intA =3D Constants.intA_V[10]; + c.charC =3D Constants.charC_V[10]; + c.booleanD =3D Constants.booleanD_V[10]; + c.shortG =3D Constants.shortG_V[10]; + c.fourthObj =3D null; + c.floatE =3D Constants.floatE_V[10]; + c.secondObj =3D null; + c.doubleB =3D Constants.doubleB_V[10]; + c.intB =3D Constants.intB_V[10]; + c.shortF =3D Constants.shortF_V[10]; + c.thirdObj =3D null; + c.intH =3D Constants.intH_V[10]; + =20 + t.rollback(); + =20 + // verify objects revert back to transient after rollback + checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRoll= back, 8, c.doubleB, c.intB, c.shortF, c.thirdObj, c.intH); + checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 8, c.floatE, c.secondObj); + checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 10, c.intA, c.charC, c.booleanD, c.shortG, c.fourthObj); + =20 + t.begin(); + =20 + // verify rollback lost all persistent changes. + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (TopNonPersistH)pm.getObjectBy= Id(objPtrB, true); + } + catch (JDOUserException e) { + // could not locate persistent object created in previous = transaction + fail(ASSERTION_FAILED, + "JDOUserException " + e + " could not reference third= Obj."); + } + =20 + try { // retrieve object created in previous transaction + a =3D (TopNonPersistH)pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rRollback, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH); + b =3D a.thirdObj; + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterRollback, 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 previ= ously created object."); + } + =20 + t.rollback(); + t =3D null; + } + finally { + if ((t !=3D null) && t.isActive()) + t.rollback(); + } + } + + void removeAllInstances(PersistenceManager pm) + { + Extent e =3D pm.getExtent(TopNonPersistH.class, true); + Iterator i =3D e.iterator(); + while( i.hasNext() ){ + pm.deletePersistent(i.next()); + } =20 + } +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/i= nheritance/NonpersistentSuperClass.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheri= tance/PersistenceCapableFlexibilityInInheritanceHierarchy.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/models/inheritance/PersistenceCapableFlexibilityInInheritanc= eHierarchy.java?view=3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/PersistenceCapableFlexibilityInInheritanceHierarchy.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/PersistenceCapableFlexibilityInInheritanceHierarchy.java Mon Apr 4 12:4= 1:23 2005 @@ -0,0 +1,227 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +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; + +/** + *Title: Persistence Capable Flexibility in Inheritance Hierarchy + *
+ *Keywords: inheritance + *
+ *Assertion ID: A6.5-3. + *
+ *Assertion Description: +Subclasses of such classes that are not persistence-capable, +but have a superclass that is persistence-capable might be persistence-cap= able. +That is, it is possible for classes in the inheritance hierarchy to be +alternately persistence-capable and not persistence-capable. + + */ + +public class PersistenceCapableFlexibilityInInheritanceHierarchy extends T= estParts { + =20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A6.5-3 (PersistenceCapableFlexibilityInInheritanceHiera= rchy) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(PersistenceCapableFlexibilityInInheritanceHier= archy.class); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTest(pm); + + pm.close(); + pm =3D null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction t =3D pm.currentTransaction(); + try { + t.setRestoreValues(true); + =20 + t.begin(); + removeAllInstances(pm); // always start fresh with no instances + t.commit(); + t.begin(); + TopPersistH refa =3D new TopPersistH(Constants.intA_V[1], Cons= tants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Constants.bo= oleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.shortG= _V[1], Constants.intH_V[1]); + pm.makePersistent(refa); + Object objPtrA =3D pm.getObjectId(refa); + =20 + refa.secondObj =3D new TopPersistH(Constants.intA_V[2], Consta= nts.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.bool= eanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.shortG_V= [2], Constants.intH_V[2]); + TestParts.secondObj_V[1] =3D refa.secondObj; + refa.thirdObj =3D new TopPersistH(Constants.intA_V[3], Constan= ts.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.boole= anD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG_V[= 3], Constants.intH_V[3]); + TestParts.thirdObj_V[1] =3D refa.thirdObj; + pm.makePersistent(refa.thirdObj); + Object objPtrB =3D pm.getObjectId(refa.thirdObj); + refa.fourthObj =3D new TopPersistH(Constants.intA_V[4], Consta= nts.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.bool= eanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.shortG_V= [4], Constants.intH_V[4]); + TestParts.fourthObj_V[1] =3D refa.fourthObj; + t.commit(); + + t.begin(); + TopPersistH a =3D null; + TopPersistH b =3D null; + =20 + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (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 third= Obj."); + } + =20 + try { // retrieve object created in previous transaction + a =3D (TopPersistH)pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rCommit, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH); + =20 + // verify referenced persistent object contains correct va= lues + b =3D a.thirdObj; + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterCommit, 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 previ= ously created object."); + } + =20 + // set in new values + a.intA =3D Constants.intA_V[5]; + a.charC =3D Constants.charC_V[5]; + a.booleanD =3D Constants.booleanD_V[5]; + a.shortG =3D Constants.shortG_V[5]; + a.fourthObj =3D new TopPersistH(Constants.intA_V[6], Constants= .doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Constants.boolean= D_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constants.shortG_V[6]= , Constants.intH_V[6]); + TestParts.fourthObj_V[5] =3D a.fourthObj; + a.floatE =3D Constants.floatE_V[5]; + a.secondObj =3D null; + a.doubleB =3D Constants.doubleB_V[5]; + a.intB =3D Constants.intB_V[5]; + a.shortF =3D Constants.shortF_V[5]; + a.thirdObj =3D null; + a.intH =3D Constants.intH_V[5]; + + b.intA =3D Constants.intA_V[7]; + b.charC =3D Constants.charC_V[7]; + b.booleanD =3D Constants.booleanD_V[7]; + b.shortG =3D Constants.shortG_V[7]; + b.fourthObj =3D null; + b.floatE =3D Constants.floatE_V[7]; + b.secondObj =3D null; + b.doubleB =3D Constants.doubleB_V[7]; + b.intB =3D Constants.intB_V[7]; + b.shortF =3D Constants.shortF_V[7]; + b.thirdObj =3D null; + b.intH =3D Constants.intH_V[7]; + =20 + // create new objects and make persistent + TopPersistH c =3D new TopPersistH(Constants.intA_V[8], Constan= ts.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.boole= anD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[= 8], Constants.intH_V[8]); + TopPersistH d =3D new TopPersistH(Constants.intA_V[9], Constan= ts.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.boole= anD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[= 9], Constants.intH_V[9]); + c.thirdObj =3D d; + c.fourthObj =3D d; + TestParts.thirdObj_V[8] =3D d; + TestParts.fourthObj_V[8] =3D d; + pm.makePersistent(c); + =20 + // change values of newly persistent object + c.intA =3D Constants.intA_V[10]; + c.charC =3D Constants.charC_V[10]; + c.booleanD =3D Constants.booleanD_V[10]; + c.shortG =3D Constants.shortG_V[10]; + c.fourthObj =3D null; + c.floatE =3D Constants.floatE_V[10]; + c.secondObj =3D null; + c.doubleB =3D Constants.doubleB_V[10]; + c.intB =3D Constants.intB_V[10]; + c.shortF =3D Constants.shortF_V[10]; + c.thirdObj =3D null; + c.intH =3D Constants.intH_V[10]; + =20 + t.rollback(); + =20 + // verify objects revert back to transient after rollback + checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRoll= back, 8, c.doubleB, c.intB, c.shortF, c.thirdObj, c.intH); + checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 8, c.floatE, c.secondObj); + checkNonpersistentAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 10, c.intA, c.charC, c.booleanD, c.shortG, c.fourthObj); + =20 + t.begin(); + =20 + // verify rollback lost all persistent changes. + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (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 third= Obj."); + } + =20 + try { // retrieve object created in previous transaction + a =3D (TopPersistH)pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rRollback, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH); + b =3D a.thirdObj; + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterRollback, 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 previ= ously created object."); + } + + t.rollback(); + t =3D null; + } + finally { + if ((t !=3D null) && t.isActive()) + t.rollback(); + } + } + + void removeAllInstances(PersistenceManager pm) + { + Extent e =3D pm.getExtent(TopNonPersistH.class, true); + Iterator i =3D e.iterator(); + while( i.hasNext() ){ + pm.deletePersistent(i.next()); + } =20 + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/i= nheritance/PersistenceCapableFlexibilityInInheritanceHierarchy.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheri= tance/PersistentFieldsArePersistentInSubClasses.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/models/inheritance/PersistentFieldsArePersistentInSubClasses= .java?view=3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/PersistentFieldsArePersistentInSubClasses.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/PersistentFieldsArePersistentInSubClasses.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,224 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +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; + +/** + *Title: Persistent Fields Are Persistent in SubClasses + *
+ *Keywords: inheritance + *
+ *Assertion ID: A6.5-4. + *
+ *Assertion Description: +Fields identified as persistent in persistence-capable classes +will be persistent in subclasses. + + */ + +public class PersistentFieldsArePersistentInSubClasses extends TestParts { + =20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A6.5-4 (PersistentFieldsArePersistentInSubClasses) fail= ed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(PersistentFieldsArePersistentInSubClasses.clas= s); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTest(pm); + + pm.close(); + pm =3D null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction t =3D pm.currentTransaction(); + try { + t.setRestoreValues(true); + =20 + t.begin(); + removeAllInstances(pm); // always start fresh with no instances + t.commit(); + t.begin(); + AllPersist4 refa =3D new AllPersist4(Constants.intA_V[1], Cons= tants.doubleB_V[1], Constants.intB_V[1], Constants.charC_V[1], Constants.bo= oleanD_V[1], Constants.floatE_V[1], Constants.shortF_V[1], Constants.shortG= _V[1], Constants.intH_V[1]); + pm.makePersistent(refa); + Object objPtrA =3D pm.getObjectId (refa); + =20 + refa.secondObj =3D new AllPersist4(Constants.intA_V[2], Consta= nts.doubleB_V[2], Constants.intB_V[2], Constants.charC_V[2], Constants.bool= eanD_V[2], Constants.floatE_V[2], Constants.shortF_V[2], Constants.shortG_V= [2], Constants.intH_V[2]); + TestParts.secondObj_V[1] =3D refa.secondObj; + refa.thirdObj =3D new AllPersist4(Constants.intA_V[3], Constan= ts.doubleB_V[3], Constants.intB_V[3], Constants.charC_V[3], Constants.boole= anD_V[3], Constants.floatE_V[3], Constants.shortF_V[3], Constants.shortG_V[= 3], Constants.intH_V[3]); + TestParts.thirdObj_V[1] =3D refa.thirdObj; + pm.makePersistent(refa.thirdObj); + Object objPtrB =3D pm.getObjectId (refa.thirdObj); + refa.fourthObj =3D new AllPersist4(Constants.intA_V[4], Consta= nts.doubleB_V[4], Constants.intB_V[4], Constants.charC_V[4], Constants.bool= eanD_V[4], Constants.floatE_V[4], Constants.shortF_V[4], Constants.shortG_V= [4], Constants.intH_V[4]); + TestParts.fourthObj_V[1] =3D refa.fourthObj; + t.commit(); + + t.begin(); + AllPersist4 a =3D null; + AllPersist4 b =3D null; + =20 + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (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 third= Obj."); + } + =20 + try { // retrieve object created in previous transaction + a =3D (AllPersist4)pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rCommit, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH); + =20 + // verify referenced persistent object contains correct va= lues + b =3D a.thirdObj; + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterCommit, 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 previ= ously created object."); + } + =20 + // set in new values + a.intA =3D Constants.intA_V[5]; + a.charC =3D Constants.charC_V[5]; + a.booleanD =3D Constants.booleanD_V[5]; + a.shortG =3D Constants.shortG_V[5]; + a.fourthObj =3D new AllPersist4(Constants.intA_V[6], Constants= .doubleB_V[6], Constants.intB_V[6], Constants.charC_V[6], Constants.boolean= D_V[6], Constants.floatE_V[6], Constants.shortF_V[6], Constants.shortG_V[6]= , Constants.intH_V[6]); + TestParts.fourthObj_V[5] =3D a.fourthObj; + a.floatE =3D Constants.floatE_V[5]; + a.secondObj =3D null; + a.doubleB =3D Constants.doubleB_V[5]; + a.intB =3D Constants.intB_V[5]; + a.shortF =3D Constants.shortF_V[5]; + a.thirdObj =3D null; + a.intH =3D Constants.intH_V[5]; + + b.intA =3D Constants.intA_V[7]; + b.charC =3D Constants.charC_V[7]; + b.booleanD =3D Constants.booleanD_V[7]; + b.shortG =3D Constants.shortG_V[7]; + b.fourthObj =3D null; + b.floatE =3D Constants.floatE_V[7]; + b.secondObj =3D null; + b.doubleB =3D Constants.doubleB_V[7]; + b.intB =3D Constants.intB_V[7]; + b.shortF =3D Constants.shortF_V[7]; + b.thirdObj =3D null; + b.intH =3D Constants.intH_V[7]; + =20 + // create new objects and make persistent + AllPersist4 c =3D new AllPersist4(Constants.intA_V[8], Constan= ts.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.boole= anD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[= 8], Constants.intH_V[8]); + AllPersist4 d =3D new AllPersist4(Constants.intA_V[9], Constan= ts.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.boole= anD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[= 9], Constants.intH_V[9]); + c.thirdObj =3D d; + c.fourthObj =3D d; + TestParts.thirdObj_V[8] =3D d; + TestParts.fourthObj_V[8] =3D d; + pm.makePersistent(c); + =20 + // change values of newly persistent object + c.intA =3D Constants.intA_V[10]; + c.charC =3D Constants.charC_V[10]; + c.booleanD =3D Constants.booleanD_V[10]; + c.shortG =3D Constants.shortG_V[10]; + c.fourthObj =3D null; + c.floatE =3D Constants.floatE_V[10]; + c.secondObj =3D null; + c.doubleB =3D Constants.doubleB_V[10]; + c.intB =3D Constants.intB_V[10]; + c.shortF =3D Constants.shortF_V[10]; + c.thirdObj =3D null; + c.intH =3D Constants.intH_V[10]; + =20 + t.rollback(); + =20 + // verify objects revert back to transient after rollback + checkPersistentAreCorrect(ASSERTION_FAILED, transientAfterRoll= back, 8, c.doubleB, c.intB, c.shortF, c.thirdObj, c.intH); + =20 + t.begin(); + =20 + // verify rollback lost all persistent changes. + try { // retrieve object created in previous transaction & st= ore in value array for later comparison + TestParts.thirdObj_V[1] =3D (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 third= Obj."); + } + =20 + try { // retrieve object created in previous transaction + a =3D (AllPersist4)pm.getObjectById(objPtrA, true); + checkPersistentAreCorrect(ASSERTION_FAILED, persistentAfte= rRollback, 1, a.doubleB, a.intB, a.shortF, a.thirdObj, a.intH); + b =3D a.thirdObj; + if(b !=3D null) { // if previous error caused b to be nul= l, then these tests cannot be performed. + checkPersistentAreCorrect(ASSERTION_FAILED, persistent= AfterRollback, 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 previ= ously created object."); + } + =20 + t.rollback(); + t =3D null; + } + finally { + if ((t !=3D null) && t.isActive()) + t.rollback(); + } + } + + void removeAllInstances(PersistenceManager pm) + { + AllPersist4 a =3D new AllPersist4(0, 0.0, 0, '0', false, 0.0f, (sh= ort)0, (short)0, 0); + pm.makePersistent(a); // guarantee the class is registered; this w= ill be removed + Extent e =3D pm.getExtent(AllPersist4.class, true); + Iterator i =3D e.iterator(); + while( i.hasNext() ){ + pm.deletePersistent(i.next()); + } =20 + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/i= nheritance/PersistentFieldsArePersistentInSubClasses.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheri= tance/TestParts.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/models/inheritance/TestParts.java?view=3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/TestParts.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/TestParts.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,125 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +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 Inher= itance 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 transactio= n=2E + * 2. A second transaction is started, the first persistent object retrie= ved and checking is done on + * its attribute values. + * 3. A rollback is performed and value comparisions are made on the tran= sient 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 { + =20 + // 0 1 2 3 4 5= 6 7 8 9 10 11 + static final Object[] secondObj_V =3D { null, null, null, null, null, = null, null, null, null, null, null, null}; + static final Object[] thirdObj_V =3D { null, null, null, null, null, nul= l, null, null, null, null, null, null}; + static final Object[] fourthObj_V =3D { null, null, null, null, null, nul= l, null, null, null, null, null, null}; + =20 + static String persistentAfterCommit =3D "Read object back after commit= ted to Database. "; + static String persistentAfterRollback =3D "Read object back after roll= back. "; + static String transientAfterRollback =3D "Object reverted to transient= after rollback. "; + =20 + /** */ + void checkPersistentAreCorrect(String assertion, String title, int ind= ex,=20 + double doubleB, int intB, short shortF,=20 + Object thirdObj, int intH) { + if(doubleB !=3D Constants.doubleB_V[index]) { + fail(assertion,=20 + title + "Persistent attribute doubleB is " + doubleB +=20 + ", it should be " + Constants.doubleB_V[index]); + } + if(intB !=3D Constants.intB_V[index]) { + fail(assertion,=20 + title + "Persistent attribute intB is " + intB +=20 + ", it should be " + Constants.intB_V[index]); + } + if(shortF !=3D Constants.shortF_V[index]) { + fail(assertion,=20 + title + "Persistent attribute shortF is " + shortF +=20 + ", it should be " + Constants.shortF_V[index]); + } + if(thirdObj !=3D TestParts.thirdObj_V[index]) { + fail(assertion,=20 + title + "Persistent attribute thirdObj is " + thirdObj +=20 + ", it should be " + TestParts.thirdObj_V[index]); + } + if(intH !=3D Constants.intH_V[index]) { + fail(assertion,=20 + title + "Persistent attribute intH is " + intH +=20 + ", it should be " + Constants.intH_V[index]); + } + } + + /** */ + void checkTransactionalAreCorrect(String assertion, String title, int = index,=20 + float floatE, Object secondObj) { + =20 + if(floatE !=3D Constants.floatE_V[index]) { + fail(assertion,=20 + title + "Transactional attribute floatE is " + floatE +=20 + ", it should be " + Constants.floatE_V[index]); + } + if(secondObj !=3D TestParts.secondObj_V[index]) { + fail(assertion,=20 + title + "Transactional attribute secondObj is " + secondO= bj +=20 + ", it should be " + TestParts.secondObj_V[index]); + } + } + =20 + /** */ + void checkNonpersistentAreCorrect(String assertion, String title, int = index,=20 + int intA, char charC, boolean boolea= nD,=20 + short shortG, Object fourthObj) { + if(intA !=3D Constants.intA_V[index]) { + fail(assertion,=20 + title + "In non-persistent class, attribute intA is " + i= ntA +=20 + ", it should be " + Constants.intA_V[index]); + } + if(charC !=3D Constants.charC_V[index]) { + fail(assertion,=20 + title + "In non-persistent class, attribute charC is " + = charC +=20 + ", it should be " + Constants.charC_V[index]); + } + if(booleanD !=3D Constants.booleanD_V[index]) { + fail(assertion,=20 + title + "In non-persistent class, attribute booleanD is "= + booleanD +=20 + ", it should be " + Constants.booleanD_V[index]); + } + if(shortG !=3D Constants.shortG_V[index]) { + fail(assertion,=20 + title + "In non-persistent class, attribute shortG is " += shortG +=20 + ", it should be " + Constants.shortG_V[index]); + } + if(fourthObj !=3D TestParts.fourthObj_V[index]) { + fail(assertion,=20 + title + "In non-persistent class, attribute fourthObj is = " + fourthObj +=20 + ", it should be " + TestParts.fourthObj_V[index]); + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/i= nheritance/TestParts.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheri= tance/TransactionalFieldsAreTransactionalInSubclasses.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/models/inheritance/TransactionalFieldsAreTransactionalInSubc= lasses.java?view=3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/TransactionalFieldsAreTransactionalInSubclasses.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/inheritan= ce/TransactionalFieldsAreTransactionalInSubclasses.java Mon Apr 4 12:41:23= 2005 @@ -0,0 +1,124 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +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; + +/** + *Title: Transactional Fields are Transactional in Subclasses + *
+ *Keywords: inheritance + *
+ *Assertion ID: A6.5-5. + *
+ *Assertion Description: +Fields marked as transactional in persistence-capable classes +will be transactional in subclasses. + + */ + +public class TransactionalFieldsAreTransactionalInSubclasses extends TestP= arts { + =20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A6.5-5 (TransactionalFieldsAreTransactionalInSubclasses= ) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(TransactionalFieldsAreTransactionalInSubclasse= s=2Eclass); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTest(pm); + + pm.close(); + pm =3D null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction t =3D pm.currentTransaction(); + try { + t.setRestoreValues(true); + =20 + t.begin(); + removeAllInstances(pm); // always start fresh with no instances + t.commit(); + t.begin(); + // create new objects and make persistent + AllPersist4 c =3D new AllPersist4(Constants.intA_V[8], Constan= ts.doubleB_V[8], Constants.intB_V[8], Constants.charC_V[8], Constants.boole= anD_V[8], Constants.floatE_V[8], Constants.shortF_V[8], Constants.shortG_V[= 8], Constants.intH_V[8]); + AllPersist4 d =3D new AllPersist4(Constants.intA_V[9], Constan= ts.doubleB_V[9], Constants.intB_V[9], Constants.charC_V[9], Constants.boole= anD_V[9], Constants.floatE_V[9], Constants.shortF_V[9], Constants.shortG_V[= 9], Constants.intH_V[9]); + c.thirdObj =3D d; + c.fourthObj =3D d; + TestParts.thirdObj_V[8] =3D d; + TestParts.fourthObj_V[8] =3D d; + pm.makePersistent(c); + =20 + // change values of newly persistent object + c.intA =3D Constants.intA_V[10]; + c.charC =3D Constants.charC_V[10]; + c.booleanD =3D Constants.booleanD_V[10]; + c.shortG =3D Constants.shortG_V[10]; + c.fourthObj =3D null; + c.floatE =3D Constants.floatE_V[10]; + c.secondObj =3D d; + c.doubleB =3D Constants.doubleB_V[10]; + c.intB =3D Constants.intB_V[10]; + c.shortF =3D Constants.shortF_V[10]; + c.thirdObj =3D null; + c.intH =3D Constants.intH_V[10]; + =20 + t.rollback(); + t =3D null; + + // verify objects revert back to transient after rollback + checkTransactionalAreCorrect(ASSERTION_FAILED, transientAfterR= ollback, 8, c.floatE, c.secondObj); + } + finally { + if ((t !=3D null) && t.isActive()) + t.rollback(); + } =20 + } + + void removeAllInstances(PersistenceManager pm) + { + AllPersist4 a =3D new AllPersist4(0, 0.0, 0, '0', false, 0.0f, (sh= ort)0, (short)0, 0); + pm.makePersistent(a); // guarantee the class is registered; this w= ill be removed + Extent e =3D pm.getExtent(AllPersist4.class, true); + Iterator i =3D e.iterator(); + while( i.hasNext() ){ + pm.deletePersistent(i.next()); + } =20 + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/i= nheritance/TransactionalFieldsAreTransactionalInSubclasses.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Ad= dress.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/pc/company/Address.java?view=3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Addre= ss.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Addre= ss.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,281 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +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=20 + 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 Address 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,=20 + String state, String zipcode, String country) + { + this.addrid =3D addrid; + this.street =3D street; + this.city =3D city; + this.state =3D state; + this.zipcode =3D zipcode; + this.country =3D country; + } + + /** + * Get the addrid associated with this object. + * @return the addrid. + */ + public long getAddrid() { + return addrid; + } + + /**=20 + * 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 =3D 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 =3D city; + } + =20 + /** + * 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 =3D 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 =3D 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 =3D country; + } + + /**=20 + * Returns true 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.=20 + * @return true if all the fields are deep equal; + * false otherwise. =20 + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance.=20 + */ + public boolean deepCompareFields(DeepEquality other,=20 + EqualityHelper helper) { + Address otherAddress =3D (Address)other; + return (addrid =3D=3D 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); + } + =20 + /**=20 + * 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.=20 + * @param o The Object to be compared.=20 + * @return a negative integer, zero, or a positive integer as this=20 + * object is less than, equal to, or greater than the specified object= .=20 + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object.=20 + */ + public int compareTo(Object o) { + return compareTo((Address)o); + } + + /**=20 + * 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. =20 + * @param other The Address object to be compared.=20 + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Address + * object.=20 + */ + public int compareTo(Address other) { + long otherId =3D other.addrid; + return (addrid < otherId ? -1 : (addrid =3D=3D otherId ? 0 : 1)); + } + =20 + /**=20 + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise.=20 + */ + public boolean equals(Object obj) { + if (obj instanceof Address) { + return compareTo((Address)obj) =3D=3D 0; + } + return false; + } + =20 + /** + * Returns a hash code value for the object.=20 + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)addrid; + } + =20 + /** + * This class is used to represent the application identifier=20 + * for the Address class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This is the identifier field for Address and must + * correspond in type and name to the field in + * Address.=20 + */ + public long addrid; + =20 + /** The required public, no-arg constructor. */ + public Oid() + { + addrid =3D 0; + } + + /** + * A constructor to initialize the identifier field. + * @param addrid the id of the Adress. + */ + public Oid(long addrid) { + this.addrid =3D addrid; + } + =20 + public Oid(String s) { addrid =3D Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": "= + addrid;} + + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj=3D=3Dnull || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o =3D (Oid) obj; + if( this.addrid !=3D o.addrid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) addrid ); + } + =20 + 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 =3D (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/compa= ny/Address.java ---------------------------------------------------------------------------= --- svn:executable =3D * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Co= mpany.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/= apache/jdo/tck/pc/company/Company.java?view=3Dauto&rev=3D160090 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Compa= ny.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/company/Compa= ny.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,292 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +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=20 + implements Serializable, Comparable, DeepEquality { + + private long companyid; + private String name; + private Date founded; + private Address address; + private transient Set departments =3D new HashSet(); // element type i= s Department + + /** This is the JDO-required no-args constructor */ + protected Company() {} + + /**=20 + * Initialize the Company 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 =3D companyid; + this.name =3D name; + this.founded =3D founded; + this.address =3D 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 =3D 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 =3D founded; + } + + /** + * Get the address of the company. + * @return The primary address of the company. + */ + public Address getAddress() { + return address; + } + =20 + /** + * Set the primary address for the company. + * @param address The address to set for the company. + */ + public void setAddress(Address address) { + this.address =3D address; + } + + /** + * Get the departments contained in the company. + * @return An unmodifiable Set that contains all the + * Departments of the company. + */ + public Set getDepartments() { + return Collections.unmodifiableSet(departments); + } + + /** + * Add a Department instance to the company. + * @param dept The Department instance to add. + */ + public void addDepartment(Department dept) { + departments.add(dept); + } + + /** + * Remove a Department instance from the company. + * @param dept The Department instance to remove. + */ + public void removeDepartment(Department dept) { + departments.remove(dept); + } + + /** + * Initialize the set of Departments in the company to th= e=20 + * parameter.=20 + * @param departments The set of Departments for the + * company.=20 + */ + public void setDepartments(Set departments) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.departments =3D=20 + (departments !=3D null) ? new HashSet(departments) : null; + } + =20 + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + departments =3D new HashSet(); + } + + /**=20 + * Returns true 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.=20 + * @return true if all the fields are deep equal; + * false otherwise. =20 + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance.=20 + */ + public boolean deepCompareFields(DeepEquality other,=20 + EqualityHelper helper) { + Company otherCompany =3D (Company)other; + return (companyid =3D=3D otherCompany.companyid) && + helper.equals(name, otherCompany.name) && + helper.equals(founded, otherCompany.founded) && + helper.deepEquals(address, otherCompany.address) && + helper.deepEquals(departments, otherCompany.departments); + } + =20 + /**=20 + * 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.=20 + * @param o The Object to be compared.=20 + * @return a negative integer, zero, or a positive integer as this=20 + * object is less than, equal to, or greater than the specified object= .=20 + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object.=20 + */ + public int compareTo(Object o) { + return compareTo((Company)o); + } + + /**=20 + * 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. =20 + * @param other The Company object to be compared.=20 + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Company + * object.=20 + */ + public int compareTo(Company other) { + long otherId =3D other.companyid; + return (companyid < otherId ? -1 : (companyid =3D=3D otherId ? 0 := 1)); + } + =20 + /**=20 + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise.=20 + */ + public boolean equals(Object obj) { + if (obj instanceof Company) { + return compareTo((Company)obj) =3D=3D 0; + } + return false; + } + =20 + /** + * Returns a hash code value for the object.=20 + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)companyid; + } + =20 + /** + * The class to be used as the application identifier + * for the Company class. It consists of both the company=20 + * 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 Company 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 =3D companyid; + } + =20 + public Oid(String s) { companyid =3D Long.parseLong(justTheId(s));= } + + public String toString() { return this.getClass().getName() + ": "= + companyid;} + + =20 + /** */ + public boolean equals(Object obj) { + if (obj=3D=3Dnull || !this.getClass().equals(obj.getClass()))=20 + return false; + Oid o =3D (Oid) obj; + if (this.companyid !=3D o.companyid)=20 + return false; + return true; + } + + /** */ + public int hashCode() { + return (int)companyid; + } + =20 + 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 =3D (Oid) obj; + if( companyid < other.companyid ) return -1; + if( companyid > other.companyid ) return 1; + return 0; + } + =20 + } + +} + Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/pc/compa= ny/Company.java ---------------------------------------------------------------------------= --- svn:executable =3D *