Search in sources :

Example 76 with TeiidException

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

the class ODataSQLBuilder method visit.

@Override
public void visit(UriInfoCrossjoin info) {
    for (String name : info.getEntitySetNames()) {
        EdmEntitySet entitySet = this.serviceMetadata.getEdm().getEntityContainer().getEntitySet(name);
        EdmEntityType entityType = entitySet.getEntityType();
        CrossJoinNode resource = null;
        try {
            boolean hasExpand = hasExpand(entitySet.getName(), info.getExpandOption());
            resource = CrossJoinNode.buildCrossJoin(entityType, null, this.metadata, this.odata, this.nameGenerator, this.aliasedGroups, getUriInfo(), this.parseService, hasExpand);
            resource.addAllColumns(!hasExpand);
            if (this.context == null) {
                this.context = resource;
                this.orderBy = this.context.addDefaultOrderBy();
            } else {
                this.context.addSibiling(resource);
                OrderBy orderby = resource.addDefaultOrderBy();
                int index = orderby.getVariableCount();
                for (int i = 0; i < index; i++) {
                    this.orderBy.addVariable(orderby.getVariable(i));
                }
            }
        } catch (TeiidException e) {
            this.exceptions.add(e);
        }
    }
    super.visit(info);
    // the expand behavior is handled above with selection of the columns
    this.expandOption = null;
}
Also used : EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) EdmEntitySet(org.apache.olingo.commons.api.edm.EdmEntitySet) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidException(org.teiid.core.TeiidException)

Example 77 with TeiidException

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

the class ReferenceUpdateSQLBuilder method updateReference.

public Update updateReference(URI referenceId, boolean prepared, boolean delete) throws SQLException {
    try {
        if (referenceId != null) {
            UriInfo uriInfo = ODataSQLBuilder.buildUriInfo(referenceId, this.baseURI, this.serviceMetadata, this.odata);
            UriResourceEntitySet uriEnitytSet = (UriResourceEntitySet) uriInfo.asUriInfoResource().getUriResourceParts().get(0);
            if (this.collection) {
                this.updateTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
            } else {
                this.referenceTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
            }
        }
    } catch (UriParserException e) {
        throw new SQLException(e);
    } catch (URISyntaxException e) {
        throw new SQLException(e);
    } catch (UriValidationException e) {
        throw new SQLException(e);
    }
    try {
        Update update = new Update();
        update.setGroup(this.updateTable.getGroupSymbol());
        List<String> columnNames = DocumentNode.getColumnNames(this.updateTable.getFk().getColumns());
        for (int i = 0; i < columnNames.size(); i++) {
            Column column = this.updateTable.getFk().getColumns().get(i);
            String columnName = columnNames.get(i);
            ElementSymbol symbol = new ElementSymbol(columnName, this.updateTable.getGroupSymbol());
            EdmEntityType entityType = this.updateTable.getEdmEntityType();
            EdmProperty edmProperty = (EdmProperty) entityType.getProperty(columnName);
            // reference table keys will be null for delete scenario
            Object value = null;
            if (!delete) {
                UriParameter parameter = getParameter(this.updateTable.getFk().getReferenceColumns().get(i), this.referenceTable.getKeyPredicates());
                value = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), parameter.getText());
            }
            if (prepared) {
                update.addChange(symbol, new Reference(i++));
                this.params.add(ODataSQLBuilder.asParam(edmProperty, value));
            } else {
                update.addChange(symbol, new Constant(ODataSQLBuilder.asParam(edmProperty, value).getValue()));
            }
        }
        Criteria criteria = DocumentNode.buildEntityKeyCriteria(this.updateTable, null, this.metadata, this.odata, null, null);
        update.setCriteria(criteria);
        return update;
    } catch (TeiidException e) {
        throw new SQLException(e);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SQLException(java.sql.SQLException) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) URISyntaxException(java.net.URISyntaxException) Criteria(org.teiid.query.sql.lang.Criteria) Update(org.teiid.query.sql.lang.Update) TeiidException(org.teiid.core.TeiidException) UriValidationException(org.apache.olingo.server.core.uri.validator.UriValidationException) Column(org.teiid.metadata.Column) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) UriResourceEntitySet(org.apache.olingo.server.api.uri.UriResourceEntitySet) UriInfo(org.apache.olingo.server.api.uri.UriInfo) UriParserException(org.apache.olingo.server.core.uri.parser.UriParserException) UriParameter(org.apache.olingo.server.api.uri.UriParameter)

Example 78 with TeiidException

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

the class TeiidServiceHandler method createEntity.

