Dynamic API - Creating the tables

Contents

This document contains an overview of the classes involved with creating the tables in the dynamic part of the database.

See also

Last updated: $Date: 2009-04-06 14:52:39 +0200 (må, 06 apr 2009) $

The VirtualDb item is the core item in the process of managing the dynamic tables. It has a one-to-one relationship with an Experiment. Thus, each experiment has a separate set of database tables used to store data for that experiment only. No dynamic tables are created until they are needed. This means that the creation of a dynamic table is initiated by one of the batcher classes when it needs to insert data into a particular table. The batcher object calls the VirtualDb.createTables() method, passing an array of VirtualTable objects to indicate which tables it needs to create.

The call the proceeds to HibernateUtil.createVirtualTables(). This method uses the information in the VirtualTable object to find out which columns should be in the table, and then builds a structure with Hibernate mapping objects. When the structure is built we use Hibernate to generate the table creation SQL for us.

The SQL is sent to the database using a separate connection. The reason is that some databases (ie. MySQL) automatically commits a transaction when certain SQL statements are executed (for example CREATE TABLE). This means that we must be careful to synchronize the two transactions as much as possible. For example, it is not allowed to create dynamic tables for a VirtualDb item that has not yet been committed to the database.

The dynamic tables are deleted by the VirtualDb.onAfterCommit() method if the action parameter is Action.DELETE