Castor

About Castor

VARS acts a front-end to a database. This allows users to easily enter and retrieve information from a database without having to know anything about databases. Internally, VARS uses Java objects to store information. These Java objects are mapped to database tables using Castor, an object/relational mapping tool.

Here is a list of the VARS Classes that are mapped to the database:

What do you, the developer, need to know about Castor?

For most deployments, you don't need to know anything about Castor. Internally, VARS uses the data access object (DAO) pattern to access the database. Each class has a corresponding DAO that is used for finding, inserting, deleting or updating data into the database; for example, to insert, update, or delete an Observation from the database you would use the ObservationDAO. The DAO classes are located in the following packages:

It is important to be aware that most database actions cascade. For example, if you have a VideoArchiveSet with several VideoArchives associated with it, when you insert the VideoArchiveSet the VideoArchives will automatically be inserted too. On the other hand, deletes cascade too. So deleting the VideoArchiveSet will also delete all the VideoArchives.

Using a DAO object

  1. Create an object to be persisted
    Observation observation = new Observation();
    observation.setConceptName('Nanomia');
    
  2. Get the DAO object that corresponds to your object
    ObservationDAO dao = ObservationDAO.getInstance();
    
  3. Insert a new object into the database
    try {
        dao.insert(observation);
    }
    catch (DAOException e) {
        // Handle Exception
    }
    
  4. Update an object that already exists in the database
    observation.setConceptName('atolla');
    try {
        dao.update(observation);
    }
    catch (DAOException e) {
        // Handle Exception
    }
    
  5. Delete an object's data from the database
    try {
        dao.delete(observation);
    }
    catch (DAOException e) {
        // Handle Exception
    }