org.d2rq.mapgen
Class MappingGenerator

java.lang.Object
  extended by org.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  String instanceNamespaceURI
           
protected  PrintWriter out
           
protected  SQLConnection sqlConnection
           
 
Constructor Summary
MappingGenerator(SQLConnection sqlConnection)
           
 
Method Summary
protected  List<Identifier> filter(TableDef table, List<Identifier> columns, boolean requireDistinct, String reason)
           
 boolean isLinkTable(TableDef table)
          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 setMapNamespaceURI(String uri)
           
 void setServeVocabulary(boolean flag)
           
 void setSkipForeignKeyTargetColumns(boolean flag)
           
 void setStartupSQLScript(URI uri)
           
 void setVocabNamespaceURI(String uri)
           
protected  String vocabularyIRITurtle(TableName tableName)
           
protected  String vocabularyIRITurtle(TableName tableName, Identifier column)
           
protected  String vocabularyIRITurtle(TableName tableName, Key columns)
           
 Model vocabularyModel()
           
 void writeColumn(TableDef table, Identifier column)
           
protected  void writeEntityIdentifier(TableDef table, List<Identifier> identifierColumns)
           
 void writeForeignKey(TableDef table, ForeignKey foreignKey)
           
 void writeLabelBridge(TableDef table, List<Identifier> labelColumns)
           
 void writeMapping(OutputStream out)
           
 void writeMapping(Writer out)
          Writes the D2RQ mapping to a writer.
protected  void writePseudoEntityIdentifier(TableDef table)
           
 void writeTable(TableDef table)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sqlConnection

protected final SQLConnection sqlConnection

instanceNamespaceURI

protected String instanceNamespaceURI

out

protected PrintWriter out
Constructor Detail

MappingGenerator

public MappingGenerator(SQLConnection sqlConnection)
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)

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(TableDef table)

writeEntityIdentifier

protected void writeEntityIdentifier(TableDef table,
                                     List<Identifier> identifierColumns)

writePseudoEntityIdentifier

protected void writePseudoEntityIdentifier(TableDef table)

writeLabelBridge

public void writeLabelBridge(TableDef table,
                             List<Identifier> labelColumns)

writeColumn

public void writeColumn(TableDef table,
                        Identifier column)

writeForeignKey

public void writeForeignKey(TableDef table,
                            ForeignKey foreignKey)

vocabularyIRITurtle

protected String vocabularyIRITurtle(TableName tableName)

vocabularyIRITurtle

protected String vocabularyIRITurtle(TableName tableName,
                                     Identifier column)

vocabularyIRITurtle

protected String vocabularyIRITurtle(TableName tableName,
                                     Key columns)

filter

protected List<Identifier> filter(TableDef table,
                                  List<Identifier> columns,
                                  boolean requireDistinct,
                                  String reason)

isLinkTable

public boolean isLinkTable(TableDef table)
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