Package org.openbravo.base.model
Class Entity
- java.lang.Object
-
- org.openbravo.base.model.Entity
-
public class Entity extends Object
Models the business object type. The Entity is the main concept in the in-memory model. An entity corresponds to aTable
in the database. An Entity has properties which are primitive typed, references or lists of child entities.- Author:
- iperdomo, mtaal
- See Also:
Property
,ModelProvider
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPUTED_COLUMNS_CLASS_APPENDIX
static String
COMPUTED_COLUMNS_PROXY_PROPERTY
static String
SEARCH_VECTOR_REF_ID
-
Constructor Summary
Constructors Constructor Description Entity()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProperty(Property property)
Add a property to the internal arrays of properties (common, identifier, etc.)void
addPropertyByName(Property p)
void
checkAccessLevel(String clientId, String orgId)
Checks if theaccessLevel
of the entity is valid for the clientId and orgId passed as parameters.void
checkIsValidProperty(String propertyName)
Check if there is a property with the name propertyName.void
checkValidPropertyAndValue(String propName, Object value)
Checks if there is a property with the name propName and if so checks that the value is of the correct type and is valid.AccessLevel
getAccessLevel()
String
getClassName()
List<Property>
getComputedColumnProperties()
String
getHelp()
List<Property>
getIdentifierProperties()
List<Property>
getIdProperties()
Returns the properties which make up the primary key of this Entity.String
getImplementsStatement()
Returns the list of interfaces implemented by instances of this Entity.List<String>
getJavaImports()
Used to generate java import statements during generate.entitiesList<String>
getJavaImports(List<Property> propertyList)
Class<?>
getMappingClass()
Loads the class using thegetClassName()
.Module
getModule()
String
getName()
List<Property>
getOrderByProperties()
The orderBy properties are used when this Entity is a child of another Entity.String
getPackageName()
List<Property>
getParentProperties()
Only applies if this Entity is a child of another Entity, for example this is the OrderLine of an Order.List<Property>
getProperties()
Property
getProperty(String propertyName)
Retrieves the property using the propertyName.Property
getProperty(String propertyName, boolean checkIsNotNull)
Retrieves the property using the propertyName.Property
getPropertyByColumnName(String columnName)
Retrieves the property using the columnName.Property
getPropertyByColumnName(String columnName, boolean checkIsNotNull)
Retrieves the property using the columnName.List<Property>
getRealProperties(boolean includeComputed)
Gets a List of properties in the entity excluding, if present, the computed column proxy virtual property.String
getSimpleClassName()
Returns the last part of the Class name of the class of this Entity.String
getTableId()
String
getTableName()
String
getTreeType()
List<UniqueConstraint>
getUniqueConstraints()
boolean
hasCompositeId()
boolean
hasComputedColumns()
Checks if entity has any computed columnboolean
hasProperty(String propertyName)
Checks if the class has a certain property by name.void
initialize(Table table)
Initializes the entity from a table, also creates the properties from the list of Columns of the table.boolean
isActiveEnabled()
boolean
isClientEnabled()
boolean
isDataSourceBased()
boolean
isDeletable()
Boolean
isDeprecated()
boolean
isHQLBased()
boolean
isInActive()
boolean
isInheritedAccessEnabled()
boolean
isMutable()
boolean
isOrganizationEnabled()
boolean
isOrganizationPartOfKey()
boolean
isTraceable()
An Entity is traceable if it has auditInfo fields such as created, createdBy etc.boolean
isView()
boolean
isVirtualEntity()
Virtual entities are used when the main entity has computed columns.void
removeDeprecated()
Removes deprecation status from entity and its propertiesvoid
removeHelp()
Removes help from this entity and all its propertiesvoid
setAccessLevel(AccessLevel accessLevel)
void
setActiveEnabled(boolean isActiveEnabled)
protected void
setClassName(String className)
void
setClientEnabled(boolean isClientEnabled)
void
setDataSourceBased(boolean isDataSourceBased)
void
setDeletable(boolean isDeletable)
void
setDeprecated(Boolean deprecated)
void
setHasInheritedFrom(boolean hasInheritedFrom)
void
setHelp(String help)
Adds help to this Entity from corresponding table Removes comment escape character sequence and wraps comments over 100 characters.void
setHQLBased(boolean isHQLBased)
void
setIdentifierProperties(List<Property> identifierProperties)
void
setIdProperties(List<Property> idProperties)
void
setInActive(boolean isInActive)
void
setModule(Module module)
void
setMutable(boolean isMutable)
void
setName(String name)
void
setOrderByProperties(List<Property> orderByProperties)
void
setOrganizationEnabled(boolean isOrganizationEnabled)
void
setOrganizationPartOfKey(boolean isOrganizationPartOfKey)
void
setParentProperties(List<Property> parentProperties)
void
setProperties(List<Property> properties)
void
setTableId(String tableId)
void
setTableName(String tableName)
void
setTraceable(boolean isTraceable)
void
setTreeType(String treeType)
void
setView(boolean isView)
String
toString()
void
validate(Object obj)
Validates the passed object using the property validators of this Entity.
-
-
-
Field Detail
-
COMPUTED_COLUMNS_PROXY_PROPERTY
public static final String COMPUTED_COLUMNS_PROXY_PROPERTY
- See Also:
- Constant Field Values
-
COMPUTED_COLUMNS_CLASS_APPENDIX
public static final String COMPUTED_COLUMNS_CLASS_APPENDIX
- See Also:
- Constant Field Values
-
SEARCH_VECTOR_REF_ID
public static final String SEARCH_VECTOR_REF_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTreeType
public String getTreeType()
-
setTreeType
public void setTreeType(String treeType)
-
initialize
public void initialize(Table table)
Initializes the entity from a table, also creates the properties from the list of Columns of the table.- Parameters:
table
- the table used to initialize the Entity
-
hasComputedColumns
public boolean hasComputedColumns()
Checks if entity has any computed column
-
isVirtualEntity
public boolean isVirtualEntity()
Virtual entities are used when the main entity has computed columns. These virtual entities are mapped to the same database table the main entity is mapped to, they contain all the computed column properties, making in this way possible to lazily compute them.
-
addProperty
public void addProperty(Property property)
Add a property to the internal arrays of properties (common, identifier, etc.)- Parameters:
property
- the Property to add
-
getUniqueConstraints
public List<UniqueConstraint> getUniqueConstraints()
-
checkAccessLevel
public void checkAccessLevel(String clientId, String orgId)
Checks if theaccessLevel
of the entity is valid for the clientId and orgId passed as parameters. Throws an OBSecurityException if the clientId and/or orgId are not valid.- Parameters:
clientId
- the clientId which is checked against the accessLevelorgId
-- Throws:
OBSecurityException
- See Also:
AccessLevelChecker
-
validate
public void validate(Object obj)
Validates the passed object using the property validators of this Entity.- Parameters:
obj
- the object to validate- See Also:
EntityValidator
,PropertyValidator
-
getName
public String getName()
-
setName
public void setName(String name)
-
getClassName
public String getClassName()
-
setClassName
protected void setClassName(String className)
-
getMappingClass
public Class<?> getMappingClass()
Loads the class using thegetClassName()
. If this fails then the null is returned and the system will use a DynamicOBObject as the runtime class.- Returns:
- the java class implementing this Entity, or null if the class is not available (not found)
-
setTraceable
public void setTraceable(boolean isTraceable)
-
setActiveEnabled
public void setActiveEnabled(boolean isActiveEnabled)
-
setOrganizationEnabled
public void setOrganizationEnabled(boolean isOrganizationEnabled)
-
setClientEnabled
public void setClientEnabled(boolean isClientEnabled)
-
setHasInheritedFrom
public void setHasInheritedFrom(boolean hasInheritedFrom)
-
getImplementsStatement
public String getImplementsStatement()
Returns the list of interfaces implemented by instances of this Entity. It is used by the entity code generation to determine which interfaces to add to the class definition.- Returns:
- comma delimited list of interfaces
-
hasProperty
public boolean hasProperty(String propertyName)
Checks if the class has a certain property by name.- Parameters:
propertyName
- the name used to search for the property- Returns:
- returns true if there is a property with this name, false otherwise
-
checkIsValidProperty
public void checkIsValidProperty(String propertyName)
Check if there is a property with the name propertyName. If not then a CheckException is thrown.- Parameters:
propertyName
- the name used to search for a property- Throws:
CheckException
-
checkValidPropertyAndValue
public void checkValidPropertyAndValue(String propName, Object value)
Checks if there is a property with the name propName and if so checks that the value is of the correct type and is valid.- Parameters:
propName
- the name used to search for the propertyvalue
- the value is checked against the constraints for the property (for example length, nullable, etc.)- Throws:
CheckException
-
addPropertyByName
public void addPropertyByName(Property p)
-
getProperty
public Property getProperty(String propertyName)
Retrieves the property using the propertyName. Throws a CheckException if no property exists with that name.- Parameters:
propertyName
- the name used to search for the property.- Returns:
- the found property
- Throws:
CheckException
-
getProperty
public Property getProperty(String propertyName, boolean checkIsNotNull)
Retrieves the property using the propertyName. Throws a CheckException if no property exists with that name in case checkIsNotNull is true.- Parameters:
propertyName
- the name used to search for the property.checkIsNotNull
- if true, fails if property does not exists in entity, if false, returns null in this case- Returns:
- the found property
- Throws:
CheckException
-
getPropertyByColumnName
public Property getPropertyByColumnName(String columnName)
Retrieves the property using the columnName. Throws a CheckException if no property exists with that columnName.- Parameters:
columnName
- the name used to search for the property.- Returns:
- the found property
- Throws:
CheckException
-
getPropertyByColumnName
public Property getPropertyByColumnName(String columnName, boolean checkIsNotNull)
Retrieves the property using the columnName. Throws a CheckException if no property exists with that columnName in case checkIsNotNull is true.- Parameters:
columnName
- the name used to search for the property.checkIsNotNull
- if true, fails if property does not exists in entity, if false, returns null in this case- Returns:
- the found property
- Throws:
CheckException
-
getPackageName
public String getPackageName()
-
getSimpleClassName
public String getSimpleClassName()
Returns the last part of the Class name of the class of this Entity. The last part is the part after the last dot.- Returns:
- the last segment of the fully qualified Class name
-
isTraceable
public boolean isTraceable()
An Entity is traceable if it has auditInfo fields such as created, createdBy etc.- Returns:
- true if this Entity has created, createdBy etc. properties.
-
isActiveEnabled
public boolean isActiveEnabled()
- Returns:
- true if this Entity has an isActive property.
-
isOrganizationEnabled
public boolean isOrganizationEnabled()
- Returns:
- true if this Entity has an organization property.
-
isInheritedAccessEnabled
public boolean isInheritedAccessEnabled()
- Returns:
- true if this Entity has an inheritedFrom property.
-
isClientEnabled
public boolean isClientEnabled()
- Returns:
- true if this Entity has a client property.
-
getRealProperties
public List<Property> getRealProperties(boolean includeComputed)
Gets a List of properties in the entity excluding, if present, the computed column proxy virtual property. IfincludeComputed
parameter istrue
, all computed columns are also excluded.- Parameters:
includeComputed
- should properties for computed columns be excluded from the list- Returns:
- all the properties excluding proxy and, optionally, computed columns
-
getIdentifierProperties
public List<Property> getIdentifierProperties()
- Returns:
- the properties which make up the identifying string of this Entity
-
getParentProperties
public List<Property> getParentProperties()
Only applies if this Entity is a child of another Entity, for example this is the OrderLine of an Order.- Returns:
- the list of properties pointing to the parent, an emptylist if there is no such association to a parent
-
getOrderByProperties
public List<Property> getOrderByProperties()
The orderBy properties are used when this Entity is a child of another Entity. For example if this Entity is the OrderLine with a lineNo property which determines the order of the lines. Then the lineNo property will be returned as element in the list of this method.- Returns:
- the properties which can be used to order instances of this Entity
-
getIdProperties
public List<Property> getIdProperties()
Returns the properties which make up the primary key of this Entity.- Returns:
- the list of primary key properties
-
getTableName
public String getTableName()
-
setTableName
public void setTableName(String tableName)
-
isMutable
public boolean isMutable()
-
setMutable
public void setMutable(boolean isMutable)
-
isDeletable
public boolean isDeletable()
-
setDeletable
public void setDeletable(boolean isDeletable)
-
hasCompositeId
public boolean hasCompositeId()
-
getAccessLevel
public AccessLevel getAccessLevel()
-
setAccessLevel
public void setAccessLevel(AccessLevel accessLevel)
-
getTableId
public String getTableId()
-
setTableId
public void setTableId(String tableId)
-
isOrganizationPartOfKey
public boolean isOrganizationPartOfKey()
-
setOrganizationPartOfKey
public void setOrganizationPartOfKey(boolean isOrganizationPartOfKey)
-
isInActive
public boolean isInActive()
-
setInActive
public void setInActive(boolean isInActive)
-
getModule
public Module getModule()
-
setModule
public void setModule(Module module)
-
isView
public boolean isView()
-
setView
public void setView(boolean isView)
-
isDataSourceBased
public boolean isDataSourceBased()
-
setDataSourceBased
public void setDataSourceBased(boolean isDataSourceBased)
-
isHQLBased
public boolean isHQLBased()
-
setHQLBased
public void setHQLBased(boolean isHQLBased)
-
getHelp
public String getHelp()
-
setHelp
public void setHelp(String help)
Adds help to this Entity from corresponding table Removes comment escape character sequence and wraps comments over 100 characters. Makes sure it doesn't generate warnings by escaping "@"- Parameters:
help
- Help comment to add to this entity
-
getJavaImports
public List<String> getJavaImports()
Used to generate java import statements during generate.entities
-
removeHelp
public void removeHelp()
Removes help from this entity and all its properties
-
removeDeprecated
public void removeDeprecated()
Removes deprecation status from entity and its properties
-
isDeprecated
public Boolean isDeprecated()
-
setDeprecated
public void setDeprecated(Boolean deprecated)
-
-