Search in sources :

Example 1 with SubqueryFromClause

use of org.teiid.query.sql.lang.SubqueryFromClause in project teiid by teiid.

the class ComplexDocumentNode method buildComplexDocumentNode.

public static ComplexDocumentNode buildComplexDocumentNode(EdmOperation edmOperation, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidProcessingException {
    ComplexDocumentNode resource = new ComplexDocumentNode();
    FullQualifiedName fqn = edmOperation.getFullQualifiedName();
    String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.') + 1);
    Schema schema = metadata.getSchema(withoutVDB);
    Procedure procedure = schema.getProcedure(edmOperation.getName());
    StoredProcedure storedQuery = new StoredProcedure();
    // $NON-NLS-1$
    storedQuery.setProcedureName(procedure.getFullName());
    for (int i = 0; i < procedure.getParameters().size(); i++) {
        storedQuery.setParameter(new SPParameter(i + 1, new Reference(i)));
    }
    String group = nameGenerator.getNextGroup();
    // $NON-NLS-1$
    SubqueryFromClause sfc = new SubqueryFromClause(group, storedQuery);
    resource.setGroupSymbol(new GroupSymbol(group));
    resource.setFromClause(sfc);
    resource.procedure = procedure;
    return resource;
}
Also used : StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) SPParameter(org.teiid.query.sql.lang.SPParameter) Reference(org.teiid.query.sql.symbol.Reference) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) Schema(org.teiid.metadata.Schema) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Procedure(org.teiid.metadata.Procedure) SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Example 2 with SubqueryFromClause

use of org.teiid.query.sql.lang.SubqueryFromClause in project teiid by teiid.

the class TestSubqueryFromClause method example1.

// ################################## HELPERS ################################
public static SubqueryFromClause example1() {
    Query query = new Query();
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("a"));
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("b"));
    query.setSelect(select);
    From from = new From();
    // $NON-NLS-1$
    from.addGroup(new GroupSymbol("m.g"));
    query.setFrom(from);
    CompareCriteria crit = new CompareCriteria();
    // $NON-NLS-1$
    crit.setLeftExpression(new ElementSymbol("a"));
    crit.setRightExpression(new Constant(new Integer(5)));
    crit.setOperator(CompareCriteria.EQ);
    query.setCriteria(crit);
    // $NON-NLS-1$
    return new SubqueryFromClause("temp", query);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Query(org.teiid.query.sql.lang.Query) Constant(org.teiid.query.sql.symbol.Constant) Select(org.teiid.query.sql.lang.Select) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) From(org.teiid.query.sql.lang.From) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Example 3 with SubqueryFromClause

use of org.teiid.query.sql.lang.SubqueryFromClause in project teiid by teiid.

the class TestSubqueryFromClause method example2.

public static SubqueryFromClause example2() {
    Query query = new Query();
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("c"));
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("d"));
    query.setSelect(select);
    From from = new From();
    // $NON-NLS-1$
    from.addGroup(new GroupSymbol("m.g2"));
    query.setFrom(from);
    CompareCriteria crit = new CompareCriteria();
    // $NON-NLS-1$
    crit.setLeftExpression(new ElementSymbol("c"));
    crit.setRightExpression(new Constant(new Integer(10)));
    crit.setOperator(CompareCriteria.EQ);
    query.setCriteria(crit);
    // $NON-NLS-1$
    return new SubqueryFromClause("temp", query);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Query(org.teiid.query.sql.lang.Query) Constant(org.teiid.query.sql.symbol.Constant) Select(org.teiid.query.sql.lang.Select) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) From(org.teiid.query.sql.lang.From) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Example 4 with SubqueryFromClause

use of org.teiid.query.sql.lang.SubqueryFromClause in project teiid by teiid.

the class TestSubqueryFromClause method example3.

public static SubqueryFromClause example3() {
    Query query = new Query();
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("a"));
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("b"));
    query.setSelect(select);
    From from = new From();
    // $NON-NLS-1$
    from.addGroup(new GroupSymbol("m.g"));
    query.setFrom(from);
    CompareCriteria crit = new CompareCriteria();
    // $NON-NLS-1$
    crit.setLeftExpression(new ElementSymbol("a"));
    crit.setRightExpression(new Constant(new Integer(5)));
    crit.setOperator(CompareCriteria.EQ);
    query.setCriteria(crit);
    // $NON-NLS-1$
    return new SubqueryFromClause("temp2", query);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Query(org.teiid.query.sql.lang.Query) Constant(org.teiid.query.sql.symbol.Constant) Select(org.teiid.query.sql.lang.Select) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) From(org.teiid.query.sql.lang.From) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Example 5 with SubqueryFromClause

use of org.teiid.query.sql.lang.SubqueryFromClause in project teiid by teiid.

the class TestSubqueryFromClause method testEquivalenceDifferentOptional.

public void testEquivalenceDifferentOptional() {
    Object s1 = example1();
    SubqueryFromClause s2 = example1();
    s2.setOptional(true);
    int equals = -1;
    UnitTestUtil.helpTestEquivalence(equals, s1, s2);
}
Also used : SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Aggregations

SubqueryFromClause (org.teiid.query.sql.lang.SubqueryFromClause)6 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)4 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)3 From (org.teiid.query.sql.lang.From)3 Query (org.teiid.query.sql.lang.Query)3 Select (org.teiid.query.sql.lang.Select)3 Constant (org.teiid.query.sql.symbol.Constant)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 FullQualifiedName (org.apache.olingo.commons.api.edm.FullQualifiedName)1 Procedure (org.teiid.metadata.Procedure)1 Schema (org.teiid.metadata.Schema)1 SPParameter (org.teiid.query.sql.lang.SPParameter)1 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)1 Reference (org.teiid.query.sql.symbol.Reference)1