public final class IndexMetadataCollector
extends java.lang.Object
P2JIndex
objects,
which are made available by table name via the queryIndexData(Session, String)
method. The
first time a databases is registered with the persistence layer it has its schema scanned and index
metadata is cached for faster lookup on subsequent occasions.Modifier and Type | Class and Description |
---|---|
private static class |
IndexMetadataCollector.ColumnKey
A hash key for a unique combination of table and column name.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.sql.Connection,java.util.Map<IndexMetadataCollector.ColumnKey,java.lang.Integer>> |
columnTypes
A transient mapping of JDBC connections to column data type maps
|
private static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<P2JIndex>>> |
indexesByTable
Mappings of table names to index lists, organized by schema
|
Constructor and Description |
---|
IndexMetadataCollector() |
Modifier and Type | Method and Description |
---|---|
private static int |
getColumnDataType(Database database,
java.sql.Connection conn,
java.lang.String table,
java.lang.String column)
Use database metadata to determine the data type of a database column.
|
(package private) static void |
queryAllIndexData(Database database,
java.lang.String schema)
Query all index metadata from the given database, using a thread pool with 1 thread per
available CPU.
|
static java.util.List<P2JIndex> |
queryIndexData(Session session,
java.lang.String table)
Gather a list of
P2JIndex objects which describe the indices on the given table. |
(package private) static java.util.Map<java.lang.String,P2JIndex> |
retrieveIndexData(java.sql.ResultSet rs,
Database database,
java.sql.Connection conn,
java.lang.String table)
Given a the result set of an index metadata query (for a certain table),
this method is responsible for creating a map which will hold, for each
index, a
P2JIndex object. |
private static final java.util.Map<java.sql.Connection,java.util.Map<IndexMetadataCollector.ColumnKey,java.lang.Integer>> columnTypes
private static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<P2JIndex>>> indexesByTable
static void queryAllIndexData(Database database, java.lang.String schema) throws PersistenceException
database
- Database from which to query index metadata.schema
- Schema containing index information.PersistenceException
- if there is an error accessing the database or querying metadata.public static java.util.List<P2JIndex> queryIndexData(Session session, java.lang.String table) throws PersistenceException
P2JIndex
objects which describe the indices on the given table. This method
uses the database metadata, if any, exposed by the database's JDBC driver.session
- The session to be used. It provides both the database which contains table
and the
connection to it.table
- Name of table to inspect.P2JIndex
objects, one per index found, or null
if the JDBC metadata
query throws SQLException
, indicating a database error, or that the JDBC driver does
not support the requested feature. An empty list is returned if the driver supported the query,
but no indices were found.PersistenceException
- if there is an error getting a session or determining an indexed column's data type.java.lang.UnsupportedOperationException
- if the JDBC driver cannot query database metadata.static java.util.Map<java.lang.String,P2JIndex> retrieveIndexData(java.sql.ResultSet rs, Database database, java.sql.Connection conn, java.lang.String table) throws PersistenceException
P2JIndex
object.rs
- The ResultSet
instance used to retrieve the index metadata.database
- Database which contains table
.conn
- Database connection.table
- The table for which the indexes are retrieved.P2JIndex
instances for each existing table index.PersistenceException
- if any database error is encountered.private static int getColumnDataType(Database database, java.sql.Connection conn, java.lang.String table, java.lang.String column) throws PersistenceException
database
- Target database.conn
- Database connection.table
- Target table.column
- Target column.java.sql.Types
constants.PersistenceException
- if there is any database error, or if the metadata query fails
to produce a result for the given column.