transaction Question ??

Questions, tips and tricks and techniques for scripting in Servoy

transaction Question ??

Postby wvitpr » Mon Jun 15, 2009 2:28 am

HI,
I would like to start using transactions for some of my methods, and am a little confused ??

Do I still need to a databaseManager.saveData() within the transaction. or does the databaseManager.commitTransaction() take care of that, really sorry if it is a stupid question, but I am not sure??
Regards,
Phillip Routley

Worldview IT
Sydney, Australia
User avatar
wvitpr
 
Posts: 219
Joined: Tue Apr 24, 2007 1:38 am

Re: transaction Question ??

Postby ROCLASI » Mon Jun 15, 2009 9:12 am

Hi Phillip,

There are 2 ways to use transactions.
1) let the back-end database handle the transactions using the following commands:
- databaseManager.startTransaction
- databaseManager.commitTransaction
- databaseManager.rollBackTransaction
Just keep in mind that some database back-ends (MySQL/MSSQL/etc.) use aggressive locking on the affected tables when using transactions so keep the transaction open as short as possible.

2) let Servoy handle the transaction in memory.
For this you need to disable autosave and handle the saving of the data to the back-end database yourself by using databaseManager.saveData() and rollback using databaseManager.rollbackEditedRecords().
Just keep in mind that deleting records will be send to the back-end immidiatly so you might want to use omit and some tracking for that.

You can mix 1 and 2 together if you want. Just make sure you saved the data to the back-end (databaseManager.saveData()) before you commit the database transaction (databaseManager.commitTransaction()).

Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: transaction Question ??

Postby wvitpr » Mon Jun 15, 2009 9:29 am

HI Robert,
Many thanks for you explaination, just one thing to confirm.

You can mix 1 and 2 together if you want. Just make sure you saved the data to the back-end (databaseManager.saveData()) before you commit the database transaction (databaseManager.commitTransaction()).

I still need to use the databaseManager.saveData() within the transaction ??? eg.

databaseManager.startTransaction

//do my job change this etc etc

databaseManager.saveData() //this has to be included ??

databaseManager.commitTransaction
OR
databaseManager.rollBackTransaction
Regards,
Phillip Routley

Worldview IT
Sydney, Australia
User avatar
wvitpr
 
Posts: 219
Joined: Tue Apr 24, 2007 1:38 am

Re: transaction Question ??

Postby ROCLASI » Mon Jun 15, 2009 1:08 pm

Hi Phillip,

When you mix 1 and 2 together then you also have autoSave off (method 2). So then you need to trigger the saving of data yourself using databaseManager.saveDate().

And when you mix it then you can use it in the following manner:

set autoSave off
edit your data
databaseManager.startTransaction
databaseManager.saveData()
check if any errors occured
commitTransaction/rollbackTransaction
set autoSave on

Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: transaction Question ??

Postby jcompagner » Mon Jun 15, 2009 1:20 pm

commitTransaction() will call saveData() itself
and if that saveData() doesnt reply correctly it will not try to commit and commitTransaction() will return false.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: transaction Question ??

Postby wvitpr » Mon Jun 15, 2009 1:30 pm

OK, no problems, thankyou
Regards,
Phillip Routley

Worldview IT
Sydney, Australia
User avatar
wvitpr
 
Posts: 219
Joined: Tue Apr 24, 2007 1:38 am


Return to Methods

Who is online

Users browsing this forum: No registered users and 34 guests