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.

1150 lines
29 KiB

  1. -- Script: uddi.v2.bindingTemplate.sql
  2. -- Author: [email protected]
  3. -- Description: Stored procedures associated with a bindingTemplate 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_bindingTemplate_get
  10. -- =============================================
  11. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_get' and type = 'P')
  12. DROP PROCEDURE net_bindingTemplate_get
  13. GO
  14. CREATE PROCEDURE net_bindingTemplate_get
  15. @bindingKey uniqueidentifier,
  16. @serviceKey uniqueidentifier OUTPUT,
  17. @URLTypeID tinyint OUTPUT,
  18. @accessPoint nvarchar(4000) OUTPUT,
  19. @hostingRedirector uniqueidentifier OUTPUT
  20. WITH ENCRYPTION
  21. AS
  22. BEGIN
  23. DECLARE
  24. @error int,
  25. @context nvarchar(4000)
  26. SELECT
  27. @serviceKey = dbo.serviceKey([serviceID]),
  28. @URLTypeID = [URLTypeID],
  29. @accessPoint = [accessPoint],
  30. @hostingRedirector = [hostingRedirector]
  31. FROM
  32. [UDC_bindingTemplates]
  33. WHERE
  34. ([bindingID] = dbo.bindingID(@bindingKey))
  35. IF @@ROWCOUNT = 0
  36. BEGIN
  37. SET @error = 60210 -- E_invalidKey
  38. SET @context = 'bindingKey = ' + dbo.UUIDSTR(@bindingKey)
  39. GOTO errorLabel
  40. END
  41. RETURN 0
  42. errorLabel:
  43. RAISERROR (@error, 16, 1, @context)
  44. RETURN 1
  45. END -- net_bindingTemplate_get
  46. GO
  47. -- =============================================
  48. -- Name: net_bindingTemplate_get_batch
  49. -- =============================================
  50. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_get_batch' and type = 'P')
  51. DROP PROCEDURE net_bindingTemplate_get_batch
  52. GO
  53. CREATE PROCEDURE net_bindingTemplate_get_batch
  54. @bindingKey uniqueidentifier,
  55. @serviceKey uniqueidentifier OUTPUT,
  56. @URLTypeID tinyint OUTPUT,
  57. @accessPoint nvarchar(4000) OUTPUT,
  58. @hostingRedirector uniqueidentifier OUTPUT
  59. WITH ENCRYPTION
  60. AS
  61. BEGIN
  62. DECLARE
  63. @error int,
  64. @context nvarchar(4000)
  65. SELECT
  66. @serviceKey = dbo.serviceKey([serviceID]),
  67. @URLTypeID = [URLTypeID],
  68. @accessPoint = [accessPoint],
  69. @hostingRedirector = [hostingRedirector]
  70. FROM
  71. [UDC_bindingTemplates]
  72. WHERE
  73. ([bindingID] = dbo.bindingID(@bindingKey))
  74. IF @@ROWCOUNT = 0
  75. BEGIN
  76. SET @error = 60210 -- E_invalidKey
  77. SET @context = 'bindingKey = ' + dbo.UUIDSTR(@bindingKey)
  78. GOTO errorLabel
  79. END
  80. -- Retrieve the contained objects
  81. EXEC net_bindingTemplate_descriptions_get @bindingKey
  82. EXEC net_bindingTemplate_tModelInstanceInfos_get @bindingKey
  83. RETURN 0
  84. errorLabel:
  85. RAISERROR (@error, 16, 1, @context)
  86. RETURN 1
  87. END -- net_bindingTemplate_get_batch
  88. GO
  89. -- =============================================
  90. -- Name: net_bindingTemplate_descriptions_get
  91. -- =============================================
  92. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_descriptions_get' and type = 'P')
  93. DROP PROCEDURE net_bindingTemplate_descriptions_get
  94. GO
  95. CREATE PROCEDURE net_bindingTemplate_descriptions_get
  96. @bindingKey uniqueidentifier
  97. WITH ENCRYPTION
  98. AS
  99. BEGIN
  100. SELECT
  101. [isoLangCode],
  102. [description]
  103. FROM
  104. [UDC_bindingDesc]
  105. WHERE
  106. ([bindingID] = dbo.bindingID(@bindingKey))
  107. RETURN 0
  108. END -- net_bindingTemplate_descriptions_get
  109. GO
  110. -- =============================================
  111. -- Name: net_bindingTemplate_tModelInstanceInfos_get
  112. -- =============================================
  113. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_tModelInstanceInfos_get' and type = 'P')
  114. DROP PROCEDURE net_bindingTemplate_tModelInstanceInfos_get
  115. GO
  116. CREATE PROCEDURE net_bindingTemplate_tModelInstanceInfos_get
  117. @bindingKey uniqueidentifier
  118. WITH ENCRYPTION
  119. AS
  120. BEGIN
  121. SELECT
  122. [instanceID],
  123. [tModelKey],
  124. [overviewURL],
  125. [instanceParms]
  126. FROM
  127. [UDC_tModelInstances]
  128. WHERE
  129. ([bindingID] = dbo.bindingID(@bindingKey))
  130. RETURN 0
  131. END -- net_bindingTemplate_tModelInstanceInfos_get
  132. GO
  133. -- =============================================
  134. -- Name: net_bindingTemplate_tModelInstanceInfo_get_batch
  135. -- =============================================
  136. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_tModelInstanceInfo_get_batch' and type = 'P')
  137. DROP PROCEDURE net_bindingTemplate_tModelInstanceInfo_get_batch
  138. GO
  139. CREATE PROCEDURE net_bindingTemplate_tModelInstanceInfo_get_batch
  140. @instanceID bigint
  141. WITH ENCRYPTION
  142. AS
  143. BEGIN
  144. EXEC net_bindingTemplate_tModelInstanceInfo_descriptions_get @instanceID
  145. EXEC net_bindingTemplate_instanceDetails_descriptions_get @instanceID
  146. EXEC net_bindingTemplate_instanceDetails_overviewDoc_descriptions_get @instanceID
  147. RETURN 0
  148. END -- net_bindingTemplate_tModelInstanceInfo_get_batch
  149. GO
  150. -- =============================================
  151. -- Name: net_bindingTemplate_tModelInstanceInfo_descriptions_get
  152. -- =============================================
  153. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_tModelInstanceInfo_descriptions_get' and type = 'P')
  154. DROP PROCEDURE net_bindingTemplate_tModelInstanceInfo_descriptions_get
  155. GO
  156. CREATE PROCEDURE net_bindingTemplate_tModelInstanceInfo_descriptions_get
  157. @instanceID bigint
  158. WITH ENCRYPTION
  159. AS
  160. BEGIN
  161. SELECT
  162. [isoLangCode],
  163. [description]
  164. FROM
  165. [UDC_instanceDesc]
  166. WHERE
  167. ([instanceID] = @instanceID) AND
  168. ([elementID] = dbo.elementID('tModelInstanceInfo'))
  169. RETURN 0
  170. END -- net_bindingTemplate_tModelInstanceInfo_descriptions_get
  171. GO
  172. -- =============================================
  173. -- Name: net_bindingTemplate_instanceDetails_descriptions_get
  174. -- =============================================
  175. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_instanceDetails_descriptions_get' and type = 'P')
  176. DROP PROCEDURE net_bindingTemplate_instanceDetails_descriptions_get
  177. GO
  178. CREATE PROCEDURE net_bindingTemplate_instanceDetails_descriptions_get
  179. @instanceID bigint
  180. WITH ENCRYPTION
  181. AS
  182. BEGIN
  183. SELECT
  184. [isoLangCode],
  185. [description]
  186. FROM
  187. [UDC_instanceDesc]
  188. WHERE
  189. ([instanceID] = @instanceID) AND
  190. ([elementID] = dbo.elementID('instanceDetails'))
  191. RETURN 0
  192. END -- net_bindingTemplate_instanceDetails_descriptions_get
  193. GO
  194. -- =============================================
  195. -- Name: net_bindingTemplate_instanceDetails_overviewDoc_descriptions_get
  196. -- =============================================
  197. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_instanceDetails_overviewDoc_descriptions_get' and type = 'P')
  198. DROP PROCEDURE net_bindingTemplate_instanceDetails_overviewDoc_descriptions_get
  199. GO
  200. CREATE PROCEDURE net_bindingTemplate_instanceDetails_overviewDoc_descriptions_get
  201. @instanceID bigint
  202. WITH ENCRYPTION
  203. AS
  204. BEGIN
  205. SELECT
  206. [isoLangCode],
  207. [description]
  208. FROM
  209. [UDC_instanceDesc]
  210. WHERE
  211. ([instanceID] = @instanceID) AND
  212. ([elementID] = dbo.elementID('overviewDoc'))
  213. RETURN 0
  214. END -- net_bindingTemplate_instanceDetails_overviewDoc_descriptions_get
  215. GO
  216. -- =============================================
  217. -- Section: Save stored procedures
  218. -- =============================================
  219. -- =============================================
  220. -- Name: net_bindingTemplate_save
  221. -- =============================================
  222. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_save' and type = 'P')
  223. DROP PROCEDURE net_bindingTemplate_save
  224. GO
  225. CREATE PROCEDURE net_bindingTemplate_save
  226. @PUID nvarchar(450),
  227. @bindingKey uniqueidentifier,
  228. @serviceKey uniqueidentifier,
  229. @generic varchar(20),
  230. @URLTypeID tinyint,
  231. @accessPoint nvarchar(4000),
  232. @hostingRedirector uniqueidentifier,
  233. @contextID uniqueidentifier,
  234. @lastChange bigint
  235. WITH ENCRYPTION
  236. AS
  237. BEGIN
  238. DECLARE
  239. @RC int,
  240. @error int,
  241. @context nvarchar(4000),
  242. @bindingLimit int,
  243. @bindingCount int,
  244. @publisherID bigint,
  245. @serviceID bigint,
  246. @isReplPublisher bit
  247. SET @RC = 0
  248. SET @serviceID = dbo.serviceID(@serviceKey)
  249. -- serviceKey validation must occur during save since its not always known at validate time
  250. IF (@serviceID IS NULL)
  251. BEGIN
  252. SET @error = 60210 -- E_invalidKey
  253. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  254. GOTO errorLabel
  255. END
  256. -- Look up publisherID
  257. SET @isReplPublisher = dbo.isReplPublisher(@PUID)
  258. SET @publisherID = dbo.publisherID(@PUID)
  259. IF (@publisherID IS NULL)
  260. BEGIN
  261. SET @error = 60150 -- E_unknownUser
  262. SET @context = 'PUID = ' + @PUID
  263. GOTO errorLabel
  264. END
  265. IF EXISTS(SELECT * FROM [UDC_bindingTemplates] WHERE [bindingKey] = @bindingKey)
  266. BEGIN
  267. DELETE [UDC_bindingTemplates] WHERE [bindingKey] = @bindingKey
  268. END
  269. ELSE
  270. BEGIN
  271. IF (@isReplPublisher = 1)
  272. BEGIN
  273. -- Perform this check only for replication publishers
  274. IF (dbo.isUuidUnique(@bindingKey) = 0)
  275. BEGIN
  276. SET @error = 60210 -- E_invalidKeyPassed
  277. SET @context = 'Key is not unique. bindingKey = ' + dbo.UUIDSTR(@bindingKey)
  278. GOTO errorLabel
  279. END
  280. END
  281. END
  282. -- Check limit
  283. SELECT
  284. @bindingLimit = [bindingLimit]
  285. FROM
  286. [UDO_publishers]
  287. WHERE
  288. ([publisherID] = @publisherID)
  289. SELECT
  290. @bindingCount = COUNT(*)
  291. FROM
  292. [UDC_bindingTemplates]
  293. WHERE
  294. ([serviceID] = @serviceID)
  295. IF ((@bindingCount + 1) > @bindingLimit)
  296. BEGIN
  297. SET @error = 60160 -- E_accountLimitExceeded
  298. SET @context = 'Publisher limit for ''bindingTemplate'' exceeded (limit=' + CAST(@bindingLimit AS nvarchar(4000)) + ', count=' + CAST(@bindingCount AS nvarchar(4000)) + ')'
  299. GOTO errorLabel
  300. END
  301. INSERT [UDC_bindingTemplates](
  302. [serviceID],
  303. [generic],
  304. [bindingKey],
  305. [URLTypeID],
  306. [accessPoint],
  307. [hostingRedirector],
  308. [lastChange])
  309. VALUES(
  310. @serviceID,
  311. @generic,
  312. @bindingKey,
  313. @URLTypeID,
  314. @accessPoint,
  315. @hostingRedirector,
  316. @lastChange)
  317. RETURN 0
  318. errorLabel:
  319. RAISERROR (@error, 16, 1, @context)
  320. RETURN 1
  321. END -- net_bindingTemplate_save
  322. GO
  323. -- =============================================
  324. -- Name: net_bindingTemplate_description_save
  325. -- =============================================
  326. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_description_save' and type = 'P')
  327. DROP PROCEDURE net_bindingTemplate_description_save
  328. GO
  329. CREATE PROCEDURE net_bindingTemplate_description_save
  330. @bindingKey uniqueidentifier,
  331. @isoLangCode varchar(17) = 'en',
  332. @description nvarchar(4000)
  333. WITH ENCRYPTION
  334. AS
  335. BEGIN
  336. INSERT [UDC_bindingDesc](
  337. [bindingID],
  338. [isoLangCode],
  339. [description])
  340. VALUES(
  341. dbo.bindingID(@bindingKey),
  342. @isoLangCode,
  343. @description)
  344. RETURN 0
  345. END -- net_bindingTemplate_description_save
  346. GO
  347. -- =============================================
  348. -- Name: net_bindingTemplate_tModelInstanceInfo_save
  349. -- =============================================
  350. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_tModelInstanceInfo_save' and type = 'P')
  351. DROP PROCEDURE net_bindingTemplate_tModelInstanceInfo_save
  352. GO
  353. CREATE PROCEDURE net_bindingTemplate_tModelInstanceInfo_save
  354. @bindingKey uniqueidentifier,
  355. @tModelKey uniqueidentifier,
  356. @overviewURL nvarchar(4000),
  357. @instanceParms nvarchar(4000),
  358. @instanceID bigint OUTPUT
  359. WITH ENCRYPTION
  360. AS
  361. BEGIN
  362. INSERT [UDC_tModelInstances](
  363. [bindingID],
  364. [tModelKey],
  365. [overviewURL],
  366. [instanceParms])
  367. VALUES(
  368. dbo.bindingID(@bindingKey),
  369. @tModelKey,
  370. @overviewURL,
  371. @instanceParms)
  372. SET @instanceID = @@IDENTITY
  373. RETURN 0
  374. END -- net_bindingTemplate_tModelInstanceInfo_save
  375. GO
  376. -- =============================================
  377. -- Name: net_bindingTemplate_tModelInstanceInfo_description_save
  378. -- =============================================
  379. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_tModelInstanceInfo_description_save' and type = 'P')
  380. DROP PROCEDURE net_bindingTemplate_tModelInstanceInfo_description_save
  381. GO
  382. CREATE PROCEDURE net_bindingTemplate_tModelInstanceInfo_description_save
  383. @instanceID bigint,
  384. @isoLangCode varchar(17) = 'en',
  385. @description nvarchar(4000)
  386. WITH ENCRYPTION
  387. AS
  388. BEGIN
  389. INSERT [UDC_instanceDesc](
  390. [instanceID],
  391. [elementID],
  392. [isoLangCode],
  393. [description])
  394. VALUES(
  395. @instanceID,
  396. dbo.elementID('tModelInstanceInfo'),
  397. @isoLangCode,
  398. @description)
  399. RETURN 0
  400. END -- net_bindingTemplate_tModelInstanceInfo_description_save
  401. GO
  402. -- =============================================
  403. -- Name: net_bindingTemplate_instanceDetails_description_save
  404. -- =============================================
  405. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_instanceDetails_description_save' and type = 'P')
  406. DROP PROCEDURE net_bindingTemplate_instanceDetails_description_save
  407. GO
  408. CREATE PROCEDURE net_bindingTemplate_instanceDetails_description_save
  409. @instanceID bigint,
  410. @isoLangCode varchar(17) = 'en',
  411. @description nvarchar(4000)
  412. WITH ENCRYPTION
  413. AS
  414. BEGIN
  415. INSERT [UDC_instanceDesc](
  416. [instanceID],
  417. [elementID],
  418. [isoLangCode],
  419. [description])
  420. VALUES(
  421. @instanceID,
  422. dbo.elementID('instanceDetails'),
  423. @isoLangCode,
  424. @description)
  425. RETURN 0
  426. END -- net_bindingTemplate_instanceDetails_description_save
  427. GO
  428. -- =============================================
  429. -- Name: net_bindingTemplate_instanceDetails_overviewDoc_description_save
  430. -- =============================================
  431. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_instanceDetails_overviewDoc_description_save' and type = 'P')
  432. DROP PROCEDURE net_bindingTemplate_instanceDetails_overviewDoc_description_save
  433. GO
  434. CREATE PROCEDURE net_bindingTemplate_instanceDetails_overviewDoc_description_save
  435. @instanceID bigint,
  436. @isoLangCode varchar(17) = 'en',
  437. @description nvarchar(4000)
  438. WITH ENCRYPTION
  439. AS
  440. BEGIN
  441. INSERT [UDC_instanceDesc](
  442. [instanceID],
  443. [elementID],
  444. [isoLangCode],
  445. [description])
  446. VALUES(
  447. @instanceID,
  448. dbo.elementID('overviewDoc'),
  449. @isoLangCode,
  450. @description)
  451. RETURN 0
  452. END -- net_bindingTemplate_instanceDetails_overviewDoc_description_save
  453. GO
  454. -- =============================================
  455. -- Section: Delete stored procedures
  456. -- =============================================
  457. -- =============================================
  458. -- Name: net_bindingTemplate_delete
  459. -- =============================================
  460. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_bindingTemplate_delete' and type = 'P')
  461. DROP PROCEDURE net_bindingTemplate_delete
  462. GO
  463. CREATE PROCEDURE net_bindingTemplate_delete
  464. @PUID nvarchar(450),
  465. @bindingKey uniqueidentifier,
  466. @contextID uniqueidentifier
  467. WITH ENCRYPTION
  468. AS
  469. BEGIN
  470. DECLARE
  471. @RC int,
  472. @error int,
  473. @context nvarchar(4000),
  474. @publisherID bigint,
  475. @operatorID bigint
  476. SET @RC = 0
  477. --
  478. -- Validate parameters
  479. --
  480. IF @bindingKey IS NULL
  481. BEGIN
  482. SET @error = 60210 -- E_invalidKey
  483. SET @context = '@bindingKey is required.'
  484. GOTO errorLabel
  485. END
  486. -- Validate publisher
  487. SET @publisherID = dbo.publisherID(@PUID)
  488. IF @publisherID IS NULL
  489. BEGIN
  490. SET @error = 60150 -- E_unknownUser
  491. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  492. GOTO errorLabel
  493. END
  494. -- Validate operator
  495. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT
  496. IF @RC <> 0
  497. BEGIN
  498. SET @error = 50006 -- E_subProcFailure
  499. SET @context = ''
  500. GOTO errorLabel
  501. END
  502. --
  503. -- Validate bindingTemplate
  504. --
  505. IF EXISTS(SELECT * FROM [UDC_bindingTemplates] WHERE ([bindingKey] = @bindingKey))
  506. BEGIN
  507. IF dbo.getBindingOperatorID(@bindingKey) <> @operatorID
  508. BEGIN
  509. -- bindingKey doesn't belong to this operator
  510. SET @error = 60130 -- E_operatorMismatch
  511. SET @context = 'bindingKey = ' + dbo.UUIDSTR(@bindingKey) + ', operator = ' + dbo.operatorName(@operatorID)
  512. GOTO errorLabel
  513. END
  514. -- serviceKey exists. Make sure it belongs to current publisher
  515. IF dbo.getBindingPublisherID(@bindingKey) <> @publisherID
  516. BEGIN
  517. SET @error = 60140 -- E_userMismatch
  518. SET @context = 'bindingKey = ' + dbo.UUIDSTR(@bindingKey)
  519. GOTO errorLabel
  520. END
  521. END
  522. ELSE
  523. BEGIN
  524. SET @error = 60210 -- E_invalidKey
  525. SET @context = 'bindingKey = ' + dbo.UUIDSTR(@bindingKey)
  526. GOTO errorLabel
  527. END
  528. DELETE [UDC_bindingTemplates] WHERE [bindingKey] = @bindingKey
  529. RETURN 0
  530. errorLabel:
  531. RAISERROR (@error, 16, 1, @context)
  532. RETURN 1
  533. END -- net_bindingTemplate_delete
  534. GO
  535. -- =============================================
  536. -- Section: Validation stored procedures
  537. -- =============================================
  538. -- =============================================
  539. -- Name: net_bindingTemplate_validate
  540. -- =============================================
  541. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_bindingTemplate_validate' AND type = 'P')
  542. DROP PROCEDURE net_bindingTemplate_validate
  543. GO
  544. CREATE PROCEDURE net_bindingTemplate_validate
  545. @PUID nvarchar(450),
  546. @bindingKey uniqueidentifier,
  547. @serviceKey uniqueidentifier,
  548. @hostingRedirector uniqueidentifier = NULL,
  549. @flag int = 0
  550. WITH ENCRYPTION
  551. AS
  552. BEGIN
  553. DECLARE
  554. @RC int,
  555. @error int,
  556. @context nvarchar(4000),
  557. @operatorID bigint,
  558. @publisherID bigint,
  559. @replActive bit
  560. SET @RC = 0
  561. SET @replActive = 0
  562. IF @flag IS NULL
  563. SET @flag = 0
  564. --
  565. -- Validate parameters
  566. --
  567. IF @bindingKey = @serviceKey
  568. BEGIN
  569. SET @error = 60210 -- E_invalidKey
  570. SET @context = 'bindingKey ' + dbo.UUIDSTR(@bindingKey) + ' and serviceKey ' + dbo.UUIDSTR(@serviceKey) + ' are the same.'
  571. GOTO errorLabel
  572. END
  573. -- Validate publisher
  574. SET @publisherID = dbo.publisherID(@PUID)
  575. IF @publisherID IS NULL
  576. BEGIN
  577. SET @error = 60150 -- E_unknownUser
  578. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  579. GOTO errorLabel
  580. END
  581. -- Validate operator / publisher association (replication only)
  582. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT, @replActive OUTPUT
  583. IF @RC <> 0
  584. BEGIN
  585. SET @error = 50006 -- E_subProcFailure
  586. SET @context = ''
  587. GOTO errorLabel
  588. END
  589. -- Validate parent businessService
  590. IF (@serviceKey IS NOT NULL) AND (EXISTS(SELECT * FROM [UDC_businessServices] WHERE [serviceKey] = @serviceKey))
  591. BEGIN
  592. IF (dbo.getServicePublisherID(@serviceKey) <> @publisherID)
  593. BEGIN
  594. SET @error = 60140 -- E_userMismatch
  595. SET @context = 'serviceKey = ' + dbo.UUIDSTR(@serviceKey)
  596. GOTO errorLabel
  597. END
  598. END
  599. --
  600. -- Validate bindingTemplate
  601. --
  602. -- Validate bindingKey
  603. IF (@bindingKey IS NOT NULL)
  604. BEGIN
  605. IF EXISTS(SELECT * FROM [UDC_bindingTemplates] WHERE ([bindingKey] = @bindingKey))
  606. BEGIN
  607. -- serviceKey exists. Make sure it belongs to current publisher
  608. IF dbo.getBindingPublisherID(@bindingKey) <> @publisherID
  609. BEGIN
  610. SET @error = 60140 -- E_userMismatch
  611. SET @context = 'bindingKey = ' + dbo.UUIDSTR(@bindingKey)
  612. GOTO errorLabel
  613. END
  614. END
  615. ELSE
  616. BEGIN
  617. -- bindingKey doesn't exist
  618. IF (@replActive = 0) AND (@flag & 0x1 <> 0x1)
  619. BEGIN
  620. -- save isn't coming from replication and preassigned keys flag is not set so throw an error
  621. SET @error = 60210 -- E_invalidKey
  622. SET @context = 'bindingKey = ' + dbo.UUIDSTR(@bindingKey)
  623. GOTO errorLabel
  624. END
  625. END
  626. END
  627. -- Validate hostingRedirector
  628. IF @replActive = 0
  629. BEGIN
  630. -- Validate bindingTemplate.hostingRedirector.bindingKey
  631. IF @hostingRedirector IS NOT NULL
  632. BEGIN
  633. IF NOT EXISTS(SELECT * FROM [UDC_bindingTemplates] WHERE [bindingKey] = @hostingRedirector)
  634. BEGIN
  635. SET @error=60210 -- E_invalidKey
  636. SET @context='hostingRedirector/@bindingKey = ' + dbo.UUIDSTR(@hostingRedirector)
  637. GOTO errorLabel
  638. END
  639. ELSE
  640. BEGIN
  641. -- Referenced bindingKey exists. Make sure it isn't a hostingRedirector.
  642. IF (SELECT [hostingRedirector] FROM [UDC_bindingTemplates] WHERE [bindingKey] = @hostingRedirector) IS NOT NULL
  643. BEGIN
  644. -- binding referenced by a hostingRedirector cannot itself reference a hostingRedirector
  645. SET @error=60210 -- E_invalidKey
  646. SET @context='Referenced bindingTemplate cannot be a hostingRedirector. hostingRedirector/@bindingKey = ' + dbo.UUIDSTR(@hostingRedirector)
  647. GOTO errorLabel
  648. END
  649. END
  650. END
  651. END
  652. RETURN 0
  653. errorLabel:
  654. RAISERROR (@error, 16, 1, @context)
  655. RETURN 1
  656. END -- net_bindingTemplate_validate
  657. GO
  658. -- =============================================
  659. -- Name: net_bindingTemplate_tModelInstanceInfo_validate
  660. -- =============================================
  661. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_bindingTemplate_tModelInstanceInfo_validate' AND type = 'P')
  662. DROP PROCEDURE net_bindingTemplate_tModelInstanceInfo_validate
  663. GO
  664. CREATE PROCEDURE net_bindingTemplate_tModelInstanceInfo_validate
  665. @PUID nvarchar(450),
  666. @tModelKey uniqueidentifier
  667. WITH ENCRYPTION
  668. AS
  669. BEGIN
  670. DECLARE
  671. @RC int,
  672. @error int,
  673. @context nvarchar(4000),
  674. @publisherID bigint,
  675. @operatorID bigint,
  676. @replActive bit
  677. SET @RC = 0
  678. SET @replActive = 0
  679. -- Validate publisher
  680. SET @publisherID = dbo.publisherID(@PUID)
  681. IF @publisherID IS NULL
  682. BEGIN
  683. SET @error = 60150 -- E_unknownUser
  684. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  685. GOTO errorLabel
  686. END
  687. -- Validate operator / publisher association (replication only)
  688. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT, @replActive OUTPUT
  689. IF @RC <> 0
  690. BEGIN
  691. SET @error = 50006 -- E_subProcFailure
  692. SET @context = ''
  693. GOTO errorLabel
  694. END
  695. -- Validate tModelKey
  696. IF NOT EXISTS(SELECT * FROM [UDC_tModels] WHERE [tModelKey] = @tModelKey)
  697. BEGIN
  698. SET @error = 60210 -- E_invalidKey
  699. SET @context = 'tModelKey = ' + dbo.addURN(@tModelKey)
  700. GOTO errorLabel
  701. END
  702. RETURN 0
  703. errorLabel:
  704. RAISERROR (@error, 16, 1, @context)
  705. RETURN 1
  706. END -- net_bindingTemplate_tModelInstanceInfo_validate
  707. GO
  708. -- =============================================
  709. -- Section: Find stored procedures
  710. -- =============================================
  711. -- =============================================
  712. -- Name: net_find_bindingTemplate_serviceKey
  713. -- =============================================
  714. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_bindingTemplate_serviceKey' AND type = 'P')
  715. DROP PROCEDURE net_find_bindingTemplate_serviceKey
  716. GO
  717. CREATE PROCEDURE net_find_bindingTemplate_serviceKey
  718. @contextID uniqueidentifier,
  719. @serviceKey uniqueidentifier,
  720. @rows int OUTPUT
  721. WITH ENCRYPTION
  722. AS
  723. BEGIN
  724. DECLARE
  725. @error int,
  726. @context nvarchar(4000),
  727. @contextRows int
  728. DECLARE @tempKeys TABLE(
  729. [entityKey] uniqueidentifier)
  730. SET @contextRows = dbo.contextRows(@contextID)
  731. IF @contextRows = 0
  732. BEGIN
  733. INSERT @tempKeys(
  734. [entityKey])
  735. SELECT DISTINCT
  736. BT.[bindingKey]
  737. FROM
  738. [UDC_bindingTemplates] BT
  739. JOIN [UDC_businessServices] BS ON BT.[serviceID] = BS.[serviceID]
  740. WHERE
  741. (BS.[serviceKey] = @serviceKey)
  742. END
  743. ELSE
  744. BEGIN
  745. INSERT @tempKeys(
  746. [entityKey])
  747. SELECT DISTINCT
  748. BT.[bindingKey]
  749. FROM
  750. [UDC_bindingTemplates] BT
  751. JOIN [UDC_businessServices] BS ON BT.[serviceID] = BS.[serviceID]
  752. WHERE
  753. (BT.[bindingKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE [contextID] = @contextID)) AND
  754. (BS.[serviceKey] = @serviceKey)
  755. END
  756. -- All keys for this search argument are combined using a logical AND
  757. IF @contextRows > 0
  758. BEGIN
  759. DELETE
  760. [UDS_findResults]
  761. WHERE
  762. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  763. END
  764. ELSE
  765. BEGIN
  766. INSERT [UDS_findResults] (
  767. [contextID],
  768. [entityKey])
  769. SELECT DISTINCT
  770. @contextID,
  771. [entityKey]
  772. FROM
  773. @tempKeys
  774. END
  775. SELECT
  776. @rows = COUNT(*)
  777. FROM
  778. [UDS_findResults]
  779. WHERE
  780. ([contextID] = @contextID)
  781. RETURN 0
  782. errorLabel:
  783. RAISERROR (@error, 16, 1, @context)
  784. RETURN 1
  785. END -- net_find_bindingTemplate_serviceKey
  786. GO
  787. -- =============================================
  788. -- Name: net_find_bindingTemplate_tModelBag
  789. -- =============================================
  790. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_bindingTemplate_tModelBag' AND type = 'P')
  791. DROP PROCEDURE net_find_bindingTemplate_tModelBag
  792. GO
  793. CREATE PROCEDURE net_find_bindingTemplate_tModelBag
  794. @contextID uniqueidentifier,
  795. @tModelKey uniqueidentifier,
  796. @orKeys bit = 0,
  797. @rows int OUTPUT
  798. WITH ENCRYPTION
  799. AS
  800. BEGIN
  801. DECLARE
  802. @error int,
  803. @context nvarchar(4000),
  804. @contextRows int
  805. DECLARE @tempKeys TABLE(
  806. [entityKey] uniqueidentifier)
  807. SET @contextRows = dbo.contextRows(@contextID)
  808. IF @contextRows = 0
  809. BEGIN
  810. -- check tModelInstances
  811. INSERT @tempKeys(
  812. [entityKey])
  813. SELECT DISTINCT
  814. BT.[bindingKey]
  815. FROM
  816. [UDC_bindingTemplates] BT
  817. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  818. WHERE
  819. (TI.[tModelKey] = @tModelKey)
  820. -- Check hostingRedirectors
  821. INSERT @tempKeys(
  822. [entityKey])
  823. SELECT DISTINCT
  824. BT.[bindingKey]
  825. FROM
  826. [UDC_bindingTemplates] BT
  827. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  828. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  829. WHERE
  830. (TI.[tModelKey] = @tModelKey)
  831. END
  832. ELSE
  833. BEGIN
  834. -- check tModelInstances
  835. INSERT @tempKeys(
  836. [entityKey])
  837. SELECT DISTINCT
  838. BT.[bindingKey]
  839. FROM
  840. [UDC_bindingTemplates] BT
  841. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  842. WHERE
  843. (BT.[bindingKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  844. (TI.[tModelKey] = @tModelKey)
  845. -- Check hostingRedirectors
  846. INSERT @tempKeys(
  847. [entityKey])
  848. SELECT DISTINCT
  849. BT.[bindingKey]
  850. FROM
  851. [UDC_bindingTemplates] BT
  852. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  853. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  854. WHERE
  855. (BT.[bindingKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  856. (TI.[tModelKey] = @tModelKey)
  857. END
  858. IF @orKeys = 1
  859. BEGIN
  860. -- OR operation between @tempKeys and the UDS_findScratch table
  861. INSERT [UDS_findScratch] (
  862. [contextID],
  863. [entityKey])
  864. SELECT DISTINCT
  865. @contextID,
  866. [entityKey]
  867. FROM
  868. @tempKeys
  869. WHERE
  870. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  871. END
  872. ELSE
  873. BEGIN
  874. -- AND operation between @tempKeys and the UDS_findScratch table
  875. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  876. BEGIN
  877. DELETE
  878. [UDS_findScratch]
  879. WHERE
  880. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  881. END
  882. ELSE
  883. BEGIN
  884. INSERT [UDS_findScratch] (
  885. [contextID],
  886. [entityKey])
  887. SELECT DISTINCT
  888. @contextID,
  889. [entityKey]
  890. FROM
  891. @tempKeys
  892. END
  893. END
  894. SELECT
  895. @rows = @@ROWCOUNT
  896. FROM
  897. [UDS_findScratch]
  898. WHERE
  899. ([contextID] = @contextID)
  900. RETURN 0
  901. errorLabel:
  902. RAISERROR (@error, 16, 1, @context)
  903. RETURN 1
  904. END -- net_find_bindingTemplate_tModelBag
  905. GO
  906. -- =============================================
  907. -- Name: net_find_bindingTemplate_commit
  908. -- =============================================
  909. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_bindingTemplate_commit' AND type = 'P')
  910. DROP PROCEDURE net_find_bindingTemplate_commit
  911. GO
  912. CREATE PROCEDURE net_find_bindingTemplate_commit
  913. @contextID uniqueidentifier,
  914. @sortByDateAsc bit,
  915. @sortByDateDesc bit,
  916. @maxRows int,
  917. @truncated int OUTPUT
  918. WITH ENCRYPTION
  919. AS
  920. BEGIN
  921. -- Finalizes a find_business and returns a key list
  922. DECLARE
  923. @error int,
  924. @context nvarchar(4000),
  925. @contextRows int
  926. SET @contextRows = dbo.contextRows(@contextID)
  927. SET @truncated = 0
  928. IF @contextRows = 0
  929. RETURN 0
  930. DECLARE @tempKeys TABLE (
  931. [seqNo] bigint IDENTITY PRIMARY KEY ,
  932. [entityKey] uniqueidentifier,
  933. [lastChange] bigint NULL,
  934. [bindingID] bigint NULL)
  935. -- Set default sorting option
  936. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  937. SET @sortByDateAsc = 1
  938. -- Set maxRows if default was passed
  939. IF ISNULL(@maxRows,0) = 0
  940. SET @maxRows = dbo.configValue('Find.MaxRowsDefault')
  941. -- sortByDateAsc
  942. IF (@sortByDateAsc = 1)
  943. BEGIN
  944. INSERT @tempKeys(
  945. [entityKey],
  946. [lastChange],
  947. [bindingID])
  948. SELECT DISTINCT
  949. FR.[entityKey],
  950. BT.[lastChange],
  951. BT.[bindingID]
  952. FROM
  953. [UDS_findResults] FR
  954. JOIN [UDC_bindingTemplates] BT ON FR.[entityKey] = BT.[bindingKey] AND @contextID = FR.[contextID]
  955. ORDER BY
  956. 2 ASC,
  957. 3 ASC
  958. GOTO endLabel
  959. END
  960. -- sortByDateDesc
  961. IF (@sortByDateDesc = 1)
  962. BEGIN
  963. INSERT @tempKeys(
  964. [entityKey],
  965. [lastChange],
  966. [bindingID])
  967. SELECT DISTINCT
  968. FR.[entityKey],
  969. BT.[lastChange],
  970. BT.[bindingID]
  971. FROM
  972. [UDS_findResults] FR
  973. JOIN [UDC_bindingTemplates] BT ON FR.[entityKey] = BT.[bindingKey] AND @contextID = FR.[contextID]
  974. ORDER BY
  975. 2 DESC,
  976. 3 DESC
  977. GOTO endLabel
  978. END
  979. endLabel:
  980. -- Set @truncated
  981. IF (SELECT COUNT(*) FROM @tempKeys) > @maxRows
  982. SET @truncated = 1
  983. -- Return keys
  984. SELECT
  985. [entityKey]
  986. FROM
  987. @tempKeys
  988. WHERE
  989. ([seqNo] <= @maxRows)
  990. -- Run cleanup
  991. EXEC net_find_cleanup @contextID
  992. RETURN 0
  993. errorLabel:
  994. RAISERROR (@error, 16, 1, @context)
  995. RETURN 1
  996. END -- net_find_bindingTemplate_commit
  997. GO