Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <summary>
        /// Returns the association name for the association from the given end to the CollectionEntry
        /// </summary>
        public static string GetRelationAssociationName(this Relation rel, RelationEndRole endRole)
        {
            if (rel == null) { throw new ArgumentNullException("rel"); }
            RelationEnd relEnd = rel.GetEndFromRole(endRole);

            return String.Format("FK_{0}_{1}_{2}_{3}", rel.A.RoleName, rel.Verb, rel.B.RoleName, relEnd.GetRole());
        }
        protected IServerCollectionHandler GetServerCollectionHandlerHelper(
            Type collectionHandlerType,
            ImplementationType aType,
            ImplementationType bType,
            RelationEndRole endRole)
        {
            if (Object.ReferenceEquals(aType, null)) { throw new ArgumentNullException("aType"); }
            if (Object.ReferenceEquals(bType, null)) { throw new ArgumentNullException("bType"); }
            try
            {
                // dynamically translate generic types into provider-known types
                Type[] genericArgs;
                if (endRole == RelationEndRole.A)
                {
                    genericArgs = new Type[] { aType.Type, bType.Type, aType.Type, bType.Type };
                }
                else
                {
                    genericArgs = new Type[] { aType.Type, bType.Type, bType.Type, aType.Type };
                }

                Type resultType = collectionHandlerType.MakeGenericType(genericArgs);
                return (IServerCollectionHandler)Activator.CreateInstance(resultType);
            }
            catch (Exception ex)
            {
                var msg = String.Format(
                    "Failed to create IServerCollectionHandler for A=[{0}], B=[{1}], role=[{2}]",
                    aType,
                    bType,
                    endRole);
                Log.Error(msg, ex);
                throw;
            }
        }
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
            IZetboxContext ctx,
            Templates.Serialization.SerializationMembersList serializationList,
            Relation rel, RelationEndRole endRole, string backingCollectionType)
        {
            if (host == null) { throw new ArgumentNullException("host"); }
            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;
            bool serializeRelationEntries = rel.GetRelationType() == RelationType.n_m;

            string entryProxyType = entryType + "." + rel.GetRelationClassName() + "Proxy";

            string inverseNavigatorName = otherEnd.Navigator != null ? otherEnd.Navigator.Name : null;

            Call(host, ctx, serializationList, name, exposedCollectionInterface, referencedInterface, backingName, backingCollectionType, aSideType, bSideType, entryType, providerCollectionType, rel.ExportGuid, endRole, eagerLoading, serializeRelationEntries, entryProxyType, inverseNavigatorName);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        /// <param name="ctx"></param>
        /// <param name="serializationList"></param>
        /// <param name="name">the name of the property to create</param>
        /// <param name="wrapperClass">the name of the wrapper class for wrapping the EntityCollection</param>
        /// <param name="exposedListType">which generic interface to use for the collection (IList or ICollection)</param>
        /// <param name="rel"></param>
        /// <param name="endRole"></param>
        /// <param name="positionPropertyName">the name of the position property for this list</param>
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
                                IZetboxContext ctx,
                                Serialization.SerializationMembersList serializationList,
                                string name,
                                string wrapperClass,
                                string exposedListType,
                                Relation rel,
                                RelationEndRole endRole,
                                string positionPropertyName)
        {
            if (rel == null)
            {
                throw new ArgumentNullException("rel");
            }

            RelationEnd relEnd   = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            string wrapperName = "_" + name;

            var otherName = otherEnd.Navigator == null ? relEnd.RoleName : otherEnd.Navigator.Name;

            string referencedInterface = otherEnd.Type.GetDataTypeString();

            Call(host, ctx, serializationList, name, wrapperName, wrapperClass, exposedListType, rel, endRole, positionPropertyName, otherName, referencedInterface);
        }
        protected virtual void ApplyIndexPropertyTemplate(Relation rel, RelationEndRole endRole)
        {
            if (rel.NeedsPositionStorage(endRole))
            {
                // provided by ObjectReferencePropertyTemplate
                string posBackingStore = "_" + endRole + Zetbox.API.Helper.PositionSuffix;

                // is serialized by the ObjectReferenceProperty
                //this.MembersToSerialize.Add(
                //    Serialization.SerializerType.All,
                //    relEnd.Type.Module.Namespace,
                //    endRole + Zetbox.API.Helper.PositionSuffix,
                //    posBackingStore);

                this.WriteObjects("        public int? ", endRole, "Index { get { return ",
                    posBackingStore, "; } set { ",
                    posBackingStore, " = value; } }");
                this.WriteLine();
            }
            else if (IsOrdered())
            {
                this.WriteLine("/// <summary>ignored implementation for INewListEntry</summary>");
                this.WriteObjects("public int? ", endRole, "Index { get { return null; } set { } }");
            }
        }
Beispiel #7
0
        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);
                    }
                }
            }
        }
