mondrian.rolap.aggmatcher
Class JdbcSchema

java.lang.Object
  extended by mondrian.rolap.aggmatcher.JdbcSchema

public class JdbcSchema
extends Object

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 an SQLException, rats.

Author:
Richard M. Emberson
 

Nested Class Summary
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
static String FACT_COUNT_COLUMN_NAME
           
static int FACT_COUNT_COLUMN_USAGE
           
static String FOREIGN_KEY_COLUMN_NAME
           
static int FOREIGN_KEY_COLUMN_USAGE
           
static String IGNORE_COLUMN_NAME
           
static int IGNORE_COLUMN_USAGE
           
static String LEVEL_COLUMN_NAME
           
static int LEVEL_COLUMN_USAGE
           
static String MEASURE_COLUMN_NAME
           
static int MEASURE_COLUMN_USAGE
           
static String UNKNOWN_COLUMN_NAME
           
static int UNKNOWN_COLUMN_USAGE
           
 
Constructor Summary
JdbcSchema(DataSource dataSource)
           
 
Method Summary
protected  void addTable(ResultSet rs)
          Make a Table from an ResultSet - the table's name is the ResultSet third entry.
protected  void clear()
          For testing ONLY void clearUsages() { for (Iterator usageIter = getTables(); usageIter.hasNext();) { Table table = (Table) usageIter.next(); table.clearUsages(); } }
static void clearAllDBs()
           
static void clearDB(DataSource dataSource)
          Clears information in a JdbcSchema associated with a DataSource.
static String convertColumnTypeToName(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.
 String getCatalogName()
          Get the database's catalog name.
 DataSource getDataSource()
           
static SqlQuery.Datatype getDatatype(int javaType)
          Converts a Types value to a SqlQuery.Datatype.
 org.apache.log4j.Logger getLogger()
          Get the Logger.
 String getSchemaName()
          Get the database's schema name.
 JdbcSchema.Table getTable(String tableName)
          Gets a table by name.
 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(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(DataSource dataSource)
          Creates or retrieves an instance of the JdbcSchema for the given DataSource.
 void print(PrintWriter pw, String prefix)
           
protected  void remove()
           
static void removeDB(DataSource dataSource)
          Removes a JdbcSchema associated with a DataSource.
(package private)  void resetAllTablesLoaded()
          This is used for testing allowing one to load tables and their columnIter from more than one datasource
 void setCatalogName(String catalog)
          Set the database's catalog name.
protected  void setDataSource(DataSource dataSource)
           
 void setSchemaName(String schema)
          Set the database's schema name.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 String UNKNOWN_COLUMN_NAME
See Also:
Constant Field Values

FOREIGN_KEY_COLUMN_NAME

public static final String FOREIGN_KEY_COLUMN_NAME
See Also:
Constant Field Values

MEASURE_COLUMN_NAME

public static final String MEASURE_COLUMN_NAME
See Also:
Constant Field Values

LEVEL_COLUMN_NAME

public static final String LEVEL_COLUMN_NAME
See Also:
Constant Field Values

FACT_COUNT_COLUMN_NAME

public static final String FACT_COUNT_COLUMN_NAME
See Also:
Constant Field Values

IGNORE_COLUMN_NAME

public static final String IGNORE_COLUMN_NAME
See Also:
Constant Field Values
Constructor Detail

JdbcSchema

JdbcSchema(DataSource dataSource)
Method Detail

getLogger

public org.apache.log4j.Logger getLogger()
Get the Logger.


makeDB

public static JdbcSchema makeDB(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(DataSource dataSource)
Clears information in a JdbcSchema associated with a DataSource.

Parameters:
dataSource - DataSource

removeDB

public static void removeDB(DataSource dataSource)
Removes a JdbcSchema associated with a DataSource.

Parameters:
dataSource - DataSource

isUniqueColumnType

public static boolean isUniqueColumnType(Set<JdbcSchema.UsageType> columnType)
Determine if the parameter represents a single column type, i.e., the column only has one usage.

Parameters:
columnType -
Returns:
true if column has only one usage.

convertColumnTypeToName

public static String convertColumnTypeToName(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 SqlQuery.Datatype getDatatype(int javaType)
Converts a Types value to a SqlQuery.Datatype.

Parameters:
javaType - JDBC type code, as per Types
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 SQLException
This forces the tables to be loaded.

Throws:
SQLException

clear

protected void clear()
For testing ONLY void clearUsages() { for (Iterator usageIter = getTables(); usageIter.hasNext();) { Table table = (Table) usageIter.next(); table.clearUsages(); } }


remove

protected void remove()

resetAllTablesLoaded

void resetAllTablesLoaded()
This is used for testing allowing one to load tables and their columnIter from more than one datasource


getDataSource

public DataSource getDataSource()

setDataSource

protected void setDataSource(DataSource dataSource)

setSchemaName

public void setSchemaName(String schema)
Set the database's schema name.

Parameters:
schema -

getSchemaName

public String getSchemaName()
Get the database's schema name.


setCatalogName

public void setCatalogName(String catalog)
Set the database's catalog name.


getCatalogName

public String getCatalogName()
Get the database's catalog name.


getTables

public Collection<JdbcSchema.Table> getTables()
Returns the database's tables. The collection is sorted by table name.


getTable

public JdbcSchema.Table getTable(String tableName)
Gets a table by name.


toString

public String toString()
Overrides:
toString in class Object

print

public void print(PrintWriter pw,
                  String prefix)

addTable

protected void addTable(ResultSet rs)
                 throws SQLException
Make a Table from an ResultSet - the table's name is the ResultSet third entry.

Throws:
SQLException
Parameters:
rs -

clearAllDBs

public static void clearAllDBs()

SourceForge.net_Logo