Inheritance: gov.va.medora.mdo.domain.sm.BaseModel
        internal static MessageAttachment getAttachmentFromReader(System.Data.IDataReader rdr, Dictionary<string, bool> columnTable)
        {
            MessageAttachment attachment = new MessageAttachment();

            if (columnTable["ATTACHMENT_ID"])
            {
                int idIndex = rdr.GetOrdinal("ATTACHMENT_ID");
                if (!rdr.IsDBNull(idIndex))
                {
                    attachment.Id = Convert.ToInt32(rdr.GetDecimal(idIndex));
                }
            }
            if (columnTable["ATTACHMENT_NAME"])
            {
                int nameIndex = rdr.GetOrdinal("ATTACHMENT_NAME");
                if (!rdr.IsDBNull(nameIndex))
                {
                    attachment.AttachmentName = rdr.GetString(nameIndex);
                }
            }
            if (columnTable["ATTACHMENT"])
            {
                int attIndex = rdr.GetOrdinal("ATTACHMENT");
                if (!rdr.IsDBNull(attIndex))
                {
                    // not crazy about this implementation as it appears to invoke the reader twice but the commented out code
                    // block directly below throws an exception when calling GetOracleBlob for some reason... The good thing about
                    // this solution is it should work for all IDataReader implementations and doesn't need to be cast to an OracleDataReader
                    byte[] blob = new byte[rdr.GetBytes(attIndex, 0, null, 0, Int32.MaxValue)];
                    rdr.GetBytes(attIndex, 0, blob, 0, blob.Length);
                    attachment.SmFile = blob;
                    //if (rdr is Oracle.DataAccess.Client.OracleDataReader)
                    //{
                    //    System.Console.WriteLine(rdr[attIndex].GetType().ToString());
                    //    Oracle.DataAccess.Types.OracleBlob blob = ((Oracle.DataAccess.Client.OracleDataReader)rdr).GetOracleBlob(attIndex);
                    //    byte[] buf = new byte[blob.Length];
                    //    blob.Read(buf, 0, Convert.ToInt32(blob.Length));
                    //    attachment.SmFile = buf;
                    //}
                }
            }
            if (columnTable["MIME_TYPE"])
            {
                int mimeTypeIndex = rdr.GetOrdinal("MIME_TYPE");
                if (!rdr.IsDBNull(mimeTypeIndex))
                {
                    attachment.MimeType = rdr.GetString(mimeTypeIndex);
                }
            }
            if (columnTable["ATTOPLOCK"])
            {
                int oplockIndex = rdr.GetOrdinal("ATTOPLOCK");
                if (!rdr.IsDBNull(oplockIndex))
                {
                    attachment.Oplock = Convert.ToInt32(rdr.GetDecimal(oplockIndex));
                }
            }

            return attachment;
        }
        public MessageAttachment attachToMessage(MessageAttachment attachment, Message message)
        {
            try
            {
                _cxn.beginTransaction();

                if (attachment.Id > 0)
                {
                    attachment = updateAttachment(attachment); // could simply rely on updateAttachment function but thought this might add a level of convenience
                }
                else if (attachment.Id <= 0)
                {
                    // create attachment
                    attachment = createAttachment(attachment.AttachmentName, attachment.SmFile, attachment.MimeType);
                    // update message - set attachment ID properties
                    message = updateMessageAttachmentFields(message, attachment.Id);
                }

                _cxn.commitTransaction();
                return attachment;
            }
            catch (Exception)
            {
                _cxn.rollbackTransaction();
                throw;
            }
        }
        internal static MessageAttachment getAttachmentFromReader(System.Data.IDataReader rdr, Dictionary <string, bool> columnTable)
        {
            MessageAttachment attachment = new MessageAttachment();

            if (columnTable["ATTACHMENT_ID"])
            {
                int idIndex = rdr.GetOrdinal("ATTACHMENT_ID");
                if (!rdr.IsDBNull(idIndex))
                {
                    attachment.Id = Convert.ToInt32(rdr.GetDecimal(idIndex));
                }
            }
            if (columnTable["ATTACHMENT_NAME"])
            {
                int nameIndex = rdr.GetOrdinal("ATTACHMENT_NAME");
                if (!rdr.IsDBNull(nameIndex))
                {
                    attachment.AttachmentName = rdr.GetString(nameIndex);
                }
            }
            if (columnTable["ATTACHMENT"])
            {
                int attIndex = rdr.GetOrdinal("ATTACHMENT");
                if (!rdr.IsDBNull(attIndex))
                {
                    // not crazy about this implementation as it appears to invoke the reader twice but the commented out code
                    // block directly below throws an exception when calling GetOracleBlob for some reason... The good thing about
                    // this solution is it should work for all IDataReader implementations and doesn't need to be cast to an OracleDataReader
                    byte[] blob = new byte[rdr.GetBytes(attIndex, 0, null, 0, Int32.MaxValue)];
                    rdr.GetBytes(attIndex, 0, blob, 0, blob.Length);
                    attachment.SmFile = blob;
                    //if (rdr is Oracle.DataAccess.Client.OracleDataReader)
                    //{
                    //    System.Console.WriteLine(rdr[attIndex].GetType().ToString());
                    //    Oracle.DataAccess.Types.OracleBlob blob = ((Oracle.DataAccess.Client.OracleDataReader)rdr).GetOracleBlob(attIndex);
                    //    byte[] buf = new byte[blob.Length];
                    //    blob.Read(buf, 0, Convert.ToInt32(blob.Length));
                    //    attachment.SmFile = buf;
                    //}
                }
            }
            if (columnTable["MIME_TYPE"])
            {
                int mimeTypeIndex = rdr.GetOrdinal("MIME_TYPE");
                if (!rdr.IsDBNull(mimeTypeIndex))
                {
                    attachment.MimeType = rdr.GetString(mimeTypeIndex);
                }
            }
            if (columnTable["ATTOPLOCK"])
            {
                int oplockIndex = rdr.GetOrdinal("ATTOPLOCK");
                if (!rdr.IsDBNull(oplockIndex))
                {
                    attachment.Oplock = Convert.ToInt32(rdr.GetDecimal(oplockIndex));
                }
            }


            return(attachment);
        }
        public OracleQuery buildUpdateAttachmentQuery(MessageAttachment attachment)
        {
            string sql = "UPDATE SMS.MESSAGE_ATTACHMENT SET ATTACHMENT_NAME=:attachmentName, ATTACHMENT=:attachment, MIME_TYPE=:mimeType, " +
                "OPLOCK=:oplockPlusOne WHERE ATTACHMENT_ID=:attachmentId AND OPLOCK=:oplock";

            OracleQuery query = new OracleQuery();
            query.Command = new OracleCommand(sql);

            OracleParameter attachmentNameParam = new OracleParameter("attachmentName", OracleDbType.Varchar2, 80);
            attachmentNameParam.Value = attachment.AttachmentName;
            query.Command.Parameters.Add(attachmentNameParam);

            OracleParameter attachmentParam = new OracleParameter("attachment", OracleDbType.Blob);
            attachmentParam.Value = attachment.SmFile;
            query.Command.Parameters.Add(attachmentParam);

            OracleParameter mimeTypeParam = new OracleParameter("mimeType", OracleDbType.Varchar2, 100);
            mimeTypeParam.Value = attachment.MimeType;
            query.Command.Parameters.Add(mimeTypeParam);

            OracleParameter oplockPlusOneParam = new OracleParameter("oplockPlusOne", OracleDbType.Decimal);
            oplockPlusOneParam.Value = attachment.Oplock + 1;
            query.Command.Parameters.Add(oplockPlusOneParam);

            OracleParameter attachmentIdParam = new OracleParameter("attachmentId", OracleDbType.Decimal);
            attachmentIdParam.Value = attachment.Id;
            query.Command.Parameters.Add(attachmentIdParam);

            OracleParameter oplockParam = new OracleParameter("oplock", OracleDbType.Decimal);
            oplockParam.Value = attachment.Oplock;
            query.Command.Parameters.Add(oplockParam);

            return query;
        }
        internal MessageAttachment toAttachment(IDataReader rdr)
        {
            MessageAttachment ma = new MessageAttachment();

            if (rdr.Read())
            {
                ma = MessageAttachment.getAttachmentFromReader(rdr);
            }
            return ma;
        }
 public domain.sm.MessageAttachment updateAttachment(MessageAttachment attachment)
 {
     OracleQuery request = buildUpdateAttachmentQuery(attachment);
     nonQuery qry = delegate() { return (Int32)request.Command.ExecuteNonQuery(); };
     if ((Int32)_cxn.query(request, qry) != 1)
     {
         throw new MdoException("Unable to update message attachment");
     }
     attachment.Oplock++;
     return attachment;
 }
 public domain.sm.MessageAttachment createAttachment(string attachmentName, byte[] attachment, string mimeType)
 {
     OracleQuery request = buildCreateAttachmentQuery(attachmentName, attachment, mimeType);
     nonQuery qry = delegate() { return (Int32)request.Command.ExecuteNonQuery(); };
     if ((Int32)_cxn.query(request, qry) != 1)
     {
         throw new MdoException("Unable to insert new message attachment");
     }
     MessageAttachment result = new MessageAttachment() { AttachmentName = attachmentName, MimeType = mimeType };
     result.Id = ((Oracle.DataAccess.Types.OracleDecimal)request.Command.Parameters["outId"].Value).ToInt32();
     return result;
 }