Beispiel #8
0
        protected virtual void ApplyIndexPropertyTemplate(Relation rel, RelationEndRole endRole)
        {
            if (rel.NeedsPositionStorage(endRole))
            {
                // provided by ObjectReferencePropertyTemplate
                string posBackingStore = "_" + endRole + Zetbox.API.Helper.PositionSuffix;

                // is serialized by the ObjectReferenceProperty
                //this.MembersToSerialize.Add(
                //    Serialization.SerializerType.All,
                //    relEnd.Type.Module.Namespace,
                //    endRole + Zetbox.API.Helper.PositionSuffix,
                //    posBackingStore);

                this.WriteObjects("        public int? ", endRole, "Index { get { return ",
                                  posBackingStore, "; } set { ",
                                  posBackingStore, " = value; } }");
                this.WriteLine();
            }
            else if (IsOrdered())
            {
                this.WriteLine("/// <summary>ignored implementation for INewListEntry</summary>");
                this.WriteObjects("public int? ", endRole, "Index { get { return null; } set { } }");
            }
        }
Beispiel #9
0
 public CollectionEntryListProperty(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, Relation rel, RelationEndRole endRole)
     : base(_host)
 {
     this.ctx = ctx;
     this.serializationList = serializationList;
     this.rel     = rel;
     this.endRole = endRole;
 }
Beispiel #10
0
        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 = relEnd.Navigator != null
                ? relEnd.Navigator.Name + Zetbox.API.Helper.ImplementationSuffix
                : null;
            bool inverseNavigatorIsList = false;
            bool notifyInverseCollection = true;

            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,
                notifyInverseCollection,
                eagerLoading,
                relDataTypeExportable,
                callGetterSetterEvents,
                false, // ObjRef with relation cannot be calculated
                false);
        }
Beispiel #11
0
 public ObjectListProperty(Arebis.CodeGeneration.IGenerationHost host,
                           IZetboxContext ctx,
                           Serialization.SerializationMembersList serializationList,
                           Relation rel,
                           RelationEndRole endRole)
     : this(host, ctx, serializationList, "name", "wrapperName", "wrapperClass", "exposedListType",
            rel, endRole, "positionPropertyName", "otherName", "referencedInterface")
 {
 }
Beispiel #12
0
 public ObjectListProperty(Arebis.CodeGeneration.IGenerationHost host,
     IZetboxContext ctx,
     Serialization.SerializationMembersList serializationList,
     Relation rel,
     RelationEndRole endRole)
     : this(host, ctx, serializationList, "name", "wrapperName", "wrapperClass", "exposedListType",
         rel, endRole, "positionPropertyName", "otherName", "referencedInterface")
 {
 }
        public CollectionEntryListProperty(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, Relation rel, RelationEndRole endRole)
            : base(_host)
        {
			this.ctx = ctx;
			this.serializationList = serializationList;
			this.rel = rel;
			this.endRole = endRole;

        }
Beispiel #14
0
        public static string GetRelationFkColumnName(this Relation rel, RelationEndRole endRole)
        {
            if (rel == null)
            {
                throw new ArgumentNullException("rel");
            }
            var relEnd = rel.GetEndFromRole(endRole);

            return("fk_" + relEnd.RoleName);
        }
