SPT Core API

com.sptci.jdo
Class JDOObject

java.lang.Object
  extended by com.sptci.jdo.JDOObject
All Implemented Interfaces:
Serializable, Cloneable, Comparable<JDOObject>, javax.jdo.InstanceCallbacks, javax.jdo.listener.ClearCallback, javax.jdo.listener.DeleteCallback, javax.jdo.listener.LoadCallback, javax.jdo.listener.StoreCallback
Direct Known Subclasses:
NameDescription, User

public abstract class JDOObject
extends Object
implements Cloneable, Comparable<JDOObject>, Serializable, javax.jdo.InstanceCallbacks

A base object from which all the JDO Object classes will be derived. Provides default implementations for common methods.

Copyright 2006, Sans Pareil Technologies, Inc.

Version:
$Id: JDOObject.java 4618 2009-02-10 00:49:30Z rakesh $
Author:
Rakesh Vidyadharan 05th February, 2006
See Also:
Serialized Form

Field Summary
protected  int hash
          The integer that represents the hash code for this object.
protected static int HASH
          The default value to use for hash.
protected static Logger logger
          The logger to use to log errors or messages to.
protected  StartLetter startLetter
          The start letter for the primary string identifier for the object.
 
Constructor Summary
protected JDOObject()
          Default constructor.
 
Method Summary
 Object clone()
          Creates and returns a copy of this object.
 int compareTo(JDOObject object)
          Compares this object with the specified object for order.
protected static XStream createXStream()
          Return the utility used to convert the object to and from XML representation.
 boolean equals(Object object)
          Default implementation of equality checking.
static JDOObject fromXML(String xml)
          Parse the object out of the XML representation of this object.
 Object getObjectId()
          Return the ObjectId of this persistent instance.
 javax.jdo.PersistenceManager getPersistenceManager()
          Return the persistence manager associated with this instance.
 StartLetter getStartLetter()
          Return the reference to the starting letter of the primary string field for this instance.
 int hashCode()
          Default computation of a hash code for the object.
 void jdoPostLoad()
          InstanceCallbacks method implementation.
 void jdoPreClear()
          InstanceCallbacks method implementation.
 void jdoPreDelete()
          InstanceCallbacks method implementation.
 void jdoPreStore()
          InstanceCallbacks method implementation.
protected  void resetHash()
          Reset the hash value.
 String toString()
          Return a string representation of this object.
 String toXML()
          Return an XML representation of the fields of this object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static final Logger logger
The logger to use to log errors or messages to.


HASH

protected static final int HASH
The default value to use for hash.

See Also:
Constant Field Values

hash

protected transient int hash
The integer that represents the hash code for this object.


startLetter

protected StartLetter startLetter
The start letter for the primary string identifier for the object. Useful for building alphabetical indices in applications. Creation and maintenance of the alphabetical indices are handled automatically by the Factory.save(T, javax.jdo.PersistenceManager) and Factory.delete(T, javax.jdo.PersistenceManager) methods.

Note: Instances of StartLetter are shared across multiple instances and hence need to be maintained separately. In particular obsolete instances of this class need to be cleaned up when deleting instances of JDOObject. Obsolete instances are created when the current entity is the only instance associated with a particular StartLetter.

Note: A default StartLetter is assigned to instances of classes that do not need alphabetical index support.

Constructor Detail

JDOObject

protected JDOObject()
Default constructor. Cannot be instantiated.

Method Detail

toString

public String toString()
Return a string representation of this object. Return an XML representation of the data-fields.

Overrides:
toString in class Object
Returns:
String The xml representation of this class.
See Also:
toXML()

clone

public Object clone()
             throws CloneNotSupportedException
Creates and returns a copy of this object. Implementation of the Cloneable interface. No special actions are performed. This method simply allows public access to the Object.clone method.

Overrides:
clone in class Object
Returns:
Object A clone of this instance.
Throws:
CloneNotSupportedException - If the super-class implementation throws an error.

equals

public boolean equals(Object object)
Default implementation of equality checking. Two objects are considered equal if they have the same ObjectId. If this instance is transient, then the super-class implementation of equals is used.

Note: Sub-classes are encouraged to over-ride this method if special equality checking rules are desired.

Overrides:
equals in class Object
Parameters:
object - The object that is to be compared for equality.
Returns:
Return true if the specified object is of the same type as this object and has the same ObjectId.

hashCode

public int hashCode()
Default computation of a hash code for the object. Computes the hash code for the ObjectId. If the instance if transient return the value as obtained from the super-class implementation.

Overrides:
hashCode in class Object
Returns:
The hash code for this object.

compareTo

public int compareTo(JDOObject object)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Note: The default implementation just compares the hashCode() values. It is recommended that sub-classes over-ride this method for appropriate sort order.

Specified by:
compareTo in interface Comparable<JDOObject>
Parameters:
object - The object that is to be compared with this object.
Returns:
int A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

createXStream

protected static XStream createXStream()
Return the utility used to convert the object to and from XML representation. This method must be used by the toXML() and fromXML(java.lang.String) methods to initialise the serialiser in a standard manner.

Returns:
The XML serialiser instance to use.

toXML

public String toXML()
Return an XML representation of the fields of this object. It is recommended that sub-classes over-ride this method to specify good aliases for fully qualified class names to make the XML for readable.

Note: Currently this method uses the XStream API to convert the object into XML. This may be modified at a later date to convert into a TMS standard XML format.

Returns:
String - The string representation of this object.
See Also:
createXStream(), fromXML(java.lang.String)

fromXML

public static JDOObject fromXML(String xml)
Parse the object out of the XML representation of this object. It is recommended that sub-classes over-ride this method to specify good aliases for fully qualified class names to make the XML for readable.

Parameters:
xml - The XML representation of this object.
Returns:
Program The object parsed out of the XML representation.
See Also:
createXStream(), toXML()

resetHash

protected void resetHash()
Reset the hash value.


getObjectId

public Object getObjectId()
Return the ObjectId of this persistent instance.

Returns:
The ObjectId of this instance. Returns null if this instance is transient.
See Also:
JDOHelper.getObjectId

getPersistenceManager

public javax.jdo.PersistenceManager getPersistenceManager()
Return the persistence manager associated with this instance.

Returns:
The PM associated with this instance. Return null if this instance is not persistent.
See Also:
JDOHelper.getPersistenceManager

getStartLetter

public StartLetter getStartLetter()
Return the reference to the starting letter of the primary string field for this instance.

Returns:
The reference to the start letter.

jdoPostLoad

public void jdoPostLoad()
InstanceCallbacks method implementation. No actions required by default.

Specified by:
jdoPostLoad in interface javax.jdo.listener.LoadCallback

jdoPreStore

public void jdoPreStore()
InstanceCallbacks method implementation. No actions required.

Specified by:
jdoPreStore in interface javax.jdo.listener.StoreCallback

jdoPreClear

public void jdoPreClear()
InstanceCallbacks method implementation. No actions required.

Specified by:
jdoPreClear in interface javax.jdo.listener.ClearCallback

jdoPreDelete

public void jdoPreDelete()
InstanceCallbacks method implementation. No actions required.

Specified by:
jdoPreDelete in interface javax.jdo.listener.DeleteCallback

SPT Core API