/*
* $Id: DefaultHSQLStorage.java,v 1.1 2006/03/06 11:30:53 azzazzel Exp $
*
* Copyright 2006 Commsen International
*
* Licensed under the Common Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/cpl1.0.txt
*
* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS
* OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*/
package com.commsen.stopwatch.storages;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.log4j.Logger;
import com.commsen.stopwatch.Stopwatch;
import com.commsen.stopwatch.StopwatchStorageException;
/**
* TODO Dokumentacja
*
* @author Milen Dyankov
*
*/
public class DefaultHSQLStorage extends AbstractDatabaseStorage {
/**
* Logger for this class
*/
private static final Logger log = Logger.getLogger(DefaultHSQLStorage.class);
private String DB_DRIVER = "db.driver";
private String DB_CONNECTION = "db.connectionString";
private String DB_USER = "db.user";
private String DB_PASSWORD = "db.password";
private String DB_TABLE = "db.tableName";
// protected String getDriver() { return "org.hsqldb.jdbcDriver"; }
protected String getDriver() { return Stopwatch.getProperty(DB_DRIVER, "org.hsqldb.jdbcDriver"); }
// protected String getConnectionString() { return "jdbc:hsqldb:hsql://localhost:9001/stopwatch"; }
protected String getConnectionString() { return Stopwatch.getProperty(DB_CONNECTION, "jdbc:hsqldb:hsql://localhost:9001/stopwatch"); }
// protected String getUser() { return "sa"; }
protected String getUser() { return Stopwatch.getProperty(DB_USER, "sa"); }
// protected String getPassword() { return ""; }
protected String getPassword() { return Stopwatch.getProperty(DB_PASSWORD, ""); }
protected String getLastIdentityQuery() { return "CALL IDENTITY()"; }
// protected String getTableName() { return "stopwatch"; }
protected String getTableName() { return Stopwatch.getProperty(DB_TABLE, "stopwatch"); }
protected String getReturnColumns() {
return
" count(1), " +
" min (DATEDIFF('ms', _start, _end)) as minTime," +
" max (DATEDIFF('ms', _start, _end)) as maxTime," +
" avg (DATEDIFF('ms', _start, _end)) as avgTime," +
" sum (DATEDIFF('ms', _start, _end)) as totalTime ";
}
private boolean debugEnabled;
/**
* @see com.commsen.stopwatch.StopwatchStorage#freeze()
*/
public void freeze() throws StopwatchStorageException {
Statement statement;
try {
statement = updateConnection.createStatement();
statement.execute("delete from stopwatch where _end is NULL");
statement.close();
} catch (SQLException e) {
getLogger().error(e,e);
}
}
/**
*
* @throws StopwatchStorageException
* @see com.commsen.stopwatch.StopwatchStorage#close()
*/
public void close() throws StopwatchStorageException {
try {
updateConnection.createStatement().execute("drop table stopwatch");
} catch (SQLException e) {
throw new StopwatchStorageException("database error", e);
}
super.close();
}
protected Logger getLogger () {
return log;
}
/**
* @return Returns the debugEnabled.
*/
public boolean isDebugEnabled() {
return debugEnabled;
}
/**
* @param debugEnabled The debugEnabled to set.
*/
public void setDebugEnabled(boolean debugEnabled) {
this.debugEnabled = debugEnabled;
}
}