Search in sources :

Example 31 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class ODataQueryExecution method execute.

@Override
public void execute() throws TranslatorException {
    String URI = this.visitor.buildURL();
    if (this.visitor.isCount()) {
        Map<String, List<String>> headers = new TreeMap<String, List<String>>();
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        headers.put("Accept", Arrays.asList("text/xml", "text/plain"));
        // $NON-NLS-1$
        BinaryWSProcedureExecution execution = executeDirect("GET", URI, null, headers);
        if (execution.getResponseCode() != Status.OK.getStatusCode()) {
            throw buildError(execution);
        }
        Blob blob = (Blob) execution.getOutputParameterValues().get(0);
        try {
            this.countResponse = Integer.parseInt(ObjectConverterUtil.convertToString(blob.getBinaryStream()));
        } catch (IOException e) {
            throw new TranslatorException(e);
        } catch (SQLException e) {
            throw new TranslatorException(e);
        }
    } else {
        Schema schema = visitor.getEnityTable().getParent();
        EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
        // $NON-NLS-1$
        this.response = executeWithReturnEntity("GET", URI, null, visitor.getEnityTable().getName(), edm, null, Status.OK, Status.NO_CONTENT, Status.NOT_FOUND);
        if (this.response != null && this.response.hasError()) {
            throw this.response.getError();
        }
    }
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) Schema(org.teiid.metadata.Schema) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException) EdmDataServices(org.odata4j.edm.EdmDataServices) IOException(java.io.IOException) TreeMap(java.util.TreeMap)

Example 32 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class ODataUpdateVisitor method visit.

@Override
public void visit(Delete obj) {
    // $NON-NLS-1$
    this.method = "DELETE";
    this.entity = obj.getTable().getMetadataObject();
    visitNode(obj.getTable());
    // only pk are allowed, no other criteria not allowed
    obj.setWhere(buildEntityKey(obj.getWhere()));
    // this will build with entity keys
    this.uri = getEnitityURL();
    if (this.uri.indexOf('(') == -1) {
        this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17011, this.filter.toString())));
    }
    if (this.filter.length() > 0) {
        this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17009, this.filter.toString())));
    }
}
Also used : TranslatorException(org.teiid.translator.TranslatorException)

Example 33 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class ODataFilterVisitor method visit.

@Override
public void visit(ColumnReference obj) {
    Column column = obj.getMetadataObject();
    ODataDocumentNode schemaElement = this.query.getSchemaElement((Table) column.getParent());
    // check if the column on pseudo column, then move it to the parent.
    if (ODataMetadataProcessor.isPseudo(column)) {
        try {
            Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
            schemaElement = this.query.getSchemaElement((Table) realColumn.getParent());
        } catch (TranslatorException e) {
            this.exceptions.add(e);
        }
    }
    if (this.filterOnElement == null) {
        this.filterOnElement = schemaElement;
    } else if (schemaElement.isExpandType() && (!this.filterOnElement.isExpandType())) {
        this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17026)));
    }
    try {
        if (this.filterOnElement.isComplexType()) {
            if (ODataMetadataProcessor.isPseudo(column)) {
                Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
                this.filter.append(realColumn.getName());
            } else {
                this.filter.append(this.filterOnElement.getName()).append("/").append(column.getName());
            }
        } else {
            if (ODataMetadataProcessor.isPseudo(column)) {
                Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
                this.filter.append(realColumn.getName());
            } else {
                this.filter.append(column.getName());
            }
        }
    } catch (TranslatorException e) {
        this.exceptions.add(e);
    }
}
Also used : Table(org.teiid.metadata.Table) BaseColumn(org.teiid.metadata.BaseColumn) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException)

Example 34 with TranslatorException

use of org.teiid.translator.TranslatorException 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)

Example 35 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    try {
        String parameters = getQueryParameters(this.command);
        InputStream response = null;
        Procedure procedure = this.command.getMetadataObject();
        if (isFunction(procedure)) {
            String URI = buildFunctionURL(this.command, parameters);
            response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        } else {
            String URI = this.command.getProcedureName();
            response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        }
    } catch (ODataDeserializerException e) {
        throw new TranslatorException(e);
    } catch (EdmPrimitiveTypeException e) {
        throw new TranslatorException(e);
    }
}
Also used : InputStream(java.io.InputStream) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException) ODataDeserializerException(org.apache.olingo.client.api.serialization.ODataDeserializerException) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)

Aggregations

TranslatorException (org.teiid.translator.TranslatorException)227 ArrayList (java.util.ArrayList)51 Column (org.teiid.metadata.Column)47 List (java.util.List)32 Table (org.teiid.metadata.Table)30 IOException (java.io.IOException)26 SQLException (java.sql.SQLException)26 ResourceException (javax.resource.ResourceException)26 Test (org.junit.Test)16 Expression (org.teiid.language.Expression)16 Literal (org.teiid.language.Literal)16 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)16 Blob (java.sql.Blob)15 Argument (org.teiid.language.Argument)13 DBObject (com.mongodb.DBObject)11 HashMap (java.util.HashMap)11 ColumnReference (org.teiid.language.ColumnReference)11 ExecutionContext (org.teiid.translator.ExecutionContext)11 BasicDBObject (com.mongodb.BasicDBObject)10 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)10