@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(); } }
/** * Inserts a new data definition to this metadata object. * * @param td * The data definition. It can be a {@link DatabaseRelationDefinition} or a * {@link ParserViewDefinition} object. */ protected <T extends RelationDefinition> void add(T td, Map<RelationID, T> schema) { if (!isStillMutable) { throw new IllegalStateException("Too late, cannot add a schema"); } schema.put(td.getID(), td); if (td.getID().hasSchema()) { RelationID noSchemaID = td.getID().getSchemalessID(); if (!schema.containsKey(noSchemaID)) { schema.put(noSchemaID, td); } else { LOGGER.warn("DUPLICATE TABLE NAMES, USE QUALIFIED NAMES:\n" + td + "\nAND\n" + schema.get(noSchemaID)); //schema.remove(noSchemaID); // TODO (ROMAN 8 Oct 2015): think of a better way of resolving ambiguities } } }
@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(); } }
/** * Inserts a new data definition to this metadata object. * * @param td * The data definition. It can be a {@link DatabaseRelationDefinition} or a * {@link ParserViewDefinition} object. */ protected <T extends RelationDefinition> void add(T td, Map<RelationID, T> schema) { if (!isStillMutable) { throw new IllegalStateException("Too late, cannot add a schema"); } schema.put(td.getID(), td); if (td.getID().hasSchema()) { RelationID noSchemaID = td.getID().getSchemalessID(); if (!schema.containsKey(noSchemaID)) { schema.put(noSchemaID, td); } else { LOGGER.warn("DUPLICATE TABLE NAMES, USE QUALIFIED NAMES:\n" + td + "\nAND\n" + schema.get(noSchemaID)); //schema.remove(noSchemaID); // TODO (ROMAN 8 Oct 2015): think of a better way of resolving ambiguities } } }
private String generateSQLString(RelationDefinition table) { StringBuilder sb = new StringBuilder("select"); boolean needComma = false; for (Attribute attr : table.getAttributes()) { if (needComma) { sb.append(","); } sb.append(" "); sb.append(attr.getID()); needComma = true; } sb.append(" "); sb.append("from"); sb.append(" "); sb.append(table.getID()); return sb.toString(); }
private static String extractPredicateName(RelationDefinition r) { RelationID id = r.getID(); String name = id.getSchemaName(); if (name == null) name = id.getTableName(); else name = name + "." + id.getTableName(); return name; }
private static String extractPredicateName(RelationDefinition r) { RelationID id = r.getID(); String name = id.getSchemaName(); if (name == null) name = id.getTableName(); else name = name + "." + id.getTableName(); return 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; }
if (def != null) { if (def instanceof DatabaseRelationDefinition) { return sqladapter.sqlTableName(dataDefinitions.get(atom).getID().getSQLRendering(), viewNames.get(atom).getSQLRendering());
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(); }
relationAlias, relation instanceof DatabaseRelationDefinition ? relation.getID().getSQLRendering() : inBrackets(((ParserViewDefinition)relation).getStatement()), relation.getAttributes().stream()
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); }
/** * 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()); }
return; } else { RelationID viewId = def.getID(); viewNames.put(atom, viewId); relationId = viewId;
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); }
/** * 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())); }