Package org.apache.metamodel.query

Examples of org.apache.metamodel.query.FromItem


    }

    protected String createSqlStatement() {
        StringBuilder sb = new StringBuilder();
        sb.append("DELETE FROM ");
        sb.append(_queryRewriter.rewriteFromItem(new FromItem(getTable())));
        sb.append(JdbcUtils.createWhereClause(getWhereItems(), _queryRewriter, _inlineValues));
        return sb.toString();
    }
View Full Code Here


    private String createSqlStatement(boolean inlineValues) {
        final Object[] values = getValues();
        final Table table = getTable();
        final StringBuilder sb = new StringBuilder();

        final String tableLabel = _queryRewriter.rewriteFromItem(new FromItem(table));

        sb.append("UPDATE ");
        sb.append(tableLabel);
        sb.append(" SET ");
View Full Code Here

        Schema schema = getExampleSchema();
        Table contributorTable = schema.getTableByName(TABLE_CONTRIBUTOR);
        Table projectTable = schema.getTableByName(TABLE_PROJECT);
        Table projectContributorTable = schema.getTableByName(TABLE_PROJECT_CONTRIBUTOR);

        FromItem sqFromItem = new FromItem(new Query().from(projectTable).from(projectContributorTable));
        FromItem fromItem = new FromItem(JoinType.INNER, new FromItem(contributorTable), sqFromItem, new SelectItem[0],
                new SelectItem[0]);
        Query q = new Query().from(fromItem);

        FromItem[] fromItems = MetaModelHelper.getTableFromItems(q);
        assertEquals(3, fromItems.length);
View Full Code Here

        }
    JdbcDataContext dataContext = getDataContext();
        Schema schema = dataContext.getDefaultSchema();
    Table departmentTable = schema.getTableByName("DEPARTMENT");
    Table employeeTable = schema.getTableByName("EMPLOYEE");
    Query q = new Query().from(new FromItem(JoinType.INNER, departmentTable.getRelationships(employeeTable)[0]));
    q.select(departmentTable.getColumns()[1]);
    q.select(new SelectItem(employeeTable.getColumns()[4]).setAlias("hire-date"));
    assertEquals(
        "SELECT \"DEPARTMENT\".\"DEPARTMENT\", \"EMPLOYEE\".\"HIRE_DATE\" AS hire-date FROM \"EMPLOYEE\" INNER JOIN \"DEPARTMENT\" ON \"EMPLOYEE\".\"EMP_NO\" = \"DEPARTMENT\".\"MNGR_NO\"",
        q.toString());
View Full Code Here

        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");

        assertEquals(
                "SELECT \"EMPLOYEES\".\"EMAIL\" AS e-mail, \"DEPARTMENTS\".\"DEPARTMENT_NAME\" FROM HR.\"EMPLOYEES\" INNER JOIN HR.\"DEPARTMENTS\" ON \"EMPLOYEES\".\"EMPLOYEE_ID\" = \"DEPARTMENTS\".\"MANAGER_ID\"",
View Full Code Here

    private FromItem fromItem;

    public TableFromBuilderImpl(Table table, Query query, DataContext dataContext) {
        super(query, dataContext);

        fromItem = new FromItem(table);
        query.from(fromItem);
    }
View Full Code Here

        JdbcDataContext dc = new JdbcDataContext(_connection);
        Schema schema = dc.getDefaultSchema();
        Table productsTable = schema.getTableByName("PRODUCTS");
        Table factTable = schema.getTableByName("ORDERFACT");

        Query q = new Query().from(new FromItem(JoinType.INNER, productsTable.getRelationships(factTable)[0])).select(
                productsTable.getColumns()[0], factTable.getColumns()[0]);
        assertEquals(
                "SELECT \"PRODUCTS\".\"PRODUCTCODE\", \"ORDERFACT\".\"ORDERNUMBER\" FROM PUBLIC.\"PRODUCTS\" INNER JOIN PUBLIC.\"ORDERFACT\" ON \"PRODUCTS\".\"PRODUCTCODE\" = \"ORDERFACT\".\"PRODUCTCODE\"",
                q.toString());
        assertEquals(25000, dc.getFetchSizeCalculator().getFetchSize(q));
View Full Code Here

    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('\"', '_'));
View Full Code Here

    sq.select(empSelectItem, custSelectItem);
    assertEquals(
        "SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c",
        sq.toString().replace('\"', '_'));
    Query q = new Query();
    FromItem sqItem = new FromItem(sq).setAlias("sq");

    custSelectItem.setAlias("c_num");
    empSelectItem.setAlias("e_num");

    q.from(sqItem);
View Full Code Here

        }

        Query q = new Query();
        q.select(primaryColumns.toArray(new Column[primaryColumns.size()]));
        q.select(foreignColumns.toArray(new Column[foreignColumns.size()]));
        q.from(new FromItem(JoinType.LEFT, relationship));
        if (logger.isDebugEnabled()) {
            logger.debug("Setting table data for '{}' to query result: {}", primaryTableName, q.toString());
        }
        List<Object[]> tableRows = executeQuery(q).toObjectArrays();
View Full Code Here

TOP

Related Classes of org.apache.metamodel.query.FromItem

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.