iidec / Integra.Space.Language-upstream

Lenguaje de consulta que permite el acceso a datos en tiempo real
0 stars 0 forks source link

Compilación de comandos debe devolver un nodo comando y no un contexto del pipeline #28

Closed OscarCanek closed 7 years ago

OscarCanek commented 8 years ago

Actualmente la compilación de comando retorna un contexto que se utiliza en el "primer pipeline". La actualización consiste que en lugar de retornar un contexto para el pipeline se retorne un objeto comando que herede de una clase abstracta SpaceCommand que implementa a su vez la interfaz ISpaceCommand. Dicha interfaz es la que se colocará en el contexto del pipeline sustituyendo toda la información que actualmente contiene de cada comando.

interface ISpaceCommand
{
   SpaceActionCommandEnum Action {get;}
   SpaceObjectEnum SpaceObjectType {get;}
   string ObjectName {get;}
}

abstract class SpaceCommand
{
   private SpaceActionCommandEnum Action;
   private SpaceObjectEnum spaceObjectType;
   private string objectName;

   public SpaceCommand()
   {
      ....
   }

   SpaceActionCommandEnum Action {get { return this.action; }}
   SpaceObjectEnum SpaceObjectType {get { return this.spaceObjectType; }}
   string ObjectName {get { return this.objectName; }}
}

Cada comando específico heredará de la clase abstracta SpaceCommand. La interfaz ISpaceCommand estará contenida en el proyecto Integra.Space.Common ya que se utilizará en Integra.Space.Language, Integra.Space e Integra.Space.UnitTests.

marianogenovese commented 8 years ago

En este caso, no surge la necesidad de usar interface puesto que es equivalente hacerlo en interface que clase abstracta.

OscarCanek commented 8 years ago

Ya fue eliminada la interfaz. La clase abstracta quedó de la siguiente forma:

internal abstract class SpaceCommand
    {
        /// <summary>
        /// Command action.
        /// </summary>
        private SpaceActionCommandEnum action;

        /// <summary>
        /// Space object type.
        /// </summary>
        private SpaceObjectEnum spaceObjectType;

        /// <summary>
        /// Space object name.
        /// </summary>
        private string objectName;

        /// <summary>
        /// Initializes a new instance of the <see cref="SpaceCommand"/> class.
        /// </summary>
        /// <param name="action">Space command action.</param>
        /// <param name="spaceObjectType">Space object type.</param>
        /// <param name="objectName">Object name.</param>
        public SpaceCommand(SpaceActionCommandEnum action, SpaceObjectEnum spaceObjectType, string objectName)
        {
            this.action = action;
            this.spaceObjectType = spaceObjectType;
            this.objectName = objectName;
        }

        /// <summary>
        /// Gets command action.
        /// </summary>
        public SpaceActionCommandEnum Action
        {
            get
            {
                return this.action;
            }
        }

        /// <summary>
        /// Gets the space object type.
        /// </summary>
        public SpaceObjectEnum SpaceObjectType
        {
            get
            {
                return this.spaceObjectType;
            }
        }

        /// <summary>
        /// Gets the object name.
        /// </summary>
        public string ObjectName
        {
            get
            {
                return this.objectName;
            }
        }

        /// <summary>
        /// Gets the list of used space object types by the command.
        /// </summary>
        /// <returns>The list of used objects by the command.</returns>
        public virtual HashSet<SpaceObjectEnum> GetUsedSpaceObjectTypes()
        {
            HashSet<SpaceObjectEnum> listOfUsedObjectTypes = new HashSet<SpaceObjectEnum>();
            listOfUsedObjectTypes.Add(this.spaceObjectType);

            return listOfUsedObjectTypes;
        }

        /// <summary>
        /// Gets the list of used space objects by the command.
        /// </summary>
        /// <returns>The list of used objects by the command.</returns>
        public virtual HashSet<Tuple<SpaceObjectEnum, string>> GetUsedSpaceObjects()
        {
            HashSet<Tuple<SpaceObjectEnum, string>> listOfUsedObjects = new HashSet<Tuple<SpaceObjectEnum, string>>(new ObjectUsedComparer());
            listOfUsedObjects.Add(Tuple.Create(this.spaceObjectType, this.objectName));

            return listOfUsedObjects;
        }

        /// <summary>
        /// Object used comparer class.
        /// </summary>
        private class ObjectUsedComparer : IEqualityComparer<Tuple<SpaceObjectEnum, string>>
        {
            /// <inheritdoc />
            public bool Equals(Tuple<SpaceObjectEnum, string> x, Tuple<SpaceObjectEnum, string> y)
            {
                if (x.Item1 == y.Item1 && x.Item2 == y.Item2)
                {
                    return true;
                }

                return false;
            }

            /// <inheritdoc />
            public int GetHashCode(Tuple<SpaceObjectEnum, string> obj)
            {
                if (obj.Item2 != null)
                {
                    return obj.Item1.GetHashCode() + obj.Item2.GetHashCode();
                }
                else
                {
                    return obj.Item1.GetHashCode();
                }
            }
        }
    }
