org.infoglue.cms.entities.kernel
Class Persistent

java.lang.Object
  extended by org.infoglue.cms.entities.kernel.Persistent
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, BaseEntityVO
Direct Known Subclasses:
CategoryVO, ContentCategoryVO, PropertiesCategoryVO

public abstract class Persistent
extends java.lang.Object
implements BaseEntityVO, java.lang.Comparable, java.io.Serializable

This base class for persistent object makes it easy to define domain objects and have them implement the basic core services of an object that will allow them to treated properly by Lists, Sets, HashMaps, Comparators, etc. Once you have these services ironed out, it becomes much easier to deal with your domain objects and test the servies that use them

Author:
Frank Febbraro (frank@phase2technology.com)
See Also:
Serialized Form

Constructor Summary
Persistent()
           
 
Method Summary
static void append(java.lang.StringBuffer buffer, Persistent persistent)
          Appends the given persistent to the given string buffer.
 int compareTo(java.lang.Object o)
          Compares an object to this one for order.
 boolean equals(java.lang.Object o)
          Compares an object to this one for equality.
 int hashCode()
          Creates a hash code for this persistent.
 boolean isSaved()
          Returns if this persisten object is saved (has generated id)
 boolean isUnsaved()
          Returns if this persisten object is unsaved (no generated id)
 java.lang.String toString()
          Returns a string representation of this object.
protected  java.lang.StringBuffer toStringBuffer()
          Returns a string buffer representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.infoglue.cms.entities.kernel.BaseEntityVO
getId, validate
 

Constructor Detail

Persistent

public Persistent()
Method Detail

isUnsaved

public boolean isUnsaved()
Returns if this persisten object is unsaved (no generated id)


isSaved

public boolean isSaved()
Returns if this persisten object is saved (has generated id)


compareTo

public int compareTo(java.lang.Object o)
Compares an object to this one for order. The comparison is based on ID unless both are unsaved, in which case the comparison is done using hashCode(). This allows us to add multiple unsaved Persistents to sets even though they have the same ID.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the object to compare
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
Throws:
java.lang.ClassCastException - if o is not an instance of Persistent
java.lang.NullPointerException - if o is null
See Also:
hashCode()

equals

public boolean equals(java.lang.Object o)
Compares an object to this one for equality.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare
Returns:
true if this == o or o != null and getClass().equals(o.getClass()) and compareTo(o) == 0
See Also:
compareTo(java.lang.Object)

hashCode

public int hashCode()
Creates a hash code for this persistent.

Overrides:
hashCode in class java.lang.Object
Returns:
Object.hashCode() if unsaved, otherwise returns the id's hashCode()

toString

public java.lang.String toString()
Returns a string representation of this object. Subclasses that require a customized string representation should override toStringBuffer() rather than this method.

Overrides:
toString in class java.lang.Object
Returns:
toStringBuffer().toString()
See Also:
toStringBuffer()

toStringBuffer

protected java.lang.StringBuffer toStringBuffer()
Returns a string buffer representation of this object. The idea is that subclasses can grab the string buffer returned by this method and append to it, to save some gratuitous string creation.

Returns:
a StringBuffer representation of this object

append

public static void append(java.lang.StringBuffer buffer,
                          Persistent persistent)
Appends the given persistent to the given string buffer. This rather odd-looking method makes it easy for subclasses overriding toStringBuffer() (or anyone else, for that matter) to add only the ID of a related object to a string buffer without having to check for null. In practice, adding entire objects to the buffer returned by an overridden toStringBuffer() can make for a long string that's hard to read when debugging. This method helps restore some sanity when dealing with a large object that has a lot of relationships.

Parameters:
buffer - the desired StringBuffer
persistent - the desired Persistent
See Also:
toStringBuffer()


Copyright © 2005 InfoGlue.org All Rights Reserved.