Ejemplo n.º 1
0
        public static void Call(IGenerationHost host, IZetboxContext ctx, ObjectClass cls)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (cls == null)
            {
                throw new ArgumentNullException("cls");
            }
            if (cls.BaseObjectClass == null)
            {
                var msg = String.Format("Only subclasses can be joined subclasses, but {0} doesn't have a base class",
                                        cls.Name);
                throw new ArgumentOutOfRangeException("cls", msg);
            }

            host.CallTemplate("Mappings.JoinedSubclassHbm",
                              new object[] { ctx }
                              .Concat(ObjectClassHbm.MakeArgs(ctx, cls, host.Settings))
                              .ToArray());
        }
Ejemplo n.º 2
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();
        }