USP_MKTSEGMENT_RELEASEAPPLOCK
Releases application resource locks for a segment and all of its selections, and conditionally release locks for all dependent selections for each selection of the segment.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@SEGMENTID | uniqueidentifier | IN | |
@INCLUDEDEPENDENTSELECTIONS | bit | IN |
Definition
Copy
CREATE procedure dbo.[USP_MKTSEGMENT_RELEASEAPPLOCK]
(
@SEGMENTID uniqueidentifier,
@INCLUDEDEPENDENTSELECTIONS bit = 0
)
as
set nocount on;
declare @LOCKNAME nvarchar(255);
/**********************************************/
/* Release the applock for the segment itself */
/**********************************************/
set @LOCKNAME = 'MKTSEGMENT:' + cast(@SEGMENTID as nvarchar(36));
if APPLOCK_MODE('public', @LOCKNAME, 'Session') <> 'NoLock'
exec sp_releaseapplock @Resource=@LOCKNAME, @LockOwner='Session';
/***************************************************************/
/* Release the applocks for all the selections of the segment, */
/* and all the selections used inside these selections. */
/***************************************************************/
declare @SELECTIONS table([ID] uniqueidentifier not null);
declare @SELECTIONID uniqueidentifier;
declare @QUERYDEFINITIONXML xml;
--Grab the selections for the segment into a temp table, so when we are waiting for a lock, we don't lock other things with our cursor...
insert into @SELECTIONS
select [SELECTIONID]
from dbo.[MKTSEGMENTSELECTION]
where [SEGMENTID] = @SEGMENTID;
--For each selection, release the applock and applocks for any dependent selections...
declare SELECTIONCURSOR cursor local fast_forward for
select [ID]
from @SELECTIONS;
open SELECTIONCURSOR;
fetch next from SELECTIONCURSOR into @SELECTIONID;
while (@@FETCH_STATUS = 0)
begin
--Release the applock for the selection...
exec dbo.[USP_IDSETREGISTER_RELEASEAPPLOCK] @SELECTIONID, @INCLUDEDEPENDENTSELECTIONS;
fetch next from SELECTIONCURSOR into @SELECTIONID;
end
close SELECTIONCURSOR;
deallocate SELECTIONCURSOR;
return 0;