*/
public void open() throws StopwatchStorageException {
try {
Class.forName(getDriver());
} catch (ClassNotFoundException e) {
throw new StopwatchStorageException("failed to load " + getDriver() + " driver.", e);
}
try {
if (isDebug())getLogger().debug("Connecting to database ... ");
updateConnection = DriverManager.getConnection(getConnectionString(), getUser(), getPassword());
selectConnection = DriverManager.getConnection(getConnectionString(), getUser(), getPassword());
if (isDebug())getLogger().debug("connection sucsessful. Checking tables ... ");
} catch (SQLException e) {
throw new StopwatchStorageException("database connection error", e);
}
// check if table exists
try {
Statement statement = selectConnection.createStatement();
statement.execute(getCheckTableQuery());
statement.close();
if (getTruncTableQuery() != null && !"".equals(getTruncTableQuery().trim())) {
try {
statement = updateConnection.createStatement();
statement.executeUpdate(getTruncTableQuery());
statement.close();
} catch (SQLException e) {
throw new StopwatchStorageException("Can not truncate table", e);
}
}
if (isDebug())getLogger().debug("table(s) exists. Engine will now attempt to create prepared statements ... ");
} catch (SQLException e) {
try {
Statement statement = updateConnection.createStatement();
statement.execute(getCreateTableQuery());
statement.close();
if (isDebug())getLogger().debug("table(s) created. Engine will now attempt to create prepared statements ... ");
} catch (SQLException e1) {
throw new StopwatchStorageException("Can not create table(s)", e1);
}
}
try {
insertPreparedStatement = updateConnection.prepareStatement(getInsertQuery());
updatePreparedStatement = updateConnection.prepareStatement(getUpdateQuery());
deletePreparedStatement = updateConnection.prepareStatement(getDeleteQuery());
lastIdentityStatement = updateConnection.prepareStatement(getLastIdentityQuery());
allReportStatement = selectConnection.prepareStatement(getAllReportQuery());
allByGroupReportStatement = selectConnection.prepareStatement(getAllByGroupReportQuery());
allByLabelReportStatement = selectConnection.prepareStatement(getAllByLabelReportQuery());
groupReportStatement = selectConnection.prepareStatement(getGroupReportQuery());
labelReportStatement = selectConnection.prepareStatement(getLabelReportQuery());
singleReportStatement = selectConnection.prepareStatement(getSingleReportQuery());
loadStatement = selectConnection.prepareStatement(getLoadQuery());
groupLoadStatement = selectConnection.prepareStatement(getGroupLoadQuery());
labelLoadStatement = selectConnection.prepareStatement(getLabelLoadQuery());
groupLabelLoadStatement = selectConnection.prepareStatement(getGroupLabelLoadQuery());
if (isDebug()) getLogger().debug("Prepared statements created!");
} catch (SQLException e) {
throw new StopwatchStorageException("can not create prepared statements", e);
}
}