Search in sources :

Example 1 with SingletonPrimitiveType

use of org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType in project teiid by teiid.

the class OperationResponseImpl method setReturnValue.

@Override
public void setReturnValue(Object returnValue) throws SQLException {
    try {
        EdmReturnType returnType = this.procedureReturn.getReturnType();
        this.returnValue = // $NON-NLS-1$
        EntityCollectionResponse.buildPropery(// $NON-NLS-1$
        "return", (SingletonPrimitiveType) returnType.getType(), returnType.getPrecision(), returnType.getScale(), returnType.isCollection(), returnValue);
    } catch (TeiidProcessingException e) {
        throw new SQLException(e);
    } catch (IOException e) {
        throw new SQLException(e);
    }
}
Also used : EdmReturnType(org.apache.olingo.commons.api.edm.EdmReturnType) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) SQLException(java.sql.SQLException) IOException(java.io.IOException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 2 with SingletonPrimitiveType

use of org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType in project teiid by teiid.

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceIt info) {
    if (info.getType() instanceof SingletonPrimitiveType) {
        org.teiid.query.sql.symbol.Expression ex = null;
        if (this.ctxQuery.getIterator() == null) {
            String group = this.nameGenerator.getNextGroup();
            GroupSymbol groupSymbol = new GroupSymbol(group);
            StoredProcedure procedure = new StoredProcedure();
            procedure.setProcedureName("arrayiterate");
            // the projected should only be the collection property at this point
            // we may need more checks here to ensure that is valid
            Collection<ProjectedColumn> values = this.ctxQuery.getProjectedColumns().values();
            Assertion.assertTrue(values.size() == 1);
            ProjectedColumn projectedColumn = values.iterator().next();
            ElementSymbol projectedEs = (ElementSymbol) projectedColumn.getExpression();
            List<SPParameter> params = new ArrayList<SPParameter>();
            SPParameter param = new SPParameter(1, SPParameter.IN, "val");
            param.setExpression(projectedEs);
            params.add(param);
            procedure.setParameter(param);
            SubqueryFromClause fromClause = new SubqueryFromClause(group, procedure);
            fromClause.setLateral(true);
            ElementSymbol es = new ElementSymbol("col", groupSymbol);
            String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
            Function castFunction = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
            DocumentNode itResource = new DocumentNode();
            org.teiid.query.sql.symbol.Expression clone = (org.teiid.query.sql.symbol.Expression) castFunction.clone();
            AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, clone);
            AliasSymbol expression = new AliasSymbol(projectedEs.getShortName(), symbol);
            itResource.setFromClause(fromClause);
            itResource.setGroupSymbol(groupSymbol);
            itResource.addProjectedColumn(expression, info.getType(), projectedColumn.getProperty(), true);
            this.ctxQuery.getProjectedColumns().remove(projectedColumn.getExpression());
            this.ctxQuery.setIterator(itResource);
            ex = castFunction;
        } else {
            GroupSymbol groupSymbol = this.ctxQuery.getIterator().getGroupSymbol();
            ElementSymbol es = new ElementSymbol("col", groupSymbol);
            String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
            ex = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
        }
        this.stack.push(ex);
    } else {
        boolean ex = true;
        if (this.ctxQuery instanceof ExpandDocumentNode) {
            ExpandDocumentNode node = (ExpandDocumentNode) this.ctxQuery;
            DocumentNode parent = node.getCollectionContext();
            if (parent != null) {
                this.ctxExpression = parent;
                ex = false;
            }
        }
        if (ex) {
            throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16010, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16010)));
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ProjectedColumn(org.teiid.olingo.ProjectedColumn) Function(org.teiid.query.sql.symbol.Function) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 3 with SingletonPrimitiveType

use of org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType in project teiid by teiid.

the class OperationResponseImpl method getComplexProperty.

private ComplexValue getComplexProperty(ResultSet rs) throws SQLException {
    HashMap<Integer, Property> properties = new HashMap<Integer, Property>();
    for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
        Object value = rs.getObject(i + 1);
        String propName = rs.getMetaData().getColumnLabel(i + 1);
        EdmElement element = ((EdmComplexType) this.procedureReturn.getReturnType().getType()).getProperty(propName);
        if (!(element instanceof EdmProperty) && !((EdmProperty) element).isPrimitive()) {
            throw new SQLException(new TeiidNotImplementedException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16024)));
        }
        EdmPropertyImpl edmProperty = (EdmPropertyImpl) element;
        Property property;
        try {
            property = EntityCollectionResponse.buildPropery(propName, (SingletonPrimitiveType) edmProperty.getType(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isCollection(), value);
            properties.put(i, property);
        } catch (IOException e) {
            throw new SQLException(e);
        } catch (TeiidProcessingException e) {
            throw new SQLException(e);
        }
    }
    // filter those columns out.
    return createComplex("result", properties.values());
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) IOException(java.io.IOException) EdmElement(org.apache.olingo.commons.api.edm.EdmElement) EdmComplexType(org.apache.olingo.commons.api.edm.EdmComplexType) EdmPropertyImpl(org.apache.olingo.commons.core.edm.EdmPropertyImpl) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) Property(org.apache.olingo.commons.api.data.Property) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty)

