}
}
protected void validateUpdate(Update update) {
try {
UpdateInfo info = update.getUpdateInfo();
// list of elements that are being updated
for (SetClause entry : update.getChangeList().getClauses()) {
ElementSymbol elementID = entry.getSymbol();
// Check that left side element is updatable
if(! getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.UPDATE)) {
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0059", elementID), elementID); //$NON-NLS-1$
}
Object metadataID = elementID.getMetadataID();
if (getMetadata().isMultiSourceElement(metadataID)){
handleValidationError(QueryPlugin.Util.getString("multi_source_update_not_allowed", elementID), elementID); //$NON-NLS-1$
}
// Check that right expression is a constant and is non-null
Expression value = entry.getValue();
if (EvaluatableVisitor.isFullyEvaluatable(value, true)) {
try {
value = new Constant(Evaluator.evaluate(value));
} catch (ExpressionEvaluationException err) {
}
}
if(value instanceof Constant) {
// If value is null, check that element supports this as a nullable column
if(((Constant)value).isNull() && ! getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.NULL)) {
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0060", SQLStringVisitor.getSQLString(elementID)), elementID); //$NON-NLS-1$
}// end of if
} else if (info != null && info.getUpdateType() == UpdateType.UPDATE_PROCEDURE && getMetadata().isVirtualGroup(update.getGroup().getMetadataID()) && !EvaluatableVisitor.willBecomeConstant(value)) {
// If this is an update on a virtual group, verify that no elements are in the right side
Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(value, false);
for (ElementSymbol element : elements) {
if(! element.isExternalReference()) {
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0061", SQLStringVisitor.getSQLString(value)), value); //$NON-NLS-1$
}
}
}
}
if (info != null && info.isInherentUpdate()) {
Set<ElementSymbol> updateCols = update.getChangeList().getClauseMap().keySet();
if (!info.hasValidUpdateMapping(updateCols)) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.nonUpdatable", updateCols), update); //$NON-NLS-1$
}
}
} catch(TeiidException e) {
handleException(e, update);