Ejemplo n.º 1
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</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");

            return hierarchy.GetObjectIdentifier(item);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</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");
            }

            return(hierarchy.GetObjectIdentifier(item));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</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");

            // If this is not a table or a view, data editing is not supported.
            if (!DataInterpreter.CompareInvariant(typeName, TableDataDescriptor.TypeName))
                return null;

            // ID is the object ID of the hierarchy item
            return hierarchy.GetObjectIdentifier(item);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns identifier of the object for the given node.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</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");
            }

            // If this is not a table or a view, data editing is not supported.
            if (!DataInterpreter.CompareInvariant(typeName, TableDataDescriptor.TypeName))
            {
                return(null);
            }

            // ID is the object ID of the hierarchy item
            return(hierarchy.GetObjectIdentifier(item));
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Drops single item. Uses object descriptor to build DROP statement.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Result of execution. Typicaly null.</returns>
        protected override object ExecuteSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
                throw new ArgumentNullException("hierarchy");
            if (item < 0)
                throw new ArgumentOutOfRangeException("item");

            // Extract type name
            string typeName = GetObjectType(hierarchy, item);
            if (String.IsNullOrEmpty(typeName))
            {
                Debug.Fail("Failed to get object type!");
                return false;
            }

            // Extract descriptor
            IObjectDescriptor descriptor = ObjectDescriptorFactory.Instance.CreateDescriptor(typeName);
            if (descriptor == null || !descriptor.CanBeDropped)
            {
                Debug.Fail("Failed to get descriptor or descriptor doesn't support dropping!");
                return null;
            }

            // Extract object identifier
            object[] identifier = hierarchy.GetObjectIdentifier(item);
            if (identifier == null)
            {
                Debug.Fail("Failed to get object identifier!");
                return null;
            }

            // TODO: Note the seconde check for TableData document. It should be replaced in the future
            // by the generic mechanism.
            
            // Check if editor is registered for the database object
            if (hierarchy.HasDocument(typeName, identifier) || hierarchy.HasDocument(TableDataDescriptor.TypeName, identifier))
            {
                UIHelper.ShowError(String.Format(
                    CultureInfo.InvariantCulture,
                    Resources.Error_CantDropBecauseOfEditor,
                    hierarchy.GetName(item)));
                return null;
            }

            // Build DROP query
			string dropQuery = String.Empty;
			if (descriptor is StoredProcDescriptor)
				dropQuery = (descriptor as StoredProcDescriptor).BuildDropSql(
					hierarchy, item, identifier);
			else
				dropQuery = descriptor.BuildDropSql(identifier);

			if (String.IsNullOrEmpty(dropQuery))
            {
                Debug.Fail("Failed to build DROP query!");
                return null;
            }

            // Extract connection
            DataConnectionWrapper connection = hierarchy.Connection;
            if (connection == null)
            {
                Debug.Fail("Failed to extract connection!");
                return null;
            }

            try
            {
                // Execute drop query
                connection.ExecuteScalar(dropQuery);

                // Drop hierarchy node
                hierarchy.DropObjectNode(item);                

                // Notify everybody about object dropping
                connection.ObjectChangeEvents.RaiseObjectRemoved(typeName, identifier);
            }
            catch (DbException e)
            {
                Trace.TraceError("Error during saving object:\n{0}", e.ToString());
                SqlErrorDialog.ShowError(e, connection.GetFullStatus());
            }
            catch (Exception e)
            {
                Trace.TraceError("Error during saving object:\n{0}", e.ToString());
                UIHelper.ShowError(e);
            }

            return null;
        }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Drops single item. Uses object descriptor to build DROP statement.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="item">Item identifier.</param>
        /// <returns>Result of execution. Typicaly null.</returns>
        protected override object ExecuteSingleItem(ServerExplorerFacade hierarchy, int item)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (item < 0)
            {
                throw new ArgumentOutOfRangeException("item");
            }

            // Extract type name
            string typeName = GetObjectType(hierarchy, item);

            if (String.IsNullOrEmpty(typeName))
            {
                Debug.Fail("Failed to get object type!");
                return(false);
            }

            // Extract descriptor
            IObjectDescriptor descriptor = ObjectDescriptorFactory.Instance.CreateDescriptor(typeName);

            if (descriptor == null || !descriptor.CanBeDropped)
            {
                Debug.Fail("Failed to get descriptor or descriptor doesn't support dropping!");
                return(null);
            }

            // Extract object identifier
            object[] identifier = hierarchy.GetObjectIdentifier(item);
            if (identifier == null)
            {
                Debug.Fail("Failed to get object identifier!");
                return(null);
            }

            // TODO: Note the seconde check for TableData document. It should be replaced in the future
            // by the generic mechanism.

            // Check if editor is registered for the database object
            if (hierarchy.HasDocument(typeName, identifier) || hierarchy.HasDocument(TableDataDescriptor.TypeName, identifier))
            {
                UIHelper.ShowError(String.Format(
                                       CultureInfo.InvariantCulture,
                                       Resources.Error_CantDropBecauseOfEditor,
                                       hierarchy.GetName(item)));
                return(null);
            }

            // Build DROP query
            string dropQuery = String.Empty;

            if (descriptor is StoredProcDescriptor)
            {
                dropQuery = (descriptor as StoredProcDescriptor).BuildDropSql(
                    hierarchy, item, identifier);
            }
            else
            {
                dropQuery = descriptor.BuildDropSql(identifier);
            }

            if (String.IsNullOrEmpty(dropQuery))
            {
                Debug.Fail("Failed to build DROP query!");
                return(null);
            }

            // Extract connection
            DataConnectionWrapper connection = hierarchy.Connection;

            if (connection == null)
            {
                Debug.Fail("Failed to extract connection!");
                return(null);
            }

            try
            {
                // Execute drop query
                connection.ExecuteScalar(dropQuery);

                // Drop hierarchy node
                hierarchy.DropObjectNode(item);

                // Notify everybody about object dropping
                connection.ObjectChangeEvents.RaiseObjectRemoved(typeName, identifier);
            }
            catch (DbException e)
            {
                Trace.TraceError("Error during saving object:\n{0}", e.ToString());
                SqlErrorDialog.ShowError(e, connection.GetFullStatus());
            }
            catch (Exception e)
            {
                Trace.TraceError("Error during saving object:\n{0}", e.ToString());
                UIHelper.ShowError(e);
            }

            return(null);
        }