Search in sources :

Example 11 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException 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 12 with TeiidProcessingException

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

the class ODataSQLBuilder method selectWithEntityKey.

// TODO: allow the generated key building.
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException {
    Table table = findTable(entityType.getName(), this.metadata);
    DocumentNode resource = new DocumentNode(table, new GroupSymbol(table.getFullName()), entityType);
    resource.setFromClause(new UnaryFromClause(new GroupSymbol(table.getFullName())));
    resource.addAllColumns(false);
    this.context = resource;
    Query query = this.context.buildQuery();
    processExpand(expand, resource, query, 1);
    Criteria criteria = null;
    KeyRecord pk = ODataSchemaBuilder.getIdentifier(table);
    for (Column c : pk.getColumns()) {
        Property prop = entity.getProperty(c.getName());
        Constant right = null;
        if (prop != null) {
            right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue(), null));
        } else {
            Object value = generatedKeys.get(c.getName());
            if (value == null) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
            }
            right = new Constant(value);
        }
        ElementSymbol left = new ElementSymbol(c.getName(), this.context.getGroupSymbol());
        if (criteria == null) {
            criteria = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
        } else {
            CompareCriteria rightCC = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
            criteria = new CompoundCriteria(CompoundCriteria.AND, criteria, rightCC);
        }
    }
    query.setCriteria(criteria);
    return query;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) Constant(org.teiid.query.sql.symbol.Constant) TeiidProcessingException(org.teiid.core.TeiidProcessingException) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) 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 13 with TeiidProcessingException

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

the class OperationResponseImpl method setReturnValue.

@Override
public void setReturnValue(Object returnValue) throws SQLException {
    try {
        EdmReturnType returnType = this.procedureReturn.getReturnType();
        this.returnValue = // $NON-NLS-1$
        EntityCollectionResponse.buildPropery(// $NON-NLS-1$
        "return", (SingletonPrimitiveType) returnType.getType(), returnType.getPrecision(), returnType.getScale(), returnType.isCollection(), returnValue);
    } catch (TeiidProcessingException e) {
        throw new SQLException(e);
    } catch (IOException e) {
        throw new SQLException(e);
    }
}
Also used : EdmReturnType(org.apache.olingo.commons.api.edm.EdmReturnType) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) SQLException(java.sql.SQLException) IOException(java.io.IOException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 14 with TeiidProcessingException

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

the class LocalClient method getVDBInternal.

private VDBMetaData getVDBInternal() throws SQLException, TeiidProcessingException {
    if (this.vdb == null) {
        LocalServerConnection lsc = (LocalServerConnection) getConnection().getServerConnection();
        vdb = lsc.getWorkContext().getVDB();
        if (vdb == null) {
            throw new TeiidRuntimeException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16001, this.vdbName, this.vdbVersion));
        }
        this.vdb = vdb;
    }
    if (vdb.getStatus() != Status.ACTIVE) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID31099, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31099, vdb, vdb.getStatus()));
    }
    return this.vdb;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) LocalServerConnection(org.teiid.transport.LocalServerConnection) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 15 with TeiidProcessingException

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

the class CorsFilter method doFilter.

/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpReq = (HttpServletRequest) request;
    HttpServletResponse httpResp = (HttpServletResponse) response;
    if (isOptionsMethod(httpReq) && !hasOriginHeader(httpReq)) {
        ODataFilter.writeError(request, new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16056)), httpResp, 400);
        return;
    }
    if (isPreflightRequest(httpReq)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        httpResp.setHeader("Access-Control-Allow-Origin", httpReq.getHeader("Origin"));
        // $NON-NLS-1$ //$NON-NLS-2$
        httpResp.setHeader("Access-Control-Allow-Credentials", "true");
        // $NON-NLS-1$ //$NON-NLS-2$
        httpResp.setHeader("Access-Control-Max-Age", "1800");
        // $NON-NLS-1$ //$NON-NLS-2$
        httpResp.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE");
        // $NON-NLS-1$ //$NON-NLS-2$
        httpResp.setHeader("Access-Control-Allow-Headers", "Content-Type,Accept,Origin,Authorization");
        httpResp.setStatus(204);
    } else {
        if (hasOriginHeader(httpReq)) {
            // $NON-NLS-1$ //$NON-NLS-2$
            httpResp.setHeader("Access-Control-Allow-Origin", httpReq.getHeader("Origin"));
            // $NON-NLS-1$ //$NON-NLS-2$
            httpResp.setHeader("Access-Control-Allow-Credentials", "true");
        }
        chain.doFilter(httpReq, httpResp);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6