Package org.eclipse.epsilon.eol.models
Class CachedModel<ModelElementType>
- java.lang.Object
-
- org.eclipse.epsilon.eol.models.Model
-
- org.eclipse.epsilon.eol.models.CachedModel<ModelElementType>
-
- All Implemented Interfaces:
AutoCloseable
,IModel
- Direct Known Subclasses:
AbstractEmfModel
,AbstractSimulinkModel
,BibtexModel
,CachedModelTests.SimpleCachedModel
,CsvModel
,HtmlModel
,JdtModel
,PlainXmlModel
,YamlModel
public abstract class CachedModel<ModelElementType> extends Model
A model that performs memoization of allContents, getAllOfType and getAllOfKind. Subclasses should implement the template methods, which compute real values from the model or provide keys that can be used with aMap
. Although the collections used here are optionally thread-safe, subclasses should manage their own data structures according to the isConcurrent flag. In particular,allContentsFromModel()
should be managed appropriately by subclasses.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.epsilon.eol.models.IModel
IModel.AmbiguityCheckResult
-
-
Field Summary
Fields Modifier and Type Field Description protected Collection<ModelElementType>
allContentsCache
protected Multimap<Object,ModelElementType>
kindCache
static String
PROPERTY_CACHED
Whether to cache allOf* calls by default.static String
PROPERTY_CONCURRENT
Whether to use thread-safe collections by default.protected Multimap<Object,ModelElementType>
typeCache
-
Fields inherited from class org.eclipse.epsilon.eol.models.Model
aliases, ENV_PREFIX, name, PROPERTY_ALIASES, PROPERTY_NAME, PROPERTY_READONLOAD, PROPERTY_READONLY, PROPERTY_STOREONDISPOSAL, propertyGetter, propertySetter, readOnLoad, storeOnDisposal
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CachedModel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addToCache(String type, ModelElementType instance)
Collection<ModelElementType>
allContents()
Returns a collection containing all of the objects contained in this model.protected abstract Collection<ModelElementType>
allContentsFromModel()
void
clearCache()
ModelElementType
createInstance(String type)
protected abstract ModelElementType
createInstanceInModel(String type)
void
deleteElement(Object o)
protected abstract boolean
deleteElementInModel(Object instance)
Returns true iff the given instance was deleted from the model.void
dispose()
protected abstract void
disposeModel()
Collection<ModelElementType>
getAllOfKind(String kind)
protected abstract Collection<ModelElementType>
getAllOfKindFromModel(String kind)
protected Collection<ModelElementType>
getAllOfKindOrType(boolean isKind, String modelElementType)
Collection<ModelElementType>
getAllOfType(String type)
protected abstract Collection<ModelElementType>
getAllOfTypeFromModel(String type)
protected abstract Collection<String>
getAllTypeNamesOf(Object instance)
Returns the fully qualified names of every type to which the given object conforms.protected abstract Object
getCacheKeyForType(String type)
Returns an identity for the given type, which will be used byCachedModel
as a key for the memoization of model elements by type.protected void
initCaches()
Sets the caches based on this model's properties.boolean
isCachingEnabled()
boolean
isConcurrent()
boolean
isLoaded()
Convenience method for determining when a model has been loaded.void
load()
void
load(StringProperties properties, IRelativePathResolver resolver)
protected abstract void
loadModel()
protected void
removeFromCache(ModelElementType instance)
void
setCachingEnabled(boolean cachingEnabled)
void
setConcurrent(boolean concurrent)
protected Collection<ModelElementType>
wrap(Collection<ModelElementType> contents)
-
Methods inherited from class org.eclipse.epsilon.eol.models.Model
allInstances, createInstance, getAliases, getFullyQualifiedTypeNameOf, getMetamodel, getName, getPropertyGetter, getPropertySetter, getTransactionSupport, getTypeOf, isModelElement, isOfKind, isOfType, isPropertySet, isReadOnLoad, isStoredOnDisposal, knowsAboutProperty, load, load, setName, setReadOnLoad, setStoredOnDisposal
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.epsilon.eol.models.IModel
checkAmbiguity, close, getElementById, getElementId, getEnumerationValue, getTypeNameOf, hasType, isInstantiable, owns, setElementId, store, store
-
-
-
-
Field Detail
-
PROPERTY_CACHED
public static final String PROPERTY_CACHED
Whether to cache allOf* calls by default. False for compatibility.- See Also:
- Constant Field Values
-
PROPERTY_CONCURRENT
public static final String PROPERTY_CONCURRENT
Whether to use thread-safe collections by default. False for compatibility.- Since:
- 1.6
- See Also:
- Constant Field Values
-
allContentsCache
protected Collection<ModelElementType> allContentsCache
-
typeCache
protected Multimap<Object,ModelElementType> typeCache
-
kindCache
protected Multimap<Object,ModelElementType> kindCache
-
-
Method Detail
-
allContentsFromModel
protected abstract Collection<ModelElementType> allContentsFromModel()
-
getAllOfTypeFromModel
protected abstract Collection<ModelElementType> getAllOfTypeFromModel(String type) throws EolModelElementTypeNotFoundException
-
getAllOfKindFromModel
protected abstract Collection<ModelElementType> getAllOfKindFromModel(String kind) throws EolModelElementTypeNotFoundException
-
createInstanceInModel
protected abstract ModelElementType createInstanceInModel(String type) throws EolModelElementTypeNotFoundException, EolNotInstantiableModelElementTypeException
-
loadModel
protected abstract void loadModel() throws EolModelLoadingException
- Throws:
EolModelLoadingException
-
disposeModel
protected abstract void disposeModel()
-
deleteElementInModel
protected abstract boolean deleteElementInModel(Object instance) throws EolRuntimeException
Returns true iff the given instance was deleted from the model.- Throws:
EolRuntimeException
-
getCacheKeyForType
protected abstract Object getCacheKeyForType(String type) throws EolModelElementTypeNotFoundException
Returns an identity for the given type, which will be used byCachedModel
as a key for the memoization of model elements by type.
-
getAllTypeNamesOf
protected abstract Collection<String> getAllTypeNamesOf(Object instance)
Returns the fully qualified names of every type to which the given object conforms. The values are used by byCachedModel
for the memoization of model elements by their kind (getAllOfKind(String)
).
-
initCaches
protected void initCaches()
Sets the caches based on this model's properties. This method should only be called if there has been a change to the properties (cachingEnabled
orconcurrent
) as the caches will be reset.- Since:
- 1.6
-
setCachingEnabled
public void setCachingEnabled(boolean cachingEnabled)
-
isCachingEnabled
public boolean isCachingEnabled()
-
isConcurrent
public boolean isConcurrent()
- Returns:
- Since:
- 1.6
-
setConcurrent
public void setConcurrent(boolean concurrent)
- Parameters:
concurrent
-- Since:
- 1.6
-
wrap
protected Collection<ModelElementType> wrap(Collection<ModelElementType> contents)
- Parameters:
contents
- The model elements- Returns:
- Since:
- 1.6
-
addToCache
protected void addToCache(String type, ModelElementType instance) throws EolModelElementTypeNotFoundException
-
removeFromCache
protected void removeFromCache(ModelElementType instance) throws EolModelElementTypeNotFoundException
-
isLoaded
public boolean isLoaded()
Convenience method for determining when a model has been loaded.- Returns:
- Whether the cache has been populated.
- Since:
- 1.6
-
allContents
public Collection<ModelElementType> allContents()
Description copied from interface:IModel
Returns a collection containing all of the objects contained in this model.- Returns:
- all of the objects contained in this model.
-
getAllOfKindOrType
protected Collection<ModelElementType> getAllOfKindOrType(boolean isKind, String modelElementType) throws EolModelElementTypeNotFoundException
- Parameters:
isKind
-true
if callinggetAllOfKind(String)
.modelElementType
- The name of the model element type.- Returns:
- All model elements conforming to the kind / type (depending on the flag).
- Throws:
EolModelElementTypeNotFoundException
- Since:
- 1.6
-
getAllOfType
public Collection<ModelElementType> getAllOfType(String type) throws EolModelElementTypeNotFoundException
-
getAllOfKind
public Collection<ModelElementType> getAllOfKind(String kind) throws EolModelElementTypeNotFoundException
-
createInstance
public ModelElementType createInstance(String type) throws EolModelElementTypeNotFoundException, EolNotInstantiableModelElementTypeException
-
deleteElement
public void deleteElement(Object o) throws EolRuntimeException
- Throws:
EolRuntimeException
-
load
public void load() throws EolModelLoadingException
- Throws:
EolModelLoadingException
-
load
public void load(StringProperties properties, IRelativePathResolver resolver) throws EolModelLoadingException
- Specified by:
load
in interfaceIModel
- Overrides:
load
in classModel
- Throws:
EolModelLoadingException
-
dispose
public void dispose()
-
clearCache
public void clearCache()
-
-