Beispiel #15
0
        /// <summary>
        /// Returns the association name for the association from the given end to the CollectionEntry
        /// </summary>
        public static string GetRelationAssociationName(this Relation rel, RelationEndRole endRole)
        {
            if (rel == null)
            {
                throw new ArgumentNullException("rel");
            }
            RelationEnd relEnd = rel.GetEndFromRole(endRole);

            return(String.Format("FK_{0}_{1}_{2}_{3}", rel.A.RoleName, rel.Verb, rel.B.RoleName, relEnd.GetRole()));
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
 // TODO: Create new override
 public override IList <T> FetchRelation <T>(Guid relationId, RelationEndRole role, IDataObject parent)
 {
     CheckDisposed();
     if (parent == null)
     {
         return(this.GetPersistenceObjectQuery <T>().ToList());
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Beispiel #18
0
 /// <summary>Only implemented for the parent==null case.</summary>
 IList <T> IReadOnlyZetboxContext.FetchRelation <T>(Guid relId, RelationEndRole role, IDataObject parent)
 {
     if (parent == null)
     {
         CheckDisposed();
         //CheckInterfaceAssembly("T", typeof(T));
         return(GetPersistenceObjectQuery(_iftFactory(typeof(T))).Cast <T>().ToList());
     }
     else
     {
         throw new NotImplementedException();
     }
 }
 public override IServerCollectionHandler GetServerCollectionHandler(
     IReadOnlyZetboxContext ctx,
     InterfaceType aType,
     InterfaceType bType,
     RelationEndRole endRole)
 {
     if (ctx == null) throw new ArgumentNullException("ctx");
     return GetServerCollectionHandlerHelper(
         typeof(ServerCollectionHandler<,,,>),
         ctx.ToImplementationType(aType),
         ctx.ToImplementationType(bType),
         endRole);
 }
Beispiel #20
0
 public static void GetEndFromRole(Relation rel, MethodReturnEventArgs<RelationEnd> e, RelationEndRole role)
 {
     switch (role)
     {
         case RelationEndRole.A:
             e.Result = rel.A;
             break;
         case RelationEndRole.B:
             e.Result = rel.B;
             break;
         default:
             throw new ArgumentOutOfRangeException("role");
     }
 }
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
            IZetboxContext ctx,
            Templates.Serialization.SerializationMembersList serializationList,
            Relation rel, RelationEndRole endRole)
        {
            if (rel == null) { throw new ArgumentNullException("rel"); }

            RelationEnd relEnd = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            string backingCollectionType = RelationToBackingCollectionType(rel, otherEnd);

            Call(host, ctx, serializationList, rel, endRole, backingCollectionType);
        }
Beispiel #22
0
        public static RelationEnd GetOtherEndFromRole(this Relation rel, RelationEndRole role)
        {
            if (rel == null) { throw new ArgumentNullException("rel"); }

            switch (role)
            {
                case RelationEndRole.A:
                    return rel.B;
                case RelationEndRole.B:
                    return rel.A;
                default:
                    throw new ArgumentOutOfRangeException("role", String.Format("unknown RelationEndRole '{0}'", role));
            }
        }
Beispiel #23
0
        protected override void ApplyObjectReferenceProperty(Relation rel, RelationEndRole endRole, string propertyName)
        {
            RelationEnd relEnd   = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            // TODO: create/use ObjectReference*IMPLEMENTATION* instead (_fk* can already be made available)
            string moduleNamespace          = rel.Module.Namespace;
            string ownInterface             = moduleNamespace + "." + rel.GetRelationClassName() + ImplementationSuffix;
            string name                     = propertyName;
            string implName                 = propertyName + ImplementationPropertySuffix;
            string eventName                = "On" + name;
            string fkBackingName            = "_fk_" + name;
            string fkGuidBackingName        = "_fk_guid_" + name;
            string referencedInterface      = relEnd.Type.GetDataTypeString();
            string referencedImplementation = referencedInterface + ImplementationSuffix;
            string associationName          = rel.GetAssociationName();
            string targetRoleName           = otherEnd.RoleName;
            string positionPropertyName     = rel.NeedsPositionStorage(endRole)
                ? name + Zetbox.API.Helper.PositionSuffix
                : null;
            string inverseNavigatorName   = null; // do not care about inverse navigator
            bool   inverseNavigatorIsList = false;
            bool   eagerLoading           = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;
            bool   relDataTypeExportable  = rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable();
            bool   callGetterSetterEvents = false;

            Properties.ObjectReferencePropertyTemplate.Call(Host,
                                                            ctx,
                                                            MembersToSerialize,
                                                            moduleNamespace,
                                                            ownInterface,
                                                            name,
                                                            implName,
                                                            eventName,
                                                            fkBackingName,
                                                            fkGuidBackingName,
                                                            referencedInterface,
                                                            referencedImplementation,
                                                            associationName,
                                                            targetRoleName,
                                                            positionPropertyName,
                                                            inverseNavigatorName,
                                                            inverseNavigatorIsList,
                                                            eagerLoading,
                                                            relDataTypeExportable,
                                                            callGetterSetterEvents,
                                                            false,
                                                            false);
        }
Beispiel #24
0
 public ObjectListProperty(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, string name, string wrapperName, string wrapperClass, string exposedListType, Relation rel, RelationEndRole endRole, string positionPropertyName, string otherName, string referencedInterface)
     : base(_host)
 {
     this.ctx = ctx;
     this.serializationList = serializationList;
     this.name                 = name;
     this.wrapperName          = wrapperName;
     this.wrapperClass         = wrapperClass;
     this.exposedListType      = exposedListType;
     this.rel                  = rel;
     this.endRole              = endRole;
     this.positionPropertyName = positionPropertyName;
     this.otherName            = otherName;
     this.referencedInterface  = referencedInterface;
 }
Beispiel #25
0
 public override IServerCollectionHandler GetServerCollectionHandler(
     IZetboxContext ctx,
     InterfaceType aType,
     InterfaceType bType,
     RelationEndRole endRole)
 {
     if (ctx == null)
     {
         throw new ArgumentNullException("ctx");
     }
     return(GetServerCollectionHandlerHelper(
                typeof(NHibernateServerCollectionHandler <, , ,>),
                ctx.ToImplementationType(aType),
                ctx.ToImplementationType(bType),
                endRole));
 }
        public ObjectListProperty(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, string name, string wrapperName, string wrapperClass, string exposedListType, Relation rel, RelationEndRole endRole, string positionPropertyName, string otherName, string referencedInterface)
            : base(_host)
        {
			this.ctx = ctx;
			this.serializationList = serializationList;
			this.name = name;
			this.wrapperName = wrapperName;
			this.wrapperClass = wrapperClass;
			this.exposedListType = exposedListType;
			this.rel = rel;
			this.endRole = endRole;
			this.positionPropertyName = positionPropertyName;
			this.otherName = otherName;
			this.referencedInterface = referencedInterface;

        }
Beispiel #27
0
        public void Do1_1_RelationChange_FromNotNullable_To_Nullable(Relation rel, RelationEndRole role)
        {
            RelationEnd relEnd = rel.GetEndFromRole(role);
            RelationEnd otherEnd = rel.GetOtherEndFromRole(role);

            var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
            var colName = Construct.ForeignKeyColumnName(otherEnd);

            if (db.CheckColumnContainsNulls(tblName, colName))
            {
                Log.ErrorFormat("column '{0}.{1}' contains NULL values, cannot set NOT NULLABLE", tblName, colName);
            }
            else
            {
                db.AlterColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);
            }
        }
Beispiel #28
0
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
                                IZetboxContext ctx,
                                Templates.Serialization.SerializationMembersList serializationList,
                                Relation rel, RelationEndRole endRole)
        {
            if (rel == null)
            {
                throw new ArgumentNullException("rel");
            }

            RelationEnd relEnd   = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            string backingCollectionType = RelationToBackingCollectionType(rel, otherEnd);

            Call(host, ctx, serializationList, rel, endRole, backingCollectionType);
        }
