use of org.teiid.query.validator.UpdateValidator in project teiid by teiid.
the class QueryResolver method resolveView.
public static QueryNode resolveView(GroupSymbol virtualGroup, QueryNode qnode, String cacheString, QueryMetadataInterface qmi, boolean logValidation) throws TeiidComponentException, QueryMetadataException, QueryResolverException, QueryValidatorException {
qmi = qmi.getDesignTimeMetadata();
// $NON-NLS-1$
cacheString = "transformation/" + cacheString;
QueryNode cachedNode = (QueryNode) qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
if (cachedNode == null) {
Command result = qnode.getCommand();
List<String> bindings = null;
if (result == null) {
try {
result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
} catch (QueryParserException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30065, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30065, virtualGroup));
}
bindings = qnode.getBindings();
} else {
result = (Command) result.clone();
}
if (bindings != null && !bindings.isEmpty()) {
QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
} else {
QueryResolver.resolveCommand(result, qmi, false);
}
Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
validateProjectedSymbols(virtualGroup, qmi, result);
cachedNode = new QueryNode(qnode.getQuery());
cachedNode.setCommand(result);
if (isView(virtualGroup, qmi)) {
String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
String deletePlan = qmi.getDeletePlan(virtualGroup.getMetadataID());
String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());
// the elements must be against the view and not the alias
if (virtualGroup.getDefinition() != null) {
GroupSymbol group = new GroupSymbol(virtualGroup.getNonCorrelationName());
group.setMetadataID(virtualGroup.getMetadataID());
virtualGroup = group;
}
List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
validator.validate(result, elements);
UpdateInfo info = validator.getUpdateInfo();
if (logValidation && qmi.groupSupports(virtualGroup.getMetadataID(), SupportConstants.Group.UPDATE)) {
if (info.isInherentInsert() && validator.getInsertReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getInsertReport().getFailureMessage(), SQLConstants.Reserved.INSERT, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentUpdate() && validator.getUpdateReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getUpdateReport().getFailureMessage(), SQLConstants.Reserved.UPDATE, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentDelete() && validator.getDeleteReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getDeleteReport().getFailureMessage(), SQLConstants.Reserved.DELETE, qmi.getFullName(virtualGroup.getMetadataID())));
}
}
cachedNode.setUpdateInfo(info);
}
qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
}
return cachedNode;
}
Aggregations