当前位置: 首页>>代码示例>>C#>>正文


C# IConnectionProvider.CloseConnection方法代码示例

本文整理汇总了C#中IConnectionProvider.CloseConnection方法的典型用法代码示例。如果您正苦于以下问题:C# IConnectionProvider.CloseConnection方法的具体用法?C# IConnectionProvider.CloseConnection怎么用?C# IConnectionProvider.CloseConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConnectionProvider的用法示例。


在下文中一共展示了IConnectionProvider.CloseConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BulkSave

        public void BulkSave(IConnectionProvider conn, IEntityCollection entitiesToSave, IEntityDaoFactory daoFactory)
        {
            IEntityCollection newEntities, changedEntities, removedEntities;
            SplitCollectionForInsertUpdateAndDeleteOperations(entitiesToSave, out newEntities, out changedEntities, out removedEntities);

            bool connIsLocal = !conn.IsOpen;
            if (connIsLocal)
                conn.OpenConnection();

            try
            {
                BulkInsert(conn, newEntities, daoFactory);
                BulkUpdate(conn, changedEntities, daoFactory);
                BulkDelete(conn, removedEntities, daoFactory);
            }
            finally
            {
                if (connIsLocal)
                    conn.CloseConnection();
            }
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:21,代码来源:SqlServerBulkSaver.cs

示例2: MaxOfAll

        private static object MaxOfAll(IConnectionProvider conn, IEntity rootEntity, IDbColumn column, DbRelation recursiveRelation, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: count returns zero.
            object maximum = null;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    object levelMax;
                    int nodeCount;
                    FetchMaxFromColumnAndCountAllNodesAtLevel(conn, rootEntity, recursiveRelation, level, column.ColumnName, out levelMax, out nodeCount);

                    maximum = MaxOfNullableValues(maximum as IComparable, levelMax as IComparable);
                    reachedEndLevel = (nodeCount == 0) || (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            if (maximum == null)
                maximum = DBNull.Value;

            return maximum;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:34,代码来源:GenericHierarchicalQueryExecutor.cs

示例3: MaxWithLeafFilter

        private static object MaxWithLeafFilter(IConnectionProvider conn, IEntity rootEntity, IDbColumn column, DbRelation recursiveRelation, SearchCondition leafFilter, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: final level reached (tree depth is measured).
            object maximum = null;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                endAtLevel = GetEndLevel(conn, rootEntity, recursiveRelation, endAtLevel);
                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    SelectStatement maxAtLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, leafFilter, level, LevelQuerySelectList.Default);
                    maxAtLevel.SelectList.Clear();
                    IDbColumn comparedColumn = maxAtLevel.FromTable.Columns.GetByColumnName(column.ColumnName);
                    maxAtLevel.SelectList.Add(AggregateFunctionFactory.Max(comparedColumn, "levelMax"));
                    DataTable results = maxAtLevel.Execute(conn);
                    object levelMax = results.Rows[0]["levelMax"];

                    maximum = MaxOfNullableValues(maximum as IComparable, levelMax as IComparable);
                    reachedEndLevel = (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            if (maximum == null)
                maximum = DBNull.Value;

            return maximum;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:38,代码来源:GenericHierarchicalQueryExecutor.cs

示例4: SumAll

        private static object SumAll(IConnectionProvider conn, IEntity rootEntity, IDbColumn column, DbRelation recursiveRelation, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: count returns zero.
            object totalSum = null;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    SelectStatement sumAtLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, null, level, LevelQuerySelectList.Default);
                    sumAtLevel.SelectList.Clear();
                    IDbColumn summedColumn = sumAtLevel.FromTable.Columns.GetByColumnName(column.ColumnName);
                    sumAtLevel.SelectList.Add(AggregateFunctionFactory.Sum(summedColumn, false, "levelSum"));
                    sumAtLevel.SelectList.Add(AggregateFunctionFactory.Count("nodeCount"));
                    DataTable results = sumAtLevel.Execute(conn);
                    object levelSum = results.Rows[0]["levelSum"];
                    int nodeCount = Convert.ToInt32(results.Rows[0]["nodeCount"], CultureInfo.InvariantCulture);

                    totalSum = SumNullableValues(column, totalSum, levelSum);
                    reachedEndLevel = (nodeCount == 0) || (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return totalSum;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:36,代码来源:GenericHierarchicalQueryExecutor.cs

示例5: SumWithLeafFilter

        private static object SumWithLeafFilter(IConnectionProvider conn, IEntity rootEntity, IDbColumn column, DbRelation recursiveRelation, SearchCondition leafFilter, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: final level reached (tree depth is measured).
            object totalSum = null;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                endAtLevel = GetEndLevel(conn, rootEntity, recursiveRelation, endAtLevel);
                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    SelectStatement sumAtLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, leafFilter, level, LevelQuerySelectList.Default);
                    sumAtLevel.SelectList.Clear();
                    IDbColumn summedColumn = sumAtLevel.FromTable.Columns.GetByColumnName(column.ColumnName);
                    sumAtLevel.SelectList.Add(AggregateFunctionFactory.Sum(summedColumn, false, "levelSum"));
                    DataTable results = sumAtLevel.Execute(conn);
                    object levelSum = results.Rows[0]["levelSum"];

                    totalSum = SumNullableValues(column, totalSum, levelSum);
                    reachedEndLevel = (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return totalSum;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:35,代码来源:GenericHierarchicalQueryExecutor.cs

示例6: CountAll

        private static int CountAll(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: count returns zero.
            int totalCount = 0;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    SelectStatement countAtLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, null, level, LevelQuerySelectList.Count);
                    DataTable results = countAtLevel.Execute(conn);
                    int nodeCount = Convert.ToInt32(results.Rows[0][0], CultureInfo.InvariantCulture);

                    totalCount += nodeCount;
                    reachedEndLevel = (nodeCount == 0) || (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return totalCount;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:31,代码来源:GenericHierarchicalQueryExecutor.cs

示例7: CountWithLeafFilter

        private static int CountWithLeafFilter(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, SearchCondition leafFilter, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: final level reached (tree depth is measured).
            int totalCount = 0;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                endAtLevel = GetEndLevel(conn, rootEntity, recursiveRelation, endAtLevel);
                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    SelectStatement countAtLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, leafFilter, level, LevelQuerySelectList.Count);
                    DataTable results = countAtLevel.Execute(conn);
                    totalCount += Convert.ToInt32(results.Rows[0][0], CultureInfo.InvariantCulture);

                    reachedEndLevel = (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return totalCount;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:31,代码来源:GenericHierarchicalQueryExecutor.cs

示例8: UpdateAll

        private static int UpdateAll(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, UpdateList setExpressions, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: rowsAffected == 0
            int totalRowsAffected = 0;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.BeginTransaction();

                // We need to perform COUNT at least once to determine whether rowsAffacted returned by UPDATE can be trusted.
                RowsAffectedCredibility trustRowsAffected = RowsAffectedCredibility.NotDetermined;
                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    // Dependening on DBMS configuration, update statements may automatically return the number of rows affected.
                    int rowsAffectedReturnedByEngine = UpdateAtLevel(conn, rootEntity, recursiveRelation, setExpressions, level);

                    // We need to perform manual counting for as long as rows affected cannot be trusted.
                    int? manualNodeCount = CountNodesAtLevelIfRowsAffectedCannotBeTrusted(conn, rootEntity, trustRowsAffected, recursiveRelation, level);                    
                    
                    // Evaluation which determines whether rows affected may be trusted takes place only once, ie. if not yet determined.
                    bool evaluateRowsAffectedCredibility = (trustRowsAffected == RowsAffectedCredibility.NotDetermined) && (manualNodeCount.HasValue);
                    if (evaluateRowsAffectedCredibility)
                    {
                        bool engineCountMatchesManualCount = (rowsAffectedReturnedByEngine == manualNodeCount.Value);
                        trustRowsAffected = (engineCountMatchesManualCount) ? RowsAffectedCredibility.Trusted : RowsAffectedCredibility.Untrusted;
                    }

                    // Manual node count is null if we have determined that rows affected value returned by engine is credible.
                    int rowsUpdatedInCurrentLevel = manualNodeCount ?? rowsAffectedReturnedByEngine;
                    totalRowsAffected += rowsUpdatedInCurrentLevel;
                    
                    // Inspect stop condition before level variable is increased.
                    reachedEndLevel = IsEndLevelReached(endAtLevel, level, rowsUpdatedInCurrentLevel);

                    // Next level.
                    level++;
                } while (!reachedEndLevel);

                if (isLocalConn)
                    conn.CommitTransaction();
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return totalRowsAffected;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:52,代码来源:GenericHierarchicalQueryExecutor.cs

示例9: UpdateWithLeafFilter

        private static int UpdateWithLeafFilter(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, UpdateList setExpressions, SearchCondition leafFilter, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: final level reached (tree depth is measured).
            // It's possible that at some intermediate levels no records satisfy the specified criteria.
            // Nevertheless, the algorithm must proceed to the next level where it might find matching records.
            // This behavior simulates the behavior of recursive CTEs.
            int totalRowsAffected = 0;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.BeginTransaction();

                endAtLevel = GetEndLevel(conn, rootEntity, recursiveRelation, endAtLevel);
                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    UpdateStatement updateAtLevel = CreateUpdateLevelStatement(rootEntity, recursiveRelation, setExpressions, leafFilter, level);
                    totalRowsAffected += updateAtLevel.Execute(conn);

                    reachedEndLevel = (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);

                if (isLocalConn)
                    conn.CommitTransaction();
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return totalRowsAffected;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:36,代码来源:GenericHierarchicalQueryExecutor.cs

示例10: DetermineTreeDepthInternal

        private static int DetermineTreeDepthInternal(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation)
        {
            EnsureRecursiveRelation(recursiveRelation);
            int depth = 0;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                bool reachedEndLevel = false;
                do
                {
                    SelectStatement countAtLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, null, depth, LevelQuerySelectList.Count);
                    DataTable results = countAtLevel.Execute(conn);
                    int nodeCount = Convert.ToInt32(results.Rows[0][0], CultureInfo.InvariantCulture);
                    if (nodeCount > 0)
                        depth++;
                    else
                        reachedEndLevel = true;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return depth;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:30,代码来源:GenericHierarchicalQueryExecutor.cs

示例11: SelectAll

        private static DataTable SelectAll(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: select returns nothing.
            DataTable mergedData = null;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    SelectStatement fetchLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, null, level, LevelQuerySelectList.AllColumns);
                    DataTable levelData = fetchLevel.Execute(conn);
                    if (levelData.Rows.Count > 0)
                        AppendData(levelData, ref mergedData);

                    reachedEndLevel = (levelData.Rows.Count == 0) || (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return mergedData;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:31,代码来源:GenericHierarchicalQueryExecutor.cs

示例12: SelectWithLeafFilter

        private static DataTable SelectWithLeafFilter(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, SearchCondition leafFilter, int beginAtLevel, int endAtLevel)
        {
            // Stop condition: final level reached (tree depth is measured).
            // It's possible that at some intermediate levels no records satisfy the specified criteria.
            // Nevertheless, the algorithm must proceed to the next level where it might find matching records.
            // This behavior simulates the behavior of recursive CTEs.
            DataTable mergedData = null;
            bool isLocalConn = !conn.IsOpen;
            try
            {
                if (isLocalConn)
                    conn.OpenConnection();

                endAtLevel = GetEndLevel(conn, rootEntity, recursiveRelation, endAtLevel);
                bool reachedEndLevel = false;
                int level = beginAtLevel;
                do
                {
                    SelectStatement fetchLevel = CreateSelectFromLevelQuery(rootEntity, recursiveRelation, leafFilter, level, LevelQuerySelectList.AllColumns);
                    DataTable levelData = fetchLevel.Execute(conn);
                    if (levelData.Rows.Count > 0)
                        AppendData(levelData, ref mergedData);

                    reachedEndLevel = (level >= endAtLevel);
                    level++;
                } while (!reachedEndLevel);
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }

            return mergedData;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:35,代码来源:GenericHierarchicalQueryExecutor.cs

示例13: CloseConnectionIfLocal

 private static void CloseConnectionIfLocal(IConnectionProvider conn, bool connIsOpennedLocally)
 {
     // Close connection if it was openned in this method.
     if (connIsOpennedLocally)
         conn.CloseConnection();
 }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:6,代码来源:DbUtil.cs

示例14: InsertAndSelectAutoNumber

        private static object InsertAndSelectAutoNumber(IConnectionProvider conn, string command, DbParameterCollection parameters, int cmdTimeout = 30)
        {
            bool isLocalConn = !conn.IsOpen;
            if (isLocalConn)
                conn.OpenConnection();

            try
            {
                DbUtil.ExecuteNonQuery(conn, command, parameters, CommandType.Text, cmdTimeout);
                // ROWID is always a 64bit integer.
                DataTable data = DbUtil.ExecuteQuery(conn, "SELECT last_insert_rowid()", new DbParameterCollection(), CommandType.Text, null, cmdTimeout);
                int lastId = Convert.ToInt32(data.Rows[0][0], CultureInfo.InvariantCulture);
                return lastId;
            }
            finally
            {
                if (isLocalConn)
                    conn.CloseConnection();
            }
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:20,代码来源:SQLiteInserter.cs

示例15: BulkDelete

        public void BulkDelete(IConnectionProvider conn, IEntityCollection removedEntities, IEntityDaoFactory daoFactory)
        {
            if (removedEntities.Count == 0)
                return;

            bool connIsLocal = !conn.IsOpen;
            if (connIsLocal)
                conn.OpenConnection();

            try
            {
                foreach (IEntity entity in removedEntities)
                    GetDao(conn, entity, daoFactory).DeleteOne();
            }
            finally
            {
                if (connIsLocal)
                    conn.CloseConnection();
            }
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:20,代码来源:SqlServerBulkSaver.cs


注:本文中的IConnectionProvider.CloseConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。