Class FWSimResourceCache
java.lang.Object
net.simplace.sim.io.FWSimCache
net.simplace.sim.io.resources.FWSimResourceCache
- All Implemented Interfaces:
FWSimFieldContainer
Cache of the data read by a resource adapter or transformer. For fast access every data line is stored as
Object[] (one value per header variable) under its key: the value of the key variable, or a list of
values if the resource has several key variables. During the simulation the line matching the current key values
is copied into the variable map (fillVarMapFromCache(FWSimVarMap)).
If configured, the cache is also stored as table in an internal database, so it can be used by the
DefaultSQLStatementTransformer.
- Author:
- Andreas Enders
-
Field Summary
Fields inherited from class FWSimCache
iArrayMode, iCache, iFieldcount, iFrequence, iHeaderVariables, iName, iOrderNumber, iVariablesIndexes -
Constructor Summary
ConstructorsConstructorDescriptionFWSimResourceCache(FWSimSession aFwSimSession, LinkedHashMap<String, String> aKeyMap, FWSimInputAdapter aResourceAdapter, String aUniqueID, FWSimInterface.INTERFACE_TYPE aInterfaceType) Creates an empty cache for an adapter or transformer; header variables, frequency, name and order number are taken from the adapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVariable(FWSimVariable<?> aVariable) Adds a header variable.voidfillVarMapFromCache(FWSimVarMap aSimVarMap) Copies the data line for the current key values into the variable map, using the adapter of this cache, seefillVarMapFromCache(FWSimVarMap, FWSimInputAdapter).voidfillVarMapFromCache(FWSimVarMap aSimVarMap, FWSimInputAdapter aInputAdapter) Copies the data line for the current key values into the variable map: the key is built from the current values of the key variables of the adapter (a list for several keys), and each value of the line is set to the corresponding header variable.Returnsres.org.jdom2.ElementReturns the create form of the adapter.org.jdom2.ElementgetEditFormXML(boolean aEnabled) Returns the edit form of the adapter.Returns an empty list; resources have no input variables.Returns the header variables.getVariable(String aID) Returns a header variable, ornullif unknown.Returns the variable map of the control cache of the session.booleanvoidremoveVariable(String aID) Removes a header variable.voidsetInterfaceType(FWSimInterface.INTERFACE_TYPE aInterfaceType) booleanshouldUpdate(FWSimVarMap aVarMap) Checks whether the variables have to be filled from the cache in the current step, using the adapter of this cache, seeshouldUpdate(FWSimVarMap, FWSimInputAdapter).booleanshouldUpdate(FWSimVarMap aVarMap, FWSimInputAdapter aInputAdapter) Checks by the frequency of the adapter whether the variables have to be filled from the cache in the current step: never for ONCE and NON, every day for DAILY, on the first day of the month for MONTHLY, on the first day of the year for YEARLY, and depending on the rule for COMPLEX (JEXL expression) and BOOLEAN (name of a boolean variable).splitCache(LinkedHashMap<String, String> aKeyMap) Splits the data lines into groups that have equal values in the given key variables (e.g.toString()org.jdom2.ElementtoXML()Returns the XML of the adapter.Methods inherited from class FWSimCache
checkCondition, createVariables, getCache, getFieldcount, getFieldMap, getFrequence, getName, getOrderNumber, getVariableIndex, getVariables, isArrayMode, isConditionCheck, setCacheMap
-
Constructor Details
-
FWSimResourceCache
public FWSimResourceCache(FWSimSession aFwSimSession, LinkedHashMap<String, String> aKeyMap, FWSimInputAdapter aResourceAdapter, String aUniqueID, FWSimInterface.INTERFACE_TYPE aInterfaceType) Creates an empty cache for an adapter or transformer; header variables, frequency, name and order number are taken from the adapter.- Parameters:
aFwSimSession- the sessionaKeyMap- key variables of the resourceaResourceAdapter- the adapter or transformeraUniqueID- unique id of the cacheaInterfaceType- type of the interface the data is read from
-
-
Method Details
-
fillVarMapFromCache
Copies the data line for the current key values into the variable map, using the adapter of this cache, seefillVarMapFromCache(FWSimVarMap, FWSimInputAdapter).- Parameters:
aSimVarMap- variable map of the simulation
-
fillVarMapFromCache
Copies the data line for the current key values into the variable map: the key is built from the current values of the key variables of the adapter (a list for several keys), and each value of the line is set to the corresponding header variable. If no line exists for the key, the variables are set tonull. Range violations and other errors are logged.- Parameters:
aSimVarMap- variable map of the simulationaInputAdapter- adapter defining key and header variables (e.g. an alias using this cache)
-
addVariable
Adds a header variable. Use with care: the data lines are not adapted.- Specified by:
addVariablein interfaceFWSimFieldContainer- Overrides:
addVariablein classFWSimCache- Parameters:
aVariable- the variable to add- See Also:
-
getVariable
Returns a header variable, ornullif unknown.- Specified by:
getVariablein interfaceFWSimFieldContainer- Overrides:
getVariablein classFWSimCache- Parameters:
aID- id of the variable- Returns:
- the variable
- See Also:
-
removeVariable
Removes a header variable. Use with care: the data lines are not adapted.- Specified by:
removeVariablein interfaceFWSimFieldContainer- Overrides:
removeVariablein classFWSimCache- Parameters:
aID- id of the variable- See Also:
-
getOutputVariables
Returns the header variables.- Specified by:
getOutputVariablesin interfaceFWSimFieldContainer- Overrides:
getOutputVariablesin classFWSimCache- Returns:
- the output variables of the field map
- See Also:
-
getInputVariables
Returns an empty list; resources have no input variables.- Specified by:
getInputVariablesin interfaceFWSimFieldContainer- Overrides:
getInputVariablesin classFWSimCache- Returns:
- the input variables of the field map
- See Also:
-
getContentType
Returnsres.- Specified by:
getContentTypein interfaceFWSimFieldContainer- Overrides:
getContentTypein classFWSimCache- Returns:
- the content type of the variables of this container (e.g.
sys,mgm) - See Also:
-
getKeyMap
- Returns:
- the key variables of the resource
-
shouldUpdate
Checks whether the variables have to be filled from the cache in the current step, using the adapter of this cache, seeshouldUpdate(FWSimVarMap, FWSimInputAdapter).- Parameters:
aVarMap- variable map of the simulation- Returns:
trueif the variables have to be updated
-
shouldUpdate
Checks by the frequency of the adapter whether the variables have to be filled from the cache in the current step: never for ONCE and NON, every day for DAILY, on the first day of the month for MONTHLY, on the first day of the year for YEARLY, and depending on the rule for COMPLEX (JEXL expression) and BOOLEAN (name of a boolean variable).- Parameters:
aVarMap- variable map of the simulationaInputAdapter- adapter defining frequency and rule- Returns:
trueif the variables have to be updated;falsealso if evaluating the rule fails (the error is logged)
-
toXML
public org.jdom2.Element toXML()Returns the XML of the adapter.- Returns:
- an XML element with all settings of this container
- See Also:
-
getCreateFormXML
public org.jdom2.Element getCreateFormXML()Returns the create form of the adapter.- Returns:
- the XML form definition used by the GUI to create this container
- See Also:
-
getEditFormXML
public org.jdom2.Element getEditFormXML(boolean aEnabled) Returns the edit form of the adapter.- Parameters:
aEnabled- iffalse, the form fields are read-only- Returns:
- the XML form definition used by the GUI to edit the settings of this container
- See Also:
-
getCurrentSession
- Returns:
- the session of the cache
-
toString
-
getUniqueID
- Returns:
- the unique id of the cache
-
isFromTransformer
public boolean isFromTransformer()- Returns:
trueif the cache was filled by a transformer
-
getResourceAdapter
- Returns:
- the adapter or transformer the cache belongs to
-
splitCache
Splits the data lines into groups that have equal values in the given key variables (e.g. one group per location if the keys are location and date). With only one key variable in the cache, the whole cache is returned as single group.- Parameters:
aKeyMap- the key variables to group by; a subset of the key variables of the cache- Returns:
- the groups of data lines, each as map from key to line
-
getVarMap
Returns the variable map of the control cache of the session.- Returns:
- the var map this container belongs to
- See Also:
-
getInterfaceType
- Returns:
- the type of the interface the data was read from
-
setInterfaceType
- Parameters:
aInterfaceType- the type of the interface the data was read from
-