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
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe hashCode.protected ObjectThe key as an Object.protected static I18NHelperThe Internationalization message helper.private ClassThe class of the target object.private StringThe name of the class of the target object. -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor only for Externalizable.protectedSingleFieldIdentity(Class pcClass) Constructor with target class. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassertKeyNotNull(Object key) Assert that the key is not null.protected intDetermine the ordering of identity objects.protected ObjectCreate the key as an Object.booleanCheck the class and class name and object type.Return the key as an Object.Return the target class.Return the target class name.protected intReturn the hash code of the class name.inthashCode()Return the cached hash code.voidRead from the input stream.protected voidsetKeyAsObject(Object key) Set the given key as the key for this instance.voidWrite to the output stream.Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparable
compareTo
-
Field Details
-
msg
The Internationalization message helper. -
targetClass
The class of the target object. -
targetClassName
The name of the class of the target object. -
hashCode
protected int hashCodeThe hashCode. -
keyAsObject
The key as an Object.
-
-
Constructor Details
-
SingleFieldIdentity
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 Details
-
setKeyAsObject
Set the given key as the key for this instance. Compute the hash code for the instance.- Since:
- 2.0
-
assertKeyNotNull
Assert that the key is not null. Throw a JDONullIdentityException if the given key is null.- Since:
- 2.0
-
getTargetClass
-
getTargetClassName
Return the target class name.- Returns:
- the target class name.
- Since:
- 2.0
-
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
Create the key as an Object.- Returns:
- the key as an Object;
- Since:
- 2.0
-
equals
-
hashClassName
protected int hashClassName()Return the hash code of the class name.- Returns:
- the hash code of the class name
- Since:
- 2.0
-
hashCode
-
writeExternal
Write to the output stream.- Specified by:
writeExternalin interfaceExternalizable- Parameters:
out- the stream- Throws:
IOException
-
readExternal
Read from the input stream. Creates a new instance with the target class name set- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
compare
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
-