Feeding a Model with Data from a Database

Using Query connectivity object, you can feed up a model with data returned by the specified query. Query result represents a set of rows. Each row contains a set of values from the table's columns you have specified in the query. You can use the query result to construct:

Constructing a replicated object based on query results

 To add instances to a replicated object based on query results

  1. Select the Query object that defines the query. 
  2. Go to the Data feeding section of the Properties view. 
  3. Select the For each row add check box.
  4. Select the Agent option.
  5. In the Agent population drop-down list, choose the agent population that you want to feed with new agents.
  6. In the table below, map the parameters of the replicated object you want to setup with the query columns to get these values from. Each mapped pair parameter-column is defined in individual row of the table. Choose the parameter you want to update in the Parameter/Field cell and type the name of the column of the database's table to get values from in the Column cell.
  7. If you want to populate the replicated object with new elements right on the model startup, select the Execute on startup check box. Otherwise you need to execute this query by calling its function execute().

Constructing a collection based on query results

You obviously feed a collection where elements are instances of some Java class. So, first you need to create a Java class with the requred fields.

Please note that all the fields of this Java class should be declared as public to enable access to them.

 To add elements to a collection based on query results

  1. Select the Query object that defines the query. 
  2. Specify the database this query will access in the Database edit box.
  3. If you need to retrieve all data from some table of the specified database, just select the Select all from the table option and specify the name of the table in the edit box to the right.
    If you are working with Access 2007 database, specify the name of the table in the square brackets, e.g.: [Table]
  4. Go to the Data feeding section of the Properties view. 
  5. Select the For each row add check box.
  6. Select the Element in collection option.
  7. Choose the collection you want to feed with values in the Collection drop-down list.
  8. In the table below, map the fields of the collection variable you want to setup with the query columns to get these values from. Each mapped pair field-column is defined in individual row of the table. Type the name of the field you want to update in the Parameter/Field cell and type the name of the column of the database's table to get values from in the Column cell.
  9. If you want to populate the collection with new elements right on the model startup, select the Execute on startup check box. Otherwise you need to execute this query by calling is function execute().