Package org.datanucleus.identity
Class ObjectId
- java.lang.Object
-
- org.datanucleus.identity.SingleFieldId<java.lang.Object,ObjectId>
-
- org.datanucleus.identity.ObjectId
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,java.lang.Comparable<ObjectId>
public class ObjectId extends SingleFieldId<java.lang.Object,ObjectId>
This class is for identity with a single Object type field.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ObjectId.StringConstructor
Construct an instance of a key class using a String as input.
-
Field Summary
Fields Modifier and Type Field Description private static java.text.DateFormat
dateFormat
The default DateFormat instance for handling java.util.Date instances.private java.lang.Object
key
(package private) static java.util.Map<java.lang.Class,ObjectId.StringConstructor>
stringConstructorMap
Special StringConstructor instances for use with specific classes that have no public String constructor.-
Fields inherited from class org.datanucleus.identity.SingleFieldId
hashCode, STRING_DELIMITER, targetClassName
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(ObjectId other)
static java.lang.Object
constructKey(java.lang.String className, java.lang.String keyString)
Construct an instance of the parameter class, using the keyString as an argument to the constructor.java.lang.Object
getKey()
java.lang.Object
getKeyAsObject()
Accessor for the keyprotected boolean
keyEquals(ObjectId obj)
void
readExternal(java.io.ObjectInput in)
Read this object.static java.lang.Object
registerStringConstructor(java.lang.Class cls, ObjectId.StringConstructor sc)
Register special StringConstructor instances.java.lang.String
toString()
Return the String form of the object id.void
writeExternal(java.io.ObjectOutput out)
Write this object.-
Methods inherited from class org.datanucleus.identity.SingleFieldId
assertKeyNotNull, compare, equals, getTargetClassName, hashCode
-
-
-
-
Field Detail
-
key
private java.lang.Object key
-
stringConstructorMap
static final java.util.Map<java.lang.Class,ObjectId.StringConstructor> stringConstructorMap
Special StringConstructor instances for use with specific classes that have no public String constructor. The Map is keyed on class instance and the value is an instance of StringConstructor.
-
dateFormat
private static java.text.DateFormat dateFormat
The default DateFormat instance for handling java.util.Date instances.
-
-
Method Detail
-
getKey
public java.lang.Object getKey()
-
getKeyAsObject
public java.lang.Object getKeyAsObject()
Description copied from class:SingleFieldId
Accessor for the key- Specified by:
getKeyAsObject
in classSingleFieldId<java.lang.Object,ObjectId>
- Returns:
- The key
-
toString
public java.lang.String toString()
Return the String form of the object id. The class of the object id is written as the first part of the result so that the class can be reconstructed later. Then the toString of the key instance is appended. During construction, this process is reversed. The class is extracted from the first part of the String, and the String constructor of the key is used to construct the key itself.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the String form of the key
-
keyEquals
protected boolean keyEquals(ObjectId obj)
- Specified by:
keyEquals
in classSingleFieldId<java.lang.Object,ObjectId>
-
compareTo
public int compareTo(ObjectId other)
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
Write this object. Write the superclass first.- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Overrides:
writeExternal
in classSingleFieldId<java.lang.Object,ObjectId>
- Parameters:
out
- the output- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
Read this object. Read the superclass first.- Specified by:
readExternal
in interfacejava.io.Externalizable
- Overrides:
readExternal
in classSingleFieldId<java.lang.Object,ObjectId>
- Parameters:
in
- the input- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
registerStringConstructor
public static java.lang.Object registerStringConstructor(java.lang.Class cls, ObjectId.StringConstructor sc)
Register special StringConstructor instances. These instances are for constructing instances from String parameters where there is no String constructor for them.- Parameters:
cls
- the class to register a StringConstructor forsc
- the StringConstructor instance- Returns:
- the previous StringConstructor registered for this class
-
constructKey
public static java.lang.Object constructKey(java.lang.String className, java.lang.String keyString)
Construct an instance of the parameter class, using the keyString as an argument to the constructor. If the class has a StringConstructor instance registered, use it. If not, try to find a constructor for the class with a single String argument. Otherwise, throw a NucleusUserException.- Parameters:
className
- the name of the classkeyString
- the String parameter for the constructor- Returns:
- the result of construction
-
-