Utilizando System.Reflection e System.Attributes para a construção de uma Ferramenta ORM - Parte 8

Construção de uma ferramenta ORM tendo como base os recursos contidos nas Namespaces System.Reflection e System.Attributes entre outras etc.

Continuação da classe DAL Genérica.

private List ExecProcSelectFilter(T pObj) { object[] atributos = null; AttParamProcDB attProcDB = null; IDbCommand command = null; IDbDataParameter param = null; IDbDataAdapter adp = null; List retorno = null; DataSet ds = null; try { this.ValidateUsageCustomAttributes(); if (this._dbManager == null || this._dbManager.Conn == null) { throw new GenericDALException("Utilize um dos métodos 'TransactionScope' para setar o escopo da transacao atual"); } foreach (PropertyInfo piInfo in pObj.GetType().GetProperties()) { atributos = piInfo.GetCustomAttributes(false); if (atributos != null && atributos.Length > 0) { foreach (object att in atributos) { if (att is AttParamProcDB) { attProcDB = (AttParamProcDB)att; if (attProcDB.TipoProcedure == ProcedureTypes.SelectFilter) { if (command == null || String.IsNullOrEmpty(command.CommandText)) { command = this._dbManager.Conn.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = attProcDB.ProcName; command.Transaction = this._dbManager.Trans; } if (command != null && attProcDB.TipoProcedure != ProcedureTypes.SelectNoFilter) { param = command.CreateParameter(); param.ParameterName = attProcDB.ParamName; param.DbType = attProcDB.DbType; param.Direction = attProcDB.Direction; if (attProcDB.Direction == ParameterDirection.Input) { param.Value = piInfo.GetValue(pObj, null); } else { piInfo.SetValue(pObj, param.Value, null); param.Size = 1000; } command.Parameters.Add(param); } } } } } } adp = this._dbManager.Adp; adp.SelectCommand = command; ds = new DataSet(); adp.Fill(ds); retorno = this.DataSetToList(ds); } catch (Exception ex) { this._dbManager.Trans.Rollback(); this._dbManager.Conn.Close(); throw ex; } finally { atributos = null; attProcDB = null; command = null; param = null; adp = null; ds = null; } return retorno; } private List ExecProcSelectNoFilter() { IDbCommand command = null; IDbDataAdapter adp = null; bool flagIsTrans = true; List retorno = null; DataSet ds = null; string procName = ""; T Obj = new T(); AttProcNameSelectNoFilter attribute = null; try { this.ValidateUsageCustomAttributes(); if (this._dbManager == null) { throw new GenericDALException("Utilize um dos métodos 'TransactionScope' para setar o escopo da transacao atual"); } if (Obj.GetType().GetCustomAttributes(typeof(AttProcNameSelectNoFilter), false)[0] != null) { attribute = (AttProcNameSelectNoFilter)Obj.GetType().GetCustomAttributes(typeof(AttProcNameSelectNoFilter), false)[0]; procName = attribute.ProcName; if (!String.IsNullOrEmpty(procName)) { if (command == null || String.IsNullOrEmpty(command.CommandText)) { command = this._dbManager.Conn.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = procName; command.Transaction = this._dbManager.Trans; adp = this._dbManager.Adp; adp.SelectCommand = command; ds = new DataSet(); adp.Fill(ds); retorno = this.DataSetToList(ds); } } } } catch (Exception ex) { this._dbManager.Trans.Rollback(); this._dbManager.Conn.Close(); throw ex; } finally { command = null; adp = null; ds = null; procName = null; Obj = default(T); attribute = null; } return retorno; } #endregion #region Protected Execute Procedures Methods protected List ExecuteProcSelectFilter(T pObj) { return this.ExecProcSelectFilter(pObj); } protected List ExecuteProcSelectNoFilter() { return this.ExecProcSelectNoFilter(); } protected void ExecuteProcInsert(T pObj) { this.ExecProc(pObj, ProcedureTypes.Insert); } protected void ExecuteProcDelete(T pObj) { this.ExecProc(pObj, ProcedureTypes.Delete); } /// protected void ExecuteProcUpdate(T pObj) { this.ExecProc(pObj, ProcedureTypes.Update); } #endregion } }

Artigos relacionados