Beispiel #29
0
 public CollectionEntryListProperty(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Serialization.SerializationMembersList serializationList, string name, string exposedCollectionInterface, string referencedInterface, string backingName, string backingCollectionType, string aSideType, string bSideType, string entryType, string providerCollectionType, Guid relId, RelationEndRole role, bool eagerLoading)
     : base(_host)
 {
     this.ctx = ctx;
     this.serializationList = serializationList;
     this.name = name;
     this.exposedCollectionInterface = exposedCollectionInterface;
     this.referencedInterface        = referencedInterface;
     this.backingName            = backingName;
     this.backingCollectionType  = backingCollectionType;
     this.aSideType              = aSideType;
     this.bSideType              = bSideType;
     this.entryType              = entryType;
     this.providerCollectionType = providerCollectionType;
     this.relId        = relId;
     this.role         = role;
     this.eagerLoading = eagerLoading;
 }
        public CollectionEntryListProperty(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Serialization.SerializationMembersList serializationList, string name, string exposedCollectionInterface, string referencedInterface, string backingName, string backingCollectionType, string aSideType, string bSideType, string entryType, string providerCollectionType, Guid relId, RelationEndRole role, bool eagerLoading)
            : base(_host)
        {
			this.ctx = ctx;
			this.serializationList = serializationList;
			this.name = name;
			this.exposedCollectionInterface = exposedCollectionInterface;
			this.referencedInterface = referencedInterface;
			this.backingName = backingName;
			this.backingCollectionType = backingCollectionType;
			this.aSideType = aSideType;
			this.bSideType = bSideType;
			this.entryType = entryType;
			this.providerCollectionType = providerCollectionType;
			this.relId = relId;
			this.role = role;
			this.eagerLoading = eagerLoading;

        }
Beispiel #31
0
        public static RelationEnd GetOtherEndFromRole(this Relation rel, RelationEndRole role)
        {
            if (rel == null)
            {
                throw new ArgumentNullException("rel");
            }

            switch (role)
            {
            case RelationEndRole.A:
                return(rel.B);

            case RelationEndRole.B:
                return(rel.A);

            default:
                throw new ArgumentOutOfRangeException("role", String.Format("unknown RelationEndRole '{0}'", role));
            }
        }
Beispiel #32
0
        public IList <T> FetchRelation <T>(Guid relationId, RelationEndRole role, IDataObject container) where T : class, IRelationEntry
        {
            List <IStreamable> auxObjects;
            var serverList = proxy.FetchRelation <T>(this, relationId, role, container, out auxObjects);

            foreach (IPersistenceObject obj in auxObjects)
            {
                this.AttachRespectingIsolationLevel(obj);
            }

            var result = new List <T>();

            foreach (IPersistenceObject obj in serverList)
            {
                var localobj = this.AttachRespectingIsolationLevel(obj);
                result.Add((T)localobj);
            }
            PlaybackNotifications();
            return(result);
        }
Beispiel #33
0
        protected IServerCollectionHandler GetServerCollectionHandlerHelper(
            Type collectionHandlerType,
            ImplementationType aType,
            ImplementationType bType,
            RelationEndRole endRole)
        {
            if (Object.ReferenceEquals(aType, null))
            {
                throw new ArgumentNullException("aType");
            }
            if (Object.ReferenceEquals(bType, null))
            {
                throw new ArgumentNullException("bType");
            }
            try
            {
                // dynamically translate generic types into provider-known types
                Type[] genericArgs;
                if (endRole == RelationEndRole.A)
                {
                    genericArgs = new Type[] { aType.Type, bType.Type, aType.Type, bType.Type };
                }
                else
                {
                    genericArgs = new Type[] { aType.Type, bType.Type, bType.Type, aType.Type };
                }

                Type resultType = collectionHandlerType.MakeGenericType(genericArgs);
                return((IServerCollectionHandler)Activator.CreateInstance(resultType));
            }
            catch (Exception ex)
            {
                var msg = String.Format(
                    "Failed to create IServerCollectionHandler for A=[{0}], B=[{1}], role=[{2}]",
                    aType,
                    bType,
                    endRole);
                Log.Error(msg, ex);
                throw;
            }
        }
