net.sf.farrago.namespace.jdbc
Class MedJdbcNameDirectory

java.lang.Object
  extended by net.sf.farrago.plugin.FarragoAbstractPluginBase
      extended by net.sf.farrago.namespace.impl.MedAbstractBase
          extended by net.sf.farrago.namespace.impl.MedAbstractNameDirectory
              extended by net.sf.farrago.namespace.jdbc.MedJdbcNameDirectory
All Implemented Interfaces:
FarragoMedNameDirectory

public class MedJdbcNameDirectory
extends MedAbstractNameDirectory

MedJdbcNameDirectory implements the FarragoMedNameDirectory interface by mapping the metadata provided by any JDBC driver.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/namespace/jdbc/MedJdbcNameDirectory.java#49 $
Author:
John V. Sichi

Field Summary
(package private)  String schemaName
           
(package private)  MedJdbcDataServer server
           
(package private)  boolean shouldSubstituteTypes
           
(package private)  Properties typeMapping
           
 
Fields inherited from class net.sf.farrago.plugin.FarragoAbstractPluginBase
BOOLEAN_CHOICES_DEFAULT_FALSE, BOOLEAN_CHOICES_DEFAULT_TRUE, EMPTY_DRIVER_PROPERTIES
 
Constructor Summary
MedJdbcNameDirectory(MedJdbcDataServer server)
           
MedJdbcNameDirectory(MedJdbcDataServer server, String schemaName)
           
 
Method Summary
private  void addTypeMapping(String s)
           
private  String getFilterPattern(FarragoMedMetadataQuery query, String typeName)
           
private  String getMappedTableName(String schema, String table, String origSchema)
          Convert the foreign database's schema and table into the "foreign" name used locally by Farrago in origSchema.
private  String[] getSchemaPattern()
           
 MedJdbcDataServer getServer()
           
private  String[] getTablePattern(FarragoMedMetadataQuery query, String typeName, String schema)
           
protected  boolean isRemoteSqlValid(SqlNode sqlNode)
          Tests whether a remote SQL query is valid by attempting to prepare it.
 FarragoMedColumnSet lookupColumnSet(FarragoTypeFactory typeFactory, String foreignName, String[] localName)
          Looks up a FarragoMedColumnSet by name.
(package private)  FarragoMedColumnSet lookupColumnSetAndImposeType(FarragoTypeFactory typeFactory, String foreignName, String[] localName, RelDataType rowType, boolean tableAlreadyMapped)
          Looks up the FarragoMedColumnSet for the given table.
 FarragoMedNameDirectory lookupSubdirectory(String foreignName)
          Looks up an immediate subdirectory by name.
private  boolean matchSchema(String s1, String s2)
           
(package private)  String normalizeQueryString(String sql)
           
private  boolean queryColumns(FarragoMedMetadataQuery query, FarragoMedMetadataSink sink, List<String> tableListActual, List<String> schemaListActual, List<String> tableListOptimized)
           
private  boolean queryColumnsImpl(FarragoMedMetadataQuery query, FarragoMedMetadataSink sink, String tableName, String actualSchemaName, Set<String> tableSet)
           
 boolean queryMetadata(FarragoMedMetadataQuery query, FarragoMedMetadataSink sink)
          Executes a query against the metadata contained by this directory.
private  boolean querySchemas(FarragoMedMetadataQuery query, FarragoMedMetadataSink sink)
           
private  boolean queryTables(FarragoMedMetadataQuery query, FarragoMedMetadataSink sink, List<String> tableListActual, List<String> schemaListActual, List<String> tableListOptimized)
           
private  RelDataType updateRowType(FarragoTypeFactory typeFactory, RelDataType currRowType, RelDataType srcRowType)
           
private  void validateRowType(RelDataType rowType, RelDataType srcRowType)
           
 
Methods inherited from class net.sf.farrago.namespace.impl.MedAbstractNameDirectory
newImportedColumnSet
 
Methods inherited from class net.sf.farrago.plugin.FarragoAbstractPluginBase
getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getLongProperty, getShortProperty, requireProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

final MedJdbcDataServer server

schemaName

String schemaName

shouldSubstituteTypes

final boolean shouldSubstituteTypes

typeMapping

final Properties typeMapping
Constructor Detail

MedJdbcNameDirectory

public MedJdbcNameDirectory(MedJdbcDataServer server)

MedJdbcNameDirectory

public MedJdbcNameDirectory(MedJdbcDataServer server,
                            String schemaName)
Method Detail

getServer

public MedJdbcDataServer getServer()
Returns:
the server exposing this directory

lookupColumnSet

public FarragoMedColumnSet lookupColumnSet(FarragoTypeFactory typeFactory,
                                           String foreignName,
                                           String[] localName)
                                    throws SQLException
Description copied from interface: FarragoMedNameDirectory
Looks up a FarragoMedColumnSet by name. This method supports Farrago's capability to reference a foreign table directly without having to create local metadata about it.

