Exemplo n.º 1
0
        public void SetIsolationLevel(IsolationLevel isolationLevel)
        {
            ZDBMS  dbms = AdoNetHelper.GetDBMS(Session.Connection.ConnectionString);
            string sql  = AdoNetHelper.SqlIsolationLevel(dbms, isolationLevel);

            if (!String.IsNullOrEmpty(sql))
            {
                SQLCommand(sql);
            }
        }
Exemplo n.º 2
0
        public virtual object GetNextSequence()
        {
            object id = null;

            if (Profile.IsIdentity && !PersistenceHelper.GeneratesIdentity(UnitOfWork.DBMS))
            {
                string sql = AdoNetHelper.GetSequenceSql(UnitOfWork.DBMS, this.GetType().Name);
                id = Session.CreateSQLQuery(sql).UniqueResult <object>();
            }

            return(id);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute Reader.
        /// </summary>
        /// <param name="dbCommand">Command</param>
        /// <param name="isolationLevel">Isolation level</param>
        /// <returns>Data Reader</returns>
        public static DbDataReader ExecuteReader(this DbCommand dbCommand,
                                                 IsolationLevel isolationLevel)
        {
            if (ConfigurationHelper.AppSettings <bool>("EasyLOB.AdoNet.IsolationLevel"))
            {
                ZDBMS  dbms = AdoNetHelper.GetDBMS(dbCommand.Connection);
                string sql  = AdoNetHelper.SqlIsolationLevel(dbms, isolationLevel);
                dbCommand.CommandText = (String.IsNullOrEmpty(sql) ? "" : sql + Environment.NewLine)
                                        + dbCommand.CommandText;
            }

            return(dbCommand.ExecuteReader());
        }
Exemplo n.º 4
0
        public virtual object GetNextSequence()
        {
            object id = null;

            if (Profile.IsIdentity && !PersistenceHelper.GeneratesIdentity(UnitOfWork.DBMS))
            {
                string sql = AdoNetHelper.GetSequenceSql(UnitOfWork.DBMS, this.GetType().Name);
                if (!String.IsNullOrEmpty(sql))
                {
                    id = Context.Database.SqlQuery <object>(sql);
                }
            }

            return(id);
        }
Exemplo n.º 5
0
        public virtual object GetNextSequence()
        {
            object id = null;

            if (Profile.IsIdentity && !PersistenceHelper.GeneratesIdentity(UnitOfWork.DBMS))
            {
                string sql = AdoNetHelper.GetSequenceSql(UnitOfWork.DBMS, this.GetType().Name);
                Connection.Command.CommandType = CommandType.Text;
                Connection.Command.CommandText = sql;

                id = Connection.Command.ExecuteScalar();
            }

            return(id);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Execute Scalar.
        /// </summary>
        /// <param name="dbCommand">Command</param>
        /// <param name="isolationLevel">Isolation level</param>
        /// <returns>object</returns>
        public static object ExecuteScalar(this DbCommand dbCommand,
                                           IsolationLevel isolationLevel)
        {
            if (isolationLevel == IsolationLevel.ReadUncommitted)
            {
                if (AdoNetHelper.GetDBMS(dbCommand.Connection) == ZDBMS.SQLServer)
                {
                    dbCommand.CommandText =
                        "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" + Environment.NewLine
                        + dbCommand.CommandText;
                }
            }

            return(dbCommand.ExecuteScalar());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get Sequence generated by DBMS.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="connectionName"></param>
        /// <returns></returns>
        public static object GetSequence(string entity, string connectionName)
        {
            object value = null;

            DbConnection connection = null;

            try
            {
                DbProviderFactory provider = AdoNetHelper.GetProvider(connectionName);
                connection = provider.CreateConnection();
                connection.ConnectionString = AdoNetHelper.GetConnectionString(connectionName);
                connection.Open();

                DbCommand command = connection.CreateCommand();
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = GetSequenceSql(GetDBMS(provider), entity);
                if (command.CommandText != "")
                {
                    if (connection.State == ConnectionState.Closed)
                    {
                        connection.Open();
                    }

                    try
                    {
                        value = LibraryHelper.ObjectToInt32(command.ExecuteScalar());
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            catch (Exception exception)
            {
                throw new Exception("GetId", exception);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(value);
        }