Skip to content

Commit

Permalink
TEIIDDES-2198 added handling of virtual parameter changes to force
Browse files Browse the repository at this point in the history
re-validation of the virtual procedure transformation
  • Loading branch information
blafond committed Jul 8, 2014
1 parent 057d544 commit 585323d
Showing 1 changed file with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down Expand Up @@ -48,6 +49,7 @@
import org.teiid.designer.diagram.ui.util.DiagramUiUtilities;
import org.teiid.designer.metamodels.core.ModelAnnotation;
import org.teiid.designer.metamodels.function.ScalarFunction;
import org.teiid.designer.metamodels.relational.ProcedureParameter;
import org.teiid.designer.metamodels.relational.Table;
import org.teiid.designer.metamodels.transformation.SqlAlias;
import org.teiid.designer.metamodels.transformation.SqlTransformation;
Expand Down Expand Up @@ -272,6 +274,13 @@ private void handleNotifications( Collection notifications,
if (!resultSetAdds.isEmpty()) {
handleTargetProcedureResultSetOrParamAddNotifications(resultSetAdds, source);
}

// Procedure Parameter Changed
// ---------------------------------------------
Collection procedParamChanges = getTargetProcedureParamChangeNotifications(validNotifications);
if (!procedParamChanges.isEmpty()) {
handleTargetProcedureParamChangeNotifications(procedParamChanges, source);
}
// ---------------------------------------------
// Procedure ResultSet Removed
// ---------------------------------------------
Expand Down Expand Up @@ -864,7 +873,7 @@ private Collection getTargetProcedureResultSetOrParamAddNotifications( Collectio
Iterator iter = notifications.iterator();
while (iter.hasNext()) {
Notification notification = (Notification)iter.next();
if (NotificationUtilities.isAdded(notification)) {
if (NotificationUtilities.isAdded(notification) ) {
// Get the object that was added to - Procedure in this case
Object changedObj = ModelerCore.getModelEditor().getChangedObject(notification);
if (TransformationHelper.isSqlVirtualProcedure(changedObj)
Expand All @@ -883,6 +892,40 @@ private Collection getTargetProcedureResultSetOrParamAddNotifications( Collectio
}
return result;
}

/*
* Get all Procedure Parameter Change Notifications. (When Parameters are changed (i.e. datatype, name, etc))
*
* @param notifications the collection of all notifications
* @return the Procedure ResultSet Add Notifications
*/
private Collection getTargetProcedureParamChangeNotifications( Collection notifications ) {
Collection result = null;
Iterator iter = notifications.iterator();
while (iter.hasNext()) {
Notification notification = (Notification)iter.next();

if( NotificationUtilities.isChanged(notification)) {
Object changedObj = ModelerCore.getModelEditor().getChangedObject(notification);
if( changedObj instanceof ProcedureParameter ) {
Object procedure = ((ProcedureParameter)changedObj).getProcedure();
if (TransformationHelper.isSqlVirtualProcedure(procedure)
&& TransformationHelper.isValidSqlTransformationTarget(procedure)) {
if (result == null) {
result = new ArrayList(notifications.size());
}
result.add(notification);
// Remove from notifications collection
iter.remove();
}
}
}
}
if (result == null) {
result = Collections.EMPTY_LIST;
}
return result;
}

/*
* Get all Procedure ResultSet Remove Notifications. (When resultSets are removed from procedures)
Expand Down Expand Up @@ -1705,6 +1748,40 @@ private void handleTargetProcedureResultSetOrParamAddNotifications( Collection n

}
}

/*
* Handler method for Procedure Parameter Change notifications.
*
* @param notifications the collection of notifications
* @param txnSource the source for the transaction
*/
private void handleTargetProcedureParamChangeNotifications( Collection notifications,
Object txnSource ) {
if (!notifications.isEmpty()) {
// Get mapping root for the SqlTransformation
EObject mappingRoot = getMappingRootFromProcParamNotifications(notifications);
// start txn if not already in txn
boolean requiredStart = ModelerCore.startTxn(NOT_SIGNIFICANT, IS_UNDOABLE, "Update attr mappings", this); //$NON-NLS-1$
boolean succeeded = false;
try {
// Invalidate cached Status regardless of resultSet or parameter addition
SqlMappingRootCache.invalidateSelectStatus(mappingRoot, true, txnSource);
// Update attribute mappings
AttributeMappingHelper.updateAttributeMappings(mappingRoot, txnSource);
succeeded = true;
} finally {
// If we start txn, commit it
if (requiredStart) {
if (succeeded) {
ModelerCore.commitTxn();
} else {
ModelerCore.rollbackTxn();
}
}
}

}
}

/*
* Handler method for Procedure ResultSet or Parameter Remove notifications. The removed objects
Expand Down Expand Up @@ -1894,6 +1971,26 @@ private EObject getMappingRootFromProcResultSetOrParamNotifications( Collection
}
return mappingRoot;
}

/*
* Get MappingRoot from Procedure Parameter Notifications
* @param parameterNotifications the Procedure Parameter Notifications
* @return the mappingRoot EObject
*/
private EObject getMappingRootFromProcParamNotifications( Collection parameterNotifications ) {
EObject mappingRoot = null;
Iterator iter = parameterNotifications.iterator();
Notification firstNotification = (Notification)iter.next();
if (firstNotification != null) {
// The changed Object is the Procedure
Object parameter = ModelerCore.getModelEditor().getChangedObject(firstNotification);
if (TransformationHelper.isSqlProcedureParameter(parameter)) {
// Mapping root for the SqlTransformation
mappingRoot = TransformationHelper.getTransformationMappingRoot((EObject)((ProcedureParameter)parameter).getProcedure());
}
}
return mappingRoot;
}

/*
* Get MappingRoot from UID SqlStatement change Notifications
Expand Down

0 comments on commit 585323d

Please sign in to comment.