org.datanucleus.identity
Class SingleFieldIdentity

java.lang.Object
  extended by org.datanucleus.identity.SingleFieldIdentity
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
ByteIdentity, CharIdentity, IntIdentity, LongIdentity, ObjectIdentity, ShortIdentity, StringIdentity

public abstract class SingleFieldIdentity
extends java.lang.Object
implements java.io.Externalizable, java.lang.Comparable

Abstract base class for all single-field identity classes.

See Also:
Serialized Form

Field Summary
protected  int hashCode
          The hashCode.
protected  java.lang.Object keyAsObject
          The key as an Object.
 
Constructor Summary
  SingleFieldIdentity()
          Constructor only for Externalizable.
protected SingleFieldIdentity(java.lang.Class pcClass)
          Constructor with target class.
 
Method Summary
protected  void assertKeyNotNull(java.lang.Object key)
          Assert that the key is not null.
protected  java.lang.Object createKeyAsObject()
          Create the key as an Object.
 boolean equals(java.lang.Object obj)
          Check the class and class name and object type.
 java.lang.Object getKeyAsObject()
          Return the key as an Object.
 java.lang.Class getTargetClass()
          Return the target class.
 java.lang.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(java.io.ObjectInput in)
          Read from the input stream.
protected  void setKeyAsObject(java.lang.Object key)
          Set the given key as the key for this instance.
 void writeExternal(java.io.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

hashCode

protected int hashCode
The hashCode.


keyAsObject

protected java.lang.Object keyAsObject
The key as an Object.

Constructor Detail

SingleFieldIdentity

protected SingleFieldIdentity(java.lang.Class pcClass)
Constructor with target class.

Parameters:
pcClass - the class of the target

SingleFieldIdentity

public SingleFieldIdentity()
Constructor only for Externalizable.

Method Detail

setKeyAsObject

protected void setKeyAsObject(java.lang.Object key)
Set the given key as the key for this instance. Compute the hash code for the instance.


assertKeyNotNull

protected void assertKeyNotNull(java.lang.Object key)
Assert that the key is not null. Throw a JDONullIdentityException if the given key is null.


getTargetClass

public java.lang.Class getTargetClass()
Return the target class.

Returns:
the target class.
Since:
2.0

getTargetClassName

public java.lang.String getTargetClassName()
Return the target class name.

Returns:
the target class name.

getKeyAsObject

public java.lang.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.

createKeyAsObject

protected java.lang.Object createKeyAsObject()
Create the key as an Object.

Returns:
the key as an Object;

equals

public boolean equals(java.lang.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 java.lang.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

hashCode

public int hashCode()
Return the cached hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
the cached hash code.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Write to the output stream.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - the stream
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Read from the input stream. Creates a new instance with the target class name set.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - Input
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 2009. All Rights Reserved.