コード例 #1
0
ファイル: nHManager.cs プロジェクト: anastasiaramos/CslaEx
        /// <summary>
        /// Ejecuta una instruccion SQL nativa mediante una nueva session
        /// </summary>
        /// <param name="query"></param>
        public void SQLNativeExecute(string query)
        {
            ISession     sess  = null;
            ITransaction trans = null;

            try
            {
                sess  = SFactory.OpenSession();
                trans = sess.BeginTransaction();
                IDbCommand command = sess.Connection.CreateCommand();

                command.CommandText = query;
                command.ExecuteNonQuery();

                trans.Commit();
            }
            catch (Exception ex)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }
                throw new Exception(ex.Message);
            }
            finally
            {
                sess.Close();
            }
        }
コード例 #2
0
ファイル: nHManager.cs プロジェクト: anastasiaramos/CslaEx
        public IList HQLSelect(string query)
        {
            ISession     sess  = SFactory.OpenSession();
            ITransaction trans = sess.BeginTransaction();
            IList        results;

            try
            {
                results = sess.CreateQuery(query).List();
                trans.Commit();
            }
            catch (Exception ex)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }
                throw new Exception(ex.Message);
            }
            finally
            {
                sess.Close();
            }

            return(results);
        }
コード例 #3
0
ファイル: nHManager.cs プロジェクト: anastasiaramos/CslaEx
        /// <summary>
        /// Abre una sesión
        /// </summary>
        /// <returns>Código de session</returns>
        ///
        public int OpenSession()
        {
            int pos = 0;

            ISession sess = SFactory.OpenSession();

            // Buscamos la primera posicion vacía
            foreach (ISession session in Sessions)
            {
                if (session == null)
                {
                    Sessions.RemoveAt(pos);
                    break;
                }
                pos++;
            }

            Sessions.Insert(pos, sess);
            return(pos);
        }
コード例 #4
0
ファイル: nHManager.cs プロジェクト: anastasiaramos/CslaEx
        /*public IList SQLNativeSelect(string query, Type type)
         * {
         *      ISession sess = SFactory.OpenSession();
         *      ITransaction trans = sess.BeginTransaction();
         *      IList results = null;
         *
         *      try
         *      {
         *              IQuery nHQ = sess.CreateSQLQuery(query)
         *                                              .SetResultTransformer(Transformers.AliasToBean(type));
         *
         *              results = nHQ.List();
         *
         *              trans.Commit();
         *      }
         *      catch (Exception ex)
         *      {
         *              if (trans != null) trans.Rollback();
         *              throw new Exception(ex.Message);
         *      }
         *      finally
         *      {
         *              sess.Close();
         *      }
         *
         *      return results;
         * }*/

        /// <summary>
        /// Ejecuta una consulta SQL nativa mediante una nueva session
        /// </summary>
        /// <param name="query"></param>
        public IDataReader SQLNativeSelect(string query)
        {
            ISession     sess  = null;
            ITransaction trans = null;

            //System.Object values;

            try
            {
                sess  = SFactory.OpenSession();
                trans = sess.BeginTransaction();
                IDbCommand command = sess.Connection.CreateCommand();

                command.CommandText = query;
                IDataReader list = command.ExecuteReader();

                trans.Commit();

                //IDataRecord rec;

                //rec.GetValues(values);

                return(list);
            }
            catch (Exception ex)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }

                throw ex;
            }
            finally
            {
                sess.Close();
            }
        }
コード例 #5
0
ファイル: nHManager.cs プロジェクト: anastasiaramos/CslaEx
        public void HQLExecute(string query, Type type)
        {
            ISession     sess  = SFactory.OpenSession();
            ITransaction trans = sess.BeginTransaction();

            try
            {
                IQuery nHQ = sess.CreateSQLQuery(query).AddEntity(type);
                nHQ.UniqueResult();
                trans.Commit();
            }
            catch (Exception ex)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }
                throw new Exception(ex.Message);
            }
            finally
            {
                sess.Close();
            }
        }