USP_IDSETREGISTER_RELEASEAPPLOCK

Releases application resource locks for a selection, and conditionally release locks for all dependent selections of the selection.

Parameters

Parameter Parameter Type Mode Description
@IDSETREGISTERID uniqueidentifier IN
@INCLUDEDEPENDENTSELECTIONS bit IN

Definition

Copy


      create procedure dbo.[USP_IDSETREGISTER_RELEASEAPPLOCK]
      (
        @IDSETREGISTERID uniqueidentifier,
        @INCLUDEDEPENDENTSELECTIONS bit = 0
      )
      as
        set nocount on;

        declare @LOCKNAME nvarchar(255);

        --Release the applock for the selection...

        set @LOCKNAME = 'IDSETREGISTER:' + cast(@IDSETREGISTERID as nvarchar(36));
        if APPLOCK_MODE('public', @LOCKNAME, 'Session') <> 'NoLock'
          exec sp_releaseapplock @Resource=@LOCKNAME, @LockOwner='Session';

        --Release the 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
                  --Release the applock for the dependent selection...

                  exec dbo.[USP_IDSETREGISTER_RELEASEAPPLOCK] @DEPENDENTSELECTIONID, @INCLUDEDEPENDENTSELECTIONS;

                  fetch next from DEPENDENTSELECTIONCURSOR into @DEPENDENTSELECTIONID;
                end

                close DEPENDENTSELECTIONCURSOR;
                deallocate DEPENDENTSELECTIONCURSOR;
              end
          end

        return 0;