de.fuberlin.wiwiss.d2rq.dbschema
Class DatabaseSchemaInspector

java.lang.Object
  extended by de.fuberlin.wiwiss.d2rq.dbschema.DatabaseSchemaInspector

public class DatabaseSchemaInspector
extends Object

Inspects a database to retrieve schema information. TODO: All the dbType checks should be moved to the Vendor subclasses TODO: This usually shouldn't be used directly, but through the ConnectedDB. Except in the MappingGenerator. ConnectedDB is easier mockable for unit tests!

Author:
Richard Cyganiak (richard@cyganiak.de)

Field Summary
static int KEYS_EXPORTED
           
static int KEYS_IMPORTED
           
 
Constructor Summary
DatabaseSchemaInspector(ConnectedDB db)
           
 
Method Summary
 DataType columnType(Attribute column)
           
 List<Join> foreignKeys(RelationName tableName, int direction)
          Returns a list of imported or exported (foreign) keys for a table.
 RelationName getCorrectCapitalization(RelationName relationName)
          Looks up a RelationName with the schema in order to retrieve the correct capitalization
 boolean isNullable(Attribute column)
           
 boolean isZerofillColumn(Attribute column)
           
 List<Attribute> listColumns(RelationName tableName)
           
 List<RelationName> listTableNames(String searchInSchema)
          Lists available table names
 List<Attribute> primaryKeyColumns(RelationName tableName)
           
 Map<String,List<String>> uniqueColumns(RelationName tableName)
          Returns unique indexes defined on the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEYS_IMPORTED

public static final int KEYS_IMPORTED
See Also:
Constant Field Values

KEYS_EXPORTED

public static final int KEYS_EXPORTED
See Also:
Constant Field Values
Constructor Detail

DatabaseSchemaInspector

public DatabaseSchemaInspector(ConnectedDB db)
Method Detail

columnType

public DataType columnType(Attribute column)
Parameters:
column -
Returns:
The column's datatype, or null if unknown

isNullable

public boolean isNullable(Attribute column)

isZerofillColumn

public boolean isZerofillColumn(Attribute column)

listTableNames

public List<RelationName> listTableNames(String searchInSchema)
Lists available table names

Parameters:
searchInSchema - Schema to list tables from; null to list tables from all schemas
Returns:
A list of RelationNames

listColumns

public List<Attribute> listColumns(RelationName tableName)

primaryKeyColumns

public List<Attribute> primaryKeyColumns(RelationName tableName)

uniqueColumns

public Map<String,List<String>> uniqueColumns(RelationName tableName)
Returns unique indexes defined on the table.

Parameters:
tableName - Name of a table
Returns:
Map from index name to list of column names

foreignKeys

public List<Join> foreignKeys(RelationName tableName,
                              int direction)
Returns a list of imported or exported (foreign) keys for a table.

Parameters:
tableName - The table we are interested in
direction - If set to KEYS_IMPORTED, the table's foreign keys are returned. If set to KEYS_EXPORTED, the table's primary keys referenced from other tables are returned.
Returns:
A list of Joins; the local columns are in attributes1()

getCorrectCapitalization

public RelationName getCorrectCapitalization(RelationName relationName)
Looks up a RelationName with the schema in order to retrieve the correct capitalization

Parameters:
relationName -
Returns:
The correctly captialized RelationName