Class ModelImpl

  • All Implemented Interfaces:
    Model

    @Service(Model.class)
    public class ModelImpl
    extends java.lang.Object
    implements Model
    Model implementation.
    Author:
    harald
    • Constructor Detail

      • ModelImpl

        public ModelImpl()
        Creates a model.
    • Method Detail

      • setSchemaNameMapped

        public void setSchemaNameMapped​(boolean mapSchemas)
        Description copied from interface: Model
        Sets whether schema names should be mapped to the leading part of tablenames.
        Specified by:
        setSchemaNameMapped in interface Model
        Parameters:
        mapSchemas - true if map
      • isSchemaNameMapped

        public boolean isSchemaNameMapped()
        Description copied from interface: Model
        Returns whether schema names are mapped.
        Specified by:
        isSchemaNameMapped in interface Model
        Returns:
        true if mapped
      • getEntityFactory

        public EntityFactory getEntityFactory()
        Description copied from interface: Model
        Gets the entity factory singleton.
        Specified by:
        getEntityFactory in interface Model
        Returns:
        the entity model factory
      • loadModel

        public void loadModel​(java.lang.String modelDir,
                              ModelDefaults defaults,
                              EntityAliases aliases)
                       throws ModelException
        Description copied from interface: Model
        Loads the whole model from the model directory if not yet done.
        Specified by:
        loadModel in interface Model
        Parameters:
        modelDir - the directory containing the model files
        defaults - optional model defaults, null if none
        aliases - optional entity aliases, null if none
        Throws:
        ModelException - if the model is inconsistent
      • clearModel

        public void clearModel()
        Description copied from interface: Model
        Clears the model.
        Specified by:
        clearModel in interface Model
      • refreshModel

        public void refreshModel()
                          throws ModelException
        Description copied from interface: Model
        Refreshes the model.
        Checks for changes and reloads if necessary.
        Specified by:
        refreshModel in interface Model
        Throws:
        ModelException - if the model is inconsistent
      • getAllEntitites

        public java.util.Collection<Entity> getAllEntitites()
                                                     throws ModelException
        Description copied from interface: Model
        Gets all cached entities.
        Specified by:
        getAllEntitites in interface Model
        Returns:
        all entities loaded so far
        Throws:
        ModelException - if the model is inconsistent
      • getByFileName

        public Entity getByFileName​(java.lang.String fileName)
                             throws ModelException
        Description copied from interface: Model
        Gets the entity by the mapfile name.
        Specified by:
        getByFileName in interface Model
        Parameters:
        fileName - the name of the mapfile
        Returns:
        the entity, null if no such entity
        Throws:
        ModelException - if the model is inconsistent
      • getByEntityName

        public Entity getByEntityName​(java.lang.String entityName)
                               throws ModelException
        Description copied from interface: Model
        Gets the entity by its name.
        Specified by:
        getByEntityName in interface Model
        Parameters:
        entityName - the name
        Returns:
        the entity, null if no such entity
        Throws:
        ModelException - if the model is inconsistent
      • getByClassId

        public Entity getByClassId​(int classId)
                            throws ModelException
        Description copied from interface: Model
        Gets the entity by its id.
        Specified by:
        getByClassId in interface Model
        Parameters:
        classId - the class id
        Returns:
        the entity, null if no such entity
        Throws:
        ModelException - if the model is inconsistent
      • loadByFileName

        public Entity loadByFileName​(java.lang.String fileName,
                                     ModelDefaults defaults,
                                     EntityAliases aliases)
                              throws ModelException
        Description copied from interface: Model
        Loads an entity for a given mapfile name.
        Entities are cached so they are loaded and parsed only once.
        Specified by:
        loadByFileName in interface Model
        Parameters:
        fileName - the name of the mapfile
        defaults - optional model defaults, null if none
        aliases - optional entity aliases, null if none
        Returns:
        the entity
        Throws:
        ModelException - if no such mapfile or parsing error
      • loadByFileName

        protected Entity loadByFileName​(java.lang.String fileName,
                                        ModelDefaults defaults,
                                        EntityAliases aliases,
                                        boolean updateRelations)
                                 throws ModelException
        Loads an entity for a given mapfile name.
        Entities are cached so they are loaded and parsed only once.
        Parameters:
        fileName - the name of the mapfile
        defaults - optional model defaults, null if none
        aliases - optional entity aliases, null if none
        updateRelations - true if update the related entites in the model
        Returns:
        the entity
        Throws:
        ModelException - if no such mapfile or parsing error
      • parseEntity

        protected Entity parseEntity​(ModelDefaults defaults,
                                     java.lang.String fileName)
                              throws ModelException
        Parses the given file and returns the created entity.
        Parameters:
        defaults - the model defaults, null if none
        fileName - the name of the file holding the model
        Returns:
        the entity
        Throws:
        ModelException - if parsing failed
      • addModelEntity

        protected void addModelEntity​(ModelEntity modelEntity)
                               throws ModelException
        Adds an entity to the model.
        Parameters:
        modelEntity - the model entity
        Throws:
        ModelException - if duplicate entities detected
      • updateRelations

        protected void updateRelations​(ModelDefaults defaults,
                                       EntityAliases aliases)
                                throws ModelException
        Updates the inheritance links and relations of all entities in the model.
        Parameters:
        defaults - the optional model defaults
        aliases - the optional entity aliases
        Throws:
        ModelException - if relations or inheritance misconfigured
      • updateRelations

        protected void updateRelations​(ModelDefaults defaults,
                                       EntityAliases aliases,
                                       ModelEntity loadedModelEntity)
                                throws ModelException
        Updates all relations.
        Parameters:
        defaults - the optional model defaults
        aliases - the optional entity aliases
        loadedModelEntity - the entity that caused the update, null if none
        Throws:
        ModelException - if relations or inheritance misconfigured
      • updateCompositePath

        protected void updateCompositePath​(java.util.List<Relation> compositePath,
                                           Entity entity)
        Updates the composite path.
        Parameters:
        compositePath - the path that leads to given entity so far
        entity - the entity
      • createEntityFactory

        protected EntityFactory createEntityFactory()
        Creates the entity factory for this model.
        The method is invoked once from within the Model constructor.
        Returns:
        the entity factory
      • createModelDirectory

        protected ModelDirectory createModelDirectory​(java.lang.String modelDir,
                                                      ModelDefaults defaults,
                                                      EntityAliases aliases)
                                               throws ModelException
        Creates a model directory object.
        Parameters:
        modelDir - the directory name
        defaults - optional model defaults, null if none
        aliases - optional entity aliases, null if none
        Returns:
        the model directory
        Throws:
        ModelException - if directory does not exist or is not a directory
      • createModelEntity

        protected ModelEntity createModelEntity​(Entity entity,
                                                java.lang.String fileName)
                                         throws ModelException
        Creates a model entity wrapper.
        Parameters:
        entity - the entity
        fileName - the model file name
        Returns:
        the model entity
        Throws:
        ModelException - if creation failed
      • createReader

        protected java.io.Reader createReader​(java.lang.String name)
                                       throws ModelException
        Creates a reader for given name.
        Parameters:
        name - the file- or resource name
        Returns:
        the reader
        Throws:
        ModelException - if creating the reader failed (because file not found)
      • validateInheritanceHierarchy

        protected void validateInheritanceHierarchy​(Entity entity,
                                                    InheritanceType inheritanceType,
                                                    TrackType trackType,
                                                    Integrity integrity,
                                                    java.util.Set<ModelError> errors)
        Verifies that the inheritance, integrity and track type is the same within a given interitance hierarchy.
        Notice that concrete classes (the leafs of the hierarchy) must have InheritanceType.NONE defined!
        Parameters:
        entity - the entity to check
        inheritanceType - the inheritance type
        trackType - the tracking type
        integrity - the integrity type
        errors - the collected model errors
      • validateComponents

        protected void validateComponents​(Entity entity,
                                          Integrity integrity,
                                          java.util.Set<ModelError> errors)
        Verifies that the integrity is the same within a given composite hierarchy.
        Parameters:
        entity - the entity to check
        integrity - the integrity type
        errors - the collected model errors
      • translateAlias

        protected java.lang.String translateAlias​(EntityAliases aliases,
                                                  java.lang.String name)
        Translates an entity name if it is an alias.
        Parameters:
        aliases - the entity aliases
        name - the original name
        Returns:
        the possibly translated name