I’ve got on Servoy difficulty I can use the lock on Servoy for an internal solution to a external application made in cobol I’m not getting to the lock !!
Please Help!!!
I’ve got on Servoy difficulty I can use the lock on Servoy for an internal solution to a external application made in cobol I’m not getting to the lock !!
Please Help!!!
Hi Felipe,
Can you show us how you try to get this lock ?
I use the following code
function lock(){
databaseManager.acquireLock(foundset,-1)
}
So you want to acquire a lock on ALL rows in that foundset.
You should check if it actually gets a lock. The function returns a true or false.
function lock(){
if ( databaseManager.acquireLock(foundset,-1) ) {
// we have a lock
} else {
// We couldn't require a lock.
}
}
So depending on your need you might want to put this in a while-loop (with a limit) to try gain a lock within x tries.
Something like this:
function lock(){
var _nCount = 0,
_bSuccess = false;
while ( _nCount < 100 || !_bSuccess ) {
_bSuccess = databaseManager.acquireLock(foundset,-1);
_nCount++;
// perhaps you want to add a application.sleep(100) here...
}
if ( _bSuccess ) {
// We have a lock!
} else {
// Couldn't get a lock in 100 tries
}
}
Hope this helps.
ROCLASI,
the problem is in an external application accessing the Servoy that no locks the record
Have you ever tested with external application?
I need a lock for the entire table from the database
felipebortoli017:
I need a lock for the entire table from the database
You mean for the foundset records?
Anyway Servoy lock is not a database lock, if you want to really lock the records in your database accessed also by other apps, have a look at the servoy admin pages for the “servoy.record.lock.lockInDB” option. Check your database server documentation first, every db behaves differently when locking records, some lock entire tables for updates, some other lock even for read operation.
cobol is an application accessing the base of postgresql
I guess the appropriate question here is what are you trying to do ? Why do you need to lock all these records ?
I have a Servoy application acessing a database (JDBC), reading one row with lock. The problem is:
One Servoy application reading one row with lock, when I open a second Servoy application, the lock works, the second application can’t read the row.
One Servoy application reading one row with lock, when I execute a COBOL application, trying to update the same row, the lock doesn’t work.
How can I change the configurations of locks on Servoy? Anyone had the same problem?
I tried to use this sintaxe on app server, but doesn’t work:
servoy.record.lock.lockInDB
Did you read my post?
Servoy lock is not a database lock, if you want to really lock the records in your database accessed also by other apps, have a look at the servoy admin pages for the “servoy.record.lock.lockInDB” option. Check your database server documentation first, every db behaves differently when locking records, some lock entire tables for updates, some other lock even for read operation.
Sorry, I didn’t finish typing.
Check how your db server is configured for locking, if things are set ok and you don’t see a lock in the db when you lock a servoy record submit a case to the support system.
Thanks to all
I’ll try some more tests, then put the result here
Hi Felipe,
PostgreSQL has a few ways to use explicit locking.
There are advisory locks but those locks are only enforced for other advisory locks.
If you want real locks then you can use SELECT … FOR UPDATE or LOCK TABLE.
And I guess you might want to do all this in a database transaction when used in Servoy so you keep using the same connection from the connection pool.
I am not sure if Servoy uses any of these out of the box (using the acquireLock function). Perhaps Rob Gansevles can answer that.
Hope this helps.
When the servoy.record.lock.lockInDB option is set to true and the acquireLock() call is running within a database transaction, then Servoy will try to do a query for the foundset records with a no-wait lock.
That means that when the data is already locked, the client will not block but return false to acquireLock().
This is only possible if the database (dialect) supports this.
Postgres does, we use ‘select … for update of … nowait’
When the dialect does support for-update select, but not the nowait option, we will fallback to that which means acquireLock() may block.
Hope this helps,
Rob
Thanks for the help, was the wrong commands. Below is one of the ways I decided:
Set up the parameter of Application Server.
servoy.record.lock.lockInDB= true
function startTransaction() {
databaseManager.startTransaction()
databaseManager.acquireLock(foundset,-1,‘lockPedido’);
}
function commitTransaction() {
databaseManager.releaseAllLocks(‘lockPedido’);
databaseManager.commitTransaction()
}
Thanks to all of you
just to chip in… locking and transactions especially onces that take quite long
And for me long transaction is one that if we look at the webclient, spawns over more then 1 request…
Try to avoid this! don’t try to have transactions and locks on record that go over multiply requests… Bad behavior is then just around the corner.
Use small transactions where you quickly update various rows that you accumulated along the way, and for locking just do it the other way around
When updating first check if a modification column is still the value you expect for this client, and if it isnt tell that to the user and say that he must re validate its input.