Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 81045 invoked from network); 19 Mar 2005 04:59:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Mar 2005 04:59:18 -0000 Received: (qmail 81665 invoked by uid 500); 19 Mar 2005 04:59:18 -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 Delivered-To: moderator for jdo-commits@db.apache.org Received: (qmail 74641 invoked by uid 99); 19 Mar 2005 00:54:00 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Message-ID: <20050319005355.24334.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: Sat, 19 Mar 2005 00:53:55 -0000 Subject: svn commit: r158175 [4/4] - in incubator/jdo/trunk/api11: ./ src/ src/dtd/ src/dtd/javax/ src/dtd/javax/jdo/ src/java/ src/java/javax/ src/java/javax/jdo/ src/java/javax/jdo/spi/ test/ test/java/ test/java/javax/ test/java/javax/jdo/ test/java/javax/jdo/pc/ test/java/javax/jdo/spi/ test/java/javax/jdo/util/ xdocs/ To: jdo-commits@db.apache.org From: mbo@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/api11/src/java/javax/jdo/spi/StateManager.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/src/java/javax= /jdo/spi/StateManager.java?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/src/java/javax/jdo/spi/StateManager.java (add= ed) +++ incubator/jdo/trunk/api11/src/java/javax/jdo/spi/StateManager.java Fri = Mar 18 16:53:48 2005 @@ -0,0 +1,462 @@ +/* + * 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. + */ + +package javax.jdo.spi; + +import javax.jdo.PersistenceManager; + +/** This interface is the point of contact between managed instances of + * PersistenceCapable classes and the JDO implementation. It= contains + * the methods used by PersistenceCapable instances to delega= te behavior to=20 + * the JDO implementation. + *

Each managed PersistenceCapable instance contains a refe= rence to a + * StateManager. A StateManager might manage on= e or multiple instances of + * PersistenceCapable instances, at the choice of the impleme= ntation. + * + * @author Craig Russell + * @version 1.0 + * + */ +public interface StateManager { + =20 + /** The owning StateManager uses this method to supply th= e=20 + * value of the flags to the PersistenceCapable instance. + * @param pc the calling PersistenceCapable instance + * @return the value of jdoFlags to be stored in the PersistenceCapable instance + */ + byte replacingFlags(PersistenceCapable pc); + + /** Replace the current value of jdoStateManager. + *

+ * This method is called by the PersistenceCapable whenev= er + * jdoReplaceStateManager is called and there is already + * an owning StateManager. This is a security precaution + * to ensure that the owning StateManager is the only + * source of any change to its reference in the PersistenceCapab= le. + * @return the new value for the jdoStateManager + * @param pc the calling PersistenceCapable instance + * @param sm the proposed new value for the jdoStateManager + */=20 + StateManager replacingStateManager (PersistenceCapable pc, StateManage= r sm); + =20 + /** Tests whether this object is dirty. + * + * Instances that have been modified, deleted, or newly=20 + * made persistent in the current transaction return true. + * + *

Transient nontransactional instances return false. + *

+ * @see PersistenceCapable#jdoMakeDirty(String fieldName) + * @param pc the calling PersistenceCapable instance + * @return true if this instance has been modified in the= current transaction. + */ + boolean isDirty(PersistenceCapable pc); + + /** Tests whether this object is transactional. + * + * Instances that respect transaction boundaries return true. These instances + * include transient instances made transactional as a result of being= the + * target of a makeTransactional method call; newly made = persistent or deleted + * persistent instances; persistent instances read in data store + * transactions; and persistent instances modified in optimistic trans= actions. + * + *

Transient nontransactional instances return false. + *

+ * @param pc the calling PersistenceCapable instance + * @return true if this instance is transactional. + */ + boolean isTransactional(PersistenceCapable pc); + + /** Tests whether this object is persistent. + * + * Instances whose state is stored in the data store return true= . + * + *

Transient instances return false. + *

+ * @see PersistenceManager#makePersistent(Object pc) + * @param pc the calling PersistenceCapable instance + * @return true if this instance is persistent. + */ + boolean isPersistent(PersistenceCapable pc); + + /** Tests whether this object has been newly made persistent. + * + * Instances that have been made persistent in the current transaction=20 + * return true. + * + *

Transient instances return false. + *

+ * @see PersistenceManager#makePersistent(Object pc) + * @param pc the calling PersistenceCapable instance + * @return true if this instance was made persistent + * in the current transaction. + */ + boolean isNew(PersistenceCapable pc); + + /** Tests whether this object has been deleted. + * + * Instances that have been deleted in the current transaction return = true. + * + *

Transient instances return false. + *

+ * @see PersistenceManager#deletePersistent(Object pc) + * @param pc the calling PersistenceCapable instance + * @return true if this instance was deleted + * in the current transaction. + */ + boolean isDeleted(PersistenceCapable pc); + =20 + /** Return the PersistenceManager that owns this instance. + * @param pc the calling PersistenceCapable instance + * @return the PersistenceManager that owns this instance + */ + PersistenceManager getPersistenceManager (PersistenceCapable pc); + =20 + /** Mark the associated PersistenceCapable field dirty. + *

The StateManager will make a copy of the field + * so it can be restored if needed later, and then mark + * the field as modified in the current transaction. + * @param pc the calling PersistenceCapable instance + * @param fieldName the name of the field + */ =20 + void makeDirty (PersistenceCapable pc, String fieldName); + =20 + /** Return the object representing the JDO identity=20 + * of the calling instance. If the JDO identity is being changed in + * the current transaction, this method returns the identity as of + * the beginning of the transaction. + * @param pc the calling PersistenceCapable instance + * @return the object representing the JDO identity of the calling ins= tance + */ =20 + Object getObjectId (PersistenceCapable pc); + + /** Return the object representing the JDO identity=20 + * of the calling instance. If the JDO identity is being changed in + * the current transaction, this method returns the current identity as + * changed in the transaction. + * @param pc the calling PersistenceCapable instance + * @return the object representing the JDO identity of the calling ins= tance + */ =20 + Object getTransactionalObjectId (PersistenceCapable pc); + + /** Return true if the field is cached in the calling + * instance. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @return whether the field is cached in the calling instance + */ =20 + boolean isLoaded (PersistenceCapable pc, int field); + =20 + /** Guarantee that the serializable transactional and persistent fields + * are loaded into the instance. This method is called by the generat= ed + * jdoPreSerialize method prior to serialization of the + * instance. + * @param pc the calling PersistenceCapable instance + */ =20 + void preSerialize (PersistenceCapable pc); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + boolean getBooleanField (PersistenceCapable pc, int field, boolean cur= rentValue); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + char getCharField (PersistenceCapable pc, int field, char currentValue= ); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + byte getByteField (PersistenceCapable pc, int field, byte currentValue= ); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + short getShortField (PersistenceCapable pc, int field, short currentVa= lue); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + int getIntField (PersistenceCapable pc, int field, int currentValue); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + long getLongField (PersistenceCapable pc, int field, long currentValue= ); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + float getFloatField (PersistenceCapable pc, int field, float currentVa= lue); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + double getDoubleField (PersistenceCapable pc, int field, double curren= tValue); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + String getStringField (PersistenceCapable pc, int field, String curren= tValue); + =20 + /** Return the value for the field. + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + * @return the new value for the field + */ =20 + Object getObjectField (PersistenceCapable pc, int field, Object curren= tValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setBooleanField (PersistenceCapable pc, int field, boolean curren= tValue, boolean newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setCharField (PersistenceCapable pc, int field, char currentValue= , char newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setByteField (PersistenceCapable pc, int field, byte currentValue= , byte newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setShortField (PersistenceCapable pc, int field, short currentVal= ue, short newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setIntField (PersistenceCapable pc, int field, int currentValue, = int newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setLongField (PersistenceCapable pc, int field, long currentValue= , long newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setFloatField (PersistenceCapable pc, int field, float currentVal= ue, float newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setDoubleField (PersistenceCapable pc, int field, double currentV= alue, double newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setStringField (PersistenceCapable pc, int field, String currentV= alue, String newValue); + + /** Mark the field as modified by the user. + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @param currentValue the current value of the field + * @param newValue the proposed new value of the field */ =20 + void setObjectField (PersistenceCapable pc, int field, Object currentV= alue, Object newValue); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedBooleanField (PersistenceCapable pc, int field, boolean c= urrentValue); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedCharField (PersistenceCapable pc, int field, char current= Value); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedByteField (PersistenceCapable pc, int field, byte current= Value); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedShortField (PersistenceCapable pc, int field, short curre= ntValue); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedIntField (PersistenceCapable pc, int field, int currentVa= lue); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedLongField (PersistenceCapable pc, int field, long current= Value); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedFloatField (PersistenceCapable pc, int field, float curre= ntValue); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedDoubleField (PersistenceCapable pc, int field, double cur= rentValue); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedStringField (PersistenceCapable pc, int field, String cur= rentValue); + + /** The value of the field requested to be provided to the State= Manager + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @param currentValue the current value of the field + */ =20 + void providedObjectField (PersistenceCapable pc, int field, Object cur= rentValue); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number + * @return the new value for the field + */ =20 + boolean replacingBooleanField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + char replacingCharField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + byte replacingByteField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + short replacingShortField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + int replacingIntField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + long replacingLongField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + float replacingFloatField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + double replacingDoubleField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + String replacingStringField (PersistenceCapable pc, int field); + + /** The replacing value of the field in the calling instance + * @param pc the calling PersistenceCapable instance + * @param field the field number=20 + * @return the new value for the field + */ =20 + Object replacingObjectField (PersistenceCapable pc, int field); + +} + Added: incubator/jdo/trunk/api11/src/java/javax/jdo/spi/package.html URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/src/java/javax= /jdo/spi/package.html?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/src/java/javax/jdo/spi/package.html (added) +++ incubator/jdo/trunk/api11/src/java/javax/jdo/spi/package.html Fri Mar 1= 8 16:53:48 2005 @@ -0,0 +1,47 @@ + + + + +JDO Service Provider Interface package + + + + +

This package contains the interfaces and classes used by JDO implementa= tions.=20 +

JDO defines interfaces and classes to be used by application programmer= s=20 +when using classes whose instances are to be stored in persistent storage=20 +(persistence-capable classes), and specifies the contracts between=20 +suppliers of persistence-capable classes and the=20 +runtime environment (which is part of the JDO implementation). +

The PersistenceCapable interface is implemented by all classes +whose instances are to be made persistent. The implementation might be +done by a combination of techniques, as determined by the JDO vendor: +

    +
  • Pre-processing .java files +
  • Post-processing .class files +
  • Generating .java or .class files directly from an abstraction +
The StateManager interface is the implementation's contact point with +the PersistenceCapable instances. It defines methods that are called by=20 +the PersistenceCapable instances to implement the required PersistenceCapa= ble +behavior for persistent and transactional instances. +

The JDOPermission class is used to manage security controls on JDO impl= ementations. +

The RegisterClassEvent class and RegisterClassListener interface are us= ed +by JDO implementations that need access to metadata of PersistenceCapable = classes. +

The JDOImplHelper class contains helper methods for JDO implementations. + + Added: incubator/jdo/trunk/api11/test/java/javax/jdo/JDOHelperTest.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/java= x/jdo/JDOHelperTest.java?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/test/java/javax/jdo/JDOHelperTest.java (added) +++ incubator/jdo/trunk/api11/test/java/javax/jdo/JDOHelperTest.java Fri Ma= r 18 16:53:48 2005 @@ -0,0 +1,142 @@ +/* + * 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. + */ + +package javax.jdo; + +import java.util.Properties; + +import javax.jdo.pc.PCPoint; +import javax.jdo.util.AbstractTest; +import javax.jdo.util.BatchTestRunner; + +/** + * Tests class javax.jdo.JDOHelper. + *

+ * TBD: implementation of testMakeDirty,=20 + * TBD: testing interrogative methods for persistent instances + * TBD: getPMF for valid PMF class + */ +public class JDOHelperTest extends AbstractTest { + =20 + /** */ + public static void main(String args[]) { + BatchTestRunner.run(JDOHelperTest.class); + } + + /** */ + public void testGetPM() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.getPersistenceManager(p) !=3D null) { + fail("JDOHelper.getPersistenceManager should return null pm fo= r non-persistent instance"); + } + + // TBD: test for persistent instance + } + + /** */ + public void testMakeDirty() { + // TBD: test JDOHelper.makeDirty(pc, fieldName); + } + + /** */ + public void testGetObjectId() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.getObjectId(p) !=3D null) { + fail("JDOHelper.getObjectId should return null ObjectId for no= n-persistent instance"); + } + + // TBD test JDOHelper.getObjectId(pc) for persistent instance + } + + /** */ + public void testGetTransactionObjectId() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.getObjectId(p) !=3D null) { + fail("JDOHelper.getTransactionalObjectId should return null Ob= jectId for non-persistent instance"); + } + + // TBD test JDOHelper.getTransactionalObjectId(pc) for persistent = instance + } + + /** */ + public void testIsDirty() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.isDirty(p)) { + fail("JDOHelper.isDirty should return false for non-persistent= instance"); + } + + // TBD test JDOHelper.isDirty(pc) for persistent instance + } + + /** */ + public void testIsTransactional() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.isTransactional(p)) { + fail("JDOHelper.isTransactional should return false for non-pe= rsistent instance"); + } + + // TBD test JDOHelper.isTransactional(pc) for persistent instance + } + + /** */ + public void testIsPersistent() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.isPersistent(p)) { + fail("JDOHelper.isPersistent should return false for non-persi= stent instance"); + } + + // TBD test JDOHelper.isPersistent(pc) for persistent instance + } + + /** */ + public void testIsNew() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.isNew(p)) { + fail("JDOHelper.isNew should return false for non-persistent i= nstance"); + } + + // TBD test JDOHelper.isNew(pc) for persistent instance + } + + + /** */ + public void testIsDeleted() { + PCPoint p =3D new PCPoint(1, new Integer(1)); + if (JDOHelper.isDeleted(p)) { + fail("JDOHelper.isDeleted should return false for non-persiste= nt instance"); + } + + // TBD test JDOHelper.isDeleted(pc) for persistent instance + } + + /** */ + public void testGetPMF() { + // test missing property javax.jdo.PersistenceManagerFactoryClass + PersistenceManagerFactory pmf =3D null; + try { + pmf =3D JDOHelper.getPersistenceManagerFactory(new Properties(= )); + fail("Missing property PersistenceManagerFactoryClass should r= esult in JDOFatalUserException "); + } + catch (JDOFatalUserException ex) { + if (verbose) + println("Caught expected exception " + ex); + } + + // TBD: valid PMF class + } + +} + Added: incubator/jdo/trunk/api11/test/java/javax/jdo/pc/PCPoint.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/java= x/jdo/pc/PCPoint.java?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/test/java/javax/jdo/pc/PCPoint.java (added) +++ incubator/jdo/trunk/api11/test/java/javax/jdo/pc/PCPoint.java Fri Mar 1= 8 16:53:48 2005 @@ -0,0 +1,448 @@ +/* + * 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. + */ + +package javax.jdo.pc; + +import java.io.*; +import java.util.*; +import javax.jdo.PersistenceManager; +import javax.jdo.spi.*; + +import javax.jdo.spi.PersistenceCapable; + +/** + * This is a hand-enhanced version of a simple class with two fields. The + * enhanced code assumes datastore identity. + * + * @author Michael Bouschen + */ +public class PCPoint=20 + implements PersistenceCapable +{ + public int x; + public Integer y; + + // JDO generated fields + protected transient StateManager jdoStateManager; + protected transient byte jdoFlags; + private static final int jdoInheritedFieldCount =3D 0; + private static final String jdoFieldNames[] =3D { "x", "y" }; + private static final Class jdoFieldTypes[];=20 + private static final byte jdoFieldFlags[] =3D {=20 + (byte)(PersistenceCapable.CHECK_READ + PersistenceCapable.CHECK_WR= ITE +=20 + PersistenceCapable.SERIALIZABLE),=20 + (byte)(PersistenceCapable.CHECK_READ + PersistenceCapable.CHECK_WR= ITE +=20 + PersistenceCapable.SERIALIZABLE),=20 + };=20 + private static final Class jdoPersistenceCapableSuperclass;=20 + + static=20 + { + jdoFieldTypes =3D (new Class[] { + Integer.TYPE, sunjdo$classForName$("java.lang.Integer") + }); + jdoPersistenceCapableSuperclass =3D null; + JDOImplHelper.registerClass( + sunjdo$classForName$("javax.jdo.pc.PCPoint"),=20 + jdoFieldNames, jdoFieldTypes, jdoFieldFlags,=20 + jdoPersistenceCapableSuperclass, new PCPoint()); + } + + /** JDO required no-args constructor. */ + public PCPoint() { } + + /** Constructor. */ + public PCPoint(int x, Integer y) { + jdoSetx(this, x); + jdoSety(this, y); + } + + /** */ + public void setX(int x) { + jdoSetx(this, x); + } + + /** */ + public int getX() { + return jdoGetx(this); + } + + /** */ + public void setY(Integer y) { + jdoSety(this, y); + } + + /** */ + public Integer getY() { + return jdoGety(this); + } + + /** */ + public boolean equals(Object o) { + if (o =3D=3D null || !(o instanceof PCPoint)) + return false; + PCPoint other =3D (PCPoint)o; + if (jdoGetx(this) !=3D jdoGetx(other)) + return false; + if (jdoGety(this) =3D=3D null) + return jdoGety(other) =3D=3D null; + if (jdoGety(other) =3D=3D null) + return jdoGety(this) =3D=3D null; + else + return jdoGety(this).intValue() =3D=3D jdoGety(other).intValue= (); + } + + /** */ + public int hashCode() { + int code =3D getX(); + if (getY() !=3D null) { + code +=3D getY().intValue(); + } + return code; + } + =20 + /** */ + public String toString() { + return "PCPoint(x: " + getX() + ", y: " + getY() + ")"; + } + =20 + + // Generated methods in least-derived PersistenceCapable class + + public final boolean jdoIsPersistent() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.isPersistent(this); + else + return false; + } + + public final boolean jdoIsTransactional() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.isTransactional(this); + else + return false; + } + + public final boolean jdoIsNew() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.isNew(this); + else + return false; + } + + public final boolean jdoIsDirty() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.isDirty(this); + else + return false; + } + + public final boolean jdoIsDeleted() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.isDeleted(this); + else + return false; + } + + public final void jdoMakeDirty(String s) { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + statemanager.makeDirty(this, s); + } + + public final PersistenceManager jdoGetPersistenceManager() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.getPersistenceManager(this); + else + return null; + } + + public final Object jdoGetObjectId() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.getObjectId(this); + else + return null; + } + + public final Object jdoGetTransactionalObjectId() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + return statemanager.getTransactionalObjectId(this); + else + return null; + } + + public final synchronized void jdoReplaceStateManager( + StateManager statemanager) { + StateManager statemanager1 =3D jdoStateManager; + if (statemanager1 !=3D null) { + jdoStateManager =3D statemanager1.replacingStateManager( + this, statemanager); + return; + }=20 + else { + JDOImplHelper.checkAuthorizedStateManager(statemanager); + jdoStateManager =3D statemanager; + jdoFlags =3D PersistenceCapable.LOAD_REQUIRED; + return; + } + } + =20 + public final void jdoReplaceFlags() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + jdoFlags =3D statemanager.replacingFlags(this); + } + + public final void jdoReplaceFields(int fields[]) { + if (fields =3D=3D null) + throw new IllegalArgumentException("fields is null"); + int i =3D fields.length; + for(int j =3D 0; j < i; j++) + jdoReplaceField(fields[j]); + + } + + public final void jdoProvideFields(int fields[]) { + if (fields =3D=3D null) + throw new IllegalArgumentException("fields is null"); + int i =3D fields.length; + for(int j =3D 0; j < i; j++) + jdoProvideField(fields[j]); + + } + + protected final void jdoPreSerialize() { + StateManager statemanager =3D jdoStateManager; + if (statemanager !=3D null) + statemanager.preSerialize(this); + } + + // Generated methods in PersistenceCapable root classes and all classes + // that declare objectid-class in xml metadata: + + public void jdoCopyKeyFieldsToObjectId( + PersistenceCapable.ObjectIdFieldSupplier objectidfieldsupplier,=20 + Object obj) { } + + public void jdoCopyKeyFieldsToObjectId(Object obj) { + } + =20 + public void jdoCopyKeyFieldsFromObjectId( + PersistenceCapable.ObjectIdFieldConsumer objectidfieldconsumer,=20 + Object obj) { } + + protected void jdoCopyKeyFieldsFromObjectId(Object obj) { + } + + public Object jdoNewObjectIdInstance() { + return null; + } + + public Object jdoNewObjectIdInstance(String s) { + return null; + } + =20 + // Generated methods in all PersistenceCapable classes + + public PersistenceCapable jdoNewInstance(StateManager statemanager) { + PCPoint pcpoint =3D new PCPoint(); + pcpoint.jdoFlags =3D PersistenceCapable.LOAD_REQUIRED; + pcpoint.jdoStateManager =3D statemanager; + return pcpoint; + } + + public PersistenceCapable jdoNewInstance( + StateManager statemanager, Object obj) { + PCPoint pcpoint =3D new PCPoint(); + pcpoint.jdoCopyKeyFieldsFromObjectId(obj); + pcpoint.jdoFlags =3D PersistenceCapable.LOAD_REQUIRED; + pcpoint.jdoStateManager =3D statemanager; + return pcpoint; + } + + protected static int jdoGetManagedFieldCount() { + return 2; + } + + public static final int jdoGetx(PCPoint pcpoint) { + if (pcpoint.jdoFlags <=3D PersistenceCapable.READ_WRITE_OK) + return pcpoint.x; + StateManager statemanager =3D pcpoint.jdoStateManager; + if (statemanager =3D=3D null) + return pcpoint.x; + if (statemanager.isLoaded(pcpoint, jdoInheritedFieldCount + 0)) + return pcpoint.x; + else + return statemanager.getIntField( + pcpoint, jdoInheritedFieldCount + 0, pcpoint.x); + } + + public static final Integer jdoGety(PCPoint pcpoint) { + if (pcpoint.jdoFlags <=3D PersistenceCapable.READ_WRITE_OK) + return pcpoint.y; + StateManager statemanager =3D pcpoint.jdoStateManager; + if (statemanager =3D=3D null) + return pcpoint.y; + if (statemanager.isLoaded(pcpoint, jdoInheritedFieldCount + 1)) + return pcpoint.y; + else + return (Integer)statemanager.getObjectField( + pcpoint, jdoInheritedFieldCount + 1, pcpoint.y); + } + + public static final void jdoSetx(PCPoint pcpoint, int i) { + if (pcpoint.jdoFlags =3D=3D PersistenceCapable.READ_WRITE_OK) { + pcpoint.x =3D i; + return; + } + StateManager statemanager =3D pcpoint.jdoStateManager; + if (statemanager =3D=3D null) { + pcpoint.x =3D i; + return; + }=20 + else { + statemanager.setIntField( + pcpoint, jdoInheritedFieldCount + 0, pcpoint.x, i); + return; + } + } + + public static final void jdoSety(PCPoint pcpoint, Integer integer) { + if (pcpoint.jdoFlags =3D=3D PersistenceCapable.READ_WRITE_OK) { + pcpoint.y =3D integer; + return; + } + StateManager statemanager =3D pcpoint.jdoStateManager; + if (statemanager =3D=3D null) { + pcpoint.y =3D integer; + return; + }=20 + else { + statemanager.setObjectField(pcpoint, jdoInheritedFieldCount + = 1, pcpoint.y, integer); + return; + } + } + + public void jdoReplaceField(int field) { + StateManager statemanager =3D jdoStateManager; + switch(field - jdoInheritedFieldCount) { + case 0:=20 + if (statemanager =3D=3D null) { + throw new IllegalStateException("jdoStateManager is null"); + }=20 + else { + x =3D statemanager.replacingIntField(this, field); + return; + } + case 1: + if (statemanager =3D=3D null) { + throw new IllegalStateException("jdoStateManager is null"); + }=20 + else { + y =3D (Integer)statemanager.replacingObjectField(this, fie= ld); + return; + } + } + throw new IllegalArgumentException("field number out of range"); + } + + public void jdoProvideField(int field) { + StateManager statemanager =3D jdoStateManager; + switch(field - jdoInheritedFieldCount) { + case 0: + if (statemanager =3D=3D null) { + throw new IllegalStateException("jdoStateManager is null"); + }=20 + else { + statemanager.providedIntField(this, field, x); + return; + } + case 1:=20 + if (statemanager =3D=3D null) { + throw new IllegalStateException("jdoStateManager is null"); + }=20 + else { + statemanager.providedObjectField(this, field, y); + return; + } + } + throw new IllegalArgumentException("field number out of range"); + } + + public void jdoCopyFields(Object obj, int fieldNumbers[]) { + if (jdoStateManager =3D=3D null) + throw new IllegalStateException("jdoStateManager is null"); + if (!(obj instanceof PCPoint)) + throw new ClassCastException(obj.getClass().getName()); + if (fieldNumbers =3D=3D null) + throw new IllegalArgumentException("fieldNumber is null"); + PCPoint pcpoint =3D (PCPoint)obj; + if (pcpoint.jdoStateManager !=3D jdoStateManager) + throw new IllegalArgumentException("wrong jdoStateManager"); + int i =3D fieldNumbers.length; + for(int j =3D 0; j < i; j++) + jdoCopyField(pcpoint, fieldNumbers[j]); + } + + protected final void jdoCopyField(PCPoint pcpoint, int fieldNumber) + { + switch(fieldNumber - jdoInheritedFieldCount) { + case 0:=20 + if (pcpoint =3D=3D null) { + throw new IllegalArgumentException("pcpoint is null"); + }=20 + else { + x =3D pcpoint.x; + return; + } + case 1:=20 + if (pcpoint =3D=3D null) { + throw new IllegalArgumentException("pcpoint is null"); + }=20 + else { + y =3D pcpoint.y; + return; + } + } + throw new IllegalArgumentException("field number out of range"); + } + + private void writeObject(java.io.ObjectOutputStream out) + throws java.io.IOException { + jdoPreSerialize(); + out.defaultWriteObject(); + } + =20 + protected static final Class sunjdo$classForName$(String s) { + try { + return Class.forName(s); + } + catch(ClassNotFoundException ex) { + throw new NoClassDefFoundError(ex.getMessage()); + } + } + =20 + =20 + +} Added: incubator/jdo/trunk/api11/test/java/javax/jdo/spi/JDOImplHelperTest.= java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/java= x/jdo/spi/JDOImplHelperTest.java?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/test/java/javax/jdo/spi/JDOImplHelperTest.jav= a (added) +++ incubator/jdo/trunk/api11/test/java/javax/jdo/spi/JDOImplHelperTest.jav= a Fri Mar 18 16:53:48 2005 @@ -0,0 +1,202 @@ +/* + * 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. + */ + +package javax.jdo.spi; + +import java.util.Collection; + +import javax.jdo.pc.PCPoint; +import javax.jdo.util.AbstractTest; +import javax.jdo.util.BatchTestRunner; + +/**=20 + * Tests class javax.jdo.spi.JDOImplHelper. + *

+ * Missing: testNewInstance + testNewObjectIdInstance + * Missing: tests for JDOImplHelper methods: copyKeyFieldsToObjectId and=20 + * copyKeyFieldsFromObjectId. + */ +public class JDOImplHelperTest extends AbstractTest { + =20 + /** */ + private RegisterClassEvent event; + + /** */ + public static void main(String args[]) { + BatchTestRunner.run(JDOImplHelperTest.class); + } + + /** */ + public void testGetFieldNames() { + JDOImplHelper implHelper =3D JDOImplHelper.getInstance(); + String[] fieldNames =3D implHelper.getFieldNames(PCPoint.class); + if (fieldNames =3D=3D null) { + fail("array of field names is null"); + } + if (fieldNames.length !=3D 2) { + fail("Unexpected length of fieldNames; expected 2, got " +=20 + fieldNames.length); + } + if (!fieldNames[0].equals("x")) { + fail("Unexpected field; expected x, got " + fieldNames[0]); + } + if (!fieldNames[1].equals("y")) { + fail("Unexpected field; expected y, got " + fieldNames[1]); + } + } + + /** */ + public void testGetFieldTypes() { + JDOImplHelper implHelper =3D JDOImplHelper.getInstance(); + Class[] fieldTypes =3D implHelper.getFieldTypes(PCPoint.class); + if (fieldTypes =3D=3D null) { + fail("array of field types is null"); + } + if (fieldTypes.length !=3D 2) { + fail("Unexpected length of fieldTypes; expected 2, got " +=20 + fieldTypes.length); + } + if (fieldTypes[0] !=3D int.class) { + fail("Unexpected field type; expected int, got " +=20 + fieldTypes[0]); + } + if (fieldTypes[1] !=3D Integer.class) { + fail("Unexpected field type; expected Integer, got " +=20 + fieldTypes[1]); + } + } + =20 + /** */ + public void testGetFieldFlags() { + byte expected =3D (byte) (PersistenceCapable.CHECK_READ + + PersistenceCapable.CHECK_WRITE + PersistenceCapable.SERIALIZAB= LE); + =20 + JDOImplHelper implHelper =3D JDOImplHelper.getInstance(); + byte[] fieldFlags =3D implHelper.getFieldFlags(PCPoint.class); + if (fieldFlags =3D=3D null) { + fail("array of field flags is null"); + } + if (fieldFlags.length !=3D 2) { + fail("Unexpected length of fieldFlags; expected 2, got " +=20 + fieldFlags.length); + } + if (fieldFlags[0] !=3D expected) { + fail("Unexpected field flag; expected " + expected +=20 + ", got " + fieldFlags[0]); + } + if (fieldFlags[1] !=3D expected) { + fail("Unexpected field flag; expected " + expected +=20 + ", got " + fieldFlags[1]); + } + } + + /** */ + public void testGetPCSuperclass() { + JDOImplHelper implHelper =3D JDOImplHelper.getInstance(); + Class pcSuper =3D=20 + implHelper.getPersistenceCapableSuperclass(PCPoint.class); + if (pcSuper !=3D null) { + fail("Wrong pc superclass of PCPoint; expected null, got " +=20 + pcSuper); + } + } + + /** */ + public void testNewInstance() { + // TBD: test JDOImplHelper.newInstance(pcClass, sm) and + // JDOImplHelper.newInstance(pcClass, sm, oid) =20 + } + + /** */ + public void testNewObjectIdInstance() { + // TBD: test JDOImplHelper.newObjectIdInstance(pcClass) + } + =20 + /** */ + public void testClassRegistration() { + JDOImplHelper implHelper =3D JDOImplHelper.getInstance(); + // make sure PCClass is loaded + PCPoint p =3D new PCPoint(1, new Integer(1)); + + Collection registeredClasses =3D implHelper.getRegisteredClasses(); + // test whether PCPoint is registered + if (!registeredClasses.contains(PCPoint.class)) { + fail("Missing registration of pc class PCPoint"); + } + + // Save registered meta data for restoring + String[] fieldNames =3D implHelper.getFieldNames(PCPoint.class); + Class[] fieldTypes =3D implHelper.getFieldTypes(PCPoint.class); + byte[] fieldFlags =3D implHelper.getFieldFlags(PCPoint.class); + Class pcSuperclass =3D implHelper.getPersistenceCapableSuperclass(= PCPoint.class); + =20 + // test unregisterClass with null parameter + try { + implHelper.unregisterClass(null); + fail("Missing exception when calling unregisterClass(null)"); + } + catch (NullPointerException ex) { + // expected exception =3D> OK + } + + // test unregister PCPoint class + implHelper.unregisterClass(PCPoint.class); + registeredClasses =3D implHelper.getRegisteredClasses(); + if (registeredClasses.contains(PCPoint.class)) { + fail("PCPoint still registered"); + } + + // register PCPoint again + JDOImplHelper.registerClass(PCPoint.class, fieldNames, fieldTypes,=20 + fieldFlags, pcSuperclass, new PCPoint(= )); + } + + /** */ + public void testClassListenerRegistration() { + JDOImplHelper implHelper =3D JDOImplHelper.getInstance(); + + // add listener and check event + event =3D null; + RegisterClassListener listener =3D new SimpleListener(); + implHelper.addRegisterClassListener(listener); + JDOImplHelper.registerClass(JDOImplHelperTest.class, new String[0]= ,=20 + new Class[0], new byte[0], null, null); + if (event =3D=3D null) { + fail("Missing event ");=20 + } + + // remove listener and check event + event =3D null; + implHelper.removeRegisterClassListener(listener); + JDOImplHelper.registerClass(JDOImplHelperTest.class, new String[0]= ,=20 + new Class[0], new byte[0], null, null); + if (event !=3D null) { + fail("Unexpected event " + event); + } + } + + /** */ + class SimpleListener implements RegisterClassListener { + + /** */ + public void registerClass(RegisterClassEvent event) { + JDOImplHelperTest.this.event =3D event; + } + =20 + } + =20 +} + Added: incubator/jdo/trunk/api11/test/java/javax/jdo/util/AbstractTest.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/java= x/jdo/util/AbstractTest.java?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/test/java/javax/jdo/util/AbstractTest.java (a= dded) +++ incubator/jdo/trunk/api11/test/java/javax/jdo/util/AbstractTest.java Fr= i Mar 18 16:53:48 2005 @@ -0,0 +1,47 @@ +/* + * 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. + */ + +package javax.jdo.util; + +import java.io.PrintStream; + +import junit.framework.TestCase; + +/** */ +public class AbstractTest extends TestCase { + + /** */ + protected static PrintStream out =3D System.out; + =20 + /** If true, print extra messages. */ + protected boolean verbose; + + /** + * Construct and initialize from properties. + */ + protected AbstractTest() { + super(null); + verbose =3D Boolean.getBoolean("verbose"); + } + =20 + /** + */ + protected void println(String s) { + if (verbose)=20 + out.println(s); + } +} + Added: incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchResultPrinte= r=2Ejava URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/java= x/jdo/util/BatchResultPrinter.java?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/test/java/javax/jdo/util/BatchResultPrinter.j= ava (added) +++ incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchResultPrinter.j= ava Fri Mar 18 16:53:48 2005 @@ -0,0 +1,103 @@ +/* + * 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. + */ + +package javax.jdo.util; + +import java.io.PrintStream; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestResult; +import junit.textui.ResultPrinter; + +/** + * Default result printer implementation for running tests in batch mode. + *=20 + * @author Michael Bouschen + */ +public class BatchResultPrinter + extends ResultPrinter +{ + /** */ + public BatchResultPrinter(PrintStream writer) { + super(writer); + } + =20 + /** Called in case of a test error. */ + public void addError(Test test, Throwable t) { + getWriter().print(" ERROR"); + } + =20 + /** Called in case of a test failure. */=20 + public void addFailure(Test test, AssertionFailedError t) { + getWriter().print(" FAILURE"); + } + =20 + /** Called when a test case is finished. */ + public void endTest(Test test) { + getWriter().println(); + } + =20 + /** Called when a test case is started. */ + public void startTest(Test test) { + String testName; + if (test instanceof TestCase) { + testName =3D getClassBaseName(test) + "." + ((TestCase)test).g= etName(); + } + else { + testName =3D test.toString(); + } + getWriter().print("RUN " + testName); + } + =20 + /** */ + protected void printHeader(long runTime) { + getWriter().println("Time: "+elapsedTimeAsString(runTime)); + } + =20 + /** */ + protected void printFooter(TestResult result) { + if (result.wasSuccessful()) { + getWriter().print("OK"); + getWriter().println (" (" + result.runCount() + " test" + (res= ult.runCount() =3D=3D 1 ? "": "s") + ")"); + =20 + } else { + getWriter().println("FAILURES!!!"); + getWriter().println("Tests run: "+result.runCount()+=20 + ", Failures: "+result.failureCount()+ + ", Errors: "+result.errorCount()); + } + } + =20 + // helper method + =20 + /**=20 + * @return Name of the class of the given object without package prefix + */ + private String getClassBaseName(Object obj) { + if (obj =3D=3D null) return null; + String className =3D obj.getClass().getName(); + int index =3D className.lastIndexOf('.'); + if (index !=3D -1) { + className =3D className.substring(index + 1); + } + return className; + } + =20 +} + + Added: incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchTestRunner.j= ava URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/java= x/jdo/util/BatchTestRunner.java?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/test/java/javax/jdo/util/BatchTestRunner.java= (added) +++ incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchTestRunner.java= Fri Mar 18 16:53:48 2005 @@ -0,0 +1,163 @@ +/* + * 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. + */ + +package javax.jdo.util; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.io.PrintStream; + +import junit.framework.Test; +import junit.framework.TestResult; +import junit.framework.TestSuite; +import junit.textui.ResultPrinter; +import junit.textui.TestRunner; + +/** + * TestRunner class for running a single test or a test suite in batch + * mode. The format of the test output is specified by the result printer + * class. The main method sets an exit code according to the test result: + *

    + *
  • 0: success + *
  • 1: failure, the test shows an unexpected behavior + *
  • 2: exception, the test throws an unhandled excption=20 + *
+ *=20 + * @author Michael Bouschen + */ +public class BatchTestRunner + extends TestRunner +{ + /** Name of the system property to specify the result printer class. */ + public static final String RESULTPRINTER_PROPERTY =3D "ResultPrinterCl= ass";=20 + =20 + /** Default of the system property ResultPrinterClass. */ + public static final String RESULTPRINTER_DEFAULT =3D BatchResultPrinte= r=2Eclass.getName(); + =20 + /**=20 + * Constructor.=20 + * It creates a result printer instance based on the system property + * and delegates to the constructor taking a result printer argument.=20 + */ + public BatchTestRunner() { + super(); + setPrinter(getResultPrinter()); + } + =20 + /** =20 + * Constructor. USes teh specified resultPrinter to format the test re= sult. + */ + public BatchTestRunner(ResultPrinter resultPrinter) { + super(resultPrinter); + } + + /** Runs all test methods from the specified class. */ + public static void run(Class clazz) { + run(new TestSuite(clazz)); + } + =20 + /** Runs the specified test. */ + public static TestResult run(Test test) { + return new BatchTestRunner().doRun(test); + } + + /** Runs the specified test and waits until the user types RETURN. */ + public static void runAndWait(Test suite) { + new BatchTestRunner().doRun(suite, true); + } + + /**=20 + * Runs in batch mode and sets an exit code. If the specified String + * array includes a single fully qualified class name, this test class + * is executed. If it is empty it runs the TestListSuite. + */ + public static void main(String args[]) { + BatchTestRunner aTestRunner=3D new BatchTestRunner(); + try { + /* + if ((args =3D=3D null) || args.length =3D=3D 0) + args =3D new String[] { TestListSuite.class.getName() }; + */ + TestResult r =3D aTestRunner.start(args); + if (!r.wasSuccessful())=20 + System.exit(FAILURE_EXIT); + System.exit(SUCCESS_EXIT); + } catch(Exception e) { + System.err.println(e.getMessage()); + System.exit(EXCEPTION_EXIT); + } + } + =20 + /** Returns a result printer instance. n instance of tCheck the system= property */ + protected ResultPrinter getResultPrinter() { + String className =3D System.getProperty(RESULTPRINTER_PROPERTY); + if (className !=3D null) { + className =3D className.trim(); + if (className.length() !=3D 0) { + String msg =3D null; + try { + // get class instance + Class clazz =3D Class.forName(className); + // constructor taking PrintStream arg + Constructor ctor =3D clazz.getConstructor( + new Class[] { PrintStream.class } ); + // create instance + return (ResultPrinter)ctor.newInstance( + new Object[] { System.out }); + } + catch (ClassNotFoundException ex) { + // specified ResultPrinter class not=20 + msg =3D "Cannot find specified result printer class " = +=20 + className + "."; + } + catch (NoSuchMethodException ex) { + msg =3D "Class " + className +=20 + " does not provide constructor taking a PrintStrea= m=2E"; + } + catch (InstantiationException ex) { + msg =3D "Class " + className + " is abstract."; + } + catch (IllegalAccessException ex) { + msg =3D "Constructor taking a PrintStream of class " +=20 + className + " is not accessible."; + } + catch (InvocationTargetException ex) { + msg =3D "Constructor call results in exception " + ex = + "."; + } + + // ResultPrinter class specified, but not avaiable + System.out.println(msg); + ResultPrinter printer =3D getDefaultResultPrinter(); + System.out.println("Using default result printer of class = " +=20 + printer.getClass().getName()); + } + } + =20 + // ResultPrinter class not specified =3D> use default + return getDefaultResultPrinter(); + } + + /**=20 + * Returns an instance of the default result printer class + * BatchResultPrinter. + */ + protected ResultPrinter getDefaultResultPrinter() { + return new BatchResultPrinter(System.out); + } + =20 + +} + Added: incubator/jdo/trunk/api11/xdocs/index.xml URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/xdocs/index.xm= l?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/xdocs/index.xml (added) +++ incubator/jdo/trunk/api11/xdocs/index.xml Fri Mar 18 16:53:48 2005 @@ -0,0 +1,27 @@ + + + + + + JDO API + Michael Bouschen + + + + +
+

The Java Data Objects (JDO) API is a standard interface-based=20 +Java model abstraction of persistence, developed as=20 +Java Specification=20 +Request 12 under the auspices of the +Java Community Process. +

+

+This project implements the public interfaces, helper classes and exceptio= ns=20 +as specified in the JDO specification. They are indented to be shared by a= ll=20 +JDO implementations.=20 +

+
+ + +
Added: incubator/jdo/trunk/api11/xdocs/navigation.xml URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/xdocs/navigati= on.xml?view=3Dauto&rev=3D158175 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api11/xdocs/navigation.xml (added) +++ incubator/jdo/trunk/api11/xdocs/navigation.xml Fri Mar 18 16:53:48 2005 @@ -0,0 +1,12 @@ + + + + JDO API + + + + + + + +