Beispiel #34
0
        /// <summary>Only implemented for the parent==null case.</summary>
        IList <T> IReadOnlyZetboxContext.FetchRelation <T>(Guid relId, RelationEndRole endRole, IDataObject parent)
        {
            if (parent == null)
            {
                return(GetPersistenceObjectQuery(IftFactory(typeof(T))).Cast <T>().ToList());
            }
            else
            {
                // TODO: #1571 This method expects IF Types, but Impl types are passed
                switch (endRole)
                {
                case RelationEndRole.A:
                    return(GetPersistenceObjectQuery(GetImplementationType(typeof(T)).ToInterfaceType()).Cast <T>().Where(i => i.AObject == parent).ToList());

                case RelationEndRole.B:
                    return(GetPersistenceObjectQuery(GetImplementationType(typeof(T)).ToInterfaceType()).Cast <T>().Where(i => i.BObject == parent).ToList());

                default:
                    throw new NotImplementedException(String.Format("Unknown RelationEndRole [{0}]", endRole));
                }
            }
        }
Beispiel #35
0
        public static bool HasStorage(this Relation rel, RelationEndRole role)
        {
            if (rel == null)
            {
                throw new ArgumentNullException("rel");
            }

            if (rel.Storage == StorageType.Replicate)
            {
                throw new NotImplementedException();
            }

            RelationType type = rel.GetRelationType();

            // n:m has no storage on A or B
            return
                ((type == RelationType.one_n && rel.Storage == StorageType.MergeIntoA && role == RelationEndRole.A) ||
                 (type == RelationType.one_n && rel.Storage == StorageType.MergeIntoB && role == RelationEndRole.B) ||
                 (type == RelationType.one_one && rel.Storage == StorageType.Replicate) ||
                 (type == RelationType.one_one && rel.Storage == StorageType.MergeIntoA && role == RelationEndRole.A) ||
                 (type == RelationType.one_one && rel.Storage == StorageType.MergeIntoB && role == RelationEndRole.B));
        }
Beispiel #36
0
        public override IList <T> FetchRelation <T>(Guid relationId, RelationEndRole endRole, IDataObject parent)
        {
            CheckDisposed();
            if (parent == null)
            {
                return(this.GetPersistenceObjectQuery <T>().ToList());
            }
            else
            {
                switch (endRole)
                {
                case RelationEndRole.A:
                    return(GetPersistenceObjectQuery <T>().Where(i => i.AObject == parent).ToList());

                case RelationEndRole.B:
                    return(GetPersistenceObjectQuery <T>().Where(i => i.BObject == parent).ToList());

                default:
                    throw new NotImplementedException(String.Format("Unknown RelationEndRole [{0}]", endRole));
                }
            }
        }
Beispiel #37
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        /// <param name="ctx"></param>
        /// <param name="serializationList"></param>
        /// <param name="name">the name of the property to create</param>
        /// <param name="wrapperClass">the name of the wrapper class for wrapping the EntityCollection</param>
        /// <param name="exposedListType">which generic interface to use for the collection (IList or ICollection)</param>
        /// <param name="rel"></param>
        /// <param name="endRole"></param>
        /// <param name="positionPropertyName">the name of the position property for this list</param>
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
            IZetboxContext ctx,
            Serialization.SerializationMembersList serializationList,
            string name,
            string wrapperClass,
            string exposedListType,
            Relation rel,
            RelationEndRole endRole,
            string positionPropertyName)
        {
            if (rel == null) { throw new ArgumentNullException("rel"); }

            RelationEnd relEnd = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            string wrapperName = "_" + name;

            var otherName = otherEnd.Navigator == null ? relEnd.RoleName : otherEnd.Navigator.Name;

            string referencedInterface = otherEnd.Type.GetDataTypeString();

            Call(host, ctx, serializationList, name, wrapperName, wrapperClass, exposedListType, rel, endRole, positionPropertyName, otherName, referencedInterface);
        }
Beispiel #38
0
        public IEnumerable <IRelationEntry> GetCollectionEntries(
            Guid version,
            IZetboxContext ctx,
            Guid relId, RelationEndRole endRole,
            int parentId)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            var rel = ctx.FindPersistenceObject <Relation>(relId);
            //var relEnd = rel.GetEndFromRole(endRole);
            //var relOtherEnd = rel.GetOtherEnd(relEnd);
            var parent = ctx.Find(ctx.GetImplementationType(typeof(TParent)).ToInterfaceType(), parentId);
            var ceType = ctx.ToImplementationType(rel.GetEntryInterfaceType()).Type;

            var method = this.GetType().GetMethod("GetCollectionEntriesInternal", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            return((IEnumerable <IRelationEntry>)method
                   .MakeGenericMethod(ceType)
                   .Invoke(this, new object[] { parent, rel, endRole }));
        }
