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.

827 lines
27 KiB

  1. /// ************************************************************************
  2. /// Microsoft UDDI version 2.0
  3. /// Copyright (c) 2000-2001 Microsoft Corporation
  4. /// All Rights Reserved
  5. /// ------------------------------------------------------------------------
  6. /// <summary>
  7. /// </summary>
  8. /// ************************************************************************
  9. ///
  10. using System;
  11. using System.Data;
  12. using System.Data.SqlClient;
  13. using System.Collections;
  14. using System.Collections.Specialized;
  15. using System.Text;
  16. using UDDI;
  17. using UDDI.Diagnostics;
  18. using UDDI.API.Business;
  19. namespace UDDI.API
  20. {
  21. /// ********************************************************************
  22. /// public class FindBuilder
  23. /// --------------------------------------------------------------------
  24. /// <summary>
  25. /// </summary>
  26. /// ********************************************************************
  27. ///
  28. public class FindBuilder
  29. {
  30. //
  31. // Find entity type
  32. //
  33. private EntityType entityType;
  34. private string entityName = null;
  35. private string parentKey = null;
  36. //
  37. // Find qualifiers
  38. //
  39. public bool ExactNameMatch = false;
  40. public bool CaseSensitiveMatch = false;
  41. public bool SortByNameAsc = false;
  42. public bool SortByNameDesc = false;
  43. public bool SortByDateAsc = false;
  44. public bool SortByDateDesc = false;
  45. public bool OrLikeKeys = false;
  46. public bool OrAllKeys = false;
  47. public bool CombineCategoryBags = false;
  48. public bool ServiceSubset = false;
  49. public bool AndAllKeys = false;
  50. public bool Soundex = false;
  51. /// ****************************************************************
  52. /// public FindBuilder [constructor]
  53. /// ----------------------------------------------------------------
  54. /// <summary>
  55. /// </summary>
  56. /// ----------------------------------------------------------------
  57. /// <param name="entityType">
  58. /// The type of entity to search for.
  59. /// </param>
  60. ///
  61. /// <param name="findQualifiers">
  62. /// </param>
  63. ///
  64. /// <param name="parentKey">
  65. /// </param>
  66. /// ****************************************************************
  67. ///
  68. public FindBuilder( EntityType entityType, FindQualifierCollection findQualifiers, string parentKey )
  69. : this( entityType, findQualifiers )
  70. {
  71. this.parentKey = parentKey;
  72. }
  73. /// ****************************************************************
  74. /// public FindBuilder [constructor]
  75. /// ----------------------------------------------------------------
  76. /// <summary>
  77. /// </summary>
  78. /// ----------------------------------------------------------------
  79. /// <param name="entityType">
  80. /// The type of entity to search for.
  81. /// </param>
  82. ///
  83. /// <param name="findQualifiers">
  84. /// </param>
  85. /// ****************************************************************
  86. ///
  87. public FindBuilder( EntityType entityType, FindQualifierCollection findQualifiers )
  88. {
  89. this.entityType = entityType;
  90. this.entityName = Conversions.EntityNameFromID( entityType );
  91. //
  92. // Parse the find qualifiers.
  93. //
  94. if( null != findQualifiers )
  95. {
  96. foreach( FindQualifier findQualifier in findQualifiers )
  97. {
  98. //
  99. // Need to trim whitespace
  100. //
  101. switch( findQualifier.Value.Trim() )
  102. {
  103. case "exactNameMatch":
  104. if( EntityType.BusinessEntity == entityType ||
  105. EntityType.BusinessService == entityType ||
  106. EntityType.TModel == entityType )
  107. ExactNameMatch = true;
  108. break;
  109. case "caseSensitiveMatch":
  110. if( EntityType.BusinessEntity == entityType ||
  111. EntityType.BusinessService == entityType ||
  112. EntityType.TModel == entityType )
  113. CaseSensitiveMatch = true;
  114. break;
  115. case "sortByNameAsc":
  116. if( EntityType.BusinessEntity == entityType ||
  117. EntityType.BusinessService == entityType ||
  118. EntityType.TModel == entityType )
  119. {
  120. //
  121. // sortByNameAsc and sortByNameDesc are mutually exclusive.
  122. //
  123. Debug.Verify( !SortByNameDesc, "UDDI_ERROR_UNSUPPORTED_NAMEASCANDDESC", ErrorType.E_unsupported );
  124. SortByNameAsc = true;
  125. }
  126. break;
  127. case "sortByNameDesc":
  128. if( EntityType.BusinessEntity == entityType ||
  129. EntityType.BusinessService == entityType ||
  130. EntityType.TModel == entityType )
  131. {
  132. //
  133. // sortByNameAsc and sortByNameDesc are mutually exclusive.
  134. //
  135. Debug.Verify( !SortByNameAsc, "UDDI_ERROR_UNSUPPORTED_NAMEASCANDDESC", ErrorType.E_unsupported );
  136. SortByNameDesc = true;
  137. }
  138. break;
  139. case "sortByDateAsc":
  140. if( EntityType.BindingTemplate == entityType ||
  141. EntityType.BusinessEntity == entityType ||
  142. EntityType.BusinessService == entityType ||
  143. EntityType.TModel == entityType )
  144. {
  145. //
  146. // sortByDateAsc and sortByDateDesc are mutually exclusive.
  147. //
  148. Debug.Verify( !SortByDateDesc, "UDDI_ERROR_UNSUPPORTED_DATEASCANDDESC", ErrorType.E_unsupported );
  149. SortByDateAsc = true;
  150. }
  151. break;
  152. case "sortByDateDesc":
  153. if( EntityType.BindingTemplate == entityType ||
  154. EntityType.BusinessEntity == entityType ||
  155. EntityType.BusinessService == entityType ||
  156. EntityType.TModel == entityType )
  157. {
  158. //
  159. // sortByDateAsc and sortByDateDesc are mutually exclusive.
  160. //
  161. Debug.Verify( !SortByDateAsc, "UDDI_ERROR_UNSUPPORTED_DATEASCANDDESC", ErrorType.E_unsupported );
  162. SortByDateDesc = true;
  163. }
  164. break;
  165. case "orLikeKeys":
  166. if( EntityType.BusinessEntity == entityType ||
  167. EntityType.BusinessService == entityType ||
  168. EntityType.TModel == entityType )
  169. {
  170. //
  171. // orLikeKeys, orAllKeys, and andAllKeys are mutually exclusive.
  172. //
  173. Debug.Verify( !OrAllKeys && !AndAllKeys, "UDDI_ERROR_UNSUPPORTED_KEYSORAND", ErrorType.E_unsupported );
  174. OrLikeKeys = true;
  175. }
  176. break;
  177. case "orAllKeys":
  178. if( EntityType.BusinessEntity == entityType ||
  179. EntityType.BindingTemplate == entityType ||
  180. EntityType.BusinessService == entityType ||
  181. EntityType.TModel == entityType )
  182. {
  183. //
  184. // orLikeKeys, orAllKeys, and andAllKeys are mutually exclusive.
  185. //
  186. Debug.Verify( !OrLikeKeys && !AndAllKeys, "UDDI_ERROR_UNSUPPORTED_KEYSORAND", ErrorType.E_unsupported );
  187. OrAllKeys = true;
  188. }
  189. break;
  190. case "combineCategoryBags":
  191. if( EntityType.BusinessEntity == entityType )
  192. {
  193. CombineCategoryBags = true;
  194. }
  195. break;
  196. case "serviceSubset":
  197. if( EntityType.BusinessEntity == entityType )
  198. {
  199. ServiceSubset = true;
  200. }
  201. break;
  202. case "andAllKeys":
  203. if( EntityType.BusinessEntity == entityType ||
  204. EntityType.TModel == entityType )
  205. {
  206. //
  207. // orLikeKeys, orAllKeys, and andAllKeys are mutually exclusive.
  208. //
  209. Debug.Verify( !OrLikeKeys && !OrAllKeys, "UDDI_ERROR_UNSUPPORTED_KEYSORAND", ErrorType.E_unsupported );
  210. AndAllKeys = true;
  211. }
  212. break;
  213. default:
  214. throw new UDDIException(
  215. ErrorType.E_unsupported,
  216. "UDDI_ERROR_UNSUPPORTED_FINDQUALIFIER",
  217. findQualifier.Value );
  218. }
  219. }
  220. }
  221. }
  222. /// ****************************************************************
  223. /// private ScratchCommit
  224. /// ----------------------------------------------------------------
  225. /// <summary>
  226. /// </summary>
  227. /// ----------------------------------------------------------------
  228. /// <returns>
  229. /// </returns>
  230. /// ****************************************************************
  231. ///
  232. private int ScratchCommit()
  233. {
  234. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_find_scratch_commit" );
  235. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  236. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  237. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  238. sp.ExecuteNonQuery();
  239. return sp.Parameters.GetInt( "@rows" );
  240. }
  241. /// ****************************************************************
  242. /// public Abort
  243. /// ----------------------------------------------------------------
  244. /// <summary>
  245. /// </summary>
  246. /// ****************************************************************
  247. ///
  248. public void Abort()
  249. {
  250. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_find_cleanup" );
  251. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  252. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  253. sp.ExecuteNonQuery();
  254. }
  255. /// ****************************************************************
  256. /// public RetrieveResults
  257. /// ----------------------------------------------------------------
  258. /// <summary>
  259. /// </summary>
  260. /// ----------------------------------------------------------------
  261. /// <param name="maxRows">
  262. /// </param>
  263. ///
  264. /// <param name="truncated">
  265. /// </param>
  266. /// ****************************************************************
  267. ///
  268. public SqlStoredProcedureAccessor RetrieveResults( int maxRows )
  269. {
  270. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  271. if( ServiceSubset )
  272. sp.ProcedureName = "net_find_businessEntity_serviceSubset_commit";
  273. else
  274. sp.ProcedureName = "net_find_" + entityName + "_commit";
  275. if( entityName != "bindingTemplate" )
  276. {
  277. sp.Parameters.Add( "@sortByNameAsc", SqlDbType.Bit );
  278. sp.Parameters.Add( "@sortByNameDesc", SqlDbType.Bit );
  279. }
  280. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  281. sp.Parameters.Add( "@sortByDateAsc", SqlDbType.Bit );
  282. sp.Parameters.Add( "@sortByDateDesc", SqlDbType.Bit );
  283. sp.Parameters.Add( "@maxRows", SqlDbType.Int );
  284. sp.Parameters.Add( "@truncated", SqlDbType.Bit, ParameterDirection.Output );
  285. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  286. if( entityName != "bindingTemplate" )
  287. {
  288. sp.Parameters.SetBool( "@sortByNameAsc", SortByNameAsc );
  289. sp.Parameters.SetBool( "@sortByNameDesc", SortByNameDesc );
  290. }
  291. sp.Parameters.SetBool( "@sortByDateAsc", SortByDateAsc );
  292. sp.Parameters.SetBool( "@sortByDateDesc", SortByDateDesc );
  293. int defaultMaxRows = Config.GetInt( "Find.MaxRowsDefault" );
  294. if( maxRows < 0 || maxRows > defaultMaxRows )
  295. maxRows = defaultMaxRows;
  296. sp.Parameters.SetInt( "@maxRows", maxRows );
  297. return sp;
  298. }
  299. /// ****************************************************************
  300. /// public FindByName
  301. /// ----------------------------------------------------------------
  302. /// <summary>
  303. /// </summary>
  304. /// ----------------------------------------------------------------
  305. /// <param name="name">
  306. /// </param>
  307. /// ****************************************************************
  308. ///
  309. public int FindByName( string name )
  310. {
  311. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  312. sp.ProcedureName = "net_find_" + entityName + "_name";
  313. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  314. sp.Parameters.Add( "@name", SqlDbType.NVarChar, UDDI.Constants.Lengths.Name );
  315. sp.Parameters.Add( "@exactNameMatch", SqlDbType.Bit );
  316. sp.Parameters.Add( "@caseSensitiveMatch", SqlDbType.Bit );
  317. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  318. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  319. sp.Parameters.SetBool( "@exactNameMatch", ExactNameMatch );
  320. sp.Parameters.SetBool( "@caseSensitiveMatch", CaseSensitiveMatch );
  321. sp.Parameters.SetString( "@name", LikeEncode( name ) );
  322. sp.ExecuteNonQuery();
  323. return ScratchCommit();
  324. }
  325. /// ****************************************************************
  326. /// public FindByNames
  327. /// ----------------------------------------------------------------
  328. /// <summary>
  329. /// </summary>
  330. /// ----------------------------------------------------------------
  331. /// <param name="names">
  332. /// </param>
  333. /// ****************************************************************
  334. ///
  335. public int FindByNames( NameCollection names )
  336. {
  337. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  338. sp.ProcedureName = "net_find_" + entityName + "_name";
  339. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  340. sp.Parameters.Add( "@name", SqlDbType.NVarChar, UDDI.Constants.Lengths.Name );
  341. sp.Parameters.Add( "@isoLangCode", SqlDbType.VarChar, UDDI.Constants.Lengths.IsoLangCode );
  342. sp.Parameters.Add( "@exactNameMatch", SqlDbType.Bit );
  343. sp.Parameters.Add( "@caseSensitiveMatch", SqlDbType.Bit );
  344. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  345. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  346. sp.Parameters.SetBool( "@exactNameMatch", ExactNameMatch );
  347. sp.Parameters.SetBool( "@caseSensitiveMatch", CaseSensitiveMatch );
  348. foreach( Name name in names )
  349. {
  350. sp.Parameters.SetString( "@name", LikeEncode( name.Value ) );
  351. if( Utility.StringEmpty( name.IsoLangCode ) )
  352. sp.Parameters.SetString( "@isoLangCode", "%" );
  353. else
  354. sp.Parameters.SetString( "@isoLangCode", name.IsoLangCode );
  355. sp.ExecuteNonQuery();
  356. }
  357. return ScratchCommit();
  358. }
  359. /// ****************************************************************
  360. /// public FindByDiscoveryUrls
  361. /// ----------------------------------------------------------------
  362. /// <summary>
  363. /// </summary>
  364. /// ----------------------------------------------------------------
  365. /// <param name="discoveryUrls">
  366. /// </param>
  367. /// ****************************************************************
  368. ///
  369. public int FindByDiscoveryUrls( DiscoveryUrlCollection discoveryUrls )
  370. {
  371. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  372. sp.ProcedureName = "net_find_" + entityName + "_discoveryURL";
  373. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  374. sp.Parameters.Add( "@useType", SqlDbType.NVarChar, UDDI.Constants.Lengths.UseType );
  375. sp.Parameters.Add( "@discoveryURL", SqlDbType.NVarChar, UDDI.Constants.Lengths.DiscoveryURL );
  376. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  377. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  378. int rows = 0;
  379. foreach( DiscoveryUrl discoveryUrl in discoveryUrls )
  380. {
  381. sp.Parameters.SetString( "@useType", discoveryUrl.UseType );
  382. sp.Parameters.SetString( "@discoveryURL", discoveryUrl.Value );
  383. sp.ExecuteNonQuery();
  384. rows = sp.Parameters.GetInt( "@rows" );
  385. }
  386. return ScratchCommit();
  387. }
  388. /// ****************************************************************
  389. /// public FindByTModelBag
  390. /// ----------------------------------------------------------------
  391. /// <summary>
  392. /// </summary>
  393. /// ----------------------------------------------------------------
  394. /// <param name="tModelBag">
  395. /// </param>
  396. /// ****************************************************************
  397. ///
  398. public int FindByTModelBag( StringCollection tModelBag )
  399. {
  400. //
  401. // First validate all the keys, this will make sure any invalid keys are 'caught' beforehand.
  402. //
  403. foreach( string tModelKey in tModelBag )
  404. {
  405. Utility.IsValidKey( EntityType.TModel, tModelKey );
  406. }
  407. //
  408. // Set up the stored procedure call and set common parameters.
  409. //
  410. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  411. sp.ProcedureName = "net_find_" + entityName + "_tModelBag";
  412. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  413. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  414. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  415. sp.Parameters.Add( "@orKeys", SqlDbType.Bit );
  416. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  417. sp.Parameters.SetBool( "@orKeys", OrAllKeys );
  418. //
  419. // Process each tModelKey.
  420. //
  421. foreach( string tModelKey in tModelBag )
  422. {
  423. sp.Parameters.SetGuidFromKey( "@tModelKey", tModelKey );
  424. sp.ExecuteNonQuery();
  425. //
  426. // No point continuing if a query returns no results in AND operation.
  427. //
  428. if( false == this.OrAllKeys &&
  429. 0 == sp.Parameters.GetInt( "@rows" ) )
  430. {
  431. break;
  432. }
  433. }
  434. return ScratchCommit();
  435. }
  436. /// ****************************************************************
  437. /// public FindByKeyedReferences
  438. /// ----------------------------------------------------------------
  439. /// <summary>
  440. /// </summary>
  441. /// ----------------------------------------------------------------
  442. /// <param name="keyedReferenceType">
  443. /// </param>
  444. ///
  445. /// <param name="keyedReferences">
  446. /// </param>
  447. /// ****************************************************************
  448. ///
  449. public int FindByKeyedReferences( KeyedReferenceType keyedReferenceType, KeyedReferenceCollection keyedReferences )
  450. {
  451. int rows = 0;
  452. //
  453. // Fix for Windows Bug #728622
  454. // OrAllKeys findQualifier was being modified for the scope of the entire find.
  455. // This fix preserves the initial value of OrAllKeys so as not to affect subsequent method invocations in the same find.
  456. // All subsequent references to OrAllKeys are replaced by OrAllKeysTemp in this method.
  457. //
  458. bool OrAllKeysTemp = OrAllKeys;
  459. //
  460. // Set up the stored procedure call and set common parameters.
  461. //
  462. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  463. switch( keyedReferenceType )
  464. {
  465. case KeyedReferenceType.CategoryBag:
  466. if( CombineCategoryBags )
  467. sp.ProcedureName = "net_find_" + entityName + "_combineCategoryBags";
  468. else if( ServiceSubset )
  469. sp.ProcedureName = "net_find_" + entityName + "_serviceSubset";
  470. else
  471. sp.ProcedureName = "net_find_" + entityName + "_categoryBag";
  472. break;
  473. case KeyedReferenceType.IdentifierBag:
  474. if (AndAllKeys == false)
  475. {
  476. //
  477. // Fix for Windows Bug #728622
  478. //
  479. // OrAllKeys = true; // if OrLikeKeys has been specified, that will be overriden below
  480. OrAllKeysTemp = true;
  481. }
  482. sp.ProcedureName = "net_find_" + entityName + "_identifierBag";
  483. break;
  484. default:
  485. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_UNEXPECTEDKRTYPE",keyedReferenceType.ToString() );
  486. }
  487. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  488. sp.Parameters.Add( "@keyName", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyName );
  489. sp.Parameters.Add( "@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue );
  490. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  491. sp.Parameters.Add( "@orKeys", SqlDbType.Bit );
  492. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  493. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  494. //
  495. // Determine whether we should be doing an 'orLikeKeys' search.
  496. //
  497. if( OrLikeKeys )
  498. {
  499. //
  500. // First group keyed references by tModelKey (basically
  501. // grouping by taxonomy). This will allow us to easily
  502. // process keyed references with the same taxonomy. In
  503. // an orLikeKeys search, we will match on any of the
  504. // keys for a given taxonomy (a logical OR operation).
  505. //
  506. ArrayList sortedList = new ArrayList();
  507. foreach( KeyedReference keyedReference in keyedReferences )
  508. sortedList.Add( keyedReference );
  509. sortedList.Sort( new TModelKeyComparer() );
  510. //
  511. // In an orLikeKeys search, we or all keys in the scratch
  512. // table.
  513. //
  514. sp.Parameters.SetBool( "@orKeys", true );
  515. //
  516. // Process each group of keyed references. Each time
  517. // we cross a group boundary (seen when the current
  518. // tModelKey is different than the last one we processed),
  519. // commit the data in the scratch table to the main results
  520. // table (a logical AND operation with the result of other
  521. // search constraints).
  522. //
  523. string prevKey = ((KeyedReference)sortedList[0]).TModelKey.ToLower();
  524. bool dirty = false;
  525. foreach( KeyedReference keyedReference in sortedList )
  526. {
  527. Utility.IsValidKey( EntityType.TModel, keyedReference.TModelKey );
  528. if( prevKey != keyedReference.TModelKey.ToLower() )
  529. {
  530. //
  531. // Logical AND scratch table results with main table.
  532. //
  533. rows = ScratchCommit();
  534. dirty = false;
  535. //
  536. // If the main results list is now empty, we don't
  537. // need to process any more constraints.
  538. //
  539. if( 0 == rows )
  540. return rows;
  541. }
  542. sp.Parameters.SetString( "@keyName", keyedReference.KeyName );
  543. sp.Parameters.SetString( "@keyValue", keyedReference.KeyValue );
  544. sp.Parameters.SetGuidFromKey( "@tModelKey", keyedReference.TModelKey );
  545. sp.ExecuteNonQuery();
  546. dirty = true;
  547. prevKey = keyedReference.TModelKey.ToLower();
  548. }
  549. //
  550. // If the scratch table contains results that haven't been
  551. // processed, logical AND them with the main table.
  552. //
  553. if( dirty )
  554. rows = ScratchCommit();
  555. }
  556. else
  557. {
  558. //
  559. // Determine whether we should be performing a logical OR or
  560. // AND on results from each keyed reference.
  561. //
  562. //
  563. //
  564. // Fix for Windows Bug #728622
  565. //
  566. // sp.Parameters.SetBool( "@orKeys", OrAllKeys );
  567. sp.Parameters.SetBool( "@orKeys", OrAllKeysTemp );
  568. //
  569. // Process each keyed reference.
  570. //
  571. foreach( KeyedReference keyedReference in keyedReferences )
  572. {
  573. sp.Parameters.SetString( "@keyName", keyedReference.KeyName );
  574. sp.Parameters.SetString( "@keyValue", keyedReference.KeyValue );
  575. sp.Parameters.SetGuidFromKey( "@tModelKey", keyedReference.TModelKey );
  576. sp.ExecuteNonQuery();
  577. int sprows = sp.Parameters.GetInt( "@rows" );
  578. //
  579. // No point continuing if a query returns no results in AND operation.
  580. //
  581. //
  582. // Fix for Windows Bug #728622
  583. //
  584. // if( false == this.OrAllKeys && 0 == sprows )
  585. if( false == OrAllKeysTemp && 0 == sprows )
  586. {
  587. break;
  588. }
  589. }
  590. //
  591. // Logical AND scratch table results with main table.
  592. //
  593. rows = ScratchCommit();
  594. }
  595. return rows;
  596. }
  597. public int FindByParentKey( string parentKey )
  598. {
  599. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  600. switch( entityType )
  601. {
  602. case EntityType.BusinessService:
  603. sp.ProcedureName = "net_find_businessService_businessKey";
  604. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  605. sp.Parameters.SetGuidFromString( "@businessKey", parentKey );
  606. break;
  607. case EntityType.BindingTemplate:
  608. sp.ProcedureName = "net_find_bindingTemplate_serviceKey";
  609. sp.Parameters.Add( "@serviceKey", SqlDbType.UniqueIdentifier );
  610. sp.Parameters.SetGuidFromString( "@serviceKey", parentKey );
  611. break;
  612. default:
  613. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_UNEXPECTEDENTITYTYPE", entityType.ToString() );
  614. }
  615. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  616. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  617. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  618. sp.ExecuteNonQuery();
  619. return sp.Parameters.GetInt( "@rows" );
  620. }
  621. public SqlStoredProcedureAccessor FindRelatedBusinesses( string businessKey, KeyedReference keyedReference, int maxRows)
  622. {
  623. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_find_businessEntity_relatedBusinesses" );
  624. sp.Parameters.Add( "@contextID", SqlDbType.UniqueIdentifier );
  625. sp.Parameters.Add( "@businessKey", SqlDbType.UniqueIdentifier );
  626. sp.Parameters.Add( "@keyName", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyName );
  627. sp.Parameters.Add( "@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue );
  628. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  629. sp.Parameters.Add( "@sortByNameAsc", SqlDbType.Bit );
  630. sp.Parameters.Add( "@sortByNameDesc", SqlDbType.Bit );
  631. sp.Parameters.Add( "@sortByDateAsc", SqlDbType.Bit );
  632. sp.Parameters.Add( "@sortByDateDesc", SqlDbType.Bit );
  633. sp.Parameters.Add( "@maxRows", SqlDbType.Int );
  634. sp.Parameters.Add( "@truncated", SqlDbType.Int, ParameterDirection.Output );
  635. sp.Parameters.Add( "@rows", SqlDbType.Int, ParameterDirection.Output );
  636. sp.Parameters.SetGuid( "@contextID", Context.ContextID );
  637. sp.Parameters.SetGuidFromString( "@businessKey", businessKey );
  638. if( null != keyedReference )
  639. {
  640. sp.Parameters.SetString( "@keyName", keyedReference.KeyName );
  641. sp.Parameters.SetString( "@keyValue", keyedReference.KeyValue );
  642. sp.Parameters.SetGuidFromKey( "@tModelKey", keyedReference.TModelKey );
  643. }
  644. else
  645. {
  646. sp.Parameters.SetNull( "@keyName" );
  647. sp.Parameters.SetNull( "@keyValue" );
  648. sp.Parameters.SetNull( "@tModelKey" );
  649. }
  650. sp.Parameters.SetBool( "@sortByNameAsc", SortByNameAsc );
  651. sp.Parameters.SetBool( "@sortByNameDesc", SortByNameDesc );
  652. sp.Parameters.SetBool( "@sortByDateAsc", SortByDateAsc );
  653. sp.Parameters.SetBool( "@sortByDateDesc", SortByDateDesc );
  654. sp.Parameters.SetInt( "@maxRows", maxRows );
  655. return sp;
  656. }
  657. private class TModelKeyComparer : IComparer
  658. {
  659. public int Compare( object keyedReference1, object keyedReference2 )
  660. {
  661. return String.Compare(
  662. ((KeyedReference)keyedReference1).TModelKey.ToLower(),
  663. ((KeyedReference)keyedReference2).TModelKey.ToLower() );
  664. }
  665. }
  666. private string LikeEncode( string str )
  667. {
  668. if( null == str )
  669. return null;
  670. StringBuilder builder = new StringBuilder( str.Length );
  671. foreach( char ch in str )
  672. {
  673. switch( ch )
  674. {
  675. case '[':
  676. builder.Append( "[ [ ]" );
  677. break;
  678. case ']':
  679. builder.Append( "[ ] ]" );
  680. break;
  681. case '%':
  682. //
  683. // We'll always treat the % as a wildcard, so don't
  684. // escape in the client string.
  685. //
  686. builder.Append( ch );
  687. break;
  688. case '_':
  689. builder.Append( "[_]" );
  690. break;
  691. default:
  692. builder.Append( ch );
  693. break;
  694. }
  695. }
  696. return builder.ToString();
  697. }
  698. }
  699. }