USP_IDSETREGISTER_GETAPPLOCK
Acquires an application resource lock for a selection, and conditionally acquire locks for all dependent selections of the specified selection.
Parameters
| Parameter | Parameter Type | Mode | Description |
|---|---|---|---|
| @IDSETREGISTERID | uniqueidentifier | IN | |
| @INCLUDEDEPENDENTSELECTIONS | bit | IN |
Definition
Copy
create procedure dbo.[USP_IDSETREGISTER_GETAPPLOCK]
(
@IDSETREGISTERID uniqueidentifier,
@INCLUDEDEPENDENTSELECTIONS bit = 0
)
as
set nocount on;
declare @LOCKNAME nvarchar(255);
declare @LOCKRESULT int;
--Get the applock for the selection...
set @LOCKNAME = 'IDSETREGISTER:' + cast(@IDSETREGISTERID as nvarchar(36));
exec @LOCKRESULT = sp_getapplock @Resource=@LOCKNAME, @LockMode='Exclusive', @LockOwner='Session', @LockTimeout=3600000;
if @LOCKRESULT < 0
begin
raiserror('A failure or timeout occurred while requesting an app lock for a selection.', 13, 1);
return @LOCKRESULT;
end
--Get applocks for the dependent selections that are used by the selection...
if @INCLUDEDEPENDENTSELECTIONS = 1
begin
declare @QUERYDEFINITIONXML xml;
select @QUERYDEFINITIONXML = [ADHOCQUERY].[QUERYDEFINITIONXML]
from dbo.[IDSETREGISTERADHOCQUERY]
inner join dbo.[ADHOCQUERY] on [ADHOCQUERY].[ID] = [IDSETREGISTERADHOCQUERY].[ADHOCQUERYID]
where [IDSETREGISTERADHOCQUERY].[IDSETREGISTERID] = @IDSETREGISTERID;
--We can only find dependent selections for adhoc query based selections, so ignore dependent selection processing for smart query and custom based selections...
if @QUERYDEFINITIONXML is not null
begin
declare @DEPENDENTSELECTIONID uniqueidentifier;
declare DEPENDENTSELECTIONCURSOR cursor local fast_forward for
select T.c.value('declare namespace AQ="Blackbaud.AppFx.WebService.API.1";(AQ:IDSetFieldInfo/AQ:ID)[1]', 'uniqueidentifier')
from @QUERYDEFINITIONXML.nodes('declare namespace AQ="Blackbaud.AppFx.WebService.API.1";/AQ:AdHocQuery/AQ:FilterFields/AQ:f') T(c)
where T.c.value('@IsIDSetField', 'bit') = 1;
open DEPENDENTSELECTIONCURSOR;
fetch next from DEPENDENTSELECTIONCURSOR into @DEPENDENTSELECTIONID;
while (@@FETCH_STATUS = 0)
begin
--Get the applock for the dependent selection...
exec dbo.[USP_IDSETREGISTER_GETAPPLOCK] @DEPENDENTSELECTIONID, @INCLUDEDEPENDENTSELECTIONS;
fetch next from DEPENDENTSELECTIONCURSOR into @DEPENDENTSELECTIONID;
end
close DEPENDENTSELECTIONCURSOR;
deallocate DEPENDENTSELECTIONCURSOR;
end
end
return 0;