public override void Implement() { Model.Logger.TraceLine("Implementig state version pattern..."); foreach (Entity entity in Model.Entities) { if (!AppliedTo(entity)) { continue; } Metamodel.Attribute a = entity.Attributes.GetByName(AtributeName, false); if (a != null && !a.Type.Equals(AttributeType)) { throw new GlException("Entity \"{0}\" has attribute \"{1}\" but its type \"{2}\" is not the same that defined in pattern configuration", entity.FullName, a.Name, a.Type.FullName); } if (a == null) { a = new Metamodel.Attribute(entity, AtributeName, AttributeType); a.TypeDefinition.Required = true; entity.Attributes.Add(a); } } }
public TypesEntity(RegistryPattern owner) { this.Entity = owner.CreateEntity(owner.TypesEntityName, owner.TypesEntityPidType); ScalarType fullNameType = (ScalarType)owner.Model.Types.GetByName("string"); fullNameType.TypeDefinition.Length = 255; fullNameType.TypeDefinition.Required = true; this.FullNameAttribute = this.Entity.AddAttribute("FullName", fullNameType); ScalarType shortNameType = (ScalarType)owner.Model.Types.GetByName("string"); shortNameType.TypeDefinition.Length = 64; fullNameType.TypeDefinition.Required = true; this.ShortNameAttribute = this.Entity.AddAttribute("ShortName", fullNameType); ScalarType descriptionType = (ScalarType)owner.Model.Types.GetByName("string"); descriptionType.TypeDefinition.Length = 1000; descriptionType.TypeDefinition.Required = false; this.DescriptionAttribute = this.Entity.AddAttribute("Description", fullNameType); UniqueId uid = new UniqueId(this.Entity, this.FullNameAttribute.Name); uid.Attributes.Add(this.FullNameAttribute); this.Entity.Constraints.UniqueIds.Add(uid); owner.Model.Entities.Add(this.Entity); }
internal Entity CreateEntity(string name, ScalarType primaryIdType) { Entity entity = new Entity(Model, Schema, name); if (PersistentSchemaDefined) { entity.Persistence.Schema = PersistentSchema; entity.Persistence.SchemaDefined = true; } Metamodel.Attribute a = entity.AddAttribute("Id", primaryIdType); a.TypeDefinition.Required = true; if (PrimaryIdType.IsIntegerValueType) { a.IsAutoincrement = true; } entity.Constraints.PrimaryId = new PrimaryId(entity, a); return(entity); }
public override void Implement() { foreach (Entity entity in Model.Entities) { if (this.AppliedTo(entity)) { string attrName = String.Format("{0}Id", this.RegistryEntity.Entity.Name); if (entity.Attributes.GetByName(attrName) != null) { throw new GlException( "Cannot apply registry pattern to entity '{0}'. Attribute '{1}' already exists. Rename it or exclude entity from pattern", entity.FullName, attrName); } Metamodel.Attribute registryAttr = entity.AddAttribute( attrName, this.RegistryEntity.Entity.PrimaryId.Attribute.Type as ScalarType); registryAttr.TypeDefinition.Required = false; UniqueId uid = new UniqueId(entity, registryAttr.Name); uid.Attributes.Add(registryAttr); entity.Constraints.UniqueIds.Add(uid); Relation r = new Relation(Model, entity.Schema, entity.Name, String.Empty, true, this.RegistryEntity.Entity.Schema, this.RegistryEntity.Entity.Name, String.Empty, false, true, Cardinality.R1_1, entity.Persistence); r.AttributesMatch.Add(new RelationAttributeMatch(r, registryAttr, this.RegistryEntity.Entity.PrimaryId.Attribute)); relations.Add(entity.FullName, r); Model.Relations.Add(r); } } }
public RegistryEntity(RegistryPattern owner) { if (owner.TypesEntity.Entity == null) { throw new GlException("TypesEntity.Entity is null"); } this.Entity = owner.CreateEntity(owner.RegistryEntityName, owner.PrimaryIdType); Metamodel.Attribute typesPid = owner.TypesEntity.Entity.PrimaryId.Attribute; this.EntityTypeAttribute = new Metamodel.Attribute( this.Entity, String.Format("EntityType{0}", typesPid.Name), typesPid.Type as ScalarType); this.EntityTypeAttribute.Migrate(typesPid); this.Entity.Attributes.Add(this.EntityTypeAttribute); owner.Model.Entities.Add(this.Entity); this.TypesRelation = new Relation( owner.Model, this.Entity.Schema, this.Entity.Name, String.Empty, true, owner.TypesEntity.Entity.Schema, owner.TypesEntity.Entity.Name, String.Empty, false, true, Cardinality.RM_1, this.Entity.Persistence); this.TypesRelation.AttributesMatch.Add( new RelationAttributeMatch(this.TypesRelation, this.EntityTypeAttribute, owner.TypesEntity.Entity.PrimaryId.Attribute)); owner.Model.Relations.Add(this.TypesRelation); }
public Metamodel.Attribute AddAttribute(string name, ScalarType type) { Metamodel.Attribute a = new Metamodel.Attribute(this, name, type); this.Attributes.Add(a); return(a); }