Search in sources :

Example 1 with Property

use of org.apache.olingo.commons.api.data.Property 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 2 with Property

use of org.apache.olingo.commons.api.data.Property 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 3 with Property

use of org.apache.olingo.commons.api.data.Property in project teiid by teiid.

the class ODataDocument method createDocument.

private static ODataDocument createDocument(String name, ComplexValue complex, ODataDocument parent) {
    ODataDocument document = new ODataDocument(name, parent);
    List<Property> properties = complex.getValue();
    for (Property property : properties) {
        populateDocument(property, document);
    }
    return document;
}
Also used : Property(org.apache.olingo.commons.api.data.Property)

Example 4 with Property

use of org.apache.olingo.commons.api.data.Property in project teiid by teiid.

the class ODataDocument method createDocument.

public static ODataDocument createDocument(ComplexValue complex) {
    ODataDocument document = new ODataDocument();
    List<Property> properties = complex.getValue();
    for (Property property : properties) {
        populateDocument(property, document);
    }
    return document;
}
Also used : Property(org.apache.olingo.commons.api.data.Property)

Example 5 with Property

use of org.apache.olingo.commons.api.data.Property in project teiid by teiid.

the class ODataProcedureExecution method handleResponse.

private void handleResponse(final Procedure procedure, final String baseUri, final InputStream payload) throws TranslatorException, ODataDeserializerException {
    if (procedure.getResultSet() != null) {
        ODataType type = ODataType.valueOf(procedure.getResultSet().getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
        this.response = new ODataResponse(payload, type, new DocumentNode()) {

            @Override
            public InputStream nextBatch(java.net.URI uri) throws TranslatorException {
                return executeSkipToken(uri, baseUri, new HttpStatusCode[] { HttpStatusCode.OK });
            }
        };
    } else if (getReturnParameter() != null) {
        // this is scalar result
        JsonDeserializer parser = new JsonDeserializer(false);
        Property property = parser.toProperty(payload).getPayload();
        if (property.isCollection()) {
            this.returnValue = property.asCollection();
        } else {
            this.returnValue = property.asPrimitive();
        }
    }
}
Also used : DocumentNode(org.teiid.translator.document.DocumentNode) InputStream(java.io.InputStream) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) TranslatorException(org.teiid.translator.TranslatorException) JsonDeserializer(org.apache.olingo.client.core.serialization.JsonDeserializer) Property(org.apache.olingo.commons.api.data.Property)

Aggregations

Property (org.apache.olingo.commons.api.data.Property)15 EdmProperty (org.apache.olingo.commons.api.edm.EdmProperty)6 Entity (org.apache.olingo.commons.api.data.Entity)5 EdmNavigationProperty (org.apache.olingo.commons.api.edm.EdmNavigationProperty)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 TeiidProcessingException (org.teiid.core.TeiidProcessingException)4 Column (org.teiid.metadata.Column)4 TranslatorException (org.teiid.translator.TranslatorException)4 EntityCollection (org.apache.olingo.commons.api.data.EntityCollection)3 Table (org.teiid.metadata.Table)3 IOException (java.io.IOException)2 JsonDeserializer (org.apache.olingo.client.core.serialization.JsonDeserializer)2 ComplexValue (org.apache.olingo.commons.api.data.ComplexValue)2 SingletonPrimitiveType (org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType)2 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)2 ODataLibraryException (org.apache.olingo.server.api.ODataLibraryException)2 Query (org.teiid.query.sql.lang.Query)2 Constant (org.teiid.query.sql.symbol.Constant)2 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)2