Database Notes

Overview

We are currently using Hibernate 3.2 to persist data objects. Hibernate hides a multitude of details at the JDBC level, including conversion of data types in queries and result sets, and transaction handling. In addition, from the Hibernate Web page:

"Hibernate is a powerful, high performance object/relational persistence and query service. Hibernate lets you develop persistent classes following object-oriented idiom - including association, inheritance, polymorphism, composition, and collections."

The underlying database server is MySQL. Currently we are using version 5.0. The MySQL server is set up to only accept connections from the machine it is running on, for security reasons. It depends on the presence of a Web server on the same machine to forward requests to it. All requests are authenticated and authorized via the AAA before being passed on to Hibernate and the database.

Database schema set up and population

OSCARS makes use of two databases, one for the AAA named "aaa", and one for the BSS, pathfinder, and PSS, named "bss". The Hibernate configuration necessary is contained in conf/public/server, in the files aaa.cfg.xml and bss.cfg.xml, respectively. These are copied to the appropriate place in the classpath as part of the build process.

The scripts to create the necessary tables in the aaa and bss databases are contained in sql/aaa/aaa.sql and sql/bss/bss.sql, respectively. sql/aaa/populateTables.sql is a sample script setting up default attributes, resources, and permissions.

The program to populate the bss database with the network topology is located in tools/updatedb/TopologyUpdater.java. It depends on the presence of a directory with previously gathered information about each router in the topology, which was gained using SNMP queries. Currently the format of the files in that directory is ESnet-specific.

Test databases

Separate test databases, testaaa and testbss, are set up for unit tests. Make sure that they are created as well as the aaa and bss databases (TODO: script). They are repopulated as necessary each time before a test suite executes. Their Hibernate configuration files are in the conf/public/server directory, testaaa.cfg.xml and testbss.cfg.xml. These are identical to the production configuration files except for the names of the databases.

Object/relational mapping

Each table in the database has a corresponding Java bean. The mapping is defined in the Hibernate configuration files mentioned above. There is also a Hibernate configuration file that maps each field in the table to a bean property, with a suffix of ".hbm.xml", located in the same directory as the bean.

OSCARS makes extensive use of the DAO (data-access object) design pattern. Each bean, for example Router.java, has an associated DAO object, in this case RouterDAO.java, that performs low-level CRUD (create, retrieve, update, delete) operations. Each DAO object sub-classes src/net/es/oscars/database/GenericHibernateDAO.java.

Useful MySQL commands

show status at a MySQL prompt will show the status of a number of variables.