Ejemplo n.º 1
0
        public IEnumerable <MemberGeneratorInfo> Create()
        {
            var generatorInfos    = CreateMembersCore(GetNonCompoundPKColumns());
            var coumboundPkColumn = GetCoumboundPKColumn();

            if (coumboundPkColumn != null)
            {
                string tableName           = ClassGenerator.GetTableName(_dbTable.Name);
                var    persistentClassInfo = _classInfos[tableName + ClassGenerator.KeyStruct].PersistentClassInfo;
                if (persistentClassInfo == null)
                {
                    throw new ArgumentNullException("persistentClassInfo with name " + _dbTable.Name + ClassGenerator.KeyStruct);
                }
                var pkDbColumns = coumboundPkColumn.Columns.OfType <string>().Select(s => _dbTable.GetColumn(s)).ToArray();
                var membersCore = CreateMembersCore(pkDbColumns, persistentClassInfo, TemplateType.ReadWriteMember, TemplateType.ReadWriteMember).ToList();
                var persistentReferenceMemberInfo = CreatePersistentReferenceMemberInfo(persistentClassInfo.Name, _classInfos[tableName].PersistentClassInfo, persistentClassInfo, TemplateType.FieldMember);
                membersCore.Add(new MemberGeneratorInfo(persistentReferenceMemberInfo, _dbTable.GetColumn(coumboundPkColumn.Columns[0])));
                if (pkDbColumns.Where(IsOneToOneOnTheKey).Count() == pkDbColumns.Length)
                {
                    string             refTableName       = ClassGenerator.GetTableName(_dbTable.ForeignKeys.First(key => key.Columns.Contains(pkDbColumns.ToList()[0].Name)).PrimaryKeyTable);
                    ClassGeneratorInfo classGeneratorInfo = _classInfos[refTableName];
                    membersCore.Add(new MemberGeneratorInfo(CreatePersistentReferenceMemberInfo(classGeneratorInfo.PersistentClassInfo.Name, _classInfos[tableName].PersistentClassInfo, classGeneratorInfo.PersistentClassInfo, TemplateType.XPOneToOneReadOnlyPropertyMember), null));
                }
                return(generatorInfos.Union(membersCore));
            }
            return(generatorInfos);
        }
Ejemplo n.º 2
0
        IPersistentCoreTypeMemberInfo CreatePersistentCoreTypeMemberInfo(DBColumn column, IPersistentClassInfo persistentClassInfo, TemplateType templateType)
        {
            var persistentCoreTypeMemberInfo = _objectSpace.Create <IPersistentCoreTypeMemberInfo>();

            persistentCoreTypeMemberInfo.Name     = column.Name;
            persistentCoreTypeMemberInfo.DataType = column.ColumnType;
            if (persistentClassInfo == null)
            {
                var tableName = ClassGenerator.GetTableName(_dbTable.Name);
                persistentClassInfo = _classInfos[tableName].PersistentClassInfo;
            }
            persistentClassInfo.OwnMembers.Add(persistentCoreTypeMemberInfo);
            persistentCoreTypeMemberInfo.SetDefaultTemplate(templateType);
            return(persistentCoreTypeMemberInfo);
        }
Ejemplo n.º 3
0
        MemberGeneratorInfo CreateFkMember(DBColumn dbColumn, IPersistentClassInfo persistentClassInfo,
                                           TemplateType coreTemplateType, TemplateType refTemplateType)
        {
            var foreignKey = _dbTable.ForeignKeys.Where(key => key.Columns.Contains(dbColumn.Name)).First(key => !Equals(key.PrimaryKeyTable, "XPObjectType"));

            var tableName = ClassGenerator.GetTableName(foreignKey.PrimaryKeyTable);

            if (_classInfos.ContainsKey(tableName))
            {
                var classGeneratorInfo = _classInfos[tableName];
                return(new MemberGeneratorInfo(CreatePersistentReferenceMemberInfo(dbColumn.Name, persistentClassInfo,
                                                                                   classGeneratorInfo.PersistentClassInfo, GetTemplateType(refTemplateType, classGeneratorInfo)), dbColumn));
            }
            return(new MemberGeneratorInfo(CreatePersistentCoreTypeMemberInfo(dbColumn, persistentClassInfo, coreTemplateType), dbColumn));
        }
