Пример #1
0
 void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
 {
     if (reader.MoveToAttribute("Left"))
     {
         _left = reader.ReadContentAsString();
     }
     if (reader.MoveToAttribute("Right"))
     {
         _right = reader.ReadContentAsString();
     }
     if (reader.MoveToAttribute("Type"))
     {
         _type = (JoinType)Enum.Parse(typeof(JoinType), reader.ReadContentAsString());
     }
     reader.MoveToElement();
     if (!reader.IsEmptyElement)
     {
         reader.ReadStartElement();
         if (!reader.IsEmptyElement && reader.LocalName == "Conditional")
         {
             _conditional = new ConditionalContainer();
             ((System.Xml.Serialization.IXmlSerializable)_conditional).ReadXml(reader);
         }
         reader.ReadEndElement();
     }
     else
     {
         reader.Skip();
     }
 }
Пример #2
0
        /// <summary>
        /// Construtor usado na deserialização dos dados.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        private QueryInfo(SerializationInfo info, StreamingContext context)
        {
            _id = info.GetInt32("Id");
            var methodText = info.GetString("Method");

            Method                   = (QueryMethod)Enum.Parse(typeof(QueryMethod), methodText);
            _projection              = (Projection)info.GetValue("Projection", typeof(Projection));
            _entities                = (EntityInfo[])info.GetValue("Entities", typeof(EntityInfo[]));
            _executePredicate        = (QueryExecutePredicate)info.GetValue("ExecutePredicate", typeof(QueryExecutePredicate));
            _groupby                 = (GroupBy)info.GetValue("GroupBy", typeof(GroupBy));
            _having                  = (ConditionalContainer)info.GetValue("Having", typeof(ConditionalContainer));
            _sort                    = (Sort)info.GetValue("Sort", typeof(Sort));
            _whereClause             = (ConditionalContainer)info.GetValue("WhereClause", typeof(ConditionalContainer));
            _takeParameters          = (TakeParameters)info.GetValue("TakeParameters", typeof(TakeParameters));
            _parameters              = (QueryParameterCollection)info.GetValue("Parameters", typeof(QueryParameterCollection));
            _nestedQueries           = (QueryInfo[])info.GetValue("NestedQueries", typeof(QueryInfo[]));
            _unions                  = (UnionInfoCollection)info.GetValue("Unions", typeof(UnionInfoCollection));
            _storedProcedureName     = (StoredProcedureName)info.GetValue("StoredProcedureName", typeof(StoredProcedureName));
            _storedProcedureProvider = info.GetString("StoredProcedureProvider");
            _ignoreRegisterUserInfo  = info.GetBoolean("IgnoreRegisterUserInfo");
            _isolationLevel          = (System.Transactions.IsolationLevel)info.GetInt16("IsolationLevel");
            _commandTimeout          = info.GetInt32("CommandTimeout");
            _providerName            = info.GetString("ProviderName");
            _ignoreTypeSchema        = info.GetBoolean("IgnoreTypeSchema");
        }
Пример #3
0
 /// <summary>
 /// Construtor usado na deserialização dos dados.
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 private JoinInfo(SerializationInfo info, StreamingContext context)
 {
     _left        = info.GetString("Left");
     _right       = info.GetString("Right");
     _conditional = info.GetValue("Conditional", typeof(ConditionalContainer)) as ConditionalContainer;
     _type        = (JoinType)Enum.Parse(typeof(JoinType), info.GetString("Type"));
 }
Пример #4
0
 /// <summary>
 /// Desserializa o objeto.
 /// </summary>
 /// <param name="reader"></param>
 void ICompactSerializable.Deserialize(Colosoft.Serialization.IO.CompactReader reader)
 {
     _left  = reader.ReadString();
     _right = reader.ReadString();
     _type  = (JoinType)Enum.Parse(typeof(JoinType), reader.ReadString());
     if (reader.ReadBoolean())
     {
         _conditional = new ConditionalContainer();
         ((ICompactSerializable)_conditional).Deserialize(reader);
     }
 }
