コード例 #1
0
ファイル: CodeGenerator.cs プロジェクト: blockspacer/niveum
            public List <String> GetQuery(QueryDef q)
            {
                var e = TypeDict[q.EntityName].Entity;

                var           Signature  = InnerWriter.GetQuerySignature(q);
                var           QueryName  = q.FriendlyName();
                var           Parameters = InnerWriter.GetQueryParameterList(q);
                List <String> Content;

                if (q.Verb.OnSelect || q.Verb.OnLock)
                {
                    Content = GetTemplate("SelectLock").Substitute("QueryName", QueryName).Substitute("Parameters", Parameters);
                }
                else if (q.Verb.OnInsert || q.Verb.OnUpdate || q.Verb.OnUpsert || q.Verb.OnDelete)
                {
                    Content = GetTemplate("InsertUpdateUpsertDelete").Substitute("QueryName", QueryName).Substitute("Parameters", Parameters);
                }
                else
                {
                    throw new InvalidOperationException();
                }
                return(GetTemplate("Query").Substitute("Signature", Signature).Substitute("Content", Content));
            }
コード例 #2
0
ファイル: CodeGenerator.cs プロジェクト: blockspacer/niveum
            public String GetQuerySignature(QueryDef q)
            {
                var or   = TypeDict[q.EntityName].Record;
                var Name = q.FriendlyName();
                var pl   = new List <String>();

                if (q.Verb.OnInsert || q.Verb.OnUpdate)
                {
                    if (q.Numeral.OnOptional)
                    {
                        pl.Add("{0} {1}".Formats(GetEscapedIdentifier(q.EntityName), GetEscapedIdentifier("v")));
                    }
                    else if (q.Numeral.OnOne)
                    {
                        pl.Add("{0} {1}".Formats(GetEscapedIdentifier(q.EntityName), GetEscapedIdentifier("v")));
                    }
                    else if (q.Numeral.OnMany)
                    {
                        pl.Add("{0} {1}".Formats(GetEscapedIdentifier("List<{0}>".Formats(q.EntityName)), GetEscapedIdentifier("l")));
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                else if (q.Verb.OnUpsert)
                {
                    if (q.Numeral.OnOne)
                    {
                        pl.Add("{0} {1}".Formats(GetEscapedIdentifier(q.EntityName), GetEscapedIdentifier("v")));
                    }
                    else if (q.Numeral.OnMany)
                    {
                        pl.Add("{0} {1}".Formats(GetEscapedIdentifier("List<{0}>".Formats(q.EntityName)), GetEscapedIdentifier("l")));
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                pl.AddRange(q.By.Select(c => "{0} {1}".Formats(GetEscapedIdentifier(GetTypeString(or.Fields.Where(f => f.Name == c).Single().Type)), GetEscapedIdentifier(c))).ToArray());
                if (q.Numeral.OnRange)
                {
                    pl.Add("Int _Skip_");
                    pl.Add("Int _Take_");
                }
                var    ParameterList = String.Join(", ", pl.ToArray());
                String Type;

                if (q.Verb.OnSelect || q.Verb.OnLock)
                {
                    if (q.Numeral.OnOptional)
                    {
                        Type = GetEscapedIdentifier("Optional<{0}>".Formats(q.EntityName));
                    }
                    else if (q.Numeral.OnOne)
                    {
                        Type = GetEscapedIdentifier(q.EntityName);
                    }
                    else if (q.Numeral.OnMany)
                    {
                        Type = GetEscapedIdentifier("List<{0}>".Formats(q.EntityName));
                    }
                    else if (q.Numeral.OnAll)
                    {
                        Type = GetEscapedIdentifier("List<{0}>".Formats(q.EntityName));
                    }
                    else if (q.Numeral.OnRange)
                    {
                        Type = GetEscapedIdentifier("List<{0}>".Formats(q.EntityName));
                    }
                    else if (q.Numeral.OnCount)
                    {
                        Type = GetEscapedIdentifier("Int");
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                else
                {
                    Type = "void";
                }
                return(GetTemplate("QuerySignature").Substitute("Name", Name).Substitute("ParameterList", ParameterList).Substitute("Type", Type).Single());
            }