/** * return the database relation for the unique constraint * * @return */ public DatabaseRelationDefinition getRelation() { return (DatabaseRelationDefinition)attributes.get(0).getRelation(); }
/** * return the database relation for the unique constraint * * @return */ public DatabaseRelationDefinition getRelation() { return (DatabaseRelationDefinition)attributes.get(0).getRelation(); }
/** * adds an attribute to the UNIQUE constraint * * @param attribute * @return */ public Builder add(Attribute attribute) { if (relation != attribute.getRelation()) throw new IllegalArgumentException("Unique Key requires the same table in all attributes: " + relation + " " + attribute); builder.add(attribute); return this; }
/** * adds an attribute to the UNIQUE constraint * * @param attribute * @return */ public Builder add(Attribute attribute) { if (relation != attribute.getRelation()) throw new IllegalArgumentException("Unique Key requires the same table in all attributes: " + relation + " " + attribute); builder.add(attribute); return this; }
/** * private constructor (use Builder instead) * * @param name * @param components */ private ForeignKeyConstraint(String name, ImmutableList<Component> components) { this.name = name; this.components = components; this.relation = (DatabaseRelationDefinition)components.get(0).getAttribute().getRelation(); this.referencedRelation = (DatabaseRelationDefinition)components.get(0).getReference().getRelation(); }
/** * private constructor (use Builder instead) * * @param name * @param components */ private ForeignKeyConstraint(String name, ImmutableList<Component> components) { this.name = name; this.components = components; this.relation = (DatabaseRelationDefinition)components.get(0).getAttribute().getRelation(); this.referencedRelation = (DatabaseRelationDefinition)components.get(0).getReference().getRelation(); }
@Override public String toString() { List<String> columns = new ArrayList<>(attributes.size()); for (Attribute c : attributes) columns.add(c.getID().toString()); StringBuilder bf = new StringBuilder(); bf.append("ALTER TABLE ").append(attributes.get(0).getRelation().getID()) .append(" ADD CONSTRAINT ").append(name).append(isPK ? " PRIMARY KEY " : " UNIQUE ") .append("("); Joiner.on(", ").appendTo(bf, columns); bf.append(")"); return bf.toString(); } }
@Override public String toString() { List<String> columns = new ArrayList<>(attributes.size()); for (Attribute c : attributes) columns.add(c.getID().toString()); StringBuilder bf = new StringBuilder(); bf.append("ALTER TABLE ").append(attributes.get(0).getRelation().getID()) .append(" ADD CONSTRAINT ").append(name).append(isPK ? " PRIMARY KEY " : " UNIQUE ") .append("("); Joiner.on(", ").appendTo(bf, columns); bf.append(")"); return bf.toString(); } }
/** * creates a single-attribute foreign key * * @param name * @param attribute * @param reference * @return */ public static ForeignKeyConstraint of(String name, Attribute attribute, Attribute reference) { return new Builder((DatabaseRelationDefinition)attribute.getRelation(), (DatabaseRelationDefinition)reference.getRelation()) .add(attribute, reference).build(name); }
/** * creates a single-attribute foreign key * * @param name * @param attribute * @param reference * @return */ public static ForeignKeyConstraint of(String name, Attribute attribute, Attribute reference) { return new Builder((DatabaseRelationDefinition)attribute.getRelation(), (DatabaseRelationDefinition)reference.getRelation()) .add(attribute, reference).build(name); }
/** * adds a pair (attribute, referenced attribute) to the FK constraint * * @param attribute * @param referencedAttribute * @return */ public Builder add(Attribute attribute, Attribute referencedAttribute) { if (attribute == null) { throw new IllegalArgumentException("Missing Foreign Key column for table " + relation.getID() +" referring to primary key "+attribute+" in table " + referencedRelation.getID()); } if (referencedAttribute == null){ throw new IllegalArgumentException("Missing Primary Key column for table " + referencedRelation.getID() +" referring to foreign key "+attribute+" in table "+ relation.getID() ); } if (relation != attribute.getRelation()) throw new IllegalArgumentException("Foreign Key requires the same table in all attributes: " + relation + " -> " + referencedRelation + " (attribute " + attribute.getRelation().getID() + "." + attribute + ")"); if (referencedRelation != referencedAttribute.getRelation()) throw new IllegalArgumentException("Foreign Key requires the same table in all referenced attributes: " + relation + " -> " + referencedRelation + " (attribute " + referencedAttribute.getRelation().getID() + "." + referencedAttribute + ")"); builder.add(new Component(attribute, referencedAttribute)); return this; }
/** * adds a pair (attribute, referenced attribute) to the FK constraint * * @param attribute * @param referencedAttribute * @return */ public Builder add(Attribute attribute, Attribute referencedAttribute) { if (attribute == null) { throw new IllegalArgumentException("Missing Foreign Key column for table " + relation.getID() +" referring to primary key "+attribute+" in table " + referencedRelation.getID()); } if (referencedAttribute == null){ throw new IllegalArgumentException("Missing Primary Key column for table " + referencedRelation.getID() +" referring to foreign key "+attribute+" in table "+ relation.getID() ); } if (relation != attribute.getRelation()) throw new IllegalArgumentException("Foreign Key requires the same table in all attributes: " + relation + " -> " + referencedRelation + " (attribute " + attribute.getRelation().getID() + "." + attribute + ")"); if (referencedRelation != referencedAttribute.getRelation()) throw new IllegalArgumentException("Foreign Key requires the same table in all referenced attributes: " + relation + " -> " + referencedRelation + " (attribute " + referencedAttribute.getRelation().getID() + "." + referencedAttribute + ")"); builder.add(new Component(attribute, referencedAttribute)); return this; }
public static UniqueConstraint primaryKeyOf(Attribute att) { UniqueConstraint.Builder builder = new UniqueConstraint.Builder((DatabaseRelationDefinition)att.getRelation()); return builder.add(att).build("PK_" + att.getRelation().getID().getTableName(), true); }
public static UniqueConstraint primaryKeyOf(Attribute att) { UniqueConstraint.Builder builder = new UniqueConstraint.Builder((DatabaseRelationDefinition)att.getRelation()); return builder.add(att).build("PK_" + att.getRelation().getID().getTableName(), true); }
public static UniqueConstraint primaryKeyOf(Attribute att, Attribute att2) { UniqueConstraint.Builder builder = new UniqueConstraint.Builder((DatabaseRelationDefinition)att.getRelation()); return builder.add(att).add(att2).build("PK_" + att.getRelation().getID().getTableName(), true); }
public static UniqueConstraint primaryKeyOf(Attribute att, Attribute att2) { UniqueConstraint.Builder builder = new UniqueConstraint.Builder((DatabaseRelationDefinition)att.getRelation()); return builder.add(att).add(att2).build("PK_" + att.getRelation().getID().getTableName(), true); }
private static String getColumnNameWithAlias(Attribute attr) { return getColumnName(attr) + " AS " + attr.getRelation().getID().getTableName() + "_" + attr.getID().getName(); }
private static String getColumnNameWithAlias(Attribute attr) { return getColumnName(attr) + " AS " + attr.getRelation().getID().getTableName() + "_" + attr.getID().getName(); }
/** * Generate an URI for datatype property from a string(name of column) The * style should be "baseIRI/tablename#columnname" as required in Direct * Mapping Definition * * A column in a table forms a literal property IRI: * * Definition literal property IRI: the concatenation of: * - the percent-encoded form of the table name, * - the hash character '#', * - the percent-encoded form of the column name. */ private String getLiteralPropertyIRI(Attribute attr) { return baseIRI + R2RMLIRISafeEncoder.encode(attr.getRelation().getID().getTableName()) + "#" + R2RMLIRISafeEncoder.encode(attr.getID().getName()); }
/** * Generate an URI for datatype property from a string(name of column) The * style should be "baseIRI/tablename#columnname" as required in Direct * Mapping Definition * * A column in a table forms a literal property IRI: * * Definition literal property IRI: the concatenation of: * - the percent-encoded form of the table name, * - the hash character '#', * - the percent-encoded form of the column name. */ private IRI getLiteralPropertyIRI(Attribute attr) { return rdfFactory.createIRI(baseIRI + R2RMLIRISafeEncoder.encode(attr.getRelation().getID().getTableName()) + "#" + R2RMLIRISafeEncoder.encode(attr.getID().getName())); }