Package de.fuberlin.wiwiss.d2rq.algebra

Examples of de.fuberlin.wiwiss.d2rq.algebra.RelationName


    }
    this.out.println("\t.");
  }

  public void writeForeignKey(Join foreignKey) {
    RelationName primaryTable = schema.getCorrectCapitalization(foreignKey.table1());
    List<Attribute> primaryColumns = foreignKey.attributes1();
    RelationName foreignTable = schema.getCorrectCapitalization(foreignKey.table2());
    this.out.println(propertyBridgeIRITurtle(primaryColumns, "ref") + " a d2rq:PropertyBridge;");
    this.out.println("\td2rq:belongsToClassMap " + classMapIRITurtle(primaryTable) + ";");
    this.out.println("\td2rq:property " + vocabularyIRITurtle(primaryColumns) + ";");
    this.out.println("\td2rq:refersToClassMap " + classMapIRITurtle(foreignTable) + ";");
    AliasMap alias = AliasMap.NO_ALIASES;
    // Same-table join? Then we need to set up an alias for the table and join to that
    if (foreignKey.isSameTable()) {
      String aliasName = foreignTable.qualifiedName().replace('.', '_') + "__alias";
      this.out.println("\td2rq:alias \"" + foreignTable.qualifiedName() + " AS " + aliasName + "\";");
      alias = AliasMap.create1(foreignTable, new RelationName(null, aliasName));
    }
    for (Attribute column: primaryColumns) {
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[foreignKey.joinDirection()] + " " +
          alias.applyTo(foreignKey.equalAttribute(column)).qualifiedName() + "\";");
    }
View Full Code Here


        !filter.matchesAll(join2.attributes1()) || !filter.matchesAll(join2.attributes2())) {
      log.info("Skipping link table " + linkTableName);
      return;
    }
    log.info("Generating d2rq:PropertyBridge instance for table " + linkTableName.qualifiedName());
    RelationName table1 = this.schema.getCorrectCapitalization(join1.table2());
    RelationName table2 = this.schema.getCorrectCapitalization(join2.table2());
    boolean isSelfJoin = table1.equals(table2);
    this.out.println("# Table " + linkTableName + (isSelfJoin ? " (n:m self-join)" : " (n:m)"));
    this.out.println(propertyBridgeIRITurtle(linkTableName, "link") + " a d2rq:PropertyBridge;");
    this.out.println("\td2rq:belongsToClassMap " + classMapIRITurtle(table1) + ";");
    this.out.println("\td2rq:property " + vocabularyIRITurtle(linkTableName) + ";");
    this.out.println("\td2rq:refersToClassMap " + classMapIRITurtle(table2) + ";");
    for (Attribute column: join1.attributes1()) {
      Attribute otherColumn = join1.equalAttribute(column);
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join1.joinDirection()] + " " + otherColumn.qualifiedName() + "\";");
    }
    AliasMap alias = AliasMap.NO_ALIASES;
    if (isSelfJoin) {
      RelationName aliasName = new RelationName(
          null, table2.tableName() + "_" + linkTableName.tableName() + "__alias");
      alias = AliasMap.create1(table2, aliasName);
      this.out.println("\td2rq:alias \"" + table2.qualifiedName() +
          " AS " + aliasName.qualifiedName() + "\";");
    }
    for (Attribute column: join2.attributes1()) {
      Attribute otherColumn = join2.equalAttribute(column);
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join2.joinDirection()] + " " + alias.applyTo(otherColumn).qualifiedName() + "\";");
    }
