Updating Remote Offline Solutions - How To

Discuss the Offline version of Servoy that allows you to run Servoy applications on and offline by using synchronization technology like Mobilink and SQL Remote.

Updating Remote Offline Solutions - How To

Postby dpearce » Mon Apr 06, 2009 10:48 pm

Having struggled for a number of weeks to work out a way to update servoy offline solutions, I thought I should share my successful attempt, so that others may improve upon it!

The core principles are:
1. to put you updated repository db file into an ftp site.
2. Have an update table on your remote server, which has two main fields - a version field and a sqltext field (the latter is so that you can update any fields or changes in your solution data table.
3. Check the remote server to see if you have versions higher than you current solution version and I have just used the number in the label i display on my login page.
4. If this is higher then firstly run through all the lines of sqltext in order for all higher versions and make the local changes using the rawsql plugin.
5. FTP the repository.db file to a new directory.
6. Now the tricky but, which seems to work, so i assume that the script continues to work in memory once sybase is shut down. You need to shut sybase down so that you can move the files around. you need to have a batch script for windows and a terminal script for mac that switches off sybase. I put this in the root directory of my servoy offline solution.
7. Now we run that as an external program and then complete some moves to back-up the old repository and log and move the new one into the database directory. (i have a folder called new and old in my database dir.)
8. A bit weird as we are now running servoy developer without the sybase repository running, so close the application.
9. On restart, the new repository swings into action and any database changes you made to the data table!

My complete script is:
Code: Select all
//first lets check the version number
var currentver=utils.stringToNumber(forms.login.elements.version.text)*100

//Get a dataset based on query
var maxReturnedRows = 100;//useful to limit number of rows
var query = 'select copy,sqltext from prefs where copy >? order by copy asc;';
var args = new Array();
args[0] = currentver
var dataset = databaseManager.getDataSetByQuery('reportwriter_server', query, args, maxReturnedRows);

application.output(currentver +' -- '+dataset.getValue(1,1))

if (currentver < (dataset.getValue(1,1)))

var thePressedButton = plugins.dialogs.showQuestionDialog('Update Available', 'A newer version of Corex is available. Updating corex will take about 30 seconds','Update Now','Remind Me Later');

if (thePressedButton=='Update Now')

//show dialog
var thePressedButton = plugins.dialogs.showInfoDialog('Warning', 'Corex will Quit as soon as the update is complete\
Starting it again will conclde the update','OK','Cancel');

if (thePressedButton =='OK')

//Show Progress
forms.login.elements.progress_lbl.visible= true
forms.login.elements.progress.visible = true // show  progress bar
forms.login.elements.progress.orientation = 0 //(0=hor(default) 1=vertical)
forms.login.elements.progress.stringPainted = true // enables showing strings inside the progres bar
forms.login.elements.progress.string = "Downloading Update..."

   for ( var j = 1 ; j <= dataset.getMaxRowIndex(); j++ )

      if (dataset.getValue(j,2))
      var sqltoexec=dataset.getValue(j,2).split('\n')

      for ( var i = 0 ; i < sqltoexec.length; i++ )
         var done = plugins.rawSQL.executeSQL("reportwriter",utils.stringMiddleWords(sqltoexec[i], 3, 1),sqltoexec[i]);
         if (done)
               //flush is required when changes are made in db
               plugins.rawSQL.flushAllClientsCache("reportwriter",utils.stringMiddleWords(sqltoexec[i], 3, 1))
            var msg = plugins.rawSQL.getException().getMessage(); //see exception node for more info about the exception obj
            plugins.dialogs.showErrorDialog('Error',  'SQL exception: '+msg,  'Ok')


var FTPClient = new Packages.sun.net.ftp.FtpClient(); 
FTPClient.login("updateservoy", "bhjbbhjh676t"); 

var buffered_input_stream = new Packages.java.io.BufferedInputStream(FTPClient.get("servoy_repository.db")); 
var output_stream = new Packages.java.io.FileOutputStream("database/new/servoy_repository.db"); 
buffered_output_stream = new Packages.java.io.BufferedOutputStream(output_stream); 
var buffer = new Packages.java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024); 
var read_count = 0;   while((read_count = buffered_input_stream.read(buffer)) > 0) 

buffered_output_stream.write(buffer, 0, read_count); 



if (application.getOSName()==='Windows XP' || application.getOSName()==='Windows Vista')
var program_output = application.executeProgram('update.bat');

var parsedDate = utils.dateFormat(new Date(),'ddMMyyyyHHmmss');

plugins.file.moveFile('database/servoy_repository.db', 'database/old/'+parsedDate+'servoy_repository.db')
plugins.file.moveFile('database/servoy_repository.log', 'database/old/'+parsedDate+'servoy_repository.log')
plugins.file.moveFile('database/new/servoy_repository.db', 'database/servoy_repository.db')



var program_output = application.executeProgram('./update.command');

var parsedDate = utils.dateFormat(new Date(),'ddMMyyyyHHmmss');

plugins.file.moveFile('database/servoy_repository.db', 'database/old/'+parsedDate+'servoy_repository.db')
plugins.file.moveFile('database/servoy_repository.log', 'database/old/'+parsedDate+'servoy_repository.log')
plugins.file.moveFile('database/new/servoy_repository.db', 'database/servoy_repository.db')




my bat file for windows is:
Code: Select all
TASKKILL /IM dbsrv10.exe
TASKKILL /F /IM dbsrv10.exe

(may not need both!!)

for mac is:

Code: Select all
here="`dirname \"$0\"`"
cd "$here"
for X in `ps acx | grep -i 'dbsrv10' | awk {'print $1'}`; do   kill $X;

It seems to work fairly seamlessly and the old repository is in the old folder in case anything goes wrong!

Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Updating Remote Offline Solutions - How To

Postby antonio » Sun Apr 19, 2009 6:28 pm

You could also look at this (Servoy 3.x)


and this for rolling back solutions
Servoy Developer Version 5.2.16
Developer MAC OSX 10.8.4 Java version 1.6.0_51
Production Debian Linux Java version 1.6.0_29
Posts: 622
Joined: Sun Apr 02, 2006 2:14 am
Location: Australia

Return to Servoy Offline Client

Who is online

Users browsing this forum: Bing [Bot] and 1 guest