net.sf.jzeno.model
Class AbstractEntity

java.lang.Object
  extended by net.sf.jzeno.model.AbstractEntity
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Entity
Direct Known Subclasses:
AbstractMutableEntity, PersistentEnum

public abstract class AbstractEntity
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Entity

Base class that model objects can derive from. It implements the equals and hashCode operation in a generic fashion... It does not support optimistic locking.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
AbstractEntity()
           
 
Method Summary
 java.lang.Object clone()
           Clone for an abstract entity takes care of a few things for you : First, clear originalValues (thus all cloned entities will return true for any isChanged(propertyName) call where the original value was not null); secondly, replace all persistent collections by new instances (to prevent collection proxies belonging to object being cloned to be associated in the database to the clone); And finally, this clone operation resets the Id property to null, waiting for the database to generate a new identity.
 int compareTo(java.lang.Object o)
           define the natural ordering of abstract entities
 boolean equals(java.lang.Object other)
           Equals is implemented to evaluate newly created objects, that hence do not have a unique identifier yet, as NOT identical, so that they may be added to the Set variables that manage our model relationships.
 java.lang.Object getChangedValue(java.lang.String propertyName)
           
 java.util.Map getChangedValues()
           
abstract  java.lang.Long getId()
           Subclasses should implement the 'id' property and map it to the right DB column..
 java.lang.Object getOriginalValue(java.lang.String propertyName)
           
 java.util.Map getOriginalValues()
          Must return the *internal* hashmap that is used for storing original values This is important because Entity detection in the AutoSync mechanism excludes the original values maps when it traverses an object graph.
 int hashCode()
           As equals is overridden, the hashCode operation needs to be made consistent.
 boolean isChanged()
           Returns true if any property has changed since it was loaded from the database.
 boolean isChanged(java.lang.String propertyName)
           Returns true if the given property has changed since it was last snapshot.
 java.lang.Boolean isUnsaved(Entity entity)
           
 void onDelete(Entity entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
           
 boolean onFlushDirty(Entity entity, java.io.Serializable id, java.lang.Object[] state, java.lang.Object[] previousState, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
           
 boolean onLoad(Entity entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
           
 boolean onSave(Entity entity, java.io.Serializable arg1, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
           
 void postFlush()
           Executed after an object has been flushed to the database.
 void preFlush()
           
abstract  void setId(java.lang.Long id)
           
 void snapshot()
           Store the current content of this entity, for difference analysis later.
 int superHashCode()
           For debugging purposes.
 java.lang.String toString()
           Generic version of the toString operation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

AbstractEntity

public AbstractEntity()
Method Detail

getId

public abstract java.lang.Long getId()

Subclasses should implement the 'id' property and map it to the right DB column..

Specified by:
getId in interface Entity

setId

public abstract void setId(java.lang.Long id)
Specified by:
setId in interface Entity

equals

public boolean equals(java.lang.Object other)

Equals is implemented to evaluate newly created objects, that hence do not have a unique identifier yet, as NOT identical, so that they may be added to the Set variables that manage our model relationships.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

As equals is overridden, the hashCode operation needs to be made consistent.

Overrides:
hashCode in class java.lang.Object

superHashCode

public int superHashCode()

For debugging purposes.


toString

public java.lang.String toString()

Generic version of the toString operation. By default it returns a clear description of the object type and the unique identity (identifier) of this object..

Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()

Clone for an abstract entity takes care of a few things for you : First, clear originalValues (thus all cloned entities will return true for any isChanged(propertyName) call where the original value was not null); secondly, replace all persistent collections by new instances (to prevent collection proxies belonging to object being cloned to be associated in the database to the clone); And finally, this clone operation resets the Id property to null, waiting for the database to generate a new identity.

Overrides:
clone in class java.lang.Object

isUnsaved

public java.lang.Boolean isUnsaved(Entity entity)
Specified by:
isUnsaved in interface Entity

onDelete

public void onDelete(Entity entity,
                     java.io.Serializable id,
                     java.lang.Object[] state,
                     java.lang.String[] propertyNames,
                     org.hibernate.type.Type[] types)
              throws org.hibernate.CallbackException
Specified by:
onDelete in interface Entity
Throws:
org.hibernate.CallbackException

onFlushDirty

public boolean onFlushDirty(Entity entity,
                            java.io.Serializable id,
                            java.lang.Object[] state,
                            java.lang.Object[] previousState,
                            java.lang.String[] propertyNames,
                            org.hibernate.type.Type[] types)
                     throws org.hibernate.CallbackException
Specified by:
onFlushDirty in interface Entity
Throws:
org.hibernate.CallbackException

onLoad

public boolean onLoad(Entity entity,
                      java.io.Serializable id,
                      java.lang.Object[] state,
                      java.lang.String[] propertyNames,
                      org.hibernate.type.Type[] types)
               throws org.hibernate.CallbackException
Specified by:
onLoad in interface Entity
Throws:
org.hibernate.CallbackException

onSave

public boolean onSave(Entity entity,
                      java.io.Serializable arg1,
                      java.lang.Object[] state,
                      java.lang.String[] propertyNames,
                      org.hibernate.type.Type[] types)
               throws org.hibernate.CallbackException
Specified by:
onSave in interface Entity
Throws:
org.hibernate.CallbackException

postFlush

public void postFlush()

Executed after an object has been flushed to the database.

Specified by:
postFlush in interface Entity

preFlush

public void preFlush()
Specified by:
preFlush in interface Entity

compareTo

public int compareTo(java.lang.Object o)

define the natural ordering of abstract entities

Specified by:
compareTo in interface java.lang.Comparable

snapshot

public void snapshot()
Description copied from interface: Entity

Store the current content of this entity, for difference analysis later. This operation is called after calling a business facade on all loaded objects by default.

Specified by:
snapshot in interface Entity

getOriginalValue

public java.lang.Object getOriginalValue(java.lang.String propertyName)
Specified by:
getOriginalValue in interface Entity

getOriginalValues

public java.util.Map getOriginalValues()
Description copied from interface: Entity
Must return the *internal* hashmap that is used for storing original values This is important because Entity detection in the AutoSync mechanism excludes the original values maps when it traverses an object graph.

Specified by:
getOriginalValues in interface Entity

getChangedValue

public java.lang.Object getChangedValue(java.lang.String propertyName)
Specified by:
getChangedValue in interface Entity

getChangedValues

public java.util.Map getChangedValues()
Specified by:
getChangedValues in interface Entity

isChanged

public boolean isChanged(java.lang.String propertyName)

Returns true if the given property has changed since it was last snapshot. Typically this means 'loaded from the database'.

Specified by:
isChanged in interface Entity

isChanged

public boolean isChanged()

Returns true if any property has changed since it was loaded from the database.

Specified by:
isChanged in interface Entity