예제 #1
0
        internal void Resolve(SchemaInfo schemaInfo)
        {
            if (parentSchema != null)
            {
                // already resolved, probably as part of included schema Resolve() process
                return;
            }

            parentSchema = schemaInfo;

            Table.Resolve(this.Name, true);
            Table.Rehash();

            Table.Fields[0].ReferencedClass = schemaInfo.FindClassByName(Table.Fields[0].References);
            if (Table.Fields[0].ReferencedClass == null)
            {
                throw new SoodaSchemaException("Class " + Table.Fields[0].References + " not found in " + this.Name + "." + Table.Fields[0].Name);
            }
            Table.Fields[1].ReferencedClass = schemaInfo.FindClassByName(Table.Fields[1].References);
            if (Table.Fields[1].ReferencedClass == null)
            {
                throw new SoodaSchemaException("Class " + Table.Fields[1].References + " not found in " + this.Name + "." + Table.Fields[1].Name);
            }
            foreach (FieldInfo fi in Table.Fields)
            {
                fi.ParentRelation = this;
            }
        }
예제 #2
0
        internal void ResolveCollections(SchemaInfo schema)
        {
            if (CollectionsNtoN != null)
            {
                foreach (CollectionManyToManyInfo cinfo in CollectionsNtoN)
                {
                    cinfo.Resolve(schema);
                }
            }

            if (Collections1toN != null)
            {
                foreach (CollectionOnetoManyInfo cinfo in Collections1toN)
                {
                    ClassInfo ci = schema.FindClassByName(cinfo.ClassName);
                    if (ci == null)
                    {
                        throw new SoodaSchemaException("Collection " + Name + "." + cinfo.Name + " cannot find class " + cinfo.ClassName);
                    }

                    FieldInfo fi = ci.FindFieldByName(cinfo.ForeignFieldName);

                    if (fi == null)
                    {
                        throw new SoodaSchemaException("Collection " + Name + "." + cinfo.Name + " cannot find field " + cinfo.ClassName + "." + cinfo.ForeignFieldName);
                    }

                    schema.AddBackRefCollection(fi, cinfo.Name);
                    cinfo.ForeignField2 = fi;
                    cinfo.Class         = ci;
                }
            }
        }
예제 #3
0
 internal void ResolveInheritance(SchemaInfo schema)
 {
     if (InheritFrom != null)
     {
         InheritsFromClass = schema.FindClassByName(InheritFrom);
     }
     else
     {
         InheritsFromClass = null;
     }
 }
예제 #4
0
        internal void ResolveReferences(SchemaInfo schema)
        {
            if (References == null)
            {
                return;
            }
            ClassInfo ci = schema.FindClassByName(References);

            if (ci == null)
            {
                throw new SoodaSchemaException("Class " + References + " not found.");
            }
            DataType        = ci.GetFirstPrimaryKeyField().DataType;
            ReferencedClass = ci;
        }
        static void Load(SoodaTransaction transaction)
        {
            SchemaInfo          schema          = transaction.Schema;
            HashSet <ClassInfo> affectedClasses = new HashSet <ClassInfo>();

            foreach (DataSourceInfo dsi in schema.DataSources)
            {
                if (!dsi.EnableDynamicFields)
                {
                    continue;
                }
                SoodaDataSource ds = transaction.OpenDataSource(dsi);
                using (IDataReader r = ds.ExecuteRawQuery("select class, field, type, nullable, fieldsize, precision from SoodaDynamicField"))
                {
                    while (r.Read())
                    {
                        string    className = r.GetString(0);
                        ClassInfo ci        = schema.FindClassByName(className);
                        if (ci == null)
                        {
                            logger.Warn("Ignoring a dynamic field of non-existent class {0} -- see the SoodaDynamicField table", className);
                            continue;
                        }

                        FieldInfo fi = new FieldInfo();
                        fi.ParentClass = ci;
                        fi.Name        = r.GetString(1);
                        fi.TypeName    = r.GetString(2);
                        fi.IsNullable  = r.GetInt32(3) != 0;
                        if (!r.IsDBNull(4))
                        {
                            fi.Size = r.GetInt32(4);
                        }
                        if (!r.IsDBNull(5))
                        {
                            fi.Precision = r.GetInt32(5);
                        }

                        ci.LocalTables.Add(Prepare(fi));
                        affectedClasses.Add(ci);
                    }
                }
            }

            Resolve(schema, affectedClasses);
        }
예제 #6
0
        internal void ResolveCollections(SchemaInfo schema)
        {
            if (CollectionsNtoN != null)
            {
                foreach (CollectionManyToManyInfo cinfo in CollectionsNtoN)
                {
                    cinfo.Resolve(schema);
                }
            }

            if (Collections1toN != null)
            {
                foreach (CollectionOnetoManyInfo cinfo in Collections1toN)
                {
                    ClassInfo ci = schema.FindClassByName(cinfo.ClassName);
                    if (ci == null)
                        throw new SoodaSchemaException("Collection " + Name + "." + cinfo.Name + " cannot find class " + cinfo.ClassName);

                    FieldInfo fi = ci.FindFieldByName(cinfo.ForeignFieldName);

                    if (fi == null)
                        throw new SoodaSchemaException("Collection " + Name + "." + cinfo.Name + " cannot find field " + cinfo.ClassName + "." + cinfo.ForeignFieldName);

                    schema.AddBackRefCollection(fi, cinfo.Name);
                    cinfo.ForeignField2 = fi;
                    cinfo.Class = ci;
                }
            }
        }
예제 #7
0
 internal void ResolveInheritance(SchemaInfo schema)
 {
     if (InheritFrom != null)
     {
         InheritsFromClass = schema.FindClassByName(InheritFrom);
     }
     else
     {
         InheritsFromClass = null;
     }
 }
예제 #8
0
 internal void ResolveReferences(SchemaInfo schema)
 {
     if (References == null)
         return;
     ClassInfo ci = schema.FindClassByName(References);
     if (ci == null)
         throw new SoodaSchemaException("Class " + References + " not found.");
     DataType = ci.GetFirstPrimaryKeyField().DataType;
     ReferencedClass = ci;
 }
예제 #9
0
        internal void Resolve(SchemaInfo schemaInfo)
        {
            if (parentSchema != null)
            {
                // already resolved, probably as part of included schema Resolve() process
                return;
            }

            parentSchema = schemaInfo;

            Table.Resolve(this.Name, true);
            Table.Rehash();

            Table.Fields[0].ReferencedClass = schemaInfo.FindClassByName(Table.Fields[0].References);
            if (Table.Fields[0].ReferencedClass == null)
                throw new SoodaSchemaException("Class " + Table.Fields[0].References + " not found in " + this.Name + "." + Table.Fields[0].Name);
            Table.Fields[1].ReferencedClass = schemaInfo.FindClassByName(Table.Fields[1].References);
            if (Table.Fields[1].ReferencedClass == null)
                throw new SoodaSchemaException("Class " + Table.Fields[1].References + " not found in " + this.Name + "." + Table.Fields[1].Name);
            foreach (FieldInfo fi in Table.Fields)
                fi.ParentRelation = this;
        }