public class IndexStatsUtil
extends java.lang.Object
This implementation assumes all tables/indexes belong to the current schema.
The timeout value is used to make the utility more resilient to differences in timing due to varying scheduling decisions, processor speeds, etc. If the system table contains the wrong number of statistics objects for the query, it will be queried repeatedly until the right number of statistics objects is obtained or the query times out.
Modifier and Type | Class and Description |
---|---|
static class |
IndexStatsUtil.IdxStats
Immutable class representing index statistics.
|
Constructor and Description |
---|
IndexStatsUtil(java.sql.Connection con)
Creates an instance querying the given database with no timeout set.
|
IndexStatsUtil(java.sql.Connection con,
long timeout)
Creates an instance querying the given database with the specified
timeout value.
|
Modifier and Type | Method and Description |
---|---|
void |
assertIndexStats(java.lang.String index,
int expectedCount)
Asserts that the expected number of statistics exists for the specified
index.
|
void |
assertNoStats()
Asserts that there are no existing statistics in the database.
|
void |
assertNoStatsTable(java.lang.String table)
Asserts that there are no existing statistics for the specified table.
|
void |
assertStats(int expectedCount)
Asserts that the expected number of statistics exists.
|
void |
assertTableStats(java.lang.String table,
int expectedCount)
Asserts that the expected number of statistics exists for the specified
table.
|
static java.lang.String |
buildStatString(IndexStatsUtil.IdxStats[] stats,
java.lang.String name)
Builds a human readable representation of a list of statistics objects.
|
IndexStatsUtil.IdxStats[] |
getNewStatsTable(java.lang.String table,
IndexStatsUtil.IdxStats[] currentStats)
Waits for the current statistics to disappear and expects to fetch the
same number of new statistics for the table.
|
IndexStatsUtil.IdxStats[] |
getStats()
Obtains all existing statistics entries.
|
IndexStatsUtil.IdxStats[] |
getStatsIndex(java.lang.String index)
Obtains statistics for the specified index.
|
IndexStatsUtil.IdxStats[] |
getStatsIndex(java.lang.String index,
int expectedCount)
Obtains statistics for the specified index, fails if the number of
statistics objects isn't as expected within the timeout.
|
IndexStatsUtil.IdxStats[] |
getStatsTable(java.lang.String table)
Obtains statistics for the specified table.
|
IndexStatsUtil.IdxStats[] |
getStatsTable(java.lang.String table,
int expectedCount)
Obtains statistics for the specified table, fails if the number of
statistics objects isn't as expected within the timeout.
|
void |
printStats()
Prints all entries in the
SYS.SYSSTATISTICS system table. |
void |
release()
Releases resources and closes the associated connection.
|
void |
release(boolean closeConnection)
Releases resources.
|
public IndexStatsUtil(java.sql.Connection con)
Querying with no timeout means that if there are too few or too many statistics objects matching the query, a failure will be raised immediately.
con
- connection to the database to querypublic IndexStatsUtil(java.sql.Connection con, long timeout)
con
- connection to the database to querytimeout
- the longest time to wait to see if the expectations for a
query are met (milliseconds)public void assertNoStats() throws java.sql.SQLException
java.sql.SQLException
- if obtaining the statistics failspublic void assertNoStatsTable(java.lang.String table) throws java.sql.SQLException
java.sql.SQLException
- if obtaining the statistics failspublic void assertStats(int expectedCount) throws java.sql.SQLException
expectedCount
- expected number of statisticsjava.sql.SQLException
- if obtaining the statistics failspublic void assertTableStats(java.lang.String table, int expectedCount) throws java.sql.SQLException
table
- the target tableexpectedCount
- expected number of statisticsjava.sql.SQLException
- if obtaining the statistics failspublic void assertIndexStats(java.lang.String index, int expectedCount) throws java.sql.SQLException
index
- the target indexexpectedCount
- expected number of statisticsjava.sql.SQLException
- if obtaining the statistics failspublic static java.lang.String buildStatString(IndexStatsUtil.IdxStats[] stats, java.lang.String name)
stats
- a list of statistics (possibly empty)name
- the name of the table(s)/index(es) associated with the statspublic IndexStatsUtil.IdxStats[] getStats() throws java.sql.SQLException
java.sql.SQLException
- if obtaining the statistics failpublic IndexStatsUtil.IdxStats[] getStatsTable(java.lang.String table) throws java.sql.SQLException
table
- table namejava.sql.SQLException
- if obtaining the statistics failpublic IndexStatsUtil.IdxStats[] getStatsTable(java.lang.String table, int expectedCount) throws java.sql.SQLException
table
- table nameexpectedCount
- number of expected statistics objectsjava.sql.SQLException
- if obtaining the statistics failpublic IndexStatsUtil.IdxStats[] getNewStatsTable(java.lang.String table, IndexStatsUtil.IdxStats[] currentStats) throws java.sql.SQLException
table
- the table to get statistics forcurrentStats
- the current statisticsjava.sql.SQLException
- if obtaining statistics failspublic IndexStatsUtil.IdxStats[] getStatsIndex(java.lang.String index) throws java.sql.SQLException
index
- index namejava.sql.SQLException
- if obtaining the statistics failpublic IndexStatsUtil.IdxStats[] getStatsIndex(java.lang.String index, int expectedCount) throws java.sql.SQLException
index
- index nameexpectedCount
- number of expected statistics objectsjava.sql.SQLException
- if obtaining the statistics failpublic void printStats() throws java.sql.SQLException
SYS.SYSSTATISTICS
system table.java.sql.SQLException
- if obtaining the statistics failspublic void release()
public void release(boolean closeConnection)
closeConnection
- whether to close the associated connection