Example #1
0
        /**
         * Get database value
         *
         * @param EntityFieldInfo field
         * @param Connection connection
         * @return dynamic
         */
        public virtual dynamic getDatabaseValue(EntityFieldInfo field, Connection connection)
        {
            IEntityManager em         = EntityManager.getInstance();
            string         field_name = field.fieldName();
            Type           db_type    = field.dbType();
            bool           is_null    = field.isNull();

            dynamic value = this.getValue(field_name);

            if (value is EntityBaseType)
            {
                value = value.value();
            }

            EntityBaseType obj = em.getEntityType(db_type);

            if (obj != null)
            {
                value = obj.convertToDatabase(value, connection);
                if (value == null && !is_null)
                {
                    value = obj.getEmptyValue();
                }
            }

            return(value);
        }
Example #2
0
        /**
         * Set database value
         *
         * @param EntityFieldInfo field
         * @param Connection connection
         * @param dynamic db_value
         */
        public virtual void setDatabaseValue(EntityFieldInfo field, Connection connection,
                                             dynamic db_value)
        {
            IEntityManager em         = EntityManager.getInstance();
            string         field_name = field.fieldName();
            Type           db_type    = field.dbType();
            bool           is_null    = field.isNull();

            dynamic        obj_value = this.getValue(field_name);
            EntityBaseType obj       = em.getEntityType(db_type);

            if (obj != null)
            {
                db_value = obj.convertFromDatabase(db_value, connection);
                if (obj_value is EntityBaseType)
                {
                    obj_value.assign(db_value);
                }
                else
                {
                    this.setValue(field_name, db_value);
                }
            }
        }