Search in sources :

Example 1 with EdmProperty

use of org.apache.olingo.commons.api.edm.EdmProperty 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 EdmProperty

use of org.apache.olingo.commons.api.edm.EdmProperty in project teiid by teiid.

the class TeiidServiceHandler method upsertStreamProperty.

@Override
public void upsertStreamProperty(DataRequest request, String entityETag, InputStream streamContent, NoContentResponse response) throws ODataLibraryException, ODataApplicationException {
    UpdateResponse updateResponse = null;
    EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
    try {
        ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
        visitor.visit(request.getUriInfo());
        Update update = visitor.updateStreamProperty(edmProperty, streamContent);
        updateResponse = getClient().executeUpdate(update, visitor.getParameters());
    } catch (SQLException | TeiidException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    }
    if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
        response.writeNoContent();
    } else {
        response.writeNotModified();
    }
}
Also used : UpdateResponse(org.teiid.odata.api.UpdateResponse) SQLException(java.sql.SQLException) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) Update(org.teiid.query.sql.lang.Update) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException) TeiidException(org.teiid.core.TeiidException)

Example 3 with EdmProperty

use of org.apache.olingo.commons.api.edm.EdmProperty in project teiid by teiid.

the class TeiidServiceHandler method updateProperty.

/**
 * since Teiid only deals with primitive types, merge does not apply
 */
@Override
public void updateProperty(DataRequest request, Property property, boolean rawValue, boolean merge, String entityETag, PropertyResponse response) throws ODataLibraryException, ODataApplicationException {
    // TODO: need to match entityETag.
    checkETag(entityETag);
    UpdateResponse updateResponse = null;
    EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
    try {
        ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
        visitor.visit(request.getUriInfo());
        Update update = visitor.updateProperty(edmProperty, property, this.prepared, rawValue);
        updateResponse = getClient().executeUpdate(update, visitor.getParameters());
    } catch (SQLException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    } catch (TeiidException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    }
    if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
        response.writePropertyUpdated();
    } else {
        response.writeNotModified();
    }
}
Also used : UpdateResponse(org.teiid.odata.api.UpdateResponse) SQLException(java.sql.SQLException) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) Update(org.teiid.query.sql.lang.Update) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException) TeiidException(org.teiid.core.TeiidException)

Example 4 with EdmProperty

use of org.apache.olingo.commons.api.edm.EdmProperty in project teiid by teiid.

the class ODataSQLBuilder method insert.

public Insert insert(EdmEntityType entityType, Entity entity, List<UriParameter> keys, boolean prepared) throws TeiidException {
    Table entityTable = findTable(entityType.getName(), this.metadata);
    DocumentNode resource = new DocumentNode(entityTable, new GroupSymbol(entityTable.getFullName()), entityType);
    List<Reference> referenceValues = new ArrayList<Reference>();
    List<Constant> constantValues = new ArrayList<Constant>();
    Insert insert = new Insert();
    insert.setGroup(resource.getGroupSymbol());
    if (keys != null) {
        for (UriParameter key : keys) {
            EdmProperty edmProperty = (EdmProperty) entityType.getProperty(key.getName());
            Column column = entityTable.getColumnByName(edmProperty.getName());
            Object propertyValue = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), key.getText());
            Property existing = entity.getProperty(edmProperty.getName());
            if (existing == null || (existing.getValue() == null && propertyValue != null) || (existing.getValue() != null && propertyValue == null) || (existing.getValue() != null && !existing.getValue().equals(propertyValue))) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16048, edmProperty.getName()));
            }
        }
    }
    int i = 0;
    for (Property prop : entity.getProperties()) {
        EdmProperty edmProp = (EdmProperty) entityType.getProperty(prop.getName());
        Column column = entityTable.getColumnByName(edmProp.getName());
        insert.addVariable(new ElementSymbol(column.getName(), resource.getGroupSymbol()));
        if (prepared) {
            referenceValues.add(new Reference(i++));
            this.params.add(asParam(edmProp, prop.getValue()));
        } else {
            constantValues.add(new Constant(asParam(edmProp, prop.getValue()).getValue()));
        }
    }
    if (prepared) {
        insert.setValues(referenceValues);
    } else {
        insert.setValues(constantValues);
    }
    return insert;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Column(org.teiid.metadata.Column) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) 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)

Example 5 with EdmProperty

use of org.apache.olingo.commons.api.edm.EdmProperty 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)

Aggregations

EdmProperty (org.apache.olingo.commons.api.edm.EdmProperty)7 SQLException (java.sql.SQLException)5 Property (org.apache.olingo.commons.api.data.Property)4 EdmNavigationProperty (org.apache.olingo.commons.api.edm.EdmNavigationProperty)3 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)3 TeiidException (org.teiid.core.TeiidException)3 Column (org.teiid.metadata.Column)3 Update (org.teiid.query.sql.lang.Update)3 Constant (org.teiid.query.sql.symbol.Constant)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Reference (org.teiid.query.sql.symbol.Reference)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 UpdateResponse (org.teiid.odata.api.UpdateResponse)2 SubqueryHint (org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entity (org.apache.olingo.commons.api.data.Entity)1 EntityCollection (org.apache.olingo.commons.api.data.EntityCollection)1