Top Description Fields Constructors Methods
com.mysql.cj.jdbc.util

public abstract Class BaseBugReport

extends Object
Class Inheritance
Imports
java.sql.Connection, .SQLException, java.util.Properties, java.util.concurrent.locks.Lock, .ReentrantLock, com.mysql.cj.jdbc.Driver

Base class to help file bug reports for Connector/J.

MySQL AB, 2008 Sun Microsystems, 2009 Oracle Corporation really appreciates repeatable testcases when reporting bugs, so we're giving you this class to make that job a bit easier (and standarized).

To create a testcase, create a class that inherits from this class (com.mysql.cj.jdbc.util.BaseBugReport), and override the methods 'setUp', 'tearDown' and 'runTest'.

In the 'setUp' method, create code that creates your tables, and populates them with any data needed to demonstrate the bug.

In the 'runTest' method, create code that demonstrates the bug using the tables and data you created in the 'setUp' method.

In the 'tearDown' method, drop any tables you created in the 'setUp' method.

In any of the above three methods, you should use one of the variants of the 'getConnection' method to create a JDBC connection to MySQL, which will use the default JDBC URL of 'jdbc:mysql:///test'.

If you need to use a JDBC URL that is different than 'jdbc:mysql:///test', then override the method 'getUrl' as well.

Use the 'assertTrue' methods to create conditions that must be met in your testcase demonstrating the behavior you are expecting (vs. the behavior you are observing, which is why you are most likely filing a bug report).

Finally, create a 'main' method that creates a new instance of your testcase, and calls the 'run' method:


public static void main(String[] args) throws Exception {
    new MyBugReport().run();
}

When filing a potential bug with MySQL Connector/J at http://bugs.mysql.com/ or on the bugs mailing list, please include the code that you have just written using this class.

Field Summary

Modifier and TypeField and Description
private Connection
private Driver
private final Lock

Constructor Summary

AccessConstructor and Description
public
BaseBugReport()

Constructor for this BugReport, sets up JDBC driver used to create connections.

Method Summary

Modifier and TypeMethod and Description
protected final void
assertTrue(String
the message to use in the exception
message
,
boolean
the condition to test for
condition
)

Throws an exception with the given message if condition evalutates to 'false'.

protected final void
assertTrue(boolean
the condition to test for
condition
)

Throws an exception if condition evalutates to 'false'.

public final Connection

Returns:

a connection to the JDBC URL specified in getUrl().
getConnection
()

Provides a connection to the JDBC URL specified in getUrl().

public final Connection

Returns:

a new java.sql.Connection to the JDBC URL.
getConnection
(String
the JDBC URL to use
url
)

Returns a connection using the given URL.

public final Connection

Returns:

a new java.sql.Connection to the JDBC URL.
getConnection
(String
the JDBC URL to use
url
,
Properties
the JDBC properties to use
props
)

Returns a connection using the given URL and properties.

public final Connection

Returns:

a new connection to the JDBC URL specified in getUrl().
getNewConnection
()

Use this if you need to get a new connection for your bug report (i.e. there's more than one connection involved).

public String

Returns:

URL
getUrl
()

Provides the JDBC URL to use to demonstrate the bug.

public final void
run()

Runs the testcase by calling the setUp(), runTest() and tearDown() methods.

public abstract void
runTest()

Override this method with code that demonstrates the bug.

public abstract void
setUp()

Override this method with code that sets up the testcase for demonstrating your bug (creating tables, populating data, etc).

public abstract void
tearDown()

Override this method with code that cleans up anything created in the setUp() method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connback to summary
private Connection conn
driverback to summary
private Driver driver
lockback to summary
private final Lock lock

Constructor Detail

BaseBugReportback to summary
public BaseBugReport()

Constructor for this BugReport, sets up JDBC driver used to create connections.

Method Detail

assertTrueback to summary
protected final void assertTrue(String message, boolean condition) throws Exception

Throws an exception with the given message if condition evalutates to 'false'.

Parameters
message:String

the message to use in the exception

condition:boolean

the condition to test for

Exceptions
Exception:
if !condition
assertTrueback to summary
protected final void assertTrue(boolean condition) throws Exception

Throws an exception if condition evalutates to 'false'.

Parameters
condition:boolean

the condition to test for

Exceptions
Exception:
if !condition
getConnectionback to summary
public final Connection getConnection() throws SQLException

Provides a connection to the JDBC URL specified in getUrl(). If a connection already exists, that connection is returned. Otherwise a new connection is created.

Returns:Connection

a connection to the JDBC URL specified in getUrl().

Exceptions
SQLException:
if an error is caused while creating the connection.
getConnectionback to summary
public final Connection getConnection(String url) throws SQLException

Returns a connection using the given URL.

Parameters
url:String

the JDBC URL to use

Returns:Connection

a new java.sql.Connection to the JDBC URL.

Exceptions
SQLException:
if an error occurs getting the connection.
getConnectionback to summary
public final Connection getConnection(String url, Properties props) throws SQLException

Returns a connection using the given URL and properties.

Parameters
url:String

the JDBC URL to use

props:Properties

the JDBC properties to use

Returns:Connection

a new java.sql.Connection to the JDBC URL.

Exceptions
SQLException:
if an error occurs getting the connection.
getNewConnectionback to summary
public final Connection getNewConnection() throws SQLException

Use this if you need to get a new connection for your bug report (i.e. there's more than one connection involved).

Returns:Connection

a new connection to the JDBC URL specified in getUrl().

Exceptions
SQLException:
if an error is caused while creating the connection.
getUrlback to summary
public String getUrl()

Provides the JDBC URL to use to demonstrate the bug. The java.sql.Connection that you use to demonstrate this bug will be provided by the getConnection() method using this URL. The default value is 'jdbc:mysql:///test'

Returns:String

URL

runback to summary
public final void run() throws Exception

Runs the testcase by calling the setUp(), runTest() and tearDown() methods. The tearDown() method is run regardless of any errors occuring in the other methods.

Exceptions
Exception:
if an error occurs in any of the aforementioned methods.
runTestback to summary
public abstract void runTest() throws Exception

Override this method with code that demonstrates the bug. This method will be called after setUp(), and before tearDown().

Exceptions
Exception:
if an error occurs during your test run.
setUpback to summary
public abstract void setUp() throws Exception

Override this method with code that sets up the testcase for demonstrating your bug (creating tables, populating data, etc).

Exceptions
Exception:
if an error occurs during the 'setUp' phase.
tearDownback to summary
public abstract void tearDown() throws Exception

Override this method with code that cleans up anything created in the setUp() method.

Exceptions
Exception:
if an error occurs during the 'tearDown' phase.