javax.jdo.identity

## Class SingleFieldIdentity

- java.lang.Object
- - javax.jdo.identity.SingleFieldIdentity

- All Implemented Interfaces:
    Externalizable, Serializable, Comparable
  Direct Known Subclasses:
    ByteIdentity, CharIdentity, IntIdentity, LongIdentity, ObjectIdentity, ShortIdentity, StringIdentity

      public abstract class SingleFieldIdentity
      extends Object
      implements Externalizable, Comparable

  This class is the abstract base class for all single field identity classes. A common case of application identity uses exactly one persistent field in the class to represent identity. In this case, the application can use a standard JDO class instead of creating a new user-defined class for the purpose.
  Version:
    2.0
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `hashCode` The hashCode.
    `protected Object` | `keyAsObject` The key as an Object.
    `protected static I18NHelper` | `msg` The Internationalization message helper.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `SingleFieldIdentity()` Constructor only for Externalizable.
    `protected` | `SingleFieldIdentity(Class pcClass)` Constructor with target class.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `assertKeyNotNull(Object key)` Assert that the key is not null.
    `protected int` | `compare(SingleFieldIdentity o)` Determine the ordering of identity objects.
    `protected Object` | `createKeyAsObject()` Create the key as an Object.
    `boolean` | `equals(Object obj)` Check the class and class name and object type.
    `Object` | `getKeyAsObject()` Return the key as an Object.
    `Class` | `getTargetClass()` Return the target class.
    `String` | `getTargetClassName()` Return the target class name.
    `protected int` | `hashClassName()` Return the hash code of the class name.
    `int` | `hashCode()` Return the cached hash code.
    `void` | `readExternal(ObjectInput in)` Read from the input stream.
    `protected void` | `setKeyAsObject(Object key)` Set the given key as the key for this instance.
    `void` | `writeExternal(ObjectOutput out)` Write to the output stream.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Comparable

      `compareTo`

- - ### Field Detail

    - #### msg

          protected static I18NHelper msg

      The Internationalization message helper.

    - #### hashCode

          protected int hashCode

      The hashCode.

    - #### keyAsObject

          protected Object keyAsObject

      The key as an Object.

  - ### Constructor Detail

    - #### SingleFieldIdentity

          protected SingleFieldIdentity(Class pcClass)

      Constructor with target class.
      Parameters:
        `pcClass` - the class of the target
      Since:
        2.0

    - #### SingleFieldIdentity

          public SingleFieldIdentity()

      Constructor only for Externalizable.
      Since:
        2.0

  - ### Method Detail

    - #### setKeyAsObject

          protected void setKeyAsObject(Object key)

      Set the given key as the key for this instance. Compute the hash code for the instance.
      Parameters:
        `key` - The key to use
      Since:
        2.0

    - #### assertKeyNotNull

          protected void assertKeyNotNull(Object key)

      Assert that the key is not null. Throw a JDONullIdentityException if the given key is null.
      Parameters:
        `key` - The key to check
      Since:
        2.0

    - #### getTargetClass

          public Class getTargetClass()

      Return the target class.
      Returns:
        the target class.
      Since:
        2.0

    - #### getTargetClassName

          public String getTargetClassName()

      Return the target class name.
      Returns:
        the target class name.
      Since:
        2.0

    - #### getKeyAsObject

          public Object getKeyAsObject()

      Return the key as an Object. The method is synchronized to avoid race conditions in multi-threaded environments.
      Returns:
        the key as an Object.
      Since:
        2.0

    - #### createKeyAsObject

          protected Object createKeyAsObject()

      Create the key as an Object.
      Returns:
        the key as an Object;
      Since:
        2.0

    - #### equals

          public boolean equals(Object obj)

      Check the class and class name and object type. If restored from serialization, class will be null so compare class name.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `obj` - the other object
      Returns:
        true if the class or class name is the same

    - #### hashClassName

          protected int hashClassName()

      Return the hash code of the class name.
      Returns:
        the hash code of the class name
      Since:
        2.0

    - #### hashCode

          public int hashCode()

      Return the cached hash code.
      Overrides:
        `hashCode` in class `Object`
      Returns:
        the cached hash code.

    - #### writeExternal

          public void writeExternal(ObjectOutput out)
                             throws IOException

      Write to the output stream.
      Specified by:
        `writeExternal` in interface `Externalizable`
      Parameters:
        `out` - the stream
      Throws:
        `IOException`

    - #### readExternal

          public void readExternal(ObjectInput in)
                            throws IOException,
                                   ClassNotFoundException

      Read from the input stream. Creates a new instance with the target class name set
      Specified by:
        `readExternal` in interface `Externalizable`
      Throws:
        `IOException`
        `ClassNotFoundException`

    - #### compare

          protected int compare(SingleFieldIdentity o)

      Determine the ordering of identity objects. Only the class name is compared. This method is only used by subclasses.
      Parameters:
        `o` - Other identity
      Returns:
        The relative ordering between the objects
      Since:
        2.2

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.