Search in sources :

Example 6 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestSearchedCaseExpressionImpl method getWhenCriteria.

public static List getWhenCriteria(int criteria) {
    ArrayList list = new ArrayList();
    // $NON-NLS-1$ //$NON-NLS-2$
    ElementSymbol x = TestElementImpl.helpExample("vm1.g1", "e1");
    for (int i = 0; i < criteria; i++) {
        list.add(new CompareCriteria(x, CompareCriteria.EQ, new Constant(new Integer(i))));
    }
    return list;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 7 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestSearchedCaseExpressionImpl method helpExample.

public static SearchedCaseExpression helpExample() {
    SearchedCaseExpression caseExpr = new SearchedCaseExpression(getWhenCriteria(3), TestCaseExpression.getThenExpressions(3));
    caseExpr.setElseExpression(new Constant(new Integer(9999)));
    return caseExpr;
}
Also used : SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Constant(org.teiid.query.sql.symbol.Constant)

Example 8 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class ODataSQLBuilder method update.

public Update update(EdmEntityType entityType, Entity entity, boolean prepared) throws TeiidException {
    Update update = new Update();
    update.setGroup(this.context.getGroupSymbol());
    int i = 0;
    for (Property property : entity.getProperties()) {
        EdmProperty edmProperty = (EdmProperty) entityType.getProperty(property.getName());
        Column column = this.context.getColumnByName(edmProperty.getName());
        ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
        boolean add = true;
        for (String c : this.context.getKeyColumnNames()) {
            if (c.equals(column.getName())) {
                add = false;
                break;
            }
        }
        if (add) {
            if (prepared) {
                update.addChange(symbol, new Reference(i++));
                this.params.add(asParam(edmProperty, property.getValue()));
            } else {
                update.addChange(symbol, new Constant(asParam(edmProperty, property.getValue()).getValue()));
            }
        }
    }
    update.setCriteria(this.context.getCriteria());
    return update;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Column(org.teiid.metadata.Column) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) Property(org.apache.olingo.commons.api.data.Property) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)

Example 9 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class ODataSQLBuilder method selectWithEntityKey.

// TODO: allow the generated key building.
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException {
    Table table = findTable(entityType.getName(), this.metadata);
    DocumentNode resource = new DocumentNode(table, new GroupSymbol(table.getFullName()), entityType);
    resource.setFromClause(new UnaryFromClause(new GroupSymbol(table.getFullName())));
    resource.addAllColumns(false);
    this.context = resource;
    Query query = this.context.buildQuery();
    processExpand(expand, resource, query, 1);
    Criteria criteria = null;
    KeyRecord pk = ODataSchemaBuilder.getIdentifier(table);
    for (Column c : pk.getColumns()) {
        Property prop = entity.getProperty(c.getName());
        Constant right = null;
        if (prop != null) {
            right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue(), null));
        } else {
            Object value = generatedKeys.get(c.getName());
            if (value == null) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
            }
            right = new Constant(value);
        }
        ElementSymbol left = new ElementSymbol(c.getName(), this.context.getGroupSymbol());
        if (criteria == null) {
            criteria = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
        } else {
            CompareCriteria rightCC = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
            criteria = new CompoundCriteria(CompoundCriteria.AND, criteria, rightCC);
        }
    }
    query.setCriteria(criteria);
    return query;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) Constant(org.teiid.query.sql.symbol.Constant) TeiidProcessingException(org.teiid.core.TeiidProcessingException) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Property(org.apache.olingo.commons.api.data.Property) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty)

Example 10 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(Literal expr) {
    try {
        Object value = null;
        if (expr.getText() != null && !expr.getText().equalsIgnoreCase("null")) {
            String type = expr.getType().getFullQualifiedName().getFullQualifiedNameAsString();
            value = ODataTypeManager.parseLiteral(type, expr.getText());
        }
        if (this.prepared) {
            if (value == null) {
                this.stack.add(new Constant(value));
            } else {
                Function ref = new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { new Reference(this.params.size()), new Constant(DataTypeManager.getDataTypeName(value.getClass())) });
                stack.add(ref);
                this.params.add(new SQLParameter(value, JDBCSQLTypeInfo.getSQLTypeFromClass(value.getClass().getName())));
            }
        } else {
            this.stack.add(new Constant(value));
        }
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant) Reference(org.teiid.query.sql.symbol.Reference) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) SQLParameter(org.teiid.odata.api.SQLParameter) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Aggregations

Constant (org.teiid.query.sql.symbol.Constant)203 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)94 Test (org.junit.Test)88 ArrayList (java.util.ArrayList)61 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)48 List (java.util.List)38 Expression (org.teiid.query.sql.symbol.Expression)38 Function (org.teiid.query.sql.symbol.Function)31 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)25 Query (org.teiid.query.sql.lang.Query)22 Select (org.teiid.query.sql.lang.Select)15 Reference (org.teiid.query.sql.symbol.Reference)14 From (org.teiid.query.sql.lang.From)12 HashMap (java.util.HashMap)11 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)11 Criteria (org.teiid.query.sql.lang.Criteria)11 SetQuery (org.teiid.query.sql.lang.SetQuery)11 LinkedList (java.util.LinkedList)10 Limit (org.teiid.query.sql.lang.Limit)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)9