Exemplo n.º 1
0
        public override void Generate()
        {
#line 34 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            this.WriteObjects("\r\n");
            this.WriteObjects("        public override void ApplyChangesFrom(", otherInterface, " obj)\r\n");
            this.WriteObjects("        {\r\n");
            this.WriteObjects("            base.ApplyChangesFrom(obj);\r\n");
            this.WriteObjects("            var other = (", clsName, ")obj;\r\n");
            this.WriteObjects("            var otherImpl = (", implName, ")obj;\r\n");
            this.WriteObjects("            var me = (", clsName, ")this;\r\n");
            this.WriteObjects("\r\n");
#line 42 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            foreach (var prop in cls.Properties.OfType <ValueTypeProperty>().Where(p => !p.IsCalculated && !p.IsList).OrderBy(p => p.Name))
            {
#line 43 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                this.WriteObjects("            me.", prop.Name, " = other.", prop.Name, ";\r\n");
#line 44 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            }
#line 45 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            foreach (var prop in cls.Properties.OfType <CompoundObjectProperty>().Where(p => !p.IsList /* && !p.IsCalculated */).OrderBy(p => p.Name))
            {
#line 46 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                this.WriteObjects("            if (me.", prop.Name, " == null && other.", prop.Name, " != null) {\r\n");
                this.WriteObjects("                me.", prop.Name, " = (", prop.GetElementTypeString(), ")other.", prop.Name, ".Clone();\r\n");
                this.WriteObjects("            } else if (me.", prop.Name, " != null && other.", prop.Name, " == null) {\r\n");
                this.WriteObjects("                me.", prop.Name, " = null;\r\n");
                this.WriteObjects("            } else if (me.", prop.Name, " != null && other.", prop.Name, " != null) {\r\n");
                this.WriteObjects("                me.", prop.Name, ".ApplyChangesFrom(other.", prop.Name, ");\r\n");
                this.WriteObjects("            }\r\n");
#line 53 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            }
#line 54 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            foreach (var prop in cls.Properties.OfType <ObjectReferenceProperty>().Where(p => !p.IsList()).OrderBy(p => p.Name))
            {
                if (prop.RelationEnd.HasPersistentOrder)
                {
                    var positionPropertyName = Construct.ListPositionPropertyName(prop.RelationEnd);

#line 58 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    this.WriteObjects("            this.", positionPropertyName, " = otherImpl.", positionPropertyName, ";\r\n");
#line 59 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                }
#line 60 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                this.WriteObjects("            this._fk_", prop.Name, " = otherImpl._fk_", prop.Name, ";\r\n");
#line 61 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            }
#line 62 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            this.WriteObjects("        }\r\n");
        }
Exemplo n.º 2
0
        protected virtual void ApplyPropertyMappings()
        {
            var relevantRelations = cls.GetRelations() // Managed by a cache
                                    .Where(r => (r.A.Type.ID == cls.ID && r.Storage == StorageType.MergeIntoA) ||
                                           (r.B.Type.ID == cls.ID && r.Storage == StorageType.MergeIntoB))
                                    .ToList()
                                    .OrderBy(r => r.GetAssociationName());

            foreach (var rel in relevantRelations)
            {
                string propertyName;
                string columnName;

                if (rel.A.Type == cls && rel.NeedsPositionStorage(RelationEndRole.A) && rel.A.Navigator != null)
                {
                    propertyName = Construct.ListPositionPropertyName(rel.A);
                    columnName   = Construct.ListPositionColumnName(rel.B);
                    this.WriteLine("<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", propertyName, columnName);
                }

                if (rel.B.Type == cls && rel.NeedsPositionStorage(RelationEndRole.B) && rel.B.Navigator != null)
                {
                    propertyName = Construct.ListPositionPropertyName(rel.B);
                    columnName   = Construct.ListPositionColumnName(rel.A);
                    this.WriteLine("<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", propertyName, columnName);
                }
            }

            foreach (var prop in cls.Properties.OfType <ValueTypeProperty>().Where(p => !p.IsList).OrderBy(p => p.Name))
            {
                ModelMslEntityTypeMappingScalarProperty.Call(Host, ctx, prop, prop.Name, String.Empty);
            }

            foreach (var prop in cls.Properties.OfType <CompoundObjectProperty>().Where(p => !p.IsList).OrderBy(p => p.Name))
            {
                ModelMslEntityTypeMappingComplexProperty.Call(Host, ctx, prop, prop.Name, String.Empty);
            }
        }
Exemplo n.º 3
0
        public override void Generate()
        {
#line 34 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
            this.WriteObjects("        #region ", this.GetType(), "\r\n");
#line 36 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
            var properties = cls.Properties.OrderBy(p => p.Name).ToList();
            var rels       = cls.GetRelations()
                             .OrderBy(i => i.A.RoleName).ThenBy(i => i.Verb).ThenBy(i => i.B.RoleName)
                             .OrderBy(i => i.A.Type.Name).ThenBy(i => i.B.Type.Name)
                             .ThenBy(i => i.ExportGuid)
                             .ToList();

            if (properties.Count > 0 || rels.Count > 0)
            {
#line 46 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                this.WriteObjects("        private static readonly object _propertiesLock = new object();\r\n");
                this.WriteObjects("        private static System.ComponentModel.PropertyDescriptor[] _properties;\r\n");
                this.WriteObjects("\r\n");
                this.WriteObjects("        private void _InitializePropertyDescriptors(Func<IFrozenContext> lazyCtx)\r\n");
                this.WriteObjects("        {\r\n");
                this.WriteObjects("            if (_properties != null) return;\r\n");
                this.WriteObjects("            lock (_propertiesLock)\r\n");
                this.WriteObjects("            {\r\n");
                this.WriteObjects("                // recheck for a lost race after aquiring the lock\r\n");
                this.WriteObjects("                if (_properties != null) return;\r\n");
                this.WriteObjects("\r\n");
                this.WriteObjects("                _properties = new System.ComponentModel.PropertyDescriptor[] {\r\n");
#line 59 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                foreach (var property in properties)
                {
                    string propertyName = property.Name;
                    if (property.IsAssociation() && !property.IsObjectReferencePropertySingle())
                    {
#line 65 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        this.WriteObjects("                    // property.IsAssociation() && !property.IsObjectReferencePropertySingle()\r\n");
                        this.WriteObjects("                    new ", propertyDescriptorName, "<", ifName, ", ", property.GetPropertyTypeString(), ">(\r\n");
                        this.WriteObjects("                        lazyCtx,\r\n");
                        this.WriteObjects("                        new Guid(\"", property.ExportGuid, "\"),\r\n");
                        this.WriteObjects("                        \"", propertyName, "\",\r\n");
                        this.WriteObjects("                        null,\r\n");
                        this.WriteObjects("                        obj => obj.", propertyName, ",\r\n");
                        this.WriteObjects("                        null, // lists are read-only properties\r\n");
                        this.WriteObjects("                        obj => On", propertyName, "_IsValid), \r\n");
#line 74 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                    }
                    else if (property is CalculatedObjectReferenceProperty)
                    {
#line 75 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        this.WriteObjects("                    // property is CalculatedObjectReferenceProperty\r\n");
                        this.WriteObjects("                    new ", propertyDescriptorName, "<", ifName, ", ", property.GetPropertyTypeString(), ">(\r\n");
                        this.WriteObjects("                        lazyCtx,\r\n");
                        this.WriteObjects("                        new Guid(\"", property.ExportGuid, "\"),\r\n");
                        this.WriteObjects("                        \"", propertyName, "\",\r\n");
                        this.WriteObjects("                        null,\r\n");
                        this.WriteObjects("                        obj => obj.", propertyName, ",\r\n");
                        this.WriteObjects("                        null, // CalculatedObjectReferenceProperty is a read-only property\r\n");
                        this.WriteObjects("						null), // no constraints on calculated properties \r\n");
#line 84 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                    }
                    else
                    {
#line 85 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        var isReadonly = (property is ValueTypeProperty) && ((ValueTypeProperty)property).IsCalculated;
#line 86 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        this.WriteObjects("                    // else\r\n");
                        this.WriteObjects("                    new ", propertyDescriptorName, "<", ifName, ", ", property.GetPropertyTypeString(), ">(\r\n");
                        this.WriteObjects("                        lazyCtx,\r\n");
                        this.WriteObjects("                        new Guid(\"", property.ExportGuid, "\"),\r\n");
                        this.WriteObjects("                        \"", propertyName, "\",\r\n");
                        this.WriteObjects("                        null,\r\n");
                        this.WriteObjects("                        obj => obj.", propertyName, ",\r\n");
#line 93 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        if (isReadonly)
                        {
#line 94 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                            this.WriteObjects("                        null, // calculated property\r\n");
                            this.WriteObjects("						null), // no constraints on calculated properties\r\n");
#line 96 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        }
                        else
                        {
#line 97 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                            this.WriteObjects("                        (obj, val) => obj.", propertyName, " = val,\r\n");
                            this.WriteObjects("						obj => On", propertyName, "_IsValid), \r\n");
#line 99 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        }
#line 100 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                    }
#line 101 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                }
#line 102 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                if ("Frozen".Equals(Settings["extrasuffix"]))
#line 103 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                {
#line 104 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                    this.WriteObjects("                    // skipping position columns for frozen context (not implemented)\r\n");
#line 105 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                }
                else
                {
#line 106 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                    this.WriteObjects("                    // position columns\r\n");
#line 108 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                    foreach (var rel in rels.Where(r => r.GetRelationType() == RelationType.one_n))
                    {
                        // only show debugging if there actually is an position column
                        if ((rel.A.Type == cls && rel.A.HasPersistentOrder) ||
                            (rel.B.Type == cls && rel.B.HasPersistentOrder))
                        {
#line 115 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                            this.WriteObjects("                    // rel: ", rel.A.RoleName, " ", rel.Verb, " ", rel.B.RoleName, " (", rel.ExportGuid, ")\r\n");
#line 117 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        }
                        if (rel.A.Type == cls && rel.A.HasPersistentOrder)
                        {
                            var posColumnName = Construct.ListPositionPropertyName(rel.A);

#line 122 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                            this.WriteObjects("                    // rel.A.Type == cls && rel.A.HasPersistentOrder\r\n");
                            this.WriteObjects("                    new ", propertyDescriptorName, "<", implName, ", int?>(\r\n");
                            this.WriteObjects("                        lazyCtx,\r\n");
                            this.WriteObjects("                        null,\r\n");
                            this.WriteObjects("                        \"", posColumnName, "\",\r\n");
                            this.WriteObjects("                        null,\r\n");
                            this.WriteObjects("                        obj => obj.", posColumnName, ",\r\n");
                            this.WriteObjects("                        (obj, val) => obj.", posColumnName, " = val,\r\n");
                            this.WriteObjects("						null),\r\n");
#line 132 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        }

                        if (rel.B.Type == cls && rel.B.HasPersistentOrder)
                        {
                            var posColumnName = Construct.ListPositionPropertyName(rel.B);

#line 138 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                            this.WriteObjects("                    // rel.B.Type == cls && rel.B.HasPersistentOrder\r\n");
                            this.WriteObjects("                    new ", propertyDescriptorName, "<", implName, ", int?>(\r\n");
                            this.WriteObjects("                        lazyCtx,\r\n");
                            this.WriteObjects("                        null,\r\n");
                            this.WriteObjects("                        \"", posColumnName, "\",\r\n");
                            this.WriteObjects("                        null,\r\n");
                            this.WriteObjects("                        obj => obj.", posColumnName, ",\r\n");
                            this.WriteObjects("                        (obj, val) => obj.", posColumnName, " = val,\r\n");
                            this.WriteObjects("						null),\r\n");
#line 148 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                        }
                    }
                }

#line 152 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
                this.WriteObjects("                };\r\n");
                this.WriteObjects("            }\r\n");
                this.WriteObjects("        }\r\n");
                this.WriteObjects("\r\n");
                this.WriteObjects("        protected override void CollectProperties(Func<IFrozenContext> lazyCtx, List<System.ComponentModel.PropertyDescriptor> props)\r\n");
                this.WriteObjects("        {\r\n");
                this.WriteObjects("            base.CollectProperties(lazyCtx, props);\r\n");
                this.WriteObjects("            _InitializePropertyDescriptors(lazyCtx);\r\n");
                this.WriteObjects("            props.AddRange(_properties);\r\n");
                this.WriteObjects("        }\r\n");
#line 162 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
            }
#line 163 "P:\zetbox\Zetbox.Generator\Templates\ObjectClasses\CustomTypeDescriptor.cst"
            this.WriteObjects("        #endregion // ", this.GetType(), "\r\n");
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public override void Generate()
        {
#line 33 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            this.WriteObjects("\r\n");
            this.WriteObjects("        public override void ApplyChangesFrom(", otherInterface, " obj)\r\n");
            this.WriteObjects("        {\r\n");
            this.WriteObjects("            base.ApplyChangesFrom(obj);\r\n");
            this.WriteObjects("            var other = (", clsName, ")obj;\r\n");
            this.WriteObjects("            var otherImpl = (", implName, ")obj;\r\n");
            this.WriteObjects("            var me = (", clsName, ")this;\r\n");
            this.WriteObjects("\r\n");
#line 41 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
// Only Client and Menory objects are applying calculated properties. NH + EF are re-calculating those properties when a depended object has changed.
#line 42 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            foreach (var prop in cls.Properties.OfType <ValueTypeProperty>().OrderBy(p => p.Name))
            {
#line 43 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                if (prop.IsList)
                {
#line 44 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    if (prop.HasPersistentOrder)
                    {
#line 45 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                        this.WriteObjects("            SynchronizeLists(this._", prop.Name, "Collection, otherImpl._", prop.Name, "Collection);\r\n");
#line 46 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    }
                    else
                    {
#line 47 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                        this.WriteObjects("            SynchronizeCollections(this._", prop.Name, "Collection, otherImpl._", prop.Name, "Collection);\r\n");
#line 48 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    }
#line 49 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                }
                else
                {
#line 50 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    if (prop.IsCalculated)
                    {
#line 51 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                        this.WriteObjects("            this.", prop.Name, " = otherImpl.", prop.Name, ";\r\n");
#line 52 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    }
                    else
                    {
#line 53 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                        this.WriteObjects("            me.", prop.Name, " = other.", prop.Name, ";\r\n");
#line 54 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    }
#line 55 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                }
#line 56 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            }
#line 57 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            foreach (var prop in cls.Properties.OfType <CompoundObjectProperty>() /*.Where(p => !p.IsCalculated)*/.OrderBy(p => p.Name))
            {
#line 58 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                if (prop.IsList)
                {
#line 59 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    if (prop.HasPersistentOrder)
                    {
#line 60 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                        this.WriteObjects("            SynchronizeLists(this._", prop.Name, "Collection, otherImpl._", prop.Name, "Collection);\r\n");
#line 61 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    }
                    else
                    {
#line 62 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                        this.WriteObjects("            SynchronizeCollections(this._", prop.Name, "Collection, otherImpl._", prop.Name, "Collection);\r\n");
#line 63 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    }
#line 64 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                }
                else
                {
#line 65 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    this.WriteObjects("            if (me.", prop.Name, " == null && other.", prop.Name, " != null) {\r\n");
                    this.WriteObjects("                me.", prop.Name, " = (", prop.GetElementTypeString(), ")other.", prop.Name, ".Clone();\r\n");
                    this.WriteObjects("            } else if (me.", prop.Name, " != null && other.", prop.Name, " == null) {\r\n");
                    this.WriteObjects("                me.", prop.Name, " = null;\r\n");
                    this.WriteObjects("            } else if (me.", prop.Name, " != null && other.", prop.Name, " != null) {\r\n");
                    this.WriteObjects("                me.", prop.Name, ".ApplyChangesFrom(other.", prop.Name, ");\r\n");
                    this.WriteObjects("            }\r\n");
#line 72 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                }
#line 73 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            }
#line 74 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            foreach (var prop in cls.Properties.OfType <ObjectReferenceProperty>().Where(p => !p.IsList()).OrderBy(p => p.Name))
            {
                if (prop.RelationEnd.HasPersistentOrder)
                {
                    var positionPropertyName = Construct.ListPositionPropertyName(prop.RelationEnd);

#line 78 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                    this.WriteObjects("            this.", positionPropertyName, " = otherImpl.", positionPropertyName, ";\r\n");
#line 79 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                }
#line 80 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
                this.WriteObjects("            this._fk_", prop.Name, " = otherImpl._fk_", prop.Name, ";\r\n");
#line 81 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            }
#line 82 "P:\zetbox\Zetbox.DalProvider.Memory.Generator\Templates\ObjectClasses\ApplyChangesFromMethod.cst"
            this.WriteObjects("        }\r\n");
        }
Exemplo n.º 6
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.º 7
0
        protected virtual void ApplyObjectReferenceProperty(string prefix, ObjectReferenceProperty prop)
        {
            this.WriteLine("<!-- ObjectReferenceProperty -->");

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

            string nameAttr  = String.Format("name=\"{0}\"", prop.Name);
            string classAttr = String.Format("class=\"{0}\"",
                                             ObjectClassHbm.GetAssemblyQualifiedProxy(otherEnd.Type, this.Settings));

            //string tableAttr = String.Format("table =\"`{0}`\" ", rel.GetAssociationName());

            switch (rel.GetRelationType())
            {
            case RelationType.one_one:
                if (rel.HasStorage(relEnd.GetRole()))
                {
                    string columnAttr = String.Format("column=\"`{0}`\"", Construct.ForeignKeyColumnName(otherEnd, prefix));
                    this.WriteObjects("        <many-to-one ", nameAttr, " ", columnAttr, " ", classAttr, " unique=\"true\" ");
                    if (prop.EagerLoading)
                    {
                        // TODO: re-think and re-test eagerloading
                        //this.WriteObjects("fetch=\"join\" ");
                    }
                    this.WriteLine("/>");
                }
                else
                {
                    this.WriteObjects("        <one-to-one ", nameAttr, " ", classAttr,
                                      " constrained=\"false\" ", // constrained must be false, because else the reference is not optional(!)
                                                                 // TODO: re-think and re-test eagerloading
                                                                 //prop.EagerLoading ? "fetch=\"join\" " : String.Empty,
                                      "property-ref=\"" + (otherEnd.Navigator != null ? otherEnd.Navigator.Name : "(no nav)") + "\" />");
                }
                break;

            case RelationType.one_n:
                if (otherEnd.Multiplicity.UpperBound() > 1)     // we are 1-side
                {
                    // always map as set, the wrapper has to translate/order the elements
                    this.WriteObjects("        <set ", nameAttr, " batch-size=\"100\" cascade=\"none\" inverse=\"true\" ");
                    if (prop.EagerLoading)
                    {
                        // TODO: re-think and re-test eagerloading
                        //this.WriteObjects("lazy=\"false\" fetch=\"join\" ");
                    }
                    this.WriteLine(">");
                    string columnAttr = String.Format("column=\"`{0}`\"", Construct.ForeignKeyColumnName(relEnd, prefix));
                    this.WriteObjects("            <key ", columnAttr, " />");
                    this.WriteLine();
                    this.WriteObjects("            <one-to-many ", classAttr, " />");
                    this.WriteLine();
                    this.WriteLine("        </set>");
                }
                else     // we are n-side
                {
                    string columnAttr = String.Format("column=\"`{0}`\"", Construct.ForeignKeyColumnName(otherEnd, prefix));
                    this.WriteObjects("        <many-to-one ", nameAttr, " ", columnAttr, " ", classAttr, " ");
                    if (prop.EagerLoading)
                    {
                        // TODO: re-think and re-test eagerloading
                        //this.WriteObjects("fetch=\"join\" ");
                    }
                    this.WriteLine("/>");
                    if (rel.NeedsPositionStorage(relEnd.GetRole()))
                    {
                        string posNameAttr   = String.Format("name=\"{0}\"", Construct.ListPositionPropertyName(relEnd));
                        string posColumnAttr = String.Format("column=\"`{0}`\"", Construct.ListPositionColumnName(otherEnd, prefix));
                        this.WriteObjects("        <property ", posNameAttr, " ", posColumnAttr, " />");
                        this.WriteLine();
                    }
                }
                break;

            case RelationType.n_m:
                ApplyNMProperty(rel, relEnd, otherEnd, prop);
                break;

            default:
                throw new NotImplementedException(String.Format("Unknown RelationType {0} found", rel.GetRelationType()));
            }

            this.WriteLine();
        }
Exemplo n.º 8
0
        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");
        }
Exemplo n.º 9
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.º 10
0
        public override void Generate()
        {
#line 35 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"

/*
 * TODO: Actually, all this should die and become a bunch of polymorphic calls.
 * See also Zetbox.DalProvider.NHibernate.Generator.Templates.Mappings.PropertiesHbm
 */

            foreach (var p in properties.OrderBy(p => p.Name))
            {
                // TODO: implement IsNullable everywhere
                if (p is ObjectReferenceProperty)
                {
                    var prop     = p as ObjectReferenceProperty;
                    var rel      = Zetbox.App.Extensions.RelationExtensions.Lookup(ctx, prop);
                    var relEnd   = rel.GetEnd(prop);
                    var otherEnd = rel.GetOtherEnd(relEnd);

                    if (rel.Storage == StorageType.Separate)
                    {
                        Debug.Assert(relEnd != null);

#line 54 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        this.WriteObjects("    <NavigationProperty Name=\"", p.Name + ImplementationPropertySuffix, "\"\r\n");
                        this.WriteObjects("                        Relationship=\"Model.", rel.GetRelationAssociationName(relEnd.GetRole()), "\"\r\n");
                        this.WriteObjects("                        FromRole=\"", relEnd.RoleName, "\"\r\n");
                        this.WriteObjects("                        ToRole=\"CollectionEntry\" />\r\n");
#line 59 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                    }
                    else
                    {
#line 63 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        this.WriteObjects("    <NavigationProperty Name=\"", p.Name + ImplementationPropertySuffix, "\"\r\n");
                        this.WriteObjects("                        Relationship=\"Model.", rel.GetAssociationName(), "\"\r\n");
                        this.WriteObjects("                        FromRole=\"", relEnd.RoleName, "\"\r\n");
                        this.WriteObjects("                        ToRole=\"", otherEnd.RoleName, "\" />\r\n");
#line 69 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        if (rel.NeedsPositionStorage(relEnd.GetRole()))
                        {
#line 72 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                            this.WriteObjects("    <Property Name=\"", Construct.ListPositionPropertyName(relEnd), "\" Type=\"Int32\" Nullable=\"true\" />\r\n");
#line 74 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        }
                    }
                }
                else if (p is ValueTypeProperty)
                {
                    var prop = (ValueTypeProperty)p;
                    if (prop.IsList && !prop.IsCalculated)
                    {
#line 83 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        this.WriteObjects("    <NavigationProperty Name=\"", prop.Name + ImplementationPropertySuffix, "\"\r\n");
                        this.WriteObjects("                        Relationship=\"Model.", prop.GetAssociationName(), "\"\r\n");
                        this.WriteObjects("                        FromRole=\"", prop.ObjectClass.Name, "\"\r\n");
                        this.WriteObjects("                        ToRole=\"CollectionEntry\" />\r\n");
#line 88 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                    }
                    else
                    {
#line 92 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        this.WriteObjects("    ", ModelCsdl.PlainPropertyDefinitionFromValueType((ValueTypeProperty)p, p.Name, ImplementationPropertySuffix), "\r\n");
#line 94 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                    }
                }
                else if (p is CompoundObjectProperty)
                {
                    var prop = (CompoundObjectProperty)p;
                    if (prop.IsList)
                    {
#line 102 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        this.WriteObjects("    <NavigationProperty Name=\"", prop.Name + ImplementationPropertySuffix, "\"\r\n");
                        this.WriteObjects("                        Relationship=\"Model.", prop.GetAssociationName(), "\"\r\n");
                        this.WriteObjects("                        FromRole=\"", prop.ObjectClass.Name, "\"\r\n");
                        this.WriteObjects("                        ToRole=\"CollectionEntry\" />\r\n");
#line 107 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                    }
                    else
                    {
                        // Nullable Complex types are not supported by EF

#line 112 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                        this.WriteObjects("    <Property Name=\"", p.Name + ImplementationPropertySuffix, "\"\r\n");
                        this.WriteObjects("              Type=\"Model.", prop.CompoundObjectDefinition.Name, "\"\r\n");
                        this.WriteObjects("              Nullable=\"false\" />\r\n");
#line 116 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.csdl.EntityTypeFields.cst"
                    }
                }
            }
        }