Package org.apache.metamodel.schema

Examples of org.apache.metamodel.schema.Relationship


        assertEquals("datacleaner", tableModel.getValueAt(0, 2));
        assertEquals("MetaModel", tableModel.getValueAt(1, 2));

        // Make a new query that joins the normalized tables together
        table = schema.getTableByName("contributors_person_address");
        Relationship relationShip = table.getRelationships()[0];
        q = new Query().select(relationShip.getPrimaryTable().getColumns())
                .select(relationShip.getForeignTable().getColumns()).from(new FromItem(JoinType.INNER, relationShip));

        assertEquals(
                "SELECT contributors_person.id, contributors_person_address.id, "
                        + "contributors_person_address.contributors_person_id, contributors_person_address.address "
                        + "FROM xml_input_eobjects.xml.contributors_person INNER JOIN xml_input_eobjects.xml.contributors_person_address "
View Full Code Here


                .materializeMainSchemaTable(dependencyTable, dependencyTable.getColumns(), -1).toObjectArrays();
        assertEquals(11, dependencyData.size());
        assertEquals("[1]", Arrays.toString(dependencyData.get(0)));
        assertEquals("[11]", Arrays.toString(dependencyData.get(10)));

        Relationship relationship = schema.getTableByName("dependency_groupId").getRelationships()[0];
        assertEquals(
                "Relationship[primaryTable=dependency,primaryColumns=[id],foreignTable=dependency_groupId,foreignColumns=[dependency_id]]",
                relationship.toString());

        dc.flattenTables(relationship);

        assertEquals("[Table[name=dependency,type=TABLE,remarks=null], "
                + "Table[name=dependency_artifactId,type=TABLE,remarks=null], "
View Full Code Here

        assertTrue(dataSet.next());
        assertEquals("Row[values=[project_contributor, VIEW, 3, null]]", dataSet.getRow().toString());
        assertFalse(dataSet.next());
        dataSet.close();

        Relationship relationship = tablesTable.getRelationships(columnsTable)[0];
        FromItem joinFromItem = new FromItem(JoinType.INNER, relationship);
        Query q = new Query().select(tablesTable.getColumnByName("name")).select(columnsTable.getColumnByName("name"))
                .select(columnsTable.getBooleanColumns()).from(joinFromItem);

        assertEquals("SELECT tables.name, columns.name, columns.nullable, columns.indexed "
View Full Code Here

            return;
        }
        Schema schema = getDataContext().getSchemaByName("HR");
        Table employeeTable = schema.getTableByName("EMPLOYEES");
        Table departmentsTable = schema.getTableByName("DEPARTMENTS");
        Relationship relationship = employeeTable.getRelationships(departmentsTable)[0];
        assertEquals(
                "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}]",
                relationship.toString());

        Query q = new Query().from(new FromItem(JoinType.INNER, relationship)).select(
                employeeTable.getColumnByName("EMAIL"), departmentsTable.getColumnByName("DEPARTMENT_NAME"));
        q.getSelectClause().getItem(0).setAlias("e-mail");
View Full Code Here

    Connection con = getTestDbConnection();
    DataContext dc = new JdbcDataContext(con);
    Schema schema = dc.getDefaultSchema();
    Table productsTable = schema.getTableByName("PRODUCTS");
    Relationship[] relationships = productsTable.getRelationships();
    Relationship relationship = relationships[0];
    assertEquals(
        "Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]",
        relationship.toString());

    Query q = new Query().from(new FromItem(JoinType.LEFT, relationship))
        .select(relationship.getForeignColumns())
        .select(relationship.getPrimaryColumns());
    assertEquals(
        "SELECT _ORDERFACT_._PRODUCTCODE_, _PRODUCTS_._PRODUCTCODE_ FROM PUBLIC._PRODUCTS_ LEFT JOIN PUBLIC._ORDERFACT_ ON _PRODUCTS_._PRODUCTCODE_ = _ORDERFACT_._PRODUCTCODE_",
        q.toString().replace('\"', '_'));

    QuerySplitter qs = new QuerySplitter(dc, q);
View Full Code Here

            // flattened in a previous loop)
            if (_tableData.containsKey(table.getName())) {
                // Find all tables that represent inner tags
                Relationship[] foreignKeyRelationships = table.getForeignKeyRelationships();
                if (foreignKeyRelationships.length == 1 && table.getPrimaryKeyRelationships().length == 0) {
                    Relationship foreignKeyRelationship = foreignKeyRelationships[0];

                    // If there is exactly one inner tag then we can probably
                    // flatten the tables, but it's only relevant if the inner
                    // tag only carry a single data column
                    int nonDataColumns = 0;
                    Column[] columns = table.getColumns();
                    for (Column column : columns) {
                        String nativeType = column.getNativeType();
                        // Use the native column type constants to determine if
                        // the column is an artificial column
                        if (NATIVE_TYPE_FOREIGN_KEY.equals(nativeType) || NATIVE_TYPE_PRIMARY_KEY.equals(nativeType)) {
                            nonDataColumns++;
                        }
                    }

                    if (columns.length == nonDataColumns + 1) {
                        // If the foreign key is unique for all rows, we will
                        // flatten it (otherwise it means that multiple inner
                        // tags occur, which requires two tables to deal with
                        // multiplicity)
                        boolean uniqueForeignKeys = true;

                        Column[] foreignColumns = foreignKeyRelationship.getForeignColumns();

                        SelectItem countAllItem = SelectItem.getCountAllItem();
                        Query q = new Query().select(foreignColumns).select(countAllItem).from(table).groupBy(foreignColumns);
                        DataSet data = executeQuery(q);
                        Comparable<Object> comparable = NumberComparator.getComparable(1);
View Full Code Here

            // flattened in a previous loop)
            if (_tableData.containsKey(table.getName())) {
                // Find all tables that represent inner tags
                Relationship[] foreignKeyRelationships = table.getForeignKeyRelationships();
                if (foreignKeyRelationships.length == 1 && table.getPrimaryKeyRelationships().length == 0) {
                    Relationship foreignKeyRelationship = foreignKeyRelationships[0];

                    // If there is exactly one inner tag then we can probably
                    // flatten the tables, but it's only relevant if the inner
                    // tag only carry a single data column
                    int nonDataColumns = 0;
                    Column[] columns = table.getColumns();
                    for (Column column : columns) {
                        String nativeType = column.getNativeType();
                        // Use the native column type constants to determine if
                        // the column is an artificial column
                        if (NATIVE_TYPE_FOREIGN_KEY.equals(nativeType) || NATIVE_TYPE_PRIMARY_KEY.equals(nativeType)) {
                            nonDataColumns++;
                        }
                    }

                    if (columns.length == nonDataColumns + 1) {
                        // If the foreign key is unique for all rows, we will
                        // flatten it (otherwise it means that multiple inner
                        // tags occur, which requires two tables to deal with
                        // multiplicity)
                        boolean uniqueForeignKeys = true;

                        Column[] foreignColumns = foreignKeyRelationship.getForeignColumns();

                        SelectItem countAllItem = SelectItem.getCountAllItem();
                        Query q = new Query().select(foreignColumns).select(countAllItem).from(table).groupBy(foreignColumns);
                        DataSet data = executeQuery(q);
                        Comparable<Object> comparable = NumberComparator.getComparable(1);
View Full Code Here

  public void testExecuteQuery() throws Exception {
    Schema schema = _dataContext.getSchemaByName("HR");
    Table employeeTable = schema.getTableByName("EMPLOYEES");
    Table departmentsTable = schema.getTableByName("DEPARTMENTS");
    Relationship relationship = employeeTable
        .getRelationships(departmentsTable)[0];
    assertEquals(
        "Relationship[primaryTable=EMPLOYEES,primaryColumns={EMPLOYEE_ID},foreignTable=DEPARTMENTS,foreignColumns={MANAGER_ID}]",
        relationship.toString());

    Query q = new Query().from(new FromItem(JoinType.INNER, relationship))
        .select(employeeTable.getColumnByName("EMAIL"),
            departmentsTable.getColumnByName("DEPARTMENT_NAME"));
    q.getSelectClause().getItem(0).setAlias("e-mail");
View Full Code Here

    assertEquals("datacleaner", tableModel.getValueAt(0, 2));
    assertEquals("MetaModel", tableModel.getValueAt(1, 2));

    // Make a new query that joins the normalized tables together
    table = schema.getTableByName("contributors_person_address");
    Relationship relationShip = table.getRelationships()[0];
    q = new Query().select(relationShip.getPrimaryTable().getColumns())
        .select(relationShip.getForeignTable().getColumns())
        .from(new FromItem(JoinType.INNER, relationShip));

    assertEquals(
        "SELECT contributors_person.id, contributors_person_address.id, "
            + "contributors_person_address.contributors_person_id, contributors_person_address.address "
View Full Code Here

        .toObjectArrays();
    assertEquals(11, dependencyData.size());
    assertEquals("[1]", Arrays.toString(dependencyData.get(0)));
    assertEquals("[11]", Arrays.toString(dependencyData.get(10)));

    Relationship relationship = schema.getTableByName("dependency_groupId")
        .getRelationships()[0];
    assertEquals(
        "Relationship[primaryTable=dependency,primaryColumns=[id],foreignTable=dependency_groupId,foreignColumns=[dependency_id]]",
        relationship.toString());

    dc.flattenTables(relationship);

    assertEquals("[Table[name=dependency,type=TABLE,remarks=null], "
        + "Table[name=dependency_artifactId,type=TABLE,remarks=null], "
View Full Code Here

TOP

Related Classes of org.apache.metamodel.schema.Relationship

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.