Exemplo n.º 1
0
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
                                IZetboxContext ctx,
                                Templates.Serialization.SerializationMembersList serializationList,
                                ObjectReferenceProperty prop, bool callGetterSetterEvents,
                                bool updateInverseNavigator)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }

            string name                = prop.Name;
            string ownInterface        = prop.ObjectClass.GetDataTypeString();
            string referencedInterface = String.Format(
                "{0}.{1}",
                prop.GetReferencedObjectClass().Module.Namespace,
                prop.GetReferencedObjectClass().Name);

            var rel             = RelationExtensions.Lookup(ctx, prop);
            var endRole         = rel.GetEnd(prop).GetRole();
            var assocNameSuffix = String.Empty;

            Call(host, ctx, serializationList,
                 ownInterface, name, referencedInterface, rel, endRole, callGetterSetterEvents, updateInverseNavigator, assocNameSuffix);
        }
Exemplo n.º 2
0
        public static bool HasPersistentOrder(this Property prop)
        {
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }

            bool result = false;

            if (prop is ObjectReferenceProperty)
            {
                var p        = (ObjectReferenceProperty)prop;
                var rel      = RelationExtensions.Lookup(p.Context, p);
                var relEnd   = rel.GetEnd(p);
                var otherEnd = rel.GetOtherEnd(relEnd);

                if (rel.NeedsPositionStorage(otherEnd.GetRole()))
                {
                    result = true;
                }
            }
            else if (prop is ValueTypeProperty)
            {
                result = ((ValueTypeProperty)prop).HasPersistentOrder;
            }
            else if (prop is CompoundObjectProperty)
            {
                result = ((CompoundObjectProperty)prop).HasPersistentOrder;
            }

            return(result);
        }
Exemplo n.º 3
0
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
                                IZetboxContext ctx,
                                Serialization.SerializationMembersList serializationList,
                                ObjectReferenceProperty prop)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }
            if (!prop.IsList())
            {
                throw new ArgumentOutOfRangeException("prop", "prop must be a List-valued property");
            }

            string name            = prop.Name;
            string wrapperClass    = "OneNRelationList";
            var    rel             = RelationExtensions.Lookup(ctx, prop);
            var    relEnd          = rel.GetEnd(prop);
            var    otherEnd        = rel.GetOtherEnd(relEnd);
            var    exposedListType = rel.NeedsPositionStorage(otherEnd.GetRole()) ? "IList" : "ICollection";
            // the name of the position property
            var positionPropertyName = rel.NeedsPositionStorage(otherEnd.GetRole()) ? Construct.ListPositionPropertyName(otherEnd) : String.Empty;

            Call(host, ctx, serializationList, name, wrapperClass, exposedListType, rel, relEnd.GetRole(), positionPropertyName);
        }
Exemplo n.º 4
0
        public static void Call(IGenerationHost host, IZetboxContext ctx,
                                DataType dataType)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (dataType == null)
            {
                throw new ArgumentNullException("dataType");
            }

            var props = dataType
                        .Properties
                        .OfType <ObjectReferenceProperty>()
                        .OrderBy(p => p.Name)
                        .Where(p =>
            {
                Relation rel = RelationExtensions.Lookup(ctx, p);
                //RelationEnd relEnd = rel.GetEnd(p);

                return((rel.Storage == StorageType.MergeIntoA && rel.A.Navigator == p) ||
                       (rel.Storage == StorageType.MergeIntoB && rel.B.Navigator == p));
            })
                        .Select(p => new UpdateParentTemplateParams()
            {
                PropertyName = p.Name,
                IfType       = string.Format("{0}.{1}", p.GetReferencedObjectClass().Module.Namespace, p.GetReferencedObjectClass().Name)
            })
                        .ToList();

            host.CallTemplate("ObjectClasses.UpdateParentTemplate",
                              props);
        }
Exemplo n.º 5
0
        private IEnumerable <KeyValuePair <string, string> > GetPersistentInitialisations()
        {
            var orps = this.ObjectClass
                       .Properties
                       .OfType <ObjectReferenceProperty>()
                       .Where(orp => orp.IsList())
                       .Select(orp =>
            {
                var type     = orp.GetElementTypeString();
                Relation rel = RelationExtensions.Lookup(ctx, orp);
                if (rel.Storage == StorageType.Separate)
                {
                    type = rel.GetRelationFullName() + ImplementationSuffix + "." + rel.GetRelationClassName() + "Proxy";
                }
                else
                {
                    type += ImplementationSuffix + "." + orp.GetReferencedObjectClass().Name + "Proxy";
                }
                return(new KeyValuePair <string, string>(orp.Name, String.Format("new Collection<{0}>()", type)));
            });

            var cops = this.ObjectClass
                       .Properties
                       .OfType <CompoundObjectProperty>()
                       .Where(cop => cop.IsList)
                       .Select(cop => new KeyValuePair <string, string>(cop.Name, String.Format("new Collection<{0}.{1}{2}.{1}Proxy>()", cop.Module.Namespace, cop.GetCollectionEntryClassName(), ImplementationSuffix)));

            var vtps = this.ObjectClass
                       .Properties
                       .OfType <ValueTypeProperty>()
                       .Where(vtp => vtp.IsList)
                       .Select(vtp => new KeyValuePair <string, string>(vtp.Name, String.Format("new Collection<{0}.{1}{2}.{1}Proxy>()", vtp.Module.Namespace, vtp.GetCollectionEntryClassName(), ImplementationSuffix)));

            return(orps.Concat(cops).Concat(vtps).OrderBy(pair => pair.Key));
        }
