コード例 #1
0
        protected virtual void OnConstructed()
        {
            this.countParam     = this.CreateParameter("COUNT", DbType.Int32);
            this.matchRoleParam = this.CreateParameter("MR", DbType.Guid);

            this.typeDbType      = DbType.Guid;
            this.cacheDbType     = DbType.Int32;
            this.singletonDbType = DbType.Int32;
            this.versionDbType   = DbType.Guid;

            this.tablesByName = new Dictionary <string, SchemaTable>();

            this.tableByClass          = new Dictionary <IClass, SchemaTable>();
            this.tablesByRelationType  = new Dictionary <IRelationType, SchemaTable>();
            this.columnsByRelationType = new Dictionary <IRelationType, SchemaColumn>();

            this.objectId      = new SchemaColumn(this, "O", this.ObjectDbType, false, true, SchemaIndexType.None);
            this.cacheId       = new SchemaColumn(this, "C", this.CacheDbType, false, false, SchemaIndexType.None);
            this.associationId = new SchemaColumn(this, "A", this.ObjectDbType, false, true, SchemaIndexType.None);
            this.roleId        = new SchemaColumn(this, "R", this.ObjectDbType, false, true, SchemaIndexType.None);
            this.typeId        = new SchemaColumn(this, "T", this.TypeDbType, false, false, SchemaIndexType.None);

            // Objects
            this.objects         = new SchemaTable(this, SchemaTableKind.System, AllorsPrefix + "O");
            this.objectsObjectId = new SchemaColumn(this, this.ObjectId.Name, this.ObjectDbType, true, true, SchemaIndexType.None);
            this.objectsCacheId  = new SchemaColumn(this, "C", this.CacheDbType, false, false, SchemaIndexType.None);
            this.objectsTypeId   = new SchemaColumn(this, this.TypeId.Name, this.TypeDbType, false, false, SchemaIndexType.None);

            this.Objects.AddColumn(this.ObjectsObjectId);
            this.Objects.AddColumn(this.ObjectsTypeId);
            this.Objects.AddColumn(this.ObjectsCacheId);
            this.tablesByName.Add(this.Objects.Name, this.Objects);

            this.CreateTablesFromMeta();
        }
コード例 #2
0
        private void CreateTablesFromMeta()
        {
            foreach (var relationType in this.Database.MetaPopulation.RelationTypes)
            {
                var associationType = relationType.AssociationType;
                var roleType        = relationType.RoleType;

                if (roleType.ObjectType is IComposite &&
                    ((associationType.IsMany && roleType.IsMany) || !relationType.ExistExclusiveClasses))
                {
                    var column = new SchemaColumn(this, "R", this.ObjectDbType, false, true, relationType.IsIndexed ? SchemaIndexType.Combined : SchemaIndexType.None, relationType);
                    this.ColumnsByRelationType.Add(relationType, column);
                }
                else
                {
                    if (roleType.ObjectType is IUnit)
                    {
                        var column = new SchemaColumn(this, roleType.SingularPropertyName, this.GetDbType(roleType), false, false, relationType.IsIndexed ? SchemaIndexType.Single : SchemaIndexType.None, relationType, roleType.Size, roleType.Precision, roleType.Scale);
                        this.ColumnsByRelationType.Add(relationType, column);
                    }
                    else if (relationType.ExistExclusiveClasses)
                    {
                        if (roleType.IsOne)
                        {
                            var column = new SchemaColumn(this, roleType.SingularPropertyName, this.ObjectDbType, false, false, relationType.IsIndexed ? SchemaIndexType.Combined : SchemaIndexType.None, relationType);
                            this.ColumnsByRelationType.Add(relationType, column);
                        }
                        else
                        {
                            var column = new SchemaColumn(this, associationType.SingularFullName, this.ObjectDbType, false, false, relationType.IsIndexed ? SchemaIndexType.Combined : SchemaIndexType.None, relationType);
                            this.ColumnsByRelationType.Add(relationType, column);
                        }
                    }
                }
            }

            foreach (var objectType in this.Database.MetaPopulation.Composites)
            {
                var @class = objectType as IClass;
                if (@class != null)
                {
                    var schemaTable = new SchemaTable(this, SchemaTableKind.Object, objectType);
                    this.TablesByName.Add(schemaTable.Name, schemaTable);
                    this.TableByClass.Add(@class, schemaTable);

                    schemaTable.AddColumn(this.ObjectId);
                    schemaTable.AddColumn(this.TypeId);

                    var roleTypes        = new List <IRoleType>();
                    var associationTypes = new List <IAssociationType>();

                    foreach (var roleType in @class.RoleTypes)
                    {
                        if (!roleTypes.Contains(roleType))
                        {
                            roleTypes.Add(roleType);
                        }
                    }

                    foreach (var associationType in @class.AssociationTypes)
                    {
                        if (!associationTypes.Contains(associationType))
                        {
                            associationTypes.Add(associationType);
                        }
                    }

                    foreach (var associationType in associationTypes)
                    {
                        var relationType = associationType.RelationType;
                        var roleType     = relationType.RoleType;
                        if (!(associationType.IsMany && roleType.IsMany) && relationType.ExistExclusiveClasses && roleType.IsMany)
                        {
                            schemaTable.AddColumn(this.Column(relationType));
                        }
                    }

                    foreach (var roleType in roleTypes)
                    {
                        var relationType    = roleType.RelationType;
                        var associationType = relationType.AssociationType;
                        if (roleType.ObjectType is IUnit)
                        {
                            schemaTable.AddColumn(this.Column(relationType));
                        }
                        else
                        {
                            if (!(associationType.IsMany && roleType.IsMany) && relationType.ExistExclusiveClasses && !roleType.IsMany)
                            {
                                schemaTable.AddColumn(this.Column(relationType));
                            }
                        }
                    }
                }
            }

            foreach (var relationType in this.Database.MetaPopulation.RelationTypes)
            {
                var associationType = relationType.AssociationType;
                var roleType        = relationType.RoleType;

                if (roleType.ObjectType is IComposite && ((associationType.IsMany && roleType.IsMany) || !relationType.ExistExclusiveClasses))
                {
                    var schemaTable = new SchemaTable(this, SchemaTableKind.Relation, relationType);
                    this.TablesByName.Add(schemaTable.Name, schemaTable);
                    this.TablesByRelationType.Add(relationType, schemaTable);

                    schemaTable.AddColumn(this.AssociationId);
                    schemaTable.AddColumn(this.Column(relationType));
                }
            }
        }
コード例 #3
0
ファイル: Database.cs プロジェクト: lulzzz/allors2
 protected abstract void CreateIndex(ManagementSession session, SchemaTable table, SchemaColumn column);
コード例 #4
0
        public static void AddError(SchemaValidationErrors schemaValidationErrors, SchemaTable table, SchemaColumn column, SchemaValidationErrorKind kind)
        {
            var roleType = column.RelationType == null ? null : column.RelationType.RoleType;

            schemaValidationErrors.AddTableError(null, null, roleType, table.ToString(), column.ToString(), kind, kind + ": " + table + "." + column);
        }
コード例 #5
0
ファイル: Database.cs プロジェクト: lulzzz/allors2
 public abstract void DropIndex(ManagementSession session, SchemaTable table, SchemaColumn column);