private void Check_1_1_RelationColumns(Relation rel, RelationEnd relEnd, RelationEndRole role) { if (rel.HasStorage(role)) { var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName); RelationEnd otherEnd = rel.GetOtherEnd(relEnd); var refTblName = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName); string colName = Construct.ForeignKeyColumnName(otherEnd); string assocName = rel.GetRelationAssociationName(role); string idxName = Construct.IndexName(tblName.Name, colName); CheckColumn(tblName, Construct.ForeignKeyColumnName(otherEnd), System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null); if (!db.CheckFKConstraintExists(tblName, assocName)) { Log.WarnFormat("FK Constraint '{0}' is missing", assocName); if (repair) { db.CreateFKConstraint(tblName, refTblName, colName, assocName, false); } } if (!db.CheckIndexExists(tblName, idxName)) { Log.WarnFormat("Index '{0}' is missing", idxName); if (repair) { db.CreateIndex(tblName, idxName, true, false, colName); } } } }
public static void Call(Arebis.CodeGeneration.IGenerationHost host, IZetboxContext ctx, Serialization.SerializationMembersList serializationList, Relation rel, RelationEndRole endRole, string backingCollectionType) { if (rel == null) { throw new ArgumentNullException("rel"); } RelationEnd relEnd = rel.GetEndFromRole(endRole); RelationEnd otherEnd = rel.GetOtherEnd(relEnd); string name = relEnd.Navigator.Name; string exposedCollectionInterface = rel.NeedsPositionStorage(otherEnd.GetRole()) ? "IList" : "ICollection"; string referencedInterface = otherEnd.Type.GetDataTypeString(); string backingName = "_" + name; string aSideType = rel.A.Type.GetDataTypeString(); string bSideType = rel.B.Type.GetDataTypeString(); string entryType = rel.GetRelationFullName() + host.Settings["extrasuffix"] + Zetbox.API.Helper.ImplementationSuffix; string providerCollectionType = (rel.NeedsPositionStorage(otherEnd.GetRole()) ? "IList<" : "ICollection<") + entryType + ">"; bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading; Call(host, ctx, serializationList, name, exposedCollectionInterface, referencedInterface, backingName, backingCollectionType, aSideType, bSideType, entryType, providerCollectionType, rel.ExportGuid, endRole, eagerLoading); }
private void ApplyRememberToDeleteTemplate(Relation rel, RelationEnd relEnd) { if (rel.GetOtherEnd(relEnd).Multiplicity == Multiplicity.ZeroOrMore) { if (relEnd.Navigator != null) { var prop = relEnd.Navigator; this.WriteObjects(" // ", rel.GetAssociationName(), " ZeroOrMore\r\n"); this.WriteObjects(" foreach(NHibernatePersistenceObject x in ", prop.Name, ") {\r\n"); this.WriteObjects(" x.ParentsToDelete.Add(this);\r\n"); this.WriteObjects(" ChildrenToDelete.Add(x);\r\n"); this.WriteObjects(" }\r\n"); } else { this.WriteObjects(" // should fetch && remember parent for ", relEnd.Parent.GetRelationClassName(), "\r\n"); } } else { if (relEnd.Navigator != null) { var prop = relEnd.Navigator; this.WriteObjects(" // ", rel.GetAssociationName(), "\r\n"); this.WriteObjects(" if (", prop.Name, " != null) {\r\n"); this.WriteObjects(" ((NHibernatePersistenceObject)", prop.Name, ").ChildrenToDelete.Add(this);\r\n"); this.WriteObjects(" ParentsToDelete.Add((NHibernatePersistenceObject)", prop.Name, ");\r\n"); this.WriteObjects(" }\r\n"); } else { this.WriteObjects(" // should fetch && remember children for ", relEnd.Parent.GetRelationClassName(), "\r\n"); } } }
public static void CreateNavigator(RelationEnd obj, MethodReturnEventArgs<ObjectReferenceProperty> e) { Relation rel = obj.AParent ?? obj.BParent; RelationEnd other = rel != null ? rel.GetOtherEnd(obj) : null; var nav = obj.Context.Create<ObjectReferenceProperty>(); nav.CategoryTags = String.Empty; nav.ObjectClass = obj.Type; nav.RelationEnd = obj; nav.Module = rel != null ? rel.Module : null; if (other != null) { if (nav.GetIsList()) { if (nav.RelationEnd.Parent.GetOtherEnd(nav.RelationEnd).HasPersistentOrder) { nav.ValueModelDescriptor = obj.Context.FindPersistenceObject<ViewModelDescriptor>(ViewModelDescriptor_ObjectListModel); } else { nav.ValueModelDescriptor = obj.Context.FindPersistenceObject<ViewModelDescriptor>(ViewModelDescriptor_ObjectCollectionModel); } } else { nav.ValueModelDescriptor = obj.Context.FindPersistenceObject<ViewModelDescriptor>(ViewModelDescriptor_ObjectReferenceModel); } nav.Name = other.RoleName; } e.Result = nav; }
public static void Call(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, ObjectReferenceProperty prop) { if (_host == null) { throw new ArgumentNullException("_host"); } if (ctx == null) { throw new ArgumentNullException("ctx"); } if (prop == null) { throw new ArgumentNullException("prop"); } Relation rel = Zetbox.App.Extensions.RelationExtensions.Lookup(ctx, prop); RelationEnd relEnd = rel.GetEnd(prop); RelationEnd otherEnd = rel.GetOtherEnd(relEnd); string referencedInterface = otherEnd.Type.Module.Namespace + "." + otherEnd.Type.Name; string referencedImplementation = Mappings.ObjectClassHbm.GetWrapperTypeReference(otherEnd.Type, _host.Settings); string name = prop.Name; string implNameUnused = null; string fkBackingName = "_fk_" + name; string fkGuidBackingName = "_fk_guid_" + name; bool isExportable = relEnd.Type.ImplementsIExportable() && otherEnd.Type.ImplementsIExportable(); ReloadOneReference.Call(_host, ctx, referencedInterface, referencedImplementation, name, implNameUnused, fkBackingName, fkGuidBackingName, isExportable); }
public static void isValid_HasPersistentOrder(RelationEnd obj, PropertyIsValidEventArgs e) { if (obj.HasPersistentOrder && obj.Multiplicity != Multiplicity.ZeroOrMore) { e.IsValid = false; e.Error = String.Format("Can only require persistent order when multiplicity is ZeroOrMore, but multiplicity is {0}", obj.Multiplicity); } }
public static string ListPositionPropertyName(RelationEnd relEnd) { if (relEnd == null) { throw new ArgumentNullException("relEnd"); } return(relEnd.RoleName + Zetbox.API.Helper.PositionSuffix); }
public static string ListPositionColumnName(RelationEnd otherEnd, string parentPropName) { if (otherEnd == null) { throw new ArgumentNullException("otherEnd"); } return(ForeignKeyColumnName(Construct.NestedColumnName(otherEnd.RoleName, parentPropName)) + Zetbox.API.Helper.PositionSuffix); }
public static string ForeignKeyColumnName(RelationEnd otherEnd, string prefix) { if (otherEnd == null) { throw new ArgumentNullException("otherEnd"); } return(ForeignKeyColumnName(NestedColumnName(otherEnd.RoleName, prefix))); }
public static void GetOtherEnd(Relation rel, MethodReturnEventArgs<RelationEnd> e, RelationEnd relEnd) { if (rel.A == relEnd) e.Result = rel.B; else if (rel.B == relEnd) e.Result = rel.A; else e.Result = null; }
public static void ToString(RelationEnd obj, MethodReturnEventArgs<string> e) { e.Result = String.Format("RelationEnd {0}({1})", obj.RoleName, obj.Type == null ? "no type" : obj.Type.Name); ToStringHelper.FixupFloatingObjectsToString(obj, e); }
protected override void ApplyObjectReferenceProperty(Relation rel, RelationEndRole endRole, string propertyName) { // TODO: create/use ObjectReference*IMPLEMENTATION* instead (_fk* can already be made available) RelationEnd relEnd = rel.GetEndFromRole(endRole); RelationEnd otherEnd = rel.GetOtherEnd(relEnd); string moduleNamespace = rel.Module.Namespace; string implName = propertyName + Zetbox.API.Helper.ImplementationSuffix; string eventName = "On" + propertyName; string fkBackingName = "_fk_" + propertyName; string fkGuidBackingName = "_fk_guid_" + propertyName; string referencedInterface = relEnd.Type.GetDataTypeString(); string referencedImplementation = referencedInterface + Host.Settings["extrasuffix"] + Zetbox.API.Helper.ImplementationSuffix; string associationName = rel.GetAssociationName() + "_" + endRole.ToString(); string targetRoleName = relEnd.RoleName; string positionPropertyName = rel.NeedsPositionStorage(endRole) ? propertyName + Zetbox.API.Helper.PositionSuffix : null; string inverseNavigatorName = null; bool inverseNavigatorIsList = false; bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading; bool relDataTypeExportable = rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable(); bool callGetterSetterEvents = false; Templates.Properties.ObjectReferencePropertyTemplate.Call(Host, ctx, MembersToSerialize, moduleNamespace, "/* not member of an interface, 'ownInterface' should not be used */", propertyName, implName, eventName, fkBackingName, fkGuidBackingName, referencedInterface, referencedImplementation, associationName, targetRoleName, positionPropertyName, inverseNavigatorName, inverseNavigatorIsList, eagerLoading, relDataTypeExportable, callGetterSetterEvents, false, // ObjRef with relation cannot be calculated false); }
public static void GetIsList(ObjectReferenceProperty prop, MethodReturnEventArgs <bool> e) { if (prop == null) { throw new ArgumentNullException("prop"); } RelationEnd relEnd = prop.RelationEnd; Relation rel = relEnd.GetParent(); RelationEnd otherEnd = rel.GetOtherEnd(relEnd); e.Result = otherEnd.Multiplicity.UpperBound() > 1; }
private void ProcessRelationEnd(Relation rel, RelationEnd relEnd) { var otherEnd = rel.GetOtherEnd(relEnd); string columnName = Construct.ForeignKeyColumnName(otherEnd, prefix); bool needPositionStorage = rel.NeedsPositionStorage(relEnd.GetRole()); string positionColumnName = Construct.ListPositionColumnName(otherEnd, prefix); GenerateProperty( columnName, needPositionStorage, positionColumnName); }
public static string RelationToBackingCollectionType(Relation rel, RelationEnd otherEnd) { if (rel == null) { throw new ArgumentNullException("rel"); } if (otherEnd == null) { throw new ArgumentNullException("otherEnd"); } string result; if (rel.NeedsPositionStorage(otherEnd.GetRole())) { result = String.Format("NHibernate{0}SideListWrapper", otherEnd.GetRole()); } else { result = String.Format("NHibernate{0}SideCollectionWrapper", otherEnd.GetRole()); } return result; }
private static string FormatNavigatorDescription(RelationEnd relEnd, ObjectClass refType) { var rel = relEnd.Parent; var otherEnd = rel.GetOtherEnd(relEnd); var prop = relEnd.Navigator; if (prop == null) { return(string.Format("No Navigator for {0} defined", string.IsNullOrEmpty(relEnd.RoleName) ? (object)relEnd.GetRole() : relEnd.RoleName)); } if (prop.GetIsList()) { return(string.Format("Navigator {1}.{2} is a {3}<{0}>", refType.Name, prop.ObjectClass.Name, prop.Name, rel.NeedsPositionStorage(otherEnd.GetRole()) ? "IList" : "ICollection")); } if (prop.IsNullable()) { return(string.Format("Navigator {1}.{2} is a nullable reference to {0}", refType.Name, prop.ObjectClass.Name, prop.Name)); } return(string.Format("Navigator {1}.{2} is a required reference to {0}", refType.Name, prop.ObjectClass.Name, prop.Name)); }
public RelationEndViewModel( IViewModelDependencies appCtx, IZetboxContext dataCtx, ViewModel parent, RelationEnd relEnd) : base(appCtx, dataCtx, parent, relEnd) { }
private void New_1_1_Relation_CreateColumns(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role) { TableRef tblName, refTblName; string assocName, colName, idxName; if (!TryInspect_1_1_Relation(rel, relEnd, otherEnd, role, out tblName, out refTblName, out assocName, out colName, out idxName)) { return; } CreateFKColumn(otherEnd, tblName, colName); db.CreateFKConstraint(tblName, refTblName, colName, assocName, false); if (db.CheckIndexPossible(tblName, idxName, true, false, colName)) db.CreateIndex(tblName, idxName, true, false, colName); else Log.WarnFormat("Cannot create index: {0}", idxName); if (rel.NeedsPositionStorage(role)) { Log.ErrorFormat("1:1 Relation should never need position storage, but this one does!"); } }
public static void get_Parent(RelationEnd relEnd, PropertyGetterEventArgs<Relation> e) { e.Result = relEnd.AParent ?? relEnd.BParent; }
public static string ListPositionColumnName(RelationEnd otherEnd) { return ListPositionColumnName(otherEnd, string.Empty); }
public static string ForeignKeyColumnName(RelationEnd otherEnd) { return ForeignKeyColumnName(otherEnd, string.Empty); }
internal bool TryInspect_1_1_Relation(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role, out TableRef tblName, out TableRef refTblName, out string assocName, out string colName, out string idxName) { tblName = relEnd.Type.GetTableRef(db); refTblName = otherEnd.Type.GetTableRef(db); assocName = rel.GetRelationAssociationName(role); colName = Construct.ForeignKeyColumnName(otherEnd); idxName = Construct.IndexName(tblName.Name, colName); return true; }
/// <summary> /// Returns the name for the foreign key <strong>to</strong> the specified role. /// </summary> public static string GetRelationFkNameToEnd(this Relation rel, RelationEnd relEnd) { if (relEnd == null) { throw new ArgumentNullException("relEnd"); } return String.Format("fk_{0}", relEnd.RoleName); }
/// <summary> /// Tries to dissect a relation for the 1_N case. /// </summary> /// <returns>false if something is wrong with the relation definition. The out parameters are only filled correctly when the function returns true.</returns> internal bool TryInspect_1_N_Relation( Relation rel, out string assocName, out RelationEnd relEnd, out RelationEnd otherEnd, out TableRef tblName, out TableRef refTblName, out string colName, out bool hasPersistentOrder, out string listPosName) { assocName = rel.GetAssociationName(); switch (rel.Storage) { case StorageType.MergeIntoA: relEnd = rel.A; otherEnd = rel.B; break; case StorageType.MergeIntoB: otherEnd = rel.A; relEnd = rel.B; break; default: Log.ErrorFormat("Skipping Relation '{0}': unsupported Storage set: {1}", assocName, rel.Storage); otherEnd = null; relEnd = null; tblName = null; refTblName = null; hasPersistentOrder = default(bool); colName = null; listPosName = null; return false; } tblName = relEnd.Type.GetTableRef(db); refTblName = otherEnd.Type.GetTableRef(db); hasPersistentOrder = rel.NeedsPositionStorage(relEnd.GetRole()); colName = Construct.ForeignKeyColumnName(otherEnd); listPosName = Construct.ListPositionColumnName(otherEnd); return true; }
/// <summary> /// Creates a fk column "colName" on table "tblName", pointing to "otherEnd". /// </summary> private void CreateFKColumn(RelationEnd otherEnd, TableRef tblName, string colName, bool forceTPH = false) { var relEnd = otherEnd.GetParent().GetOtherEnd(otherEnd); var isNullable = otherEnd.IsNullable(); var checkNotNull = !isNullable; var createCheckConstraint = false; string errorMsg = null; if (checkNotNull && (forceTPH || (relEnd.Type.GetTableMapping() == TableMapping.TPH && relEnd.Type.BaseObjectClass != null))) { isNullable = true; createCheckConstraint = true; } else if (checkNotNull && db.CheckTableContainsData(tblName)) { isNullable = true; errorMsg = "Unable to create NOT NULL column ({1}), since table ({0}) contains data. Created nullable column instead"; } db.CreateColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, isNullable); if (createCheckConstraint) { CreateTPHNotNullCheckConstraint(tblName, colName, relEnd.Type); } if (errorMsg != null) { Log.ErrorFormat(errorMsg, tblName, colName); } }
/// <summary>Returns the name for a fk column pointing to otherEnd</summary> /// <returns>The prefixed name for a fk column pointing to otherEnd</returns> public static string ForeignKeyColumnName(RelationEnd otherEnd, string prefix) { if (otherEnd == null) { throw new ArgumentNullException("otherEnd"); } var rel = otherEnd.GetParent(); var relEnd = rel.GetOtherEnd(otherEnd); if (relEnd.Type.GetTableMapping() == TableMapping.TPH && relEnd.Type.BaseObjectClass != null && rel.HasStorage(relEnd.GetRole())) { return NestedColumnName(ForeignKeyColumnName(NestedColumnName(otherEnd.RoleName, prefix)), relEnd.Type.TableName); } else { return ForeignKeyColumnName(NestedColumnName(otherEnd.RoleName, prefix)); } }
public static string ListPositionPropertyName(RelationEnd relEnd) { if (relEnd == null) { throw new ArgumentNullException("relEnd"); } return relEnd.RoleName + Zetbox.API.Helper.PositionSuffix; }
private void Delete_1_1_Relation_DropColumns(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role) { var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName); var colName = Construct.ForeignKeyColumnName(otherEnd); var assocName = rel.GetRelationAssociationName(role); if (db.CheckFKConstraintExists(tblName, assocName)) db.DropFKConstraint(tblName, assocName); if (db.CheckColumnExists(tblName, colName)) db.DropColumn(tblName, colName); if (rel.NeedsPositionStorage(role) && db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd))) db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd)); }
public static string ForeignKeyColumnName(RelationEnd otherEnd, string prefix) { if (otherEnd == null) { throw new ArgumentNullException("otherEnd"); } return ForeignKeyColumnName(NestedColumnName(otherEnd.RoleName, prefix)); }
private void New_1_1_Relation_CreateColumns(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role) { var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName); var refTblName = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName); var colName = Construct.ForeignKeyColumnName(otherEnd); var assocName = rel.GetRelationAssociationName(role); var idxName = Construct.IndexName(tblName.Name, colName); CreateFKColumn(otherEnd, tblName, colName); db.CreateFKConstraint(tblName, refTblName, colName, assocName, false); if (db.CheckIndexPossible(tblName, idxName, true, false, colName)) db.CreateIndex(tblName, idxName, true, false, colName); else Log.WarnFormat("Cannot create index: {0}", idxName); if (rel.NeedsPositionStorage(role)) { Log.ErrorFormat("1:1 Relation should never need position storage, but this one does!"); } }
public static string ListPositionColumnName(RelationEnd otherEnd, string parentPropName) { if (otherEnd == null) { throw new ArgumentNullException("otherEnd"); } return ForeignKeyColumnName(Construct.NestedColumnName(otherEnd.RoleName, parentPropName)) + Zetbox.API.Helper.PositionSuffix; }
public override void Generate() { #line 40 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" RelationEnd relEnd = rel.GetEndFromRole(endRole); RelationEnd otherEnd = rel.GetOtherEnd(relEnd); // the ef-visible property's name string efName = name + ImplementationPropertySuffix; // the name of the position property as string argument string positionPropertyNameArgument = rel.NeedsPositionStorage(otherEnd.GetRole()) ? String.Format(@", ""{0}""", Construct.ListPositionPropertyName(otherEnd)) : String.Empty; // the name of the EF association string assocName = rel.GetAssociationName() + (relEnd.Multiplicity.UpperBound() > 1 ? "_" + relEnd.GetRole().ToString() : String.Empty); string targetRoleName = otherEnd.RoleName; // which Zetbox interface this is string thisInterface = relEnd.Type.GetDataTypeString(); // the actual implementation class of the list's elements string referencedImplementation = referencedInterface + ImplementationSuffix; // whether or not the collection will be eagerly loaded bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading; // override and ignore Base's notion of wrapper classes wrapperClass = rel.NeedsPositionStorage(otherEnd.GetRole()) ? "EntityListWrapper" : "EntityCollectionWrapper"; var eventName = "On" + name + "_PostSetter"; #line 65 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" this.WriteObjects(" // ", this.GetType(), "\r\n"); this.WriteObjects(" // implement the user-visible interface\r\n"); this.WriteObjects(" [XmlIgnore()]\r\n"); this.WriteObjects(" [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]\r\n"); this.WriteObjects(" public ", exposedListType, "<", referencedInterface, "> ", name, "\r\n"); this.WriteObjects(" {\r\n"); this.WriteObjects(" get\r\n"); this.WriteObjects(" {\r\n"); this.WriteObjects(" if (", wrapperName, " == null)\r\n"); this.WriteObjects(" {\r\n"); this.WriteObjects(" ", wrapperName, " = new ", wrapperClass, "<", referencedInterface, ", ", referencedImplementation, ">(\r\n"); this.WriteObjects(" this.Context, ", efName, ",\r\n"); this.WriteObjects(" () => this.NotifyPropertyChanging(\"", name, "\", null, null),\r\n"); this.WriteObjects(" () => { this.NotifyPropertyChanged(\"", name, "\", null, null); if(", eventName, " != null && IsAttached) ", eventName, "(this); },\r\n"); this.WriteObjects(" (item) => item.NotifyPropertyChanging(\"", otherName, "\", null, null),\r\n"); this.WriteObjects(" (item) => item.NotifyPropertyChanged(\"", otherName, "\", null, null)"); #line 81 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" // TODO: improve this! if (rel.NeedsPositionStorage(otherEnd.GetRole())) { this.WriteObjects(", \"", relEnd.RoleName, "\""); } #line 86 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" this.WriteObjects("", positionPropertyNameArgument, ");\r\n"); this.WriteObjects(" }\r\n"); this.WriteObjects(" return ", wrapperName, ";\r\n"); this.WriteObjects(" }\r\n"); this.WriteObjects(" }\r\n"); this.WriteObjects(" \r\n"); this.WriteObjects(" [EdmRelationshipNavigationProperty(\"Model\", \"", assocName, "\", \"", targetRoleName, "\")]\r\n"); this.WriteObjects(" public EntityCollection<", referencedImplementation, "> ", efName, "\r\n"); this.WriteObjects(" {\r\n"); this.WriteObjects(" get\r\n"); this.WriteObjects(" {\r\n"); this.WriteObjects(" var c = ((IEntityWithRelationships)(this)).RelationshipManager\r\n"); this.WriteObjects(" .GetRelatedCollection<", referencedImplementation, ">(\r\n"); this.WriteObjects(" \"Model.", assocName, "\",\r\n"); this.WriteObjects(" \"", targetRoleName, "\");\r\n"); this.WriteObjects(" if (this.EntityState.In(System.Data.EntityState.Modified, System.Data.EntityState.Unchanged)\r\n"); this.WriteObjects(" && !c.IsLoaded)\r\n"); this.WriteObjects(" {\r\n"); this.WriteObjects(" c.Load();\r\n"); this.WriteObjects(" }\r\n"); this.WriteObjects(" c.ForEach(i => i.AttachToContext(Context));\r\n"); this.WriteObjects(" return c;\r\n"); this.WriteObjects(" }\r\n"); this.WriteObjects(" }\r\n"); this.WriteObjects(" private ", wrapperClass, "<", referencedInterface, ", ", referencedImplementation, "> ", wrapperName, ";\r\n"); this.WriteObjects("\r\n"); #line 112 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" if (eagerLoading) { #line 113 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" this.WriteObjects(" private List<int> ", name, "Ids;\r\n"); this.WriteObjects(" private bool ", name, "_was_eagerLoaded = false;\r\n"); #line 116 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" if (serializationList != null) { serializationList.Add("Serialization.EagerLoadingSerialization", Zetbox.Generator.Templates.Serialization.SerializerType.Binary, null, null, name, true, false, null); } } #line 122 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\Properties\ObjectListProperty.cst" this.WriteObjects("\r\n"); }
private void Check_1_1_RelationColumns(Relation rel, RelationEnd relEnd, RelationEndRole role) { if (rel.HasStorage(role)) { var tblName = relEnd.Type.GetTableRef(db); RelationEnd otherEnd = rel.GetOtherEnd(relEnd); var refTblName = otherEnd.Type.GetTableRef(db); string colName = Construct.ForeignKeyColumnName(otherEnd); string assocName = rel.GetRelationAssociationName(role); string idxName = Construct.IndexName(tblName.Name, colName); var realIsNullable = otherEnd.IsNullable(); if (realIsNullable == false) realIsNullable = relEnd.Type.GetTableMapping() == TableMapping.TPH && relEnd.Type.BaseObjectClass != null; CheckColumn(tblName, Construct.ForeignKeyColumnName(otherEnd), System.Data.DbType.Int32, 0, 0, realIsNullable, null); if (!db.CheckFKConstraintExists(tblName, assocName)) { Log.WarnFormat("FK Constraint '{0}' is missing", assocName); if (repair) { db.CreateFKConstraint(tblName, refTblName, colName, assocName, false); } } if (!db.CheckIndexExists(tblName, idxName)) { Log.WarnFormat("Index '{0}' is missing", idxName); if (repair) { db.CreateIndex(tblName, idxName, true, false, colName); } } } }
public static void isValid_Navigator(RelationEnd obj, PropertyIsValidEventArgs e) { var relEnd = obj; var rel = relEnd.GetParent(); if (rel == null) { e.IsValid = false; e.Error = "No Relation assigned to Relation end"; return; } var otherEnd = rel.GetOtherEnd(relEnd); var orp = obj.Navigator; e.IsValid = true; if (orp != null) { if (orp.ObjectClass == null) { e.IsValid = false; e.Error = String.Format("Navigator should be attached to {0}", relEnd.Type); } if (orp.ObjectClass != relEnd.Type) { e.IsValid = false; e.Error = String.Format("Navigator is attached to {0} but should be attached to {1}", orp.ObjectClass, relEnd.Type); } switch (otherEnd.Multiplicity) { case Multiplicity.One: if(orp.Constraints.OfType<NotNullableConstraint>().Count() == 0) { e.IsValid = false; e.Error = "Navigator should have NotNullableConstraint because Multiplicity of opposite RelationEnd is One"; } break; case Multiplicity.ZeroOrMore: if(orp.Constraints.OfType<NotNullableConstraint>().Count() > 0) { e.IsValid = false; e.Error = "Navigator should not have NotNullableConstraint because Multiplicity of opposite RelationEnd is ZeroOrMore"; } break; case Multiplicity.ZeroOrOne: if(orp.Constraints.OfType<NotNullableConstraint>().Count() > 0) { e.IsValid = false; e.Error = "Navigator should not have NotNullableConstraint because Multiplicity of opposite RelationEnd is ZeroOrOne"; } break; } } }
private static string FormatNavigatorDescription(RelationEnd relEnd, ObjectClass refType) { var rel = relEnd.Parent; var otherEnd = rel.GetOtherEnd(relEnd); var prop = relEnd.Navigator; if (prop == null) return string.Format("No Navigator for {0} defined", string.IsNullOrEmpty(relEnd.RoleName) ? (object)relEnd.GetRole() : relEnd.RoleName); if (prop.GetIsList()) { return string.Format("Navigator {1}.{2} is a {3}<{0}>", refType.Name, prop.ObjectClass.Name, prop.Name, rel.NeedsPositionStorage(otherEnd.GetRole()) ? "IList" : "ICollection"); } if (prop.IsNullable()) return string.Format("Navigator {1}.{2} is a nullable reference to {0}", refType.Name, prop.ObjectClass.Name, prop.Name); return string.Format("Navigator {1}.{2} is a required reference to {0}", refType.Name, prop.ObjectClass.Name, prop.Name); }
private void Delete_1_1_Relation_DropColumns(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role) { var tblName = relEnd.Type.GetTableRef(db); var colName = Construct.ForeignKeyColumnName(otherEnd); var assocName = rel.GetRelationAssociationName(role); var indexName = Construct.IndexName(tblName.Name, colName); var checkConstraintName = Construct.CheckConstraintName(tblName.Name, colName); if (db.CheckFKConstraintExists(tblName, assocName)) db.DropFKConstraint(tblName, assocName); if (db.CheckIndexExists(tblName, indexName)) db.DropIndex(tblName, indexName); if (db.CheckCheckConstraintExists(tblName, checkConstraintName)) db.DropCheckConstraint(tblName, checkConstraintName); if (db.CheckColumnExists(tblName, colName)) db.DropColumn(tblName, colName); if (rel.NeedsPositionStorage(role) && db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd))) db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd)); }
private void ApplyNMProperty( Relation rel, RelationEnd relEnd, RelationEnd otherEnd, ObjectReferenceProperty prop) { this.WriteLine(" <!-- NMProperty -->"); this.WriteLine(" <!-- rel={0} -->", rel.GetRelationClassName()); this.WriteLine(" <!-- relEnd={0} otherEnd={1} -->", relEnd.RoleName, otherEnd.RoleName); string nameAttr = String.Format("name=\"{0}\"", prop.Name); string tableName = rel.GetRelationTableName(); string tableAttr = String.Format("table=\"`{0}`\"", tableName); string relationEntryClassAttr = String.Format("class=\"{0}.{1}{2}+{1}Proxy,Zetbox.Objects.NHibernateImpl\"", rel.Module.Namespace, rel.GetRelationClassName(), ImplementationSuffix); string fkThisColumnAttr = String.Format("column=\"`{0}`\"", Construct.ForeignKeyColumnName(relEnd)); //string fkOtherColumnAttr = String.Format("column=\"`{0}`\"", Construct.ForeignKeyColumnName(otherEnd)); // always map as set, the wrapper has to translate/order the elements this.WriteObjects(" <set ", nameAttr, " ", tableAttr, " inverse=\"true\" cascade=\"all-delete-orphan\" batch-size=\"100\" "); if (prop.EagerLoading) { // TODO: re-think and re-test eagerloading //this.WriteObjects("lazy=\"false\" fetch=\"join\" "); } this.WriteLine(">"); this.WriteObjects(" <key ", fkThisColumnAttr, " />"); this.WriteLine(); this.WriteObjects(" <one-to-many ", relationEntryClassAttr, " />"); this.WriteLine(); this.WriteObjects(" </set>"); this.WriteLine(); }
private void CreateFKColumn(RelationEnd otherEnd, TableRef tblName, string colName) { if (otherEnd.IsNullable() || !db.CheckTableContainsData(tblName)) { db.CreateColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable()); } else { db.CreateColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, true); Log.ErrorFormat("Unable to create NOT NULL column, since table contains data. Created nullable column instead"); } }