private void AssociationTableProcessing(IStereotypeInstance table, IClass cls) { foreach (IProperty p in cls.Members) { IEnumerable<IStereotypeInstance> columns = p.AppliedStereotypes.Where(s => s.Name == "Column"); foreach (IStereotypeInstance column in columns) { _py.AddProperty(p); _sql.AddProperty(p); } } List<string> unique = new List<string>(); foreach (IProperty ae in cls.GetOutgoingAssociationEnds()) { IAssociation association = ae.Association; IEnumerable<IProperty> comps = association.MemberEnds.Where(s => s.IsComposite && s.Name == ae.Name); foreach (IProperty pComp in comps) { _py.AddCompositeProperty(pComp); _sql.AddCompositeProperty(pComp); unique.Add(pComp.Name); } IEnumerable<IStereotypeInstance> fks = association.AppliedStereotypes.Where(s => s.Name == "ForeignKey"); foreach (IStereotypeInstance fk in fks) { if (IsNavigableAssoc(ae) && fk != null) { unique.Add(ae.Name + "Id"); _py.AddFKProperty(ae); _sql.AddFKProperty(ae); _sql.AddFKConstraint(association.Name, cls.Name, ae.Name, ae.Type.Name, TableKeys[ae.Type.Name], UmlHelper.GetDeleteAction(fk)); } } IEnumerable<IStereotypeInstance> ars = association.AppliedStereotypes.Where(s => s.Name == "AbstractReference"); foreach (IStereotypeInstance ar in ars) { if (IsNavigableAssoc(ae)) { _sql.AddAbstractReferenceProperty(ae); _sql.AddIndexConstraint(ae.Name + "AbstractRefIndex", ae.Name + "Id, " + ae.Name + "Table", ""); _py.AddAbstractReferenceProperty(ae); unique.Add(ae.Name + "Id, " + ae.Name + "Table"); } } IEnumerable<IStereotypeInstance> refs = association.AppliedStereotypes.Where(s => s.Name == "Reference"); foreach (IStereotypeInstance r in refs) { DealWithReflexiveReferences(ae, association); unique.Add(ae.Name + "Id"); } } _sql.AddUniqueConstraint(unique); }
private bool IsPrimaryKey(IStereotypeInstance column) { IStereotypePropertyInstance pk = column.PropertyInstances.Where(p => p.Name == "PrimaryKey").First(); return bool.Parse(pk.Value) == true ? true : false; ; }
private string GetNull(IStereotypeInstance column) { IStereotypePropertyInstance allowNulls = column.PropertyInstances.Where(p => p.Name == "AllowNulls").First(); return bool.Parse(allowNulls.Value) == true ? string.Empty : "not null"; }
private string GetLength(IStereotypeInstance column) { IStereotypePropertyInstance length = column.PropertyInstances.Where(p => p.Name == "Length").First(); return length.Value; }
private string GetDeleteAction(IStereotypeInstance assoc) { IStereotypePropertyInstance deleteRule = assoc.PropertyInstances.Where(p => p.Name == "DeleteRule").First(); return deleteRule.Value; }
private string GetDataType(IStereotypeInstance column) { IStereotypePropertyInstance dataType = column.PropertyInstances.Where(p => p.Name == "DataType").First(); return dataType.Value; }
private void WriteProperty(IProperty p, IStereotypeInstance column) { _fsSql.WriteLine(" {0} {1} {2} {3},", p.Name, BuildDataType(column), UmlHelper.GetNull(column), UmlHelper.GetDefaultValue(p)); }
private void WritePKProperty(IProperty p, IStereotypeInstance column) { if (_run == SQLGenerateRun.Postgres) { _fsSql.WriteLine(" {0} bigserial {1} {2},", p.Name, UmlHelper.GetNull(column), UmlHelper.GetDefaultValue(p)); } else { _fsSql.WriteLine(" {0} {1} {2} Auto_Increment {3},", p.Name, BuildDataType(column), UmlHelper.GetNull(column), UmlHelper.GetDefaultValue(p)); } }
private string BuildDataType(IStereotypeInstance column) { string s = UmlHelper.GetDataType(column); StringBuilder dt = new StringBuilder(s); if (s.Contains("()")) { dt.Insert(dt.Length - 1, UmlHelper.GetLength(column)); } return dt.ToString(); }
private string BuildDjangoDataType(IStereotypeInstance column) { string s = UmlHelper.GetDataType(column); string dt = String.Empty; if (s.Contains("()")) { // Special Processing for floats and decimals if (s == "float()" || s == "decimal()") { string[] maxAndPlaces = UmlHelper.GetLength(column).ToString().Split(','); dt = SqlPythonTypes[s] + String.Format("(max_digits={0}, decimal_places={1}, ", maxAndPlaces[0], maxAndPlaces[1]); } else { dt = SqlPythonTypes[s] + String.Format("(max_length={0}, ", UmlHelper.GetLength(column).ToString()); } } else { dt = SqlPythonTypes[s] + "("; } return dt; }
public void WriteProperty(IProperty p, IStereotypeInstance column) { _fsPy.WriteLine(" {0} = models.{1}db_column='{2}', blank={3} {4})", LowerCaseVarName(p.Name), BuildDjangoDataType(column), p.Name, String.IsNullOrEmpty(UmlHelper.GetNull(column)) ? "True" : "False", String.IsNullOrEmpty(UmlHelper.GetDefaultValue(p)) ? "" : ", default={0})", UmlHelper.GetDefaultValue(p)); //description = models.CharField(max_length=768, db_column='Description', blank=True) }
public void WritePKProperty(IProperty p, IStereotypeInstance column) { _fsPy.WriteLine(" {0} = models.BigIntegerField(primary_key=True, db_column='{1}')", LowerCaseVarName(p.Name), p.Name); }
private void HierarchyTableProcessing(IStereotypeInstance table, IClass cls) { String childName = String.Empty; String parentName = String.Empty; String kindName = String.Empty; foreach (IProperty p in cls.Members) { IEnumerable<IStereotypeInstance> columns = p.AppliedStereotypes.Where(s => s.Name == "Column"); foreach (IStereotypeInstance column in columns) { _py.AddProperty(p); _sql.AddProperty(p); } } foreach (IProperty p in cls.GetOutgoingAssociationEnds()) { IAssociation association = p.Association; IEnumerable<IStereotypeInstance> parent = association.AppliedStereotypes.Where(s => s.Name == "Parent"); foreach (IStereotypeInstance fk in parent) { //kindName is the Table kind for which this table is a hierarchy kindName = association.EndTypes.Where(s => s.Name != cls.Name).First().Name; if (IsNavigableAssoc(p) && fk != null) { parentName = p.Name + "Id"; _py.AddFKProperty(p); _sql.AddFKProperty(p); _sql.AddFKConstraint(association.Name, cls.Name, p.Name, p.Type.Name, TableKeys[p.Type.Name], "Delete"); } } IEnumerable<IStereotypeInstance> child = association.AppliedStereotypes.Where(s => s.Name == "Child"); foreach (IStereotypeInstance fk in child) { if (IsNavigableAssoc(p) && fk != null) { childName = p.Name + "Id"; _py.AddFKProperty(p); _sql.AddFKProperty(p); _sql.AddFKConstraint(association.Name, cls.Name, p.Name, p.Type.Name, TableKeys[p.Type.Name], "Delete"); } } } _sql.AddIndexConstraint(cls.Name + "Index", parentName + ", " + childName, ""); _sql.AddSubtreeProcedure(cls.Name, kindName, parentName, childName); }
private string BuildDataType(IStereotypeInstance column) { // TODO - rewrite this using dictionaries for the various DBs // and map to datatypes allowed in DSL string s = UmlHelper.GetDataType(column); StringBuilder dt = new StringBuilder(s); if (_run == SQLGenerateRun.Postgres) { if (s == "float()") { return "real"; } else if (s == "datetime") { return "timestamp"; } else if (s == "datetimezone") { return "timestamp with time zone"; } else if (s == "blob") { return "bytea"; } else if (s == "double") { return "double precision"; } else if (s == "varbinary()") { return "boolean"; } else if (s == "tinyint") { return "smallint"; } else if (s == "text") { return "text"; } else if (s == "guid") { return "uuid"; } else if (s.Contains("()")) { dt.Insert(dt.Length - 1, UmlHelper.GetLength(column)); return dt.ToString(); } else { return dt.ToString(); } } else if (_run == SQLGenerateRun.INNODB || _run == SQLGenerateRun.MyISAM) { if (s.Contains("()")) { dt.Insert(dt.Length - 1, UmlHelper.GetLength(column)); return dt.ToString(); } return dt.ToString(); } else { return ""; } }