Package adipe.translate.sql

Examples of adipe.translate.sql.State2


     * @throw TranslationException      when a derived table is parsed with a derived column list of the wrong size
     * TODO update
     */
    final State2 interpret() throws IndexOutOfBoundsException, TranslationException
    {
        State2 st = interpretEtc();
        stores.onVisibleRelations(relationsFound);
        stores.onRelationFormula(st);
        return st;
    }
View Full Code Here


        registerRelation(r.alias(), colNamesWr[0]);
        return makeState2(r, colNamesWr[0].asColumnIndexesLookup(), addQualifiedColumnNames(knownAs == null?primaryName:knownAs, colNamesWr[0]));
    }

    private State2 makeState2(Relation r, ColumnIndexesImpl indexes, ColumnNamesImpl named) {
        return new State2(r, indexes, named, scope.tableScope());
    }
View Full Code Here

            @Override
            public void onRelationFormula(State2 relation) { }
        };

        State2 r1 = TableReferenceTranslation.of(tableReference.get(0), storesForJoin, translates, schema).interpret();
        State2 r2 = TableReferenceTranslation.of(tableReference.get(1), storesForJoin, translates, schema).interpret();

        if (natural != null) {
            throw new RuntimeException("NATURAL JOIN is not supported"); // TODO
        }

        if (joinSpecification == null) {
            // TODO
            throw new RuntimeException("JOIN specification missing");
        }

        boolean isInnerJoin = joinType == null || joinType.INNER() != null;

        ColumnNamesImpl named = new ColumnNamesImpl();
        named.addAll(r1.named().inner());
        named.addAll(r2.named().inner());

        if (! isInnerJoin) {
            r1.overwriteExpand();
            r2.overwriteExpand();
        }

        Proposition p = visitJoinSpecification(joinSpecification, columnNamesLookupForJoin2(r1, r2));

        // TODO move the check inside {@link Proposition} instead of matching like this
        boolean pIsEq;
        String pcode = p.code(columnIndexesForJoin2(r1, r2));
        Matcher eqMatcher = EQ_PATTERN.matcher(pcode);
        pIsEq = eqMatcher.matches();
        if (pIsEq) {
            // TODO refactor
            int index1 = Integer.parseInt(eqMatcher.group(1));
            int index2 = Integer.parseInt(eqMatcher.group(2));
            if (index1 > index2) {
                int tmp = index1;
                index1 = index2;
                index2 = tmp;
            }

            boolean bothColumnsFromSameOperand = (index1 > r1.relation().columns().size() || index2 <= r1.relation().columns().size());
            if (bothColumnsFromSameOperand) {
                pIsEq = false;
            } else if (isInnerJoin) {
                index2 = index2 - r1.relation().columns().size();

                SimpleColumn replacedColumn = r2.relation().columns().get(index2 - 1);
                SimpleColumn replacedBy = r1.relation().columns().get(index1 - 1);
                for (ColumnNamesImpl cibn : relationsFound.values()) {
                    // TODO improve time complexity
                    cibn.replace(replacedColumn, replacedBy);
                }
                named.replace(replacedColumn, replacedBy);
            }
        }

        if (checkContainsSubquery(p)) {
            throw new RuntimeException("not implemented (EXISTS in JOIN condition)");
        }

        Relation rel;
        if (! isInnerJoin) {
            if (joinType.UNION() != null) {
                throw new RuntimeException("UNION JOIN is not supported");// TODO
            } else {
                checkNotNull(joinType.outerJoinType());
                if (joinType.outerJoinType().LEFT() != null) {
                    rel = r1.relation().leftOuterJoin(r2.relation(), pcode, pIsEq);
                } else if (joinType.outerJoinType().RIGHT() != null) {
                    rel = r1.relation().rightOuterJoin(r2.relation(), pcode, pIsEq);
                } else {
                    checkNotNull(joinType.outerJoinType().FULL());
                    rel = r1.relation().fullOuterJoin(r2.relation(), pcode, pIsEq);
                }
            }
        } else {
            rel = r1.relation().join(r2.relation(), pcode, pIsEq);
        }

        return makeState2(rel, rel.columns(), named);
    }
View Full Code Here

     */
    private QueryExpressionTranslation(State state, Schema schema) {
        this.state = state;
        this.tablesRelation = new TablesRelation(this.state.rela);
        this.schema = schema;
        this.state2 = new State2(this.tablesRelation.value, new ColumnIndexesImpl(), this.state.scope.columnScope().asColumnNames(), state.scope.tableScope());
    }
View Full Code Here

TOP

Related Classes of adipe.translate.sql.State2

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.