Class ModelProvider

  • All Implemented Interfaces:
    OBProvidable, OBSingleton

    public class ModelProvider
    extends Object
    implements OBSingleton
    Builds the Runtime model base on the data model (application dictionary: table, column, reference, etc). Makes the runtime model (Entity and Property) available to the rest of the system.
    Author:
    iperdomo, mtaal
    See Also:
    Entity, Property, Table, Column
    • Constructor Detail

      • ModelProvider

        public ModelProvider()
    • Method Detail

      • getInstance

        public static ModelProvider getInstance()
        Returns the singleton instance providing the ModelProvider functionality.
        Returns:
        the ModelProvider instance
      • setInstance

        public static void setInstance​(ModelProvider instance)
        Makes it possible to override the default ModelProvider with a custom implementation.
        Parameters:
        instance - the custom ModelProvider
      • refresh

        public static void refresh()
        Creates a new ModelProvider, initializes it and sets it in the instance here.
      • getModel

        public List<Entity> getModel()
        The list of Entities created on the basis of the Application Dictionary. The main entry point for retrieving the in-memory model. This method will initialize the in-memory model when it is called for the first time.
        Returns:
        the list Entities
      • getTables

        public List<Table> getTables()
        Returns list of tables known in the dal in memory model. This excludes i.e. tables which do not have any column defined with iskey='Y'
        Returns:
        list of tables known by dal in no particular stable order
      • getDataSourceBasedTables

        public List<Table> getDataSourceBasedTables()
        Returns list of dataSource based tables known in the dal in memory model.
        Returns:
        list of dataSource based tables known by dal in no particular stable order
      • computeLastUpdateModelTime

        public long computeLastUpdateModelTime()
        Returns:
        the last time that one of the relevant Application Dictionary objects was modified. Relevant AD objects are: Table, Column, Reference, RefList, RefSearch, RefTable, Module, Package.
      • shouldGenerateChildPropertyInParent

        public boolean shouldGenerateChildPropertyInParent​(Property p,
                                                           boolean generateAllChildProperties)
        Determines whether for a given property, it is a child that should have a property on its parent entity.
      • list

        public <T> List<T> list​(org.hibernate.Session session,
                                Class<T> clazz)
        Retrieves a list of model objects of the class passed as parameter.
        Parameters:
        session - the session used to query for the objects
        clazz - the class of the model objects to be retrieved
        Returns:
        a list of model objects
      • getTable

        public Table getTable​(String tableName)
                       throws CheckException
        Return the table using the tableName. If not found then a CheckException is thrown.
        Parameters:
        tableName -
        Returns:
        the Table object
        Throws:
        CheckException
      • getTableWithoutCheck

        public Table getTableWithoutCheck​(String tableName)
        Retrieves a table using the tableName. If not found then continue without exception.
        Returns:
        Table if exists, otherwise null.
      • getEntity

        public Entity getEntity​(String entityName)
                         throws CheckException
        Retrieves an Entity using the entityName. If not found then a CheckException is thrown.
        Parameters:
        entityName - the name used for searching the Entity.
        Returns:
        the Entity object
        Throws:
        CheckException
      • getEntity

        public Entity getEntity​(String entityName,
                                boolean checkIfNotExists)
                         throws CheckException
        Retrieves an Entity using the entityName. If not found then a CheckException is thrown if the checkIfNotExists parameter is true.
        Parameters:
        entityName - the name used for searching the Entity.
        checkIfNotExists - a boolean that is true calls to Check.fail if the entity does not exist
        Returns:
        the Entity object
        Throws:
        CheckException
      • getEntityByTableName

        public Entity getEntityByTableName​(String tableName)
        Returns an Entity using the table name of the table belonging to the Entity. If no Entity is found then null is returned, no Exception is thrown. Note: the AD_Table.tablename should be used here, not the AD_Table.name!
        Parameters:
        tableName - the name used to search for the Entity
        Returns:
        the Entity or null if not found
      • getEntityByTableId

        public Entity getEntityByTableId​(String tableId)
        Returns an Entity based on the ID of the table belonging to the Entity. If no Entity is found then null is returned, no Exception is thrown.
        Parameters:
        tableId - the ID of the table belonging to the table
        Returns:
        the Entity or null if not found
      • getEntity

        public Entity getEntity​(Class<?> clz)
                         throws CheckException
        Searches for an Entity using the business object class implementing the Entity in the business code. Throws a CheckException if the Entity can not be found.
        Parameters:
        clz - the java class used for the Entity
        Returns:
        the Entity
        Throws:
        CheckException
      • getReference

        public Reference getReference​(String referenceId)
        Returns a reference instance from the org.openbravo.base.model package.
        Parameters:
        referenceId -
        Returns:
        the reference identified by the referenceId, if not found then null is returned
      • getAllReferences

        public Collection<Reference> getAllReferences()
        Returns all reference (instance from the org.openbravo.base.model package).
        Returns:
        the references
      • getEntityFromTreeType

        public Entity getEntityFromTreeType​(String treeType)
        Returns the entity for a specific tree type. The tree type is used to link an entity to a tree (see the AD_Tree table).
        Parameters:
        treeType - the tree type
        Returns:
        Entity or null if none found
      • getEntityWithImage

        public HashMap<Entity,​List<String>> getEntityWithImage()
        Returns the entities that have images
        Returns:
        Entity list
      • getEntityWithFile

        public HashMap<Entity,​List<String>> getEntityWithFile()
        Returns the entities that have images
        Returns:
        Entity list
      • getSession

        public org.hibernate.Session getSession()
        This method can be used to get the session of the ModelProvider. This method is intended to be used by DomainType classes during initialization phase, to do queries in the database
      • addHelpAndDeprecationToModel

        public void addHelpAndDeprecationToModel​(boolean addDeprecation)
        Adds help comments and deprecation status to corresponding entities and properties in the model
      • removeHelpAndDeprecationFromModel

        public void removeHelpAndDeprecationFromModel()
        Removes help comments and deprecation status from all entities and properties in the model