Exemplo n.º 6
0
        protected override void ApplyObjectReferenceListTemplate(ObjectReferenceProperty prop)
        {
            var rel = RelationExtensions.Lookup(ctx, prop);

            var relEnd = rel.GetEnd(prop);

            //var otherEnd = rel.GetOtherEnd(relEnd);

            // without navigator, there should be no property
            if (relEnd.Navigator == null)
            {
                return;
            }

            switch ((StorageType)rel.Storage)
            {
            case StorageType.MergeIntoA:
            case StorageType.MergeIntoB:
            case StorageType.Replicate:
                // simple and direct reference
                this.WriteLine("        // object list property");
                ApplyObjectListPropertyTemplate(prop);
                break;

            case StorageType.Separate:
                this.WriteLine("        // collection entry list property");
                ApplyCollectionEntryListTemplate(prop);
                break;

            default:
                throw new NotImplementedException("unknown StorageHint for ObjectReferenceProperty[IsList == true]");
            }
        }
Exemplo n.º 7
0
        protected virtual void ApplyCollectionEntryListTemplate(ObjectReferenceProperty prop)
        {
            var rel    = RelationExtensions.Lookup(ctx, prop);
            var relEnd = rel.GetEnd(prop);

            Properties.CollectionEntryListProperty.Call(Host, ctx,
                                                        this.MembersToSerialize,
                                                        rel, relEnd.GetRole());
        }
Exemplo n.º 8
0
        public static void Call(Arebis.CodeGeneration.IGenerationHost host,
                                IZetboxContext ctx,
                                Templates.Serialization.SerializationMembersList serializationList,
                                ObjectReferenceProperty prop)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }
            if (!prop.IsList())
            {
                throw new ArgumentOutOfRangeException("prop", "prop must be a List-valued property");
            }

            var rel      = RelationExtensions.Lookup(ctx, prop);
            var relEnd   = rel.GetEnd(prop);
            var otherEnd = rel.GetOtherEnd(relEnd);

            string name = prop.Name;

            // whether or not the collection will be eagerly loaded
            bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;

            string wrapperName  = "_" + name;
            string wrapperClass = "OneNRelationList";

            var exposedListType = otherEnd.HasPersistentOrder ? "IList" : "ICollection";
            // the name of the position property
            var positionPropertyName = rel.NeedsPositionStorage(otherEnd.GetRole()) ? Construct.ListPositionPropertyName(otherEnd) : String.Empty;
            var otherName            = otherEnd.Navigator == null ? relEnd.RoleName : otherEnd.Navigator.Name;
            var referencedInterface  = otherEnd.Type.GetDataTypeString();
            var referencedProxy      = Mappings.ObjectClassHbm.GetProxyTypeReference(otherEnd.Type, host.Settings);

            Call(host, ctx, serializationList, name, eagerLoading, wrapperName, wrapperClass, exposedListType, positionPropertyName, otherName, referencedInterface, referencedProxy);
        }
Exemplo n.º 9
0
        protected override void ApplyObjectReferenceListTemplate(ObjectReferenceProperty prop)
        {
            // TODO: move debugging output into Templates
            this.WriteLine("    /*");
            RelationDebugTemplate.Call(Host, ctx, Zetbox.App.Extensions.RelationExtensions.Lookup(ctx, prop));
            this.WriteLine("    */");

            var rel = RelationExtensions.Lookup(ctx, prop);

            var relEnd   = rel.GetEnd(prop);
            var otherEnd = rel.GetOtherEnd(relEnd);

            // without navigator, there should be no property
            if (relEnd.Navigator == null)
            {
                return;
            }

            switch ((StorageType)rel.Storage)
            {
            case StorageType.MergeIntoA:
            case StorageType.MergeIntoB:
            case StorageType.Replicate:
                // simple and direct reference
                this.WriteLine("        // object list property");
                base.ApplyObjectReferenceListTemplate(relEnd.Navigator as ObjectReferenceProperty);
                break;

            case StorageType.Separate:
                this.WriteLine("        // collection reference property");
                ApplyCollectionEntryListTemplate(rel, relEnd.GetRole());
                break;

            default:
                throw new NotImplementedException("unknown StorageHint for ObjectReferenceProperty[IsList == true]");
            }
        }
