CHAPTER 7

DATABASE BEANS

The output data of a simulation is very important to the user. A user who runs the simulation may try to use the simulation to predict the behavior of a complicated system and help him/her make some decisions. Some simulation data may be used later to compare with other simulations. Therefore, it is good idea to store the output data in an well-organized fashion. Database management systems provide an easy and powerful way to define, manage and manipulate large amounts of data.

In JSIM component simulation environment, the database accessing must be implemented as component too. This database-accessing bean should be able to work with all kinds of model and model agent beans. To make database accessing easy, a package called jquery is implemented to handle all kinds of operations related to database.

7.1 Java Database Connection

The database bean is connected to some DBMS by Java Database Connection (JDBC). The database bean is able to expose its properties to the environment and user can modify them. These properties include url of the hosting machine of the DBMS, the port number for data communication, the database name, as well as user login ID and password. With these properties, a database bean can connect to a DBMS and get

database metadata. In a typical simulation, users want to store properties of models and model agents, as well as the simulation output data to a database. To do this, the user needs to connect ScenarioAgent and model agent with DbUpdate bean. The ScenarioAgent fires ScenarioEvent, which contains the properties of model and model agent. The model agent can trigger a PrimaryReportEvent, when the simulation is finished. This event will carry the simulation primary results to the DbUpdate bean. The DbUpdate bean gets the data from the coming events and retrieves the name of table that the data is going to be stored. It compares the name of table with all the names of tables in database metadata. If there is match, it will continue to retrieve the column name and types from database metadata. If column names and types match the data to be stored, the data can be stored properly. If anything goes wrong, the database bean will give an error message to indicate what is wrong. Because the database bean can search the DBMS metadata to find the right table, it can store output data for any model and model agent as long as the table related to the model or model agent is in the database. The further details about storing data using JDBC is covered in [Ge, 1998].

7.2 jquery Package

The jquery package contains classes and beans making it easy for other components to access relational (e.g., Mini SQL) and object-relational (e.g., Oracle 8) databases. JSIM can be linked to a variety of database management systems because of its reliance on Java Database Connectivity (JDBC). Typically, this is as easy as changing the connection specification (e.g., to change the connection specification from Mini SQL to Oracle simply changes the url as shown below).

url = "jdbc:msql://sandstone.cs.uga.edu:1888/jsim"

url = "jdbc:oracle:thin://orion.cs.uga.edu:1521/jsim"

In the worst case, the JDBC driver may need to be changed, but this only effects a few lines of code since the JDBC API is the same in any case. A couple of important beans in this package are the following.

7.2.1 DbQuery Bean.

The DbQuery bean responds to events that embed SQL queries. Using JDBC it sends a query to the designated database and places the results in an AbstractTableModel allowing the results to be readily sent back to the requester or displayed. DbQuery can help user to find out, quickly and easily, the information related to simulation, such as the properties of a model, properties of a model agent, available simulation results. Figure 1 is a screen shot of the DbQuery bean.

 

Figure 1: Screen shot of DbQuery bean

7.2.2 DbUpdate Bean.

The DbUpdate bean similarly responds to events that embed SQL updates. It is mainly used by model and model agent beans to store their properties. It also can store away the simulation data associated with particular model and model agent properties. This makes it easy to run models with or without a database, or switch databases since the association between the beans is established dynamically.

7.2.3 DbBrowser Bean

The DbBrowser can retrieve all the names of tables from the database once it connected to a specific database chosen by users. Users can browser the entire context of a table by selecting the name of the table and clicking the Browse button. This will help user to allocate the data s/he is interested in without knowing the entire database very well. The amount of data stored in database may be very large. To make the data searching fast, the DbBrowser bean also shows the column names of the selected table. Users can pick a column name, and the DbBrowser bean will display the entire table content ordered by that column name. A screen shot of DbBrowser bean is shown in figure 2.

 

Figure 2. DbBrowser Bean window

User also can browse other database information. The only thing s/he needs to do is reset the url of the hosting machine, the port number, and the database name, as well as the user login ID and password. When this is done, s/he clicks the Connect button to establish the connection.

7.3 Database Schema

To store the properties of a model and model agent to a relational database properly, a suitable database schema is required. This schema makes use of part of the database schema described by the Yongfu Ge’s thesis [Ge, 98]. Because new entities, such as AgentProperty entity, is added to the schema. There are two main entities in simulation related data storage. They are model property entity, which describes the

Figure 3: Entity-Relationship model of Database schema

properties of model, and model agent property entity, which captures model agent properties. The primary output data is a relationship which shows the association between model property and agent property entities. It describes the output of the simulation. The distribution is a multivalued attribute of the model property entity. It is used to store the distribution data related to the model property. According to the entities and their relationship, the Entity-Relationship model of the schema is shown in figure 3. The database tables and their attributes are show in table 1, with key attributes underlined.

CREATE TABLE ModelProperty(

mPropertyID int not null,

paraName char(20) not null,

distribution char(5),

paraValue char(20)

)

CREATE TABLE AgentProperty(

agentID int not null,

agentName char(20) not null,

tranTime real not null,

relPrecision real,

batchSize int,

minNumBatch int,

confidence real,

replSize int,

)

CREATE TABLE Distribution(

distrID int not null,

distrName char(20) not null,

para1 real,

para2 real,

para3 real,

para4 real

)

 

CREATE TABLE PrimaryOutPut(

mPropertyID int not null,

agentID int not null,

name char(20),

numSample int,

minimum real,

maximum real,

mean real,

stdDev real,

interval real

)

Table 1: Database schema of the simulation output data

The model property table has four attributes. Model property ID and parameter name are key attributes. To make the parameter name unique, the original parameter name is appended to the node name to form the new parameter name. The distribution is a boolean variable to indicate if the model property parameter is a distribution. If the parameter is a distribution, the distribution ID will be stored as value of the attribute paraValue. Otherwise, paraValue stores the actual value of the model property.

The Distribution table captures the information of a distribution pertaining to a model node. The distribution ID is the key, distribution name and other arguments of the distribution are the attributes of this table. In JSIM, there are twenty-four different distributions, the maximum number of arguments are four. The null value is used in case some distributions do not have four arguments.

The output data analyzed by a particular model agent is closely related to the properties of the model agent. The values of these properties are important and must be stored in database as well. For current situation, there are two model agents. One model agent property table can cope with very well. All the properties of the two model agents can be well described by this table.

The primary output data is the main outcome of the simulation from a simulation run. It is composed of the name, minimum value, maximum value, mean value, standard deviation, and standard interval. The output data depends on the properties of the model and the model agent. Therefore, mPropertyID and agentID are key attributes.

With the strength of JDBC and Java component technology, the data storage of simulation can be achieved with lot of freedom and flexibility. This is another advantage of Web-based simulation.