de.fuberlin.wiwiss.d2rq.mapgen
Class MappingGenerator

java.lang.Object
  extended by de.fuberlin.wiwiss.d2rq.mapgen.MappingGenerator
Direct Known Subclasses:
W3CMappingGenerator

public class MappingGenerator
extends Object

Generates a D2RQ mapping by introspecting a database schema. Result is available as a high-quality Turtle serialization, or as a parsed model.

Author:
Richard Cyganiak (richard@cyganiak.de)

Field Summary
protected  ConnectedDB database
           
protected  String instanceNamespaceURI
           
protected  PrintWriter out
           
protected  DatabaseSchemaInspector schema
           
 
Constructor Summary
MappingGenerator(ConnectedDB database)
           
 
Method Summary
protected  List<Attribute> filter(List<Attribute> columns, boolean requireDistinct, String reason)
           
 boolean isLinkTable(RelationName tableName)
          A table T is considered to be a link table if it has exactly two foreign key constraints, and the constraints reference other tables (not T), and the constraints cover all columns of T, and there are no foreign keys from other tables pointing to this table
 Model mappingModel(String baseURI)
          Returns an in-memory Jena model containing the D2RQ mapping.
 void setFilter(Filter filter)
           
 void setGenerateClasses(boolean flag)
           
 void setGenerateDefinitionLabels(boolean flag)
           
 void setGenerateLabelBridges(boolean flag)
           
 void setHandleLinkTables(boolean flag)
           
 void setInstanceNamespaceURI(String uri)
           
 void setJDBCDriverClass(String driverClassName)
           
 void setMapNamespaceURI(String uri)
           
 void setServeVocabulary(boolean flag)
           
 void setSkipForeignKeyTargetColumns(boolean flag)
           
 void setStartupSQLScript(URI uri)
           
 void setVocabNamespaceURI(String uri)
           
protected  String vocabularyIRITurtle(Attribute attribute)
           
protected  String vocabularyIRITurtle(List<Attribute> attributes)
           
protected  String vocabularyIRITurtle(RelationName tableName)
           
 Model vocabularyModel()
           
 void writeColumn(Attribute column)
           
protected  void writeEntityIdentifier(RelationName tableName, List<Attribute> identifierColumns)
           
 void writeForeignKey(Join foreignKey)
           
 void writeLabelBridge(RelationName tableName, List<Attribute> labelColumns)
           
 void writeMapping(OutputStream out)
           
 void writeMapping(Writer out)
          Writes the D2RQ mapping to a writer.
protected  void writePseudoEntityIdentifier(RelationName tableName)
           
 void writeTable(RelationName tableName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

database

protected final ConnectedDB database

schema

protected final DatabaseSchemaInspector schema

instanceNamespaceURI

protected String instanceNamespaceURI

out

protected PrintWriter out
Constructor Detail

MappingGenerator

public MappingGenerator(ConnectedDB database)
Method Detail

setMapNamespaceURI

public void setMapNamespaceURI(String uri)

setInstanceNamespaceURI

public void setInstanceNamespaceURI(String uri)

setVocabNamespaceURI

public void setVocabNamespaceURI(String uri)

setFilter

public void setFilter(Filter filter)

setJDBCDriverClass

public void setJDBCDriverClass(String driverClassName)

setStartupSQLScript

public void setStartupSQLScript(URI uri)

setGenerateLabelBridges

public void setGenerateLabelBridges(boolean flag)
Parameters:
flag - Generate an rdfs:label property bridge based on the PK?

setGenerateClasses

public void setGenerateClasses(boolean flag)
Parameters:
flag - Generate a d2rq:class for every class map?

setHandleLinkTables

public void setHandleLinkTables(boolean flag)
Parameters:
flag - Handle Link Tables as properties (true) or normal tables (false)

setGenerateDefinitionLabels

public void setGenerateDefinitionLabels(boolean flag)
Parameters:
flag - Generate ClassDefinitionLabels and PropertyDefinitionLabels?

setServeVocabulary

public void setServeVocabulary(boolean flag)
Parameters:
flag - Value for d2rq:serveVocabulary in map:Configuration

setSkipForeignKeyTargetColumns

public void setSkipForeignKeyTargetColumns(boolean flag)

vocabularyModel

public Model vocabularyModel()

mappingModel

public Model mappingModel(String baseURI)
Returns an in-memory Jena model containing the D2RQ mapping.

Parameters:
baseURI - Base URI for resolving relative URIs in the mapping, e.g., map namespace
Returns:
In-memory Jena model containing the D2RQ mapping

writeMapping

public void writeMapping(OutputStream out)

writeMapping

public void writeMapping(Writer out)
Writes the D2RQ mapping to a writer. Note that the calling code is responsible for closing the writers after use.

Parameters:
out - Stream for writing data to the file or console

writeTable

public void writeTable(RelationName tableName)

writeEntityIdentifier

protected void writeEntityIdentifier(RelationName tableName,
                                     List<Attribute> identifierColumns)

writePseudoEntityIdentifier

protected void writePseudoEntityIdentifier(RelationName tableName)

writeLabelBridge

public void writeLabelBridge(RelationName tableName,
                             List<Attribute> labelColumns)

writeColumn

public void writeColumn(Attribute column)

writeForeignKey

public void writeForeignKey(Join foreignKey)

vocabularyIRITurtle

protected String vocabularyIRITurtle(RelationName tableName)

vocabularyIRITurtle

protected String vocabularyIRITurtle(Attribute attribute)

vocabularyIRITurtle

protected String vocabularyIRITurtle(List<Attribute> attributes)

filter

protected List<Attribute> filter(List<Attribute> columns,
                                 boolean requireDistinct,
                                 String reason)

isLinkTable

public boolean isLinkTable(RelationName tableName)
A table T is considered to be a link table if it has exactly two foreign key constraints, and the constraints reference other tables (not T), and the constraints cover all columns of T, and there are no foreign keys from other tables pointing to this table