Exemplo n.º 10
0
        private IEnumerable <KeyValuePair <string, string> > GetPersistentProperties()
        {
            var relationPosProperties = ctx.GetQuery <RelationEnd>()
                                        .Where(relEnd => relEnd.Type == this.ObjectClass)
                                        .ToList()
                                        .Where(relEnd => relEnd.Parent.NeedsPositionStorage(relEnd.GetRole()))
                                        .Select(relEnd => new KeyValuePair <string, string>("int?", relEnd.RoleName + Zetbox.API.Helper.PositionSuffix));

            // Look for relations where we have no navigator where the storage should be
            // there we need to create navigators to map them with NHibernate
            //var relationProperties = ctx.GetQuery<Relation>()
            //    .Where(rel => rel.A.Multiplicity == Multiplicity.One && rel.B.Multiplicity == Multiplicity.One
            //        && ((rel.A.Type == this.ObjectClass && rel.B.Navigator == null && rel.Storage == StorageType.MergeIntoB)
            //            || (rel.B.Type == this.ObjectClass && rel.A.Navigator == null && rel.Storage == StorageType.MergeIntoA)))
            //    .ToList()
            //    .Select(rel => rel.Storage == StorageType.MergeIntoA
            //        ? new KeyValuePair<string, string>(rel.B.Type.Module.Namespace + "." + rel.B.Type, rel.A.RoleName + ImplementationPropertySuffix)
            //        : new KeyValuePair<string, string>(rel.A.Type.Module.Namespace + "." + rel.A.Type, rel.B.RoleName + ImplementationPropertySuffix));

            var valuePosProperties = this.ObjectClass
                                     .Properties
                                     .OfType <ValueTypeProperty>()
                                     .Where(p => p.IsList)
                                     .Select(p => new KeyValuePair <string, string>("int?", p.Name + Zetbox.API.Helper.PositionSuffix));

            var compoundPosProperties = this.ObjectClass
                                        .Properties
                                        .OfType <CompoundObjectProperty>()
                                        .Where(p => p.IsList)
                                        .Select(p => new KeyValuePair <string, string>("int?", p.Name + Zetbox.API.Helper.PositionSuffix));

            var enumPosProperties = this.ObjectClass
                                    .Properties
                                    .OfType <EnumerationProperty>()
                                    .Where(p => p.IsList)
                                    .Select(p => new KeyValuePair <string, string>("int?", p.Name + Zetbox.API.Helper.PositionSuffix));

            var securityProperties = NeedsRightsTable()
                ? new[] { new KeyValuePair <string, string>("ICollection<" + Construct.SecurityRulesClassName(this.ObjectClass as ObjectClass) + ImplementationSuffix + ">", "SecurityRightsCollectionImpl") }
                : new KeyValuePair <string, string> [0];

            return(this.ObjectClass
                   .Properties
                   .Select(prop =>
            {
                var type = prop.GetElementTypeString();
                var orp = prop as ObjectReferenceProperty;

                // object references have to be translated to internal proxy interfaces
                if (orp != null)
                {
                    Relation rel = RelationExtensions.Lookup(ctx, orp);
                    if (rel.Storage == StorageType.Separate)
                    {
                        type = rel.GetRelationFullName() + ImplementationSuffix + "." + rel.GetRelationClassName() + "Proxy";
                    }
                    else
                    {
                        type += ImplementationSuffix + "." + orp.GetReferencedObjectClass().Name + "Proxy";
                    }
                    if (orp.IsList())
                    {
                        // always hold as collection, the wrapper has to translate/order the elements
                        type = "ICollection<" + type + ">";
                    }
                }
                else
                {
                    var ceClassName = prop.GetCollectionEntryClassName();
                    var ceCollectionType = String.Format("ICollection<{0}.{1}{2}.{1}Proxy>",
                                                         prop.GetCollectionEntryNamespace(),
                                                         ceClassName,
                                                         ImplementationSuffix);
                    var cop = prop as CompoundObjectProperty;
                    if (cop != null)
                    {
                        if (cop.IsList)
                        {
                            type = ceCollectionType;
                        }
                        else
                        {
                            type += ImplementationSuffix;
                        }
                    }
                    else
                    {
                        var vtp = prop as ValueTypeProperty;
                        if (vtp != null && vtp.IsList)
                        {
                            type = ceCollectionType;
                        }
                    }
                }
                return new KeyValuePair <string, string>(type, prop.Name);
            })
                   .Concat(relationPosProperties)
                   //.Concat(relationProperties)
                   .Concat(valuePosProperties)
                   .Concat(compoundPosProperties)
                   .Concat(enumPosProperties)
                   .OrderBy(kv => kv.Value)
                   // always add at the end
                   .Concat(securityProperties)
                   .Where(kv => kv.Key != null));
        }