Page 1 of 1

reading object from database field

PostPosted: Fri Jul 29, 2011 5:12 pm
by jdbruijn
Is there a known issue with reading an object from a databasefield with the stringserializer? Because I cannot get it working from the batchprocessor, while it is working from the developer.

I've got a batch processor that first retrieves a list of tenant databases. Next it needs to read the settings from each database. However it is not returning my settings object!
Code: Select all
   for(var j = 0; j < dbs.length; j++) //dbs is my array of tenant databases
   {
      fsSettings = databaseManager.getFoundSet(dbs[j],'prontogeneral')
      fsSettings.addFoundSetFilterParam('prontogeneral_id','=','3');
      fsSettings.loadAllRecords();
      if(fsSettings.getSize() == 1)
      {
         inbox = new Object();
         inbox = fsSettings.pronto_obj; // this field is in each tenant db a text field with stringserializer enabled
         if(inbox && inbox.active) {
            _mailboxes.push(inbox);
         }
         else
         {
            if(inbox) {
               application.output("TESTING inbox active "+inbox.active, LOGGINGLEVEL.INFO)
            }
         }
      }
   }

When I look at the last output string I get the value when I run inside developer but an undefined when i run the batchprocessor.

Re: reading object from database field

PostPosted: Mon Aug 01, 2011 3:05 pm
by rgansevles
jdbruijn,

Have you checked the data is actually in all these dbs?

When you access these tenant dbs via databasemanager.switchServer(), the column settings (which contains the stringserializer def) of the main db are used.
But when you access the tenant dbs directly as in your example, the column definitions as stored with the tenant dbs is used, this may be different.

Can you try something like this?
Code: Select all
// main tenant db is called main, others are called tenant_[i]n[/i]
success = databasemanager.switch_server('main', 'tenant_1')
fsSettings = databaseManager.getFoundSet('main','prontogeneral')
...
success = databasemanager.switch_server('main', 'tenant_2')
fsSettings = databaseManager.getFoundSet('main','prontogeneral')
...
success = databasemanager.switch_server('main', 'tenant_99')
fsSettings = databaseManager.getFoundSet('main','prontogeneral')
...

// switch back to original
databasemanager.switch_server('main', 'main')


Rob

Re: reading object from database field

PostPosted: Tue Aug 02, 2011 4:21 pm
by jdbruijn
Thx Rob,

Using switchServer fixed my problem.

Jos

Re: reading object from database field

PostPosted: Fri Aug 12, 2011 2:28 pm
by jdbruijn
I'm afraid my batch proces is still not reading the object correctly from the database.
I'm using the following code now:
Code: Select all
/**
* @param {Array} _mailboxes
* @properties={typeid:24,uuid:"A3CC3B2E-C38B-4710-A1F8-43DA2D28BE78"}
*/
function loadInboxSettings(_mailboxes)
{
   /** @type {JSFoundset<db:/svy_framework/sec_owner>} */
   var fsOwners = databaseManager.getFoundSet('svy_framework', 'sec_owner');
   var dbs = new Array();
   /** @type {{server:String, login:String, pwd:String, active:Boolean}} */
   var inbox
   
   fsOwners.loadAllRecords();
   for(var i = 0; i < fsOwners.getSize();i++)
   {
      fsOwners.setSelectedIndex(i+1);
      dbs[i] = fsOwners.database_name;
      if(dbs[i] == '')
         dbs[i] = 'welcome';
   }
   application.output("loadInboxSettings - dbs: "+dbs, LOGGINGLEVEL.INFO);   
   /** @type {JSFoundset<db:/welcome/prontogeneral>} */
   var fsSettings;
   for(var j = 0; j < dbs.length; j++)
   {
      if(!databaseManager.switchServer('welcome',dbs[j])) {
         application.output("loadInboxSettings - Failed to switch to: "+dbs[j], LOGGINGLEVEL.ERROR)
      } else {
         application.output("loadInboxSettings - Switched to: "+dbs[j], LOGGINGLEVEL.INFO)
      }
      fsSettings = databaseManager.getFoundSet(dbs[j],'prontogeneral')
      fsSettings.addFoundSetFilterParam('prontogeneral_id','=','3');
      fsSettings.loadAllRecords();
      if(fsSettings.getSize() == 1)
      {
         inbox = new Object();
         inbox = fsSettings.pronto_obj;
         application.output("loadInboxSettings: "+inbox)
         if(inbox) {
            application.output("loadInboxSettings: "+inbox.server)
            if(inbox.active) {
            _mailboxes.push(inbox);
            } else{
               application.output("loadInboxSettings inbox not active: "+inbox.active)
            }
         }else {
            application.output("loadInboxSettings no inbox loaded: "+inbox)
         }
      }
   }
   application.output(_mailboxes.length + " mailboxes ready for proces", LOGGINGLEVEL.INFO)   
}


When I run this solution from my developer it reads the inbox objects correctly for all databases, but running in the test server it seems that the serializer is not used for the tenant databases.
The following loglines are from the test server, first part is the default server and next a tenant database:
Code: Select all
loadInboxSettings - Switched to: welcome
loadInboxSettings: [object Object]
loadInboxSettings: exchange.local

loadInboxSettings - Switched to: FBricks_Demo
loadInboxSettings: {"_server":"exchange.local","_database":"FBricks_Demo","_active":1,"_pwd":"RL7wWt6LmUhSVNMh13o4+A==","javaClass":"org.mozilla.javascript.NativeObject","_login":"demo"}
loadInboxSettings: undefined

Re: reading object from database field

PostPosted: Fri Aug 12, 2011 2:40 pm
by jdbruijn
I forgot to mention that I've upgraded to servoy 6 in my development and test environment

Re: reading object from database field

PostPosted: Mon Aug 15, 2011 11:45 am
by rgansevles
Jos,

Code: Select all
fsSettings = databaseManager.getFoundSet(dbs[j],'prontogeneral')


should be

Code: Select all
fsSettings = databaseManager.getFoundSet('welcome','prontogeneral')



Switch-server is transparent to js client code, you always program against the designed db.

Rob

Re: reading object from database field

PostPosted: Mon Aug 15, 2011 12:31 pm
by jdbruijn
Thx Rob,

:oops: I should have read your earlier post more carefully :oops:

Jos.