__SEND_MESG_DEBUG("Entering updateTarget for class_name:'%s' method_name:'%s' ", class_name, method_name)
//getting info from vtable
coa_AppendElement(cnx, get_class_names, "meta_vtable");
coa_AppendElement(cnx, get_prop_names, "id");
coa_AppendElement(cnx, get_class_names, "meta_vtable");
coa_AppendElement(cnx, get_prop_names, "target_class_name");
coa_AppendElement(cnx, filter_class_names, "meta_vtable");
coa_AppendElement(cnx, filter_prop_names, "class_name");
coa_AppendElement(cnx, filter_operators, "=");
coa_AppendCopyOfElement(cnx, filter_values, class_name);
coa_AppendElement(cnx, filter_class_names, "meta_vtable");
coa_AppendElement(cnx, filter_prop_names, "method_name");
coa_AppendElement(cnx, filter_operators, "=");
coa_AppendCopyOfElement(cnx, filter_values, method_name);
@co_lcall(par_area,'"meta_vtable"',"selectX",par_area=>par_area,par_class=>'"meta_vtable"',par_id=>-1, get_class_names=>get_class_names,get_prop_names=>get_prop_names, filter_class_names=>filter_class_names,filter_prop_names=>filter_prop_names, filter_operators=>filter_operators, filter_values=>filter_values);
__GET_RETURNED_RECORDSET(corec)
__SEND_MESG_DEBUG("we have corec")
NTuples = cor_GetTupleCount(cnx, corec);
__ASSERT(NTuples<2,"HARD CORE ERROR - more than one record in meta_vtable for class:%s, method:%s",class_name, method_name)
__SEND_MESG_DEBUG("we have NTuples: %d", NTuples)
if(NTuples==0)
{
// super-new
//1. insert into meta_vtable
//TODO: check whether these values are valid
coa_AppendElement(cnx, create_params, "method_name");
coa_AppendCopyOfElement(cnx, create_params, method_name);
coa_AppendElement(cnx, create_params, "class_name");
coa_AppendCopyOfElement(cnx, create_params, class_name);
coa_AppendElement(cnx, create_params, "target_class_name");
coa_AppendCopyOfElement(cnx, create_params, target_class);
str_id_permission = ap_psprintf(p, "%d", id_permission);
coa_AppendElement(cnx, create_params, "id_permission");
coa_AppendCopyOfElement(cnx, create_params, str_id_permission);
str_sec_type = ap_psprintf(p, "%d", sec_type);
coa_AppendElement(cnx, create_params, "sec_type");
coa_AppendCopyOfElement(cnx, create_params, str_sec_type);
str_force_sec_type = ap_psprintf(p, "%d", force_sec_type);
coa_AppendElement(cnx, create_params, "force_sec_type");
coa_AppendCopyOfElement(cnx, create_params, str_force_sec_type);
@co_lcall(par_area,'"meta_vtable"',"createAndSetWithACL",par_area=>par_area,par_class=>'"meta_vtable"',par_id=>-1,create_params=>create_params);
do_for_sub_class=1;
}
if(NTuples==1)
{
//overloaded
// first we check if we implement this method on this level
char * target_class_name = cor_GetValueByName(cnx, corec, 0, "target_class_name");
if(strcmp(target_class_name, class_name)!=0)
{
// if this inherited method then we change target class
//TODO: what about sec, force_sec and others?
int id_vtable = atoi(cor_GetValueByName(cnx, corec, 0, "id"));
@co_call(par_area, '"meta_vtable"', "update",par_area=>par_area, par_class=>'"meta_vtable"',par_id=>id_vtable,par_prop=>'"target_class_name"',new_value=>target_class);
do_for_sub_class=1;
}
}
if(do_for_sub_class==1)
{
// we call updateTarget for all sub-classes
__SEND_MESG_DEBUG("getting id for class_name:%s", class_name)
@co_filterByProp(par_area, '"meta_class"', '"id"', '"class_name"', class_name);
NClasses = cor_GetTupleCount(cnx,corec);
__ASSERT(NClasses==1, "More then one or 0 records in meta_class for class_name:%s", class_name)
id_class = atoi(cor_GetValue(cnx, corec, 0, 0));
@co_lcall(par_area,'"meta_class"', "getRelatedData", par_area=>par_area,par_class=>'"meta_class"',par_id=>id_class, related_class=>'"meta_class"',related_prop=>'"inherits_from"');
__SEND_MESG_DEBUG("related classes finished!")
{
co_recordset * corec2;
co_array_of_pointers * sub_class_names;
int NElems=0;
// we implicitly clear corec!
__GET_RETURNED_RECORDSET(corec2)
__SEND_MESG_DEBUG("we have recordset")
NClasses = cor_GetTupleCount(cnx, corec2);
__SEND_MESG_DEBUG("Number of sub-classes:%d", NClasses)
sub_class_names = cor_GetCopyOfColumnByName(cnx, corec2, "class_name");
__ASSERT(sub_class_names!=NULL, "Error in getting array of sub-class names")
NElems = coa_GetElementCount(cnx, sub_class_names);
__ASSERT(NElems>-1, "Error in getting number of elements for array of sub-class names")
__SEND_MESG_DEBUG("we have column with sub_class_names NEl: %d", NElems);
__ASSERT(NElems==NClasses, "HARD CORE ERROR number of elements not equal to number of tuples after cor_GetCopyOfColumnByName")
for(i=0; i<NClasses; i++)
{
char * sub_class_name;
__SEND_MESG_DEBUG("Getting sub_class_name i:%d NClasses:%d", i, NClasses)
sub_class_name = coa_GetStringElement(cnx, sub_class_names, i);
__SEND_MESG_DEBUG("Calling updateTarget for class_name:'%s' method_name:'%s' i:%d NClasses:%d", sub_class_name, method_name, i, NClasses)
@co_call(par_area,'"meta_vtable"',"updateTarget", par_area=>par_area, par_class=>'"meta_vtable"', par_id=>-1, class_name=>sub_class_name, method_name=>method_name, target_class=>target_class, id_permission=>id_permission, sec_type=>sec_type, force_sec_type=>force_sec_type);
__SEND_MESG_DEBUG("After call updateTarget for class_name:'%s' method_name:'%s' i:%d NClasses:%d", sub_class_name, method_name, i, NClasses)
}
}
__SEND_MESG_DEBUG("Finished updateTarget for class_name:'%s' method_name:'%s' ", class_name, method_name)
}