Package org.apache.ws.jaxme.sqls

Examples of org.apache.ws.jaxme.sqls.CombinedConstraint


        return result;
    }
   
    public CombinedConstraint createOrConstraint() {
        ObjectFactory f = getConstrainedStatement().getSQLFactory().getObjectFactory();
        CombinedConstraint result = f.newCombinedConstraint(getConstrainedStatement(),
                CombinedConstraint.Type.OR);
        parts.add(result);
        return result;
    }
View Full Code Here


        return parts.iterator();
    }
   
    public void addConstraint(Map pMap, Constraint pConstraint) {
        if (pConstraint instanceof CombinedConstraint) {
            CombinedConstraint source = (CombinedConstraint) pConstraint;
            CombinedConstraint target;
            if (source.getType().equals(getType())) {
                target = this;
            } else if (source.getType().equals(CombinedConstraint.Type.AND)) {
                target = createAndConstraint();
            } else if (source.getType().equals(CombinedConstraint.Type.OR)) {
                target = createOrConstraint();
            } else {
                throw new IllegalStateException("Unknown combined constraint type: " +
                        source.getType());
            }
            for (Iterator iter = source.getParts();  iter.hasNext()) {
                Object o = iter.next();
                if (o instanceof CombinedConstraint) {
                    target.addConstraint(pMap, (CombinedConstraint) o);
                } else if (o instanceof BooleanConstraint) {
                    target.addConstraint(pMap, (BooleanConstraint) o);
                } else {
                    throw new IllegalArgumentException("Invalid part: " + o.getClass().getName());
                }
            }
        } else if (pConstraint instanceof BooleanConstraint) {
            BooleanConstraint source = (BooleanConstraint) pConstraint;
            BooleanConstraint target;
            BooleanConstraint.Type sourceType = source.getType();
            if (BooleanConstraint.Type.EQ.equals(sourceType)) {
                target = createEQ();
            } else if (BooleanConstraint.Type.NE.equals(sourceType)) {
                target = createNE();
            } else if (BooleanConstraint.Type.GT.equals(sourceType)) {
                target = createGT();
            } else if (BooleanConstraint.Type.LT.equals(sourceType)) {
                target = createLT();
            } else if (BooleanConstraint.Type.GE.equals(sourceType)) {
                target = createGE();
            } else if (BooleanConstraint.Type.LE.equals(sourceType)) {
                target = createLE();
            } else if (BooleanConstraint.Type.LIKE.equals(sourceType)) {
                target = createLIKE();
            else if (BooleanConstraint.Type.ISNULL.equals(sourceType)) {
                target = createISNULL();
            } else if (BooleanConstraint.Type.IN.equals(sourceType)) {
                target = createIN();
            } else {
                throw new IllegalArgumentException("Invalid boolean constraint type: " + sourceType);
            }
            for (Iterator iter = source.getParts();  iter.hasNext()) {
                Object o = iter.next();
                if (o instanceof Value) {
                    target.addPart((Value) o);
                } else if (o instanceof ColumnReference) {
                    ColumnReference colRef = (ColumnReference) o;
                    TableReference tableRef = (TableReference) pMap.get(colRef.getTableReference());
                    if (tableRef == null) {
                        throw new IllegalStateException("Unknown reference to table " + colRef.getTableReference().getTable().getQName());
                    }
                    target.addPart(tableRef.newColumnReference(colRef.getColumn()));
                } else {
                    throw new IllegalStateException("Unknown part type: " + o.getClass().getName());
                }
            }
        } else {
View Full Code Here

        return sb.toString();
    }

    public String getConstraint(Constraint pConstraint) {
        if (pConstraint instanceof CombinedConstraint) {
            CombinedConstraint cc = (CombinedConstraint) pConstraint;
            Statement st = cc.getConstrainedStatement();
            if (st instanceof SelectStatement) {
                SelectStatementMetaData selectStatementMetaData = newSelectStatementMetaData((SelectStatement) st);
                return getCombinedConstraint(selectStatementMetaData, cc);
            } else {
                return getCombinedConstraint(null, cc);
View Full Code Here

        TableReference refLocal = tableReference;
        TableReference refRef = tableReference.getRightJoinedTableReference();
       
        joinReference.getOn().addJoin((ForeignKey) otherTable.getForeignKeys().next(),
                refLocal, refRef);
        CombinedConstraint cc = statement.getWhere();
        BooleanConstraint bc = cc.createEQ();
        bc.addPart(tableReference.newColumnReference("MyIndex"));
        bc.addPlaceholder();
        return statement;
    }
View Full Code Here

        TableReference refLocal = tableReference;
        TableReference refRef = tableReference.getRightJoinedTableReference();
       
        joinReference.getOn().addJoin((ForeignKey) otherTable.getForeignKeys().next(),
                refLocal, refRef);
        CombinedConstraint cc = statement.getWhere();
        BooleanConstraint bc = cc.createEQ();
        bc.addPart(tableReference.newColumnReference("MyIndex"));
        bc.addPlaceholder();
       
        SQLGenerator generator = getSQLGenerator();
        generator.setLineTerminator("\n");
View Full Code Here

    public void testNOT() {
        Table table = getBasicTable();
        SelectStatement selectStatement = table.getSelectStatement();
        SelectTableReference ref = selectStatement.getSelectTableReference();
        CombinedConstraint and = selectStatement.getWhere();
        BooleanConstraint bc = and.createLIKE();
        bc.addPart(ref.newColumnReference("MyName"));
        bc.addPart("%a%");
        CombinedConstraint or = and.createOrConstraint();
        or.setNOT(true);
        bc = or.createEQ();
        bc.addPart(ref.newColumnReference("MyIndex"));
        bc.addPart(1);
        SQLGenerator gen = getSQLGenerator();
        String query = gen.getQuery(selectStatement);
        assertEquals("SELECT MyIndex, MyName, MyDate FROM MySchema.MyTable WHERE (MyName LIKE '%a%' AND NOT (MyIndex=1))", query);

        bc = or.createEQ();
        bc.addPart(ref.newColumnReference("MyIndex"));
        bc.addPart(2);
        query = gen.getQuery(selectStatement);
        assertEquals("SELECT MyIndex, MyName, MyDate FROM MySchema.MyTable WHERE (MyName LIKE '%a%' AND (NOT (MyIndex=1 OR MyIndex=2)))", query);
    }
View Full Code Here

    public void testConnectByPrior() {
        Table table = getBasicTable();
        OraSelectStatement selectStatement = (OraSelectStatement) table.getSelectStatement();
        SelectTableReference ref = selectStatement.getSelectTableReference();
        CombinedConstraint startWith = selectStatement.getStartWith();
        BooleanConstraint bc = startWith.createEQ();
        bc.addPart(ref.newColumnReference("MyIndex"));
        bc.addPart(1);
        CombinedConstraint connectByPrior = selectStatement.getConnectBy();
        bc = connectByPrior.createEQ();
        OraColumnReference oraRef = (OraColumnReference) ref.newColumnReference("MyIndex");
        oraRef.setPrior(true);
        bc.addPart(oraRef);
        bc.addPart(ref.newColumnReference("MyName"));
        SQLGenerator gen = getSQLGenerator();
View Full Code Here

        return sb.toString();
    }

    public String getConstraint(Constraint pConstraint) {
        if (pConstraint instanceof CombinedConstraint) {
            CombinedConstraint cc = (CombinedConstraint) pConstraint;
            Statement st = cc.getConstrainedStatement();
            if (st instanceof SelectStatement) {
                StatementMetaData selectStatementMetaData = newStatementMetaData((SelectStatement) st);
                return getCombinedConstraint(selectStatementMetaData, cc);
            } else {
                return getCombinedConstraint(null, cc);
View Full Code Here

        akte.setAlias("a");

        //aktenzeichen joinen
        JoinReference az = akte.join(dbAktenzeichen);
        az.setAlias("az");
        CombinedConstraint onClause = az.getOn();
        BooleanConstraint bc = onClause.createEQ();
        bc.addPart(akte.newColumnReference(dbAkte.getColumn("aId")));
        bc.addPart(az.newColumnReference(dbAktenzeichen.getColumn("aAktenId")));
        bc = onClause.createEQ();
        bc.addPart(az.newColumnReference(dbAktenzeichen.getColumn("aFilter")));
        bc.addPart("Hauptverfahren");

        //beteiligte joinen
        JoinReference kl, be;
View Full Code Here

     */
    private DeleteStatement getDeleteAllChildsByOrganisationsId() {
        DeleteStatement dstmt = sqlFactory.newDeleteStatement();
        dstmt.setTable(kettenElement);
        TableReference tRef  = dstmt.getTableReference();
        CombinedConstraint whereClause = dstmt.getWhere();
        BooleanConstraint bc = whereClause.createIN();
        bc.addPart(tRef.newColumnReference(kettenElement.getColumn("aId")));
        bc.addPart(getSelectAllChildsByOrganisationsId());
        return dstmt;
    }
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.sqls.CombinedConstraint

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.