Search in sources :

Example 6 with Delete

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

the class DeleteResolver method resolveProceduralCommand.

/**
 * @see org.teiid.query.resolver.ProcedureContainerResolver#resolveProceduralCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter)
 */
public void resolveProceduralCommand(Command command, TempMetadataAdapter metadata) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    // Cast to known type
    Delete delete = (Delete) command;
    Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
    groups.add(delete.getGroup());
    QueryResolver.resolveSubqueries(command, metadata, groups);
    ResolverVisitor.resolveLanguageObject(delete, groups, delete.getExternalGroupContexts(), metadata);
}
Also used : Delete(org.teiid.query.sql.lang.Delete) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) HashSet(java.util.HashSet)

Example 7 with Delete

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

the class TestGroupCollectorVisitor method testDelete.

public void testDelete() {
    GroupSymbol gs1 = exampleGroupSymbol(1);
    Delete delete = new Delete();
    delete.setGroup(gs1);
    Set groups = new HashSet();
    groups.add(gs1);
    helpTestGroups(delete, 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) HashSet(java.util.HashSet)

Example 8 with Delete

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

the class TestStaticSymbolMappingVisitor method testVisitDelete1.

public void testVisitDelete1() {
    Delete delete = new Delete(exampleGroup(true, 0));
    helpTest(delete, getSymbolMap());
}
Also used : Delete(org.teiid.query.sql.lang.Delete)

Example 9 with Delete

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

the class TeiidServiceHandler method updateEntity.

@Override
public void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
    // TODO: need to match entityETag.
    checkETag(entityETag);
    UpdateResponse updateResponse = null;
    if (merge) {
        try {
            ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            visitor.visit(request.getUriInfo());
            EdmEntityType entityType = request.getEntitySet().getEntityType();
            Update update = visitor.update(entityType, entity, this.prepared);
            updateResponse = getClient().executeUpdate(update, visitor.getParameters());
        } 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);
        }
    } else {
        // delete, then insert
        String txn = startTransaction();
        boolean success = false;
        try {
            // build insert first as it could fail to validate
            ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            visitor.visit(request.getUriInfo());
            EdmEntityType entityType = request.getEntitySet().getEntityType();
            List<UriParameter> keys = request.getKeyPredicates();
            Insert command = visitor.insert(entityType, entity, keys, this.prepared);
            // run delete
            ODataSQLBuilder deleteVisitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            deleteVisitor.visit(request.getUriInfo());
            Delete delete = deleteVisitor.delete();
            updateResponse = getClient().executeUpdate(delete, deleteVisitor.getParameters());
            // run insert
            updateResponse = getClient().executeUpdate(command, visitor.getParameters());
            commit(txn);
            success = true;
        } 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);
        } finally {
            if (!success) {
                rollback(txn);
            }
        }
    }
    if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
        response.writeUpdatedEntity();
    } else {
        response.writeNotModified();
    }
}
Also used : Delete(org.teiid.query.sql.lang.Delete) SQLException(java.sql.SQLException) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) Update(org.teiid.query.sql.lang.Update) Insert(org.teiid.query.sql.lang.Insert) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException) TeiidException(org.teiid.core.TeiidException) UpdateResponse(org.teiid.odata.api.UpdateResponse) UriParameter(org.apache.olingo.server.api.uri.UriParameter)

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