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