this.out.println("\t.");
}
private void writeLinkTable(RelationName linkTableName) {
List<Join> keys = schema.foreignKeys(linkTableName, DatabaseSchemaInspector.KEYS_IMPORTED);
Join join1 = keys.get(0);
Join join2 = keys.get(1);
if (!filter.matches(join1.table1()) || !filter.matches(join1.table2()) ||
!filter.matchesAll(join1.attributes1()) || !filter.matchesAll(join1.attributes2()) ||
!filter.matches(join2.table1()) || !filter.matches(join2.table2()) ||
!filter.matchesAll(join2.attributes1()) || !filter.matchesAll(join2.attributes2())) {
log.info("Skipping link table " + linkTableName);
return;
}
log.info("Generating d2rq:PropertyBridge instance for table " + linkTableName.qualifiedName());
RelationName table1 = this.schema.getCorrectCapitalization(join1.table2());
RelationName table2 = this.schema.getCorrectCapitalization(join2.table2());
boolean isSelfJoin = table1.equals(table2);
this.out.println("# Table " + linkTableName + (isSelfJoin ? " (n:m self-join)" : " (n:m)"));
this.out.println(propertyBridgeIRITurtle(linkTableName, "link") + " a d2rq:PropertyBridge;");
this.out.println("\td2rq:belongsToClassMap " + classMapIRITurtle(table1) + ";");
this.out.println("\td2rq:property " + vocabularyIRITurtle(linkTableName) + ";");
this.out.println("\td2rq:refersToClassMap " + classMapIRITurtle(table2) + ";");
for (Attribute column: join1.attributes1()) {
Attribute otherColumn = join1.equalAttribute(column);
this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join1.joinDirection()] + " " + otherColumn.qualifiedName() + "\";");
}
AliasMap alias = AliasMap.NO_ALIASES;
if (isSelfJoin) {
RelationName aliasName = new RelationName(
null, table2.tableName() + "_" + linkTableName.tableName() + "__alias");
alias = AliasMap.create1(table2, aliasName);
this.out.println("\td2rq:alias \"" + table2.qualifiedName() +
" AS " + aliasName.qualifiedName() + "\";");
}
for (Attribute column: join2.attributes1()) {
Attribute otherColumn = join2.equalAttribute(column);
this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join2.joinDirection()] + " " + alias.applyTo(otherColumn).qualifiedName() + "\";");
}
this.out.println("\t.");
this.out.println();
createLinkProperty(linkTableName, table1, table2);
this.out.flush();