Parallels H-Sphere Documentation Developer Guide

 

Database Connections

 
 

Related Docs:   The H-Sphere System Database Getting Information from the H-Sphere Database

Last modified: 28 Dec 2007

 

WARNING: This documentation covers Parallels H-Sphere versions up to 3.1. For the latest up-to-date Parallels H-Sphere documentation, please proceed to the official Parallels site.

There are two possible types of connections to the H-Sphere database:

IMPORTANT:
In any case, you should use only prepared stataments when working with the H-Sphere database!

 

Regular Shared Connections

The part of the code which establishes and uses a regular database connection should look something similar to this:

PreparedStatement ps = null;
Connection con = Session.getDb();
try {
    ps = con.prepareStatement(...........);
    ......................................
} finally {
    Session.closeStatement(ps);
    con.close();
}
        

 

Connections With Opened Transaction

In general, the part of the code which establishes and uses a transaction connection should look as follows:

// checking if the transaction exists
boolean wasTrans = Session.isTransConnection();
Connection con = wasTrans ? Session.getDb() : Session.getTransConnection();
try {
    // some operation with the database
} catch (Exception ex){
    if (!wasTrans) {
        // rollback transaction
        con.rollback();
        // here should also be some data to release cache and to synchronize with old data in HS DB
    }
    throw ex;
} finally {
    if (!wasTrans) {
        // commit transaction and release connection
        Session.commitTransConnection(con);
    } else {
        con.close();
    }
}
        

Important:

  1. There is the pool of transaction connections (5 by default). Opening a new transaction that exceeds this maximum would cause the system to hang up.

  2. As the number of available transactions is resctricted, you must release the transaction connection you have opened by using the following command:

    Session.commitTransConnection(con);

  3. To get an opened transaction connection:

    con = Session.getTransConnection();

    Later in the code, you may get the same connection:

    con = Session.getDb();

    Never close a transaction connection you haven't opened!

  4. Please make sure you synchronize your objects with the corresponding data in the database. You must release your cache if you make a rollback.


Related Docs:   The H-Sphere System Database Getting Information from the H-Sphere Database



© Copyright 2017. Parallels Holdings. All rights reserved.