Пример #5
0
 /// <summary>
 /// Recupera os parametros do container.
 /// </summary>
 /// <param name="container"></param>
 /// <returns></returns>
 private static IEnumerable <QueryParameter> GetParameters(ConditionalContainer container)
 {
     foreach (var i in container.ParameterContainer)
     {
         yield return(i);
     }
     foreach (var conditional in container.Conditionals)
     {
         foreach (var i in GetParameters(conditional))
         {
             yield return(i);
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Clona um container condicional.
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            var container = new ConditionalContainer();

            foreach (var term in this.Conditionals)
            {
                container._conditionals.Add((ConditionalTerm)term.Clone());
            }
            foreach (var param in this.ParameterContainer)
            {
                container.Add((QueryParameter)param.Clone());
            }
            container._logicalOperators = new List <LogicalOperator>(this.LogicalOperators);
            return(container);
        }
Пример #7
0
        void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            var attribute = reader.GetAttribute("Id");

            int.TryParse(attribute, out _id);
            attribute = reader.GetAttribute("Method");
            if (!string.IsNullOrEmpty(attribute))
            {
                Enum.TryParse <QueryMethod>(attribute, out _method);
            }
            attribute = reader.GetAttribute("IsSelectDistinct");
            bool.TryParse(attribute, out _isSelectDistinct);
            attribute = reader.GetAttribute("IgnoreRegisterUserInfo");
            bool.TryParse(attribute, out _ignoreRegisterUserInfo);
            attribute = reader.GetAttribute("IsolationLevel");
            if (!Enum.TryParse <System.Transactions.IsolationLevel>(attribute, out _isolationLevel))
            {
                _isolationLevel = System.Transactions.IsolationLevel.Unspecified;
            }
            attribute = reader.GetAttribute("CommandTimeout");
            if (!int.TryParse(attribute, out _commandTimeout))
            {
                _commandTimeout = 30;
            }
            _providerName            = reader.GetAttribute("ProviderName");
            _storedProcedureProvider = reader.GetAttribute("StoredProcedureProvider");
            attribute = reader.GetAttribute("IgnoreTypeSchema");
            bool.TryParse(attribute, out _ignoreTypeSchema);
            reader.ReadStartElement();
            _projection       = ReadItem <Projection>(reader, "Projection");
            _executePredicate = ReadItem <QueryExecutePredicate>(reader, "ExecutePredicate");
            var entitiesQueue = new Queue <EntityInfo>();

            if (!reader.IsEmptyElement && reader.LocalName == "Entities")
            {
                reader.ReadStartElement("Entities", Namespaces.Query);
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    var join = new EntityInfo();
                    ((System.Xml.Serialization.IXmlSerializable)join).ReadXml(reader);
                    entitiesQueue.Enqueue(join);
                }
                reader.ReadEndElement();
            }
            else
            {
                reader.Skip();
            }
            _entities = entitiesQueue.ToArray();
            var joinsQueue = new Queue <JoinInfo>();

            if (!reader.IsEmptyElement && reader.LocalName == "Joins")
            {
                reader.ReadStartElement("Joins", Namespaces.Query);
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    var join = new JoinInfo();
                    ((System.Xml.Serialization.IXmlSerializable)join).ReadXml(reader);
                    joinsQueue.Enqueue(join);
                }
                reader.ReadEndElement();
            }
            else
            {
                reader.Skip();
            }
            _joins          = joinsQueue.ToArray();
            _whereClause    = ReadItem <ConditionalContainer>(reader, "Where");
            _sort           = ReadItem <Sort>(reader, "Sort");
            _groupby        = ReadItem <GroupBy>(reader, "GroupBy");
            _having         = ReadItem <ConditionalContainer>(reader, "Having");
            _takeParameters = ReadItem <TakeParameters>(reader, "TakeParameters");
            var nestedQueries = new List <QueryInfo>();

            if (!reader.IsEmptyElement && reader.LocalName == "NestedQueries")
            {
                reader.ReadStartElement("NestedQueries", Namespaces.Query);
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    var queryInfo = new QueryInfo();
                    ((System.Xml.Serialization.IXmlSerializable)queryInfo).ReadXml(reader);
                    nestedQueries.Add(queryInfo);
                }
                reader.ReadEndElement();
            }
            else
            {
                reader.Skip();
            }
            _nestedQueries = nestedQueries.ToArray();
            _parameters    = new QueryParameterCollection();
            if (!reader.IsEmptyElement && reader.LocalName == "Parameters")
            {
                reader.ReadStartElement("Parameters", Namespaces.Query);
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    var parameter = new QueryParameter();
                    ((System.Xml.Serialization.IXmlSerializable)parameter).ReadXml(reader);
                    _parameters.Add(parameter);
                }
                reader.ReadEndElement();
            }
            else
            {
                reader.Skip();
            }
            _storedProcedureName = ReadItem <StoredProcedureName>(reader, "StoredProcedureName");
            _unions = new UnionInfoCollection();
            if (!reader.IsEmptyElement && reader.LocalName == "Unions")
            {
                reader.ReadStartElement("Unions", Namespaces.Query);
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    var union = new UnionInfo();
                    ((System.Xml.Serialization.IXmlSerializable)union).ReadXml(reader);
                    _unions.Add(union);
                }
                reader.ReadEndElement();
            }
            else
            {
                reader.Skip();
            }
            reader.ReadEndElement();
        }
