Package org.objectweb.medor.api

Examples of org.objectweb.medor.api.Field


    /**
     * Add the prefetch field to the current query tree
     * @param qd is the definition of the query
     */
    private void addPrefetchField(JDOQueryDefinitionImpl qd) throws MedorException {
        Field f = ((PropagatedField) selectfields.get(0)).getOriginFields()[0];
        if (f instanceof PNameField) {
            PNameField pnf = (PNameField) f;
            if (pnf.isClassPName() && !pnf.isInGenClass()) {
                //Add prefeched fields
                ClassExtent ce = (ClassExtent) pnf.getQueryTree();
View Full Code Here


    private Nest addAggregateNode() throws SpeedoException, MedorException {
        Map old2newFields = new HashMap();
        //project used fields on the QueryNode #top
        for (int i = 0; i < usedFields.size(); i++) {
            QueryTreeField qtf = (QueryTreeField) usedFields.get(i);
            Field newf = top.addPropagatedField(qtf.getName(), qtf
                        .getType(), new QueryTreeField[] { qtf });
                old2newFields.put(qtf, newf);
        }
        //replace the use of old fields in 'grouped' by the new projected
        replaceFieldsInList(groupedFields, old2newFields);
View Full Code Here

    private void projectFields()
      throws SpeedoException, MedorException, ExpressionException {
        //project field on the #top query node
        for (int i = 0; i < selectfields.size(); i++) {
            Object o = selectfields.get(i);
            Field fieldOnTop = null;
            String fieldName = (String) aliases.get(i);
            if (o instanceof Expression) {
                if (fieldName == null || fieldName.length() == 0) {
                    fieldName = "field_" + i;
                }
                Expression e = (Expression) o;
                e.compileExpression();
                fieldOnTop = top.addCalculatedField(fieldName, e.getType(), e);
            } else if (o instanceof Field) {
                Field f = (Field) o;
                if (fieldName == null || fieldName.length() == 0) {
                    fieldName = f.getName();
                }
                if (!groupByFields.contains(f) || (top instanceof Nest)) {
                    fieldOnTop = top.addPropagatedField(fieldName, f.getType(),
                            new QueryTreeField[] { (QueryTreeField) f });
                } else {
                    String fn = top.getName();
                    if (fn == null || fn.length() == 0) {
                        fn = "";
                    } else {
                        fn += ".";
                    }
                    fn += f.getName();
                    fieldOnTop = top.getTupleStructure().getField(fn);
                }
            }
            //Compute the field type
            selectFieldTypes.add(getFieldClass(fieldOnTop));
View Full Code Here

        case PType.TYPECODE_STRING:
            return String.class;

        case PType.TYPECODE_REFERENCE:
            if (field instanceof PropagatedField) {
                Field f = ((PropagatedField) field).getOriginFields()[0];
                if (f instanceof PNameField) {
                    PNameField pnf = (PNameField) f;
                    if (pnf.isClassPName()) {
                        if (pnf.isInGenClass()) {
                            //identifier of the genclass
View Full Code Here

     */
    private void replaceFieldsInExpression(Expression e, Map old2newElement)
            throws SpeedoException {
        if (e instanceof FieldOperand) {
            FieldOperand fo = (FieldOperand) e;
            Field old = fo.getField();
            Field neo = (Field) old2newElement.get(old);
            if (neo != null && old != neo) {
                ((FieldOperand) e).setField(neo);
            }
        } else if (e instanceof Operator) {
            Operator operator = (Operator) e;
View Full Code Here

    private void parseFieldExpression(String token, Stack stack) throws SpeedoException {
        //field expression
        if (token.equals("*")) {
            token = "this";
        }
        Field f = sqvv.getField(token);
        if (!usedFields.contains(f)) {
            usedFields.add(f);
        }
        stack.push(f);
    }
View Full Code Here

        StringTokenizer st = new StringTokenizer(groupby, ",", false);
        while (st.hasMoreTokens()) {
            groupByFields.add(sqvv.getField(st.nextToken().trim()));
        }
        for (int i = 0; i < groupByFields.size(); i++) {
            Field f = (Field) groupByFields.get(i);
            if (!usedFields.contains(f)) {
                usedFields.add(f);
            }
        }
    }
View Full Code Here

     * @param result
     *            is the list to fill with Field used in the expression
     */
    private void getFieldsFromExpression(Expression e, List result) {
        if (e instanceof FieldOperand) {
            Field f = ((FieldOperand) e).getField();
            if (!result.contains(f)) {
                result.add(f);
            }
        } else if (e instanceof Operator) {
            Operator operator = (Operator) e;
View Full Code Here

            if (o instanceof ParameterOperand) {
                //myParam.contains(...)
                if (debug) {
                    logger.log(BasicLevel.DEBUG, tab + "(" +  name + ") InCollection (" + o + ")");
                }
                Field qtf =  (Field) fields.get(name);
                Expression e = new InCollection(
                        new BasicFieldOperand(qtf),
                        (ParameterOperand) o, qtf.getType());
                stack.push(e);
               
            } else if (o instanceof String) {
                String pathset = (String) o;
                String[] spli = splitPath(pathset);
                if (vars.containsKey(splitted[0])) {
                    //x.y.bs.contains(b)
                    //The variable definition is managed by the Variable visitor
                    //thus forget the expression
                    if ((nbNot % 2) == 0) {
                        stack.push(REMOVER);
                    } else {
                        QueryTreeField f = (QueryTreeField) fields.get(name);
                      stack.push(new Not(new IsEmpty(new BasicFieldOperand(f))));
                    }
                } else {
                    //x.y.bs.contains(u.v.b)
                    String rest = mergePath(spli, 1, spli.length - 2);
                    QueryBuilder subquery = new QueryBuilder(qb);
                    subquery.define("", qb.navigate(spli[0]));
                    QueryTreeField setField = subquery.project(subquery.navigate(rest));
                    QueryTreeField f = (QueryTreeField) fields.get(name);

                    stack.push(new MemberOf(
                            Collections.singletonList(
                                    new BasicFieldOperand(f)),
                            Collections.singletonList(
                                    new BasicFieldOperand(setField))
                          ));
                }
            } else {
                if (debug) {
                    logger.log(BasicLevel.DEBUG, tab + "Do not use the pathset of the contain operator");
                }
                stack.push(REMOVER);
            }
            return;
        }

        //maybe there is an operator
        String last = splitted[splitted.length - 1];
        operatorId = isMethodOperator(last);
        if (operatorId == -1) {
            //No operator found ==> default case
            if (debug) {
                logger.log(BasicLevel.DEBUG, tab + "create a fieldOperand with:" + name);
            }
        Field f = (Field) fields.get(name);
        if (f == null) {
            throw new SpeedoException("Internal error: No field '" + name + "' found during filter parsing");
        }
        stack.push(new BasicFieldOperand(f));
            return;
        }
        //There is an operator
        String begin = buildStringwithout(splitted, splitted.length-1, ".");
        if (operatorId == CONTAINS_OPERATOR) {
            //The contains contraint is managed during the QueryTree creation
        //see the variable vistor
          //However push some stuff in the stack in order to known that
          // the next qualifiedName is used in a contain constraint.
            if (debug) {
                logger.log(BasicLevel.DEBUG, tab + "contains operator: set=" + begin);
            }
            stack.push(begin);
            stack.push(CONTAINS_PATH_SET);
            return;
        } else if (operatorId == IS_EMPTY_OPERATOR) {
            if (debug) {
               logger.log(BasicLevel.DEBUG, tab + "Visit IsEmpty: " + begin);
            }
            String rest = mergePath(splitted, 1, splitted.length - 2);
            QueryBuilder subquery = new QueryBuilder(qb);
            subquery.define("", qb.navigate(splitted[0]));
            Field f = subquery.project(subquery.navigate(rest));
            stack.push(new IsEmpty(new BasicFieldOperand(f)));
            return;
        }
               
        if (debug) {
            logger.log(BasicLevel.DEBUG, tab + "create a fieldOperand with:" + begin);
        }
        Field f = (Field) fields.get(begin);
        Expression e = new BasicFieldOperand(f);
        switch (operatorId) {
        case TO_LOWER_OPERATOR:
            e = new StringLower(e);
            stack.push(e);
View Full Code Here

TOP

Related Classes of org.objectweb.medor.api.Field

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.