Parameters:
typeFactory - FarragoTypeFactory to use for defining types
foreignName - simple name of foreign ColumnSet to lookup as a direct child of this directory
localName - compound identifier by which FarragoMedColumnSet will be referenced locally
Returns:
FarragoMedColumnSet, or null if none found
Throws:
SQLException - if metadata access is unsuccessful

lookupColumnSetAndImposeType

FarragoMedColumnSet lookupColumnSetAndImposeType(FarragoTypeFactory typeFactory,
                                                 String foreignName,
                                                 String[] localName,
                                                 RelDataType rowType,
                                                 boolean tableAlreadyMapped)
                                           throws SQLException
Looks up the FarragoMedColumnSet for the given table.

Parameters:
typeFactory - typeFactory to use for type mapping
foreignName - foreign table name
localName - fully qualified local table name
rowType - expected row type
tableAlreadyMapped - if true, foreignName has already been mapped to the foreign database name; if false the mapping has not yet been applied
Returns:
a FarragoMedColumnSet representing the table
Throws:
SQLException - if there is an error querying metadata in the underlying database

normalizeQueryString

String normalizeQueryString(String sql)

lookupSubdirectory

public FarragoMedNameDirectory lookupSubdirectory(String foreignName)
                                           throws SQLException
Description copied from interface: FarragoMedNameDirectory
Looks up an immediate subdirectory by name.

Specified by:
lookupSubdirectory in interface FarragoMedNameDirectory
Overrides:
lookupSubdirectory in class MedAbstractNameDirectory
Parameters:
foreignName - identifier for subdirectory
Returns:
subdirectory, or null if none found
Throws:
SQLException - if metadata access is unsuccessful

queryMetadata

public boolean queryMetadata(FarragoMedMetadataQuery query,
                             FarragoMedMetadataSink sink)
                      throws SQLException
Description copied from interface: FarragoMedNameDirectory
Executes a query against the metadata contained by this directory. This method supports the SQL/MED IMPORT FOREIGN SCHEMA statement, and general metadata browsing.

NOTE: the supplied sink may be used to implement passive aborts by throwing an unchecked exception when an abort request is detected.

Specified by:
queryMetadata in interface FarragoMedNameDirectory
Overrides:
queryMetadata in class MedAbstractNameDirectory
Parameters:
query - the query to execute
sink - target which receives the query results
Returns:
true if the query executed successfully; false if the requested query type was not supported
Throws:
SQLException - if metadata access is unsuccessful (but not if query is unsupported)

querySchemas

private boolean querySchemas(FarragoMedMetadataQuery query,
                             FarragoMedMetadataSink sink)
                      throws SQLException
Throws:
SQLException

queryTables

private boolean queryTables(FarragoMedMetadataQuery query,
                            FarragoMedMetadataSink sink,
                            List<String> tableListActual,
                            List<String> schemaListActual,
                            List<String> tableListOptimized)
                     throws SQLException
Throws:
SQLException

queryColumns

private boolean queryColumns(FarragoMedMetadataQuery query,
                             FarragoMedMetadataSink sink,
                             List<String> tableListActual,
                             List<String> schemaListActual,
                             List<String> tableListOptimized)
                      throws SQLException
Throws:
SQLException

queryColumnsImpl

private boolean queryColumnsImpl(FarragoMedMetadataQuery query,
                                 FarragoMedMetadataSink sink,
                                 String tableName,
                                 String actualSchemaName,
                                 Set<String> tableSet)
                          throws SQLException
Throws:
SQLException

getSchemaPattern

private String[] getSchemaPattern()

getTablePattern

private String[] getTablePattern(FarragoMedMetadataQuery query,
                                 String typeName,
                                 String schema)

getFilterPattern

private String getFilterPattern(FarragoMedMetadataQuery query,
                                String typeName)

getMappedTableName

private String getMappedTableName(String schema,
                                  String table,
                                  String origSchema)
Convert the foreign database's schema and table into the "foreign" name used locally by Farrago in origSchema.

Parameters:
schema - foreign database's schema
table - foreign database's table
origSchema - Farrago schema to which the table is mapped
Returns:
the Farrago foreign table to which schema.table is mapped, of table if no mapping is found

matchSchema

private boolean matchSchema(String s1,
                            String s2)

addTypeMapping

private void addTypeMapping(String s)

updateRowType

private RelDataType updateRowType(FarragoTypeFactory typeFactory,
                                  RelDataType currRowType,
                                  RelDataType srcRowType)

validateRowType

private void validateRowType(RelDataType rowType,
                             RelDataType srcRowType)

isRemoteSqlValid

protected boolean isRemoteSqlValid(SqlNode sqlNode)
Tests whether a remote SQL query is valid by attempting to prepare it. This is intended for use by pushdown rules constructing remote SQL from fragments of relational algebra.

Parameters:
sqlNode - SQL query to be tested
Returns:
true if statement is valid