public virtual void WriteCreatePrimaryKey(IPrimaryId constraint, IEnvironmentHelper environment) { WriteLine("ALTER TABLE {0}", constraint.Entity.Persistence.FullName); Indent++; WriteLine("ADD CONSTRAINT {0} PRIMARY KEY ({1})", constraint.Persistence.Name, constraint.Attributes.ToPersistentNamesString(",")); }
public ILayerMethod GetProxyById(IPrimaryId primaryId, IEnvironmentHelper environment) { return(new LayerMethod(String.Format("Get{0}ById", primaryId.Entity.Name), environment.ToParams(primaryId.Attributes))); }
private void ProcessPrimaryId(IPrimaryId primaryId, XmlNode classNode) { XmlNode propNode = null; if (primaryId.Composite) { propNode = map.CreateElement("composite-id"); foreach (IAttribute pidAttribute in primaryId.Attributes) { IRelation manyToOne = pidAttribute.GetManyToOne(); if (manyToOne != null) { map.CreateElement("key-many-to-one"); map.AddAttribute("name", manyToOne.ChildName); map.AddAttribute("class", environment.ToTypeName(manyToOne.ParentEntity, true)); map.AddAttribute("column", pidAttribute.Persistence.Name); propNode.AppendChild(map.CurrentNode); DeclareManyToOneProperty(manyToOne, null); manyToOne.Processed = true; } else { map.CreateElement("key-property"); map.AddAttribute("name", pidAttribute.Name); map.AddAttribute("type", environment.ToTypeName(pidAttribute, true)); map.AddAttribute("column", pidAttribute.Persistence.Name); propNode.AppendChild(map.CurrentNode); DeclareProperty(pidAttribute, null); } pidAttribute.Processed = true; } cw.BeginRegion("Composite id override methods"); cw.BeginFunction("public override bool Equals(object o)"); cw.WriteLine("return o != null && (o as {0}) != null && {1};", environment.ToTypeName(primaryId.Entity, false), cw.ToSeparatedString(primaryId.Attributes.ToList(), " && ", delegate(object item, int count) { string name = (item as IAttribute).Name; IRelation manyToOne = (item as IAttribute).GetManyToOne(); if (manyToOne != null) { IAttribute related = (item as IAttribute).GetManyToOneRelatedAttribute(); name = String.Format("{0}.{1}", manyToOne.ChildName, related.Name); } return(String.Format("this.{0} == (o as {1}).{0}", name, environment.ToTypeName(primaryId.Entity, false))); }) ); cw.EndFunction(); cw.WriteLine(); cw.BeginFunction("public override int GetHashCode()"); cw.WriteLine("return ({0}).GetHashCode();", cw.ToSeparatedString(primaryId.Attributes.ToList(), " + \"|\" + ", delegate(object item, int count) { string name = (item as IAttribute).Name; IRelation manyToOne = (item as IAttribute).GetManyToOne(); if (manyToOne != null) { IAttribute related = (item as IAttribute).GetManyToOneRelatedAttribute(); name = String.Format("{0}.{1}", manyToOne.ChildName, related.Name); } return(String.Format("this.{0}.ToString()", name)); }) ); cw.EndFunction(); cw.EndRegion(); cw.WriteLine(); } else { if (primaryId.Entity.HasSupertype) { if (DomainLayerConfig.MappingStrategy == GenieLamp.Core.Layers.MappingStrategy.TablePerSubclass) { propNode = map.CreateElement("key"); } else { propNode = null; } } else { propNode = map.CreateElement("id"); map.AddAttribute("name", primaryId.Attributes[0].Name); map.AddAttribute("access", "property"); if (primaryId.HasGenerator) { XmlNode generatorNode = map.CreateElement("generator"); propNode.AppendChild(generatorNode); switch (primaryId.Generator.Type) { case GeneratorType.Sequence: map.AddAttribute("class", "native"); // "native" supports both sequeces and identity XmlNode genParam = map.CreateElement("param"); generatorNode.AppendChild(genParam); map.AddAttribute("name", "sequence"); genParam.InnerText = primaryId.Generator.Persistence.FullName; break; case GeneratorType.Guid: map.AddAttribute("class", "guid"); break; case GeneratorType.GuidHex: map.AddAttribute("class", "uuid.hex"); break; } } } if (propNode != null) { map.CurrentNode = propNode; map.AddAttribute("column", primaryId.Attributes[0].Persistence.Name); } } foreach (IAttribute attribute in primaryId.Attributes) { if (!primaryId.Entity.HasSupertype && !attribute.Processed) { DeclareProperty(attribute, null); } attribute.Processed = true; } if (propNode != null) { map.CurrentNode = classNode; map.AddFirstChild(propNode); } }
public ILayerMethod GetById(IPrimaryId primaryId, IEnvironmentHelper environment) { return(new LayerMethod("GetById", environment.ToParams(primaryId.Attributes))); }
public void WriteDropPrimaryKey(IPrimaryId constraint, IEnvironmentHelper environment) { WriteLine("ALTER TABLE {0} DROP PRIMARY KEY {1}", constraint.Entity.Persistence.FullName, constraint.Persistence.Name); }