Package mondrian.rolap.aggmatcher
Class JdbcSchema
- java.lang.Object
-
- mondrian.rolap.aggmatcher.JdbcSchema
-
public class JdbcSchema extends java.lang.Object
Metadata gleaned from JDBC about the tables and columns in the star schema. This class is used to scrape a database and store information about its tables and columnIter.The structure of this information is as follows: A database has tables. A table has columnIter. A column has one or more usages. A usage might be a column being used as a foreign key or as part of a measure.
Tables are created when calling code requests the set of available tables. This call
getTables()
causes all tables to be loaded. But a table's columnIter are not loaded until, on a table-by-table basis, a request is made to get the set of columnIter associated with the table. Since, the AggTableManager first attempts table name matches (recognition) most tables do not match, so why load their columnIter. Of course, as a result, there are a host of methods that can throw anSQLException
, rats.- Author:
- Richard M. Emberson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JdbcSchema.Factory
static class
JdbcSchema.StdFactory
class
JdbcSchema.Table
A table in a database.(package private) static class
JdbcSchema.TableUsageType
(package private) static class
JdbcSchema.UsageType
Enumeration of ways that an aggregate table can use a column.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FACT_COUNT_COLUMN_NAME
static int
FACT_COUNT_COLUMN_USAGE
static java.lang.String
FOREIGN_KEY_COLUMN_NAME
static int
FOREIGN_KEY_COLUMN_USAGE
static java.lang.String
IGNORE_COLUMN_NAME
static int
IGNORE_COLUMN_USAGE
static java.lang.String
LEVEL_COLUMN_NAME
static int
LEVEL_COLUMN_USAGE
static java.lang.String
MEASURE_COLUMN_NAME
static int
MEASURE_COLUMN_USAGE
static java.lang.String
UNKNOWN_COLUMN_NAME
static int
UNKNOWN_COLUMN_USAGE
-
Constructor Summary
Constructors Constructor Description JdbcSchema(javax.sql.DataSource dataSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addTable(java.sql.ResultSet rs)
Makes a Table from an ResultSet: the table's name is the ResultSet third entry.protected void
clear()
static void
clearAllDBs()
static void
clearDB(javax.sql.DataSource dataSource)
Clears information in a JdbcSchema associated with a DataSource.static java.lang.String
convertColumnTypeToName(java.util.Set<JdbcSchema.UsageType> columnType)
Maps from column type enum to column type name or list of names if the parameter represents more than on usage.void
flushUsages()
flushes all star usage referencesjava.lang.String
getCatalogName()
Returns the database's catalog name.javax.sql.DataSource
getDataSource()
static Dialect.Datatype
getDatatype(int javaType)
Converts aTypes
value to aDialect.Datatype
.org.apache.log4j.Logger
getLogger()
Returns the Logger.java.lang.String
getSchemaName()
Returns the database's schema name.JdbcSchema.Table
getTable(java.lang.String tableName)
Gets a table by name.java.util.Collection<JdbcSchema.Table>
getTables()
Returns the database's tables.static boolean
isText(int javaType)
Returns true if the parameter is a java.sql.Type text type.static boolean
isUniqueColumnType(java.util.Set<JdbcSchema.UsageType> columnType)
Determine if the parameter represents a single column type, i.e., the column only has one usage.void
load()
This forces the tables to be loaded.static JdbcSchema
makeDB(javax.sql.DataSource dataSource)
Creates or retrieves an instance of the JdbcSchema for the given DataSource.void
print(java.io.PrintWriter pw, java.lang.String prefix)
protected void
remove()
static void
removeDB(javax.sql.DataSource dataSource)
Removes a JdbcSchema associated with a DataSource.(package private) void
resetAllTablesLoaded()
Used for testing allowing one to load tables and their columnIter from more than one datasourcevoid
setCatalogName(java.lang.String catalog)
Sets the database's catalog name.protected void
setDataSource(javax.sql.DataSource dataSource)
void
setSchemaName(java.lang.String schema)
Sets the database's schema name.java.lang.String
toString()
-
-
-
Field Detail
-
UNKNOWN_COLUMN_USAGE
public static final int UNKNOWN_COLUMN_USAGE
- See Also:
- Constant Field Values
-
FOREIGN_KEY_COLUMN_USAGE
public static final int FOREIGN_KEY_COLUMN_USAGE
- See Also:
- Constant Field Values
-
MEASURE_COLUMN_USAGE
public static final int MEASURE_COLUMN_USAGE
- See Also:
- Constant Field Values
-
LEVEL_COLUMN_USAGE
public static final int LEVEL_COLUMN_USAGE
- See Also:
- Constant Field Values
-
FACT_COUNT_COLUMN_USAGE
public static final int FACT_COUNT_COLUMN_USAGE
- See Also:
- Constant Field Values
-
IGNORE_COLUMN_USAGE
public static final int IGNORE_COLUMN_USAGE
- See Also:
- Constant Field Values
-
UNKNOWN_COLUMN_NAME
public static final java.lang.String UNKNOWN_COLUMN_NAME
- See Also:
- Constant Field Values
-
FOREIGN_KEY_COLUMN_NAME
public static final java.lang.String FOREIGN_KEY_COLUMN_NAME
- See Also:
- Constant Field Values
-
MEASURE_COLUMN_NAME
public static final java.lang.String MEASURE_COLUMN_NAME
- See Also:
- Constant Field Values
-
LEVEL_COLUMN_NAME
public static final java.lang.String LEVEL_COLUMN_NAME
- See Also:
- Constant Field Values
-
FACT_COUNT_COLUMN_NAME
public static final java.lang.String FACT_COUNT_COLUMN_NAME
- See Also:
- Constant Field Values
-
IGNORE_COLUMN_NAME
public static final java.lang.String IGNORE_COLUMN_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getLogger
public org.apache.log4j.Logger getLogger()
Returns the Logger.
-
makeDB
public static JdbcSchema makeDB(javax.sql.DataSource dataSource)
Creates or retrieves an instance of the JdbcSchema for the given DataSource.- Parameters:
dataSource
- DataSource- Returns:
- instance of the JdbcSchema for the given DataSource
-
clearDB
public static void clearDB(javax.sql.DataSource dataSource)
Clears information in a JdbcSchema associated with a DataSource.- Parameters:
dataSource
- DataSource
-
removeDB
public static void removeDB(javax.sql.DataSource dataSource)
Removes a JdbcSchema associated with a DataSource.- Parameters:
dataSource
- DataSource
-
isUniqueColumnType
public static boolean isUniqueColumnType(java.util.Set<JdbcSchema.UsageType> columnType)
Determine if the parameter represents a single column type, i.e., the column only has one usage.- Parameters:
columnType
- Column types- Returns:
- true if column has only one usage.
-
convertColumnTypeToName
public static java.lang.String convertColumnTypeToName(java.util.Set<JdbcSchema.UsageType> columnType)
Maps from column type enum to column type name or list of names if the parameter represents more than on usage.
-
getDatatype
public static Dialect.Datatype getDatatype(int javaType)
Converts aTypes
value to aDialect.Datatype
.- Parameters:
javaType
- JDBC type code, as perTypes
- Returns:
- Datatype
-
isText
public static boolean isText(int javaType)
Returns true if the parameter is a java.sql.Type text type.
-
load
public void load() throws java.sql.SQLException
This forces the tables to be loaded.- Throws:
java.sql.SQLException
-
clear
protected void clear()
-
remove
protected void remove()
-
resetAllTablesLoaded
void resetAllTablesLoaded()
Used for testing allowing one to load tables and their columnIter from more than one datasource
-
getDataSource
public javax.sql.DataSource getDataSource()
-
setDataSource
protected void setDataSource(javax.sql.DataSource dataSource)
-
setSchemaName
public void setSchemaName(java.lang.String schema)
Sets the database's schema name.- Parameters:
schema
- Schema name
-
getSchemaName
public java.lang.String getSchemaName()
Returns the database's schema name.
-
setCatalogName
public void setCatalogName(java.lang.String catalog)
Sets the database's catalog name.
-
getCatalogName
public java.lang.String getCatalogName()
Returns the database's catalog name.
-
getTables
public java.util.Collection<JdbcSchema.Table> getTables()
Returns the database's tables. The collection is sorted by table name.
-
flushUsages
public void flushUsages()
flushes all star usage references
-
getTable
public JdbcSchema.Table getTable(java.lang.String tableName)
Gets a table by name.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
print
public void print(java.io.PrintWriter pw, java.lang.String prefix)
-
addTable
protected void addTable(java.sql.ResultSet rs) throws java.sql.SQLException
Makes a Table from an ResultSet: the table's name is the ResultSet third entry.- Parameters:
rs
- Result set- Throws:
java.sql.SQLException
-
clearAllDBs
public static void clearAllDBs()
-
-