Beispiel #1
0
        protected StringBuilder ComputeSqlJoin(Serializer.Serializer serializer, IList <Type> path, String restriction, String target)
        {
            AttributeWorker w = AttributeWorker.GetInstance(target);

            QueryGenerator ret = new QueryGenerator();

            ret.AddQueryComponent(new PlaceHolderComponent());

            //StringBuilder b = new StringBuilder();
            //b.Append(" @@@");

            for (int i = 0; i < path.Count - 1; i++)
            {
                Type from = path[i];
                Type to   = path[i + 1];
                //if (i > 0)
                //{
                //    b.Replace(" @@@", " WHERE  @@@");
                //}

                IVirtualKey    vKey = w.CreateVirtualKey(serializer, from, to);
                QueryGenerator gen1 = vKey.ToSqlRestriction(target, from, to, serializer);
                ret.ReplacePlaceHolders(gen1);
                //b.Replace(" @@@", vKey.ToSqlRestriction(target, from, to));

                if (i == path.Count - 2)
                {
                    QueryGenerator gen2 = new QueryGenerator();
                    gen2.AddQueryComponent(new SqlStringComponent(" WHERE "));
                    gen2.AddQueryComponent(new SqlStringComponent(restriction));
                    ret.ReplacePlaceHolders(gen2);

                    //b.Replace(" @@@", " WHERE  @@@");
                    //b.Replace(" @@@", restriction);
                }
            }

            if (path.Count == 1)
            {
                QueryGenerator gen3 = new QueryGenerator();
                gen3.AddQueryComponent(new SqlStringComponent(" WHERE "));
                gen3.AddQueryComponent(new SqlStringComponent(restriction));
                ret.ReplacePlaceHolders(gen3);

                //b.Replace(" @@@", " WHERE  @@@");
                //b.Replace(" @@@", restriction);
            }


            //Entferne das führende " WHERE "

            return(ret.ToSqlString());

            //return b.Remove(0,7);
        }
        public override Object LoadOneToMany(ISerializableObject owner, Type storedType, Serializer serializer)
        {
            Type genType = typeof(DirectAccesIteratorImpl <>).MakeGenericType(new Type[] { storedType });
            IDirectAccessIteratorConfiguration conf = (IDirectAccessIteratorConfiguration)Activator.CreateInstance(genType);

            IVirtualKey vKey = AttributeWorker.GetInstance(serializer.Target).CreateVirtualKey(serializer, owner.GetType(), storedType);

            vKey.InitVirtualKeyBySource(owner);

            conf.Restriction = Restrictions.RestrictionFactory.SqlRestriction(storedType, vKey.ToSqlStringForward(serializer.Target));
            conf.Serializer  = serializer;

            return(conf);
        }
Beispiel #3
0
        public void ConnectOneToOne(ISerializableObject source, ISerializableObject target)
        {
            IVirtualKey vKey = AttributeWorker.GetInstance(Target).CreateVirtualKey(this, source.GetType(), target.GetType());

            vKey.InitVirtualKeyBySource(source);
            vKey.ApplyVirtualKeyToTarget(target);

            try
            {
                vKey.TargetField.SetValue(target, source);
            }
            catch (Exception)
            {
            }
        }
Beispiel #4
0
        public void HandleOneToOneReflexive(ISerializableObject handledItem, OneToOneDefAttribute attr, FieldInfo field)
        {
            Type        type = field.FieldType;
            IVirtualKey vKey = AttributeWorker.GetInstance(_serializer.Target).CreateVirtualKey(_serializer, type, handledItem.GetType());

            try
            {
                vKey.InitVirtualKeyBySource(handledItem);
            }
            catch (InvalidOperationException)
            {
                field.SetValue(handledItem, null);
                return;
            }
            IRestriction        r   = Restrictions.RestrictionFactory.SqlRestriction(type, vKey.ToSqlStringForward(_serializer.Target));
            ISerializableObject tmp = _serializer.Connector.Load(type, r);

            field.SetValue(handledItem, tmp);
        }