Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1714 lines
42 KiB

  1. -- Script: uddi.v2.businessService.sql
  2. -- Author: [email protected]
  3. -- Description: Stored procedures associated with a businessService object.
  4. -- Note: This file is best viewed and edited with a tab width of 2.
  5. -- =============================================
  6. -- Section: Get stored procedures
  7. -- =============================================
  8. -- =============================================
  9. -- Name: net_businessService_get
  10. -- =============================================
  11. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_get' and type = 'P')
  12. DROP PROCEDURE net_businessService_get
  13. GO
  14. CREATE PROCEDURE net_businessService_get
  15. @serviceKey uniqueidentifier,
  16. @businessKey uniqueidentifier OUTPUT
  17. WITH ENCRYPTION
  18. AS
  19. BEGIN
  20. DECLARE
  21. @error int,
  22. @context nvarchar(4000)
  23. SELECT
  24. @businessKey = dbo.businessKey([businessID])
  25. FROM
  26. [UDC_businessServices]
  27. WHERE
  28. [serviceKey] = @serviceKey
  29. IF @@ROWCOUNT = 0
  30. BEGIN
  31. SET @error = 60210 -- E_invalidKey
  32. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  33. GOTO errorLabel
  34. END
  35. RETURN 0
  36. errorLabel:
  37. RAISERROR (@error, 16, 1, @context)
  38. RETURN 1
  39. END -- net_businessService_get
  40. GO
  41. -- =============================================
  42. -- Name: net_businessService_get_batch
  43. -- =============================================
  44. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_get_batch' and type = 'P')
  45. DROP PROCEDURE net_businessService_get_batch
  46. GO
  47. CREATE PROCEDURE net_businessService_get_batch
  48. @serviceKey uniqueidentifier,
  49. @businessKey uniqueidentifier OUTPUT
  50. WITH ENCRYPTION
  51. AS
  52. BEGIN
  53. DECLARE
  54. @error int,
  55. @context nvarchar(4000)
  56. SELECT
  57. @businessKey = dbo.businessKey([businessID])
  58. FROM
  59. [UDC_businessServices]
  60. WHERE
  61. [serviceKey] = @serviceKey
  62. IF @@ROWCOUNT = 0
  63. BEGIN
  64. SET @error = 60210 -- E_invalidKey
  65. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  66. GOTO errorLabel
  67. END
  68. -- Retrieve the contained objects
  69. EXEC net_businessService_descriptions_get @serviceKey
  70. EXEC net_businessService_names_get @serviceKey
  71. EXEC net_businessService_bindingTemplates_get @serviceKey
  72. EXEC net_businessService_categoryBag_get @serviceKey
  73. RETURN 0
  74. errorLabel:
  75. RAISERROR (@error, 16, 1, @context)
  76. RETURN 1
  77. END -- net_businessService_get_batch
  78. GO
  79. -- =============================================
  80. -- Name: net_serviceInfo_get_batch
  81. -- =============================================
  82. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_serviceInfo_get_batch' and type = 'P')
  83. DROP PROCEDURE net_serviceInfo_get_batch
  84. GO
  85. CREATE PROCEDURE net_serviceInfo_get_batch
  86. @serviceKey uniqueidentifier,
  87. @businessKey uniqueidentifier OUTPUT
  88. WITH ENCRYPTION
  89. AS
  90. BEGIN
  91. DECLARE
  92. @error int,
  93. @context nvarchar(4000)
  94. SELECT
  95. @businessKey = dbo.businessKey([businessID])
  96. FROM
  97. [UDC_businessServices]
  98. WHERE
  99. [serviceKey] = @serviceKey
  100. IF @@ROWCOUNT = 0
  101. BEGIN
  102. SET @error = 60210 -- E_invalidKey
  103. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  104. GOTO errorLabel
  105. END
  106. -- Retrieve the contained objects
  107. EXEC net_businessService_names_get @serviceKey
  108. RETURN 0
  109. errorLabel:
  110. RAISERROR (@error, 16, 1, @context)
  111. RETURN 1
  112. END -- net_businessService_get_batch
  113. GO
  114. -- =============================================
  115. -- Name: net_businessService_names_get
  116. -- =============================================
  117. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_names_get' and type = 'P')
  118. DROP PROCEDURE net_businessService_names_get
  119. GO
  120. CREATE PROCEDURE net_businessService_names_get
  121. @serviceKey uniqueidentifier
  122. WITH ENCRYPTION
  123. AS
  124. BEGIN
  125. SELECT
  126. [isoLangCode],
  127. [name]
  128. FROM
  129. [UDC_names_BS]
  130. WHERE
  131. ([serviceID] = dbo.serviceID(@serviceKey))
  132. RETURN 0
  133. END -- net_businessService_names_get
  134. GO
  135. -- =============================================
  136. -- Name: net_businessService_descriptions_get
  137. -- =============================================
  138. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_descriptions_get' and type = 'P')
  139. DROP PROCEDURE net_businessService_descriptions_get
  140. GO
  141. CREATE PROCEDURE net_businessService_descriptions_get
  142. @serviceKey uniqueidentifier
  143. WITH ENCRYPTION
  144. AS
  145. BEGIN
  146. SELECT
  147. [isoLangCode],
  148. [description]
  149. FROM
  150. [UDC_serviceDesc]
  151. WHERE
  152. ([serviceID] = dbo.serviceID(@serviceKey))
  153. RETURN 0
  154. END -- net_businessService_descriptions_get
  155. GO
  156. -- =============================================
  157. -- Name: net_businessService_categoryBag_get
  158. -- =============================================
  159. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_categoryBag_get' and type = 'P')
  160. DROP PROCEDURE net_businessService_categoryBag_get
  161. GO
  162. CREATE PROCEDURE net_businessService_categoryBag_get
  163. @serviceKey uniqueidentifier
  164. WITH ENCRYPTION
  165. AS
  166. BEGIN
  167. SELECT
  168. [keyName],
  169. [keyValue],
  170. [tModelKey]
  171. FROM
  172. [UDC_categoryBag_BS]
  173. WHERE
  174. [serviceID] = dbo.serviceID(@serviceKey)
  175. RETURN 0
  176. END -- net_businessService_categoryBag_get
  177. GO
  178. -- =============================================
  179. -- Name: net_businessService_bindingTemplates_get
  180. -- =============================================
  181. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_bindingTemplates_get' and type = 'P')
  182. DROP PROCEDURE net_businessService_bindingTemplates_get
  183. GO
  184. CREATE PROCEDURE net_businessService_bindingTemplates_get
  185. @serviceKey uniqueidentifier
  186. WITH ENCRYPTION
  187. AS
  188. BEGIN
  189. SELECT
  190. [bindingKey],
  191. [lastChange],
  192. [bindingID]
  193. FROM
  194. [UDC_bindingTemplates]
  195. WHERE
  196. ([serviceID] = dbo.serviceID(@serviceKey))
  197. ORDER BY
  198. 2 ASC, -- lastChange
  199. 3 ASC -- bindingID
  200. RETURN 0
  201. END -- net_businessService_bindingTemplates_get
  202. GO
  203. -- =============================================
  204. -- Section: Save stored procedures
  205. -- =============================================
  206. -- =============================================
  207. -- Name: net_businessService_save
  208. -- =============================================
  209. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_save' and type = 'P')
  210. DROP PROCEDURE net_businessService_save
  211. GO
  212. CREATE PROCEDURE net_businessService_save
  213. @PUID nvarchar(450),
  214. @serviceKey uniqueidentifier,
  215. @businessKey uniqueidentifier,
  216. @generic varchar(20),
  217. @contextID uniqueidentifier,
  218. @lastChange bigint
  219. WITH ENCRYPTION
  220. AS
  221. BEGIN
  222. DECLARE
  223. @RC int,
  224. @error int,
  225. @context nvarchar(4000),
  226. @serviceLimit int,
  227. @serviceCount int,
  228. @publisherID bigint,
  229. @businessID bigint,
  230. @isReplPublisher bit,
  231. @original_businessID bigint
  232. SET @RC = 0
  233. SET @businessID = dbo.businessID(@businessKey)
  234. -- businessKey validation must occur during save since its not always known at validate time
  235. IF (@businessID IS NULL)
  236. BEGIN
  237. SET @error = 60210 -- E_invalidKey
  238. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  239. GOTO errorLabel
  240. END
  241. -- Look up publisherID
  242. SET @isReplPublisher = dbo.isReplPublisher(@PUID)
  243. SET @publisherID = dbo.publisherID(@PUID)
  244. IF (@publisherID IS NULL)
  245. BEGIN
  246. SET @error = 60150 -- E_unknownUser
  247. SET @context = 'PUID = ' + @PUID
  248. GOTO errorLabel
  249. END
  250. -- Get the original businessID for this service. Use the existence of this key to determine
  251. -- whether or not there was an existing service in the first place. If there was one, we'll delete
  252. -- it. We'll need this ID later on to determine whether this save operation was actually a move
  253. -- operation.
  254. SELECT
  255. @original_businessID = [businessID]
  256. FROM
  257. [UDC_businessServices]
  258. WHERE
  259. ([serviceKey] = @serviceKey)
  260. IF (@original_businessID IS NOT NULL)
  261. BEGIN
  262. DELETE [UDC_businessServices] WHERE [serviceKey] = @serviceKey
  263. END
  264. ELSE
  265. BEGIN
  266. IF (@isReplPublisher) = 1
  267. BEGIN
  268. -- Perform this check only for replication publishers
  269. IF (dbo.isUuidUnique(@serviceKey) = 0)
  270. BEGIN
  271. SET @error = 60210 -- E_invalidKeyPassed
  272. SET @context = 'Key is not unique. serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  273. GOTO errorLabel
  274. END
  275. END
  276. END
  277. -- Check limit
  278. SELECT
  279. @serviceLimit = [serviceLimit]
  280. FROM
  281. [UDO_publishers]
  282. WHERE
  283. ([publisherID] = @publisherID)
  284. SELECT
  285. @serviceCount = COUNT(*)
  286. FROM
  287. [UDC_businessServices]
  288. WHERE
  289. ([businessID] = @businessID)
  290. IF ((@serviceCount + 1) > @serviceLimit)
  291. BEGIN
  292. SET @error = 60160 -- E_accountLimitExceeded
  293. SET @context = 'Publisher limit for ''businessService'' exceeded (limit=' + CAST(@serviceLimit AS nvarchar(4000)) + ', count=' + CAST(@serviceCount AS nvarchar(4000)) + ')'
  294. GOTO errorLabel
  295. END
  296. -- Insert service
  297. INSERT [UDC_businessServices](
  298. [businessID],
  299. [generic],
  300. [serviceKey],
  301. [lastChange])
  302. VALUES(
  303. @businessID,
  304. @generic,
  305. @serviceKey,
  306. @lastChange)
  307. -- The original business ID will be non-NULL if there this service existed before. It will
  308. -- not be the value of the given business ID if this save operation was a move operation. If
  309. -- both of these conditions are true, then we want to make sure that this service is not a
  310. -- service projection for the given business. We need to remove this service projection since
  311. -- this service actually belongs to the business now.
  312. IF ((@original_businessID IS NOT NULL) AND (@original_businessID <> @businessID))
  313. BEGIN
  314. DELETE
  315. [UDC_serviceProjections]
  316. WHERE
  317. ([businessKey] = @businessKey) AND
  318. ([serviceKey] = @serviceKey)
  319. -- TODO remove this check after a few clean test runs
  320. IF (@@ROWCOUNT > 1)
  321. BEGIN
  322. SET @error = 60500 -- E_fatalError
  323. SET @context = 'Error, multiple service projections were deleted.'
  324. GOTO errorLabel
  325. END
  326. END
  327. RETURN 0
  328. errorLabel:
  329. RAISERROR (@error, 16, 1, @context)
  330. RETURN 1
  331. END -- net_businessService_save
  332. GO
  333. -- =============================================
  334. -- Name: net_serviceProjection_save
  335. -- =============================================
  336. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_serviceProjection_save' and type = 'P')
  337. DROP PROCEDURE net_serviceProjection_save
  338. GO
  339. CREATE PROCEDURE net_serviceProjection_save
  340. @serviceKey uniqueidentifier,
  341. @businessKey uniqueidentifier,
  342. @lastChange bigint
  343. WITH ENCRYPTION
  344. AS
  345. BEGIN
  346. DECLARE
  347. @RC int,
  348. @error int,
  349. @context nvarchar(4000),
  350. @businessKey2 uniqueidentifier
  351. SET @RC = 0
  352. -- businessKey validation must occur during save since its not always known at validate time
  353. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @businessKey)
  354. BEGIN
  355. SET @error = 60210 -- E_invalidKey
  356. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  357. GOTO errorLabel
  358. END
  359. -- serviceKey validation must occur during save since its not always known at validate time
  360. IF NOT EXISTS(SELECT * FROM [UDC_businessServices] WHERE [serviceKey] = @serviceKey)
  361. BEGIN
  362. SET @error = 60210 -- E_invalidKey
  363. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  364. GOTO errorLabel
  365. END
  366. -- Look up the true parent of the service, need this later in case true parent is deleted
  367. SELECT
  368. @businessKey2 = BE.[businessKey]
  369. FROM
  370. [UDC_businessServices] BS
  371. JOIN [UDC_businessEntities] BE ON BS.[businessID] = BE.[businessID]
  372. WHERE
  373. (BS.[serviceKey] = @serviceKey)
  374. -- Add service projection if it doesn't already exist
  375. IF NOT EXISTS(SELECT * FROM [UDC_serviceProjections] WHERE ([businessKey] = @businessKey) AND ([serviceKey] = @serviceKey))
  376. BEGIN
  377. INSERT [UDC_serviceProjections](
  378. [businessKey],
  379. [serviceKey],
  380. [businessKey2],
  381. [lastChange])
  382. VALUES(
  383. @businessKey,
  384. @serviceKey,
  385. @businessKey2,
  386. @lastChange)
  387. END
  388. RETURN 0
  389. errorLabel:
  390. RAISERROR (@error, 16, 1, @context)
  391. RETURN 1
  392. END -- net_serviceProjection_save
  393. GO
  394. -- =============================================
  395. -- Name: net_serviceProjection_repl_save
  396. -- =============================================
  397. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_serviceProjection_repl_save' and type = 'P')
  398. DROP PROCEDURE net_serviceProjection_repl_save
  399. GO
  400. CREATE PROCEDURE net_serviceProjection_repl_save
  401. @serviceKey uniqueidentifier,
  402. @businessKey uniqueidentifier,
  403. @businessKey2 uniqueidentifier,
  404. @lastChange bigint
  405. WITH ENCRYPTION
  406. AS
  407. BEGIN
  408. DECLARE
  409. @RC int,
  410. @error int,
  411. @context nvarchar(4000)
  412. SET @RC = 0
  413. -- IMPORTANT: This sproc should only ever be called for replication. As per IN 60, we have to process service projection
  414. -- change records even if they refer to business services that no longer exist. Both businesses referenced
  415. -- by the service projection must exist.
  416. -- businessKey validation must occur during save since its not always known at validate time
  417. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @businessKey)
  418. BEGIN
  419. SET @error = 60210 -- E_invalidKey
  420. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  421. GOTO errorLabel
  422. END
  423. --
  424. -- Commenting out the following check to comply with IN60 as per UDDI bug 2454
  425. -- Which states that service projections that refer to a deleted service must be successfully saved
  426. -- From this we can imply that service projections that refer to a deleted business must also be successfully saved
  427. --
  428. --IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @businessKey2)
  429. --BEGIN
  430. --SET @error = 60210 -- E_invalidKey
  431. --SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey2)
  432. --GOTO errorLabel
  433. --END
  434. -- Add service projection if it doesn't already exist
  435. IF NOT EXISTS(SELECT * FROM [UDC_serviceProjections] WHERE ([businessKey] = @businessKey) AND ([serviceKey] = @serviceKey))
  436. BEGIN
  437. INSERT [UDC_serviceProjections](
  438. [businessKey],
  439. [serviceKey],
  440. [businessKey2],
  441. [lastChange])
  442. VALUES(
  443. @businessKey,
  444. @serviceKey,
  445. @businessKey2,
  446. @lastChange)
  447. END
  448. RETURN 0
  449. errorLabel:
  450. RAISERROR (@error, 16, 1, @context)
  451. RETURN 1
  452. END -- net_serviceProjection_repl_save
  453. GO
  454. -- =============================================
  455. -- Name: net_businessService_name_save
  456. -- =============================================
  457. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_name_save' and type = 'P')
  458. DROP PROCEDURE net_businessService_name_save
  459. GO
  460. CREATE PROCEDURE net_businessService_name_save
  461. @serviceKey uniqueidentifier,
  462. @isoLangCode varchar(17) = 'en',
  463. @name nvarchar(450)
  464. WITH ENCRYPTION
  465. AS
  466. BEGIN
  467. DECLARE
  468. @RC int,
  469. @error int,
  470. @context nvarchar(4000)
  471. -- Check for valid name
  472. IF (@name IS NULL) OR (LEN(@name) = 0)
  473. BEGIN
  474. SET @error = 60500 -- E_fatalError
  475. SET @context = 'name cannot be blank.'
  476. GOTO errorLabel
  477. END
  478. INSERT [UDC_names_BS](
  479. [serviceID],
  480. [isoLangCode],
  481. [name])
  482. VALUES(
  483. dbo.serviceID(@serviceKey),
  484. @isoLangCode,
  485. @name)
  486. RETURN 0
  487. errorLabel:
  488. RAISERROR (@error, 16, 1, @context)
  489. RETURN 1
  490. END -- net_businessService_name_save
  491. GO
  492. -- =============================================
  493. -- Name: net_businessService_description_save
  494. -- =============================================
  495. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_description_save' and type = 'P')
  496. DROP PROCEDURE net_businessService_description_save
  497. GO
  498. CREATE PROCEDURE net_businessService_description_save
  499. @serviceKey uniqueidentifier,
  500. @isoLangCode varchar(17) = 'en',
  501. @description nvarchar(4000)
  502. WITH ENCRYPTION
  503. AS
  504. BEGIN
  505. INSERT [UDC_serviceDesc](
  506. [serviceID],
  507. [isoLangCode],
  508. [description])
  509. VALUES(
  510. dbo.serviceID(@serviceKey),
  511. @isoLangCode,
  512. @description)
  513. RETURN 0
  514. END -- net_businessService_save
  515. GO
  516. -- =============================================
  517. -- Name: net_businessService_categoryBag_save
  518. -- =============================================
  519. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_categoryBag_save' and type = 'P')
  520. DROP PROCEDURE net_businessService_categoryBag_save
  521. GO
  522. CREATE PROCEDURE net_businessService_categoryBag_save
  523. @serviceKey uniqueidentifier,
  524. @keyName nvarchar(255),
  525. @keyValue nvarchar(255),
  526. @tModelKey uniqueidentifier
  527. WITH ENCRYPTION
  528. AS
  529. BEGIN
  530. INSERT [UDC_categoryBag_BS](
  531. [serviceID],
  532. [keyName],
  533. [keyValue],
  534. [tModelKey])
  535. VALUES(
  536. dbo.serviceID(@serviceKey),
  537. @keyName,
  538. @keyValue,
  539. @tModelKey)
  540. RETURN 0
  541. END -- net_businessService_categoryBag_save
  542. GO
  543. -- =============================================
  544. -- Section: Delete stored procedures
  545. -- =============================================
  546. -- =============================================
  547. -- Name: net_businessService_delete
  548. -- =============================================
  549. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessService_delete' and type = 'P')
  550. DROP PROCEDURE net_businessService_delete
  551. GO
  552. CREATE PROCEDURE net_businessService_delete
  553. @PUID nvarchar(450),
  554. @serviceKey uniqueidentifier,
  555. @contextID uniqueidentifier
  556. WITH ENCRYPTION
  557. AS
  558. BEGIN
  559. DECLARE
  560. @RC int,
  561. @error int,
  562. @context nvarchar(4000),
  563. @publisherID bigint,
  564. @operatorID bigint
  565. SET @RC = 0
  566. --
  567. -- Validate parameters
  568. --
  569. IF @serviceKey IS NULL
  570. BEGIN
  571. SET @error = 60210 -- E_invalidKey
  572. SET @context = '@serviceKey is required.'
  573. GOTO errorLabel
  574. END
  575. -- Validate publisher
  576. SET @publisherID = dbo.publisherID(@PUID)
  577. IF @publisherID IS NULL
  578. BEGIN
  579. SET @error = 60150 -- E_unknownUser
  580. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  581. GOTO errorLabel
  582. END
  583. -- Validate operator
  584. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT
  585. IF @RC <> 0
  586. BEGIN
  587. SET @error = 50006 -- E_subProcFailure
  588. SET @context = ''
  589. GOTO errorLabel
  590. END
  591. -- Validate businessService
  592. IF EXISTS(SELECT * FROM [UDC_businessServices] WHERE ([serviceKey] = @serviceKey))
  593. BEGIN
  594. -- serviceKey exists. Make sure it belongs to current publisher
  595. IF dbo.getServicePublisherID(@serviceKey) <> @publisherID
  596. BEGIN
  597. SET @error = 60140 -- E_userMismatch
  598. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  599. GOTO errorLabel
  600. END
  601. END
  602. ELSE
  603. BEGIN
  604. -- serviceKey doesn't exist
  605. SET @error = 60210 -- E_invalidKey
  606. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  607. GOTO errorLabel
  608. END
  609. DELETE [UDC_businessServices] WHERE [serviceKey] = @serviceKey
  610. RETURN 0
  611. errorLabel:
  612. RAISERROR (@error, 16, 1, @context)
  613. RETURN 1
  614. END -- net_businessService_delete
  615. GO
  616. -- =============================================
  617. -- Section: Validation stored procedures
  618. -- =============================================
  619. -- =============================================
  620. -- Name: net_serviceProjection_validate
  621. -- =============================================
  622. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_serviceProjection_validate' AND type = 'P')
  623. DROP PROCEDURE net_serviceProjection_validate
  624. GO
  625. CREATE PROCEDURE net_serviceProjection_validate
  626. @serviceKey uniqueidentifier,
  627. @businessKey uniqueidentifier
  628. WITH ENCRYPTION
  629. AS
  630. BEGIN
  631. DECLARE
  632. @error int,
  633. @context nvarchar(4000),
  634. @businessID bigint
  635. -- Try to get the parent business ID of this service
  636. SET @businessID = (SELECT businessID from UDC_businessServices where serviceKey = @serviceKey)
  637. IF (@businessID IS NOT NULL)
  638. BEGIN
  639. -- The service being projected exists, make sure it belongs to the specified business entity
  640. IF (@businessID <> dbo.businessID(@businessKey))
  641. BEGIN
  642. -- Business service being projected does not belong to the specified business entity so
  643. -- throw an error
  644. SET @error = 60210 -- E_invalidKey
  645. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  646. GOTO errorLabel
  647. END
  648. END
  649. -- It is not an error if the service being projected does not exist.
  650. RETURN 0
  651. errorLabel:
  652. RAISERROR (@error, 16, 1, @context)
  653. RETURN 1
  654. END
  655. GO
  656. -- =============================================
  657. -- Name: net_businessService_validate
  658. -- =============================================
  659. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_businessService_validate' AND type = 'P')
  660. DROP PROCEDURE net_businessService_validate
  661. GO
  662. CREATE PROCEDURE net_businessService_validate
  663. @PUID nvarchar(450),
  664. @serviceKey uniqueidentifier,
  665. @businessKey uniqueidentifier,
  666. @flag int = 0
  667. WITH ENCRYPTION
  668. AS
  669. BEGIN
  670. DECLARE
  671. @RC int,
  672. @error int,
  673. @context nvarchar(4000),
  674. @operatorID bigint,
  675. @publisherID bigint,
  676. @replActive bit
  677. SET @RC = 0
  678. SET @replActive = 0
  679. IF @flag IS NULL
  680. SET @flag = 0
  681. --
  682. -- Validate parameters
  683. --
  684. IF @serviceKey = @businessKey
  685. BEGIN
  686. SET @error = 60210 -- E_invalidKey
  687. SET @context = 'serviceKey ' + dbo.UUIDSTR(@serviceKey) + ' and businessKey ' + dbo.UUIDSTR(@businessKey) + ' are the same.'
  688. GOTO errorLabel
  689. END
  690. -- Validate publisher
  691. SET @publisherID = dbo.publisherID(@PUID)
  692. IF @publisherID IS NULL
  693. BEGIN
  694. SET @error = 60150 -- E_unknownUser
  695. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  696. GOTO errorLabel
  697. END
  698. -- Validate operator / publisher association (replication only)
  699. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT, @replActive OUTPUT
  700. IF @RC <> 0
  701. BEGIN
  702. SET @error = 50006 -- E_subProcFailure
  703. SET @context = ''
  704. GOTO errorLabel
  705. END
  706. --
  707. -- Validate parent business
  708. --
  709. IF (@businessKey IS NOT NULL) AND (EXISTS(SELECT * FROM [UDC_businessEntities] WHERE ([businessKey] = @businessKey)))
  710. BEGIN
  711. IF (dbo.getBusinessPublisherID(@businessKey) <> @publisherID)
  712. BEGIN
  713. SET @error = 60140 -- E_userMismatch
  714. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  715. GOTO errorLabel
  716. END
  717. END
  718. --
  719. -- Validate businessService
  720. --
  721. IF (@serviceKey IS NOT NULL)
  722. BEGIN
  723. IF EXISTS(SELECT * FROM [UDC_businessServices] WHERE ([serviceKey] = @serviceKey))
  724. BEGIN
  725. -- serviceKey exists. Make sure it belongs to current publisher
  726. IF (dbo.getServicePublisherID(@serviceKey) <> @publisherID)
  727. BEGIN
  728. SET @error = 60140 -- E_userMismatch
  729. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  730. GOTO errorLabel
  731. END
  732. END
  733. ELSE
  734. BEGIN
  735. -- serviceKey doesn't exist
  736. IF (@replActive = 0) AND (@flag & 0x1 <> 0x1)
  737. BEGIN
  738. -- save isn't coming from replication and preassigned keys flag is not set so throw an error
  739. SET @error = 60210 -- E_invalidKey
  740. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  741. GOTO errorLabel
  742. END
  743. END
  744. END
  745. RETURN 0
  746. errorLabel:
  747. RAISERROR (@error, 16, 1, @context)
  748. RETURN 1
  749. END -- net_businessService_validate
  750. GO
  751. -- =============================================
  752. -- Section: Find stored procedures
  753. -- =============================================
  754. -- =============================================
  755. -- Name: net_find_businessService_businessKey
  756. -- =============================================
  757. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessService_businessKey' AND type = 'P')
  758. DROP PROCEDURE net_find_businessService_businessKey
  759. GO
  760. CREATE PROCEDURE net_find_businessService_businessKey
  761. @contextID uniqueidentifier,
  762. @businessKey uniqueidentifier,
  763. @rows int OUTPUT
  764. WITH ENCRYPTION
  765. AS
  766. BEGIN
  767. DECLARE
  768. @error int,
  769. @context nvarchar(4000),
  770. @contextRows int
  771. DECLARE @tempKeys TABLE(
  772. [entityKey] uniqueidentifier)
  773. SET @contextRows = dbo.contextRows(@contextID)
  774. IF @contextRows = 0
  775. BEGIN
  776. -- Standard services
  777. INSERT @tempKeys(
  778. [entityKey])
  779. SELECT DISTINCT
  780. BS.[serviceKey]
  781. FROM
  782. [UDC_businessServices] BS
  783. JOIN [UDC_businessEntities] BE ON BS.[businessID] = BE.[businessID]
  784. WHERE
  785. (BE.[businessKey] = @businessKey)
  786. -- Projected services
  787. INSERT @tempKeys(
  788. [entityKey])
  789. SELECT DISTINCT
  790. BS.[serviceKey]
  791. FROM
  792. [UDC_businessServices] BS
  793. JOIN [UDC_serviceProjections] SP ON BS.[serviceKey] = SP.[serviceKey]
  794. WHERE
  795. (SP.[businessKey] = @businessKey)
  796. END
  797. ELSE
  798. BEGIN
  799. -- Standard services
  800. INSERT @tempKeys(
  801. [entityKey])
  802. SELECT DISTINCT
  803. BS.[serviceKey]
  804. FROM
  805. [UDC_businessServices] BS
  806. JOIN [UDC_businessEntities] BE ON BS.[businessID] = BE.[businessID]
  807. WHERE
  808. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE [contextID] = @contextID)) AND
  809. (BE.[businessKey] = @businessKey)
  810. -- Projected services
  811. INSERT @tempKeys(
  812. [entityKey])
  813. SELECT DISTINCT
  814. BS.[serviceKey]
  815. FROM
  816. [UDC_businessServices] BS
  817. JOIN [UDC_serviceProjections] SP ON BS.[serviceKey] = SP.[serviceKey]
  818. WHERE
  819. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE [contextID] = @contextID)) AND
  820. (SP.[businessKey] = @businessKey)
  821. END
  822. -- All keys for this search argument are combined using a logical AND
  823. IF @contextRows > 0
  824. BEGIN
  825. DELETE
  826. [UDS_findResults]
  827. WHERE
  828. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  829. END
  830. ELSE
  831. BEGIN
  832. INSERT [UDS_findResults] (
  833. [contextID],
  834. [entityKey])
  835. SELECT DISTINCT
  836. @contextID,
  837. [entityKey]
  838. FROM
  839. @tempKeys
  840. END
  841. SELECT
  842. @rows = COUNT(*)
  843. FROM
  844. [UDS_findResults]
  845. WHERE
  846. ([contextID] = @contextID)
  847. RETURN 0
  848. errorLabel:
  849. RAISERROR (@error, 16, 1, @context)
  850. RETURN 1
  851. END -- net_find_businessService_businessKey
  852. GO
  853. -- =============================================
  854. -- Name: net_find_businessService_name
  855. -- =============================================
  856. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_businessService_name' AND type = 'P')
  857. DROP PROCEDURE net_find_businessService_name
  858. GO
  859. CREATE PROCEDURE net_find_businessService_name
  860. @contextID uniqueidentifier,
  861. @isoLangCode varchar(17) = '%',
  862. @name nvarchar(450),
  863. @exactNameMatch bit,
  864. @caseSensitiveMatch bit,
  865. @rows int OUTPUT
  866. WITH ENCRYPTION
  867. AS
  868. BEGIN
  869. -- Adds name search arguments for a find_business
  870. DECLARE
  871. @error int,
  872. @context nvarchar(4000),
  873. @contextRows int,
  874. @wildCardSarg nvarchar(451)
  875. DECLARE @tempKeys TABLE(
  876. [entityKey] uniqueidentifier,
  877. [name] nvarchar(450))
  878. SET @contextRows = dbo.contextRows(@contextID)
  879. IF dbo.containsWildcard(@isoLangCode) = 0
  880. SET @isoLangCode = @isoLangCode + N'%'
  881. --
  882. -- Do a wildcard search (default)
  883. --
  884. IF (@exactNameMatch = 0)
  885. BEGIN
  886. SET @wildCardSarg = @name
  887. IF dbo.containsWildcard(@name) = 0
  888. SET @wildCardSarg = @wildCardSarg + N'%'
  889. IF @contextRows = 0
  890. BEGIN
  891. INSERT INTO @tempKeys(
  892. [entityKey],
  893. [name])
  894. SELECT
  895. BS.[serviceKey],
  896. SN.[name]
  897. FROM
  898. [UDC_businessServices] BS JOIN
  899. [UDC_names_BS] SN ON BS.[serviceID] = SN.[serviceID]
  900. WHERE
  901. (SN.[name] LIKE @wildCardSarg) AND
  902. (SN.[isoLangCode] LIKE @isoLangCode)
  903. END
  904. ELSE
  905. BEGIN
  906. INSERT INTO @tempKeys(
  907. [entityKey],
  908. [name])
  909. SELECT
  910. BS.[serviceKey],
  911. SN.[name]
  912. FROM
  913. [UDC_businessServices] BS JOIN
  914. [UDC_names_BS] SN ON BS.[serviceID] = SN.[serviceID]
  915. WHERE
  916. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  917. (SN.[name] LIKE @wildCardSarg) AND
  918. (SN.[isoLangCode] LIKE @isoLangCode)
  919. END
  920. END
  921. --
  922. -- Do an exactNameMatch search
  923. --
  924. IF (@exactNameMatch = 1)
  925. BEGIN
  926. IF @contextRows = 0
  927. BEGIN
  928. INSERT INTO @tempKeys(
  929. [entityKey],
  930. [name])
  931. SELECT
  932. BS.[serviceKey],
  933. SN.[name]
  934. FROM
  935. [UDC_businessServices] BS JOIN
  936. [UDC_names_BS] SN ON BS.[serviceID] = SN.[serviceID]
  937. WHERE
  938. (SN.[name] = @name) AND
  939. (SN.[isoLangCode] LIKE @isoLangCode)
  940. END
  941. ELSE
  942. BEGIN
  943. INSERT INTO @tempKeys(
  944. [entityKey],
  945. [name])
  946. SELECT
  947. BS.[serviceKey],
  948. SN.[name]
  949. FROM
  950. [UDC_businessServices] BS JOIN
  951. [UDC_names_BS] SN ON BS.[serviceID] = SN.[serviceID]
  952. WHERE
  953. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  954. (SN.[name] = @name) AND
  955. (SN.[isoLangCode] LIKE @isoLangCode)
  956. END
  957. END
  958. IF (@caseSensitiveMatch = 1)
  959. DELETE
  960. @tempKeys
  961. WHERE
  962. (dbo.caseSensitiveMatch(@name, [name], @exactNameMatch) = 0)
  963. -- name search arguments are combined using a logical OR by default
  964. INSERT [UDS_findScratch] (
  965. [contextID],
  966. [entityKey])
  967. SELECT DISTINCT
  968. @contextID,
  969. [entityKey]
  970. FROM
  971. @tempKeys
  972. WHERE
  973. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  974. SET @rows = @@ROWCOUNT
  975. RETURN 0
  976. errorLabel:
  977. RAISERROR (@error, 16, 1, @context)
  978. RETURN 1
  979. END -- net_find_businessService_name
  980. GO
  981. -- =============================================
  982. -- Name: net_find_businessService_categoryBag
  983. -- =============================================
  984. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessService_categoryBag' AND type = 'P')
  985. DROP PROCEDURE net_find_businessService_categoryBag
  986. GO
  987. CREATE PROCEDURE net_find_businessService_categoryBag
  988. @contextID uniqueidentifier,
  989. @keyName nvarchar(4000),
  990. @keyValue nvarchar(4000),
  991. @tModelKey uniqueidentifier,
  992. @orKeys bit = 0,
  993. @rows int OUTPUT
  994. WITH ENCRYPTION
  995. AS
  996. BEGIN
  997. DECLARE
  998. @error int,
  999. @context nvarchar(4000),
  1000. @contextRows int,
  1001. @genKeywordsMatch bit
  1002. DECLARE @tempKeys TABLE(
  1003. [entityKey] uniqueidentifier)
  1004. SET @contextRows = dbo.contextRows(@contextID)
  1005. SET @genKeywordsMatch = 0
  1006. IF @tModelKey = dbo.genKeywordsKey()
  1007. SET @genKeywordsMatch = 1
  1008. IF @contextRows = 0
  1009. BEGIN
  1010. IF @genKeywordsMatch = 0
  1011. BEGIN
  1012. -- Ignore keyName
  1013. INSERT @tempKeys(
  1014. [entityKey])
  1015. SELECT DISTINCT
  1016. [serviceKey]
  1017. FROM
  1018. [UDC_businessServices] BS
  1019. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1020. WHERE
  1021. ([tModelKey] = @tModelKey) AND
  1022. ([keyValue] = @keyValue)
  1023. END
  1024. ELSE
  1025. BEGIN
  1026. -- Include keyName
  1027. INSERT @tempKeys(
  1028. [entityKey])
  1029. SELECT DISTINCT
  1030. [serviceKey]
  1031. FROM
  1032. [UDC_businessServices] BS
  1033. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1034. WHERE
  1035. ([tModelKey] = @tModelKey) AND
  1036. ([keyValue] = @keyValue) AND
  1037. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1038. END
  1039. END
  1040. ELSE
  1041. BEGIN
  1042. IF @genKeywordsMatch = 0
  1043. BEGIN
  1044. -- Ignore keyName
  1045. INSERT @tempKeys(
  1046. [entityKey])
  1047. SELECT DISTINCT
  1048. [serviceKey]
  1049. FROM
  1050. [UDC_businessServices] BS
  1051. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1052. WHERE
  1053. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1054. ([tModelKey] = @tModelKey) AND
  1055. ([keyValue] = @keyValue)
  1056. END
  1057. ELSE
  1058. BEGIN
  1059. -- Include keyName
  1060. INSERT @tempKeys(
  1061. [entityKey])
  1062. SELECT DISTINCT
  1063. [serviceKey]
  1064. FROM
  1065. [UDC_businessServices] BS
  1066. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1067. WHERE
  1068. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1069. ([tModelKey] = @tModelKey) AND
  1070. ([keyValue] = @keyValue) AND
  1071. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1072. END
  1073. END
  1074. IF @orKeys = 1
  1075. BEGIN
  1076. INSERT [UDS_findScratch] (
  1077. [contextID],
  1078. [entityKey])
  1079. SELECT DISTINCT
  1080. @contextID,
  1081. [entityKey]
  1082. FROM
  1083. @tempKeys
  1084. WHERE
  1085. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1086. END
  1087. ELSE
  1088. BEGIN
  1089. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  1090. BEGIN
  1091. DELETE
  1092. [UDS_findScratch]
  1093. WHERE
  1094. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  1095. END
  1096. ELSE
  1097. BEGIN
  1098. INSERT [UDS_findScratch] (
  1099. [contextID],
  1100. [entityKey])
  1101. SELECT DISTINCT
  1102. @contextID,
  1103. [entityKey]
  1104. FROM
  1105. @tempKeys
  1106. END
  1107. END
  1108. SELECT
  1109. @rows = COUNT(*)
  1110. FROM
  1111. [UDS_findScratch]
  1112. WHERE
  1113. ([contextID] = @contextID)
  1114. RETURN 0
  1115. errorLabel:
  1116. RAISERROR (@error, 16, 1, @context)
  1117. RETURN 1
  1118. END -- net_find_businessService_categoryBag
  1119. GO
  1120. -- =============================================
  1121. -- Name: net_find_businessService_tModelBag
  1122. -- =============================================
  1123. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessService_tModelBag' AND type = 'P')
  1124. DROP PROCEDURE net_find_businessService_tModelBag
  1125. GO
  1126. CREATE PROCEDURE net_find_businessService_tModelBag
  1127. @contextID uniqueidentifier,
  1128. @tModelKey uniqueidentifier,
  1129. @orKeys bit = 0,
  1130. @rows int OUTPUT
  1131. WITH ENCRYPTION
  1132. AS
  1133. BEGIN
  1134. DECLARE
  1135. @error int,
  1136. @context nvarchar(4000),
  1137. @contextRows int
  1138. DECLARE @tempKeys TABLE(
  1139. [entityKey] uniqueidentifier)
  1140. SET @contextRows = dbo.contextRows(@contextID)
  1141. IF @contextRows = 0
  1142. BEGIN
  1143. -- check tModelInstances
  1144. INSERT @tempKeys(
  1145. [entityKey])
  1146. SELECT DISTINCT
  1147. BS.[serviceKey]
  1148. FROM
  1149. [UDC_businessServices] BS
  1150. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  1151. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  1152. WHERE
  1153. (TI.[tModelKey] = @tModelKey)
  1154. -- Check hostingRedirectors
  1155. INSERT @tempKeys(
  1156. [entityKey])
  1157. SELECT DISTINCT
  1158. BS.[serviceKey]
  1159. FROM
  1160. [UDC_businessServices] BS
  1161. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  1162. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  1163. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  1164. WHERE
  1165. (TI.[tModelKey] = @tModelKey)
  1166. END
  1167. ELSE
  1168. BEGIN
  1169. -- check tModelInstances
  1170. INSERT @tempKeys(
  1171. [entityKey])
  1172. SELECT DISTINCT
  1173. BS.[serviceKey]
  1174. FROM
  1175. [UDC_businessServices] BS
  1176. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  1177. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  1178. WHERE
  1179. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1180. (TI.[tModelKey] = @tModelKey)
  1181. -- Check hostingRedirectors
  1182. INSERT @tempKeys(
  1183. [entityKey])
  1184. SELECT DISTINCT
  1185. BS.[serviceKey]
  1186. FROM
  1187. [UDC_businessServices] BS
  1188. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  1189. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  1190. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  1191. WHERE
  1192. (BS.[serviceKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1193. (TI.[tModelKey] = @tModelKey)
  1194. END
  1195. IF @orKeys = 1
  1196. BEGIN
  1197. -- OR operation between @tempKeys and the UDS_findScratch table
  1198. INSERT [UDS_findScratch] (
  1199. [contextID],
  1200. [entityKey])
  1201. SELECT DISTINCT
  1202. @contextID,
  1203. [entityKey]
  1204. FROM
  1205. @tempKeys
  1206. WHERE
  1207. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1208. END
  1209. ELSE
  1210. BEGIN
  1211. -- AND operation between @tempKeys and the UDS_findScratch table
  1212. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  1213. BEGIN
  1214. DELETE
  1215. [UDS_findScratch]
  1216. WHERE
  1217. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  1218. END
  1219. ELSE
  1220. BEGIN
  1221. INSERT [UDS_findScratch] (
  1222. [contextID],
  1223. [entityKey])
  1224. SELECT DISTINCT
  1225. @contextID,
  1226. [entityKey]
  1227. FROM
  1228. @tempKeys
  1229. END
  1230. END
  1231. SELECT
  1232. @rows = COUNT(*)
  1233. FROM
  1234. [UDS_findScratch]
  1235. WHERE
  1236. ([contextID] = @contextID)
  1237. RETURN 0
  1238. errorLabel:
  1239. RAISERROR (@error, 16, 1, @context)
  1240. RETURN 1
  1241. END -- net_find_businessService_tModelBag
  1242. GO
  1243. -- =============================================
  1244. -- Name: net_find_businessService_commit
  1245. -- =============================================
  1246. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_businessService_commit' AND type = 'P')
  1247. DROP PROCEDURE net_find_businessService_commit
  1248. GO
  1249. CREATE PROCEDURE net_find_businessService_commit
  1250. @contextID uniqueidentifier,
  1251. @sortByNameAsc bit,
  1252. @sortByNameDesc bit,
  1253. @sortByDateAsc bit,
  1254. @sortByDateDesc bit,
  1255. @maxRows int,
  1256. @truncated int OUTPUT
  1257. WITH ENCRYPTION
  1258. AS
  1259. BEGIN
  1260. -- Finalizes a find_business and returns a key list
  1261. DECLARE
  1262. @error int,
  1263. @context nvarchar(4000),
  1264. @contextRows int
  1265. SET @contextRows = dbo.contextRows(@contextID)
  1266. SET @truncated = 0
  1267. IF @contextRows = 0
  1268. RETURN 0
  1269. DECLARE @tempKeys TABLE (
  1270. [seqNo] bigint IDENTITY PRIMARY KEY ,
  1271. [entityKey] uniqueidentifier,
  1272. [name] nvarchar(450) NULL,
  1273. [lastChange] bigint NULL,
  1274. [serviceID] bigint NULL)
  1275. -- Set default sorting option
  1276. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0) AND (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  1277. SET @sortByNameAsc = 1
  1278. -- Set maxRows if default was passed
  1279. IF ISNULL(@maxRows,0) = 0
  1280. SET @maxRows = dbo.configValue('Find.MaxRowsDefault')
  1281. -- sortByNameAsc
  1282. IF (@sortByNameAsc = 1)
  1283. BEGIN
  1284. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  1285. SET @sortByDateAsc = 1
  1286. IF (@sortByDateAsc = 1)
  1287. BEGIN
  1288. INSERT @tempKeys(
  1289. [entityKey],
  1290. [name],
  1291. [lastChange],
  1292. [serviceID])
  1293. SELECT DISTINCT
  1294. FR.[entityKey],
  1295. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1296. BS.[lastChange],
  1297. BS.[serviceID]
  1298. FROM
  1299. [UDS_findResults] FR
  1300. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1301. WHERE
  1302. (@contextID = FR.[contextID])
  1303. ORDER BY
  1304. 2 ASC,
  1305. 3 ASC,
  1306. 4 ASC
  1307. END
  1308. ELSE
  1309. BEGIN
  1310. INSERT @tempKeys(
  1311. [entityKey],
  1312. [name],
  1313. [lastChange],
  1314. [serviceID])
  1315. SELECT DISTINCT
  1316. FR.[entityKey],
  1317. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1318. BS.[lastChange],
  1319. BS.[serviceID]
  1320. FROM
  1321. [UDS_findResults] FR
  1322. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1323. WHERE
  1324. (@contextID = FR.[contextID])
  1325. ORDER BY
  1326. 2 ASC,
  1327. 3 DESC,
  1328. 4 DESC
  1329. END
  1330. GOTO endLabel
  1331. END
  1332. -- sortByNameDesc
  1333. IF (@sortByNameDesc = 1)
  1334. BEGIN
  1335. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  1336. SET @sortByDateAsc = 1
  1337. IF (@sortByDateAsc = 1)
  1338. BEGIN
  1339. INSERT @tempKeys(
  1340. [entityKey],
  1341. [name],
  1342. [lastChange],
  1343. [serviceID])
  1344. SELECT DISTINCT
  1345. FR.[entityKey],
  1346. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1347. BS.[lastChange],
  1348. BS.[serviceID]
  1349. FROM
  1350. [UDS_findResults] FR
  1351. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1352. WHERE
  1353. (@contextID = FR.[contextID])
  1354. ORDER BY
  1355. 2 DESC,
  1356. 3 ASC,
  1357. 4 ASC
  1358. END
  1359. ELSE
  1360. BEGIN
  1361. INSERT @tempKeys(
  1362. [entityKey],
  1363. [name],
  1364. [lastChange],
  1365. [serviceID])
  1366. SELECT DISTINCT
  1367. FR.[entityKey],
  1368. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1369. BS.[lastChange],
  1370. BS.[serviceID]
  1371. FROM
  1372. [UDS_findResults] FR
  1373. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1374. WHERE
  1375. (@contextID = FR.[contextID])
  1376. ORDER BY
  1377. 2 DESC,
  1378. 3 DESC,
  1379. 4 DESC
  1380. END
  1381. GOTO endLabel
  1382. END
  1383. -- sortByDateAsc
  1384. IF (@sortByDateAsc = 1)
  1385. BEGIN
  1386. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  1387. SET @sortByNameAsc = 1
  1388. IF (@sortByNameAsc = 1)
  1389. BEGIN
  1390. INSERT @tempKeys(
  1391. [entityKey],
  1392. [name],
  1393. [lastChange],
  1394. [serviceID])
  1395. SELECT DISTINCT
  1396. FR.[entityKey],
  1397. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1398. BS.[lastChange],
  1399. BS.[serviceID]
  1400. FROM
  1401. [UDS_findResults] FR
  1402. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1403. WHERE
  1404. (@contextID = FR.[contextID])
  1405. ORDER BY
  1406. 3 ASC,
  1407. 4 ASC,
  1408. 2 ASC
  1409. END
  1410. ELSE
  1411. BEGIN
  1412. INSERT @tempKeys(
  1413. [entityKey],
  1414. [name],
  1415. [lastChange],
  1416. [serviceID])
  1417. SELECT DISTINCT
  1418. FR.[entityKey],
  1419. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1420. BS.[lastChange],
  1421. BS.[serviceID]
  1422. FROM
  1423. [UDS_findResults] FR
  1424. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1425. WHERE
  1426. (@contextID = FR.[contextID])
  1427. ORDER BY
  1428. 3 ASC,
  1429. 4 ASC,
  1430. 2 DESC
  1431. END
  1432. GOTO endLabel
  1433. END
  1434. -- sortByDateDesc
  1435. IF (@sortByDateDesc = 1)
  1436. BEGIN
  1437. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  1438. SET @sortByNameAsc = 1
  1439. IF (@sortByNameAsc = 1)
  1440. BEGIN
  1441. INSERT @tempKeys(
  1442. [entityKey],
  1443. [name],
  1444. [lastChange],
  1445. [serviceID])
  1446. SELECT DISTINCT
  1447. FR.[entityKey],
  1448. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1449. BS.[lastChange],
  1450. BS.[serviceID]
  1451. FROM
  1452. [UDS_findResults] FR
  1453. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1454. WHERE
  1455. (@contextID = FR.[contextID])
  1456. ORDER BY
  1457. 3 DESC,
  1458. 4 DESC,
  1459. 2 ASC
  1460. END
  1461. ELSE
  1462. BEGIN
  1463. INSERT @tempKeys(
  1464. [entityKey],
  1465. [name],
  1466. [lastChange],
  1467. [serviceID])
  1468. SELECT DISTINCT
  1469. FR.[entityKey],
  1470. (SELECT TOP 1 [name] FROM [UDC_names_BS] WHERE ([serviceID] = dbo.serviceID([entityKey]))),
  1471. BS.[lastChange],
  1472. BS.[serviceID]
  1473. FROM
  1474. [UDS_findResults] FR
  1475. JOIN [UDC_businessServices] BS ON FR.[entityKey] = BS.[serviceKey]
  1476. WHERE
  1477. (@contextID = FR.[contextID])
  1478. ORDER BY
  1479. 3 DESC,
  1480. 4 DESC,
  1481. 2 DESC
  1482. END
  1483. GOTO endLabel
  1484. END
  1485. endLabel:
  1486. -- Set @truncated
  1487. IF (SELECT COUNT(*) FROM @tempKeys) > @maxRows
  1488. SET @truncated = 1
  1489. -- Return keys
  1490. SELECT
  1491. TK.[entityKey],
  1492. BE.[businessKey] AS [parentEntityKey] -- Must look up parent businessKey in case find_service with no businessKey is requested
  1493. FROM
  1494. @tempKeys TK
  1495. JOIN [UDC_businessServices] BS ON TK.[entityKey] = BS.[serviceKey]
  1496. JOIN [UDC_businessEntities] BE ON BS.[businessID] = BE.[businessID]
  1497. WHERE
  1498. ([seqNo] <= @maxRows)
  1499. -- Run cleanup
  1500. EXEC net_find_cleanup @contextID
  1501. RETURN 0
  1502. errorLabel:
  1503. RAISERROR (@error, 16, 1, @context)
  1504. RETURN 1
  1505. END -- net_find_businessService_commit
  1506. GO