javax.jdo.identity
Class SingleFieldIdentity
java.lang.Object
javax.jdo.identity.SingleFieldIdentity
- Externalizable
public abstract class SingleFieldIdentity
extends java.lang.Object
implements Externalizable
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.
hashCode
protected int hashCode
The hashCode.
keyAsObject
protected Object keyAsObject
The key as an Object.
msg
protected static I18NHelper msg
The Internationalization message helper.
SingleFieldIdentity
public SingleFieldIdentity()
Constructor only for Externalizable.
SingleFieldIdentity
protected SingleFieldIdentity(Class pcClass)
Constructor with target class.
pcClass
- the class of the target
assertKeyNotNull
protected void assertKeyNotNull(Object key)
Assert that the key is not null. Throw a JDONullIdentityException
if the given key is null.
createKeyAsObject
protected Object createKeyAsObject()
Create the key as an Object.
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.
- true if the class or class name is the same
getKeyAsObject
public Object getKeyAsObject()
Return the key as an Object. The method is synchronized to avoid
race conditions in multi-threaded environments.
getTargetClass
public Class getTargetClass()
Return the target class.
getTargetClassName
public String getTargetClassName()
Return the target class name.
hashClassName
protected int hashClassName()
Return the hash code of the class name.
- the hash code of the class name
hashCode
public int hashCode()
Return the cached hash code.
readExternal
public void readExternal(ObjectInput in)
throws IOException,
ClassNotFoundException
Read from the input stream.
Creates a new instance with the target class name set
setKeyAsObject
protected void setKeyAsObject(Object key)
Set the given key as the key for this instance.
Compute the hash code for the instance.
writeExternal
public void writeExternal(ObjectOutput out)
throws IOException
Write to the output stream.