Tasked to create a script (JSERV) to add check constraint for columns of all tables under a package/sub-package whose name ending '_IND' and of CHAR data type.
I know how to write the script to navigate a selected package and to create a check constraint for columns meeting the criteria as shown below:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.......
// Add check constraint for the attribute intended
if ( currentAttribute.Name.substring(currentAttribute.Name.length-4)== "_IND" && currentAttribute.Type == "CHAR" )
{
//checking if the check constriant already exists
var chk_exists = false;
for( var j = 0; j < methodsCollection.Count; j++ )
{
var method as EA.Method;
method = methodsCollection.GetAt( j );
if( method == null )
continue;
//Session.Output("method: "+method.Name);
if ( method.Name == "CK_"+ currentAttribute.Name.substring(0,Math.min(currentAttribute.Name.length,27)) )
{
chk_exists = true;
break;
}
}
if ( chk_exists == false )
{
var Methods as EA.Collection;
Methods = theElement.Methods;
var newMethod as EA.Method;
newMethod = Methods.addNew( "CK_"+currentAttribute.Name.substring(0,Math.min(currentAttribute.Name.length,27)),"");
newMethod.Stereotype="check"
newMethod.Code=currentAttribute.Name+" in ('Y','N')"
newMethod.Update();
Methods.Refresh();
Session.Output( " Added Check constraint: " + newMethod.Name +
" (Type=" + newMethod.Stereotype +
", ID=" + newMethod.MethodID + ")" );
}
else
....
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
However, I don't know what object/API to use to specify the related column for the check constraint created, as one can do manually via table properties, in other words, how to add a record into the SPARX repository table t_operationparams (information only, it does not actually prevent me to generate correct check constraint under ORACLE target platform once the check constraint is created. Attempted the following however, it had not worked:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
......
var Methods as EA.Collection;
Methods = theElement.Methods;
var newMethod as EA.Method;
newMethod = Methods.addNew( "CK_"+currentAttribute.Name.substring(0,Math.min(currentAttribute.Name.length,27)),"");
newMethod.Stereotype="check"
newMethod.Code=currentAttribute.Name+" in ('Y','N')"
newMethod.Update();
Methods.Refresh();
[highlight]var MethodsPara as EA.Collection;
MethodsPara = newMethod.Parameters
var newMethodPara as EA.Parameter;
newMethodPara=MethodsPara.AddNew(currentAttribute.Name,"CHAR");[/highlight]
Session.Output( " Added Check constraint: " + newMethod.Name +
" (Type=" + newMethod.Stereotype +
", ID=" + newMethod.MethodID + ")" );
.....
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Could anyone shed some light on me? Many thanks in advance.