View Full Code Here

      Map<String,ForeignKey> fks = new HashMap<String,ForeignKey>();
      ResultSet rs = (direction == KEYS_IMPORTED
          ? this.schema.getImportedKeys(null, schemaName(tableName), tableName(tableName))
          : this.schema.getExportedKeys(null, schemaName(tableName), tableName(tableName)));
      while (rs.next()) {
        RelationName pkTable = toRelationName(
            rs.getString("PKTABLE_SCHEM"), rs.getString("PKTABLE_NAME"));
        Attribute primaryColumn = new Attribute(pkTable, rs.getString("PKCOLUMN_NAME"));
        RelationName fkTable = toRelationName(
            rs.getString("FKTABLE_SCHEM"), rs.getString("FKTABLE_NAME"));
        Attribute foreignColumn = new Attribute(fkTable, rs.getString("FKCOLUMN_NAME"));
        String fkName = rs.getString("FK_NAME");
        if (!fks.containsKey(fkName)) {
          fks.put(fkName, new ForeignKey());
View Full Code Here

  }

  private RelationName toRelationName(String schema, String table) {
    if (schema == null) {
      // Table without schema
      return new RelationName(null, table, db.lowerCaseTableNames());
    } else if ((db.vendor() == Vendor.PostgreSQL || db.vendor() == Vendor.HSQLDB)
        && "public".equals(schema.toLowerCase())) {
      // Call the tables in PostgreSQL or HSQLDB default schema "FOO", not "PUBLIC.FOO"
      return new RelationName(null, table, db.lowerCaseTableNames());
    }
    return new RelationName(schema, table, db.lowerCaseTableNames());
  }
View Full Code Here

    if (!relationName.caseUnspecified() || !db.lowerCaseTableNames())
      return relationName;
   
    Iterator<RelationName> it = listTableNames(null).iterator();
    while (it.hasNext()) {
      RelationName r = it.next();
      if (r.equals(relationName))
        return r;
    }
    return null;
  }
View Full Code Here

    if (!match.matches()) {
      throw new D2RQException("Relation name \"" + qualifiedName +
          "\" is not in \"[schema.]table\" notation",
          D2RQException.SQL_INVALID_RELATIONNAME);
    }
    return new RelationName(match.group(1), match.group(2));
  }
View Full Code Here

  private final static Alias fooAsBar = new Alias(
      new RelationName(null, "foo"),
      new RelationName(null, "bar"));
 
  public void testParseRelationNameNoSchema() {
    RelationName r = SQL.parseRelationName("table");
    assertEquals("table", r.tableName());
    assertNull(r.schemaName());
  }
View Full Code Here

    assertEquals("table", r.tableName());
    assertNull(r.schemaName());
  }
 
  public void testParseRelationNameWithSchema() {
    RelationName r = SQL.parseRelationName("schema.table");
    assertEquals("table", r.tableName());
    assertEquals("schema", r.schemaName());
  }
View Full Code Here

    assertEquals(new HashSet<Attribute>(Arrays.asList(new Attribute[]{foo_col1})),
        SQL.findColumnsInExpression("FUNC('mustnot.match', foo.col1, 'must.not.match')"));
  }
 
  public void testReplaceColumnsInExpressionWithAliasMap() {
    Alias alias = new Alias(new RelationName(null, "foo"), new RelationName(null, "bar"));
    AliasMap fooAsBar = new AliasMap(Collections.singleton(alias));
    assertEquals("bar.col1",
        SQL.replaceColumnsInExpression("foo.col1", fooAsBar));
    assertEquals("LEN(bar.col1) > 0",
        SQL.replaceColumnsInExpression("LEN(foo.col1) > 0", fooAsBar));
View Full Code Here

    assertEquals("ofoo.col1",
        SQL.replaceColumnsInExpression("ofoo.col1", fooAsBar));
  }
 
  public void testReplaceColumnsWithSchemaInExpressionWithAliasMap() {
    Alias alias = new Alias(new RelationName("schema", "foo"), new RelationName("schema", "bar"));
    AliasMap fooAsBar = new AliasMap(Collections.singleton(alias));
    assertEquals("schema.bar.col1",
        SQL.replaceColumnsInExpression("schema.foo.col1", fooAsBar));
  }
View Full Code Here

TOP

Related Classes of de.fuberlin.wiwiss.d2rq.algebra.RelationName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.