Search in sources :

Example 1 with Delete

use of org.teiid.query.sql.lang.Delete in project teiid by teiid.

the class TeiidServiceHandler method deleteEntity.

@Override
public void deleteEntity(DataRequest request, String entityETag, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
    // TODO: need to match entityETag.
    checkETag(entityETag);
    UpdateResponse updateResponse = null;
    try {
        ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
        visitor.visit(request.getUriInfo());
        Delete delete = visitor.delete();
        updateResponse = getClient().executeUpdate(delete, visitor.getParameters());
    } catch (SQLException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    }
    if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
        response.writeDeletedEntityOrReference();
    } else {
        // since DELETE is idempotent same response as otherwise success operation.
        response.writeDeletedEntityOrReference();
    }
}
Also used : Delete(org.teiid.query.sql.lang.Delete) UpdateResponse(org.teiid.odata.api.UpdateResponse) SQLException(java.sql.SQLException) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException)

Example 2 with Delete

use of org.teiid.query.sql.lang.Delete in project teiid by teiid.

the class TestGroupCollectorVisitor method testBatchedUpdateCommand.

public void testBatchedUpdateCommand() {
    GroupSymbol g1 = exampleGroupSymbol(1);
    GroupSymbol g2 = exampleGroupSymbol(2);
    GroupSymbol g3 = exampleGroupSymbol(3);
    Insert insert = new Insert();
    insert.setGroup(g1);
    Update update = new Update();
    update.setGroup(g2);
    Delete delete = new Delete();
    delete.setGroup(g3);
    List updates = new ArrayList(3);
    updates.add(insert);
    updates.add(update);
    updates.add(delete);
    Set groups = new HashSet();
    groups.add(g1);
    groups.add(g2);
    groups.add(g3);
    helpTestGroups(new BatchedUpdateCommand(updates), true, groups);
}
Also used : Delete(org.teiid.query.sql.lang.Delete) Set(java.util.Set) HashSet(java.util.HashSet) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Insert(org.teiid.query.sql.lang.Insert) Update(org.teiid.query.sql.lang.Update) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) HashSet(java.util.HashSet)

Example 3 with Delete

use of org.teiid.query.sql.lang.Delete in project teiid by teiid.

the class TestStaticSymbolMappingVisitor method testVisitDelete2.

public void testVisitDelete2() {
    Delete delete = new Delete(exampleGroup(true, 0));
    delete.setCriteria(new CompareCriteria(exampleElement(true, 0), CompareCriteria.EQ, exampleElement(true, 1)));
    helpTest(delete, getSymbolMap());
}
Also used : Delete(org.teiid.query.sql.lang.Delete) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 4 with Delete

use of org.teiid.query.sql.lang.Delete in project teiid by teiid.

the class LanguageBridgeFactory method translate.

public org.teiid.language.Command translate(Command command) {
    try {
        if (command == null) {
            return null;
        }
        if (command instanceof Query) {
            Select result = translate((Query) command);
            result.setDependentValues(this.dependentSets);
            setProjected(result);
            return result;
        } else if (command instanceof SetQuery) {
            org.teiid.language.SetQuery result = translate((SetQuery) command);
            setProjected(result);
            return result;
        } else if (command instanceof Insert) {
            return translate((Insert) command);
        } else if (command instanceof Update) {
            return translate((Update) command);
        } else if (command instanceof Delete) {
            return translate((Delete) command);
        } else if (command instanceof StoredProcedure) {
            return translate((StoredProcedure) command);
        } else if (command instanceof BatchedUpdateCommand) {
            return translate((BatchedUpdateCommand) command);
        }
        // $NON-NLS-1$
        throw new AssertionError(command.getClass().getName() + " " + command);
    } finally {
        this.allValues.clear();
        this.dependentSets = null;
        this.valueIndex = 0;
    }
}
Also used : Delete(org.teiid.query.sql.lang.Delete) SetQuery(org.teiid.query.sql.lang.SetQuery) SetQuery(org.teiid.query.sql.lang.SetQuery) Select(org.teiid.language.Select) Insert(org.teiid.query.sql.lang.Insert) Update(org.teiid.query.sql.lang.Update)

Example 5 with Delete

use of org.teiid.query.sql.lang.Delete in project teiid by teiid.

the class RuleAccessPatternValidation method validateAccessPatterns.

/**
 * @param node
 * @throws QueryPlannerException
 */
private void validateAccessPatterns(PlanNode node) throws QueryPlannerException {
    if (!node.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS)) {
        return;
    }
    Criteria criteria = null;
    if (node.hasProperty(NodeConstants.Info.ATOMIC_REQUEST)) {
        Object req = node.getProperty(NodeConstants.Info.ATOMIC_REQUEST);
        if (req instanceof Insert) {
            return;
        }
        if (req instanceof Delete) {
            criteria = ((Delete) req).getCriteria();
        } else if (req instanceof Update) {
            criteria = ((Update) req).getCriteria();
        }
    }
    List accessPatterns = (List) node.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
    if (criteria != null) {
        for (Criteria crit : Criteria.separateCriteriaByAnd(criteria)) {
            Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(crit, true);
            if (RulePushSelectCriteria.satisfyAccessPatterns(accessPatterns, elements)) {
                return;
            }
        }
    }
    Object groups = node.getGroups();
    throw new QueryPlannerException(QueryPlugin.Event.TEIID30278, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30278, new Object[] { groups, accessPatterns }));
}
Also used : Delete(org.teiid.query.sql.lang.Delete) ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) List(java.util.List) Criteria(org.teiid.query.sql.lang.Criteria) Insert(org.teiid.query.sql.lang.Insert) Update(org.teiid.query.sql.lang.Update) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Aggregations

Delete (org.teiid.query.sql.lang.Delete)9 Insert (org.teiid.query.sql.lang.Insert)4 Update (org.teiid.query.sql.lang.Update)4 HashSet (java.util.HashSet)3 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)3 SQLException (java.sql.SQLException)2 List (java.util.List)2 Set (java.util.Set)2 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)2 UpdateResponse (org.teiid.odata.api.UpdateResponse)2 ArrayList (java.util.ArrayList)1 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)1 UriParameter (org.apache.olingo.server.api.uri.UriParameter)1 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)1 TeiidException (org.teiid.core.TeiidException)1 Select (org.teiid.language.Select)1 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)1 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)1 Criteria (org.teiid.query.sql.lang.Criteria)1 SetQuery (org.teiid.query.sql.lang.SetQuery)1