reading object from database field

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

reading object from database field

Postby jdbruijn » Fri Jul 29, 2011 5:12 pm

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.
Jos de Bruijn
Welcome CCS
Servoy Certified Developer
Image
jdbruijn
 
Posts: 445
Joined: Sun Apr 11, 2010 6:34 pm

Re: reading object from database field

Postby rgansevles » Mon Aug 01, 2011 3:05 pm

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
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1838
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: reading object from database field

Postby jdbruijn » Tue Aug 02, 2011 4:21 pm

Thx Rob,

Using switchServer fixed my problem.

Jos
Jos de Bruijn
Welcome CCS
Servoy Certified Developer
Image
jdbruijn
 
Posts: 445
Joined: Sun Apr 11, 2010 6:34 pm

Re: reading object from database field

Postby jdbruijn » Fri Aug 12, 2011 2:28 pm

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
Jos de Bruijn
Welcome CCS
Servoy Certified Developer
Image
jdbruijn
 
Posts: 445
Joined: Sun Apr 11, 2010 6:34 pm

Re: reading object from database field

Postby jdbruijn » Fri Aug 12, 2011 2:40 pm

I forgot to mention that I've upgraded to servoy 6 in my development and test environment
Jos de Bruijn
Welcome CCS
Servoy Certified Developer
Image
jdbruijn
 
Posts: 445
Joined: Sun Apr 11, 2010 6:34 pm

Re: reading object from database field

Postby rgansevles » Mon Aug 15, 2011 11:45 am

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
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1838
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: reading object from database field

Postby jdbruijn » Mon Aug 15, 2011 12:31 pm

Thx Rob,

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

Jos.
Jos de Bruijn
Welcome CCS
Servoy Certified Developer
Image
jdbruijn
 
Posts: 445
Joined: Sun Apr 11, 2010 6:34 pm


Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 2 guests