Package com.anylogic.engine.connectivity
- java.lang.Object
- com.anylogic.engine.connectivity.ConnectivityBase
- com.anylogic.engine.connectivity.DatabaseAccessor
- com.anylogic.engine.connectivity.Query
- All Implemented Interfaces:
Serializable
public class Query extends DatabaseAccessor
Query object for database connectivity
Works in 2 modes:
This object is only available in the AnyLogic Professional
Works in 2 modes:
- Returns
ResultSet
object (seeexecute()
) which can be iterated to retrieve result values - Maps rows of database resulting table to the fields of newly created
elements in collection or new
Agent
s in agent population (seeexecuteAndMap()
)
This object is only available in the AnyLogic Professional
- Author:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
- Serialized Form
Constructor | Description |
---|---|
Query | |
Query |
Creates new
Query for work in the Mapping mode (executeAndMap()
method)Note the execute() method is still available for this object |
Modifier and Type | Method | Description |
---|---|---|
Object | createNewRowElementInstance_xjal() |
Extension-point for element creation
In the Mapping mode, this method should be overridden to create specific element and return it |
final ResultSet | execute() |
Executes query in the database and returns single
ResultSet If any error occurs, throws RuntimeException Connects Database if it is not connected. |
final int | executeAndMap() |
This method fills underlying collection or agent population
(created agents are started automatically) with elements created
from rows of database Query result
This method works only in the Mapping mode |
final int | executeAndMap |
This method fills underlying collection or agent population with
elements created from rows of database Query result
This method works only in the Mapping mode |
void | registerNewRowElement_xjal |
Extension-point for element creation
In the Mapping mode, this method should be overridden to start given element (previously created by createNewRowElementInstance_xjal() and parametrized) add it to the
underlying collection and return it |
String | toString() |
public Query(String name, Database database, boolean selectFromTable, String tableNameOrQueryText)
- Parameters:
name
- object name (decoration purpose)database
-selectFromTable
-tableNameOrQueryText
-
public Query(String name, Database database, boolean selectFromTable, String tableNameOrQueryText, String[][] mapping)
Creates new
Note the
Query
for work in the Mapping mode (executeAndMap()
method)Note the
execute()
method is still available for this object- Parameters:
name
- object name (decoration purpose)database
- database to connect toselectFromTable
- flag indicating what value is contained in parametertableNameOrQueryText
tableNameOrQueryText
-- the table name to select data from, - if
selectFromTable
istrue
- SQL query text, otherwise
- the table name to select data from, - if
mapping
- mappings array with dimensionsN x 2
like:new String[][] { { "fieldName0", "columnLabel0" }, { "fieldName1", "columnLabel1" }, // ... }
where- fieldName is name of field in the created collection element
or
Agent
- columnLabel is column's title which is used in printouts and
displays. This title is usually specified by the SQL
AS
clause. If a SQLAS
is not specified, the table column name is assumed
- fieldName is name of field in the created collection element
or
@AnyLogicInternalCodegenAPI public Object createNewRowElementInstance_xjal()
Extension-point for element creation
In the Mapping mode, this method should be overridden to create specific element and return it
In the Mapping mode, this method should be overridden to create specific element and return it
- Returns:
- new element instance created for each row
@AnyLogicInternalCodegenAPI public void registerNewRowElement_xjal(Object element, boolean startAgents)
Extension-point for element creation
In the Mapping mode, this method should be overridden to start given element (previously created by
In the Mapping mode, this method should be overridden to start given element (previously created by
createNewRowElementInstance_xjal()
and parametrized) add it to the
underlying collection and return it- Parameters:
startAgents
- defines either created agents are started or not
overridden method should callstart()
method on agent only if this parameter istrue
public final ResultSet execute()
Executes query in the database and returns single
If any error occurs, throws
Connects
ResultSet
If any error occurs, throws
RuntimeException
Connects
Database
if it is not connected. After this method call
Database
remains connected.- Returns:
- new
ResultSet
object; nevernull
Please callResultSet.close()
method after all needed operations are completed
public final int executeAndMap()
This method fills underlying collection or agent population
(created agents are started automatically) with elements created
from rows of database Query result
This method works only in the Mapping mode
This method works only in the Mapping mode
- Returns:
- number of created objects
public final int executeAndMap(boolean startAgents)
This method fills underlying collection or agent population with
elements created from rows of database Query result
This method works only in the Mapping mode
This method works only in the Mapping mode
- Parameters:
startAgents
- defines either created agents are started or not- Returns:
- number of created objects
public String toString()
- Overrides:
toString
in classConnectivityBase