public void Save(string parentKey, EntityType parentType, KeyedReferenceType keyedReferenceType) { Debug.Enter(); // // IN 87 Need to validate that keyedReferences that contain the uddi-org:owningBusinessKey. We can't // do this in validate because the parentKey won't be set if the parent is a new tmodel. // ValidateOwningBusiness(parentType, keyedReferenceType); SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor(); switch (parentType) { case EntityType.BusinessEntity: if (KeyedReferenceType.CategoryBag == keyedReferenceType) { sp.ProcedureName = "net_businessEntity_categoryBag_save"; } else { sp.ProcedureName = "net_businessEntity_identifierBag_save"; } sp.Parameters.Add("@businessKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromString("@businessKey", parentKey); break; case EntityType.BusinessService: Debug.Assert( KeyedReferenceType.CategoryBag == keyedReferenceType, "Unexpected keyed reference type '" + keyedReferenceType.ToString() + "' for parent entity type '" + parentType.ToString() + "'"); sp.ProcedureName = "net_businessService_categoryBag_save"; sp.Parameters.Add("@serviceKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromString("@serviceKey", parentKey); break; case EntityType.TModel: if (KeyedReferenceType.CategoryBag == keyedReferenceType) { sp.ProcedureName = "net_tModel_categoryBag_save"; } else { sp.ProcedureName = "net_tModel_identifierBag_save"; } sp.Parameters.Add("@tModelKeyParent", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromKey("@tModelKeyParent", parentKey); break; default: throw new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_UNEXPECTED_PARENT_ENTITY_TYPE", parentType.ToString()); } sp.Parameters.Add("@keyName", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyName); sp.Parameters.Add("@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue); sp.Parameters.Add("@tModelKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetString("@keyName", KeyName); sp.Parameters.SetString("@keyValue", KeyValue); sp.Parameters.SetGuidFromKey("@tModelKey", TModelKey); sp.ExecuteNonQuery(); Debug.Leave(); }
public void Get(string parentKey, EntityType parentType, KeyedReferenceType keyedReferenceType) { Debug.Enter(); SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor(); switch (parentType) { case EntityType.BusinessEntity: if (KeyedReferenceType.CategoryBag == keyedReferenceType) { sp.ProcedureName = "net_businessEntity_categoryBag_get"; } else { sp.ProcedureName = "net_businessEntity_identifierBag_get"; } sp.Parameters.Add("@businessKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromString("@businessKey", parentKey); break; case EntityType.BusinessService: Debug.Assert( KeyedReferenceType.CategoryBag == keyedReferenceType, "Unexpected keyed reference type '" + keyedReferenceType.ToString() + "' for parent entity type '" + parentType.ToString() + "'"); sp.ProcedureName = "net_businessService_categoryBag_get"; sp.Parameters.Add("@serviceKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromString("@serviceKey", parentKey); break; case EntityType.TModel: if (KeyedReferenceType.CategoryBag == keyedReferenceType) { sp.ProcedureName = "net_tModel_categoryBag_get"; } else { sp.ProcedureName = "net_tModel_identifierBag_get"; } sp.Parameters.Add("@tModelKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromKey("@tModelKey", parentKey); break; default: throw new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_UNEXPECTED_PARENT_ENTITY_TYPE", parentType.ToString()); } SqlDataReaderAccessor reader = sp.ExecuteReader(); try { Read(reader); #if never while (reader.Read()) { Add( reader.GetString("keyName"), reader.GetString("keyValue"), reader.GetKeyFromGuid("tModelKey")); } #endif } finally { reader.Close(); } Debug.Leave(); }
/// **************************************************************** /// public FindByKeyedReferences /// ---------------------------------------------------------------- /// <summary> /// </summary> /// ---------------------------------------------------------------- /// <param name="keyedReferenceType"> /// </param> /// /// <param name="keyedReferences"> /// </param> /// **************************************************************** /// public int FindByKeyedReferences(KeyedReferenceType keyedReferenceType, KeyedReferenceCollection keyedReferences) { int rows = 0; // // Fix for Windows Bug #728622 // OrAllKeys findQualifier was being modified for the scope of the entire find. // This fix preserves the initial value of OrAllKeys so as not to affect subsequent method invocations in the same find. // All subsequent references to OrAllKeys are replaced by OrAllKeysTemp in this method. // bool OrAllKeysTemp = OrAllKeys; // // Set up the stored procedure call and set common parameters. // SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor(); switch (keyedReferenceType) { case KeyedReferenceType.CategoryBag: if (CombineCategoryBags) { sp.ProcedureName = "net_find_" + entityName + "_combineCategoryBags"; } else if (ServiceSubset) { sp.ProcedureName = "net_find_" + entityName + "_serviceSubset"; } else { sp.ProcedureName = "net_find_" + entityName + "_categoryBag"; } break; case KeyedReferenceType.IdentifierBag: if (AndAllKeys == false) { // // Fix for Windows Bug #728622 // // OrAllKeys = true; // if OrLikeKeys has been specified, that will be overriden below OrAllKeysTemp = true; } sp.ProcedureName = "net_find_" + entityName + "_identifierBag"; break; default: throw new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_UNEXPECTEDKRTYPE", keyedReferenceType.ToString()); } sp.Parameters.Add("@contextID", SqlDbType.UniqueIdentifier); sp.Parameters.Add("@keyName", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyName); sp.Parameters.Add("@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue); sp.Parameters.Add("@tModelKey", SqlDbType.UniqueIdentifier); sp.Parameters.Add("@orKeys", SqlDbType.Bit); sp.Parameters.Add("@rows", SqlDbType.Int, ParameterDirection.Output); sp.Parameters.SetGuid("@contextID", Context.ContextID); // // Determine whether we should be doing an 'orLikeKeys' search. // if (OrLikeKeys) { // // First group keyed references by tModelKey (basically // grouping by taxonomy). This will allow us to easily // process keyed references with the same taxonomy. In // an orLikeKeys search, we will match on any of the // keys for a given taxonomy (a logical OR operation). // ArrayList sortedList = new ArrayList(); foreach (KeyedReference keyedReference in keyedReferences) { sortedList.Add(keyedReference); } sortedList.Sort(new TModelKeyComparer()); // // In an orLikeKeys search, we or all keys in the scratch // table. // sp.Parameters.SetBool("@orKeys", true); // // Process each group of keyed references. Each time // we cross a group boundary (seen when the current // tModelKey is different than the last one we processed), // commit the data in the scratch table to the main results // table (a logical AND operation with the result of other // search constraints). // string prevKey = ((KeyedReference)sortedList[0]).TModelKey.ToLower(); bool dirty = false; foreach (KeyedReference keyedReference in sortedList) { Utility.IsValidKey(EntityType.TModel, keyedReference.TModelKey); if (prevKey != keyedReference.TModelKey.ToLower()) { // // Logical AND scratch table results with main table. // rows = ScratchCommit(); dirty = false; // // If the main results list is now empty, we don't // need to process any more constraints. // if (0 == rows) { return(rows); } } sp.Parameters.SetString("@keyName", keyedReference.KeyName); sp.Parameters.SetString("@keyValue", keyedReference.KeyValue); sp.Parameters.SetGuidFromKey("@tModelKey", keyedReference.TModelKey); sp.ExecuteNonQuery(); dirty = true; prevKey = keyedReference.TModelKey.ToLower(); } // // If the scratch table contains results that haven't been // processed, logical AND them with the main table. // if (dirty) { rows = ScratchCommit(); } } else { // // Determine whether we should be performing a logical OR or // AND on results from each keyed reference. // // // // Fix for Windows Bug #728622 // // sp.Parameters.SetBool( "@orKeys", OrAllKeys ); sp.Parameters.SetBool("@orKeys", OrAllKeysTemp); // // Process each keyed reference. // foreach (KeyedReference keyedReference in keyedReferences) { sp.Parameters.SetString("@keyName", keyedReference.KeyName); sp.Parameters.SetString("@keyValue", keyedReference.KeyValue); sp.Parameters.SetGuidFromKey("@tModelKey", keyedReference.TModelKey); sp.ExecuteNonQuery(); int sprows = sp.Parameters.GetInt("@rows"); // // No point continuing if a query returns no results in AND operation. // // // Fix for Windows Bug #728622 // // if( false == this.OrAllKeys && 0 == sprows ) if (false == OrAllKeysTemp && 0 == sprows) { break; } } // // Logical AND scratch table results with main table. // rows = ScratchCommit(); } return(rows); }