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);
}
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);
}
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());
}
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();
}
}
Aggregations