Ejemplo n.º 1
0
        /// <summary>
        /// Loads an Object of the given type with the given criteria. The criteria must uniquely identify an Object, otherwise an exception is thrown.
        /// </summary>
        /// <typeparam name="T">The type of the Object to load.</typeparam>
        /// <param name="p_object_conditions">The criteria the loaded Object must match.</param>
        /// <returns>The loaded Object that matched the criteria. If no Object matches the criteria, default(T) is returned, if multiple objects matched, an error is thrown.</returns>
        public CDBWizardStatus LoadClass <T>(T p_obj, params KeyValuePair <String, Object>[] p_object_conditions) where T : class
        {
            CObjectMap p_object_map = CObjectMap.Get(p_obj.GetType());

            if (p_object_map.m_p_begin_load_call_back != null)
            {
                p_object_map.m_p_begin_load_call_back(p_obj);
            }

            SQL.CWhereCondition[] p_conditions = new SQL.CWhereCondition[p_object_conditions.Length];
            for (Int32 i = 0; i < p_object_conditions.Length; ++i)
            {
                p_conditions[i] = new SQL.CWhereCondition(p_object_conditions[i].Key, "=", p_object_conditions[i].Value.ToString());
            }

            CDataBaseObject p_db_obj = new CDataBaseObject(p_object_map);
            CDBWizardStatus p_status = p_object_map.LoadObject(
                this,
                new SQL.CWhereCondition(p_conditions),
                p_db_obj
                );

            if (!p_status.IsError)
            {
                try
                {
                    p_db_obj.MapToClass(p_obj);

                    if (p_object_map.m_p_end_load_call_back != null)
                    {
                        p_object_map.m_p_end_load_call_back(p_obj);
                    }
                }
                catch (Exception p_except)
                {
                    return(new CDBWizardStatus(EDBWizardStatusCode.err_exception_thrown, p_except));
                }
            }
            return(p_status);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads an Object of the given type with the given primary key. The criteria must uniquely identify an Object, otherwise an exception is thrown.
        /// </summary>
        /// <typeparam name="T">The type of the Object to load.</typeparam>
        /// <param name="p_primary_key_value">The criteria the loaded Object must match.</param>
        /// <returns>A status Object containing information about the success/failure of the operation.</returns>
        public CDBWizardStatus LoadClass <T>(T p_obj, Object p_primary_key_value) where T : class
        {
            CObjectMap p_object_map = CObjectMap.Get(p_obj.GetType());

            if (p_object_map.m_p_begin_load_call_back != null)
            {
                p_object_map.m_p_begin_load_call_back(p_obj);
            }

            CDataBaseObject p_db_obj = new CDataBaseObject(p_object_map);

            if (p_object_map.m_p_unique_keys.Count == 0)
            {
                throw new Exception("The class \"" + typeof(T).FullName + "\" does not define a primary key.");
            }
            CDBWizardStatus p_status = p_object_map.LoadObject(
                this,
                new SQL.CWhereCondition(p_object_map.m_p_unique_keys[0].m_p_column_name, "=", p_primary_key_value.ToString()),
                p_db_obj
                );

            if (!p_status.IsError)
            {
                try
                {
                    p_db_obj.MapToClass(p_obj);

                    if (p_object_map.m_p_end_load_call_back != null)
                    {
                        p_object_map.m_p_end_load_call_back(p_obj);
                    }
                }
                catch (Exception p_except)
                {
                    return(new CDBWizardStatus(EDBWizardStatusCode.err_exception_thrown, p_except));
                }
            }
            return(p_status);
        }
Ejemplo n.º 3
0
        public Tuple <CDBWizardStatus, CDataBaseObject> LoadObject(Type p_object_type, Object p_primary_key_value)
        {
            CObjectMap p_object_map = CObjectMap.Get(p_object_type);

            CDataBaseObject p_result = new CDataBaseObject(p_object_map);

            if (p_object_map.m_p_unique_keys.Count == 0)
            {
                throw new Exception("The class \"" + p_object_type.FullName + "\" does not define a primary key.");
            }
            CDBWizardStatus p_status = p_object_map.LoadObject(
                this,
                new SQL.CWhereCondition(p_object_map.m_p_unique_keys[0].m_p_column_name, "=", p_primary_key_value.ToString()),
                p_result
                );

            if (p_status.IsError)
            {
                p_result = null;
            }

            return(new Tuple <CDBWizardStatus, CDataBaseObject>(p_status, p_result));
        }