Package org.apache.oodt.cas.filemgr.structs

Examples of org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria


    private QueryCriteria handleQueryCriteria(QueryCriteria qc) throws QueryFormulationException {
        if (qc instanceof BooleanQueryCriteria) {
            LinkedList<QueryCriteria> qcList = new LinkedList<QueryCriteria>();
            for (QueryCriteria criteria : ((BooleanQueryCriteria) qc).getTerms())
                qcList.add(this.handleQueryCriteria(criteria));
            BooleanQueryCriteria bqc = new BooleanQueryCriteria();
            bqc.setOperator(((BooleanQueryCriteria) qc).getOperator());
            bqc.setElementName(qc.getElementName());
            for (QueryCriteria criteria : qcList)
                bqc.addTerm(criteria);
            return bqc;
        }else if (qc.getElementName().equals(elementName) && qc instanceof TermQueryCriteria) {
            return this.handleTermQueryCriteria((TermQueryCriteria) qc);
        }else if (qc.getElementName().equals(elementName) && qc instanceof RangeQueryCriteria) {
            return this.handleRangeQueryCriteria((RangeQueryCriteria) qc);
View Full Code Here


                + (sqlQueryString != null ? " WHERE " + sqlQueryString : "") + " }";
    }

    public static String getInfixCriteriaString(List<QueryCriteria> criteriaList) throws QueryFormulationException {
        if (criteriaList.size() > 1)
            return getInfixCriteriaString(new BooleanQueryCriteria(criteriaList, BooleanQueryCriteria.AND));
        else if (criteriaList.size() == 1)
            return getInfixCriteriaString(criteriaList.get(0));
        else
            return null;
    }
View Full Code Here

    }
   
    public static String getInfixCriteriaString(QueryCriteria criteria) {
        String returnString = "";
        if (criteria instanceof BooleanQueryCriteria) {
            BooleanQueryCriteria bqc = (BooleanQueryCriteria) criteria;
            List<QueryCriteria> terms = bqc.getTerms();
            switch(bqc.getOperator()){
            case 0:
                returnString = "(" + getInfixCriteriaString((QueryCriteria) terms.get(0));
                for (int i = 1; i < terms.size(); i++)
                    returnString += " AND " + getInfixCriteriaString((QueryCriteria) terms.get(i));
                returnString += ")";
                break;
            case 1:
                returnString = "(" + getInfixCriteriaString((QueryCriteria) terms.get(0));
                for (int i = 1; i < terms.size(); i++)
                    returnString += " OR " + getInfixCriteriaString((QueryCriteria) terms.get(i));
                returnString += ")";
                break;
            case 2:
                QueryCriteria qc = bqc.getTerms().get(0);
                if (qc instanceof TermQueryCriteria) {
                    TermQueryCriteria tqc = (TermQueryCriteria) qc;
                    returnString = tqc.getElementName() + " != '" + tqc.getValue() + "'";
                }else {
                    returnString = "NOT(" + getInfixCriteriaString(qc) + ")";
View Full Code Here

    private static QueryCriteria parseStatement(LinkedList<String> postFixStatement)
            throws QueryFormulationException {
        Stack<QueryCriteria> stack = new Stack<QueryCriteria>();
        for (String item : postFixStatement) {
            if (item.equals("AND")) {
                BooleanQueryCriteria bQC = new BooleanQueryCriteria();
                bQC.addTerm(stack.pop());
                bQC.addTerm(stack.pop());
                stack.push(bQC);
            } else if (item.equals("OR")) {
                BooleanQueryCriteria bQC = new BooleanQueryCriteria();
                bQC.setOperator(BooleanQueryCriteria.OR);
                bQC.addTerm(stack.pop());
                bQC.addTerm(stack.pop());
                stack.push(bQC);
            } else if (item.equals("NOT")) {
                BooleanQueryCriteria bQC = new BooleanQueryCriteria();
                bQC.setOperator(BooleanQueryCriteria.NOT);
                bQC.addTerm(stack.pop());
                stack.push(bQC);
            } else {
                stack.push(new Expression(item).convertToQueryCriteria());
            }
        }
View Full Code Here

            case LESS_THAN:
                return new RangeQueryCriteria(this.key, null, this.val, false);
            case EQUAL_TO:
                return new TermQueryCriteria(this.key, this.val);
            case NOT_EQUAL_TO:
                BooleanQueryCriteria notEqBQC = new BooleanQueryCriteria();
                notEqBQC.setOperator(BooleanQueryCriteria.NOT);
                notEqBQC.addTerm(new TermQueryCriteria(this.key, this.val));
                return notEqBQC;
            case GREATER_THAN_OR_EQUAL_TO:
                return new RangeQueryCriteria(this.key, this.val, null, true);
            case LESS_THAN_OR_EQUAL_TO:
                return new RangeQueryCriteria(this.key, null, this.val, true);
View Full Code Here

                    ((RangeQueryCriteria)criteria).getStartValue():"");
            criteriaHash.put("elementEndValue", ((RangeQueryCriteria)criteria).getEndValue() != null ?
                    ((RangeQueryCriteria)criteria).getEndValue():"");
            criteriaHash.put("inclusive", Boolean.toString(((RangeQueryCriteria) criteria).getInclusive()));
        } else if(criteria instanceof BooleanQueryCriteria){
            BooleanQueryCriteria boolQuery = (BooleanQueryCriteria) criteria;
            criteriaHash.put("operator", new Integer(boolQuery.getOperator()));
            Vector<Hashtable<String, Object>> termsHash = new Vector<Hashtable<String, Object>>();
            List<QueryCriteria> terms = boolQuery.getTerms();
           
            for(int i=0;i<terms.size();i++){
                QueryCriteria term = terms.get(i);
                Hashtable<String, Object> termHash = getXmlRpcQueryCriteria(term);
                termsHash.add(termHash);
View Full Code Here

                    null : (String)criteriaHash.get("elementEndValue");
            ((RangeQueryCriteria)criteria).setStartValue(startVal);
            ((RangeQueryCriteria)criteria).setEndValue(endVal);
            ((RangeQueryCriteria)criteria).setInclusive(Boolean.parseBoolean((String) criteriaHash.get("inclusive")));
        } else if(((String)criteriaHash.get("class")).equals(BooleanQueryCriteria.class.getCanonicalName())){
            criteria = new BooleanQueryCriteria();
            try{
              ((BooleanQueryCriteria)criteria).setOperator( ((Integer)criteriaHash.get("operator")).intValue() );
            } catch (QueryFormulationException e){
                System.out.println("Error generating Boolean Query.");
            }
View Full Code Here

            if (query.getCriteria().size() == 0) {
                getProductSql = "SELECT DISTINCT product_id FROM " + type.getName() + "_metadata";
            }else if (query.getCriteria().size() == 1) {
                getProductSql = this.getSqlQuery(query.getCriteria().get(0), type);
            }else {
                getProductSql = this.getSqlQuery(new BooleanQueryCriteria(query.getCriteria(), BooleanQueryCriteria.AND), type);
            }
            getProductSql += " ORDER BY product_id DESC ";

            LOG.log(Level.FINE, "catalog query: executing: " + getProductSql);
View Full Code Here

    }
   
    private String getSqlQuery(QueryCriteria queryCriteria, ProductType type) throws ValidationLayerException, CatalogException {
        String sqlQuery = null;
        if (queryCriteria instanceof BooleanQueryCriteria) {
            BooleanQueryCriteria bqc = (BooleanQueryCriteria) queryCriteria;
            if (bqc.getOperator() == BooleanQueryCriteria.NOT) {
                sqlQuery = "SELECT DISTINCT product_id FROM " + type.getName() + "_metadata WHERE product_id NOT IN (" + this.getSqlQuery(bqc.getTerms().get(0), type) + ")";
            }else {
                sqlQuery = "(" + this.getSqlQuery(bqc.getTerms().get(0), type);
                String op = bqc.getOperator() == BooleanQueryCriteria.AND ? "INTERSECT" : "UNION";
                for (int i = 1; i < bqc.getTerms().size(); i++)
                    sqlQuery += ") " + op + " (" + this.getSqlQuery(bqc.getTerms().get(i), type);
                sqlQuery += ")";
            }
        }else {
            String elementIdStr = this.validationLayer.getElementByName(queryCriteria.getElementName()).getElementId();
            if (fieldIdStringFlag)
View Full Code Here

            }
      }
     
      // Formulate a test query
      Query query = new Query();
      BooleanQueryCriteria bqc = new BooleanQueryCriteria();
      try{
        bqc.setOperator(BooleanQueryCriteria.AND);
      }catch (Exception e){
        e.printStackTrace();
            fail(e.getMessage());
      }
      TermQueryCriteria tqc = new TermQueryCriteria();
      tqc.setElementName("ProductStructure");
      tqc.setValue("Flat");
      try{
        bqc.addTerm(tqc);
      }catch (Exception e){
        e.printStackTrace();
            fail(e.getMessage());
      }
      tqc = new TermQueryCriteria();
      tqc.setElementName("Filename");
      tqc.setValue("tempProduct1");
      try{
        bqc.addTerm(tqc);
      }catch (Exception e){
        e.printStackTrace();
            fail(e.getMessage());
      }
      query.addCriterion(bqc);
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria

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.