Class ModelImpl

java.lang.Object
org.tentackle.model.impl.ModelImpl
All Implemented Interfaces:
Model

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

  • Method Details

    • setSchemaNameMapped

      public void setSchemaNameMapped(boolean mapSchemas)
      Description copied from interface: Model
      Sets whether schema names should be mapped to the leading part of table names.
      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
    • getModelDefaults

      public ModelDefaults getModelDefaults()
      Description copied from interface: Model
      Gets the model defaults.
      Specified by:
      getModelDefaults in interface Model
      Returns:
      the model defaults, null if none
    • setModelDefaults

      public void setModelDefaults(ModelDefaults modelDefaults)
      Description copied from interface: Model
      Sets the model defaults to apply when loading the model sources.
      Specified by:
      setModelDefaults in interface Model
      Parameters:
      modelDefaults - the model defaults, null if none
    • getEntityAliases

      public EntityAliases getEntityAliases()
      Description copied from interface: Model
      Gets the entity aliases.
      Specified by:
      getEntityAliases in interface Model
      Returns:
      the aliases, null if none
    • setEntityAliases

      public void setEntityAliases(EntityAliases entityAliases)
      Description copied from interface: Model
      Sets the entity aliases for relations between entities.
      Specified by:
      setEntityAliases in interface Model
      Parameters:
      entityAliases - the aliases, null if none
    • getIndexName

      public String getIndexName()
      Description copied from interface: Model
      Gets the name of the model index list.
      Specified by:
      getIndexName in interface Model
      Returns:
      the name of the list containing the entity model resource names
    • setIndexName

      public void setIndexName(String indexName)
      Description copied from interface: Model
      Sets the name of the model index list.
      The default is Model.DEFAULT_INDEX_NAME.
      Specified by:
      setIndexName in interface Model
      Parameters:
      indexName - the name of the list containing the entity model resource names
    • 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
    • loadFromDirectory

      public Collection<EntityInfo> loadFromDirectory(String modelDir, boolean updateRelations) throws ModelException
      Description copied from interface: Model
      Loads the whole model from the model directory if not yet done.
      Specified by:
      loadFromDirectory in interface Model
      Parameters:
      modelDir - the name of the directory containing the model files
      updateRelations - true if update the relations, false if model is still incomplete
      Returns:
      the entity infos of the loaded model files
      Throws:
      ModelException - if the model is inconsistent
      See Also:
    • loadFromURL

      public EntityInfo loadFromURL(URL url, boolean updateRelations) throws ModelException
      Description copied from interface: Model
      Loads an entity from a given URL.
      Entities are cached, so they are loaded and parsed only once.
      Specified by:
      loadFromURL in interface Model
      Parameters:
      url - the URL of the model file
      updateRelations - true if update the relations, false if model is still incomplete
      Returns:
      the entity info
      Throws:
      ModelException - if the model is inconsistent
      See Also:
    • loadFromJar

      public Collection<EntityInfo> loadFromJar(File file, boolean updateRelations) throws ModelException
      Description copied from interface: Model
      Loads the model from a jar file.
      Reads the model files listed in META-INF/MODEL-INDEX.LIST.
      Specified by:
      loadFromJar in interface Model
      Parameters:
      file - the jar file
      updateRelations - true if update the relations, false if model is still incomplete
      Returns:
      the entity infos of the loaded model files
      Throws:
      ModelException - if the model is inconsistent
    • loadFromResources

      public Collection<EntityInfo> loadFromResources(boolean updateRelations) throws ModelException
      Description copied from interface: Model
      Loads from resources.
      Locates all META-INF/MODEL-INDEX.LIST resources and loads the model files.
      Specified by:
      loadFromResources in interface Model
      Parameters:
      updateRelations - true if update the relations, false if model is still incomplete
      Returns:
      the entity infos of the loaded model files
      Throws:
      ModelException - if the model is inconsistent
    • updateRelations

      public void updateRelations() throws ModelException
      Description copied from interface: Model
      Updates the relations if not yet done during load.
      Specified by:
      updateRelations in interface Model
      Throws:
      ModelException - if model is inconsistent
      See Also:
    • 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
    • getAllEntities

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

      public Entity getByURL(URL url) throws ModelException
      Description copied from interface: Model
      Gets the entity by the model file path.
      Specified by:
      getByURL in interface Model
      Parameters:
      url - the URL of the model file
      Returns:
      the entity, null if no such entity
      Throws:
      ModelException - if the model is inconsistent
    • getByEntityName

      public Entity getByEntityName(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
    • getByTableName

      public Entity getByTableName(String tableName) throws ModelException
      Description copied from interface: Model
      Gets the entity by its table name.
      Specified by:
      getByTableName in interface Model
      Parameters:
      tableName - the table name (optional leading schema will be ignored)
      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 class 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
    • getEntityInfo

      public EntityInfo getEntityInfo(Entity entity) throws ModelException
      Description copied from interface: Model
      Gets the model information for the given entity.
      Specified by:
      getEntityInfo in interface Model
      Parameters:
      entity - the entity
      Returns:
      the model info, never null
      Throws:
      ModelException - if the model is inconsistent or no such entity
    • getForeignKeys

      public Collection<ForeignKey> getForeignKeys() throws ModelException
      Description copied from interface: Model
      Gets all foreign keys.
      Specified by:
      getForeignKeys in interface Model
      Returns:
      the foreign keys
      Throws:
      ModelException - if model is inconsistent
    • addEntityInfo

      protected void addEntityInfo(EntityInfo entityInfo) throws ModelException
      Adds an entity to the model.
      Parameters:
      entityInfo - the model entity
      Throws:
      ModelException - if duplicate entities detected
    • updateRelations

      protected void updateRelations(EntityInfo loadedEntityInfo) throws ModelException
      Updates all relations.
      Parameters:
      loadedEntityInfo - the entity that caused the update, null if none
      Throws:
      ModelException - if relations or inheritance misconfiguration
    • applyTableAlias

      protected boolean applyTableAlias(Map<String,Entity> aliasMap, Entity entity, String alias)
      Applies the table alias if unique and valid.
      Parameters:
      aliasMap - the map holding the aliases mapped to entities
      entity - the entity to apply the alias to
      alias - the alias
      Returns:
      true if applied, false if alias already exists or is not valid for at least one backend
    • isValidTableAlias

      protected boolean isValidTableAlias(String alias)
      Checks if a table alias is a valid name for all backends.
      Parameters:
      alias - the table alias
      Returns:
      true if ok
    • updateCompositePath

      protected void updateCompositePath(List<Relation> compositePath, Entity entity) throws ModelException
      Updates the composite path.
      Parameters:
      compositePath - the path that leads to given entity so far
      entity - the entity
      Throws:
      ModelException
    • 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(String modelDir) throws ModelException
      Creates a model directory object.
      Parameters:
      modelDir - the directory name
      Returns:
      the model directory
      Throws:
      ModelException - if directory does not exist or is not a directory
    • createEntityInfo

      protected EntityInfo createEntityInfo(ModelDefaults defaults, URL url) throws ModelException
      Creates a model entity wrapper.
      Parameters:
      defaults - the optional model defaults
      url - the url of the model file
      Returns:
      the model entity
      Throws:
      ModelException - if creation failed
    • createReader

      protected Reader createReader(URL url) throws ModelException
      Creates a reader for given name.
      Parameters:
      url - the model url
      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, Set<ModelError> errors)
      Verifies that the inheritance, integrity and track type is the same within a given inheritance 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, 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 String translateAlias(String name)
      Translates an entity name if it is an alias.
      Parameters:
      name - the original name
      Returns:
      the possibly translated name