Esempio n. 1
0
        public static void CheckSchema(IEntitySchema view)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            var dbProvider = DbConnectionManager.Gain(view.ConnectKey, true);

            if (dbProvider.AccessLevel == AccessLevel.ReadOnly)
            {
                throw new InvalidOperationException("DbProvider key:" + view.ConnectKey + ", read only!");
            }
            var tables = view.Tables;

            if (tables.Count == 0)
            {
                throw new InvalidOperationException("no entity schema table!");
            }
            if (!tables.All(p => CheckTableChanged(p, dbProvider)))
            {
                return;
            }
            if (tables.Count >= 2)
            {
                CheckViewChanged(view, dbProvider);
            }
            if (view.Attributes.HasFlag(EntitySchemaAttributes.CreateProcedure))
            {
                CheckProcedureChanged(view, ProcedureUsage.Insert, dbProvider);
                CheckProcedureChanged(view, ProcedureUsage.Update, dbProvider);
                if (view.Attributes.HasFlag(EntitySchemaAttributes.CreateType))
                {
                    if (ProcedureExists(view, ProcedureUsage.TypeInsert, dbProvider))
                    {
                        var strComm = string.Format("Drop Procedure [dbo].[Insert{0}Type]", view.Name);
                        dbProvider.ExecuteNonQuery(strComm);
                    }
                    if (ProcedureExists(view, ProcedureUsage.TypeUpdate, dbProvider))
                    {
                        var strComm = string.Format("Drop Procedure [dbo].[Update{0}Type]", view.Name);
                        dbProvider.ExecuteNonQuery(strComm);
                    }

                    CheckTypeChanged(view, dbProvider);
                    CheckProcedureChanged(view, ProcedureUsage.TypeInsert, dbProvider);
                    CheckProcedureChanged(view, ProcedureUsage.TypeUpdate, dbProvider);
                }
            }
        }
Esempio n. 2
0
        public static bool CheckTableChanged(ISchemaTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (!DbConnectionManager.TryGet(table.Schema.ConnectKey, out DbConnectionProvider connectionProvider))
            {
                throw new KeyNotFoundException("not found DbProvider key:" + table.Schema.ConnectKey);
            }
            if (connectionProvider.AccessLevel == AccessLevel.ReadOnly)
            {
                throw new InvalidOperationException("DbProvider key:" + table.Schema.ConnectKey + ", read only!");
            }

            return(CheckTableChanged(table, connectionProvider));
        }
Esempio n. 3
0
        public static bool CheckViewChanged(IEntitySchema entitySchema)
        {
            if (entitySchema == null)
            {
                throw new ArgumentNullException(nameof(entitySchema));
            }

            if (!DbConnectionManager.TryGet(entitySchema.ConnectKey, out DbConnectionProvider connectionProvider))
            {
                throw new KeyNotFoundException("not found DbProvider key:" + entitySchema.ConnectKey);
            }
            if (connectionProvider.AccessLevel == AccessLevel.ReadOnly)
            {
                throw new InvalidOperationException("DbProvider key:" + entitySchema.ConnectKey + ", read only!");
            }

            return(CheckViewChanged(entitySchema, connectionProvider));
        }
Esempio n. 4
0
        public static bool CheckProcedureChanged(IEntitySchema view, ProcedureUsage usage)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            if (!DbConnectionManager.TryGet(view.ConnectKey, out DbConnectionProvider connectionProvider))
            {
                throw new KeyNotFoundException("not found DbProvider key:" + view.ConnectKey);
            }
            if (connectionProvider.AccessLevel == AccessLevel.ReadOnly)
            {
                throw new InvalidOperationException("DbProvider key:" + view.ConnectKey + ", read only!");
            }

            return(CheckProcedureChanged(view, usage, connectionProvider));
        }
Esempio n. 5
0
        /// <summary>
        /// 根据数据库的逻辑名称创建Database实例
        /// </summary>
        /// <param name="name">数据库逻辑名称</param>
        /// <returns>Database实例</returns>
        public static Database Create(string name)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(name, "name");

            //// 根据数据驱动名称对应的数据库实体
            //// 如果以后需要开放DeluxeWorks.Db提供自动加载第三方Database类型的话,也仅需要修改这个方法
            //switch (DbConnectionManager.GetDbProviderName(name))
            //{
            //    case "System.Data.SqlClient":
            //        return new SqlDatabase(name);
            //    case "System.Data.OracleClient":
            //        return new OracleDatabase(name);
            //    //case "Oracle.DataAccess.Client":
            //    //    return new ODP.OracleDatabase(name);
            //    default:
            //        throw new NotSupportedException(name + " 所定义的数据驱动不支持");
            //}

            return(DbConnectionManager.GetDataProvider(name) as Database);
        }
Esempio n. 6
0
        /// <summary>
        /// 根据名称得到当前引用的连接
        /// </summary>
        /// <param name="connName">数据库连接名称</param>
        /// <returns>连接对象</returns>
        protected ReferenceConnection GetRefConnectionWithoutTx(string connName)
        {
            ReferenceConnection refConnection = null;

            GraphWithoutTransaction connections = GraphWithoutTx;

            lock (connections)
            {
                if (connections.TryGetValue(connName, out refConnection) == false)
                {
                    DbConnection connection = DbConnectionManager.GetConnection(connName);
                    this.isConnectionCreator = true;

                    refConnection = new ReferenceConnection(connName, connection);
                    connections.Add(connName, refConnection);
                }
                else
                {
                    refConnection.ReferenceCount++;
                }
            }

            return(refConnection);
        }