/// <summary> /// Creates new object identifier template without name part. Base implementation supports /// only 3-parts identifiers. /// </summary> /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param> /// <param name="typeName">Object type name to create identifier.</param> /// <returns>Returns new object identifier template without name part.</returns> protected virtual object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName) { if (hierarchy == null) { throw new ArgumentNullException("hierarchy"); } if (typeName == null) { throw new ArgumentNullException("typeName"); } // Only objects with identifier length 3 is supported if (ObjectDescriptor.GetIdentifierLength(typeName) != 3) { throw new NotSupportedException(String.Format( CultureInfo.CurrentCulture, Resources.Error_ObjectTypeNotSupported, typeName)); } // Get default schema string schema = hierarchy.Connection.Schema; Debug.Assert(!String.IsNullOrEmpty(schema), "Failed to retrive schema name!"); if (schema == null) { return(null); } // Create template ID return(new object[] { null, schema, null }); }
/// <summary> /// This function is overriden to control trigger names uniques for whole database and /// not for each table. /// </summary> /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param> /// <param name="typeName">Object type name.</param> /// <param name="id">Array with object identifier.</param> /// <param name="template">Template for the new object identifier.</param> protected override void CompleteNewObjectID(ServerExplorerFacade hierarchy, string typeName, ref object[] id, string template) { if (hierarchy == null) { throw new ArgumentNullException("hierarchy"); } if (typeName == null) { throw new ArgumentNullException("typeName"); } if (id == null) { throw new ArgumentNullException("id"); } if (id.Length < 3 || id[2] == null) { throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Resources.Error_InvlaidIdentifier, id.Length, typeName, ObjectDescriptor.GetIdentifierLength(typeName)), "id"); } if (String.IsNullOrEmpty(template)) { throw new ArgumentException(Resources.Error_EmptyString, "template"); } // Initialize complete parameters string actualTameplate = template; int counter = 0; do { // Stores table id and reset it to null in template, because trigger names must be // unique for a whole database. object tableID = id[2]; id[2] = null; // Use base method for completion base.CompleteNewObjectID(hierarchy, typeName, ref id, actualTameplate); // Restores table id id[2] = tableID; // Change template and add new counter actualTameplate = template + (++counter).ToString(); } // We need to control open editors here separately, because base method will miss them // (it doesn't know table ID) while (hierarchy.HasDocument(typeName, id)); }
/// <summary> /// Template for trigger includes owner table name. /// </summary> /// <param name="typeName">Type name of the object.</param> /// <param name="id">Identifier base for the object created so far.</param> /// <returns>Returns template for the new object name.</returns> protected override string GetTemplate(string typeName, object[] id) { if (typeName == null) { throw new ArgumentNullException("typeName"); } if (id == null || id.Length < 3 || id[2] == null) { throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Resources.Error_InvlaidIdentifier, id.Length, typeName, ObjectDescriptor.GetIdentifierLength(typeName)), "id"); } return(id[2].ToString() + '_' + typeName); }
/// <summary> /// Generates new object identifier. For objects owned directly by schema, generates /// variation of "schema.{object type}¹". For nested objects returns variation of /// "{parent ID}.{object type}¹". /// </summary> /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param> /// <param name="item">Item identifier.</param> /// <param name="typeName">Object type name.</param> /// <returns>Returns array with multipart identifier for the object.</returns> protected override object[] GetObjectID(ServerExplorerFacade hierarchy, string typeName, int item) { if (hierarchy == null) { throw new ArgumentNullException("hierarchy"); } if (item < 0) { throw new ArgumentOutOfRangeException("item"); } if (typeName == null) { throw new ArgumentNullException("typeName"); } // Get identifier length int idLength = ObjectDescriptor.GetIdentifierLength(typeName); if (idLength <= 0) { throw new NotSupportedException(String.Format( CultureInfo.CurrentCulture, Resources.Error_ObjectTypeNotSupported, typeName)); } // Create object ID template object[] id; // Get parent object identifier object[] parentID = hierarchy.GetObjectIdentifier(item); // For embedded objects ID is ID of owner object with one additional slot. if (parentID != null && parentID.Length == idLength - 1) { // Initialize object identifier template id = new object[idLength]; // Copy parent object identifier to the template parentID.CopyTo(id, 0); } // For root objects (objects owned directly by schema) ID has three slots with // schema name in the middle else { id = CreateNewIDBase(hierarchy, typeName); if (id == null || id.Length != idLength) { throw new NotSupportedException(String.Format( CultureInfo.CurrentCulture, Resources.Error_ObjectTypeNotSupported, typeName)); } } // Extract template for the new name string template = GetTemplate(typeName, id); if (template == null) { template = typeName; } // Generate object name (fill the last slot) CompleteNewObjectID(hierarchy, typeName, ref id, template); // Return result return(id); }