java.lang.Object
org.tentackle.model.impl.ModelImpl
- All Implemented Interfaces:
Model
Model implementation.
- Author:
- harald
-
Field Summary
Fields inherited from interface org.tentackle.model.Model
MODEL_INDEX_LIST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddEntityInfo(EntityInfo entityInfo) 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 EntityInfocreateEntityInfo(ModelDefaults defaults, URL url) Creates a model entity wrapper.protected ModelDirectorycreateModelDirectory(String modelDir) Creates a model directory object.protected ReadercreateReader(URL url) 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.getByTableName(String tableName) Gets the entity by its table name.Gets the entity by the model file path.Gets the entity aliases.Gets the entity factory singleton.getEntityInfo(Entity entity) Gets the model information for the given entity.Gets all foreign keys.Gets the model defaults.booleanReturns whether schema names are mapped.protected booleanisValidTableAlias(String alias) Checks if a table alias is a valid name for all backends.loadFromDirectory(String modelDir, boolean updateRelations) Loads the whole model from the model directory if not yet done.loadFromJar(File file, boolean updateRelations) Loads the model from a jar file.
Reads the model files listed inMETA-INF/MODEL-INDEX.LIST.loadFromResources(boolean updateRelations) Loads from resources.
Locates allMETA-INF/MODEL-INDEX.LISTresources and loads the model files.loadFromURL(URL url, boolean updateRelations) Loads an entity from a given URL.
Entities are cached, so they are loaded and parsed only once.voidRefreshes the model.
Checks for changes and reloads if necessary.voidsetEntityAliases(EntityAliases entityAliases) Sets the entity aliases for relations between entities.voidsetModelDefaults(ModelDefaults modelDefaults) Sets the model defaults to apply when loading the model sources.voidsetSchemaNameMapped(boolean mapSchemas) Sets whether schema names should be mapped to the leading part of table names.protected StringtranslateAlias(String name) Translates an entity name if it is an alias.protected voidupdateCompositePath(List<Relation> compositePath, Entity entity) Updates the composite path.voidUpdates the relations if not yet done during load.protected voidupdateRelations(EntityInfo loadedEntityInfo) 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 inheritance hierarchy.
Notice that concrete classes (the leafs of the hierarchy) must haveInheritanceType.NONEdefined!
-
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 table names.- 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
-
getModelDefaults
Description copied from interface:ModelGets the model defaults.- Specified by:
getModelDefaultsin interfaceModel- Returns:
- the model defaults, null if none
-
setModelDefaults
Description copied from interface:ModelSets the model defaults to apply when loading the model sources.- Specified by:
setModelDefaultsin interfaceModel- Parameters:
modelDefaults- the model defaults, null if none
-
getEntityAliases
Description copied from interface:ModelGets the entity aliases.- Specified by:
getEntityAliasesin interfaceModel- Returns:
- the aliases, null if none
-
setEntityAliases
Description copied from interface:ModelSets the entity aliases for relations between entities.- Specified by:
setEntityAliasesin interfaceModel- Parameters:
entityAliases- the aliases, null if none
-
getEntityFactory
Description copied from interface:ModelGets the entity factory singleton.- Specified by:
getEntityFactoryin interfaceModel- Returns:
- the entity model factory
-
loadFromDirectory
public Collection<EntityInfo> loadFromDirectory(String modelDir, boolean updateRelations) throws ModelException Description copied from interface:ModelLoads the whole model from the model directory if not yet done.- Specified by:
loadFromDirectoryin interfaceModel- Parameters:
modelDir- the name of the directory containing the model filesupdateRelations- 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
Description copied from interface:ModelLoads an entity from a given URL.
Entities are cached, so they are loaded and parsed only once.- Specified by:
loadFromURLin interfaceModel- Parameters:
url- the URL of the model fileupdateRelations- 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
Description copied from interface:ModelLoads the model from a jar file.
Reads the model files listed inMETA-INF/MODEL-INDEX.LIST.- Specified by:
loadFromJarin interfaceModel- Parameters:
file- the jar fileupdateRelations- 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
Description copied from interface:ModelLoads from resources.
Locates allMETA-INF/MODEL-INDEX.LISTresources and loads the model files.- Specified by:
loadFromResourcesin interfaceModel- 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
Description copied from interface:ModelUpdates the relations if not yet done during load.- Specified by:
updateRelationsin interfaceModel- Throws:
ModelException- if model is inconsistent- See Also:
-
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
-
getAllEntities
Description copied from interface:ModelGets all cached entities.- Specified by:
getAllEntitiesin interfaceModel- Returns:
- all entities loaded so far
- Throws:
ModelException- if the model is inconsistent
-
getByURL
Description copied from interface:ModelGets the entity by the model file path.- Specified by:
getByURLin interfaceModel- Parameters:
url- the URL of the model file- 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
-
getEntityInfo
Description copied from interface:ModelGets the model information for the given entity.- Specified by:
getEntityInfoin interfaceModel- Parameters:
entity- the entity- Returns:
- the model info, never null
- Throws:
ModelException- if the model is inconsistent or no such entity
-
getForeignKeys
Description copied from interface:ModelGets all foreign keys.- Specified by:
getForeignKeysin interfaceModel- Returns:
- the foreign keys
- Throws:
ModelException- if model is inconsistent
-
addEntityInfo
Adds an entity to the model.- Parameters:
entityInfo- the model entity- Throws:
ModelException- if duplicate entities detected
-
updateRelations
Updates all relations.- Parameters:
loadedEntityInfo- the entity that caused the update, null if none- Throws:
ModelException- if relations or inheritance misconfiguration
-
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
protected void updateCompositePath(List<Relation> compositePath, Entity entity) throws ModelException Updates the composite path.- Parameters:
compositePath- the path that leads to given entity so farentity- the entity- Throws:
ModelException
-
createEntityFactory
Creates the entity factory for this model.
The method is invoked once from within the Model constructor.- Returns:
- the entity factory
-
createModelDirectory
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
Creates a model entity wrapper.- Parameters:
defaults- the optional model defaultsurl- the url of the model file- Returns:
- the model entity
- Throws:
ModelException- if creation failed
-
createReader
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 haveInheritanceType.NONEdefined!- 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:
name- the original name- Returns:
- the possibly translated name
-