SPT Core API

com.sptci.jpa
Class JPAObject

java.lang.Object
  extended by com.sptci.jpa.JPAObject
All Implemented Interfaces:
Serializable, Cloneable, Comparable<JPAObject>
Direct Known Subclasses:
NameDescription, StartLetter

public abstract class JPAObject
extends Object
implements Cloneable, Comparable<JPAObject>, Serializable

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

© Copyright 2007, Sans Pareil Technologies, Inc.

Version:
$Id: JPAObject.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2007-05-24
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  Long oid
          The object id (primary key) for the object instance.
protected  StartLetter startLetter
          The start letter for the primary string identifier for the object.
 
Constructor Summary
protected JPAObject()
          Default constructor.
 
Method Summary
 Object clone()
          Creates and returns a copy of this object.
 int compareTo(JPAObject 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 JPAObject fromXML(String xml)
          Parse the object out of the XML representation of this object.
 Object getObjectId()
          Return the ObjectId of this persistent instance.
 StartLetter getStartLetter()
          Returns startLetter.
 int hashCode()
          Default computation of a hash code for the object.
 void jdoPostLoad()
          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 int hash
The integer that represents the hash code for this object.


oid

protected Long oid
The object id (primary key) for the object instance.


startLetter

protected StartLetter startLetter
The start letter for the primary string identifier for the object. Useful for building alphabeetical indices in applications.

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 JPAObject. Obsolete instances are created when the current entity is the only instance associated with a particular StartLetter.

Constructor Detail

JPAObject

protected JPAObject()
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(JPAObject 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<JPAObject>
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.


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 JPAObject 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.

getStartLetter

public StartLetter getStartLetter()
Returns startLetter.

Returns:
The value/reference of/to startLetter.

jdoPostLoad

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


jdoPreStore

public void jdoPreStore()
InstanceCallbacks method implementation. Computes hash code.


jdoPreDelete

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


SPT Core API