java.lang.Object
org.tentackle.model.impl.ModelImpl
- All Implemented Interfaces:
Model
Model implementation.
- Author:
- harald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddModelEntity(ModelEntity modelEntity) Adds an entity to the model.protected booleanApplies the table alias if unique and valid.voidClears the model.protected EntityFactoryCreates the entity factory for this model.
The method is invoked once from within the Model constructor.protected ModelDirectorycreateModelDirectory(String modelDir, ModelDefaults defaults, EntityAliases aliases) Creates a model directory object.protected ModelEntitycreateModelEntity(Entity entity, String fileName) Creates a model entity wrapper.protected ReadercreateReader(String name) Creates a reader for given name.Gets all cached entities.getByClassId(int classId) Gets the entity by its class id.getByEntityName(String entityName) Gets the entity by its name.getByFilePath(String filePath) Gets the entity by the mapfile path.getByTableName(String tableName) Gets the entity by its table name.Gets the entity factory singleton.Gets all foreign keys.booleanReturns whether schema names are mapped.protected booleanisValidTableAlias(String alias) Checks if a table alias is a valid name for all backends.loadByFilePath(String filePath, ModelDefaults defaults, EntityAliases aliases) Loads an entity for a given mapfile name.
Entities are cached so they are loaded and parsed only once.protected EntityloadByFilePath(String filePath, ModelDefaults defaults, EntityAliases aliases, boolean updateRelations) Loads an entity for a given mapfile path.
Entities are cached so they are loaded and parsed only once.voidloadModel(String modelDir, ModelDefaults defaults, EntityAliases aliases) Loads the whole model from the model directory if not yet done.protected EntityparseEntity(ModelDefaults defaults, String fileName) Parses the given file and returns the created entity.voidRefreshes the model.
Checks for changes and reloads if necessary.voidsetSchemaNameMapped(boolean mapSchemas) Sets whether schema names should be mapped to the leading part of tablenames.protected StringtranslateAlias(EntityAliases aliases, String name) Translates an entity name if it is an alias.protected voidupdateCompositePath(List<Relation> compositePath, Entity entity) Updates the composite path.protected voidupdateRelations(ModelDefaults defaults, EntityAliases aliases) Updates the inheritance links and relations of all entities in the model.protected voidupdateRelations(ModelDefaults defaults, EntityAliases aliases, ModelEntity loadedModelEntity) Updates all relations.protected voidvalidateComponents(Entity entity, Integrity integrity, Set<ModelError> errors) Verifies that the integrity is the same within a given composite hierarchy.protected voidvalidateInheritanceHierarchy(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 interitance hierarchy.
Notice that concrete classes (the leafs of the hierarchy) must have InheritanceType.NONE defined!
-
Constructor Details
-
ModelImpl
public ModelImpl()Creates a model.
-
-
Method Details
-
setSchemaNameMapped
public void setSchemaNameMapped(boolean mapSchemas) Description copied from interface:ModelSets whether schema names should be mapped to the leading part of tablenames.- Specified by:
setSchemaNameMappedin interfaceModel- Parameters:
mapSchemas- true if map
-
isSchemaNameMapped
public boolean isSchemaNameMapped()Description copied from interface:ModelReturns whether schema names are mapped.- Specified by:
isSchemaNameMappedin interfaceModel- Returns:
- true if mapped
-
getEntityFactory
Description copied from interface:ModelGets the entity factory singleton.- Specified by:
getEntityFactoryin interfaceModel- Returns:
- the entity model factory
-
loadModel
public void loadModel(String modelDir, ModelDefaults defaults, EntityAliases aliases) throws ModelException Description copied from interface:ModelLoads the whole model from the model directory if not yet done.- Specified by:
loadModelin interfaceModel- Parameters:
modelDir- the directory containing the model filesdefaults- optional model defaults, null if nonealiases- optional entity aliases, null if none- Throws:
ModelException- if the model is inconsistent
-
clearModel
public void clearModel()Description copied from interface:ModelClears the model.- Specified by:
clearModelin interfaceModel
-
refreshModel
Description copied from interface:ModelRefreshes the model.
Checks for changes and reloads if necessary.- Specified by:
refreshModelin interfaceModel- Throws:
ModelException- if the model is inconsistent
-
getAllEntitites
Description copied from interface:ModelGets all cached entities.- Specified by:
getAllEntititesin interfaceModel- Returns:
- all entities loaded so far
- Throws:
ModelException- if the model is inconsistent
-
getByFilePath
Description copied from interface:ModelGets the entity by the mapfile path.- Specified by:
getByFilePathin interfaceModel- Parameters:
filePath- the pathname of the mapfile- Returns:
- the entity, null if no such entity
- Throws:
ModelException- if the model is inconsistent
-
getByEntityName
Description copied from interface:ModelGets the entity by its name.- Specified by:
getByEntityNamein interfaceModel- Parameters:
entityName- the name- Returns:
- the entity, null if no such entity
- Throws:
ModelException- if the model is inconsistent
-
getByTableName
Description copied from interface:ModelGets the entity by its table name.- Specified by:
getByTableNamein interfaceModel- 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
Description copied from interface:ModelGets the entity by its class id.- Specified by:
getByClassIdin interfaceModel- Parameters:
classId- the class id- Returns:
- the entity, null if no such entity
- Throws:
ModelException- if the model is inconsistent
-
loadByFilePath
public Entity loadByFilePath(String filePath, ModelDefaults defaults, EntityAliases aliases) throws ModelException Description copied from interface:ModelLoads an entity for a given mapfile name.
Entities are cached so they are loaded and parsed only once.- Specified by:
loadByFilePathin interfaceModel- Parameters:
filePath- the path of the mapfiledefaults- optional model defaults, null if nonealiases- optional entity aliases, null if none- Returns:
- the entity
- Throws:
ModelException- if no such mapfile or parsing error
-
loadByFilePath
protected Entity loadByFilePath(String filePath, ModelDefaults defaults, EntityAliases aliases, boolean updateRelations) throws ModelException Loads an entity for a given mapfile path.
Entities are cached so they are loaded and parsed only once.- Parameters:
filePath- the path of the mapfiledefaults- optional model defaults, null if nonealiases- optional entity aliases, null if noneupdateRelations- true if update the related entites in the model- Returns:
- the entity
- Throws:
ModelException- if no such mapfile or parsing error
-
parseEntity
Parses the given file and returns the created entity.- Parameters:
defaults- the model defaults, null if nonefileName- the name of the file holding the model- Returns:
- the entity
- Throws:
ModelException- if parsing failed
-
addModelEntity
Adds an entity to the model.- Parameters:
modelEntity- the model entity- Throws:
ModelException- if duplicate entities detected
-
updateRelations
Updates the inheritance links and relations of all entities in the model.- Parameters:
defaults- the optional model defaultsaliases- 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 defaultsaliases- the optional entity aliasesloadedModelEntity- the entity that caused the update, null if none- Throws:
ModelException- if relations or inheritance misconfigured
-
applyTableAlias
Applies the table alias if unique and valid.- Parameters:
aliasMap- the map holding the aliases mapped to entitiesentity- the entity to apply the alias toalias- the alias- Returns:
- true if applied, false if alias already exists or is not valid for at least one backend
-
isValidTableAlias
Checks if a table alias is a valid name for all backends.- Parameters:
alias- the table alias- Returns:
- true if ok
-
updateCompositePath
Updates the composite path.- Parameters:
compositePath- the path that leads to given entity so farentity- the entity
-
getForeignKeys
Description copied from interface:ModelGets all foreign keys.- Specified by:
getForeignKeysin interfaceModel- Returns:
- the foreign keys
- Throws:
ModelException- if model is inconsistent
-
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, ModelDefaults defaults, EntityAliases aliases) throws ModelException Creates a model directory object.- Parameters:
modelDir- the directory namedefaults- optional model defaults, null if nonealiases- optional entity aliases, null if none- Returns:
- the model directory
- Throws:
ModelException- if directory does not exist or is not a directory
-
createModelEntity
Creates a model entity wrapper.- Parameters:
entity- the entityfileName- the model file name- Returns:
- the model entity
- Throws:
ModelException- if creation failed
-
createReader
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, 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 checkinheritanceType- the inheritance typetrackType- the tracking typeintegrity- the integrity typeerrors- the collected model errors
-
validateComponents
Verifies that the integrity is the same within a given composite hierarchy.- Parameters:
entity- the entity to checkintegrity- the integrity typeerrors- the collected model errors
-
translateAlias
Translates an entity name if it is an alias.- Parameters:
aliases- the entity aliasesname- the original name- Returns:
- the possibly translated name
-