Search in sources :

Example 1 with ProcedureReturn

use of org.teiid.olingo.service.ProcedureSQLBuilder.ProcedureReturn in project teiid by teiid.

the class ODataSQLBuilder method visitOperation.

private void visitOperation(EdmOperation operation) {
    try {
        ProcedureSQLBuilder builder = new ProcedureSQLBuilder(this.metadata, operation, this.parameters, this.params);
        ProcedureReturn pp = builder.getReturn();
        if (!pp.hasResultSet()) {
            NoDocumentNode ndn = new NoDocumentNode();
            ndn.setProcedureReturn(pp);
            ndn.setQuery(builder.buildProcedureSQL());
            this.context = ndn;
        } else {
            ComplexDocumentNode cdn = ComplexDocumentNode.buildComplexDocumentNode(operation, this.metadata, this.odata, this.nameGenerator, this.aliasedGroups, getUriInfo(), this.parseService);
            cdn.setProcedureReturn(pp);
            this.context = cdn;
        }
    } catch (TeiidProcessingException e) {
        throw new ODataRuntimeException(e);
    }
}
Also used : ProcedureReturn(org.teiid.olingo.service.ProcedureSQLBuilder.ProcedureReturn) ODataRuntimeException(org.apache.olingo.commons.api.ex.ODataRuntimeException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 2 with ProcedureReturn

use of org.teiid.olingo.service.ProcedureSQLBuilder.ProcedureReturn in project teiid by teiid.

the class TeiidServiceHandler method invokeOperation.

private <T extends ServiceResponse> void invokeOperation(final OperationRequest request, OperationParameterValueProvider parameters, T response) throws ODataApplicationException, ODataLibraryException {
    checkExpand(request.getUriInfo().asUriInfoResource());
    final ODataSQLBuilder visitor = new ODataSQLBuilder(odata, getClient().getMetadataStore(), this.prepared, true, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
    visitor.setOperationParameterValueProvider(parameters);
    visitor.visit(request.getUriInfo());
    final OperationResponseImpl queryResponse;
    try {
        if (visitor.getContext() instanceof NoDocumentNode) {
            NoDocumentNode cdn = (NoDocumentNode) visitor.getContext();
            ProcedureReturn procReturn = cdn.getProcedureReturn();
            queryResponse = new OperationResponseImpl(procReturn);
            getClient().executeCall(cdn.getQuery(), visitor.getParameters(), procReturn, queryResponse);
        } else {
            Query query = visitor.selectQuery();
            queryResponse = (OperationResponseImpl) executeQuery(request, request.isCountRequest(), visitor, query);
        }
    } catch (Throwable e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    }
    /*
        try {
            MetadataStore store = getClient().getMetadataStore();
            ProcedureSQLBuilder builder = new ProcedureSQLBuilder(store.getSchema(schemaName), request);
            ProcedureReturn procedureReturn = builder.getReturn();
            result = new OperationResponseImpl(procedureReturn);
            
            getClient().executeCall(builder.buildProcedureSQL(), builder.getSqlParameters(), procedureReturn, result);
        } 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);
        } 
        */
    final OperationResponseImpl operationResult = queryResponse;
    response.accepts(new ServiceResponseVisior() {

        @Override
        public void visit(PropertyResponse response) throws ODataLibraryException, ODataApplicationException {
            Property property = (Property) operationResult.getResult();
            Object value = property.getValue();
            if (value instanceof SQLXML || value instanceof Blob || value instanceof Clob) {
                try {
                    handleLobResult(getClient().getProperty(Client.CHARSET), value, response);
                } catch (SQLException e) {
                    LogManager.logDetail(LogConstants.CTX_ODATA, e);
                    response.writeServerError(true);
                }
            } else {
                response.writeProperty(request.getReturnType().getType(), property);
            }
        }
    });
}
Also used : Blob(java.sql.Blob) Query(org.teiid.query.sql.lang.Query) SQLException(java.sql.SQLException) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException) ODataLibraryException(org.apache.olingo.server.api.ODataLibraryException) SQLXML(java.sql.SQLXML) ProcedureReturn(org.teiid.olingo.service.ProcedureSQLBuilder.ProcedureReturn) Clob(java.sql.Clob) Property(org.apache.olingo.commons.api.data.Property) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty)

Aggregations

ProcedureReturn (org.teiid.olingo.service.ProcedureSQLBuilder.ProcedureReturn)2 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 SQLException (java.sql.SQLException)1 SQLXML (java.sql.SQLXML)1 Property (org.apache.olingo.commons.api.data.Property)1 EdmNavigationProperty (org.apache.olingo.commons.api.edm.EdmNavigationProperty)1 EdmProperty (org.apache.olingo.commons.api.edm.EdmProperty)1 ODataRuntimeException (org.apache.olingo.commons.api.ex.ODataRuntimeException)1 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)1 ODataLibraryException (org.apache.olingo.server.api.ODataLibraryException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 Query (org.teiid.query.sql.lang.Query)1