it.amattioli.dominate
Class EntityImpl

Show UML class diagram
java.lang.Object
  extended by it.amattioli.dominate.EntityImpl
All Implemented Interfaces:
Entity<Long>, OptLockEntity<Long>, PropertyChangeEmitter

public class EntityImpl
extends Object
implements OptLockEntity<Long>, PropertyChangeEmitter

Typical implementation of an entity object whose identifier is a Long value.

This implementation can be used, for example, as a base class for object persisted on a relational database and whose primary key is generated using a sequence or an id field.

It has optimistic lock version property and property change support too

Author:
a.mattioli

Constructor Summary
EntityImpl()
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 boolean equals(Object obj)
          Two entities are equals if they have the same id and their classes are compatible.
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
           
 Long getId()
          Returns this entity object identifier.
 Long getVersion()
           
 int hashCode()
          Calculate this entity object hash code using its id
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void setId(Long id)
          Sets this entity object identifier.
 void setVersion(Long version)
           
 String toString()
          Return a string containing class name, id and version of the entity
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EntityImpl

public EntityImpl()
Method Detail

getId

public Long getId()
Description copied from interface: Entity
Returns this entity object identifier.

Specified by:
getId in interface Entity<Long>
Returns:
this entity object identifier

setId

public void setId(Long id)
Description copied from interface: Entity
Sets this entity object identifier.

Specified by:
setId in interface Entity<Long>
Parameters:
id - the identifier to be set

getVersion

public Long getVersion()
Specified by:
getVersion in interface OptLockEntity<Long>

setVersion

public void setVersion(Long version)
Specified by:
setVersion in interface OptLockEntity<Long>

equals

public boolean equals(Object obj)
Two entities are equals if they have the same id and their classes are compatible.

Overrides:
equals in class Object
Parameters:
obj - the object with which to compare
Returns:
true if this object is equal to obj, false otherwise
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Calculate this entity object hash code using its id

Overrides:
hashCode in class Object
Returns:
this entity object hash code
See Also:
Object.hashCode()

toString

public String toString()
Return a string containing class name, id and version of the entity

Overrides:
toString in class Object
Returns:
a string containing class name, id and version of the entity

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  Object oldValue,
                                  Object newValue)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface PropertyChangeEmitter

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface PropertyChangeEmitter


Copyright © 2011. All Rights Reserved.