Search in sources :

Example 1 with Settings

use of org.odata4j.format.Settings in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    String URI = this.visitor.buildURL();
    Schema schema = visitor.getProcedure().getParent();
    EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
    if (this.visitor.hasCollectionReturn()) {
        if (this.visitor.isReturnComplexType()) {
            // complex return
            this.response = executeWithComplexReturn(this.visitor.getMethod(), URI, null, this.visitor.getReturnEntityTypeName(), edm, null, Status.OK, Status.NO_CONTENT);
        } else {
            // entity type return
            this.response = executeWithReturnEntity(this.visitor.getMethod(), URI, null, this.visitor.getTable().getName(), edm, null, Status.OK, Status.NO_CONTENT);
        }
        if (this.response != null && this.response.hasError()) {
            throw this.response.getError();
        }
    } else {
        try {
            BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), URI, null, getDefaultHeaders());
            if (execution.getResponseCode() != Status.OK.getStatusCode()) {
                throw buildError(execution);
            }
            Blob blob = (Blob) execution.getOutputParameterValues().get(0);
            ODataVersion version = getODataVersion(execution);
            // if the procedure is not void
            if (this.visitor.getReturnType() != null) {
                FormatParser<? extends OObject> parser = FormatParserFactory.getParser(OSimpleObject.class, FormatType.ATOM, new Settings(version, edm, this.visitor.getProcedure().getName(), // entitykey
                null, // isResponse
                true, ODataTypeManager.odataType(this.visitor.getReturnType())));
                OSimpleObject object = (OSimpleObject) parser.parse(new InputStreamReader(blob.getBinaryStream()));
                this.returnValue = this.translator.retrieveValue(object.getValue(), this.visitor.getReturnTypeClass());
            }
        } catch (SQLException e) {
            throw new TranslatorException(e);
        }
    }
}
Also used : Blob(java.sql.Blob) OSimpleObject(org.odata4j.core.OSimpleObject) InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) Schema(org.teiid.metadata.Schema) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ODataVersion(org.odata4j.core.ODataVersion) EdmDataServices(org.odata4j.edm.EdmDataServices) TranslatorException(org.teiid.translator.TranslatorException) Settings(org.odata4j.format.Settings)

Aggregations

InputStreamReader (java.io.InputStreamReader)1 Blob (java.sql.Blob)1 SQLException (java.sql.SQLException)1 ODataVersion (org.odata4j.core.ODataVersion)1 OSimpleObject (org.odata4j.core.OSimpleObject)1 EdmDataServices (org.odata4j.edm.EdmDataServices)1 Settings (org.odata4j.format.Settings)1 Schema (org.teiid.metadata.Schema)1 TranslatorException (org.teiid.translator.TranslatorException)1 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)1