Beispiel #1
0
        public void UpdateDpo(PersistentObject dpo)
        {
            Type      type      = dpo.GetType();
            FieldInfo fieldInfo = type.GetField(field.Name);

            fieldInfo.SetValue(dpo, this.value);
        }
Beispiel #2
0
        public void UpdateValue(PersistentObject dpo)
        {
            Type      type      = dpo.GetType();
            FieldInfo fieldInfo = type.GetField(field.Name);

            object val = fieldInfo.GetValue(dpo);
            Type   ty  = fieldInfo.FieldType;

            UpdateValue(val);
        }
Beispiel #3
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="source"></param>
        public void CopyFrom(PersistentObject source)
        {
            if (source == null)
            {
                throw new MessageException("source cannot be null");
            }

            Type t1 = this.GetType();
            Type t2 = source.GetType();

            if (t1 != t2 && !t2.IsSubclassOf(t1))
            {
                throw new MessageException("class type {0} is not matched to {1}.", t2.FullName, t1.FullName);
            }

            foreach (PropertyInfo propertyInfo in this.columnProperties)
            {
                object value = propertyInfo.GetValue(source, null);
                propertyInfo.SetValue(this, value, null);
            }
        }
Beispiel #4
0
        private SqlBuilder clause2;     //B := SELECT * FROM Roles WHERE Roles.Role_ID IN (A)

        public Mapping(PersistentObject dpo, PropertyInfo propertyInfo2)
        {
            this.association = Reflex.GetAssociationAttribute(propertyInfo2);

            if (association == null)
            {
                return;
            }

            this.dpoInstance   = dpo;
            this.propertyInfo2 = propertyInfo2;

            Type dpoType2;            //typeof(RoleDpo)

            if (propertyInfo2.PropertyType.IsGenericType)
            {
                dpoType2 = PersistentObject.GetCollectionGenericType(propertyInfo2);

                if (this.association.TRelation == null)
                {
                    mappingType = MappingType.One2Many;
                }
                else
                {
                    mappingType = MappingType.Many2Many;
                }
            }
            else
            {
                dpoType2    = propertyInfo2.PropertyType;
                mappingType = MappingType.One2One;
            }



            this.propertyInfo1 = dpo.GetType().GetProperty(association.Column1);


            if (mappingType == MappingType.Many2Many)
            {
                this.clause1 = new SqlBuilder()
                               .SELECT().COLUMNS(association.Relation2)
                               .FROM(association.TRelation)
                               .WHERE(association.Relation1.ColumnName() == association.Column1.ParameterName());

                this.clause2 = new SqlBuilder()
                               .SELECT()
                               .COLUMNS()
                               .FROM(dpoType2)
                               .WHERE(association.Relation2.ColumnName().IN(this.clause1));
            }
            else
            {
                SqlExpr where = association.Column2.ColumnName() == association.Column1.ParameterName();
                if (association.Filter != null)
                {
                    where = where.AND(association.Filter);
                }

                this.clause2 = new SqlBuilder()
                               .SELECT()
                               .COLUMNS()
                               .FROM(dpoType2)
                               .WHERE(where);

                if (association.OrderBy != null)
                {
                    this.clause2 = clause2.ORDER_BY(association.OrderBy);
                }
            }
        }