Example 4 with SingletonPrimitiveType

use of org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType in project teiid by teiid.

the class EntityCollectionResponse method createEntity.

static Entity createEntity(Row row, DocumentNode node, String baseURL, EntityCollectionResponse response) throws SQLException {
    List<ProjectedColumn> projected = node.getAllProjectedColumns();
    EdmEntityType entityType = node.getEdmEntityType();
    LinkedHashMap<String, Link> streamProperties = new LinkedHashMap<String, Link>();
    Entity entity = new Entity();
    entity.setType(entityType.getFullQualifiedName().getFullQualifiedNameAsString());
    boolean allNulls = true;
    for (ProjectedColumn column : projected) {
        /*
            if (!column.isVisible()) {
                continue;
            }*/
        String propertyName = Symbol.getShortName(column.getExpression());
        Object value = row.getObject(column.getOrdinal());
        if (value != null) {
            allNulls = false;
        }
        try {
            SingletonPrimitiveType type = (SingletonPrimitiveType) column.getEdmType();
            if (type instanceof EdmStream) {
                buildStreamLink(streamProperties, value, propertyName);
                if (response != null) {
                    // this will only be used for a stream response off of the first entity. In all other scenarios it will be ignored.
                    response.setStream(propertyName, value);
                }
            } else {
                Property property = buildPropery(propertyName, type, column.getPrecision(), column.getScale(), column.isCollection(), value);
                entity.addProperty(property);
            }
        } catch (IOException e) {
            throw new SQLException(e);
        } catch (TeiidProcessingException e) {
            throw new SQLException(e);
        }
    }
    if (allNulls) {
        return null;
    }
    // Build the navigation and Stream Links
    try {
        String id = EntityResponse.buildLocation(baseURL, entity, entityType.getName(), entityType);
        entity.setId(new URI(id));
        // build stream properties
        for (String name : streamProperties.keySet()) {
            Link link = streamProperties.get(name);
            link.setHref(id + "/" + name);
            entity.getMediaEditLinks().add(link);
            entity.addProperty(createPrimitive(name, EdmStream.getInstance(), new URI(link.getHref())));
        }
        // build navigations
        for (String name : entityType.getNavigationPropertyNames()) {
            Link navLink = new Link();
            navLink.setTitle(name);
            navLink.setHref(id + "/" + name);
            navLink.setRel("http://docs.oasis-open.org/odata/ns/related/" + name);
            entity.getNavigationLinks().add(navLink);
            Link assosiationLink = new Link();
            assosiationLink.setTitle(name);
            assosiationLink.setHref(id + "/" + name + "/$ref");
            assosiationLink.setRel("http://docs.oasis-open.org/odata/ns/relatedlinks/" + name);
            entity.getAssociationLinks().add(assosiationLink);
        }
    } catch (URISyntaxException e) {
        throw new SQLException(e);
    } catch (EdmPrimitiveTypeException e) {
        throw new SQLException(e);
    }
    return entity;
}
Also used : Entity(org.apache.olingo.commons.api.data.Entity) SQLException(java.sql.SQLException) EdmStream(org.apache.olingo.commons.core.edm.primitivetype.EdmStream) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) URI(java.net.URI) ProjectedColumn(org.teiid.olingo.ProjectedColumn) LinkedHashMap(java.util.LinkedHashMap) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) Property(org.apache.olingo.commons.api.data.Property) Link(org.apache.olingo.commons.api.data.Link)

Aggregations

SingletonPrimitiveType (org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Property (org.apache.olingo.commons.api.data.Property)2 ProjectedColumn (org.teiid.olingo.ProjectedColumn)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Entity (org.apache.olingo.commons.api.data.Entity)1 Link (org.apache.olingo.commons.api.data.Link)1 EdmComplexType (org.apache.olingo.commons.api.edm.EdmComplexType)1 EdmElement (org.apache.olingo.commons.api.edm.EdmElement)1 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)1 EdmPrimitiveTypeException (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)1 EdmProperty (org.apache.olingo.commons.api.edm.EdmProperty)1 EdmReturnType (org.apache.olingo.commons.api.edm.EdmReturnType)1 EdmPropertyImpl (org.apache.olingo.commons.core.edm.EdmPropertyImpl)1