Search in sources :

Example 1 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class ODataSQLBuilder method visit.

@Override
public void visit(FilterOption info) {
    ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(this.context, this.prepared, getUriInfo(), this.metadata, this.odata, this.nameGenerator, this.params, this.parseService);
    Expression filter = null;
    try {
        filter = visitor.getExpression(info.getExpression());
    } catch (TeiidException e) {
        this.exceptions.add(e);
    }
    // Here Lambda operation may have joined a table and changed the context.
    this.context = visitor.getEntityResource();
    this.context.addCriteria(filter);
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) TeiidException(org.teiid.core.TeiidException)

Example 2 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class ODataSQLBuilder method visit.

@Override
public void visit(UriResourceNavigation info) {
    EdmNavigationProperty property = info.getProperty();
    try {
        DocumentNode joinResource = DocumentNode.build(property.getType(), info.getKeyPredicates(), this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), parseService);
        this.context.joinTable(joinResource, property, JoinType.JOIN_INNER);
        // In the context of canonical queries if key predicates are available then do not set the criteria
        if (joinResource.getCriteria() == null) {
            joinResource.addCriteria(this.context.getCriteria());
        }
        this.context = joinResource;
        this.navigation = true;
    } catch (TeiidException e) {
        this.exceptions.add(e);
    }
}
Also used : EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) TeiidException(org.teiid.core.TeiidException)

Example 3 with TeiidException

use of org.teiid.core.TeiidException 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)

Example 4 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceLambdaVariable resource) {
    try {
        if (this.ctxLambda == null) {
            DocumentNode lambda = DocumentNode.build((EdmEntityType) resource.getType(), null, this.metadata, this.odata, this.nameGenerator, false, this.uriInfo, this.parseService);
            lambda.setGroupSymbol(new GroupSymbol(resource.getVariableName(), lambda.getFullName()));
            this.ctxLambda = lambda;
        }
        this.ctxExpression = ctxLambda;
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 5 with TeiidException

use of org.teiid.core.TeiidException 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)

Aggregations

TeiidException (org.teiid.core.TeiidException)85 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)26 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)13 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 SQLException (java.sql.SQLException)9 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)8 BigInteger (java.math.BigInteger)6 Column (org.teiid.metadata.Column)6 Command (org.teiid.query.sql.lang.Command)6 TranslatorException (org.teiid.translator.TranslatorException)6 IOException (java.io.IOException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 List (java.util.List)4 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)4 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 UpdateResponse (org.teiid.odata.api.UpdateResponse)4 Update (org.teiid.query.sql.lang.Update)4 SocketTimeoutException (java.net.SocketTimeoutException)3