OscarCanek commented 8 years ago

Actualización

//-----------------------------------------------------------------------
// <copyright file="SystemCommand.cs" company="Integra.Space.Common">
//     Copyright (c) Integra.Space.Common. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Integra.Space.Language
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using System.Linq;
    using Common;

    /// <summary>
    /// Command action node class.
    /// </summary>
    internal abstract class SystemCommand
    {
        /// <summary>
        /// Command action.
        /// </summary>
        private ActionCommandEnum action;

        /// <summary>
        /// Objects specified in the command.
        /// </summary>
        private HashSet<CommandObject> commandObjects;

        /// <summary>
        /// Initializes a new instance of the <see cref="SystemCommand"/> class.
        /// </summary>
        /// <param name="action">Space command action.</param>
        /// <param name="commandObject">Command object.</param>
        /// <param name="schemaName">Schema name for the command execution.</param>
        /// <param name="databaseName">Database name for the command execution.</param>
        public SystemCommand(ActionCommandEnum action, CommandObject commandObject, string schemaName, string databaseName)
        {
            Contract.Assert(commandObject != null);

            this.action = action;
            this.SchemaName = schemaName;
            this.DatabaseName = databaseName;
            this.MainCommandObject = commandObject;
            this.commandObjects = new HashSet<CommandObject>(new CommandObjectComparer());
            this.commandObjects.Add(commandObject);

            if (!string.IsNullOrWhiteSpace(schemaName))
            {
                this.commandObjects.Add(new CommandObject(SystemObjectEnum.Schema, schemaName, PermissionsEnum.None, false));
            }

            if (!string.IsNullOrWhiteSpace(databaseName))
            {
                this.commandObjects.Add(new CommandObject(SystemObjectEnum.Database, databaseName, PermissionsEnum.Connect, false));
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SystemCommand"/> class.
        /// </summary>
        /// <param name="action">Space command action.</param>
        /// <param name="commandObjects">Command objects.</param>
        /// <param name="schemaName">Schema name for the command execution.</param>
        /// <param name="databaseName">Database name for the command execution.</param>
        public SystemCommand(ActionCommandEnum action, HashSet<CommandObject> commandObjects, string schemaName, string databaseName)
        {
            Contract.Assert(commandObjects != null);
            Contract.Assert(commandObjects.Count > 0);
            Contract.Assert(commandObjects.All(x => !string.IsNullOrWhiteSpace(x.Name)));

            this.action = action;
            this.SchemaName = schemaName;
            this.DatabaseName = databaseName;
            this.commandObjects = commandObjects;

            if (!string.IsNullOrWhiteSpace(schemaName))
            {
                this.commandObjects.Add(new CommandObject(SystemObjectEnum.Schema, schemaName, PermissionsEnum.None, false));
            }

            if (!string.IsNullOrWhiteSpace(databaseName))
            {
                this.commandObjects.Add(new CommandObject(SystemObjectEnum.Database, databaseName, PermissionsEnum.Connect, false));
            }
        }

        /// <summary>
        /// Gets the objects specified in the command.
        /// </summary>
        public virtual HashSet<CommandObject> CommandObjects
        {
            get
            {
                return this.commandObjects;
            }
        }

        /// <summary>
        /// Gets command action.
        /// </summary>
        public ActionCommandEnum Action
        {
            get
            {
                return this.action;
            }
        }

        /// <summary>
        /// Gets the schema of the object.
        /// </summary>
        public string SchemaName { get; private set; }

        /// <summary>
        /// Gets the database name for the command execution.
        /// </summary>
        public string DatabaseName { get; private set; }

        /// <summary>
        /// Gets the main command object.
        /// </summary>
        public CommandObject MainCommandObject { get; private set; }
    }
}
OscarCanek commented 8 years ago

Debido a que ahora el comando se coloca dentro de los contextos de los pipelines, ya sea de primer nivel o segundo nivel, el objeto común de comunicación entre los pipes es el contexto, por lo tanto la entrada y la salida de cada uno es un objeto contexto de primer o segundo nivel. Debido a lo anterior este issue se cerrará ya que no aplica para en la implementación actual.