- java.lang.Object
-
- org.tentackle.model.impl.ModelImpl
-
- All Implemented Interfaces:
Model
@Service(Model.class) public class ModelImpl extends java.lang.Object implements Model
Model implementation.- Author:
- harald
-
-
Constructor Summary
Constructors Constructor Description ModelImpl()Creates a model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddModelEntity(ModelEntity modelEntity)Adds an entity to the model.voidclearModel()Clears the model.protected EntityFactorycreateEntityFactory()Creates the entity factory for this model.
The method is invoked once from within the Model constructor.protected ModelDirectorycreateModelDirectory(java.lang.String modelDir, ModelDefaults defaults, EntityAliases aliases)Creates a model directory object.protected ModelEntitycreateModelEntity(Entity entity, java.lang.String fileName)Creates a model entity wrapper.protected java.io.ReadercreateReader(java.lang.String name)Creates a reader for given name.java.util.Collection<Entity>getAllEntitites()Gets all cached entities.EntitygetByClassId(int classId)Gets the entity by its id.EntitygetByEntityName(java.lang.String entityName)Gets the entity by its name.EntitygetByFileName(java.lang.String fileName)Gets the entity by the mapfile name.EntityFactorygetEntityFactory()Gets the entity factory singleton.java.util.Collection<ForeignKey>getForeignKeys()Gets all foreign keys.booleanisSchemaNameMapped()Returns whether schema names are mapped.EntityloadByFileName(java.lang.String fileName, ModelDefaults defaults, EntityAliases aliases)Loads an entity for a given mapfile name.
Entities are cached so they are loaded and parsed only once.protected EntityloadByFileName(java.lang.String fileName, ModelDefaults defaults, EntityAliases aliases, boolean updateRelations)Loads an entity for a given mapfile name.
Entities are cached so they are loaded and parsed only once.voidloadModel(java.lang.String modelDir, ModelDefaults defaults, EntityAliases aliases)Loads the whole model from the model directory if not yet done.protected EntityparseEntity(ModelDefaults defaults, java.lang.String fileName)Parses the given file and returns the created entity.voidrefreshModel()Refreshes 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 java.lang.StringtranslateAlias(EntityAliases aliases, java.lang.String name)Translates an entity name if it is an alias.protected voidupdateCompositePath(java.util.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, java.util.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, 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!
-
-
-
Method Detail
-
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
public EntityFactory getEntityFactory()
Description copied from interface:ModelGets the entity factory singleton.- Specified by:
getEntityFactoryin interfaceModel- Returns:
- the entity model factory
-
loadModel
public void loadModel(java.lang.String modelDir, ModelDefaults defaults, EntityAliases aliases) throws ModelExceptionDescription 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
public void refreshModel() throws ModelExceptionDescription 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
public java.util.Collection<Entity> getAllEntitites() throws ModelException
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
-
getByFileName
public Entity getByFileName(java.lang.String fileName) throws ModelException
Description copied from interface:ModelGets the entity by the mapfile name.- Specified by:
getByFileNamein interfaceModel- 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: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
-
getByClassId
public Entity getByClassId(int classId) throws ModelException
Description copied from interface:ModelGets the entity by its 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
-
loadByFileName
public Entity loadByFileName(java.lang.String fileName, 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:
loadByFileNamein interfaceModel- Parameters:
fileName- the name 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
-
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 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
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 nonefileName- 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 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
-
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 farentity- the entity
-
getForeignKeys
public java.util.Collection<ForeignKey> getForeignKeys() throws ModelException
Description copied from interface:ModelGets all foreign keys.- Specified by:
getForeignKeysin interfaceModel- Returns:
- the foreign keys
- Throws:
ModelException- if model is inconsistent
-
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 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
protected ModelEntity createModelEntity(Entity entity, java.lang.String fileName) throws ModelException
Creates a model entity wrapper.- Parameters:
entity- the entityfileName- the model file name- Returns:
- the model entity
- Throws:
ModelException- if creation failed
-
createReader
protected java.io.Reader createReader(java.lang.String name) throws ModelExceptionCreates 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 checkinheritanceType- the inheritance typetrackType- the tracking typeintegrity- the integrity typeerrors- 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 checkintegrity- the integrity typeerrors- 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 aliasesname- the original name- Returns:
- the possibly translated name
-
-