Пример #8
0
        /// <summary>
        /// Desserializa o objeto.
        /// </summary>
        /// <param name="reader"></param>
        void ICompactSerializable.Deserialize(Colosoft.Serialization.IO.CompactReader reader)
        {
            _id = reader.ReadInt32();
            _isSelectDistinct       = reader.ReadBoolean();
            _ignoreRegisterUserInfo = reader.ReadBoolean();
            try
            {
                Enum.TryParse <QueryMethod>(reader.ReadString(), out _method);
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            _isolationLevel   = (System.Transactions.IsolationLevel)reader.ReadInt16();
            _commandTimeout   = reader.ReadInt32();
            _providerName     = reader.ReadString();
            _ignoreTypeSchema = reader.ReadBoolean();
            if (reader.ReadBoolean())
            {
                _storedProcedureProvider = reader.ReadString();
            }
            if (reader.ReadBoolean())
            {
                _projection = new Projection();
                ((ICompactSerializable)_projection).Deserialize(reader);
            }
            if (reader.ReadBoolean())
            {
                _executePredicate = new QueryExecutePredicate();
                ((ICompactSerializable)_executePredicate).Deserialize(reader);
            }
            var entitiesQueue = new Queue <EntityInfo>();

            while (reader.ReadBoolean())
            {
                var entity = new EntityInfo();
                ((ICompactSerializable)entity).Deserialize(reader);
                entitiesQueue.Enqueue(entity);
            }
            _entities = entitiesQueue.ToArray();
            var joinQueue = new Queue <JoinInfo>();

            while (reader.ReadBoolean())
            {
                var join = new JoinInfo();
                ((ICompactSerializable)join).Deserialize(reader);
                joinQueue.Enqueue(join);
            }
            _joins = joinQueue.ToArray();
            if (reader.ReadBoolean())
            {
                _whereClause = new ConditionalContainer();
                ((ICompactSerializable)_whereClause).Deserialize(reader);
            }
            if (reader.ReadBoolean())
            {
                _sort = new Sort();
                ((ICompactSerializable)_sort).Deserialize(reader);
            }
            if (reader.ReadBoolean())
            {
                _groupby = new GroupBy();
                ((ICompactSerializable)_groupby).Deserialize(reader);
            }
            if (reader.ReadBoolean())
            {
                _having = new ConditionalContainer();
                ((ICompactSerializable)_having).Deserialize(reader);
            }
            if (reader.ReadBoolean())
            {
                _takeParameters = new TakeParameters();
                ((ICompactSerializable)_takeParameters).Deserialize(reader);
            }
            var nestedQueries = new List <QueryInfo>();

            while (reader.ReadBoolean())
            {
                var nestedQuery = new QueryInfo();
                ((ICompactSerializable)nestedQuery).Deserialize(reader);
                nestedQueries.Add(nestedQuery);
            }
            _nestedQueries = nestedQueries.ToArray();
            if (_parameters == null)
            {
                _parameters = new QueryParameterCollection();
            }
            while (reader.ReadBoolean())
            {
                var parameter = new QueryParameter();
                parameter.Deserialize(reader);
                _parameters.Add(parameter);
            }
            if (reader.ReadBoolean())
            {
                _storedProcedureName = new StoredProcedureName();
                ((ICompactSerializable)_storedProcedureName).Deserialize(reader);
            }
            if (_unions == null)
            {
                _unions = new UnionInfoCollection();
            }
            while (reader.ReadBoolean())
            {
                var union = new UnionInfo();
                union.Deserialize(reader);
                _unions.Add(union);
            }
        }
Пример #9
0
        /// <summary>
        /// Recupera container condicional.
        /// </summary>
        /// <param name="enumerator">Enumerador dos items que serão analizados.</param>
        /// <param name="configuration"></param>
        /// <param name="containerInfo"></param>
        /// <returns></returns>
        private static ConditionalTerm GetContainer(ref IEnumerator <Text.InterpreterExpression.Expression> enumerator, Text.InterpreterExpression.ILexerConfiguration configuration, Text.InterpreterExpression.ContainerChars containerInfo)
        {
            ConditionalContainer container = null;
            var logical = Text.InterpreterExpression.TokenID.And;

            while (containerInfo == null || (string.IsNullOrEmpty(enumerator.Current.Text) || enumerator.Current.Text[0] != containerInfo.Stop))
            {
                var conditional = GetConditional(ref enumerator, configuration, containerInfo != null ? (char?)containerInfo.Stop : null);
                if (((conditional is ValuesArray) || (conditional is FunctionCall)) && container == null)
                {
                    return(conditional);
                }
                else if (container == null)
                {
                    container = new ConditionalContainer(conditional);
                }
                else if (logical == Text.InterpreterExpression.TokenID.And)
                {
                    container.And(conditional);
                }
                else if (logical == Text.InterpreterExpression.TokenID.Plus || logical == Text.InterpreterExpression.TokenID.Minus || logical == Text.InterpreterExpression.TokenID.Star || logical == Text.InterpreterExpression.TokenID.Slash)
                {
                    Operator oper = null;
                    switch (logical)
                    {
                    case Text.InterpreterExpression.TokenID.Plus:
                        oper = new Operator("+");
                        break;

                    case Text.InterpreterExpression.TokenID.Minus:
                        oper = new Operator("-");
                        break;

                    case Text.InterpreterExpression.TokenID.Star:
                        oper = new Operator("*");
                        break;

                    case Text.InterpreterExpression.TokenID.Slash:
                        oper = new Operator("/");
                        break;
                    }
                    ConditionalTerm left = container;
                    if (container.ConditionalsCount == 1)
                    {
                        left = container.Conditionals.First();
                    }
                    container = new ConditionalContainer(new Conditional(left, oper, conditional));
                }
                else
                {
                    container.Or(conditional);
                }
                if (enumerator.Current == null || (containerInfo != null && enumerator.Current.Text[0] == containerInfo.Stop))
                {
                    return(container);
                }
                else if (enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.And || enumerator.Current.Token == (int)Query.Parser.SqlTokenID.kAnd)
                {
                    logical = Text.InterpreterExpression.TokenID.And;
                }
                else if (enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.Or || enumerator.Current.Token == (int)Query.Parser.SqlTokenID.kOr)
                {
                    logical = Text.InterpreterExpression.TokenID.Or;
                }
                else if (enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.Plus || enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.Minus || enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.Star || enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.Slash)
                {
                    logical = (Text.InterpreterExpression.TokenID)enumerator.Current.Token;
                }
                if (!enumerator.MoveNext())
                {
                    break;
                }
            }
            return(container);
        }
Пример #10
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="container"></param>
 public WhereClause(ConditionalContainer container)
 {
     container.Require("container").NotNull();
     _container = container;
 }
Пример #11
0
 /// <summary>
 /// Adiciona o container condição inicial. Essa operação limpa todas a outras condições já existentes.
 /// </summary>
 /// <param name="conditional"></param>
 /// <returns></returns>
 public virtual IWhereClause Start(ConditionalContainer conditional)
 {
     Container.Start(conditional);
     return(this);
 }
Пример #12
0
 /// <summary>
 /// Adiciona um container de condição do tipo OR.
 /// </summary>
 /// <param name="conditional"></param>
 /// <returns></returns>
 public virtual IWhereClause Or(ConditionalContainer conditional)
 {
     Container.Or(conditional);
     return(this);
 }
Пример #13
0
        /// <summary>
        /// Recupera o termo condicional contido no reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal static protected ConditionalTerm GetConditionalTerm(Colosoft.Serialization.IO.CompactReader reader)
        {
            var             type = reader.ReadString();
            ConditionalTerm term = null;

            if (string.IsNullOrEmpty(type))
            {
                term = new Constant();
            }
            else
            {
                if (type == "Conditional")
                {
                    term = new Conditional();
                }
                else if (type == "ConditionalContainer")
                {
                    term = new ConditionalContainer();
                }
                else if (type == "Operator")
                {
                    term = new Operator();
                }
                else if (type == "Constant")
                {
                    term = new Constant();
                }
                else if (type == "Column")
                {
                    term = new Column();
                }
                else if (type == "Variable")
                {
                    term = new Variable();
                }
                else if (type == "ValuesArray")
                {
                    term = new ValuesArray();
                }
                else if (type == "QueryTerm")
                {
                    term = new QueryTerm();
                }
                else if (type == "FunctionCall")
                {
                    term = new FunctionCall();
                }
                else if (type == "MinusTerm")
                {
                    term = new MinusTerm();
                }
                else if (type == "Formula")
                {
                    term = new Formula();
                }
                else if (type == "Empty")
                {
                    return(null);
                }
                else
                {
                    throw new QueryInvalidOperationException("Invalid conditional type");
                }
            }
            ((ICompactSerializable)term).Deserialize(reader);
            return(term);
        }
Пример #14
0
        /// <summary>
        /// Recupera o termo condicional contido no reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal protected static ConditionalTerm GetConditionalTerm(System.Xml.XmlReader reader)
        {
            var type = reader.GetAttribute("type", Namespaces.SchemaInstance);

            if (string.IsNullOrEmpty(type))
            {
                type = reader.LocalName;
            }
            ConditionalTerm term = null;

            if (string.IsNullOrEmpty(type))
            {
                term = new Constant();
            }
            else
            {
                var index1 = type.IndexOf(":");
                if (index1 >= 0)
                {
                    type = type.Substring(index1 + 1);
                }
                var startPoint = type.IndexOf('.');
                if (startPoint >= 0)
                {
                    type = type.Substring(startPoint + 1);
                }
                if (type == "Conditional")
                {
                    term = new Conditional();
                }
                else if (type == "ConditionalContainer")
                {
                    term = new ConditionalContainer();
                }
                else if (type == "Operator")
                {
                    term = new Operator();
                }
                else if (type == "Constant")
                {
                    term = new Constant();
                }
                else if (type == "Column")
                {
                    term = new Column();
                }
                else if (type == "Variable")
                {
                    term = new Variable();
                }
                else if (type == "ValuesArray")
                {
                    term = new ValuesArray();
                }
                else if (type == "QueryTerm")
                {
                    term = new QueryTerm();
                }
                else if (type == "FunctionCall")
                {
                    term = new FunctionCall();
                }
                else if (type == "MinusTerm")
                {
                    term = new MinusTerm();
                }
                else if (type == "Formula")
                {
                    term = new Formula();
                }
                else if (type == "Empty")
                {
                    return(null);
                }
                else if (type == "Case")
                {
                    term = new CaseConditional();
                }
                else
                {
                    throw new QueryInvalidOperationException("Invalid conditional type");
                }
            }
            ((System.Xml.Serialization.IXmlSerializable)term).ReadXml(reader);
            return(term);
        }