Class DatabaseResourceAdapter
java.lang.Object
net.simplace.sim.io.FWSimIOAdapter
net.simplace.sim.io.resources.FWSimInputAdapter
net.simplace.sim.io.resources.FWSimResourceAdapter<ResultSet>
net.simplace.sim.io.resources.adapter.DatabaseResourceAdapter
- All Implemented Interfaces:
FWSimFieldContainer
- Direct Known Subclasses:
DBFResourceAdapter
Resource adapter for databases (
DatabaseInterface). The data is read with the SQL statement of the
statement child (default SELECT * FROM <resource id>); tokens ${...}
in the statement are replaced with the values of the current simulation. The query is only executed again if the
resulting statement changed.- Author:
- Andreas Enders
-
Nested Class Summary
Nested classes/interfaces inherited from class FWSimIOAdapter
FWSimIOAdapter.FREQUENCE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringstatement executed last (tokens replaced); the same statement is not executed twiceprotected StringSQL statement, may contain${...}tokensFields inherited from class FWSimResourceAdapter
iLinesToReadFields inherited from class FWSimInputAdapter
iJexlScript, iShouldCacheToDBFields inherited from class FWSimIOAdapter
iArrayMode, iFieldcount, iFrequence, iHeaderVariables, iInterface, iJexlRule, iKeyMap, iName, iOrderNumber, iProcessTime, iResourceElement, iSession, iSourceKey -
Constructor Summary
ConstructorsConstructorDescriptionDatabaseResourceAdapter(String aPoolName, String aComponentName, int aOrderNumber, FWSimSession aFwSimSession, FWSimIOAdapter.FREQUENCE aFrequence, Map<String, String> aKeyMap, String aDriver, String aUrl, String aUser, String aPass, String aStatement) Creates the adapter from the graph panel: creates the database interface and derives the header variables from the result of the statement (seereadHeaderList(DatabaseInterface, String, Map, FWSimSession)).DatabaseResourceAdapter(FWSimResourceAdapter<?> aAdapter, DatabaseInterface aInterface) Copy constructor used when the interface is replaced; the key variables are taken over.DatabaseResourceAdapter(org.jdom2.Element aResourceElement, FWSimSession aSession, int aOrderNumber) Creates the adapter from aresourceelement of the solution. -
Method Summary
Modifier and TypeMethodDescriptiongetData(FWSimVarMap aVarMap) Executes the statement and reads the result into a new cache.getResultSet(FWSimVarMap aVarMap) Replaces the tokens in the statement and executes it, unless the resulting statement was executed last time.readHeaderList(DatabaseInterface aInterface, String aStatement, Map<String, String> aKeyMap, FWSimSession aSession) Determines the header variables from the column names and types of the statement result, plus a variableprojectid.voidsetStatement(String aStatement) Changes the SQL statement (e.g.org.jdom2.ElementtoXML()Adds thestatementelement to the element of the base class, if it differs from the defaultSELECT * FROM <resource id>.Methods inherited from class FWSimResourceAdapter
createAdapterFromObservable, createResourceAdapter, getLinesToRead, setLinesToRead, updateAdapterMethods inherited from class FWSimInputAdapter
getContentType, getInputVariables, getJexlScript, getOutputVariables, getVarMap, isTransformer, setFrequenceAndRule, shouldCacheToDB, toHTMLTablestringMethods inherited from class FWSimIOAdapter
addProcessTime, addVariable, checkCondition, createFormFields, createVariables, finalize, getCreateFormXML, getEditFormXML, getFieldMap, getFrequence, getHeaderVariables, getHeaderXML, getInterface, getJexlRule, getKeyMap, getName, getOrderNumber, getVariable, isArrayMode, isConditionCheck, removeVariable, setInterface, setOrderNumber, toString, writeHeaderList
-
Field Details
-
iStatement
SQL statement, may contain${...}tokens -
iLastStatement
statement executed last (tokens replaced); the same statement is not executed twice
-
-
Constructor Details
-
DatabaseResourceAdapter
public DatabaseResourceAdapter(org.jdom2.Element aResourceElement, FWSimSession aSession, int aOrderNumber) Creates the adapter from aresourceelement of the solution.- Parameters:
aResourceElement- theresourceelementaSession- the sessionaOrderNumber- order number of the adapter
-
DatabaseResourceAdapter
public DatabaseResourceAdapter(String aPoolName, String aComponentName, int aOrderNumber, FWSimSession aFwSimSession, FWSimIOAdapter.FREQUENCE aFrequence, Map<String, String> aKeyMap, String aDriver, String aUrl, String aUser, String aPass, String aStatement) throws ExceptionCreates the adapter from the graph panel: creates the database interface and derives the header variables from the result of the statement (seereadHeaderList(DatabaseInterface, String, Map, FWSimSession)).- Parameters:
aPoolName- name of the connection poolaComponentName- name of the adapteraOrderNumber- order number of the adapteraFwSimSession- the sessionaFrequence- frequency the data is read withaKeyMap- key variables; if empty, the user is asked to select themaDriver- JDBC driver classaUrl- JDBC URLaUser- database useraPass- passwordaStatement- SQL statement, defaultSELECT * FROM <component name>- Throws:
Exception- if the connection or the query failsSimFieldMissingException- if no key variables are given or selected
-
DatabaseResourceAdapter
Copy constructor used when the interface is replaced; the key variables are taken over.- Parameters:
aAdapter- the adapter to copyaInterface- the new interface
-
-
Method Details
-
getData
Executes the statement and reads the result into a new cache.- Specified by:
getDatain classFWSimInputAdapter- Parameters:
aVarMap- variable map of the simulation (e.g. for the key values of the rule)- Returns:
- the new cache, or
nullif the statement is unchanged (the previous cache stays valid) - Throws:
MissingSimResourceException- if the data cannot be read- See Also:
-
getResultSet
Replaces the tokens in the statement and executes it, unless the resulting statement was executed last time.- Parameters:
aVarMap- variable map of the simulation- Returns:
- the result set, or
nullif the statement is unchanged - Throws:
MissingSimResourceException- if the query fails
-
getStatement
- Returns:
- the SQL statement (with tokens)
-
setStatement
Changes the SQL statement (e.g. in the GUI); empty meansSELECT * FROM <resource id>. The statement is executed again on the next read.- Parameters:
aStatement- SQL statement, may contain tokens
-
toXML
public org.jdom2.Element toXML()Adds thestatementelement to the element of the base class, if it differs from the defaultSELECT * FROM <resource id>.- Specified by:
toXMLin interfaceFWSimFieldContainer- Overrides:
toXMLin classFWSimResourceAdapter<ResultSet>- Returns:
- an XML element with all settings of this container
- See Also:
-
readHeaderList
public Map<String,String> readHeaderList(DatabaseInterface aInterface, String aStatement, Map<String, String> aKeyMap, FWSimSession aSession) throws ExceptionDetermines the header variables from the column names and types of the statement result, plus a variableprojectid. If no key variables are given, the user is asked to select them.- Parameters:
aInterface- the database interfaceaStatement- SQL statementaKeyMap- key variables, may benullor emptyaSession- the session (provides the model variables for the key selection)- Returns:
- the key variables, or
nullif none were given or selected - Throws:
Exception- if the query fails
-