|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.commsen.stopwatch.storages.AbstractDatabaseStorage
public abstract class AbstractDatabaseStorage
Abstract class representig database storage. It has predefined methods to crete table(s) as well
as insert, update and delete records. The default implementation is limited to the very basic
measurment data - time and count. If any other info is to be stored, the extending class should
overwrite appropriate getXxxxQuery() method(s)
| Field Summary | |
|---|---|
protected java.sql.PreparedStatement |
allByGroupReportStatement
Prepared statement initialized in open() method with query returned by
getAllByGroupReportQuery() |
protected java.sql.PreparedStatement |
allByLabelReportStatement
Prepared statement initialized in open() method with query returned by
getAllByLabelReportQuery() |
protected java.sql.PreparedStatement |
allReportStatement
Prepared statement initialized in open() method with query returned by
getAllReportQuery() |
protected java.sql.PreparedStatement |
deletePreparedStatement
Prepared statement initialized in open() method with query returned by
getDeleteQuery() |
protected java.sql.PreparedStatement |
groupLabelLoadStatement
|
protected java.sql.PreparedStatement |
groupLoadStatement
|
protected java.sql.PreparedStatement |
groupReportStatement
Prepared statement initialized in open() method with query returned by
getGroupReportQuery() |
protected java.sql.PreparedStatement |
insertPreparedStatement
Prepared statement initialized in open() method with query returned by
getInsertQuery() |
protected java.sql.PreparedStatement |
labelLoadStatement
|
protected java.sql.PreparedStatement |
labelReportStatement
Prepared statement initialized in open() method with query returned by
getLabelReportQuery() |
protected java.sql.PreparedStatement |
lastIdentityStatement
Prepared statement initialized in open() method with query returned by
getLastIdentityQuery() |
protected java.sql.PreparedStatement |
loadStatement
|
protected java.util.Properties |
properties
|
protected java.sql.PreparedStatement |
singleReportStatement
Prepared statement initialized in open() method with query returned by
getSingleReportQuery() |
protected java.sql.PreparedStatement |
updatePreparedStatement
Prepared statement initialized in open() method with query returned by
getUpdateQuery() |
| Constructor Summary | |
|---|---|
AbstractDatabaseStorage()
|
|
| Method Summary | |
|---|---|
void |
close()
Called when engine is about to be stopped or for some other reason will no more use this storage. |
boolean |
completeRecord(long id,
java.lang.Object[] parameters)
Instructs the storage to complete (at least remember the time) the record identified by given parameters. |
void |
freeze()
Called when engine is about to be paused or for some other reason will temporary not use this storage. |
protected java.lang.String |
getAllByGroupReportQuery()
Called to obtain the query to be executed when summary report about all groups is to be generated |
Report[] |
getAllByGroupReports()
This method simply calls prepareReports(PreparedStatement, Object[]) passing
allByGroupReportStatement as statement and no parameters (null
value). |
protected java.lang.String |
getAllByLabelReportQuery()
Called to obtain the query to be executed when summary report about all labels is to be generated |
Report[] |
getAllByLabelReports()
This method simply calls prepareReports(PreparedStatement, Object[]) passing
allByLabelReportStatement as statement and no parameters (null
value). |
protected java.lang.String |
getAllReportQuery()
Called to obtain the query to be executed when report about all groups and labels is to be generated |
protected java.lang.String |
getCheckTableQuery()
Provides SQL query which will be executed to check if table exist |
protected abstract java.lang.String |
getConnectionString()
Called to obtain the connection string |
protected java.lang.String |
getCreateTableQuery()
Called to obtain the query to be executed when table needs to be created. |
protected java.lang.String |
getDeleteQuery()
|
protected abstract java.lang.String |
getDriver()
Called to obtain the JDBC driver to use |
protected java.lang.String |
getGroupBy()
The group by clause used in all report queries Default is: _group, _label |
protected java.lang.String |
getGroupLabelLoadQuery()
|
protected java.lang.String |
getGroupLoadQuery()
|
protected java.lang.String |
getGroupReportQuery()
Called to obtain the query to be executed when report about given group and label is to be generated |
Report[] |
getGroupReports(java.lang.String group)
This method simply calls prepareReports(PreparedStatement, Object[]) passing
groupReportStatement as statement and group as parameter. |
java.lang.String |
getInsertQuery()
|
protected java.lang.String |
getLabelLoadQuery()
|
protected java.lang.String |
getLabelReportQuery()
Called to obtain the query to be executed when report about given group and label is to be generated |
Report[] |
getLabelReports(java.lang.String label)
This method simply calls prepareReports(PreparedStatement, Object[]) passing
labelReportStatement as statement and label as parameter. |
protected abstract java.lang.String |
getLastIdentityQuery()
|
long[] |
getLoad(java.lang.String group,
java.lang.String label,
int field,
int value)
Implementing methods should generate and return information of how many instances of the code specified by group and label ware running for the last numberOfPeriods periods. |
protected java.lang.String |
getLoadQuery()
|
protected abstract org.apache.log4j.Logger |
getLogger()
Returns the logger for this class |
protected java.lang.String |
getOrderBy()
The order by clause used in all report queries Default is: _group, _label |
protected abstract java.lang.String |
getPassword()
Called to obtain the database password |
java.util.Properties |
getProperties()
Returns storage properties. |
Report |
getReport(java.lang.String group,
java.lang.String label)
This method simply calls prepareReports(PreparedStatement, Object[]) passing
singleReportStatement as statement and group and label
as parameters. |
Report[] |
getReports()
This method simply calls prepareReports(PreparedStatement, Object[]) passing
allReportStatement as statement and no parameters (null value). |
protected abstract java.lang.String |
getReturnColumns()
Called to obtain the columns to be returned. |
protected java.lang.String |
getSingleReportQuery()
Called to obtain the query to be executed when report about given group and label is to be generated |
protected abstract java.lang.String |
getTableName()
Provides the table name |
protected java.lang.String |
getTruncTableQuery()
Called to obtain the query to be executed when table needs to be truncated |
protected java.lang.String |
getUpdateQuery()
|
protected abstract java.lang.String |
getUser()
Called to obtain the database user name |
protected boolean |
isDebug()
Checks if debug log level is enabled in both Stopwatch and Log4j. |
abstract boolean |
isDebugEnabled()
|
long |
newCompleteRecord(java.lang.Object[] startParameters,
java.lang.Object[] endParameters)
Instructs the storage to create new complete record and store passed parameters. |
long |
newRecord(java.lang.Object[] parameters)
Instructs the storage to create new record and store passed parameters. |
void |
open()
Called when engine is about to use the storage for the first time. |
protected Report[] |
prepareReports(java.sql.PreparedStatement statement,
java.lang.Object[] params)
This method simply executes given statement with given params. |
boolean |
removeRecord(long id)
Instructs the storage to remove the record identified by given parameters. |
void |
setProperties(java.util.Properties properties)
Called by Stopwatch to set storage properties . |
void |
unfreeze()
Called when engine is about to be resumed. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.commsen.stopwatch.StopwatchStorage |
|---|
setDebugEnabled |
| Field Detail |
|---|
protected java.util.Properties properties
protected java.sql.PreparedStatement insertPreparedStatement
open() method with query returned by
getInsertQuery()
protected java.sql.PreparedStatement updatePreparedStatement
open() method with query returned by
getUpdateQuery()
protected java.sql.PreparedStatement deletePreparedStatement
open() method with query returned by
getDeleteQuery()
protected java.sql.PreparedStatement lastIdentityStatement
open() method with query returned by
getLastIdentityQuery()
protected java.sql.PreparedStatement allReportStatement
open() method with query returned by
getAllReportQuery()
protected java.sql.PreparedStatement allByGroupReportStatement
open() method with query returned by
getAllByGroupReportQuery()
protected java.sql.PreparedStatement allByLabelReportStatement
open() method with query returned by
getAllByLabelReportQuery()
protected java.sql.PreparedStatement groupReportStatement
open() method with query returned by
getGroupReportQuery()
protected java.sql.PreparedStatement labelReportStatement
open() method with query returned by
getLabelReportQuery()
protected java.sql.PreparedStatement singleReportStatement
open() method with query returned by
getSingleReportQuery()
protected java.sql.PreparedStatement groupLabelLoadStatement
protected java.sql.PreparedStatement groupLoadStatement
protected java.sql.PreparedStatement labelLoadStatement
protected java.sql.PreparedStatement loadStatement
| Constructor Detail |
|---|
public AbstractDatabaseStorage()
| Method Detail |
|---|
protected abstract java.lang.String getDriver()
protected abstract java.lang.String getConnectionString()
protected abstract java.lang.String getUser()
protected abstract java.lang.String getPassword()
protected abstract java.lang.String getTableName()
protected java.lang.String getCheckTableQuery()
Default is: select 1 from
getTableName()
protected java.lang.String getCreateTableQuery()
Default is:
create table
getTableName() (
_id INT GENERATED BY DEFAULT AS IDENTITY,
_group VARCHAR,
_label VARCHAR,
_start TIMESTAMP,
_end TIMESTAMP
)
protected java.lang.String getTruncTableQuery()
Default is: delete from
getTableName()
protected abstract java.lang.String getReturnColumns()
protected java.lang.String getGroupBy()
_group, _label
protected java.lang.String getOrderBy()
_group, _label
protected java.lang.String getAllReportQuery()
Default is:
select
getReturnColumns()
from getTableName()
where _end is not null
group by getGroupBy()
order by getOrderBy()
)
protected java.lang.String getAllByGroupReportQuery()
Default is:
select
getReturnColumns()
from getTableName()
where _end is not null
group by _group
order by _group
)
protected java.lang.String getAllByLabelReportQuery()
Default is:
select
getReturnColumns()
from getTableName()
where _end is not null
group by _label
order by _label
)
protected java.lang.String getSingleReportQuery()
Default is:
select
getReturnColumns()
from getTableName()
where _end is not null and _group = ? and _label = ?
group by getGroupBy()
order by getOrderBy()
)
protected java.lang.String getLabelReportQuery()
Default is:
select
getReturnColumns()
from getTableName()
where _end is not null and _label = ?
group by getGroupBy()
order by getOrderBy()
)
protected java.lang.String getGroupReportQuery()
Default is:
select
getReturnColumns()
from getTableName()
where _end is not null and _group = ?
group by getGroupBy()
order by getOrderBy()
)
public java.lang.String getInsertQuery()
protected java.lang.String getUpdateQuery()
protected java.lang.String getDeleteQuery()
protected abstract java.lang.String getLastIdentityQuery()
protected java.lang.String getLoadQuery()
protected java.lang.String getGroupLoadQuery()
protected java.lang.String getLabelLoadQuery()
protected java.lang.String getGroupLabelLoadQuery()
public void open()
throws StopwatchStorageException
StopwatchStorage
open in interface StopwatchStorageStopwatchStorageException - if there is problem preparing the storage.StopwatchStorage.open()
public void freeze()
throws StopwatchStorageException
StopwatchStorage
freeze in interface StopwatchStorageStopwatchStorageException - if there is a problem with freezing the storage.StopwatchStorage.freeze()
public void unfreeze()
throws StopwatchStorageException
StopwatchStorage
unfreeze in interface StopwatchStorageStopwatchStorageException - if there is a problem with unfreezing the storage.StopwatchStorage.unfreeze()
public void close()
throws StopwatchStorageException
StopwatchStorage
close in interface StopwatchStorageStopwatchStorageException - if there is a problem closing the storageStopwatchStorage.close()
public long newRecord(java.lang.Object[] parameters)
throws StopwatchStorageException
StopwatchStorage
newRecord in interface StopwatchStorageStopwatchStorageExceptionStopwatchStorage.newRecord(java.lang.Object[])
public long newCompleteRecord(java.lang.Object[] startParameters,
java.lang.Object[] endParameters)
throws StopwatchStorageException
StopwatchStorage
newCompleteRecord in interface StopwatchStoragestartParameters - parameters describing start conditionendParameters - parameters describing end condition
true if record was completed successfuly, false otherwise
StopwatchStorageException - on errorStopwatchStorage.newRecord(java.lang.Object[])
public boolean removeRecord(long id)
throws StopwatchStorageException
StopwatchStorage
removeRecord in interface StopwatchStorageid - of the database record to be removed
true if record was removed successfuly, false otherwise
StopwatchStorageException - on errorStopwatchStorage.removeRecord(long)
public boolean completeRecord(long id,
java.lang.Object[] parameters)
throws StopwatchStorageException
StopwatchStorage
completeRecord in interface StopwatchStorageid - of the database record to be updatedparameters - used to find the record
true if record was completed successfuly, false otherwise
StopwatchStorageException - on errorStopwatchStorage.completeRecord(long, Object[])public Report[] getReports()
prepareReports(PreparedStatement, Object[]) passing
allReportStatement as statement and no parameters (null value).
getReports in interface StopwatchStorageStopwatchStorage.getReports()public Report[] getAllByGroupReports()
prepareReports(PreparedStatement, Object[]) passing
allByGroupReportStatement as statement and no parameters (null
value).
getAllByGroupReports in interface StopwatchStorageStopwatchStorage.getReports()public Report[] getAllByLabelReports()
prepareReports(PreparedStatement, Object[]) passing
allByLabelReportStatement as statement and no parameters (null
value).
getAllByLabelReports in interface StopwatchStorageStopwatchStorage.getReports()
public Report getReport(java.lang.String group,
java.lang.String label)
prepareReports(PreparedStatement, Object[]) passing
singleReportStatement as statement and group and label
as parameters.
getReport in interface StopwatchStoragegroup - the group for which report should be generatedlabel - the label for which report should be generated
StopwatchStorage.getReport(java.lang.String, java.lang.String)public Report[] getGroupReports(java.lang.String group)
prepareReports(PreparedStatement, Object[]) passing
groupReportStatement as statement and group as parameter.
getGroupReports in interface StopwatchStoragegroup - the name of group for which report should be generated
StopwatchStorage.getGroupReports(java.lang.String)public Report[] getLabelReports(java.lang.String label)
prepareReports(PreparedStatement, Object[]) passing
labelReportStatement as statement and label as parameter.
getLabelReports in interface StopwatchStoragelabel - the label for which report should be generated
StopwatchStorage.getLabelReports(java.lang.String)
protected Report[] prepareReports(java.sql.PreparedStatement statement,
java.lang.Object[] params)
throws java.sql.SQLException
statement with given params.
All report queries call this method to obtain array of reports. This method should be
overwriten by extending classes that need to provide more measurment information then basic
time and count.
statement - the prepared statement to executeparams - the params to passed to the prepared statement
Report
java.sql.SQLException - on database connection error or other errors
public long[] getLoad(java.lang.String group,
java.lang.String label,
int field,
int value)
StopwatchStoragegroup and label ware running for the last numberOfPeriods periods.
Period length is defined by periodField which can be one of Calendar.FIELD_NAME
For example to see how many instances of code labeled "l1" in group "g1" were running per minute for the last 30 minutes, one could use:
long[] load = Stopwatch.getLoad("g1, "l1", Calendar.MINUTE, 30);
which will forward the call to the appropriate storage implementation. In this case load[0] will contain the
number of code instances running 30 minutes ago and load[29] number of code instances running in the last minute.
If group is null - summary load of all masurments labeled label should be returned.
If label is null - summary load of all masurments in group gtroup should be returned.
If both group and label are null - summary load of all masurments should be returned.
getLoad in interface StopwatchStoragegroup - the group for which load report should be generatedlabel - the label for which load report should be generatedfield - can be one of Calendar.FIELD_NAMEvalue - number of periods
numberOfPeriods where every element represents the load for given pariod.com.commsen.stopwatch.StopwatchStorage#getLoad(int, int)protected abstract org.apache.log4j.Logger getLogger()
protected boolean isDebug()
true if debug log level is enabled, false otherwise.public abstract boolean isDebugEnabled()
StopwatchEngine.setDebugEnabled(boolean)public java.util.Properties getProperties()
getProperties in interface StopwatchStoragepublic void setProperties(java.util.Properties properties)
setProperties in interface StopwatchStorageproperties - the properties
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||