Beispiel #39
0
 public bool Is_N_M_RelationChange_FromNotIndexed_To_Indexed(Relation rel, RelationEndRole role)
 {
     var savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
     if (savedRel == null) return false;
     return rel.NeedsPositionStorage(role) && !savedRel.NeedsPositionStorage(role);
 }
Beispiel #40
0
        public static bool HasStorage(this Relation rel, RelationEndRole role)
        {
            if (rel == null) { throw new ArgumentNullException("rel"); }

            if (rel.Storage == StorageType.Replicate)
                throw new NotImplementedException();

            RelationType type = rel.GetRelationType();
            // n:m has no storage on A or B
            return
                   (type == RelationType.one_n && rel.Storage == StorageType.MergeIntoA && role == RelationEndRole.A)
                || (type == RelationType.one_n && rel.Storage == StorageType.MergeIntoB && role == RelationEndRole.B)
                || (type == RelationType.one_one && rel.Storage == StorageType.Replicate)
                || (type == RelationType.one_one && rel.Storage == StorageType.MergeIntoA && role == RelationEndRole.A)
                || (type == RelationType.one_one && rel.Storage == StorageType.MergeIntoB && role == RelationEndRole.B);
        }
Beispiel #41
0
        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));
        }
Beispiel #42
0
 protected virtual void ApplyCollectionEntryListTemplate(Relation rel, RelationEndRole endRole)
 {
     Properties.CollectionEntryListProperty.Call(Host, ctx,
         this.MembersToSerialize,
         rel, endRole);
 }
Beispiel #43
0
        protected override void ApplyObjectReferenceProperty(Relation rel, RelationEndRole endRole, string propertyName)
        {
            RelationEnd relEnd = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            // TODO: create/use ObjectReference*IMPLEMENTATION* instead (_fk* can already be made available)
            string moduleNamespace = rel.Module.Namespace;
            string ownInterface = moduleNamespace + "." + rel.GetRelationClassName() + ImplementationSuffix;
            string name = propertyName;
            string implName = propertyName + ImplementationPropertySuffix;
            string eventName = "On" + name;
            string fkBackingName = "_fk_" + name;
            string fkGuidBackingName = "_fk_guid_" + name;
            string referencedInterface = relEnd.Type.GetDataTypeString();
            string referencedImplementation = referencedInterface + ImplementationSuffix;
            string associationName = rel.GetAssociationName();
            string targetRoleName = otherEnd.RoleName;
            string positionPropertyName = rel.NeedsPositionStorage(endRole)
                ? name + Zetbox.API.Helper.PositionSuffix
                : null;
            string inverseNavigatorName = null; // do not care about inverse navigator
            bool inverseNavigatorIsList = false;
            bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;
            bool relDataTypeExportable = rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable();
            bool callGetterSetterEvents = false;

            Properties.ObjectReferencePropertyTemplate.Call(Host,
                ctx,
                MembersToSerialize,
                moduleNamespace,
                ownInterface,
                name,
                implName,
                eventName,
                fkBackingName,
                fkGuidBackingName,
                referencedInterface,
                referencedImplementation,
                associationName,
                targetRoleName,
                positionPropertyName,
                inverseNavigatorName,
                inverseNavigatorIsList,
                eagerLoading,
                relDataTypeExportable,
                callGetterSetterEvents,
                false,
                false);
        }
        public static void Call(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, string name, string exposedCollectionInterface, string referencedInterface, string backingName, string backingCollectionType, string aSideType, string bSideType, string entryType, string providerCollectionType, Guid relId, RelationEndRole role, bool eagerLoading, bool serializeRelationEntries, string entryProxyType, string inverseNavigatorName)
        {
            if (_host == null) { throw new global::System.ArgumentNullException("_host"); }

            _host.CallTemplate("Properties.CollectionEntryListProperty", ctx, serializationList, name, exposedCollectionInterface, referencedInterface, backingName, backingCollectionType, aSideType, bSideType, entryType, providerCollectionType, relId, role, eagerLoading, serializeRelationEntries, entryProxyType, inverseNavigatorName);
        }
Beispiel #45
0
        public static void Call(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Serialization.SerializationMembersList serializationList, string name, string exposedCollectionInterface, string referencedInterface, string backingName, string backingCollectionType, string aSideType, string bSideType, string entryType, string providerCollectionType, Guid relId, RelationEndRole role, bool eagerLoading)
        {
            if (_host == null)
            {
                throw new global::System.ArgumentNullException("_host");
            }

            _host.CallTemplate("Properties.CollectionEntryListProperty", ctx, serializationList, name, exposedCollectionInterface, referencedInterface, backingName, backingCollectionType, aSideType, bSideType, entryType, providerCollectionType, relId, role, eagerLoading);
        }
