Exemplo n.º 1
0
            public Writer(Schema Schema, String NamespaceName, Boolean WithFirefly = true)
            {
                this.Schema        = Schema;
                this.NamespaceName = NamespaceName;
                InnerSchema        = PlainObjectSchemaGenerator.Generate(Schema, NamespaceName);
                TypeDict           = OS.ObjectSchemaExtensions.GetMap(InnerSchema).ToDictionary(p => p.Key.Split('.').Last(), p => p.Value, StringComparer.OrdinalIgnoreCase);
                InnerWriter        = new OS.CSharp.Templates(InnerSchema);

                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Int").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Int");
                }
            }
Exemplo n.º 2
0
            public Writer(Schema Schema, String EntityNamespaceName, String NamespaceName)
            {
                this.Schema = Schema;
                this.EntityNamespaceName = EntityNamespaceName;
                this.NamespaceName       = NamespaceName;
                InnerSchema   = PlainObjectSchemaGenerator.Generate(Schema, EntityNamespaceName);
                TypeDict      = Schema.GetMap().ToDictionary(p => p.Key, p => p.Value, StringComparer.OrdinalIgnoreCase);
                InnerTypeDict = Niveum.ObjectSchema.ObjectSchemaExtensions.GetMap(InnerSchema).ToDictionary(p => p.Key.Split('.').Last(), p => p.Value, StringComparer.OrdinalIgnoreCase);

                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Unit").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Unit");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Boolean").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Boolean");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "String").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: String");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Int").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Int");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Int64").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Int64");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Real").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Real");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Byte").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Byte");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Optional").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Optional");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "List").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: List");
                }

                InnerWriter = new CSharpPlain.CodeGenerator.Writer(Schema, EntityNamespaceName);
            }
Exemplo n.º 3
0
            public Writer(Schema Schema, String EntityNamespaceName, String NamespaceName)
            {
                this.Schema = Schema;
                this.EntityNamespaceName = EntityNamespaceName;
                this.NamespaceName       = NamespaceName;
                InnerSchema = PlainObjectSchemaGenerator.Generate(Schema, EntityNamespaceName);
                TypeDict    = Schema.GetMap().ToDictionary(p => p.Key, p => p.Value, StringComparer.OrdinalIgnoreCase);

                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Unit").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Unit");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Boolean").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Boolean");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "String").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: String");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Int").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Int");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Int64").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Int64");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Real").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Real");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Byte").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Byte");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Optional").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Optional");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "List").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: List");
                }

                InnerWriter = new CppPlain.CodeGenerator.Writer(Schema, EntityNamespaceName);
                var Types = new List <OS.TypeDef>();

                Types.AddRange(InnerSchema.Types);
                var EntityNamespaceParts = EntityNamespaceName.Split('.').ToList();
                var TableFields          = Schema.Types.Where(t => t.OnEntity).Select(t => t.Entity).Select
                                           (
                    e => new OS.VariableDef
                {
                    Name = e.Name,
                    Type = OS.TypeSpec.CreateGenericTypeSpec
                           (
                        new OS.GenericTypeSpec
                    {
                        TypeSpec = OS.TypeSpec.CreateTypeRef(new OS.TypeRef {
                            Name = new List <String> {
                                "List"
                            }, Version = ""
                        }),
                        ParameterValues = new List <OS.TypeSpec>
                        {
                            OS.TypeSpec.CreateTypeRef(new OS.TypeRef {
                                Name = EntityNamespaceParts.Concat(new List <String> {
                                    e.Name
                                }).ToList(), Version = ""
                            })
                        }
                    }
                           )
                }
                                           ).ToList();

                Types.Add(OS.TypeDef.CreateRecord(new OS.RecordDef {
                    Name = EntityNamespaceParts.Concat(new List <String> {
                        "MemoryDataTables"
                    }).ToList(), Version = "", GenericParameters = new List <OS.VariableDef> {
                    }, Attributes = new List <KeyValuePair <String, List <String> > > {
                    }, Fields = TableFields, Description = ""
                }));
                InnerSchema = new OS.Schema {
                    Types = Types, TypeRefs = InnerSchema.TypeRefs, Imports = InnerSchema.Imports
                };
                InnerTypeDict     = Niveum.ObjectSchema.ObjectSchemaExtensions.GetMap(InnerSchema).ToDictionary(p => p.Key.Split('.').Last(), p => p.Value, StringComparer.OrdinalIgnoreCase);
                InnerBinaryWriter = new OS.CppBinary.Templates(InnerSchema, false, false);
            }