Ejemplo n.º 4
0
        void CreateCollection(IPersistentReferenceMemberInfo persistentReferenceMemberInfo, IPersistentClassInfo owner)
        {
            var persistentCollectionMemberInfo = _objectSpace.Create <IPersistentCollectionMemberInfo>();

            persistentReferenceMemberInfo.ReferenceClassInfo.OwnMembers.Add(persistentCollectionMemberInfo);
            persistentCollectionMemberInfo.Name  = persistentReferenceMemberInfo.Owner.Name + persistentReferenceMemberInfo.Name + "s";
            persistentCollectionMemberInfo.Owner = persistentReferenceMemberInfo.ReferenceClassInfo;
            var tableName = ClassGenerator.GetTableName(Regex.Replace(owner.Name, ClassGenerator.KeyStruct, "", RegexOptions.Singleline | RegexOptions.IgnoreCase));

            persistentCollectionMemberInfo.CollectionClassInfo = owner.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.Struct ? _classInfos[tableName].PersistentClassInfo : owner;
            persistentCollectionMemberInfo.SetDefaultTemplate(TemplateType.XPCollectionMember);
            var persistentAssociationAttribute = _objectSpace.Create <IPersistentAssociationAttribute>();

            persistentCollectionMemberInfo.TypeAttributes.Add(persistentAssociationAttribute);
            persistentAssociationAttribute.AssociationName = $"{persistentReferenceMemberInfo.Name}-{persistentCollectionMemberInfo.Name}s";
        }
Ejemplo n.º 5
0
        IPersistentMemberInfo CreatePersistentReferenceMemberInfo(string name, IPersistentClassInfo persistentClassInfo, IPersistentClassInfo persistentReferenceClassInfo, TemplateType templateType)
        {
            var persistentReferenceMemberInfo = _objectSpace.Create <IPersistentReferenceMemberInfo>();

            persistentReferenceMemberInfo.Name = name;
            persistentReferenceMemberInfo.ReferenceClassInfo = persistentReferenceClassInfo;
            if (persistentClassInfo == null)
            {
                persistentClassInfo = _classInfos[ClassGenerator.GetTableName(_dbTable.Name)].PersistentClassInfo;
            }
            persistentClassInfo.OwnMembers.Add(persistentReferenceMemberInfo);
            persistentReferenceMemberInfo.SetDefaultTemplate(templateType);
            if (templateType != TemplateType.XPOneToOnePropertyMember && templateType != TemplateType.XPOneToOneReadOnlyPropertyMember && persistentClassInfo.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.Class && persistentReferenceClassInfo.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.Class)
            {
                CreateCollection(persistentReferenceMemberInfo, persistentClassInfo);
            }
            return(persistentReferenceMemberInfo);
        }
Ejemplo n.º 6
0
        public void Create()
        {
            Dictionary <string, ClassGeneratorInfo> generatorInfos = new ClassGenerator(_persistentAssemblyInfo, _storageTables).CreateAll().ToDictionary(classGeneratorInfo => classGeneratorInfo.PersistentClassInfo.Name);

            foreach (var classGeneratorInfo in generatorInfos.Where(pair => pair.Value.PersistentClassInfo.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.Class))
            {
                var generatorInfo = classGeneratorInfo.Value;
                new ClassAtrributeGenerator(generatorInfo, _navigationPath).Create().Each(info => generatorInfo.PersistentClassInfo.TypeAttributes.Add(info));
                var memberGeneratorInfos = new MemberGenerator(classGeneratorInfo.Value.DbTable, generatorInfos).Create();
                memberGeneratorInfos.Each(info => new MemberAttributeGenerator(info, generatorInfo).Create());
            }
            var oneToOneMemberInfos = _persistentAssemblyInfo.PersistentClassInfos.SelectMany(info => info.OwnMembers.OfType <IPersistentReferenceMemberInfo>()).Where(info => info.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.XPOneToOnePropertyMember);

            foreach (var oneToOneMemberInfo in oneToOneMemberInfos)
            {
                var codeTemplate = _objectSpace.Create <ICodeTemplate>();
                codeTemplate.TemplateCode = oneToOneMemberInfo.ReferenceClassInfo.OwnMembers.OfType <IPersistentReferenceMemberInfo>().Single(info => info.CodeTemplateInfo.CodeTemplate.TemplateType == TemplateType.XPOneToOnePropertyMember).Name;
                oneToOneMemberInfo.TemplateInfos.Add(codeTemplate);
            }
            _persistentAssemblyInfo.SupportCompositeKeyPersistentObjects();
            CreateAssemblyAttributes();
        }
Ejemplo n.º 7
0
        bool IsOneToOneOnTheKey(DBColumn dbColumn)
        {
            IEnumerable <DBForeignKey> foreignPKeys = _dbTable.ForeignKeys.Where(key => _dbTable.PrimaryKey.Columns.Contains(dbColumn.Name) && key.PrimaryKeyTable != _dbTable.Name && key.Columns.Contains(dbColumn.Name));
            var keies = foreignPKeys.Select(key => new { FK = key, PrimaryTable = _classInfos[ClassGenerator.GetTableName(key.PrimaryKeyTable)].DbTable });

            return(keies.Any(arg => arg.PrimaryTable.PrimaryKey.Columns.OfType <string>().All(s => arg.FK.PrimaryKeyTableKeyColumns.OfType <string>().Contains(s))));
        }