DAV_LOCK sets a new lock or refresh an existing lock or creates a lock object.
DAV_UNLOCK releases a lock.
DAV_IS_LOCKED reports whether the resource or collection is locked.
DAV_LIST_LOCKS returns a full list of all locks on a resource or collection.
It is strongly recommended to carefully study DAV standards before using these functions in applications. Improper use of DAV locks may result in subtle application errors that are hard to debug.
The following example shows how two users can prevent each other from undesired operations.
The sample function DAV_LOCK_DEMO() uses a function DUMP_VEC() that print the content of vector in Virtuoso/PL syntax. Yon can find the implementation of this function as one of examples for vector() Virtuoso/PL function.
create procedure DAV_LOCK_DEMO (in dav_passwd varchar := 'dav') { declare ACTION, RETVAL, token_s1, token_s2, token_x varchar; result_names (ACTION, RETVAL); result ('Adding group lock_demo_grp:', DAV_ADD_GROUP ('lock_demo_grp', 'dav', dav_passwd) ); result ('Adding user lock_u1:', DAV_ADD_USER ('lock_u1', 'lock_u1_pwd', 'lock_demo_grp', '110110000T', 0, '/DAV/lock_demo_u1_home/', 'First User of lock demo', 'lock_u1@localhost', 'dav', dav_passwd) ); result ('Adding user lock_u2:', DAV_ADD_USER ('lock_u2', 'lock_u2_pwd', 'lock_demo_grp', '110110000T', 0, '/DAV/lock_demo_u2_home/', 'Second User of lock demo', 'lock_u2@localhost', 'dav', dav_passwd) ); result ('Adding a collection:', DAV_COL_CREATE ('/DAV/lock_demo/', '110110000R', 'lock_u1', 'lock_demo_grp', 'dav', dav_passwd) ); result ('Uploading /DAV/lock_demo/sample.htm:', DAV_RES_UPLOAD ('/DAV/lock_demo/sample.htm', '<html><body>This is /DAV/lock_demo/sample.htm</body></html>', 'text/plain', '110110000R', 'lock_u1', 'lock_demo_grp', 'lock_u1', 'lock_u1_pwd') ); token_s1 := DAV_LOCK ('/DAV/lock_demo/sample.htm', '', 'S', NULL, 'user1@example.com', '', '0', NULL, 'lock_u1', 'lock_u1_pwd'); result ('First user set a shared lock:', token_s1); token_s2 := DAV_LOCK ('/DAV/lock_demo/sample.htm', '', 'S', NULL, 'user2@example.com', '', '0', NULL, 'lock_u2', 'lock_u2_pwd'); result ('Second user set a shared lock:', token_s2); token_x := DAV_LOCK ('/DAV/lock_demo/sample.htm', '', 'X', NULL, 'user1@example.com', token_s1, '0', NULL, 'lock_u1', 'lock_u1_pwd'); result ('Lock dump', DUMP_VEC (DAV_LIST_LOCKS (DAV_SEARCH_ID ('/DAV/lock_demo/sample.htm', 'R'), 'R')) ); result ('First user tries to set an exclusive lock:', token_x); result ('Second user releases his lock:', DAV_UNLOCK ('/DAV/lock_demo/sample.htm', token_s2, 'lock_u2', 'lock_u2_pwd') ); token_x := DAV_LOCK ('/DAV/lock_demo/sample.htm', '', 'X', NULL, 'user1@example.com', token_s1, '0', NULL, 'lock_u1', 'lock_u1_pwd'); result ('First user sets an exclusive lock:', token_x); result ('First user releases his lock:', DAV_UNLOCK ('/DAV/lock_demo/sample.htm', token_s1, 'lock_u1', 'lock_u1_pwd') ); token_x := DAV_LOCK ('/DAV/lock_demo/sample.htm', '', 'X', NULL, 'user1@example.com', token_s1, '0', NULL, 'lock_u1', 'lock_u1_pwd'); result ('First user sets an exclusive lock:', token_x); result ('Second user tries to add a property to the resource:', DAV_PROP_SET ('/DAV/lock_demo/sample.htm', 'sample_prop', 'sample value', 'lock_u2', 'lock_u2_pwd') ); result ('First user releases his shared:', DAV_UNLOCK ('/DAV/lock_demo/sample.htm', token_x, 'lock_u1', 'lock_u1_pwd') ); result ('Second user adds a property to the resource:', DAV_PROP_SET ('/DAV/lock_demo/sample.htm', 'sample_prop', 'sample value', 'lock_u2', 'lock_u2_pwd') ); } DAV_LOCK_DEMO (); ACTION RETVAL VARCHAR VARCHAR _______________________________________________________________________________ Adding group lock_demo_grp: 107 Adding user lock_u1: 108 Adding user lock_u2: 109 Adding a collection: 171 Uploading /DAV/lock_demo/sample.htm: 1103 First user set a shared lock: 1545ce54-3599-11da-8697-8f3efbd86ef2 Second user set a shared lock: 15460590-3599-11da-8697-8f3efbd86ef2 Lock dump vector ( vector ('', 'S', '1545ce54-3599-11da-8697-8f3efbd86ef2', 604800, 108, 'user1@example.com'), vector ('', 'S', '15460590-3599-11da-8697-8f3efbd86ef2', 604800, 109, 'user2@example.com')) First user tries to set an exclusive lock: -8 Second user releases his lock: 15460590-3599-11da-8697-8f3efbd86ef2 First user sets an exclusive lock: -8 First user releases his lock: 1545ce54-3599-11da-8697-8f3efbd86ef2 First user sets an exclusive lock: 1547251a-3599-11da-8697-8f3efbd86ef2 Second user tries to add a property to the resource: -8 First user releases his shared: 1547251a-3599-11da-8697-8f3efbd86ef2 Second user adds a property to the resource: 1321