@Override public String toString() { return getSQLRendering(); }
/** * * table IRI: * the relative IRI consisting of the percent-encoded form of the table name. * * @return table IRI */ private String getTableIRI(RelationID tableId) { return baseIRI + R2RMLIRISafeEncoder.encode(tableId.getTableName()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj instanceof QualifiedAttributeID) { QualifiedAttributeID other = (QualifiedAttributeID)obj; return (this.attribute.equals(other.attribute) && ((this.relation == other.relation) || ((this.relation != null) && this.relation.equals(other.relation)))); } return false; }
@Override public DatabaseRelationDefinition getDatabaseRelation(RelationID id) { DatabaseRelationDefinition def = tables.get(id); if (def == null && id.hasSchema()) { def = tables.get(id.getSchemalessID()); } return def; }
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; }
/** * Retrieve the normalized list of tables from a given list of RelationIDs */ private static List<RelationID> getTableList(String defaultTableSchema, Set<RelationID> realTables, QuotedIDFactory idfac) throws SQLException { List<RelationID> fks = new LinkedList<>(); for (RelationID table : realTables) { // defaultTableSchema is non-empty only for Oracle and DUAL is a special Oracle table if (table.hasSchema() || (defaultTableSchema == null) || table.getTableName().equals("DUAL")) fks.add(table); else { RelationID qualifiedTableId = idfac.createRelationID(defaultTableSchema, table.getTableNameSQLRendering()); fks.add(qualifiedTableId); } } return fks; }
RelationID id = relation.getID(); try (ResultSet rs = md.getPrimaryKeys(null, id.getSchemaName(), id.getTableName())) { Map<Integer, String> primaryKeyAttributes = new HashMap<>(); String currentName = null; while (rs.next()) { RelationID id2 = RelationID.createRelationIdFromDatabaseRecord(idfac, rs.getString("TABLE_SCHEM"), rs.getString("TABLE_NAME")); if (id2.equals(id)) { currentName = rs.getString("PK_NAME"); // may be null String attr = rs.getString("COLUMN_NAME");
try (ResultSet rs = md.getImportedKeys(null, relationId.getSchemaName(), relationId.getTableName())) { ForeignKeyConstraint.Builder builder = null; String currentName = null; while (rs.next()) { RelationID refId = RelationID.createRelationIdFromDatabaseRecord(idfac, rs.getString("PKTABLE_SCHEM"), rs.getString("PKTABLE_NAME")); DatabaseRelationDefinition ref = metadata.getDatabaseRelation(refId);
String table = relationId.getTableName(); if (relationId.getTableName().startsWith("QVIEW")) { Map<Function, RelationID> views = index.viewNames; for (Function func : views.keySet()) { RelationID knownViewId = views.get(func); if (knownViewId.equals(relationId)) { table = func.getFunctionSymbol().toString(); break; if (tabledef.getID().getTableName().equals(table)) { List<Attribute> attr = tabledef.getAttributes(); for (Attribute a : attr) {
relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) attrs = RAExpressionAttributes.create(attributes.build(), alias, relation.getID().getSchemalessID()); else attrs = RAExpressionAttributes.create(attributes.build(), alias);
private static void extractPrimaryKey(DatabaseRelationDefinition relation, QuotedIDFactory idfac, RelationID id, ResultSet rs) throws SQLException { Map<Integer, String> primaryKeyAttributes = new HashMap<>(); String currentName = null; while (rs.next()) { // TABLE_CAT is ignored for now; assume here that relation has a fully specified name RelationID id2 = RelationID.createRelationIdFromDatabaseRecord(idfac, rs.getString("TABLE_SCHEM"), rs.getString("TABLE_NAME")); if (id2.equals(id)) { currentName = rs.getString("PK_NAME"); // may be null String attr = rs.getString("COLUMN_NAME"); int seq = rs.getShort("KEY_SEQ"); primaryKeyAttributes.put(seq, attr); } } if (!primaryKeyAttributes.isEmpty()) { // use the KEY_SEQ values to restore the correct order of attributes in the PK UniqueConstraint.Builder builder = UniqueConstraint.builder(relation); for (int i = 1; i <= primaryKeyAttributes.size(); i++) { QuotedID attrId = QuotedID.createIdFromDatabaseRecord(idfac, primaryKeyAttributes.get(i)); builder.add(relation.getAttribute(attrId)); } relation.addUniqueConstraint(builder.build(currentName, true)); } }
/** * * @return the relation ID that has the same name but no schema name */ public RelationID getSchemalessID() { return new RelationID(QuotedID.EMPTY_ID, table); }
@Override public RelationID getTableID(ResultSet rs) throws SQLException { return RelationID.createRelationIdFromDatabaseRecord(idfac, defaultTableOwner, rs.getString("object_name")); } };
try (ResultSet rs = md.getColumns(null, seedId.getSchemaName(), seedId.getTableName(), null)) { while (rs.next()) { String schema = rs.getString("TABLE_SCHEM"); schema = rs.getString("TABLE_CAT"); RelationID relationId = RelationID.createRelationIdFromDatabaseRecord(idfac, schema, rs.getString("TABLE_NAME")); QuotedID attributeId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("COLUMN_NAME")); System.out.println(" " + relationId + "." + attributeId); if (currentRelation == null || !currentRelation.getID().equals(relationId)) {
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; }
/** * Retrieve the normalized list of tables from a given list of RelationIDs */ private static List<RelationID> getTableList(String defaultTableSchema, Set<RelationID> realTables, QuotedIDFactory idfac) throws SQLException { List<RelationID> fks = new LinkedList<>(); for (RelationID table : realTables) { // defaultTableSchema is non-empty only for Oracle and DUAL is a special Oracle table if (table.hasSchema() || (defaultTableSchema == null) || table.getTableName().equals("DUAL")) fks.add(table); else { RelationID qualifiedTableId = idfac.createRelationID(defaultTableSchema, table.getTableNameSQLRendering()); fks.add(qualifiedTableId); } } return fks; }
relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) attrs = RAExpressionAttributes.create(attributes.build(), alias, relation.getID().getSchemalessID()); else attrs = RAExpressionAttributes.create(attributes.build(), alias);
@Override public DatabaseRelationDefinition getDatabaseRelation(RelationID id) { DatabaseRelationDefinition def = tables.get(id); if (def == null && id.hasSchema()) { def = tables.get(id.getSchemalessID()); } return def; }
/** * * @return the relation ID that has the same name but no schema name */ public RelationID getSchemalessID() { return new RelationID(QuotedID.EMPTY_ID, table); }
@Override public RelationID getTableID(ResultSet rs) throws SQLException { return RelationID.createRelationIdFromDatabaseRecord(idfac, defaultTableOwner, rs.getString("object_name")); } };