Beispiel #46
0
 public override IList <T> FetchRelation <T>(Guid relationId, RelationEndRole role, IDataObject parent)
 {
     throw new NotImplementedException();
 }
        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);
                    }
                }
            }
        }
Beispiel #48
0
 protected virtual void ApplyCollectionEntryListTemplate(Relation rel, RelationEndRole endRole)
 {
     Properties.CollectionEntryListProperty.Call(Host, ctx,
                                                 this.MembersToSerialize,
                                                 rel, endRole);
 }
Beispiel #49
0
        public static void NeedsPositionStorage(Relation rel, MethodReturnEventArgs<bool> e, RelationEndRole endRole)
        {
            if (rel == null)
            {
                throw new ArgumentNullException("rel");
            }
            if (rel.A == null)
            {
                throw new ArgumentNullException("rel", "rel.A is null");
            }
            if (rel.B == null)
            {
                throw new ArgumentNullException("rel", "rel.B is null");
            }

            e.Result = ((rel.Storage == StorageType.MergeIntoA && RelationEndRole.A == endRole && rel.A.HasPersistentOrder)
                || (rel.Storage == StorageType.MergeIntoB && RelationEndRole.B == endRole && rel.B.HasPersistentOrder)
                || (rel.Storage == StorageType.Replicate
                    && (
                        (rel.A.HasPersistentOrder && RelationEndRole.A == endRole)
                        || (rel.B.HasPersistentOrder && RelationEndRole.B == endRole))
                    )
                || (rel.Storage == StorageType.Separate && (rel.A.HasPersistentOrder || rel.B.HasPersistentOrder))
                );
        }
Beispiel #50
0
        public static void Call(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, string name, string wrapperName, string wrapperClass, string exposedListType, Relation rel, RelationEndRole endRole, string positionPropertyName, string otherName, string referencedInterface)
        {
            if (_host == null)
            {
                throw new global::System.ArgumentNullException("_host");
            }

            _host.CallTemplate("Properties.ObjectListProperty", ctx, serializationList, name, wrapperName, wrapperClass, exposedListType, rel, endRole, positionPropertyName, otherName, referencedInterface);
        }
Beispiel #51
0
        public IEnumerable <T> FetchRelation <T>(IZetboxContext ctx, Guid relationId, RelationEndRole role, IDataObject parent, out List <IStreamable> auxObjects)
            where T : class, IRelationEntry
        {
            var ifType      = ctx.GetInterfaceType(parent);
            var ticks       = _perfCounter.IncrementFetchRelation(ifType);
            int resultCount = 0;

            try
            {
                // TODO: could be implemented in generated properties
                if (parent.ObjectState == DataObjectState.New)
                {
                    auxObjects = new List <IStreamable>();
                    return(new List <T>());
                }

                IEnumerable <T>    result        = null;
                List <IStreamable> tmpAuxObjects = null;
                byte[]             bytes         = null;

                MakeRequest(() =>
                {
                    bytes = _service.FetchRelation(ZetboxGeneratedVersionAttribute.Current, relationId, (int)role, parent.ID);
                });
                using (MemoryStream s = new MemoryStream(bytes))
                    using (var sr = _readerFactory(new BinaryReader(s)))
                    {
                        result = ReceiveObjects(ctx, sr, out tmpAuxObjects).Cast <T>();
                    }
                resultCount = result.Count();

                auxObjects = tmpAuxObjects;
                return(result);
            }
            finally
            {
                _perfCounter.DecrementFetchRelation(ifType, resultCount, ticks);
            }
        }
Beispiel #52
0
 public bool Is1_1_RelationChange_FromNullable_To_NotNullable(Relation rel, RelationEndRole role)
 {
     Relation savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
     if (savedRel == null)
     {
         return false;
     }
     return savedRel.GetOtherEndFromRole(role).IsNullable() && !rel.GetOtherEndFromRole(role).IsNullable()
         && ((rel.Storage == StorageType.MergeIntoA && role == RelationEndRole.A)
             || (rel.Storage == StorageType.MergeIntoB && role == RelationEndRole.B)
             || (rel.Storage == StorageType.Replicate));
 }
