Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 66961 invoked from network); 28 Mar 2005 18:32:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Mar 2005 18:32:40 -0000 Received: (qmail 72580 invoked by uid 500); 28 Mar 2005 18:32:40 -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 72567 invoked by uid 99); 28 Mar 2005 18:32:40 -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, 28 Mar 2005 10:32:38 -0800 Received: (qmail 63478 invoked by uid 65534); 28 Mar 2005 18:25:17 -0000 Message-ID: <20050328182517.63476.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, 28 Mar 2005 18:25:17 -0000 Subject: svn commit: r159273 [5/5] - in incubator/jdo/trunk/api20: ./ src/java/ src/java/javax/ src/java/javax/jdo/ src/java/javax/jdo/datastore/ src/java/javax/jdo/identity/ src/java/javax/jdo/listener/ src/java/javax/jdo/spi/ test/ test/java/ test/java/javax/ test/java/javax/jdo/ test/java/javax/jdo/identity/ test/java/javax/jdo/listener/ To: jdo-commits@db.apache.org From: clr@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/api20/src/java/javax/jdo/spi/StateManager.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax= /jdo/spi/StateManager.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/src/java/javax/jdo/spi/StateManager.java (add= ed) +++ incubator/jdo/trunk/api20/src/java/javax/jdo/spi/StateManager.java Mon = Mar 28 10:25:05 2005 @@ -0,0 +1,516 @@ +/* + * 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.BitSet; + +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. + * + * @version 2.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 the object representing the version=20 + * of the calling instance. + * @param pc the calling PersistenceCapable instance + * @return the object representing the version of the calling instance + * @since 2.0 + */ =20 + Object getVersion (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); + + /** The replacing value of the object id in the calling instance. + * @param pc the calling PersistenceCapable instance + * @param oid the current value of the oid + * @return the new value for the oid + * @since 2.0 + */ + Object replacingObjectId (PersistenceCapable pc, Object oid); + =20 + /** The replacing value of the version in the calling instance. + * @param pc the calling PersistenceCapable instance + * @param version the current value of the version + * @return the new value for the version + * @since 2.0 + */ + Object replacingVersion (PersistenceCapable pc, Object version); + + /** The provided value of the loaded field list in the calling instanc= e=2E + * @param pc the calling PersistenceCapable instance + * @param loaded the current value of the loaded field list + * @since 2.0 + */ + void providedLoadedFieldList (PersistenceCapable pc, BitSet loaded); + + /** The replacing value of the loaded field list in the calling instan= ce. + * @param pc the calling PersistenceCapable instance + * @param loaded the current value of the loaded field list + * @return the replacement value for the loaded field list + * @since 2.0 + */ + BitSet replacingLoadedFieldList (PersistenceCapable pc, BitSet loaded); + + /** The provided value of the modified field list in the calling insta= nce. + * @param pc the calling PersistenceCapable instance + * @param modified the current value of the modified field list + * @since 2.0 + */ + void providedModifiedFieldList (PersistenceCapable pc, BitSet modified= ); + + /** The replacing value of the modified field list in the calling inst= ance. + * @param pc the calling PersistenceCapable instance + * @param modified the current value of the modified field list + * @return the replacement value for the modified field list + * @since 2.0 + */ + BitSet replacingModifiedFieldList (PersistenceCapable pc, BitSet modif= ied); +} + Added: incubator/jdo/trunk/api20/src/java/javax/jdo/spi/package.html URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax= /jdo/spi/package.html?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/src/java/javax/jdo/spi/package.html (added) +++ incubator/jdo/trunk/api20/src/java/javax/jdo/spi/package.html Mon Mar 2= 8 10:25:05 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/api20/test/java/javax/jdo/JDOHelperTest.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/JDOHelperTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/JDOHelperTest.java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java Mon Ma= r 28 10:25:05 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/api20/test/java/javax/jdo/identity/ByteIdentityT= est.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/ByteIdentityTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/ByteIdentityTest= .java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ByteIdentityTest= .java Mon Mar 28 10:25:05 2005 @@ -0,0 +1,100 @@ +/* + * 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. + */ + +/* + * ByteIdentityTest.java + * + */ + +package javax.jdo.identity; + +import javax.jdo.util.BatchTestRunner; + +/** + * + */ +public class ByteIdentityTest extends SingleFieldIdentityTest { + =20 + /** Creates a new instance of ByteIdentityTest */ + public ByteIdentityTest() { + } + =20 + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BatchTestRunner.run(ByteIdentityTest.class); + } + =20 + public void testConstructor() { + ByteIdentity c1 =3D new ByteIdentity(Object.class, (byte)1); + ByteIdentity c2 =3D new ByteIdentity(Object.class, (byte)1); + ByteIdentity c3 =3D new ByteIdentity(Object.class, (byte)2); + assertEquals("Equal ByteIdentity instances compare not equal.", c1= , c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testByteConstructor() { + ByteIdentity c1 =3D new ByteIdentity(Object.class, (byte)1); + ByteIdentity c2 =3D new ByteIdentity(Object.class, new Byte((byte)= 1)); + ByteIdentity c3 =3D new ByteIdentity(Object.class, new Byte((byte)= 2)); + assertEquals ("Equal ByteIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testIntConstructor() { + ByteIdentity c1 =3D new ByteIdentity(Object.class, (byte)1); + ByteIdentity c2 =3D new ByteIdentity(Object.class, 1); + ByteIdentity c3 =3D new ByteIdentity(Object.class, 2); + assertEquals ("Equal ByteIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testStringConstructor() { + ByteIdentity c1 =3D new ByteIdentity(Object.class, (byte)1); + ByteIdentity c2 =3D new ByteIdentity(Object.class, "1"); + ByteIdentity c3 =3D new ByteIdentity(Object.class, "2"); + assertEquals ("Equal ByteIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testIllegalStringConstructor() { + try { + ByteIdentity c1 =3D new ByteIdentity(Object.class, "b"); + } catch (IllegalArgumentException iae) { + return; // good + } + fail ("No exception caught for illegal String."); + } + =20 + public void testSerialized() { + ByteIdentity c1 =3D new ByteIdentity(Object.class, (byte)1); + ByteIdentity c2 =3D new ByteIdentity(Object.class, "1"); + ByteIdentity c3 =3D new ByteIdentity(Object.class, "2"); + Object[] scis =3D writeReadSerialized(new Object[] {c1, c2, c3}); + Object sc1 =3D scis[0]; + Object sc2 =3D scis[1]; + Object sc3 =3D scis[2]; + assertEquals ("Equal ByteIdentity instances compare not equal.", c= 1, sc1); + assertEquals ("Equal ByteIdentity instances compare not equal.", c= 2, sc2); + assertEquals ("Equal ByteIdentity instances compare not equal.", s= c1, c2); + assertEquals ("Equal ByteIdentity instances compare not equal.", s= c2, c1); + assertFalse ("Not equal ByteIdentity instances compare equal.", c1= .equals(sc3)); + assertFalse ("Not equal ByteIdentity instances compare equal.", sc= 1=2Eequals(c3)); + assertFalse ("Not equal ByteIdentity instances compare equal.", sc= 1=2Eequals(sc3)); + assertFalse ("Not equal ByteIdentity instances compare equal.", sc= 3=2Eequals(sc1)); + } +} Added: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityT= est.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/CharIdentityTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/CharIdentityTest= .java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest= .java Mon Mar 28 10:25:05 2005 @@ -0,0 +1,110 @@ +/* + * 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. + */ + +/* + * CharIdentityTest.java + * + */ + +package javax.jdo.identity; + +import javax.jdo.util.BatchTestRunner; + +/** + * + * @author clr + */ +public class CharIdentityTest extends SingleFieldIdentityTest { + =20 + /** Creates a new instance of CharIdentityTest */ + public CharIdentityTest() { + } + =20 + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BatchTestRunner.run(CharIdentityTest.class); + } + =20 + public void testConstructor() { + CharIdentity c1 =3D new CharIdentity(Object.class, 'a'); + CharIdentity c2 =3D new CharIdentity(Object.class, 'a'); + CharIdentity c3 =3D new CharIdentity(Object.class, 'b'); + assertEquals("Equal CharIdentity instances compare not equal.", c1= , c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testIntConstructor() { + CharIdentity c1 =3D new CharIdentity(Object.class, 'a'); + CharIdentity c2 =3D new CharIdentity(Object.class, 97); + CharIdentity c3 =3D new CharIdentity(Object.class, 98); + assertEquals ("Equal CharIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testStringConstructor() { + CharIdentity c1 =3D new CharIdentity(Object.class, 'a'); + CharIdentity c2 =3D new CharIdentity(Object.class, "a"); + CharIdentity c3 =3D new CharIdentity(Object.class, "b"); + assertEquals ("Equal CharIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testStringConstructorTooLong() { + try { + CharIdentity c1 =3D new CharIdentity(Object.class, "ab"); + } catch (IllegalArgumentException iae) { + return; // good + } + fail ("No exception caught for String too long."); + } + =20 + public void testStringConstructorTooShort() { + try { + CharIdentity c1 =3D new CharIdentity(Object.class, ""); + } catch (IllegalArgumentException iae) { + return; // good + } + fail ("No exception caught for String too short."); + } + =20 + public void testCharacterConstructor() { + CharIdentity c1 =3D new CharIdentity(Object.class, 'a'); + CharIdentity c2 =3D new CharIdentity(Object.class, new Character('= a')); + CharIdentity c3 =3D new CharIdentity(Object.class, new Character('= b')); + assertEquals ("Equal CharIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testSerialized() { + CharIdentity c1 =3D new CharIdentity(Object.class, 'a'); + CharIdentity c2 =3D new CharIdentity(Object.class, "a"); + CharIdentity c3 =3D new CharIdentity(Object.class, "b"); + Object[] scis =3D writeReadSerialized(new Object[] {c1, c2, c3}); + Object sc1 =3D scis[0]; + Object sc2 =3D scis[1]; + Object sc3 =3D scis[2]; + assertEquals ("Equal CharIdentity instances compare not equal.", c= 1, sc1); + assertEquals ("Equal CharIdentity instances compare not equal.", c= 2, sc2); + assertEquals ("Equal CharIdentity instances compare not equal.", s= c1, c2); + assertEquals ("Equal CharIdentity instances compare not equal.", s= c2, c1); + assertFalse ("Not equal CharIdentity instances compare equal.", c1= .equals(sc3)); + assertFalse ("Not equal CharIdentity instances compare equal.", sc= 1=2Eequals(c3)); + assertFalse ("Not equal CharIdentity instances compare equal.", sc= 1=2Eequals(sc3)); + assertFalse ("Not equal CharIdentity instances compare equal.", sc= 3=2Eequals(sc1)); + } +} Added: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ConcreteTestI= dentity.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/ConcreteTestIdentity.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/ConcreteTestIden= tity.java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ConcreteTestIden= tity.java Mon Mar 28 10:25:05 2005 @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* + * ConcreteTestIdentity.java + * + */ + +package javax.jdo.identity; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +/** + * + * @author clr + */ + public class ConcreteTestIdentity extends SingleFieldIdentity { + =20 + ConcreteTestIdentity(Class cls) { + super(cls); + } + =20 + /** This constructor is only for Serialization + */ + public ConcreteTestIdentity() { + super(); + } + =20 + public void writeExternal(ObjectOutput out) throws IOException { + super.writeExternal(out); + }=20 + + public void readExternal(ObjectInput in)=20 + throws IOException, ClassNotFoundException { + super.readExternal(in); + } + } Added: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTe= st.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/IntIdentityTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/IntIdentityTest.= java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.= java Mon Mar 28 10:25:05 2005 @@ -0,0 +1,92 @@ +/* + * 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. + */ + +/* + * IntIdentityTest.java + * + */ + +package javax.jdo.identity; + +import javax.jdo.util.BatchTestRunner; + +/** + * + */ +public class IntIdentityTest extends SingleFieldIdentityTest { + =20 + /** Creates a new instance of IntIdentityTest */ + public IntIdentityTest() { + } + =20 + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BatchTestRunner.run(IntIdentityTest.class); + } + =20 + public void testConstructor() { + IntIdentity c1 =3D new IntIdentity(Object.class, (int)1); + IntIdentity c2 =3D new IntIdentity(Object.class, (int)1); + IntIdentity c3 =3D new IntIdentity(Object.class, (int)2); + assertEquals("Equal IntIdentity instances compare not equal.", c1,= c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testintConstructor() { + IntIdentity c1 =3D new IntIdentity(Object.class, (int)1); + IntIdentity c2 =3D new IntIdentity(Object.class, new Integer((int)= 1)); + IntIdentity c3 =3D new IntIdentity(Object.class, new Integer((int)= 2)); + assertEquals ("Equal intIdentity instances compare not equal.", c1= , c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testStringConstructor() { + IntIdentity c1 =3D new IntIdentity(Object.class, (int)1); + IntIdentity c2 =3D new IntIdentity(Object.class, "1"); + IntIdentity c3 =3D new IntIdentity(Object.class, "2"); + assertEquals ("Equal IntIdentity instances compare not equal.", c1= , c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testIllegalStringConstructor() { + try { + IntIdentity c1 =3D new IntIdentity(Object.class, "b"); + } catch (IllegalArgumentException iae) { + return; // good + } + fail ("No exception caught for illegal String."); + } + =20 + public void testSerialized() { + IntIdentity c1 =3D new IntIdentity(Object.class, (int)1); + IntIdentity c2 =3D new IntIdentity(Object.class, "1"); + IntIdentity c3 =3D new IntIdentity(Object.class, "2"); + Object[] scis =3D writeReadSerialized(new Object[] {c1, c2, c3}); + Object sc1 =3D scis[0]; + Object sc2 =3D scis[1]; + Object sc3 =3D scis[2]; + assertEquals ("Equal IntIdentity instances compare not equal.", c1= , sc1); + assertEquals ("Equal IntIdentity instances compare not equal.", c2= , sc2); + assertEquals ("Equal IntIdentity instances compare not equal.", sc= 1, c2); + assertEquals ("Equal IntIdentity instances compare not equal.", sc= 2, c1); + assertFalse ("Not equal InrIdentity instances compare equal.", c1.= equals(sc3)); + assertFalse ("Not equal IntIdentity instances compare equal.", sc1= .equals(c3)); + assertFalse ("Not equal IntIdentity instances compare equal.", sc1= .equals(sc3)); + assertFalse ("Not equal IntIdentity instances compare equal.", sc3= .equals(sc1)); + } +} Added: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityT= est.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/LongIdentityTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/LongIdentityTest= .java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityTest= .java Mon Mar 28 10:25:05 2005 @@ -0,0 +1,92 @@ +/* + * 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. + */ + +/* + * LongIdentityTest.java + * + */ + +package javax.jdo.identity; + +import javax.jdo.util.BatchTestRunner; + +/** + * + */ +public class LongIdentityTest extends SingleFieldIdentityTest { + =20 + /** Creates a new instance of LongIdentityTest */ + public LongIdentityTest() { + } + =20 + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BatchTestRunner.run(LongIdentityTest.class); + } + =20 + public void testConstructor() { + LongIdentity c1 =3D new LongIdentity(Object.class, 1); + LongIdentity c2 =3D new LongIdentity(Object.class, 1); + LongIdentity c3 =3D new LongIdentity(Object.class, 2); + assertEquals("Equal LongIdentity instances compare not equal.", c1= , c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testLongConstructor() { + LongIdentity c1 =3D new LongIdentity(Object.class, 1); + LongIdentity c2 =3D new LongIdentity(Object.class, new Long(1)); + LongIdentity c3 =3D new LongIdentity(Object.class, new Long(2)); + assertEquals ("Equal LongIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testStringConstructor() { + LongIdentity c1 =3D new LongIdentity(Object.class, 1); + LongIdentity c2 =3D new LongIdentity(Object.class, "1"); + LongIdentity c3 =3D new LongIdentity(Object.class, "2"); + assertEquals ("Equal LongIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testIllegalStringConstructor() { + try { + LongIdentity c1 =3D new LongIdentity(Object.class, "b"); + } catch (IllegalArgumentException iae) { + return; // good + } + fail ("No exception caught for illegal String."); + } + =20 + public void testSerialized() { + LongIdentity c1 =3D new LongIdentity(Object.class, 1); + LongIdentity c2 =3D new LongIdentity(Object.class, "1"); + LongIdentity c3 =3D new LongIdentity(Object.class, "2"); + Object[] scis =3D writeReadSerialized(new Object[] {c1, c2, c3}); + Object sc1 =3D scis[0]; + Object sc2 =3D scis[1]; + Object sc3 =3D scis[2]; + assertEquals ("Equal LongIdentity instances compare not equal.", c= 1, sc1); + assertEquals ("Equal LongIdentity instances compare not equal.", c= 2, sc2); + assertEquals ("Equal LongIdentity instances compare not equal.", s= c1, c2); + assertEquals ("Equal LongIdentity instances compare not equal.", s= c2, c1); + assertFalse ("Not equal LongIdentity instances compare equal.", c1= .equals(sc3)); + assertFalse ("Not equal LongIdentity instances compare equal.", sc= 1=2Eequals(c3)); + assertFalse ("Not equal LongIdentity instances compare equal.", sc= 1=2Eequals(sc3)); + assertFalse ("Not equal LongIdentity instances compare equal.", sc= 3=2Eequals(sc1)); + } +} Added: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentity= Test.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/ShortIdentityTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/ShortIdentityTes= t=2Ejava (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTes= t=2Ejava Mon Mar 28 10:25:05 2005 @@ -0,0 +1,100 @@ +/* + * 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. + */ + +/* + * ShortIdentityTest.java + * + */ + +package javax.jdo.identity; + +import javax.jdo.util.BatchTestRunner; + +/** + * + */ +public class ShortIdentityTest extends SingleFieldIdentityTest { + =20 + /** Creates a new instance of ShortIdentityTest */ + public ShortIdentityTest() { + } + =20 + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BatchTestRunner.run(ShortIdentityTest.class); + } + =20 + public void testConstructor() { + ShortIdentity c1 =3D new ShortIdentity(Object.class, (short)1); + ShortIdentity c2 =3D new ShortIdentity(Object.class, (short)1); + ShortIdentity c3 =3D new ShortIdentity(Object.class, (short)2); + assertEquals("Equal ShortIdentity instances compare not equal.", c= 1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testShortConstructor() { + ShortIdentity c1 =3D new ShortIdentity(Object.class, (short)1); + ShortIdentity c2 =3D new ShortIdentity(Object.class, new Short((sh= ort)1)); + ShortIdentity c3 =3D new ShortIdentity(Object.class, new Short((sh= ort)2)); + assertEquals ("Equal ShortIdentity instances compare not equal.", = c1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testIntConstructor() { + ShortIdentity c1 =3D new ShortIdentity(Object.class, (short)1); + ShortIdentity c2 =3D new ShortIdentity(Object.class, 1); + ShortIdentity c3 =3D new ShortIdentity(Object.class, 2); + assertEquals ("Equal ShortIdentity instances compare not equal.", = c1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + + public void testStringConstructor() { + ShortIdentity c1 =3D new ShortIdentity(Object.class, (short)1); + ShortIdentity c2 =3D new ShortIdentity(Object.class, "1"); + ShortIdentity c3 =3D new ShortIdentity(Object.class, "2"); + assertEquals ("Equal ShortIdentity instances compare not equal.", = c1, c2); + assertFalse ("Not equal ByteIdentity instances compare equal", c1.= equals(c3)); + } + =20 + public void testIllegalStringConstructor() { + try { + ShortIdentity c1 =3D new ShortIdentity(Object.class, "b"); + } catch (IllegalArgumentException iae) { + return; // good + } + fail ("No exception caught for illegal String."); + } + =20 + public void testSerialized() { + ShortIdentity c1 =3D new ShortIdentity(Object.class, (short)1); + ShortIdentity c2 =3D new ShortIdentity(Object.class, "1"); + ShortIdentity c3 =3D new ShortIdentity(Object.class, "2"); + Object[] scis =3D writeReadSerialized(new Object[] {c1, c2, c3}); + Object sc1 =3D scis[0]; + Object sc2 =3D scis[1]; + Object sc3 =3D scis[2]; + assertEquals ("Equal ShortIdentity instances compare not equal.", = c1, sc1); + assertEquals ("Equal ShortIdentity instances compare not equal.", = c2, sc2); + assertEquals ("Equal ShortIdentity instances compare not equal.", = sc1, c2); + assertEquals ("Equal ShortIdentity instances compare not equal.", = sc2, c1); + assertFalse ("Not equal ShortIdentity instances compare equal.", c= 1=2Eequals(sc3)); + assertFalse ("Not equal ShortIdentity instances compare equal.", s= c1.equals(c3)); + assertFalse ("Not equal ShortIdentity instances compare equal.", s= c1.equals(sc3)); + assertFalse ("Not equal ShortIdentity instances compare equal.", s= c3.equals(sc1)); + } +} Added: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/SingleFieldId= entityTest.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/SingleFieldIdentityTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/SingleFieldIdent= ityTest.java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/SingleFieldIdent= ityTest.java Mon Mar 28 10:25:05 2005 @@ -0,0 +1,109 @@ +/* + * 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. + */ + +/* + * SingleFieldIdentityTest.java + * + */ + +package javax.jdo.identity; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +import javax.jdo.util.AbstractTest; +import javax.jdo.util.BatchTestRunner; + +/** + *=20 + */ +public class SingleFieldIdentityTest extends AbstractTest { + =20 + ConcreteTestIdentity cti1; + ConcreteTestIdentity cti2; + ConcreteTestIdentity cti3; + =20 + Object scti1; + Object scti2; + Object scti3; + + /** Creates a new instance of SingleFieldIdentityTest */ + public SingleFieldIdentityTest() { + } + =20 + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BatchTestRunner.run(SingleFieldIdentityTest.class); + } + =20 + public void testConstructor() { + cti1 =3D new ConcreteTestIdentity(Object.class); + cti2 =3D new ConcreteTestIdentity(Object.class); + cti3 =3D new ConcreteTestIdentity(Class.class); + =20 + assertEquals ("Equal identity instances compare not equal.", cti1,= cti2); + if (cti1.equals(cti3))=20 + fail ("Not equal identity instances compare equal."); + } + =20 + public void testSerialized() { + cti1 =3D new ConcreteTestIdentity(Object.class); + cti2 =3D new ConcreteTestIdentity(Object.class); + cti3 =3D new ConcreteTestIdentity(Class.class); + Object[] sctis =3D writeReadSerialized(new Object[]{cti1, cti2, ct= i3}); + scti1 =3D sctis[0]; + scti2 =3D sctis[1]; + scti3 =3D sctis[2]; + assertEquals ("Deserialized instance compare not equal.", cti1, sc= ti1); + assertEquals ("Deserialized instance compare not equal.", cti2, sc= ti2); + assertEquals ("Deserialized instance compare not equal.", cti3, sc= ti3); + assertEquals ("Deserialized instance compare not equal.", scti1, c= ti1); + assertEquals ("Deserialized instance compare not equal.", scti2, c= ti2); + assertEquals ("Deserialized instance compare not equal.", scti3, c= ti3); + if (scti1.equals(scti3))=20 + fail ("Not equal identity instances compare equal."); + =20 + } + =20 + protected Object[] writeReadSerialized(Object[] in) { + int length =3D in.length; + Object[] result =3D new Object[length]; + try { + ByteArrayOutputStream baos =3D new ByteArrayOutputStream(); + ObjectOutputStream oos =3D new ObjectOutputStream(baos); + for (int i =3D 0; i < length; ++i) { + oos.writeObject(in[i]); + } + byte[] ba =3D baos.toByteArray(); + ByteArrayInputStream bais =3D new ByteArrayInputStream(ba); + ObjectInputStream ois =3D new ObjectInputStream(bais); + for (int i =3D 0; i < length; ++i) { + result[i] =3D ois.readObject(); + } + } catch (Exception e) { + fail(e.toString()); + } + return result; + } + =20 +} Added: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentit= yTest.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/java= x/jdo/identity/StringIdentityTest.java?view=3Dauto&rev=3D159273 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/api20/test/java/javax/jdo/identity/StringIdentityTe= st.java (added) +++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTe= st.java Mon Mar 28 10:25:05 2005 @@ -0,0 +1,67 @@ +/* + * 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. + */ + +/* + * StringIdentityTest.java + * + */ + +package javax.jdo.identity; + +import javax.jdo.util.BatchTestRunner; + +/** + * + */ +public class StringIdentityTest extends SingleFieldIdentityTest { + =20 + /** Creates a new instance of StringIdentityTest */ + public StringIdentityTest() { + } + =20 + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BatchTestRunner.run(StringIdentityTest.class); + } + =20 + public void testConstructor() { + StringIdentity c1 =3D new StringIdentity(Object.class, "1"); + StringIdentity c2 =3D new StringIdentity(Object.class, "1"); + StringIdentity c3 =3D new StringIdentity(Object.class, "2"); + assertEquals("Equal StringIdentity instances compare not equal.", = c1, c2); + assertFalse ("Not equal StringIdentity instances compare equal", c= 1=2Eequals(c3)); + } + =20 + public void testSerialized() { + StringIdentity c1 =3D new StringIdentity(Object.class, "1"); + StringIdentity c2 =3D new StringIdentity(Object.class, "1"); + StringIdentity c3 =3D new StringIdentity(Object.class, "2"); + Object[] scis =3D writeReadSerialized(new Object[] {c1, c2, c3}); + Object sc1 =3D scis[0]; + Object sc2 =3D scis[1]; + Object sc3 =3D scis[2]; + assertEquals ("Equal StringIdentity instances compare not equal.",= c1, sc1); + assertEquals ("Equal StringIdentity instances compare not equal.",= c2, sc2); + assertEquals ("Equal StringIdentity instances compare not equal.",= sc1, c2); + assertEquals ("Equal StringIdentity instances compare not equal.",= sc2, c1); + assertFalse ("Not equal StringIdentity instances compare equal.", = c1.equals(sc3)); + assertFalse ("Not equal StringIdentity instances compare equal.", = sc1.equals(c3)); + assertFalse ("Not equal StringIdentity instances compare equal.", = sc1.equals(sc3)); + assertFalse ("Not equal StringIdentity instances compare equal.", = sc3.equals(sc1)); + } +}