List of methods assigned to table events

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

List of methods assigned to table events

Postby abeermann » Wed May 16, 2018 10:44 am

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
abeermann
 
Posts: 106
Joined: Fri Nov 26, 2010 12:46 pm

Re: List of methods assigned to table events

Postby Peter de Groot » Wed May 16, 2018 11:45 am

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
User avatar
Peter de Groot
 
Posts: 215
Joined: Thu Jan 10, 2008 8:38 pm
Location: Not sure...

Re: List of methods assigned to table events

Postby abeermann » Thu May 17, 2018 5:16 pm

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
Attachments
screenshot.1.jpg
screenshot.1.jpg (155.6 KiB) Viewed 2617 times
abeermann
 
Posts: 106
Joined: Fri Nov 26, 2010 12:46 pm

Re: List of methods assigned to table events

Postby mboegem » Thu May 17, 2018 5:44 pm

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
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 10 guests