private String getReferencePropertyIRI(ForeignKeyConstraint fk) { List<String> attributes = new ArrayList<>(fk.getComponents().size()); for (Component component : fk.getComponents()) attributes.add(R2RMLIRISafeEncoder.encode(component.getAttribute().getID().getName())); return baseIRI + R2RMLIRISafeEncoder.encode(fk.getRelation().getID().getTableName()) + "#ref-" + Joiner.on(";").join(attributes); }
private IRI getReferencePropertyIRI(ForeignKeyConstraint fk) { List<String> attributes = new ArrayList<>(fk.getComponents().size()); for (Component component : fk.getComponents()) attributes.add(R2RMLIRISafeEncoder.encode(component.getAttribute().getID().getName())); return rdfFactory.createIRI(baseIRI + R2RMLIRISafeEncoder.encode(fk.getRelation().getID().getTableName()) + "#ref-" + Joiner.on(";").join(attributes)); }
/** * Definition row graph: an RDF graph consisting of the following triples: * * - a reference triple for each <column name list> in a table's foreign keys where none of the column values is NULL. * */ private ImmutableList<TargetAtom> getRefCQ(ForeignKeyConstraint fk) { ImmutableTerm sub = generateSubject(fk.getRelation(), true); ImmutableTerm obj = generateSubject(fk.getReferencedRelation(), true); TargetAtom atom = getAtom(getReferencePropertyIRI(fk), sub, obj); return ImmutableList.of(atom); }
/*** * Definition reference triple: an RDF triple with: * <p/> * subject: the row node for the row. * predicate: the reference property IRI for the columns. * object: the row node for the referenced row. * * @param fk * @return */ private String getRefSQL(ForeignKeyConstraint fk) { Set<Object> columns = new LinkedHashSet<>(); // Set avoids duplicated and LinkedHashSet keeps the insertion order for (Attribute attr : getIdentifyingAttributes(fk.getRelation())) columns.add(getColumnNameWithAlias(attr)); List<String> conditions = new ArrayList<>(fk.getComponents().size()); for (ForeignKeyConstraint.Component comp : fk.getComponents()) { columns.add(getColumnNameWithAlias(comp.getReference())); conditions.add(getColumnName(comp.getAttribute()) + " = " + getColumnName(comp.getReference())); } for (Attribute attr : getIdentifyingAttributes(fk.getReferencedRelation())) columns.add(getColumnNameWithAlias(attr)); final String tables = fk.getRelation().getID().getSQLRendering() + ", " + fk.getReferencedRelation().getID().getSQLRendering(); return String.format("SELECT %s FROM %s WHERE %s", Joiner.on(", ").join(columns), tables, Joiner.on(" AND ").join(conditions)); }
/** * Definition row graph: an RDF graph consisting of the following triples: * * - a reference triple for each <column name list> in a table's foreign keys where none of the column values is NULL. * */ private ImmutableList<ImmutableFunctionalTerm> getRefCQ(ForeignKeyConstraint fk) { ImmutableTerm sub = generateSubject(fk.getRelation(), true); ImmutableTerm obj = generateSubject(fk.getReferencedRelation(), true); ImmutableFunctionalTerm atom = df.getImmutableFunctionalTerm( df.getObjectPropertyPredicate(getReferencePropertyIRI(fk)), sub, obj); return ImmutableList.of(atom); }
/*** * Definition reference triple: an RDF triple with: * <p/> * subject: the row node for the row. * predicate: the reference property IRI for the columns. * object: the row node for the referenced row. * * @param fk * @return */ private String getRefSQL(ForeignKeyConstraint fk) { Set<Object> columns = new LinkedHashSet<>(); // Set avoids duplicated and LinkedHashSet keeps the insertion order for (Attribute attr : getIdentifyingAttributes(fk.getRelation())) columns.add(getColumnNameWithAlias(attr)); List<String> conditions = new ArrayList<>(fk.getComponents().size()); for (ForeignKeyConstraint.Component comp : fk.getComponents()) { columns.add(getColumnNameWithAlias(comp.getReference())); conditions.add(getColumnName(comp.getAttribute()) + " = " + getColumnName(comp.getReference())); } for (Attribute attr : getIdentifyingAttributes(fk.getReferencedRelation())) columns.add(getColumnNameWithAlias(attr)); final String tables = fk.getRelation().getID().getSQLRendering() + ", " + fk.getReferencedRelation().getID().getSQLRendering(); return String.format("SELECT %s FROM %s WHERE %s", Joiner.on(", ").join(columns), tables, Joiner.on(" AND ").join(conditions)); }
private LinearInclusionDependency getLinearInclusionDependency(ForeignKeyConstraint fk) { DatabaseRelationDefinition def = fk.getRelation(); DatabaseRelationDefinition def2 = fk.getReferencedRelation(); // create variables for the current table int len1 = def.getAttributes().size(); List<Term> terms1 = new ArrayList<>(len1); for (int i = 1; i <= len1; i++) terms1.add(termFactory.getVariable("t" + i)); // create variables for the referenced table int len2 = def2.getAttributes().size(); List<Term> terms2 = new ArrayList<>(len2); for (int i = 1; i <= len2; i++) terms2.add(termFactory.getVariable("p" + i)); for (ForeignKeyConstraint.Component comp : fk.getComponents()) { // indexes start at 1 int pos1 = comp.getAttribute().getIndex() - 1; // current column (1) int pos2 = comp.getReference().getIndex() - 1; // referenced column (2) terms1.set(pos1, terms2.get(pos2)); } Function head = termFactory.getFunction(def2.getAtomPredicate(), terms2); Function body = termFactory.getFunction(def.getAtomPredicate(), terms1); return new LinearInclusionDependency(head, body); }