/** * adds a unique constraint (a primary key or a unique constraint proper) * * @param uc */ public void addUniqueConstraint(UniqueConstraint uc) { if (uc.isPrimaryKey()) { if (pk != null) throw new IllegalArgumentException("Duplicate PK " + pk + " " + uc); pk = uc; } else { if (pk != null) if (uc.getAttributes().equals(pk.getAttributes())) // ignore the unique index created for the primary key return; } ucs.add(uc); }
/** * adds a unique constraint (a primary key or a unique constraint proper) * * @param uc */ public void addUniqueConstraint(UniqueConstraint uc) { if (uc.isPrimaryKey()) { if (pk != null) throw new IllegalArgumentException("Duplicate PK " + pk + " " + uc); pk = uc; } else { if (pk != null) if (uc.getAttributes().equals(pk.getAttributes())) // ignore the unique index created for the primary key return; } ucs.add(uc); }
private boolean isUcMatching(UniqueConstraint uniqueConstraint, ImmutableList<? extends VariableOrGroundTerm> leftArguments, ImmutableList<? extends VariableOrGroundTerm> rightArguments) { return uniqueConstraint.getAttributes().stream() .allMatch(a -> leftArguments.get(a.getIndex() -1) .equals(rightArguments.get(a.getIndex() - 1)) // Excludes nullable attributes for the moment. TODO: reconsider it && !a.canNull()); }
private Stream<Map.Entry<RelationPredicate, ImmutableList<Integer>>> extractUniqueConstraintsFromRelation( DatabaseRelationDefinition relation) { return relation.getUniqueConstraints().stream() .map(uc -> uc.getAttributes().stream() .map(Attribute::getIndex) .collect(ImmutableCollectors.toList())) .map(positions -> new AbstractMap.SimpleEntry<>(relation.getAtomPredicate(), positions)); }
private Stream<Map.Entry<AtomPredicate, ImmutableList<Integer>>> extractUniqueConstraintsFromRelation( DatabaseRelationDefinition relation, Map<Predicate, AtomPredicate> predicateCache) { Predicate originalPredicate = Relation2Predicate.createPredicateFromRelation(relation); AtomPredicate atomPredicate = convertToAtomPredicate(originalPredicate, predicateCache); return relation.getUniqueConstraints().stream() .map(uc -> uc.getAttributes().stream() .map(Attribute::getIndex) .collect(ImmutableCollectors.toList())) .map(positions -> new AbstractMap.SimpleEntry<>(atomPredicate, positions)); }
private boolean isUcMatching(UniqueConstraint uniqueConstraint, ImmutableList<? extends VariableOrGroundTerm> leftArguments, ImmutableList<? extends VariableOrGroundTerm> rightArguments) { return uniqueConstraint.getAttributes().stream() .allMatch(a -> leftArguments.get(a.getIndex() -1) .equals(rightArguments.get(a.getIndex() - 1)) // Excludes nullable attributes for the moment. TODO: reconsider it && !a.canNull()); }
private static List<Attribute> getIdentifyingAttributes(DatabaseRelationDefinition table) { UniqueConstraint pk = table.getPrimaryKey(); if (pk != null) return pk.getAttributes(); else return table.getAttributes(); }
private static List<Attribute> getIdentifyingAttributes(DatabaseRelationDefinition table) { UniqueConstraint pk = table.getPrimaryKey(); if (pk != null) return pk.getAttributes(); else return table.getAttributes(); }
private ImmutableSet<Integer> extractNonMatchedRightAttributeIndexes(ImmutableCollection<UniqueConstraint> matchedUCs, ImmutableCollection<ForeignKeyConstraint> matchedFKs, int arity) { return IntStream.range(0, arity) .filter(i -> (matchedUCs.stream() .noneMatch(uc -> uc.getAttributes().stream() .anyMatch(a -> a.getIndex() == (i + 1))))) .filter(i -> (matchedFKs.stream() .noneMatch(fk -> fk.getComponents().stream() .anyMatch(c -> c.getReference().getIndex() == (i + 1))))) .boxed() .collect(ImmutableCollectors.toSet()); }
private ImmutableSet<Integer> extractNonMatchedRightAttributeIndexes(ImmutableCollection<UniqueConstraint> matchedUCs, ImmutableCollection<ForeignKeyConstraint> matchedFKs, int arity) { return IntStream.range(0, arity) .filter(i -> (matchedUCs.stream() .noneMatch(uc -> uc.getAttributes().stream() .anyMatch(a -> a.getIndex() == (i + 1))))) .filter(i -> (matchedFKs.stream() .noneMatch(fk -> fk.getComponents().stream() .anyMatch(c -> c.getReference().getIndex() == (i + 1))))) .boxed() .collect(ImmutableCollectors.toSet()); }
List<ImmutableTerm> terms = new ArrayList<>(pk.getAttributes().size() + 1); List<String> attributes = new ArrayList<>(pk.getAttributes().size()); for (Attribute att : pk.getAttributes()) attributes.add(R2RMLIRISafeEncoder.encode(att.getID().getName()) + "={}"); terms.add(termFactory.getConstantLiteral(template)); for (Attribute att : pk.getAttributes()) terms.add(termFactory.getVariable(varNamePrefix + att.getID().getName()));
List<ImmutableTerm> terms = new ArrayList<>(pk.getAttributes().size() + 1); List<String> attributes = new ArrayList<>(pk.getAttributes().size()); for (Attribute att : pk.getAttributes()) attributes.add(R2RMLIRISafeEncoder.encode(att.getID().getName()) + "={}"); terms.add(df.getConstantLiteral(template)); for (Attribute att : pk.getAttributes()) terms.add(df.getVariable(varNamePrefix + att.getID().getName()));