Beispiel #53
0
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
                                IZetboxContext ctx,
                                Serialization.SerializationMembersList serializationList,
                                string ownInterface,
                                string name,
                                string referencedInterface,
                                Relation rel,
                                RelationEndRole endRole,
                                bool callGetterSetterEvents,
                                bool updateInverseNavigator,
                                string assocNameSuffix)
        {
            // TODO: split off relation expansion in own Call() method
            RelationEnd relEnd   = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            string moduleNamespace = rel.Module.Namespace;
            string implName        = name + Zetbox.API.Helper.ImplementationSuffix;
            string eventName       = "On" + name;

            string fkBackingName     = "_fk_" + name;
            string fkGuidBackingName = "_fk_guid_" + name;

            string referencedImplementation = referencedInterface
                                              + host.Settings["extrasuffix"] + Zetbox.API.Helper.ImplementationSuffix;
            string associationName = rel.GetAssociationName() + assocNameSuffix;
            string targetRoleName  = otherEnd.RoleName;

            string positionPropertyName = rel.NeedsPositionStorage(endRole)
                ? Construct.ListPositionPropertyName(relEnd)
                : null;

            string inverseNavigatorName = updateInverseNavigator && otherEnd.Navigator != null
                ? otherEnd.Navigator.Name
                : null;
            bool inverseNavigatorIsList = otherEnd.Navigator != null && otherEnd.Navigator.GetIsList();

            bool eagerLoading          = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;
            bool relDataTypeExportable = rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable();

            Call(host,
                 ctx,
                 serializationList,
                 moduleNamespace,
                 ownInterface,
                 name,
                 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 Call(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, string name, string wrapperName, string wrapperClass, string exposedListType, Relation rel, RelationEndRole endRole, string positionPropertyName, string otherName, string referencedInterface)
        {
            if (_host == null) { throw new global::System.ArgumentNullException("_host"); }

            _host.CallTemplate("Properties.ObjectListProperty", ctx, serializationList, name, wrapperName, wrapperClass, exposedListType, rel, endRole, positionPropertyName, otherName, referencedInterface);
        }
Beispiel #55
0
        public void Do1_1_RelationChange_FromNullable_To_NotNullable(Relation rel, RelationEndRole role)
        {
            RelationEnd relEnd = rel.GetEndFromRole(role);
            RelationEnd otherEnd = rel.GetOtherEndFromRole(role);

            var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
            var colName = Construct.ForeignKeyColumnName(otherEnd);

            db.AlterColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);
        }
Beispiel #56
0
 public static string GetRelationFkColumnName(this Relation rel, RelationEndRole endRole)
 {
     if (rel == null) { throw new ArgumentNullException("rel"); }
     var relEnd = rel.GetEndFromRole(endRole);
     return Construct.ForeignKeyColumnName(relEnd);
 }
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
            IZetboxContext ctx,
            Serialization.SerializationMembersList serializationList,
            string ownInterface,
            string name,
            string referencedInterface,
            Relation rel,
            RelationEndRole endRole,
            bool callGetterSetterEvents,
            bool updateInverseNavigator,
            string assocNameSuffix)
        {
            // TODO: split off relation expansion in own Call() method
            RelationEnd relEnd = rel.GetEndFromRole(endRole);
            RelationEnd otherEnd = rel.GetOtherEnd(relEnd);

            string moduleNamespace = rel.Module.Namespace;
            string implName = name + Zetbox.API.Helper.ImplementationSuffix;
            string eventName = "On" + name;

            string fkBackingName = "_fk_" + name;
            string fkGuidBackingName = "_fk_guid_" + name;

            string referencedImplementation = referencedInterface
                + host.Settings["extrasuffix"] + Zetbox.API.Helper.ImplementationSuffix;
            string associationName = rel.GetAssociationName() + assocNameSuffix;
            string targetRoleName = otherEnd.RoleName;

            string positionPropertyName = rel.NeedsPositionStorage(endRole)
                ? Construct.ListPositionPropertyName(relEnd)
                : null;

            string inverseNavigatorName = updateInverseNavigator && otherEnd.Navigator != null
                ? otherEnd.Navigator.Name
                : null;
            bool inverseNavigatorIsList = otherEnd.Navigator != null && otherEnd.Navigator.GetIsList();

            bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;
            bool relDataTypeExportable = rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable();

            Call(host,
                ctx,
                serializationList,
                moduleNamespace,
                ownInterface,
                name,
                implName,
                eventName,
                fkBackingName,
                fkGuidBackingName,
                referencedInterface,
                referencedImplementation,
                associationName,
                targetRoleName,
                positionPropertyName,
                inverseNavigatorName,
                inverseNavigatorIsList,
                eagerLoading,
                relDataTypeExportable,
                callGetterSetterEvents,
                false, // ObjRef with relation cannot be calculated
                false);
        }
Beispiel #58
0
        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!");
            }
        }
Beispiel #59
0
 //// Helper method which is only called by reflection from GetCollectionEntries
 private IEnumerable <IRelationEntry> GetCollectionEntriesInternal <IMPL>(TParent parent, Relation rel, RelationEndRole endRole)
     where IMPL : BaseMemoryPersistenceObject
 {
     return(MagicCollectionFactory.WrapAsCollection <IRelationEntry>(parent.GetPrivatePropertyValue <object>(rel.GetEndFromRole(endRole).Navigator.Name)).ToList());
 }
        public static void Call(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Zetbox.Generator.Templates.Serialization.SerializationMembersList serializationList, Relation rel, RelationEndRole endRole)
        {
            if (_host == null) { throw new global::System.ArgumentNullException("_host"); }

            _host.CallTemplate("Properties.CollectionEntryListProperty", ctx, serializationList, rel, endRole);
        }