@Override
public void createEntity(DataRequest request, Entity entity, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
    EdmEntityType entityType = request.getEntitySet().getEntityType();
    String txn;
    try {
        txn = getClient().startTransaction();
    } catch (SQLException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    }
    boolean success = false;
    try {
        List<ExpandNode> expands = new ArrayList<TeiidServiceHandler.ExpandNode>();
        int insertDepth = insertDepth(entityType, entity);
        // don't count the root
        ODataSQLBuilder.checkExpandLevel(insertDepth - 1);
        UpdateResponse updateResponse = performDeepInsert(request.getODataRequest().getRawBaseUri(), request.getUriInfo(), entityType, entity, expands);
        if (updateResponse != null && updateResponse.getUpdateCount() == 1) {
            ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), true, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            Query query = visitor.selectWithEntityKey(entityType, entity, updateResponse.getGeneratedKeys(), expands);
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logDetail(LogConstants.CTX_ODATA, null, "created entity = ", entityType.getName(), " with key=", query.getCriteria().toString());
            EntityCollectionResponse result = new EntityCollectionResponse(request.getODataRequest().getRawBaseUri(), visitor.getContext());
            getClient().executeSQL(query, visitor.getParameters(), false, null, null, null, 1, result);
            if (!result.getEntities().isEmpty()) {
                entity = result.getEntities().get(0);
                String location = EntityResponse.buildLocation(request.getODataRequest().getRawBaseUri(), entity, request.getEntitySet().getName(), entityType);
                entity.setId(new URI(location));
            }
            response.writeCreatedEntity(request.getEntitySet(), entity);
        } else {
            response.writeNotModified();
        }
        getClient().commit(txn);
        success = true;
    } catch (EdmPrimitiveTypeException | TeiidException | SQLException | URISyntaxException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    } finally {
        if (!success) {
            try {
                getClient().rollback(txn);
            } catch (SQLException e1) {
            // ignore
            }
        }
    }
}
Also used : Query(org.teiid.query.sql.lang.Query) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException) TeiidException(org.teiid.core.TeiidException) UpdateResponse(org.teiid.odata.api.UpdateResponse)

Example 79 with TeiidException

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

the class TranslatorUtil method buildDelegateAwareExecutionFactory.

public static ExecutionFactory<Object, Object> buildDelegateAwareExecutionFactory(VDBTranslatorMetaData translator, ExecutionFactoryProvider provider) throws ConnectorManagerException {
    ExecutionFactory<Object, Object> ef = null;
    try {
        ef = buildExecutionFactory(translator);
    } catch (TeiidException e) {
        throw new ConnectorManagerException(e);
    }
    if (ef instanceof DelegatingExecutionFactory) {
        DelegatingExecutionFactory delegator = (DelegatingExecutionFactory) ef;
        String delegateName = delegator.getDelegateName();
        if (delegateName != null) {
            ExecutionFactory<Object, Object> delegate = provider.getExecutionFactory(delegateName);
            if (delegate == null) {
                throw new ConnectorManagerException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40155, delegateName));
            }
            ((DelegatingExecutionFactory<Object, Object>) ef).setDelegate(delegate);
        }
    }
    return ef;
}
Also used : ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) DelegatingExecutionFactory(org.teiid.translator.DelegatingExecutionFactory) TeiidException(org.teiid.core.TeiidException)

Example 80 with TeiidException

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

the class TranslatorUtil method buildExecutionFactory.

public static ExecutionFactory buildExecutionFactory(VDBTranslatorMetaData data) throws TeiidException {
    ExecutionFactory executionFactory;
    try {
        Class<?> executionClass = data.getExecutionFactoryClass();
        Object o = executionClass.newInstance();
        if (!(o instanceof ExecutionFactory)) {
            throw new TeiidException(RuntimePlugin.Event.TEIID40024, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40024, executionClass));
        }
        executionFactory = (ExecutionFactory) o;
        synchronized (executionFactory) {
            injectProperties(executionFactory, data);
            ClassLoader orginalCL = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(executionFactory.getClass().getClassLoader());
                executionFactory.start();
            } finally {
                Thread.currentThread().setContextClassLoader(orginalCL);
            }
        }
        return executionFactory;
    } catch (InvocationTargetException e) {
        throw new TeiidException(RuntimePlugin.Event.TEIID40025, e);
    } catch (IllegalAccessException e) {
        throw new TeiidException(RuntimePlugin.Event.TEIID40026, e);
    } catch (InstantiationException e) {
        throw new TeiidException(CorePlugin.Event.TEIID10036, e);
    }
}
Also used : DelegatingExecutionFactory(org.teiid.translator.DelegatingExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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