Query implementation
--------------------

                 Key: OAK-28
                 URL: https://issues.apache.org/jira/browse/OAK-28
             Project: Jackrabbit Oak
          Issue Type: New Feature
          Components: core
            Reporter: Thomas Mueller
            Assignee: Thomas Mueller


A query engine needs to be implemented. 

This includes a query parser in oak-core (where we don't want to use the JCR 
API), and a query parser in oak-jcr (where the parsed query tree needs to 
implement the JCR API).

To avoid writing two independent parsers, I suggest to change the parser to 
emit a non-JCR query tree (so the parser can be used in oak-core). There needs 
to be a converter from the non-JCR query tree to a JCR query tree, so the same 
parser can be used in oak-jcr.

This will still require two independent query tree implementations (about 37 
duplicated classes: 37 classes for oak-core and 37 classes in oak-jcr). Plus it 
requires a tree converter.

If somebody has a better idea please tell me :-)

Prototype implementation of the query tree converter. Please note the class 
names are only to for illustration, but I don't know yet a good naming 
convention. Ideas are welcome!

import javax.jcr.query.qom.And;
import javax.jcr.query.qom.Constraint;
public class OakToJcrQueryTreeConverter {
    public static void main(String... args) {
        OakAnd oak = new OakAnd();
        oak.constraint1 = new OakConstraint();
        oak.constraint1.s = "x=1";
        oak.constraint2 = new OakConstraint();
        oak.constraint2.s = "y=1";
        System.out.println("Oak constraint: " + oak);
        JcrConstraint jcr = convertOakToJcr(oak);
        System.out.println("JCR constraint: " + jcr);
    }
    static JcrConstraint convertOakToJcr(OakConstraint constraint) {
        if (constraint instanceof OakAnd) {
            OakAnd o = (OakAnd) constraint;
            return new JcrAnd(o.constraint1, o.constraint2);
        } else {
            JcrConstraint c = new JcrConstraint();
            c.s = constraint.s;
            return c;
        }
    }
}
class OakConstraint {
    String s;
    public String toString() {
        return "(OakConstraint) " + s;
    }
}
class OakAnd extends OakConstraint {
    public OakConstraint constraint1, constraint2;
    public String toString() {
        return constraint1 + " and " + constraint2;
    }
}
class JcrConstraint implements Constraint {
    String s;
    public String toString() {
        return "(JcrConstraint) " + s;
    }
}
class JcrAnd extends JcrConstraint implements And {
    JcrConstraint constraint1, constraint2;
    JcrAnd(OakConstraint constraint1, OakConstraint constraint2) {
        this.constraint1 = 
OakToJcrQueryTreeConverter.convertOakToJcr(constraint1);
        this.constraint2 = 
OakToJcrQueryTreeConverter.convertOakToJcr(constraint2);
    }
    public JcrConstraint getConstraint1() {
        return constraint1;
    }
    public JcrConstraint getConstraint2() {
        return constraint2;
    }
    public String toString() {
        return constraint1 + " and " + constraint2;
    }
}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to