com.carrotsearch.junitbenchmarks.db
Class DbConsumer

java.lang.Object
  extended by com.carrotsearch.junitbenchmarks.AutocloseConsumer
      extended by com.carrotsearch.junitbenchmarks.db.DbConsumer
All Implemented Interfaces:
IResultsConsumer, Closeable
Direct Known Subclasses:
H2Consumer, MySQLConsumer

public abstract class DbConsumer
extends AutocloseConsumer
implements Closeable

Parent class for database consumer implementations.


Field Summary
static int BENCHMARK_ROUNDS
           
static int CLASSNAME
           
static int GC_AVG
           
static int GC_INVOCATIONS
           
static int GC_STDDEV
           
static int GC_TIME
           
static int NAME
           
static int ROUND_AVG
           
static int ROUND_STDDEV
           
static int RUN_ID
           
static int TIME_BENCHMARK
           
static int TIME_WARMUP
           
static int WARMUP_ROUNDS
           
 
Constructor Summary
DbConsumer(File chartsDir, String customKeyValue)
          Creates a new DbConsumer.
 
Method Summary
 void accept(Result result)
          Accept a single benchmark result.
protected  void checkSchema()
          Check database schema and create it if needed.
 void close()
          Close the database connection and finalize transaction.
protected abstract  Connection createConnection()
          Instantiates the database connection.
protected abstract  String getAddCustomKeySql()
          Gets the SQL for adding a custom key.
 File getChartsDir()
          Gets the charts directory.
 Connection getConnection()
          Gets the connection, instantiating it if necessary.
protected abstract  String getCreateDbVersionSql()
          Gets the SQL for creating the DB Version table.
protected abstract  String getCreateRunsSql()
          Gets the SQL for creating the runs table.
protected abstract  String getCreateTestsSql()
          Gets the SQL for creating the tests table.
 String getCustomKeyValue()
          Gets the custom key value.
 DbVersions getDbVersion()
          Retrieve DB version.
static File getDefaultChartsDir()
          Gets the default charts directory
static String getDefaultCustomKey()
          Gets the default custom key.
 String getHistoryHtmlTemplate()
          Gets the history HTML template.
abstract  String getMethodChartPropertiesQuery()
          Gets the SQL for obtaining method chart properties.
abstract  String getMethodChartResultsQuery()
          Gets the SQL for obtaining method chart results.
 String getMethodHtmlTemplate()
          Gets the method HTML template.
protected abstract  String getNewRunSql()
          Gets the SQL for inserting into the runs table.
protected static String getResource(Class<?> c, String resourceName)
          Read a given resource from classpath and return UTF-8 decoded string.
 int getRunId()
          Gets the run ID, lazy-loading it if it was not already read.
protected abstract  String getTestInsertSql()
          Gets the SQL for inserting into the test table.
protected  PreparedStatement getTestInsertStatement()
          Lazy-loads the test insert statement.
 void rollback()
          Rollback all performed operations on request.
 
Methods inherited from class com.carrotsearch.junitbenchmarks.AutocloseConsumer
addAutoclose, removeAutoclose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RUN_ID

public static final int RUN_ID

CLASSNAME

public static final int CLASSNAME

NAME

public static final int NAME

BENCHMARK_ROUNDS

public static final int BENCHMARK_ROUNDS

WARMUP_ROUNDS

public static final int WARMUP_ROUNDS

ROUND_AVG

public static final int ROUND_AVG

ROUND_STDDEV

public static final int ROUND_STDDEV

GC_AVG

public static final int GC_AVG

GC_STDDEV

public static final int GC_STDDEV

GC_INVOCATIONS

public static final int GC_INVOCATIONS

GC_TIME

public static final int GC_TIME

TIME_BENCHMARK

public static final int TIME_BENCHMARK

TIME_WARMUP

public static final int TIME_WARMUP
Constructor Detail

DbConsumer

public DbConsumer(File chartsDir,
                  String customKeyValue)
Creates a new DbConsumer.

Parameters:
chartsDir - the charts directory
customKeyValue - the custom key value
Method Detail

accept

public void accept(Result result)
Accept a single benchmark result.

Specified by:
accept in interface IResultsConsumer

close

public void close()
Close the database connection and finalize transaction.

Specified by:
close in interface Closeable

rollback

public void rollback()
Rollback all performed operations on request.


getDbVersion

public DbVersions getDbVersion()
                        throws SQLException
Retrieve DB version.

Throws:
SQLException

getResource

protected static String getResource(Class<?> c,
                                    String resourceName)
Read a given resource from classpath and return UTF-8 decoded string.


getDefaultCustomKey

public static String getDefaultCustomKey()
Gets the default custom key.

Returns:
the default custom key

getDefaultChartsDir

public static File getDefaultChartsDir()
Gets the default charts directory

Returns:
the default charts directory

checkSchema

protected void checkSchema()
                    throws SQLException
Check database schema and create it if needed.

Throws:
SQLException

getConnection

public Connection getConnection()
                         throws SQLException
Gets the connection, instantiating it if necessary.

Throws:
SQLException

getCustomKeyValue

public String getCustomKeyValue()
Gets the custom key value.

Returns:
the custom key value

getChartsDir

public File getChartsDir()
Gets the charts directory.

Returns:
the charts directory

getHistoryHtmlTemplate

public String getHistoryHtmlTemplate()
Gets the history HTML template.

Returns:
the history HTML template

getMethodHtmlTemplate

public String getMethodHtmlTemplate()
Gets the method HTML template.

Returns:
the method html template

getRunId

public int getRunId()
             throws SQLException
Gets the run ID, lazy-loading it if it was not already read.

Returns:
the run Id
Throws:
SQLException - if the run ID cannot be determined

getTestInsertStatement

protected PreparedStatement getTestInsertStatement()
                                            throws SQLException
Lazy-loads the test insert statement.

Returns:
the test insert statement
Throws:
SQLException - if the test insert statement cannot be created

getMethodChartPropertiesQuery

public abstract String getMethodChartPropertiesQuery()
Gets the SQL for obtaining method chart properties.

Returns:
the SQL for obtaining method chart properties

getMethodChartResultsQuery

public abstract String getMethodChartResultsQuery()
Gets the SQL for obtaining method chart results.

Returns:
the SQL for obtaining method chart results

getCreateTestsSql

protected abstract String getCreateTestsSql()
Gets the SQL for creating the tests table.

Returns:
the SQL for creating the tests table

getTestInsertSql

protected abstract String getTestInsertSql()
Gets the SQL for inserting into the test table.

Returns:
the SQL for inserting into the test table

getCreateRunsSql

protected abstract String getCreateRunsSql()
Gets the SQL for creating the runs table.

Returns:
the SQL for creating the runs table

getNewRunSql

protected abstract String getNewRunSql()
Gets the SQL for inserting into the runs table.

Returns:
the SQL for inserting into the runs table

getCreateDbVersionSql

protected abstract String getCreateDbVersionSql()
Gets the SQL for creating the DB Version table.

Returns:
the SQL for creating the DB version table

getAddCustomKeySql

protected abstract String getAddCustomKeySql()
Gets the SQL for adding a custom key.

Returns:
the SQL for adding a custom key

createConnection

protected abstract Connection createConnection()
                                        throws SQLException
Instantiates the database connection.

Returns:
a new, open database connection
Throws:
SQLException - if the database connection cannot be created


Copyright © 2013 Carrot Search s.c.. All Rights Reserved.