Exemplo n.º 4
0
            public Writer(Schema Schema, String EntityNamespaceName, String NamespaceName)
            {
                this.Schema = Schema;
                this.EntityNamespaceName = EntityNamespaceName;
                this.NamespaceName       = NamespaceName;
                InnerSchema   = PlainObjectSchemaGenerator.Generate(Schema, EntityNamespaceName);
                TypeDict      = Schema.GetMap().ToDictionary(p => p.Key, p => p.Value, StringComparer.OrdinalIgnoreCase);
                InnerTypeDict = Niveum.ObjectSchema.ObjectSchemaExtensions.GetMap(InnerSchema).ToDictionary(p => p.Key.Split('.').Last(), p => p.Value, StringComparer.OrdinalIgnoreCase);

                KeysDict = new Dictionary <String, Key[]>(StringComparer.OrdinalIgnoreCase);
                foreach (var e in Schema.Types.Where(t => t.OnEntity).Select(t => t.Entity))
                {
                    var Keys = (new Key[] { e.PrimaryKey }).Concat(e.UniqueKeys).Concat(e.NonUniqueKeys.Select(k => ConvertNonUniqueKeyToUniqueKey(k, e.PrimaryKey))).Select(k => new Key {
                        Columns = k.Columns, IsClustered = false
                    }).Distinct(new KeyComparer()).ToArray();
                    KeysDict.Add(e.Name, Keys);
                }

                var Queries = Schema.Types.Where(t => t.OnQueryList).SelectMany(t => t.QueryList.Queries).ToList();

                QueryToSearchKey = new Dictionary <QueryDef, Key>();
                foreach (var q in Queries)
                {
                    var e = TypeDict[q.EntityName].Entity;

                    var By = q.By;
                    if (q.Verb.OnInsert || q.Verb.OnUpdate || q.Verb.OnUpsert)
                    {
                        By = e.PrimaryKey.Columns.Select(c => c.Name).ToList();
                    }
                    var ByColumns     = new HashSet <String>(By, StringComparer.OrdinalIgnoreCase);
                    var ActualOrderBy = q.OrderBy.Where(c => !ByColumns.Contains(c.Name)).ToList();
                    Key SearchKey     = null;
                    foreach (var k in KeysDict[e.Name])
                    {
                        if (k.Columns.Count < By.Count + ActualOrderBy.Count)
                        {
                            continue;
                        }
                        if (!k.Columns.Take(By.Count).Zip(By, (Left, Right) => Left.Name.Equals(Right, StringComparison.OrdinalIgnoreCase)).Any(f => !f))
                        {
                            if (!k.Columns.Skip(By.Count).Take(ActualOrderBy.Count).Zip(ActualOrderBy, (Left, Right) => Left.Name.Equals(Right.Name) && (Left.IsDescending == Right.IsDescending)).Any(f => !f))
                            {
                                SearchKey = k;
                                break;
                            }
                        }
                    }
                    if (SearchKey == null)
                    {
                        throw new InvalidOperationException();
                    }
                    QueryToSearchKey.Add(q, SearchKey);
                }

                KeyCanBePartitioned = new Dictionary <Key, Boolean>();
                var EntityNameToQueries = Queries.GroupBy(q => q.EntityName).ToDictionary(g => g.Key, g => g.ToList());

                foreach (var e in Schema.Types.Where(t => t.OnEntity).Select(t => t.Entity))
                {
                    var or         = InnerTypeDict[e.Name].Record;
                    var d          = or.Fields.ToDictionary(f => f.Name, StringComparer.OrdinalIgnoreCase);
                    var Keys       = KeysDict[e.Name];
                    var KeyQueries = (EntityNameToQueries.ContainsKey(e.Name) ? EntityNameToQueries[e.Name] : new List <QueryDef>()).GroupBy(q => QueryToSearchKey[q]).ToDictionary(g => g.Key, g => g.ToList());
                    foreach (var k in Keys)
                    {
                        var CanBePartitioned = true;
                        if (KeyQueries.ContainsKey(k))
                        {
                            foreach (var q in KeyQueries[k])
                            {
                                if (q.Verb.OnSelect || q.Verb.OnLock || q.Verb.OnDelete)
                                {
                                    if ((q.By.Count == 0) && (q.OrderBy.Count != 0))
                                    {
                                        CanBePartitioned = false;
                                        break;
                                    }
                                }
                            }
                        }
                        var FirstColumnType = d[k.Columns.First().Name].Type;
                        if (!FirstColumnType.OnTypeRef || !FirstColumnType.TypeRef.Name.Equals("Int"))
                        {
                            CanBePartitioned = false;
                        }
                        KeyCanBePartitioned.Add(k, CanBePartitioned);
                    }
                }

                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Unit").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Unit");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Boolean").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Boolean");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "String").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: String");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Int").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Int");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Int64").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Int64");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Real").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Real");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Byte").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Byte");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "Optional").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: Optional");
                }
                if (!Schema.TypeRefs.Concat(Schema.Types).Where(t => t.OnPrimitive && t.Primitive.Name == "List").Any())
                {
                    throw new InvalidOperationException("PrimitiveMissing: List");
                }

                InnerWriter = new CSharpPlain.CodeGenerator.Writer(Schema, EntityNamespaceName);
            }