本文整理汇总了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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例13: CloseConnectionIfLocal
private static void CloseConnectionIfLocal(IConnectionProvider conn, bool connIsOpennedLocally)
{
// Close connection if it was openned in this method.
if (connIsOpennedLocally)
conn.CloseConnection();
}
示例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();
}
}
示例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();
}
}