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=auto&rev=159273
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/spi/StateManager.java (added)
+++ 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.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package javax.jdo.spi;
+
+import java.util.BitSet;
+
+import javax.jdo.PersistenceManager;
+
+/** This interface is the point of contact between managed instances of
+ * <code>PersistenceCapable</code> classes and the JDO implementation.  It 
contains
+ * the methods used by <code>PersistenceCapable</code> instances to delegate 
behavior to 
+ * the JDO implementation.
+ *<P>Each managed <code>PersistenceCapable</code> instance contains a 
reference to a
+ * <code>StateManager</code>.  A <code>StateManager</code> might manage one or 
multiple instances of
+ * <code>PersistenceCapable</code> instances, at the choice of the 
implementation.
+ *
+ * @version 2.0
+ *
+ */
+public interface StateManager {
+    
+    /** The owning <code>StateManager</code> uses this method to supply the 
+     * value of the flags to the <code>PersistenceCapable</code> instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return the value of <code>jdoFlags</code> to be stored in the 
<code>PersistenceCapable</code> instance
+     */
+    byte replacingFlags(PersistenceCapable pc);
+
+    /** Replace the current value of <code>jdoStateManager</code>.
+     * <P>
+     * This method is called by the <code>PersistenceCapable</code> whenever
+     * <code>jdoReplaceStateManager</code> is called and there is already
+     * an owning <code>StateManager</code>.  This is a security precaution
+     * to ensure that the owning <code>StateManager</code> is the only
+     * source of any change to its reference in the 
<code>PersistenceCapable</code>.
+     * @return the new value for the <code>jdoStateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param sm the proposed new value for the <code>jdoStateManager</code>
+     */ 
+    StateManager replacingStateManager (PersistenceCapable pc, StateManager 
sm);
+    
+    /** Tests whether this object is dirty.
+     *
+     * Instances that have been modified, deleted, or newly 
+     * made persistent in the current transaction return <code>true</code>.
+     *
+     *<P>Transient nontransactional instances return <code>false</code>.
+     *<P>
+     * @see PersistenceCapable#jdoMakeDirty(String fieldName)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> 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 <code>true</code>. 
 These instances
+     * include transient instances made transactional as a result of being the
+     * target of a <code>makeTransactional</code> method call; newly made 
persistent or deleted
+     * persistent instances; persistent instances read in data store
+     * transactions; and persistent instances modified in optimistic 
transactions.
+     *
+     *<P>Transient nontransactional instances return <code>false</code>.
+     *<P>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> 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 
<code>true</code>.
+     *
+     *<P>Transient instances return <code>false</code>.
+     *<P>
+     * @see PersistenceManager#makePersistent(Object pc)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> 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 
+     * return <code>true</code>.
+     *
+     *<P>Transient instances return <code>false</code>.
+     *<P>
+     * @see PersistenceManager#makePersistent(Object pc)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> 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 
<code>true</code>.
+     *
+     *<P>Transient instances return <code>false</code>.
+     *<P>
+     * @see PersistenceManager#deletePersistent(Object pc)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> if this instance was deleted
+     * in the current transaction.
+     */
+    boolean isDeleted(PersistenceCapable pc);
+    
+    /** Return the <code>PersistenceManager</code> that owns this instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return the <code>PersistenceManager</code> that owns this instance
+     */
+    PersistenceManager getPersistenceManager (PersistenceCapable pc);
+    
+    /** Mark the associated <code>PersistenceCapable</code> field dirty.
+     * <P>The <code>StateManager</code> 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 <code>PersistenceCapable</code> instance
+     * @param fieldName the name of the field
+     */    
+    void makeDirty (PersistenceCapable pc, String fieldName);
+    
+    /** Return the object representing the JDO identity 
+     * 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 <code>PersistenceCapable</code> instance
+     * @return the object representing the JDO identity of the calling instance
+     */    
+    Object getObjectId (PersistenceCapable pc);
+
+    /** Return the object representing the JDO identity 
+     * 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 <code>PersistenceCapable</code> instance
+     * @return the object representing the JDO identity of the calling instance
+     */    
+    Object getTransactionalObjectId (PersistenceCapable pc);
+
+    /** Return the object representing the version 
+     * of the calling instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return the object representing the version of the calling instance
+     * @since 2.0
+     */    
+    Object getVersion (PersistenceCapable pc);
+
+    /** Return <code>true</code> if the field is cached in the calling
+     * instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @return whether the field is cached in the calling instance
+     */    
+    boolean isLoaded (PersistenceCapable pc, int field);
+    
+    /** Guarantee that the serializable transactional and persistent fields
+     * are loaded into the instance.  This method is called by the generated
+     * <code>jdoPreSerialize</code> method prior to serialization of the
+     * instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     */    
+    void preSerialize (PersistenceCapable pc);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    boolean getBooleanField (PersistenceCapable pc, int field, boolean 
currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    char getCharField (PersistenceCapable pc, int field, char currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    byte getByteField (PersistenceCapable pc, int field, byte currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    short getShortField (PersistenceCapable pc, int field, short currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    int getIntField (PersistenceCapable pc, int field, int currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    long getLongField (PersistenceCapable pc, int field, long currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    float getFloatField (PersistenceCapable pc, int field, float currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    double getDoubleField (PersistenceCapable pc, int field, double 
currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    String getStringField (PersistenceCapable pc, int field, String 
currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    Object getObjectField (PersistenceCapable pc, int field, Object 
currentValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setBooleanField (PersistenceCapable pc, int field, boolean 
currentValue, boolean newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setCharField (PersistenceCapable pc, int field, char currentValue, 
char newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setByteField (PersistenceCapable pc, int field, byte currentValue, 
byte newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setShortField (PersistenceCapable pc, int field, short currentValue, 
short newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setIntField (PersistenceCapable pc, int field, int currentValue, int 
newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setLongField (PersistenceCapable pc, int field, long currentValue, 
long newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setFloatField (PersistenceCapable pc, int field, float currentValue, 
float newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setDoubleField (PersistenceCapable pc, int field, double 
currentValue, double newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setStringField (PersistenceCapable pc, int field, String 
currentValue, String newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setObjectField (PersistenceCapable pc, int field, Object 
currentValue, Object newValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedBooleanField (PersistenceCapable pc, int field, boolean 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedCharField (PersistenceCapable pc, int field, char 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedByteField (PersistenceCapable pc, int field, byte 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedShortField (PersistenceCapable pc, int field, short 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedIntField (PersistenceCapable pc, int field, int currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedLongField (PersistenceCapable pc, int field, long 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedFloatField (PersistenceCapable pc, int field, float 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedDoubleField (PersistenceCapable pc, int field, double 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedStringField (PersistenceCapable pc, int field, String 
currentValue);
+
+    /** The value of the field requested to be provided to the 
<code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedObjectField (PersistenceCapable pc, int field, Object 
currentValue);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @return the new value for the field
+     */    
+    boolean replacingBooleanField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    char replacingCharField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    byte replacingByteField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    short replacingShortField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    int replacingIntField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    long replacingLongField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    float replacingFloatField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    double replacingDoubleField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    String replacingStringField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    Object replacingObjectField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the object id in the calling instance.
+     * @param pc the calling <code>PersistenceCapable</code> 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);
+    
+    /** The replacing value of the version in the calling instance.
+     * @param pc the calling <code>PersistenceCapable</code> 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 instance.
+     * @param pc the calling <code>PersistenceCapable</code> 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 instance.
+     * @param pc the calling <code>PersistenceCapable</code> 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 instance.
+     * @param pc the calling <code>PersistenceCapable</code> 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 instance.
+     * @param pc the calling <code>PersistenceCapable</code> 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 modified);
+}
+

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=auto&rev=159273
==============================================================================
--- 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 28 
10:25:05 2005
@@ -0,0 +1,47 @@
+<!--
+ Copyright 2005 The Apache Software Foundation.
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at 
+ 
+     http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software 
+ distributed under the License is distributed on an "AS IS" BASIS, 
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ See the License for the specific language governing permissions and 
+ limitations under the License.
+-->
+
+<html>
+<head>
+<title>JDO Service Provider Interface package</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<P>This package contains the interfaces and classes used by JDO 
implementations. 
+<P>JDO defines interfaces and classes to be used by application programmers 
+when using classes whose instances are to be stored in persistent storage 
+(persistence-capable classes), and specifies the contracts between 
+suppliers of persistence-capable classes and the 
+runtime environment (which is part of the JDO implementation).
+<P>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:
+<ul>
+<li>Pre-processing .java files
+<li>Post-processing .class files
+<li>Generating .java or .class files directly from an abstraction
+</ul
+<P>The StateManager interface is the implementation's contact point with
+the PersistenceCapable instances.  It defines methods that are called by 
+the PersistenceCapable instances to implement the required PersistenceCapable
+behavior for persistent and transactional instances.
+<P>The JDOPermission class is used to manage security controls on JDO 
implementations.
+<P>The RegisterClassEvent class and RegisterClassListener interface are used
+by JDO implementations that need access to metadata of PersistenceCapable 
classes.
+<P>The JDOImplHelper class contains helper methods for JDO implementations.
+</body>
+</html>

Added: incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java?view=auto&rev=159273
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java (added)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java Mon Mar 28 
10:25:05 2005
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+package 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.
+ * <p>
+ * TBD: implementation of testMakeDirty, 
+ * TBD: testing interrogative methods for persistent instances
+ * TBD: getPMF for valid PMF class
+ */
+public class JDOHelperTest extends AbstractTest {
+    
+    /** */
+    public static void main(String args[]) {
+        BatchTestRunner.run(JDOHelperTest.class);
+    }
+
+    /** */
+    public void testGetPM() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.getPersistenceManager(p) != null) {
+            fail("JDOHelper.getPersistenceManager should return null pm for 
non-persistent instance");
+        }
+
+        // TBD: test for persistent instance
+    }
+
+    /** */
+    public void testMakeDirty() {
+        // TBD: test JDOHelper.makeDirty(pc, fieldName);
+    }
+
+    /** */
+    public void testGetObjectId() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.getObjectId(p) != null) {
+            fail("JDOHelper.getObjectId should return null ObjectId for 
non-persistent instance");
+        }
+
+        // TBD test JDOHelper.getObjectId(pc) for persistent instance
+    }
+
+    /** */
+    public void testGetTransactionObjectId() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.getObjectId(p) != null) {
+            fail("JDOHelper.getTransactionalObjectId should return null 
ObjectId for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.getTransactionalObjectId(pc) for persistent 
instance
+    }
+
+    /** */
+    public void testIsDirty() {
+        PCPoint p = 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 = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isTransactional(p)) {
+            fail("JDOHelper.isTransactional should return false for 
non-persistent instance");
+        }
+
+        // TBD test JDOHelper.isTransactional(pc) for persistent instance
+    }
+
+    /** */
+    public void testIsPersistent() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isPersistent(p)) {
+            fail("JDOHelper.isPersistent should return false for 
non-persistent instance");
+        }
+
+        // TBD test JDOHelper.isPersistent(pc) for persistent instance
+    }
+
+    /** */
+    public void testIsNew() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isNew(p)) {
+            fail("JDOHelper.isNew should return false for non-persistent 
instance");
+        }
+
+        // TBD test JDOHelper.isNew(pc) for persistent instance
+    }
+
+
+    /** */
+    public void testIsDeleted() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isDeleted(p)) {
+            fail("JDOHelper.isDeleted should return false for non-persistent 
instance");
+        }
+
+        // TBD test JDOHelper.isDeleted(pc) for persistent instance
+    }
+
+    /** */
+    public void testGetPMF() {
+        // test missing property javax.jdo.PersistenceManagerFactoryClass
+        PersistenceManagerFactory pmf = null;
+        try {
+            pmf = JDOHelper.getPersistenceManagerFactory(new Properties());
+            fail("Missing property PersistenceManagerFactoryClass should 
result 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/ByteIdentityTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ByteIdentityTest.java?view=auto&rev=159273
==============================================================================
--- 
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.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * ByteIdentityTest.java
+ *
+ */
+
+package javax.jdo.identity;
+
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ *
+ */
+public class ByteIdentityTest extends SingleFieldIdentityTest {
+    
+    /** Creates a new instance of ByteIdentityTest */
+    public ByteIdentityTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(ByteIdentityTest.class);
+    }
+    
+    public void testConstructor() {
+        ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
+        ByteIdentity c2 = new ByteIdentity(Object.class, (byte)1);
+        ByteIdentity c3 = 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 = new ByteIdentity(Object.class, (byte)1);
+        ByteIdentity c2 = new ByteIdentity(Object.class, new Byte((byte)1));
+        ByteIdentity c3 = new ByteIdentity(Object.class, new Byte((byte)2));
+        assertEquals ("Equal ByteIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+
+    public void testIntConstructor() {
+        ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
+        ByteIdentity c2 = new ByteIdentity(Object.class, 1);
+        ByteIdentity c3 = new ByteIdentity(Object.class, 2);
+        assertEquals ("Equal ByteIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+
+    public void testStringConstructor() {
+        ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
+        ByteIdentity c2 = new ByteIdentity(Object.class, "1");
+        ByteIdentity c3 = new ByteIdentity(Object.class, "2");
+        assertEquals ("Equal ByteIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+    
+    public void testIllegalStringConstructor() {
+        try {
+            ByteIdentity c1 = new ByteIdentity(Object.class, "b");
+        } catch (IllegalArgumentException iae) {
+            return; // good
+        }
+        fail ("No exception caught for illegal String.");
+    }
+    
+    public void testSerialized() {
+        ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
+        ByteIdentity c2 = new ByteIdentity(Object.class, "1");
+        ByteIdentity c3 = new ByteIdentity(Object.class, "2");
+        Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
+        Object sc1 = scis[0];
+        Object sc2 = scis[1];
+        Object sc3 = scis[2];
+        assertEquals ("Equal ByteIdentity instances compare not equal.", c1, 
sc1);
+        assertEquals ("Equal ByteIdentity instances compare not equal.", c2, 
sc2);
+        assertEquals ("Equal ByteIdentity instances compare not equal.", sc1, 
c2);
+        assertEquals ("Equal ByteIdentity instances compare not equal.", sc2, 
c1);
+        assertFalse ("Not equal ByteIdentity instances compare equal.", 
c1.equals(sc3));
+        assertFalse ("Not equal ByteIdentity instances compare equal.", 
sc1.equals(c3));
+        assertFalse ("Not equal ByteIdentity instances compare equal.", 
sc1.equals(sc3));
+        assertFalse ("Not equal ByteIdentity instances compare equal.", 
sc3.equals(sc1));
+    }
+}

Added: 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest.java?view=auto&rev=159273
==============================================================================
--- 
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.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * CharIdentityTest.java
+ *
+ */
+
+package javax.jdo.identity;
+
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ *
+ * @author clr
+ */
+public class CharIdentityTest extends SingleFieldIdentityTest {
+    
+    /** Creates a new instance of CharIdentityTest */
+    public CharIdentityTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(CharIdentityTest.class);
+    }
+    
+    public void testConstructor() {
+        CharIdentity c1 = new CharIdentity(Object.class, 'a');
+        CharIdentity c2 = new CharIdentity(Object.class, 'a');
+        CharIdentity c3 = new CharIdentity(Object.class, 'b');
+        assertEquals("Equal CharIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+    
+    public void testIntConstructor() {
+        CharIdentity c1 = new CharIdentity(Object.class, 'a');
+        CharIdentity c2 = new CharIdentity(Object.class, 97);
+        CharIdentity c3 = new CharIdentity(Object.class, 98);
+        assertEquals ("Equal CharIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+    
+    public void testStringConstructor() {
+        CharIdentity c1 = new CharIdentity(Object.class, 'a');
+        CharIdentity c2 = new CharIdentity(Object.class, "a");
+        CharIdentity c3 = new CharIdentity(Object.class, "b");
+        assertEquals ("Equal CharIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+    
+    public void testStringConstructorTooLong() {
+        try {
+            CharIdentity c1 = new CharIdentity(Object.class, "ab");
+        } catch (IllegalArgumentException iae) {
+            return; // good
+        }
+        fail ("No exception caught for String too long.");
+    }
+    
+    public void testStringConstructorTooShort() {
+        try {
+            CharIdentity c1 = new CharIdentity(Object.class, "");
+        } catch (IllegalArgumentException iae) {
+            return; // good
+        }
+        fail ("No exception caught for String too short.");
+    }
+    
+    public void testCharacterConstructor() {
+        CharIdentity c1 = new CharIdentity(Object.class, 'a');
+        CharIdentity c2 = new CharIdentity(Object.class, new Character('a'));
+        CharIdentity c3 = new CharIdentity(Object.class, new Character('b'));
+        assertEquals ("Equal CharIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+    
+    public void testSerialized() {
+        CharIdentity c1 = new CharIdentity(Object.class, 'a');
+        CharIdentity c2 = new CharIdentity(Object.class, "a");
+        CharIdentity c3 = new CharIdentity(Object.class, "b");
+        Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
+        Object sc1 = scis[0];
+        Object sc2 = scis[1];
+        Object sc3 = scis[2];
+        assertEquals ("Equal CharIdentity instances compare not equal.", c1, 
sc1);
+        assertEquals ("Equal CharIdentity instances compare not equal.", c2, 
sc2);
+        assertEquals ("Equal CharIdentity instances compare not equal.", sc1, 
c2);
+        assertEquals ("Equal CharIdentity instances compare not equal.", sc2, 
c1);
+        assertFalse ("Not equal CharIdentity instances compare equal.", 
c1.equals(sc3));
+        assertFalse ("Not equal CharIdentity instances compare equal.", 
sc1.equals(c3));
+        assertFalse ("Not equal CharIdentity instances compare equal.", 
sc1.equals(sc3));
+        assertFalse ("Not equal CharIdentity instances compare equal.", 
sc3.equals(sc1));
+    }
+}

Added: 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ConcreteTestIdentity.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ConcreteTestIdentity.java?view=auto&rev=159273
==============================================================================
--- 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ConcreteTestIdentity.java
 (added)
+++ 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ConcreteTestIdentity.java
 Mon Mar 28 10:25:05 2005
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * 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 {
+        
+        ConcreteTestIdentity(Class cls) {
+            super(cls);
+        }
+        
+        /** This constructor is only for Serialization
+         */
+        public ConcreteTestIdentity() {
+            super();
+        }
+        
+        public void writeExternal(ObjectOutput out) throws IOException {
+            super.writeExternal(out);
+        } 
+
+        public void readExternal(ObjectInput in) 
+            throws IOException, ClassNotFoundException {
+            super.readExternal(in);
+        }
+    }

Added: 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.java?view=auto&rev=159273
==============================================================================
--- 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.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * IntIdentityTest.java
+ *
+ */
+
+package javax.jdo.identity;
+
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ *
+ */
+public class IntIdentityTest extends SingleFieldIdentityTest {
+    
+    /** Creates a new instance of IntIdentityTest */
+    public IntIdentityTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(IntIdentityTest.class);
+    }
+    
+    public void testConstructor() {
+        IntIdentity c1 = new IntIdentity(Object.class, (int)1);
+        IntIdentity c2 = new IntIdentity(Object.class, (int)1);
+        IntIdentity c3 = 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 = new IntIdentity(Object.class, (int)1);
+        IntIdentity c2 = new IntIdentity(Object.class, new Integer((int)1));
+        IntIdentity c3 = 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 = new IntIdentity(Object.class, (int)1);
+        IntIdentity c2 = new IntIdentity(Object.class, "1");
+        IntIdentity c3 = new IntIdentity(Object.class, "2");
+        assertEquals ("Equal IntIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+    
+    public void testIllegalStringConstructor() {
+        try {
+            IntIdentity c1 = new IntIdentity(Object.class, "b");
+        } catch (IllegalArgumentException iae) {
+            return; // good
+        }
+        fail ("No exception caught for illegal String.");
+    }
+    
+    public void testSerialized() {
+        IntIdentity c1 = new IntIdentity(Object.class, (int)1);
+        IntIdentity c2 = new IntIdentity(Object.class, "1");
+        IntIdentity c3 = new IntIdentity(Object.class, "2");
+        Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
+        Object sc1 = scis[0];
+        Object sc2 = scis[1];
+        Object sc3 = 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.", sc1, 
c2);
+        assertEquals ("Equal IntIdentity instances compare not equal.", sc2, 
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/LongIdentityTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityTest.java?view=auto&rev=159273
==============================================================================
--- 
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.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * LongIdentityTest.java
+ *
+ */
+
+package javax.jdo.identity;
+
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ *
+ */
+public class LongIdentityTest extends SingleFieldIdentityTest {
+    
+    /** Creates a new instance of LongIdentityTest */
+    public LongIdentityTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(LongIdentityTest.class);
+    }
+    
+    public void testConstructor() {
+        LongIdentity c1 = new LongIdentity(Object.class, 1);
+        LongIdentity c2 = new LongIdentity(Object.class, 1);
+        LongIdentity c3 = 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 = new LongIdentity(Object.class, 1);
+        LongIdentity c2 = new LongIdentity(Object.class, new Long(1));
+        LongIdentity c3 = new LongIdentity(Object.class, new Long(2));
+        assertEquals ("Equal LongIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+
+    public void testStringConstructor() {
+        LongIdentity c1 = new LongIdentity(Object.class, 1);
+        LongIdentity c2 = new LongIdentity(Object.class, "1");
+        LongIdentity c3 = 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 testIllegalStringConstructor() {
+        try {
+            LongIdentity c1 = new LongIdentity(Object.class, "b");
+        } catch (IllegalArgumentException iae) {
+            return; // good
+        }
+        fail ("No exception caught for illegal String.");
+    }
+    
+    public void testSerialized() {
+        LongIdentity c1 = new LongIdentity(Object.class, 1);
+        LongIdentity c2 = new LongIdentity(Object.class, "1");
+        LongIdentity c3 = new LongIdentity(Object.class, "2");
+        Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
+        Object sc1 = scis[0];
+        Object sc2 = scis[1];
+        Object sc3 = scis[2];
+        assertEquals ("Equal LongIdentity instances compare not equal.", c1, 
sc1);
+        assertEquals ("Equal LongIdentity instances compare not equal.", c2, 
sc2);
+        assertEquals ("Equal LongIdentity instances compare not equal.", sc1, 
c2);
+        assertEquals ("Equal LongIdentity instances compare not equal.", sc2, 
c1);
+        assertFalse ("Not equal LongIdentity instances compare equal.", 
c1.equals(sc3));
+        assertFalse ("Not equal LongIdentity instances compare equal.", 
sc1.equals(c3));
+        assertFalse ("Not equal LongIdentity instances compare equal.", 
sc1.equals(sc3));
+        assertFalse ("Not equal LongIdentity instances compare equal.", 
sc3.equals(sc1));
+    }
+}

Added: 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java?view=auto&rev=159273
==============================================================================
--- 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java 
(added)
+++ 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java 
Mon Mar 28 10:25:05 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * ShortIdentityTest.java
+ *
+ */
+
+package javax.jdo.identity;
+
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ *
+ */
+public class ShortIdentityTest extends SingleFieldIdentityTest {
+    
+    /** Creates a new instance of ShortIdentityTest */
+    public ShortIdentityTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(ShortIdentityTest.class);
+    }
+    
+    public void testConstructor() {
+        ShortIdentity c1 = new ShortIdentity(Object.class, (short)1);
+        ShortIdentity c2 = new ShortIdentity(Object.class, (short)1);
+        ShortIdentity c3 = new ShortIdentity(Object.class, (short)2);
+        assertEquals("Equal ShortIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal ByteIdentity instances compare equal", 
c1.equals(c3));
+    }
+
+    public void testShortConstructor() {
+        ShortIdentity c1 = new ShortIdentity(Object.class, (short)1);
+        ShortIdentity c2 = new ShortIdentity(Object.class, new 
Short((short)1));
+        ShortIdentity c3 = new ShortIdentity(Object.class, new 
Short((short)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 = new ShortIdentity(Object.class, (short)1);
+        ShortIdentity c2 = new ShortIdentity(Object.class, 1);
+        ShortIdentity c3 = 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 = new ShortIdentity(Object.class, (short)1);
+        ShortIdentity c2 = new ShortIdentity(Object.class, "1");
+        ShortIdentity c3 = 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 testIllegalStringConstructor() {
+        try {
+            ShortIdentity c1 = new ShortIdentity(Object.class, "b");
+        } catch (IllegalArgumentException iae) {
+            return; // good
+        }
+        fail ("No exception caught for illegal String.");
+    }
+    
+    public void testSerialized() {
+        ShortIdentity c1 = new ShortIdentity(Object.class, (short)1);
+        ShortIdentity c2 = new ShortIdentity(Object.class, "1");
+        ShortIdentity c3 = new ShortIdentity(Object.class, "2");
+        Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
+        Object sc1 = scis[0];
+        Object sc2 = scis[1];
+        Object sc3 = 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.", 
c1.equals(sc3));
+        assertFalse ("Not equal ShortIdentity instances compare equal.", 
sc1.equals(c3));
+        assertFalse ("Not equal ShortIdentity instances compare equal.", 
sc1.equals(sc3));
+        assertFalse ("Not equal ShortIdentity instances compare equal.", 
sc3.equals(sc1));
+    }
+}

Added: 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/SingleFieldIdentityTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/SingleFieldIdentityTest.java?view=auto&rev=159273
==============================================================================
--- 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/SingleFieldIdentityTest.java
 (added)
+++ 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/SingleFieldIdentityTest.java
 Mon Mar 28 10:25:05 2005
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * 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;
+
+/**
+ * 
+ */
+public class SingleFieldIdentityTest extends AbstractTest {
+    
+    ConcreteTestIdentity cti1;
+    ConcreteTestIdentity cti2;
+    ConcreteTestIdentity cti3;
+    
+    Object scti1;
+    Object scti2;
+    Object scti3;
+
+    /** Creates a new instance of SingleFieldIdentityTest */
+    public SingleFieldIdentityTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(SingleFieldIdentityTest.class);
+    }
+    
+    public void testConstructor() {
+    cti1 = new ConcreteTestIdentity(Object.class);
+    cti2 = new ConcreteTestIdentity(Object.class);
+    cti3 = new ConcreteTestIdentity(Class.class);
+    
+        assertEquals ("Equal identity instances compare not equal.", cti1, 
cti2);
+        if (cti1.equals(cti3)) 
+            fail ("Not equal identity instances compare equal.");
+    }
+    
+    public void testSerialized() {
+        cti1 = new ConcreteTestIdentity(Object.class);
+        cti2 = new ConcreteTestIdentity(Object.class);
+        cti3 = new ConcreteTestIdentity(Class.class);
+        Object[] sctis = writeReadSerialized(new Object[]{cti1, cti2, cti3});
+        scti1 = sctis[0];
+        scti2 = sctis[1];
+        scti3 = sctis[2];
+        assertEquals ("Deserialized instance compare not equal.", cti1, scti1);
+        assertEquals ("Deserialized instance compare not equal.", cti2, scti2);
+        assertEquals ("Deserialized instance compare not equal.", cti3, scti3);
+        assertEquals ("Deserialized instance compare not equal.", scti1, cti1);
+        assertEquals ("Deserialized instance compare not equal.", scti2, cti2);
+        assertEquals ("Deserialized instance compare not equal.", scti3, cti3);
+        if (scti1.equals(scti3)) 
+            fail ("Not equal identity instances compare equal.");
+        
+    }
+    
+    protected Object[] writeReadSerialized(Object[] in) {
+        int length = in.length;
+        Object[] result = new Object[length];
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            for (int i = 0; i < length; ++i) {
+                oos.writeObject(in[i]);
+            }
+            byte[] ba = baos.toByteArray();
+            ByteArrayInputStream bais = new ByteArrayInputStream(ba);
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            for (int i = 0; i < length; ++i) {
+                result[i] = ois.readObject();
+            }
+        } catch (Exception e) {
+            fail(e.toString());
+        }
+        return result;
+    }
+  
+}

Added: 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java?view=auto&rev=159273
==============================================================================
--- 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java 
(added)
+++ 
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java 
Mon Mar 28 10:25:05 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/*
+ * StringIdentityTest.java
+ *
+ */
+
+package javax.jdo.identity;
+
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ *
+ */
+public class StringIdentityTest extends SingleFieldIdentityTest {
+    
+    /** Creates a new instance of StringIdentityTest */
+    public StringIdentityTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(StringIdentityTest.class);
+    }
+    
+    public void testConstructor() {
+        StringIdentity c1 = new StringIdentity(Object.class, "1");
+        StringIdentity c2 = new StringIdentity(Object.class, "1");
+        StringIdentity c3 = new StringIdentity(Object.class, "2");
+        assertEquals("Equal StringIdentity instances compare not equal.", c1, 
c2);
+        assertFalse ("Not equal StringIdentity instances compare equal", 
c1.equals(c3));
+    }
+    
+    public void testSerialized() {
+        StringIdentity c1 = new StringIdentity(Object.class, "1");
+        StringIdentity c2 = new StringIdentity(Object.class, "1");
+        StringIdentity c3 = new StringIdentity(Object.class, "2");
+        Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
+        Object sc1 = scis[0];
+        Object sc2 = scis[1];
+        Object sc3 = 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));
+    }
+}


Reply via email to