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.

1325 lines
29 KiB

  1. -- Script: uddi.v2.tModel.sql
  2. -- Author: [email protected]
  3. -- Description: Stored procedures associated with a tModel 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_tModel_get
  10. -- =============================================
  11. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_get' and type = 'P')
  12. DROP PROCEDURE net_tModel_get
  13. GO
  14. CREATE PROCEDURE net_tModel_get
  15. @tModelKey uniqueidentifier,
  16. @operatorName nvarchar(450) OUTPUT,
  17. @authorizedName nvarchar(4000) OUTPUT,
  18. @name nvarchar(450) OUTPUT,
  19. @overviewURL nvarchar(4000) OUTPUT
  20. WITH ENCRYPTION
  21. AS
  22. BEGIN
  23. DECLARE
  24. @error int,
  25. @context nvarchar(4000)
  26. SELECT
  27. @operatorName = dbo.publisherOperatorName([publisherID]),
  28. @authorizedName = ISNULL([authorizedName],dbo.publisherName([publisherID])),
  29. @name = [name],
  30. @overviewURL = [overviewURL]
  31. FROM
  32. [UDC_tModels]
  33. WHERE
  34. ([tModelKey] = @tModelKey)
  35. IF @@ROWCOUNT = 0
  36. BEGIN
  37. SET @error = 60210 -- E_invalidKey
  38. SET @context = 'tModelKey = ' + dbo.addURN(@tModelKey)
  39. GOTO errorLabel
  40. END
  41. RETURN 0
  42. errorLabel:
  43. RAISERROR (@error, 16, 1, @context)
  44. RETURN 1
  45. END -- net_tModel_get
  46. GO
  47. -- =============================================
  48. -- Name: net_tModel_get_batch
  49. -- =============================================
  50. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_get_batch' and type = 'P')
  51. DROP PROCEDURE net_tModel_get_batch
  52. GO
  53. CREATE PROCEDURE net_tModel_get_batch
  54. @tModelKey uniqueidentifier,
  55. @operatorName nvarchar(450) OUTPUT,
  56. @authorizedName nvarchar(4000) OUTPUT,
  57. @name nvarchar(450) OUTPUT,
  58. @overviewURL nvarchar(4000) OUTPUT
  59. WITH ENCRYPTION
  60. AS
  61. BEGIN
  62. DECLARE
  63. @error int,
  64. @context nvarchar(4000)
  65. SELECT
  66. @operatorName = dbo.publisherOperatorName([publisherID]),
  67. @authorizedName = ISNULL([authorizedName],dbo.publisherName([publisherID])),
  68. @name = [name],
  69. @overviewURL = [overviewURL]
  70. FROM
  71. [UDC_tModels]
  72. WHERE
  73. ([tModelKey] = @tModelKey)
  74. IF @@ROWCOUNT = 0
  75. BEGIN
  76. SET @error = 60210 -- E_invalidKey
  77. SET @context = 'tModelKey = ' + dbo.addURN(@tModelKey)
  78. GOTO errorLabel
  79. END
  80. -- Get contained objects
  81. EXEC net_tModel_descriptions_get @tModelKey
  82. EXEC net_tModel_overviewDoc_descriptions_get @tModelKey
  83. EXEC net_tModel_identifierBag_get @tModelKey
  84. EXEC net_tModel_categoryBag_get @tModelKey
  85. RETURN 0
  86. errorLabel:
  87. RAISERROR (@error, 16, 1, @context)
  88. RETURN 1
  89. END -- net_tModel_get_batch
  90. GO
  91. -- =============================================
  92. -- Name: net_tModel_descriptions_get
  93. -- =============================================
  94. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_descriptions_get' and type = 'P')
  95. DROP PROCEDURE net_tModel_descriptions_get
  96. GO
  97. CREATE PROCEDURE net_tModel_descriptions_get
  98. @tModelKey uniqueidentifier
  99. WITH ENCRYPTION
  100. AS
  101. BEGIN
  102. SELECT
  103. [isoLangCode],
  104. [description]
  105. FROM
  106. [UDC_tModelDesc]
  107. WHERE
  108. ([tModelID] = dbo.tModelID(@tModelKey)) AND
  109. ([elementID] = dbo.elementID('tModel'))
  110. RETURN 0
  111. END -- net_tModel_descriptions_get
  112. GO
  113. -- =============================================
  114. -- Name: net_tModel_overviewDoc_descriptions_get
  115. -- =============================================
  116. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_overviewDoc_descriptions_get' and type = 'P')
  117. DROP PROCEDURE net_tModel_overviewDoc_descriptions_get
  118. GO
  119. CREATE PROCEDURE net_tModel_overviewDoc_descriptions_get
  120. @tModelKey uniqueidentifier
  121. WITH ENCRYPTION
  122. AS
  123. BEGIN
  124. SELECT
  125. [isoLangCode],
  126. [description]
  127. FROM
  128. [UDC_tModelDesc]
  129. WHERE
  130. ([tModelID] = dbo.tModelID(@tModelKey)) AND
  131. ([elementID] = dbo.elementID('overviewDoc'))
  132. RETURN 0
  133. END -- net_tModel_overviewDoc_descriptions_get
  134. GO
  135. -- =============================================
  136. -- Name: net_tModel_categoryBag_get
  137. -- =============================================
  138. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_categoryBag_get' and type = 'P')
  139. DROP PROCEDURE net_tModel_categoryBag_get
  140. GO
  141. CREATE PROCEDURE net_tModel_categoryBag_get
  142. @tModelKey uniqueidentifier
  143. WITH ENCRYPTION
  144. AS
  145. BEGIN
  146. SELECT
  147. [keyName],
  148. [keyValue],
  149. [tModelKey]
  150. FROM
  151. [UDC_categoryBag_TM]
  152. WHERE
  153. [tModelID] = dbo.tModelID(@tModelKey)
  154. RETURN 0
  155. END -- net_tModel_categoryBag_get
  156. GO
  157. -- =============================================
  158. -- Name: net_tModel_identifierBag_get
  159. -- =============================================
  160. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_identifierBag_get' and type = 'P')
  161. DROP PROCEDURE net_tModel_identifierBag_get
  162. GO
  163. CREATE PROCEDURE net_tModel_identifierBag_get
  164. @tModelKey uniqueidentifier
  165. WITH ENCRYPTION
  166. AS
  167. BEGIN
  168. SELECT
  169. [keyName],
  170. [keyValue],
  171. [tModelKey]
  172. FROM
  173. [UDC_identifierBag_TM]
  174. WHERE
  175. [tModelID] = dbo.tModelID(@tModelKey)
  176. RETURN 0
  177. END -- net_tModel_identifierBag_get
  178. GO
  179. -- =============================================
  180. -- Section: Save stored procedures
  181. -- =============================================
  182. -- =============================================
  183. -- Name: net_tModel_save
  184. -- =============================================
  185. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_save' and type = 'P')
  186. DROP PROCEDURE net_tModel_save
  187. GO
  188. CREATE PROCEDURE net_tModel_save
  189. @tModelKey uniqueidentifier,
  190. @PUID nvarchar(450),
  191. @generic varchar(20),
  192. @authorizedName nvarchar(4000) OUTPUT,
  193. @name nvarchar(450),
  194. @overviewURL nvarchar(4000),
  195. @contextID uniqueidentifier,
  196. @lastChange bigint
  197. WITH ENCRYPTION
  198. AS
  199. BEGIN
  200. DECLARE
  201. @RC int,
  202. @error int,
  203. @context nvarchar(4000),
  204. @publisherID bigint,
  205. @isReplPublisher bit
  206. SET @RC = 0
  207. SET @publisherID = dbo.publisherID(@PUID)
  208. -- validate @publisherID is not NULL?
  209. SET @isReplPublisher = dbo.isReplPublisher(@PUID)
  210. IF @isReplPublisher = 0
  211. SET @authorizedName = NULL
  212. IF EXISTS(SELECT * FROM [UDC_tModels] WHERE [tModelKey] = @tModelKey)
  213. BEGIN
  214. DELETE [UDC_tModels] WHERE [tModelKey] = @tModelKey
  215. END
  216. ELSE
  217. BEGIN
  218. IF (@isReplPublisher = 1)
  219. BEGIN
  220. -- Perform this check only for replication publishers
  221. IF (dbo.isUuidUnique(@tModelKey) = 0)
  222. BEGIN
  223. SET @error = 60210 -- E_invalidKeyPassed
  224. SET @context = 'Key is not unique. tModelKey = ' + dbo.UUIDSTR(@tModelKey)
  225. GOTO errorLabel
  226. END
  227. END
  228. END
  229. INSERT [UDC_tModels](
  230. [publisherID],
  231. [generic],
  232. [authorizedName],
  233. [tModelKey],
  234. [name],
  235. [overviewURL],
  236. [lastChange],
  237. [flag])
  238. VALUES(
  239. @publisherID,
  240. ISNULL(@generic,dbo.configValue('CurrentAPIVersion')),
  241. @authorizedName,
  242. @tModelKey,
  243. @name,
  244. @overviewURL,
  245. @lastChange,
  246. 0)
  247. SET @authorizedName = dbo.publisherName(@publisherID)
  248. RETURN 0
  249. errorLabel:
  250. RAISERROR (@error, 16, 1, @context)
  251. RETURN 1
  252. END -- net_tModel_save
  253. GO
  254. -- =============================================
  255. -- Name: net_tModel_description_save
  256. -- =============================================
  257. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_description_save' and type = 'P')
  258. DROP PROCEDURE net_tModel_description_save
  259. GO
  260. CREATE PROCEDURE net_tModel_description_save
  261. @tModelKey uniqueidentifier,
  262. @isoLangCode varchar(17) = 'en',
  263. @description nvarchar(4000)
  264. WITH ENCRYPTION
  265. AS
  266. BEGIN
  267. INSERT [UDC_tModelDesc](
  268. [tModelID],
  269. [elementID],
  270. [isoLangCode],
  271. [description])
  272. VALUES(
  273. dbo.tModelID(@tModelKey),
  274. dbo.elementID('tModel'),
  275. @isoLangCode,
  276. @description)
  277. RETURN 0
  278. END -- net_tModel_description_save
  279. GO
  280. -- =============================================
  281. -- Name: net_tModel_overviewDoc_description_save
  282. -- =============================================
  283. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_overviewDoc_description_save' and type = 'P')
  284. DROP PROCEDURE net_tModel_overviewDoc_description_save
  285. GO
  286. CREATE PROCEDURE net_tModel_overviewDoc_description_save
  287. @tModelKey uniqueidentifier,
  288. @isoLangCode varchar(17) = 'en',
  289. @description nvarchar(4000)
  290. WITH ENCRYPTION
  291. AS
  292. BEGIN
  293. INSERT [UDC_tModelDesc](
  294. [tModelID],
  295. [elementID],
  296. [isoLangCode],
  297. [description])
  298. VALUES(
  299. dbo.tModelID(@tModelKey),
  300. dbo.elementID('overviewDoc'),
  301. @isoLangCode,
  302. @description)
  303. RETURN 0
  304. END -- net_tModel_overviewDoc_description_save
  305. GO
  306. -- =============================================
  307. -- Name: net_tModel_categoryBag_save
  308. -- =============================================
  309. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_categoryBag_save' and type = 'P')
  310. DROP PROCEDURE net_tModel_categoryBag_save
  311. GO
  312. CREATE PROCEDURE net_tModel_categoryBag_save
  313. @tModelKeyParent uniqueidentifier,
  314. @keyName nvarchar(255),
  315. @keyValue nvarchar(255),
  316. @tModelKey uniqueidentifier
  317. WITH ENCRYPTION
  318. AS
  319. BEGIN
  320. INSERT [UDC_categoryBag_TM](
  321. [tModelID],
  322. [keyName],
  323. [keyValue],
  324. [tModelKey])
  325. VALUES(
  326. dbo.tModelID(@tModelKeyParent),
  327. @keyName,
  328. @keyValue,
  329. @tModelKey)
  330. RETURN 0
  331. END -- net_tModel_categoryBag_save
  332. GO
  333. -- =============================================
  334. -- Name: net_tModel_identifierBag_save
  335. -- =============================================
  336. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_identifierBag_save' and type = 'P')
  337. DROP PROCEDURE net_tModel_identifierBag_save
  338. GO
  339. CREATE PROCEDURE net_tModel_identifierBag_save
  340. @tModelKeyParent uniqueidentifier,
  341. @keyName nvarchar(255),
  342. @keyValue nvarchar(255),
  343. @tModelKey uniqueidentifier
  344. WITH ENCRYPTION
  345. AS
  346. BEGIN
  347. INSERT [UDC_identifierBag_TM](
  348. [tModelID],
  349. [keyName],
  350. [keyValue],
  351. [tModelKey])
  352. VALUES(
  353. dbo.tModelID(@tModelKeyParent),
  354. @keyName,
  355. @keyValue,
  356. @tModelKey)
  357. RETURN 0
  358. END -- net_tModel_identifierBag_save
  359. GO
  360. -- =============================================
  361. -- Section: Delete stored procedures
  362. -- =============================================
  363. -- =============================================
  364. -- Name: net_tModel_delete
  365. -- =============================================
  366. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_tModel_delete' and type = 'P')
  367. DROP PROCEDURE net_tModel_delete
  368. GO
  369. CREATE PROCEDURE net_tModel_delete
  370. @PUID nvarchar(450),
  371. @tModelKey uniqueidentifier,
  372. @contextID uniqueidentifier,
  373. @lastChange bigint
  374. WITH ENCRYPTION
  375. AS
  376. BEGIN
  377. DECLARE
  378. @RC int,
  379. @error int,
  380. @context nvarchar(4000),
  381. @operatorID bigint,
  382. @publisherID bigint
  383. SET @RC = 0
  384. --
  385. -- Validate parameters
  386. --
  387. IF @tModelKey IS NULL
  388. BEGIN
  389. SET @error = 60210 -- E_invalidKey
  390. SET @context = '@tModelKey is required.'
  391. GOTO errorLabel
  392. END
  393. -- Validate publisher
  394. SET @publisherID = dbo.publisherID(@PUID)
  395. IF @publisherID IS NULL
  396. BEGIN
  397. SET @error = 60150 -- E_unknownUser
  398. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  399. GOTO errorLabel
  400. END
  401. -- Check to see if tModelKey exists
  402. IF EXISTS(SELECT * FROM [UDC_tModels] WHERE (tModelKey = @tModelKey))
  403. BEGIN
  404. -- tModelKey exists. Make sure it belongs to current publisher
  405. IF NOT EXISTS(SELECT * FROM [UDC_tModels] WHERE (tModelKey = @tModelKey) AND (publisherID = @publisherID))
  406. BEGIN
  407. SET @error = 60140 -- E_userMismatch
  408. SET @context = 'tModelKey = ' + dbo.addURN(@tModelKey)
  409. GOTO errorLabel
  410. END
  411. END
  412. ELSE
  413. BEGIN
  414. SET @error = 60210 -- E_invalidKey
  415. SET @context = '@tModelKey = ' + dbo.addURN(@tModelKey)
  416. GOTO errorLabel
  417. END
  418. -- Hide the tModel
  419. UPDATE
  420. [UDC_tModels]
  421. SET
  422. [lastChange] = @lastChange,
  423. [flag] = 0x1
  424. WHERE
  425. ([tModelKey] = @tModelKey)
  426. RETURN 0
  427. errorLabel:
  428. RAISERROR (@error, 16, 1, @context)
  429. RETURN 1
  430. END -- net_tModel_delete
  431. GO
  432. -- =============================================
  433. -- Section: tModel validation stored procedures
  434. -- =============================================
  435. -- =============================================
  436. -- Name: net_tModel_validate
  437. -- =============================================
  438. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_tModel_validate' AND type = 'P')
  439. DROP PROCEDURE net_tModel_validate
  440. GO
  441. CREATE PROCEDURE net_tModel_validate
  442. @PUID nvarchar(450),
  443. @tModelKey uniqueidentifier,
  444. @flag int = 0
  445. WITH ENCRYPTION
  446. AS
  447. BEGIN
  448. DECLARE
  449. @RC int,
  450. @error int,
  451. @context nvarchar(4000),
  452. @operatorID bigint,
  453. @publisherID bigint,
  454. @replActive bit
  455. SET @RC = 0
  456. SET @replActive = 0
  457. IF @flag IS NULL
  458. SET @flag = 0
  459. --
  460. -- Validate parameters
  461. --
  462. IF @tModelKey IS NULL
  463. BEGIN
  464. SET @error = 60210 -- E_invalidKey
  465. SET @context = '@tModelKey is required.'
  466. GOTO errorLabel
  467. END
  468. -- Validate publisher
  469. SET @publisherID = dbo.publisherID(@PUID)
  470. IF @publisherID IS NULL
  471. BEGIN
  472. SET @error = 60150 -- E_unknownUser
  473. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  474. GOTO errorLabel
  475. END
  476. -- Validate operator / publisher association (replication only)
  477. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT, @replActive OUTPUT
  478. --
  479. -- Validate tModel
  480. --
  481. -- Check to see if tModelKey exists
  482. IF EXISTS(SELECT * FROM [UDC_tModels] WHERE (tModelKey = @tModelKey))
  483. BEGIN
  484. -- tModelKey exists. Make sure it belongs to current publisher
  485. IF NOT EXISTS(SELECT * FROM [UDC_tModels] WHERE (tModelKey = @tModelKey) AND (publisherID = @publisherID))
  486. BEGIN
  487. SET @error = 60140 -- E_userMismatch
  488. SET @context = 'tModelKey = ' + dbo.addURN(@tModelKey)
  489. GOTO errorLabel
  490. END
  491. IF @replActive = 0
  492. BEGIN
  493. IF @operatorID <> dbo.currentOperatorID()
  494. BEGIN
  495. SET @error = 60130 -- E_operatorMismatch
  496. SET @context = 'Operator ' + dbo.operatorName(@operatorID) + ' is not the local operator.'
  497. GOTO errorLabel
  498. END
  499. END
  500. END
  501. ELSE
  502. BEGIN
  503. -- tModelKey doesn't exist
  504. IF (@replActive = 0) AND (@flag & 0x1 <> 0x1)
  505. BEGIN
  506. -- save isn't coming from replication and preassigned keys flag is not set so throw an error
  507. SET @error = 60210 -- E_invalidKey
  508. SET @context = '@tModelKey = ' + dbo.addURN(@tModelKey)
  509. GOTO errorLabel
  510. END
  511. END
  512. RETURN 0
  513. errorLabel:
  514. RAISERROR (@error, 16, 1, @context)
  515. RETURN 1
  516. END -- net_tModel_validate
  517. GO
  518. -- =============================================
  519. -- Section: Find stored procedures
  520. -- =============================================
  521. -- =============================================
  522. -- Name: net_find_tModel_name
  523. -- =============================================
  524. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_tModel_name' AND type = 'P')
  525. DROP PROCEDURE net_find_tModel_name
  526. GO
  527. CREATE PROCEDURE net_find_tModel_name
  528. @contextID uniqueidentifier,
  529. @name nvarchar(450),
  530. @exactNameMatch bit,
  531. @caseSensitiveMatch bit,
  532. @rows int OUTPUT
  533. WITH ENCRYPTION
  534. AS
  535. BEGIN
  536. -- Adds name search arguments for a find_business
  537. DECLARE
  538. @error int,
  539. @context nvarchar(4000),
  540. @contextRows int,
  541. @wildCardSarg nvarchar(451)
  542. DECLARE @tempKeys TABLE(
  543. [entityKey] uniqueidentifier,
  544. [name] nvarchar(450))
  545. SET @contextRows = dbo.contextRows(@contextID)
  546. --
  547. -- Do a wildcard search (default)
  548. --
  549. IF (@exactNameMatch = 0)
  550. BEGIN
  551. SET @wildCardSarg = @name
  552. IF dbo.containsWildcard(@name) = 0
  553. SET @wildCardSarg = @wildCardSarg + N'%'
  554. IF @contextRows = 0
  555. BEGIN
  556. INSERT INTO @tempKeys(
  557. [entityKey],
  558. [name])
  559. SELECT
  560. [tModelKey],
  561. [name]
  562. FROM
  563. [UDC_tModels]
  564. WHERE
  565. ([name] LIKE @wildCardSarg) AND
  566. ([flag] = 0)
  567. END
  568. ELSE
  569. BEGIN
  570. INSERT INTO @tempKeys(
  571. [entityKey],
  572. [name])
  573. SELECT
  574. [tModelKey],
  575. [name]
  576. FROM
  577. [UDC_tModels]
  578. WHERE
  579. ([tModelKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  580. ([name] LIKE @wildCardSarg) AND
  581. ([flag] = 0)
  582. END
  583. END
  584. --
  585. -- Do an exactNameMatch search
  586. --
  587. IF (@exactNameMatch = 1)
  588. BEGIN
  589. IF @contextRows = 0
  590. BEGIN
  591. INSERT INTO @tempKeys(
  592. [entityKey],
  593. [name])
  594. SELECT
  595. [tModelKey],
  596. [name]
  597. FROM
  598. [UDC_tModels]
  599. WHERE
  600. ([name] = @name) AND
  601. ([flag] = 0)
  602. END
  603. ELSE
  604. BEGIN
  605. INSERT INTO @tempKeys(
  606. [entityKey],
  607. [name])
  608. SELECT
  609. [tModelKey],
  610. [name]
  611. FROM
  612. [UDC_tModels]
  613. WHERE
  614. ([tModelKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  615. ([name] = @name) AND
  616. ([flag] = 0)
  617. END
  618. END
  619. IF (@caseSensitiveMatch = 1)
  620. DELETE
  621. @tempKeys
  622. WHERE
  623. (dbo.caseSensitiveMatch(@name, [name], @exactNameMatch) = 0)
  624. -- name search arguments are combined using a logical OR by default
  625. INSERT [UDS_findScratch] (
  626. [contextID],
  627. [entityKey])
  628. SELECT DISTINCT
  629. @contextID,
  630. [entityKey]
  631. FROM
  632. @tempKeys
  633. WHERE
  634. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  635. SET @rows = @@ROWCOUNT
  636. RETURN 0
  637. errorLabel:
  638. RAISERROR (@error, 16, 1, @context)
  639. RETURN 1
  640. END -- net_find_tModel_name
  641. GO
  642. -- =============================================
  643. -- Name: net_find_tModel_identifierBag
  644. -- =============================================
  645. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_tModel_identifierBag' AND type = 'P')
  646. DROP PROCEDURE net_find_tModel_identifierBag
  647. GO
  648. CREATE PROCEDURE net_find_tModel_identifierBag
  649. @contextID uniqueidentifier,
  650. @keyName nvarchar(4000),
  651. @keyValue nvarchar(4000),
  652. @tModelKey uniqueidentifier,
  653. @orKeys bit = 0,
  654. @rows int OUTPUT
  655. WITH ENCRYPTION
  656. AS
  657. BEGIN
  658. DECLARE
  659. @error int,
  660. @context nvarchar(4000),
  661. @contextRows int
  662. DECLARE @tempKeys TABLE(
  663. [entityKey] uniqueidentifier)
  664. SET @contextRows = dbo.contextRows(@contextID)
  665. IF @contextRows = 0
  666. BEGIN
  667. INSERT @tempKeys(
  668. [entityKey])
  669. SELECT DISTINCT
  670. TM.[tModelKey]
  671. FROM
  672. [UDC_tModels] TM
  673. JOIN [UDC_identifierBag_TM] IB ON TM.[tModelID] = IB.[tModelID]
  674. WHERE
  675. (IB.[tModelKey] = @tModelKey) AND
  676. (IB.[keyValue] = @keyValue) AND
  677. (TM.[flag] = 0)
  678. END
  679. ELSE
  680. BEGIN
  681. INSERT @tempKeys(
  682. [entityKey])
  683. SELECT DISTINCT
  684. TM.[tModelKey]
  685. FROM
  686. [UDC_tModels] TM
  687. JOIN [UDC_identifierBag_TM] IB ON TM.[tModelID] = IB.[tModelID]
  688. WHERE
  689. (TM.[tModelKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  690. (IB.[tModelKey] = @tModelKey) AND
  691. (IB.[keyValue] = @keyValue) AND
  692. (TM.[flag] = 0)
  693. END
  694. IF @orKeys = 1
  695. BEGIN
  696. INSERT [UDS_findScratch] (
  697. [contextID],
  698. [entityKey])
  699. SELECT DISTINCT
  700. @contextID,
  701. [entityKey]
  702. FROM
  703. @tempKeys
  704. WHERE
  705. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  706. END
  707. ELSE
  708. BEGIN
  709. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  710. BEGIN
  711. DELETE
  712. [UDS_findScratch]
  713. WHERE
  714. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  715. END
  716. ELSE
  717. BEGIN
  718. INSERT [UDS_findScratch] (
  719. [contextID],
  720. [entityKey])
  721. SELECT DISTINCT
  722. @contextID,
  723. [entityKey]
  724. FROM
  725. @tempKeys
  726. END
  727. END
  728. SELECT
  729. @rows = COUNT(*)
  730. FROM
  731. [UDS_findScratch]
  732. WHERE
  733. ([contextID] = @contextID)
  734. RETURN 0
  735. errorLabel:
  736. RAISERROR (@error, 16, 1, @context)
  737. RETURN 1
  738. END -- net_find_tModel_identifierBag
  739. GO
  740. -- =============================================
  741. -- Name: net_find_tModel_categoryBag
  742. -- =============================================
  743. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_tModel_categoryBag' AND type = 'P')
  744. DROP PROCEDURE net_find_tModel_categoryBag
  745. GO
  746. CREATE PROCEDURE net_find_tModel_categoryBag
  747. @contextID uniqueidentifier,
  748. @keyName nvarchar(4000),
  749. @keyValue nvarchar(4000),
  750. @tModelKey uniqueidentifier,
  751. @orKeys bit = 0,
  752. @rows int OUTPUT
  753. WITH ENCRYPTION
  754. AS
  755. BEGIN
  756. DECLARE
  757. @error int,
  758. @context nvarchar(4000),
  759. @contextRows int,
  760. @genKeywordsMatch bit
  761. DECLARE @tempKeys TABLE(
  762. [entityKey] uniqueidentifier)
  763. SET @contextRows = dbo.contextRows(@contextID)
  764. SET @genKeywordsMatch = 0
  765. IF @tModelKey = dbo.genKeywordsKey()
  766. SET @genKeywordsMatch = 1
  767. IF @contextRows = 0
  768. BEGIN
  769. IF @genKeywordsMatch = 0
  770. BEGIN
  771. -- Ignore keyName
  772. INSERT @tempKeys(
  773. [entityKey])
  774. SELECT DISTINCT
  775. TM.[tModelKey]
  776. FROM
  777. [UDC_tModels] TM
  778. JOIN [UDC_categoryBag_TM] CB ON TM.[tModelID] = CB.[tModelID]
  779. WHERE
  780. (CB.[tModelKey] = @tModelKey) AND
  781. (CB.[keyValue] = @keyValue) AND
  782. (TM.[flag] = 0)
  783. END
  784. ELSE
  785. BEGIN
  786. -- Include keyName
  787. INSERT @tempKeys(
  788. [entityKey])
  789. SELECT DISTINCT
  790. TM.[tModelKey]
  791. FROM
  792. [UDC_tModels] TM
  793. JOIN [UDC_categoryBag_TM] CB ON TM.[tModelID] = CB.[tModelID]
  794. WHERE
  795. (CB.[tModelKey] = @tModelKey) AND
  796. (CB.[keyValue] = @keyValue) AND
  797. (ISNULL(CB.[keyName],'') = ISNULL(@keyName,'')) AND
  798. (TM.[flag] = 0)
  799. END
  800. END
  801. ELSE
  802. BEGIN
  803. IF @genKeywordsMatch = 0
  804. BEGIN
  805. -- Ignore keyName
  806. INSERT @tempKeys(
  807. [entityKey])
  808. SELECT DISTINCT
  809. TM.[tModelKey]
  810. FROM
  811. [UDC_tModels] TM
  812. JOIN [UDC_categoryBag_TM] CB ON TM.[tModelID] = CB.[tModelID]
  813. WHERE
  814. (TM.[tModelKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  815. (CB.[tModelKey] = @tModelKey) AND
  816. (CB.[keyValue] = @keyValue) AND
  817. (TM.[flag] = 0)
  818. END
  819. ELSE
  820. BEGIN
  821. -- Include keyName
  822. INSERT @tempKeys(
  823. [entityKey])
  824. SELECT DISTINCT
  825. TM.[tModelKey]
  826. FROM
  827. [UDC_tModels] TM
  828. JOIN [UDC_categoryBag_TM] CB ON TM.[tModelID] = CB.[tModelID]
  829. WHERE
  830. (TM.[tModelKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  831. (CB.[tModelKey] = @tModelKey) AND
  832. (CB.[keyValue] = @keyValue) AND
  833. (ISNULL(CB.[keyName],'') = ISNULL(@keyName,'')) AND
  834. (TM.[flag] = 0)
  835. END
  836. END
  837. IF @orKeys = 1
  838. BEGIN
  839. INSERT [UDS_findScratch] (
  840. [contextID],
  841. [entityKey])
  842. SELECT DISTINCT
  843. @contextID,
  844. [entityKey]
  845. FROM
  846. @tempKeys
  847. WHERE
  848. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  849. END
  850. ELSE
  851. BEGIN
  852. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  853. BEGIN
  854. DELETE
  855. [UDS_findScratch]
  856. WHERE
  857. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  858. END
  859. ELSE
  860. BEGIN
  861. INSERT [UDS_findScratch] (
  862. [contextID],
  863. [entityKey])
  864. SELECT DISTINCT
  865. @contextID,
  866. [entityKey]
  867. FROM
  868. @tempKeys
  869. END
  870. END
  871. SELECT
  872. @rows = COUNT(*)
  873. FROM
  874. [UDS_findScratch]
  875. WHERE
  876. ([contextID] = @contextID)
  877. RETURN 0
  878. errorLabel:
  879. RAISERROR (@error, 16, 1, @context)
  880. RETURN 1
  881. END -- net_find_tModel_categoryBag
  882. GO
  883. -- =============================================
  884. -- Name: net_find_tModel_commit
  885. -- =============================================
  886. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_tModel_commit' AND type = 'P')
  887. DROP PROCEDURE net_find_tModel_commit
  888. GO
  889. CREATE PROCEDURE net_find_tModel_commit
  890. @contextID uniqueidentifier,
  891. @sortByNameAsc bit,
  892. @sortByNameDesc bit,
  893. @sortByDateAsc bit,
  894. @sortByDateDesc bit,
  895. @maxRows int,
  896. @truncated int OUTPUT
  897. WITH ENCRYPTION
  898. AS
  899. BEGIN
  900. -- Finalizes a find_business and returns a key list
  901. DECLARE
  902. @error int,
  903. @context nvarchar(4000),
  904. @contextRows int
  905. SET @contextRows = dbo.contextRows(@contextID)
  906. SET @truncated = 0
  907. IF @contextRows = 0
  908. RETURN 0
  909. DECLARE @tempKeys TABLE (
  910. [seqNo] bigint IDENTITY PRIMARY KEY ,
  911. [entityKey] uniqueidentifier,
  912. [name] nvarchar(450) NULL,
  913. [lastChange] bigint NULL,
  914. [tModelID] bigint NULL)
  915. -- Set default sorting option
  916. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0) AND (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  917. SET @sortByNameAsc = 1
  918. -- Set maxRows if default was passed
  919. IF ISNULL(@maxRows,0) = 0
  920. SET @maxRows = dbo.configValue('Find.MaxRowsDefault')
  921. -- sortByNameAsc
  922. IF (@sortByNameAsc = 1)
  923. BEGIN
  924. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  925. SET @sortByDateAsc = 1
  926. IF (@sortByDateAsc = 1)
  927. BEGIN
  928. INSERT @tempKeys(
  929. [entityKey],
  930. [name],
  931. [lastChange],
  932. [tModelID])
  933. SELECT DISTINCT
  934. FR.[entityKey],
  935. TM.[name],
  936. TM.[lastChange],
  937. TM.[tModelID]
  938. FROM
  939. [UDS_findResults] FR
  940. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  941. ORDER BY
  942. 2 ASC,
  943. 3 ASC,
  944. 4 ASC
  945. END
  946. ELSE
  947. BEGIN
  948. INSERT @tempKeys(
  949. [entityKey],
  950. [name],
  951. [lastChange],
  952. [tModelID])
  953. SELECT DISTINCT
  954. FR.[entityKey],
  955. TM.[name],
  956. TM.[lastChange],
  957. TM.[tModelID]
  958. FROM
  959. [UDS_findResults] FR
  960. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  961. ORDER BY
  962. 2 ASC,
  963. 3 DESC,
  964. 4 DESC
  965. END
  966. GOTO endLabel
  967. END
  968. -- sortByNameDesc
  969. IF (@sortByNameDesc = 1)
  970. BEGIN
  971. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  972. SET @sortByDateAsc = 1
  973. IF (@sortByDateAsc = 1)
  974. BEGIN
  975. INSERT @tempKeys(
  976. [entityKey],
  977. [name],
  978. [lastChange],
  979. [tModelID])
  980. SELECT DISTINCT
  981. FR.[entityKey],
  982. TM.[name],
  983. TM.[lastChange],
  984. TM.[tModelID]
  985. FROM
  986. [UDS_findResults] FR
  987. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  988. ORDER BY
  989. 2 DESC,
  990. 3 ASC,
  991. 4 ASC
  992. END
  993. ELSE
  994. BEGIN
  995. INSERT @tempKeys(
  996. [entityKey],
  997. [name],
  998. [lastChange],
  999. [tModelID])
  1000. SELECT DISTINCT
  1001. FR.[entityKey],
  1002. TM.[name],
  1003. TM.[lastChange],
  1004. TM.[tModelID]
  1005. FROM
  1006. [UDS_findResults] FR
  1007. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  1008. ORDER BY
  1009. 2 DESC,
  1010. 3 DESC,
  1011. 4 DESC
  1012. END
  1013. GOTO endLabel
  1014. END
  1015. -- sortByDateAsc
  1016. IF (@sortByDateAsc = 1)
  1017. BEGIN
  1018. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  1019. SET @sortByNameAsc = 1
  1020. IF (@sortByNameAsc = 1)
  1021. BEGIN
  1022. INSERT @tempKeys(
  1023. [entityKey],
  1024. [name],
  1025. [lastChange],
  1026. [tModelID])
  1027. SELECT DISTINCT
  1028. FR.[entityKey],
  1029. TM.[name],
  1030. TM.[lastChange],
  1031. TM.[tModelID]
  1032. FROM
  1033. [UDS_findResults] FR
  1034. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  1035. ORDER BY
  1036. 3 ASC,
  1037. 4 ASC,
  1038. 2 ASC
  1039. END
  1040. ELSE
  1041. BEGIN
  1042. INSERT @tempKeys(
  1043. [entityKey],
  1044. [name],
  1045. [lastChange],
  1046. [tModelID])
  1047. SELECT DISTINCT
  1048. FR.[entityKey],
  1049. TM.[name],
  1050. TM.[lastChange],
  1051. TM.[tModelID]
  1052. FROM
  1053. [UDS_findResults] FR
  1054. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  1055. ORDER BY
  1056. 3 ASC,
  1057. 4 ASC,
  1058. 2 DESC
  1059. END
  1060. GOTO endLabel
  1061. END
  1062. -- sortByDateDesc
  1063. IF (@sortByDateDesc = 1)
  1064. BEGIN
  1065. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  1066. SET @sortByNameAsc = 1
  1067. IF (@sortByNameAsc = 1)
  1068. BEGIN
  1069. INSERT @tempKeys(
  1070. [entityKey],
  1071. [name],
  1072. [lastChange],
  1073. [tModelID])
  1074. SELECT DISTINCT
  1075. FR.[entityKey],
  1076. TM.[name],
  1077. TM.[lastChange],
  1078. TM.[tModelID]
  1079. FROM
  1080. [UDS_findResults] FR
  1081. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  1082. ORDER BY
  1083. 3 DESC,
  1084. 4 DESC,
  1085. 2 ASC
  1086. END
  1087. ELSE
  1088. BEGIN
  1089. INSERT @tempKeys(
  1090. [entityKey],
  1091. [name],
  1092. [lastChange],
  1093. [tModelID])
  1094. SELECT DISTINCT
  1095. FR.[entityKey],
  1096. TM.[name],
  1097. TM.[lastChange],
  1098. TM.[tModelID]
  1099. FROM
  1100. [UDS_findResults] FR
  1101. JOIN [UDC_tModels] TM ON FR.[entityKey] = TM.[tModelKey] AND @contextID = FR.[contextID]
  1102. ORDER BY
  1103. 3 DESC,
  1104. 4 DESC,
  1105. 2 DESC
  1106. END
  1107. GOTO endLabel
  1108. END
  1109. endLabel:
  1110. -- Set @truncated
  1111. IF (SELECT COUNT(*) FROM @tempKeys) > @maxRows
  1112. SET @truncated = 1
  1113. -- Return keys
  1114. SELECT
  1115. [entityKey]
  1116. FROM
  1117. @tempKeys
  1118. WHERE
  1119. ([seqNo] <= @maxRows)
  1120. -- Run cleanup
  1121. EXEC net_find_cleanup @contextID
  1122. RETURN 0
  1123. errorLabel:
  1124. RAISERROR (@error, 16, 1, @context)
  1125. RETURN 1
  1126. END -- net_find_tModel_commit
  1127. GO
  1128. -- =============================================
  1129. -- Section: Miscellaneous
  1130. -- =============================================
  1131. -- =============================================
  1132. -- Name: net_tModel_owner_update
  1133. -- =============================================
  1134. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_tModel_owner_update' AND type = 'P')
  1135. DROP PROCEDURE net_tModel_owner_update
  1136. GO
  1137. CREATE PROCEDURE net_tModel_owner_update
  1138. @tModelKey uniqueidentifier,
  1139. @PUID nvarchar(450)
  1140. WITH ENCRYPTION
  1141. AS
  1142. BEGIN
  1143. DECLARE
  1144. @error int,
  1145. @context nvarchar(4000),
  1146. @tModelID bigint,
  1147. @publisherID bigint
  1148. -- Validate parameters
  1149. SET @tModelID = dbo.tModelID(@tModelKey)
  1150. IF @tModelID IS NULL
  1151. BEGIN
  1152. SET @error = 60210 -- E_invalidKeyPassed
  1153. SET @context = 'tModelKey = ' + dbo.UUIDSTR(@tModelKey)
  1154. GOTO errorLabel
  1155. END
  1156. SET @publisherID = dbo.publisherID(@PUID)
  1157. IF @publisherID IS NULL
  1158. BEGIN
  1159. SET @error = 60150 -- E_unknownUser
  1160. SET @context = 'PUID = ' + @PUID
  1161. GOTO errorLabel
  1162. END
  1163. UPDATE
  1164. [UDC_tModels]
  1165. SET
  1166. [publisherID] = @publisherID
  1167. WHERE
  1168. ([tModelID] = @tModelID)
  1169. RETURN 0
  1170. errorLabel:
  1171. RAISERROR (@error, 16, 1, @context)
  1172. RETURN 1
  1173. END -- net_tModel_owner_update
  1174. GO