Page 1 of 1

List of methods assigned to table events

PostPosted: Wed May 16, 2018 10:44 am
by abeermann
Hello Everybody

I need a list of all tables from a server and all the methods which are assigned to the onAfterInsert and onAfterUpdate events from different solutions.
The result should be something like this:

table1 solution_x onAfterInsert = methodA
table1 solution_y onAfterInsert = methodB
table1 solution_z onAfterInsert = methodA
table1 solution_x onAfterUpdate = methodx
table1 solution_y onAfterUpdate = null
table1 solution_z onAfterUpdate = methodz

table2 solution_x onAfterInsert = null
table2 solution_y onAfterInsert = methodB2
table2 solution_z onAfterInsert = methodA2
table2 solution_x onAfterUpdate = null
table2 solution_y onAfterUpdate = method11y
table2 solution_z onAfterUpdate = method22z

I start with:
var allTabs = databaseManager.getTableNames(servername);
(this will be more than 500 tables!)

But how to continue?
Any help/example welcomed?
Best regards
Albert

Re: List of methods assigned to table events

PostPosted: Wed May 16, 2018 11:45 am
by Peter de Groot
Hi,

Run code below to get the table methods (I use the Usermanager plugin)


Code: Select all
function tableMethods() {
   var $i, $j, $k, $servers, $tables;
   
   $servers   = plugins.UserManager.Server().getDbConnectionInfos();
   
   for($i = 0 ; $i < $servers.length ; $i++){
      if(!$servers[$i][0])continue
      getDbTables();
   }
   

   
   function getDbTables() {
      $tables   = databaseManager.getTableNames($servers[$i][0]);
      if(!$tables)return;
      
      for($j = 0 ; $j < $tables.length ; $j++){
         getTableMethods()
      }
   }
   
   function getTableMethods() {
      var $table = databaseManager.getDataSource($servers[$i][0],$tables[$j])
      var $method = solutionModel.getDataSourceNode($table).getMethods();
      
      
      
      if($method.length > 0){
         for($k = 0 ; $k < $method.length ; $k++){
            application.output('DB [' +$servers[$i][0]+'] TABLE ['+ $tables[$j] +']  METHOD [' + $method[$k].getName()+']');
         }
         
      }
      
   }
   
}


This is the result,
DB [mneme] TABLE [additional_levels] METHOD [new_method]
DB [pbs] TABLE [_table_] METHOD [new_method]
DB [pbs] TABLE [iso] METHOD [onRecordInsert]
DB [pbs] TABLE [iso] METHOD [onRecordUpdate]


Regards,

Peter

Re: List of methods assigned to table events

PostPosted: Thu May 17, 2018 5:16 pm
by abeermann
Hello Peter

Thank you for your quick answer, but no success?

I tried the following on a small test db:
function welcheTabellenMethoden() {
//var servername = 'maxdb';
var servername = 'pugbilder';
var alletabellen = databaseManager.getTableNames(servername);
application.output("Start");
application.output(alletabellen);

var vmax = alletabellen.length
for (var index = 0; index < vmax; index++) {
var tabellenname = alletabellen[index];

/** @type {String} */
var tabellenDS = databaseManager.getDataSource(servername, tabellenname);
var tabellenMethoden = solutionModel.getDataSourceNode(tabellenDS).getMethods();

var vmmax = tabellenMethoden.length;
if (vmmax > 0) {
for (var mindex = 0; mindex < vmmax; mindex++) {
application.output('DB [' + servername + '] TABLE [' + tabellenname + '] METHOD [' + tabellenMethoden[mindex].getName() + ']');
}
}
}
}


Start
[bilder, dokumente]

Application.output shows the tables, but no methods found.(no further output??)
What i wanted to find is in the attachment.
I need to find out, that the solution PUG_Default_Forms fires the method "notNullDefaultsSetzen" onRecordInsert and onRecordUpdate of table "bilder" .(screenshot).

Regards
Albert

Re: List of methods assigned to table events

PostPosted: Thu May 17, 2018 5:44 pm
by mboegem
Hello Albert,

to get the methods on a datasource as in the example code, will return the methods as defined in the entity scope.
This will not return the methods bound to the database events as you requested.

AFAIK, there's no way to retrieve this programmatically, but if you do a search in Eclipse (ctrl-H) > tab "file search", you can at least extract a list with methodID's

You should search for the string 'on*MethodID' and set the filename pattern to *.tbl
The result should look something like this:
Code: Select all
onAfterCreateMethodID:"79E5383E-133D-4367-B2C1-C7291720AE38",
onDeleteMethodID:"732E7B06-C063-4560-AA82-C2A8E8BFCEB4",
onInsertMethodID:"D42A8FC8-E394-4C51-9DD3-2C68FE71F651",
onUpdateMethodID:"D0C2D667-1971-419C-991F-99F48C2467DC",


I guess if you want to take this a step further, you can copy paste the result in a textfile and write a simple script to parse the unique methodID's from this file.

Hope this helps