Пример #1
0
        /// <summary>
        /// 按照Builder查询应用所包含的元素(角色和权限)
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="includingDeleted"></param>
        /// <param name="timePoint"></param>
        /// <returns></returns>
        public SchemaObjectCollection QueryApplicationObjectsByBuilder(IConnectiveSqlClause builder, bool includingDeleted, DateTime timePoint)
        {
            builder.NullCheck("builder");

            SchemaObjectCollection result = new SchemaObjectCollection();

            if (builder.IsEmpty == false)
            {
                IConnectiveSqlClause extraBuilder = CreateStatusAndTimePointBuilder(includingDeleted, timePoint,
                                                                                    "SC.", "A.", "M.");

                ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(builder, extraBuilder);

                string resourcePath = "QueryApplicationObjects_Current.sql";

                if (timePoint != DateTime.MinValue && includingDeleted == true)
                {
                    resourcePath = "QueryApplicationObjects.sql";
                }

                string sqlTemplate = ResourceHelper.LoadStringFromResource(Assembly.GetExecutingAssembly(), string.Concat("MCS.Library.SOA.DataObjects.Security.Adapters.Templates.", resourcePath));

                string sql = string.Format(sqlTemplate, connectiveBuilder.ToSqlString(TSqlBuilder.Instance));

                DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0];

                result.LoadFromDataView(table.DefaultView);
            }

            return(result);
        }
        /// <summary>
        /// 按照Builder查询应用所包含的元素(角色和权限)
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="includingDeleted"></param>
        /// <param name="timePoint"></param>
        /// <returns></returns>
        public SchemaObjectCollection QueryApplicationObjectsByBuilder(IConnectiveSqlClause builder, bool includingDeleted, DateTime timePoint)
        {
            builder.NullCheck("builder");

            SchemaObjectCollection result = new SchemaObjectCollection();

            if (builder.IsEmpty == false)
            {
                IConnectiveSqlClause extraBuilder = CreateStatusAndTimePointBuilder(includingDeleted, timePoint,
                    "SC.", "A.", "M.");

                ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(builder, extraBuilder);

                string resourcePath = "QueryApplicationObjects_Current.sql";

                if (timePoint != DateTime.MinValue && includingDeleted == true)
                    resourcePath = "QueryApplicationObjects.sql";

                string sqlTemplate = ResourceHelper.LoadStringFromResource(Assembly.GetExecutingAssembly(), string.Concat("MCS.Library.SOA.DataObjects.Security.Adapters.Templates.", resourcePath));

                string sql = string.Format(sqlTemplate, connectiveBuilder.ToSqlString(TSqlBuilder.Instance));

                DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0];

                result.LoadFromDataView(table.DefaultView);
            }

            return result;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ownerKeyBuilder"></param>
        /// <param name="data"></param>
        /// <param name="ignoreProperties">需要忽略的属性</param>
        public void UpdateCollectionInContext(IConnectiveSqlClause ownerKeyBuilder, IEnumerable <T> data, params string[] ignoreProperties)
        {
            ownerKeyBuilder.NullCheck("ownerKeyBuilder");
            data.NullCheck("objs");

            Dictionary <string, object> context = new Dictionary <string, object>();

            SqlContextItem sqlContext = this.GetSqlContext();

            this.BeforeInnerUpdateCollectionInContext(data, sqlContext, context);

            string sql = VersionStrategyUpdateSqlBuilder <T> .DefaultInstance.ToUpdateCollectionSql(ownerKeyBuilder, this.GetMappingInfo(), data, false, ignoreProperties);

            sqlContext.AppendSqlWithSperatorInContext(TSqlBuilder.Instance, sql);
        }
Пример #4
0
        /// <summary>
        /// 根据外界的builder加载数据
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="orderByBuilder"></param>
        /// <returns></returns>
        public virtual TCollection LoadByBuilder(IConnectiveSqlClause builder, OrderBySqlClauseBuilder orderByBuilder)
        {
            builder.NullCheck("builder");

            TCollection result = null;

            PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadByBuilder({0})", this.GetType().FullName), () =>
            {
                result = InnerLoadByBuilder(builder.ToSqlString(TSqlBuilder.Instance),
                                            orderByBuilder,
                                            this.GetQueryMappingInfo());
            });

            return(result);
        }
