Class 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 a Table in the database. An Entity has properties which are primitive typed, references or lists of child entities.
    Author:
    iperdomo, mtaal
    See Also:
    Property, ModelProvider
    • Constructor Detail

      • Entity

        public Entity()
    • 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
      • getComputedColumnProperties

        public List<Property> getComputedColumnProperties()
      • 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
      • checkAccessLevel

        public void checkAccessLevel​(String clientId,
                                     String orgId)
        Checks if the accessLevel 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 accessLevel
        orgId -
        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 the getClassName() . 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 property
        value - 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. If includeComputed parameter is true, 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
      • setProperties

        public void setProperties​(List<Property> properties)
      • getIdentifierProperties

        public List<Property> getIdentifierProperties()
        Returns:
        the properties which make up the identifying string of this Entity
      • setIdentifierProperties

        public void setIdentifierProperties​(List<Property> identifierProperties)
      • 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
      • setParentProperties

        public void setParentProperties​(List<Property> parentProperties)
      • 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
      • setOrderByProperties

        public void setOrderByProperties​(List<Property> orderByProperties)
      • getIdProperties

        public List<Property> getIdProperties()
        Returns the properties which make up the primary key of this Entity.
        Returns:
        the list of primary key properties
      • setIdProperties

        public void setIdProperties​(List<Property> idProperties)
      • 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()
      • 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)