SRJRCFrames
v0.1.296

de.schwarzrot.data.support
Class AbstractEntity

java.lang.Object
  extended by com.jgoodies.binding.beans.Model
      extended by de.schwarzrot.data.support.AbstractEntity
All Implemented Interfaces:
com.jgoodies.binding.beans.Observable, Entity, Serializable, Comparable<Entity>
Direct Known Subclasses:
AbstractConfigBase, AbstractEntityReference, AbstractMetaEntity, DriveMapping, Option, OptionBundle, PageProperties, ServiceDefinition, User

public abstract class AbstractEntity
extends com.jgoodies.binding.beans.Model
implements Entity

cuts off all persistence necessities from business objects. So the business-classes could be coded and used like standard beans. This base class in cooperation with Repository and EntityManagers does all the tedious stuff you don't really wonna care about.

Author:
Reinhard Mantey
See Also:
Repository, EntityManager, EntityDescriptor, Serialized Form

Constructor Summary
AbstractEntity()
          bean like constructor (use for "real" instances")
AbstractEntity(AbstractEntity other)
           
 
Method Summary
<E extends ChildEntity>
void
adoptChildren(List<E> children)
           
<E extends ChildEntity>
void
adoptChildren(Map<?,E> children)
           
<E extends ChildEntity>
void
adoptGroupedChildren(Map<?,List<E>> children)
           
 int compareTo(Entity other)
           
 boolean equals(Object any)
           
 Long getCModified()
          returns the number of modifications that happened to this instance.
 Comparable<?> getCode()
           
 List<SortInfo> getDefaultOrder()
          returns a list of SortInfo, that build the order for default list-queries.
 Date getDtCreated()
          returns the timestamp when this instance was created
 Date getDtModified()
          returns the timestamp of the last saving operation.
 Long getId()
          returns the id of an Entity-instance.
protected  org.apache.commons.logging.Log getLogger()
           
 Map<String,String> getMappings()
          returns a map with mappings of logical property names to physical property names (column names in database terms).
 String getPersistenceName()
          returns the name of the entity for persistance.
 String getSchemaName()
          returns the schema for this entity.
 Map<String,Integer> getSkipList()
          returns a map with property names, that EntityManagers should ignore.
 Class<?> getSystemClass()
          return the classtype for system usage
 String getUCreated()
          returns the name of the user, that created this instance
 String getUModified()
          returns the name of the user, that triggered the last write operation for this instance.
 List<String> getUniqColumnNames()
          returns a list of property names, which serve to detect a uniq instance without the usage of the primary key.
 List<String> getUserAttributes()
          return a list of properties, that are user attributes.
 String getVariantColumnName()
          returns the name of the property that is used to distinguish Entity-variants.
 Map<Object,String> getVariantTypeMap()
          returns a map with the content of getVariantColumnName as key and fully qualified classnames as value.
 int hashCode()
           
 boolean isDirty()
          returns whether the instance contains changes not saved to persistence.
 boolean isUserType()
          returns true, if this entity is a usertype and false, if it is a system type
 boolean isVirtual()
          returns whether this class is virtual or real.
 void setCModified(Long modified)
          set's the number of modifications, that happened to this instance.
 void setDirty(boolean dirty)
          marks an instance as dirty, which means the instance has changes, not written to persistence yet.
 void setDtCreated(Date dtCreated)
          set's the timestamp of the moment, this instance was created.
 void setDtModified(Date dtModified)
          set's the timestamp of the last modification.
 void setId(Long id)
          set's the id of this instance.
static void setSchemaName(String schemaName)
           
 void setUCreated(String created)
          set's the name of the user, that created this instance.
 void setUModified(String modified)
          set's the name of the user, that performed the last modification of this instance.
 String toString()
           
 void validate(boolean read)
          will be called just before saving and after loading, so it is intended to give the opportunity to calculate virtual fields.
 
Methods inherited from class com.jgoodies.binding.beans.Model
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jgoodies.binding.beans.Observable
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

AbstractEntity

public AbstractEntity()
bean like constructor (use for "real" instances")


AbstractEntity

public AbstractEntity(AbstractEntity other)
Method Detail

adoptChildren

public <E extends ChildEntity> void adoptChildren(List<E> children)

adoptChildren

public <E extends ChildEntity> void adoptChildren(Map<?,E> children)

adoptGroupedChildren

public <E extends ChildEntity> void adoptGroupedChildren(Map<?,List<E>> children)

compareTo

public int compareTo(Entity other)
              throws IllegalArgumentException
Specified by:
compareTo in interface Comparable<Entity>
Throws:
IllegalArgumentException

equals

public boolean equals(Object any)
Overrides:
equals in class Object

getCModified

public final Long getCModified()
Description copied from interface: Entity
returns the number of modifications that happened to this instance.

Specified by:
getCModified in interface Entity
Returns:
a modification counter

getCode

public Comparable<?> getCode()

getDefaultOrder

public List<SortInfo> getDefaultOrder()
Description copied from interface: Entity
returns a list of SortInfo, that build the order for default list-queries.

Specified by:
getDefaultOrder in interface Entity
Returns:
a list of property names

getDtCreated

public final Date getDtCreated()
Description copied from interface: Entity
returns the timestamp when this instance was created

Specified by:
getDtCreated in interface Entity
Returns:
a timestamp

getDtModified

public final Date getDtModified()
Description copied from interface: Entity
returns the timestamp of the last saving operation.

Specified by:
getDtModified in interface Entity
Returns:
a timestamp

getId

public final Long getId()
Description copied from interface: Entity
returns the id of an Entity-instance. Normally the id are the primary key for the instances in persistence layer.

Specified by:
getId in interface Entity
Returns:
the id of an instance

getMappings

public Map<String,String> getMappings()
Description copied from interface: Entity
returns a map with mappings of logical property names to physical property names (column names in database terms).

Every implementation should respect the parents mappings. The following sample shows different mapping types:

 public Map<String, String> getMappings() {
     Map<String, String> mappings = super.getMappings();
     mappings.put("title", "name");
     mappings.put("streams", Stream.class.getName());
     mappings.put("pageDefinitions", "pageType|" + ThemeElement.class.getName());
     return mappings;
 }
 
The mappings explained:
"title" -> "name"
the logical "title"-attribute is stored to persistence with a physical name "name"
"streams" -> Stream.class.getName()
the "streams" property holds related children. Unknown children are hold in a List, known (named) children are hold in a Map. The mapped value is used as classname to create child instances.
"pageDefinitions" -> "pageType|" + ThemeElement.class.getName()
pageDefinitions is a property of type Map, that holds grouped children. Known children are hold by a Map, unknown children by a List, so "pageDefinitions" may contain elements of type Map, or List. pageType, a property of ThemeElement, is used to group the children. The word before the '|' is the property name used as key value for grouping and the type after '|' is used to create instances.

Specified by:
getMappings in interface Entity
Returns:
a Map with property names as keys and column names as values.

getPersistenceName

public String getPersistenceName()
Description copied from interface: Entity
returns the name of the entity for persistance. Normally it would be the same result as getClass().getSimpleName(), but some storage may have size limitations, or don't support case sensitive names, so this call is to deal with that kind of limitations.

Specified by:
getPersistenceName in interface Entity
Returns:
the entity-name used for persistence

getSchemaName

public String getSchemaName()
Description copied from interface: Entity
returns the schema for this entity. Not all storage types support schemata, so on systems, where the schema is not supported, it will be a prefix to the persistent name.

Specified by:
getSchemaName in interface Entity
Returns:
a schema name

getSkipList

public Map<String,Integer> getSkipList()
Description copied from interface: Entity
returns a map with property names, that EntityManagers should ignore. These properties may be virtual properties, that not should be saved to persistence and/or methods that start with 'get' and that are not getters.

Implemention uses HashMaps for performance reasons, but the values are never used. So the map consists of propertynames as keys and an Integer as Value.

Every implementation should use the Map from parent class:

 public Map<String, Integer> getSkipList() {
     Map<String, Integer> skipList = super.getSkipList();
     skipList.put("a_virtual_field", 1);
     return skipList;
 }
 

Specified by:
getSkipList in interface Entity
Returns:
a Map

getSystemClass

public Class<?> getSystemClass()
Description copied from interface: Entity
return the classtype for system usage

Specified by:
getSystemClass in interface Entity
Returns:
a class

getUCreated

public final String getUCreated()
Description copied from interface: Entity
returns the name of the user, that created this instance

Specified by:
getUCreated in interface Entity
Returns:
a username

getUModified

public final String getUModified()
Description copied from interface: Entity
returns the name of the user, that triggered the last write operation for this instance.

Specified by:
getUModified in interface Entity
Returns:
a username

getUniqColumnNames

public List<String> getUniqColumnNames()
Description copied from interface: Entity
returns a list of property names, which serve to detect a uniq instance without the usage of the primary key. In database context this list is used to decide, whether a save operation needs an update or an insert.

Specified by:
getUniqColumnNames in interface Entity
Returns:
a list of property names

getUserAttributes

public List<String> getUserAttributes()
Description copied from interface: Entity
return a list of properties, that are user attributes. Default is to return null to signal, that all properties are user attributes. In case this entity is a system entity, there may exists attributes, that may be overridded by users. So return a list of those attributes.

Specified by:
getUserAttributes in interface Entity
Returns:
a list of property names

getVariantColumnName

public String getVariantColumnName()
Description copied from interface: Entity
returns the name of the property that is used to distinguish Entity-variants. This is neede, if several entities share the same storage, so the real classname has to be determined by a stored value.

Specified by:
getVariantColumnName in interface Entity
Returns:
the name of a property

getVariantTypeMap

public Map<Object,String> getVariantTypeMap()
Description copied from interface: Entity
returns a map with the content of getVariantColumnName as key and fully qualified classnames as value.

There are 2 types of polymorphism supported:

known children
all derived types are known and not expected to increase. In this case a shortcut could be saved to persistence which gets resolved by this map.
unknown children
the type system is open for user expansion. In this case the returned map must be null and the content of the getVariantColumnName must hold the canonical class name of the java classes.

Example (for known children): suppose a table animals that should hold entities Cat and Dog. The class Animal will overload the method getPersistenceName, wich returns "animal". Additionally it will declare an Enum as

 Enum Animal { 
  CAT,
  DOG
 };
 
as well as a property animalType of type Animal. The constructor of Cat initializes the property animalType with CAT, the constructor of Dog initializes the property animalType with DOG. The variantTypeMap returned will then look like:
 Map<Animal, String> variantTypeMap = new HashMap<Animal, String>();
 
 variantTypeMap.put(CAT, Cat.class.getName());
 variantTypeMap.put(DOG, Dog.class.getName());
 

Example (for known children): if the sample from above should support more animals, even those unknown at time of writing, getVariantTypeMap() should return null . The content of column animalType should then match Cat.class.getName() instead of just Cat.

Specified by:
getVariantTypeMap in interface Entity
Returns:
a map with values of getVariantColumnName as key and fully qualified classnames as value, or null for unknown child types.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isDirty

public final boolean isDirty()
Description copied from interface: Entity
returns whether the instance contains changes not saved to persistence.

Specified by:
isDirty in interface Entity
Returns:
boolean

isUserType

public boolean isUserType()
Description copied from interface: Entity
returns true, if this entity is a usertype and false, if it is a system type

Specified by:
isUserType in interface Entity
Returns:
true or false

isVirtual

public boolean isVirtual()
Description copied from interface: Entity
returns whether this class is virtual or real.

When you have a table, that should contain animals and you implent classes for each animal type, you don't want that instances of class Animal should exists. Normally you would make such a class abstract, but this is forbidden for beans and so for entities! This method signals the EntityManager that Animal is not the type of the entity. Instead it has to be determined by the loaded content.

Specified by:
isVirtual in interface Entity
Returns:
true for virtual (abstract) classes, default false

setCModified

public final void setCModified(Long modified)
Description copied from interface: Entity
set's the number of modifications, that happened to this instance.
This method should be considered internal!.

Specified by:
setCModified in interface Entity
Parameters:
modified - the new modification counter

setDirty

public void setDirty(boolean dirty)
Description copied from interface: Entity
marks an instance as dirty, which means the instance has changes, not written to persistence yet. Each setter should observe the changes and mark the instance as dirty as necessary.

Specified by:
setDirty in interface Entity
Parameters:
dirty - - true if instance has unsafed changes
See Also:
AbstractEntity

setDtCreated

public final void setDtCreated(Date dtCreated)
Description copied from interface: Entity
set's the timestamp of the moment, this instance was created.
This method should be considered internal!.

Specified by:
setDtCreated in interface Entity
Parameters:
dtCreated - a timestamp

setDtModified

public final void setDtModified(Date dtModified)
Description copied from interface: Entity
set's the timestamp of the last modification.
This method should be considered internal!.

Specified by:
setDtModified in interface Entity
Parameters:
dtModified - a timestamp

setId

public final void setId(Long id)
Description copied from interface: Entity
set's the id of this instance. From application point of view, this should NOT occure, but on reading from persistence, it must be set.
So this method should be considered internal!.

Specified by:
setId in interface Entity
Parameters:
id - the id for this instance

setUCreated

public final void setUCreated(String created)
Description copied from interface: Entity
set's the name of the user, that created this instance.
This method should be considered internal!.

Specified by:
setUCreated in interface Entity
Parameters:
created - a username

setUModified

public final void setUModified(String modified)
Description copied from interface: Entity
set's the name of the user, that performed the last modification of this instance.
This method should be considered internal!.

Specified by:
setUModified in interface Entity
Parameters:
modified - a username

toString

public String toString()
Overrides:
toString in class Object

validate

public void validate(boolean read)
Description copied from interface: Entity
will be called just before saving and after loading, so it is intended to give the opportunity to calculate virtual fields.

Specified by:
validate in interface Entity
Parameters:
read - signals whether calculation should be done for reading or for writing

getLogger

protected final org.apache.commons.logging.Log getLogger()

setSchemaName

public static void setSchemaName(String schemaName)

SRJRCFrames
v0.1.296

hosted at
Find SRJRCFrames at SourceForge.net. Fast, secure and free:
           Open Source Software download
Submit a bug or request a feature

SRJRCFrames is published according to the GNU General Public License
Copyright 2005-2012 Reinhard Mantey - some rights reserved.