/** * * 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()); }
/** * 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; }
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; }
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; }
/** * * table IRI: * the relative IRI consisting of the percent-encoded form of the table name. * * @return table IRI */ private IRI getTableIRI(RelationID tableId) { return rdfFactory.createIRI(baseIRI + R2RMLIRISafeEncoder.encode(tableId.getTableName())); }
/** * Retrieves the primary key for the table * */ private static void getPrimaryKey(DatabaseMetaData md, DatabaseRelationDefinition relation, QuotedIDFactory idfac) throws SQLException { RelationID id = relation.getID(); // Retrieves a description of the given table's primary key columns. They are ordered by COLUMN_NAME (sic!) try (ResultSet rs = md.getPrimaryKeys(null, id.getSchemaName(), id.getTableName())) { extractPrimaryKey(relation, idfac, id, rs); } catch (SQLSyntaxErrorException e) { // WORKAROUND for MySQL connector >= 8.0: // <https://github.com/ontop/ontop/issues/270> try (ResultSet rs = md.getPrimaryKeys(id.getSchemaName(), null, id.getTableName())) { extractPrimaryKey(relation, idfac, id, rs); } } }
/** * Retrieves the unique attributes(s) * @param md * @return * @throws SQLException */ private static void getUniqueAttributes(DatabaseMetaData md, DatabaseRelationDefinition relation, QuotedIDFactory idfac) throws SQLException { RelationID id = relation.getID(); // extracting unique try (ResultSet rs = md.getIndexInfo(null, id.getSchemaName(), id.getTableName(), true, true)) { extractUniqueAttributes(relation, idfac, rs); } catch (Exception e){ // Workaround for MySQL-connector >= 8.0 try (ResultSet rs = md.getIndexInfo(id.getSchemaName(),null, id.getTableName(), true, true)) { extractUniqueAttributes(relation, idfac, rs); } } }
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)); }
RelationID id = relation.getID(); try (ResultSet rs = md.getPrimaryKeys(null, id.getSchemaName(), id.getTableName())) { Map<Integer, String> primaryKeyAttributes = new HashMap<>(); String currentName = null;
/** * Retrieves the foreign keys for the table * */ private static void getForeignKeys(DatabaseMetaData md, DatabaseRelationDefinition relation, DBMetadata metadata) throws SQLException { QuotedIDFactory idfac = metadata.getQuotedIDFactory(); RelationID relationId = relation.getID(); try (ResultSet rs = md.getImportedKeys(null, relationId.getSchemaName(), relationId.getTableName())) { extractForeignKeys(relation, metadata, idfac, rs); } catch (Exception ex) { try (ResultSet rs = md.getImportedKeys(relationId.getSchemaName(),null, relationId.getTableName())) { extractForeignKeys(relation, metadata, idfac, rs); } } }
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(); }
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()); }
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())); }