Пример #5
0
        /// <summary>
        /// 得到更新当前快照的SQL
        /// </summary>
        /// <param name="srcTableName"></param>
        /// <param name="targetTableName"></param>
        /// <param name="builder"></param>
        /// <returns></returns>
        private string GetInternalUpdateCurrentSnapshotSql(string srcTableName, string targetTableName, IConnectiveSqlClause builder)
        {
            builder.NullCheck("builder");

            StringBuilder strB = new StringBuilder();

            if (builder.IsEmpty == false)
            {
                IConnectiveSqlClause timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(DateTime.MinValue);

                ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(builder, timePointBuilder);

                string sql = string.Format("SELECT * FROM {0} WHERE Status = {1} AND {2}",
                                           srcTableName,
                                           (int)SchemaObjectStatus.Normal,
                                           connectiveBuilder.ToSqlString(TSqlBuilder.Instance));

                DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0];

                if (table.Rows.Count > 0)
                {
                    UpdateSqlClauseBuilder updateBuilder = new UpdateSqlClauseBuilder();
                    DataRowToBuilder(table.Rows[0], updateBuilder, "RowUniqueID");

                    InsertSqlClauseBuilder insertBuilder = new InsertSqlClauseBuilder();
                    DataRowToBuilder(table.Rows[0], insertBuilder);

                    strB.AppendFormat("UPDATE {0} SET {1} WHERE {2}",
                                      targetTableName,
                                      updateBuilder.ToSqlString(TSqlBuilder.Instance),
                                      builder.ToSqlString(TSqlBuilder.Instance));

                    strB.Append(TSqlBuilder.Instance.DBStatementSeperator);
                    strB.Append("IF @@ROWCOUNT = 0");
                    strB.Append(TSqlBuilder.Instance.DBStatementSeperator);
                    strB.AppendFormat("INSERT INTO {0} {1}",
                                      targetTableName,
                                      insertBuilder.ToSqlString(TSqlBuilder.Instance));
                }
                else
                {
                    strB.AppendFormat("DELETE {0} WHERE {1}", targetTableName, builder.ToSqlString(TSqlBuilder.Instance));
                }
            }

            return(strB.ToString());
        }
Пример #6
0
        public string GetUpdateCurrentSnapshotSql(string srcTableName, string targetTableName, IConnectiveSqlClause builder)
        {
            builder.NullCheck("builder");

            StringBuilder strB = new StringBuilder();

            if (builder.IsEmpty == false)
            {
                strB.AppendFormat("DELETE {0} WHERE {1}", targetTableName, builder.ToSqlString(TSqlBuilder.Instance));
                strB.Append(TSqlBuilder.Instance.DBStatementSeperator);

                IConnectiveSqlClause timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(DateTime.MinValue);

                ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(builder, timePointBuilder);

                strB.AppendFormat("INSERT INTO {0} SELECT * FROM {1} WHERE Status = {2} AND {3}",
                                  targetTableName, srcTableName, (int)SchemaObjectStatus.Normal, connectiveBuilder.ToSqlString(TSqlBuilder.Instance));
            }

            return(strB.ToString());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ownerKeyBuilder"></param>
        /// <param name="data"></param>
        public void UpdateCollection(IConnectiveSqlClause ownerKeyBuilder, IEnumerable <T> data)
        {
            ownerKeyBuilder.NullCheck("ownerKeyBuilder");
            data.NullCheck("objs");

            Dictionary <string, object> context = new Dictionary <string, object>();

            this.BeforeInnerUpdateCollection(data, context);

            string sql = VersionStrategyUpdateSqlBuilder <T> .DefaultInstance.ToUpdateCollectionSql(ownerKeyBuilder, this.GetMappingInfo(), data);

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DateTime dt = (DateTime)DbHelper.RunSqlReturnScalar(sql, this.GetConnectionName());

                this.AfterInnerUpdateCollection(data, context);

                DBTimePointActionContext.Current.TimePoint.IsMinValue(() => DBTimePointActionContext.Current.TimePoint = dt);

                scope.Complete();
            }
        }