Class GenericEntity
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<GenericEntity>,Map<String,Object>
- Direct Known Subclasses:
GenericPK,GenericValue
Note that this class extends Observable to achieve change notification for
Observers. Whenever a field changes the name of the field will be passed to
the notifyObservers() method, and through that to the update() method of each
Observer.
Created Wed Aug 08 2001
- Version:
- 1.0
- Author:
- David E. Jones, Andy Zeneski
- See Also:
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionName of the GenericDelegator, used to re-get the GenericDelegator when deserializedContains the entityName of this entity, necessary for efficiency when creating EJBsContains the fields for this entity.Reference to an instance of GenericDelegator used to do some basic operations on this entity value.Contains the ModelEntity instance that represents the definition of this entity, not to be serializedbooleanDenotes whether or not this entity has been modified, or is known to be out of sync with the persistent record -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.GenericEntity(GenericDelegator delegator) Creates new GenericEntityGenericEntity(GenericDelegator delegator, ModelEntity modelEntity) Creates new GenericEntity.GenericEntity(GenericDelegator delegator, ModelEntity modelEntity, Map<String, ?> fields) Creates new GenericEntity from existing Map.GenericEntity(GenericEntity value) Copy Constructor: Creates new GenericEntity from existing GenericEntityGenericEntity(ModelEntity modelEntity) Deprecated.GenericEntity(ModelEntity modelEntity, Map<String, ?> fields) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic intaddToXmlDocument(Collection<GenericValue> values, Document document) voidclear()clone()Clones this GenericEntity, this is a shallow clone & uses the default shallow HashMap cloneintcompareTo(GenericEntity obj) Compares this GenericEntity to the passed objectbooleancontainsKey(Object key) booleanReturns true if the entity contains all of the primary key fields.booleancontainsValue(Object value) dangerousGetNoCheckButFast(ModelField modelField) voiddangerousSetNoCheckButFast(ModelField modelField, Object value) entrySet()booleanDetermines the equality of two GenericEntity objects, overrides the default equalsReturns key/value pairs of entity fieldsReturns keys of entity fieldsgetBoolean(String name) byte[]Get the GenericDelegator instance that created this value object and that is responsible for it.getFields(Collection<String> keysofFields) Used by clients to specify exactly the fields they are interested ingetInteger(String name) getTimestamp(String name) inthashCode()Creates a hashCode for the entity, using the default String hashCode and Map hashCode, overrides the default hashCodebooleanisEmpty()booleanbooleanReturns true if the entity contains all of the primary key fields, but NO others.keySet()booleanUsed to indicate if locking is enabled for this entitystatic DocumentmakeXmlDocument(Collection<GenericValue> values) makeXmlElement(Document document) Makes an XML Element object with an attribute for each field of the entitymakeXmlElement(Document document, String prefix) Makes an XML Element object with an attribute for each field of the entitybooleanmatchesFields(Map<String, ?> keyValuePairs) voidvoidSets the named field to the passed value, even if the value is nullSets the named field to the passed value.voidSets a field with an array of bytes, wrapping them automatically for easy use.voidsetDelegator(GenericDelegator internalDelegator) Set the GenericDelegator instance that created this value object and that is responsible for it.voidUpdates the given fields of this entity with the values in the given map, including nulls.voidsetNonPKFields(Map<String, Object> fields) go through the non-pks and for each one see if there is an entry in fields to setvoidsetNonPKFields(Map<String, Object> fields, boolean setIfEmpty) go through the non-pks and for each one see if there is an entry in fields to setvoidsetPKFields(Map<String, Object> fields) go through the pks and for each one see if there is an entry in fields to setvoidsetPKFields(Map<String, Object> fields, boolean setIfEmpty) go through the pks and for each one see if there is an entry in fields to setvoidSets the named field to the passed value, converting the value from a String to the correct type usingType.valueOf()or similar.intsize()toString()Creates a String for the entity, overrides the default toStringvalues()voidwriteXmlText(PrintWriter writer, String prefix) Writes XML text with an attribute or CDATA element for each field of the entityMethods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChangedMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
delegatorName
Name of the GenericDelegator, used to re-get the GenericDelegator when deserialized -
internalDelegator
Reference to an instance of GenericDelegator used to do some basic operations on this entity value. If null various methods in this class will fail. This is automatically set by the GenericDelegator for all GenericValue objects instantiated through it. You may set this manually for objects you instantiate manually, but it is optional. -
fields
Contains the fields for this entity. -
entityName
Contains the entityName of this entity, necessary for efficiency when creating EJBs -
modelEntity
Contains the ModelEntity instance that represents the definition of this entity, not to be serialized -
modified
public boolean modifiedDenotes whether or not this entity has been modified, or is known to be out of sync with the persistent record
-
-
Constructor Details
-
GenericEntity
Creates new GenericEntity- Since:
- 1.0.13
-
GenericEntity
Creates new GenericEntity.- Since:
- 1.0.13
-
GenericEntity
Creates new GenericEntity from existing Map.- Since:
- 1.0.13
-
GenericEntity
public GenericEntity()Deprecated.since 1.0.13 UseGenericEntity(GenericDelegator internalDelegator)Creates new GenericEntity -
GenericEntity
Deprecated.Creates new GenericEntity. -
GenericEntity
Deprecated.Creates new GenericEntity from existing Map. -
GenericEntity
Copy Constructor: Creates new GenericEntity from existing GenericEntity
-
-
Method Details
-
isModified
public boolean isModified() -
getEntityName
-
getModelEntity
-
getDelegator
Get the GenericDelegator instance that created this value object and that is responsible for it.- Returns:
- GenericDelegator object
-
setDelegator
Set the GenericDelegator instance that created this value object and that is responsible for it. -
get
-
isPrimaryKey
public boolean isPrimaryKey()Returns true if the entity contains all of the primary key fields, but NO others. -
containsPrimaryKey
public boolean containsPrimaryKey()Returns true if the entity contains all of the primary key fields. -
set
Sets the named field to the passed value, even if the value is null- Parameters:
name- The field name to setvalue- The value to set
-
set
Sets the named field to the passed value. If value is null, it is only set if the setIfNull parameter is true. This is useful because an update will only set values that are included in the HashMap and will store null values in the HashMap to the datastore. If a value is not in the HashMap, it will be left unmodified in the datastore.- Parameters:
field- the name of the field to set; must be a valid field of this entityvalue- the value to set; if null, will only be stored ifsetIfNullis truesetIfNull- specifies whether or not to set the value if it is null- Returns:
- the previous value of the given field (whether updated or not)
-
dangerousSetNoCheckButFast
-
dangerousGetNoCheckButFast
-
setString
Sets the named field to the passed value, converting the value from a String to the correct type usingType.valueOf()or similar.WARNING: calling this for an
OBJECTfield is ambiguous, because you could mean either that theStringis the Base64-encoded representation of the object and should be be deserialized or that theStringis the actual object to be stored. Since this method is intended for use in restoring the entity from an XML export, it assumes that the value is the Base64-encoding of an arbitrary object and attempts to deserialize it. If this is not what is intended, then it is up to the caller to useset(String, Object)for those fields, instead.- Parameters:
name- The field name to setvalue- The String value to convert and set
-
setBytes
Sets a field with an array of bytes, wrapping them automatically for easy use.- Parameters:
name- The field name to setbytes- The byte array to be wrapped and set
-
getBoolean
-
getString
-
getTimestamp
-
getTime
-
getDate
-
getInteger
-
getLong
-
getFloat
-
getDouble
-
getBytes
-
getPrimaryKey
-
setPKFields
go through the pks and for each one see if there is an entry in fields to set -
setPKFields
go through the pks and for each one see if there is an entry in fields to set -
setNonPKFields
go through the non-pks and for each one see if there is an entry in fields to set -
setNonPKFields
go through the non-pks and for each one see if there is an entry in fields to set -
getAllKeys
Returns keys of entity fields- Returns:
- java.util.Collection
-
getAllFields
Returns key/value pairs of entity fields- Returns:
- java.util.Map
-
getFields
Used by clients to specify exactly the fields they are interested in- Parameters:
keysofFields- the name of the fields the client is interested in- Returns:
- java.util.Map
-
setFields
Updates the given fields of this entity with the values in the given map, including nulls.- Parameters:
newFieldValues- map of valid field names to new values; if null, this method does nothing
-
matchesFields
-
lockEnabled
public boolean lockEnabled()Used to indicate if locking is enabled for this entity- Returns:
- True if locking is enabled
-
makeXmlDocument
-
addToXmlDocument
-
makeXmlElement
Makes an XML Element object with an attribute for each field of the entity- Parameters:
document- The XML Document that the new Element will be part of- Returns:
- org.w3c.dom.Element object representing this generic entity
-
makeXmlElement
Makes an XML Element object with an attribute for each field of the entity- Parameters:
document- The XML Document that the new Element will be part ofprefix- A prefix to put in front of the entity name in the tag name- Returns:
- org.w3c.dom.Element object representing this generic entity
-
writeXmlText
Writes XML text with an attribute or CDATA element for each field of the entity- Parameters:
writer- A PrintWriter to write toprefix- A prefix to put in front of the entity name in the tag name
-
equals
Determines the equality of two GenericEntity objects, overrides the default equals -
hashCode
public int hashCode()Creates a hashCode for the entity, using the default String hashCode and Map hashCode, overrides the default hashCode -
toString
Creates a String for the entity, overrides the default toString -
compareTo
Compares this GenericEntity to the passed object- Specified by:
compareToin interfaceComparable<GenericEntity>- Parameters:
obj- Object to compare this to- Returns:
- int representing the result of the comparison (-1,0, or 1)
-
clone
Clones this GenericEntity, this is a shallow clone & uses the default shallow HashMap clone -
remove
-
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object>
-
entrySet
-
put
-
putAll
-
clear
public void clear() -
get
-
keySet
-
isEmpty
public boolean isEmpty() -
values
-
containsValue
- Specified by:
containsValuein interfaceMap<String,Object>
-
size
public int size()
-
GenericEntity(GenericDelegator internalDelegator)