Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Removed the concept of a 'local session'. If a session is passed in,
Browse files Browse the repository at this point in the history
it will not be disposed off on the dispose method of CassandraContext like
normal. Added a CloseClient method to CassandraSession and call it in the
finally block of CassandraContext::ExecuteOperation to, based on the pool
type, close the connection to the server, or release the connection back
to the pool. This should suffice contexts being kept around for a while be
it in a static var etc etc. We definetly need to rework the connection
concepts but for the mean time this should work.
  • Loading branch information
eplowe committed Nov 15, 2012
1 parent 4423a23 commit 79db9aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion FluentCassandra.sln
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCassandra", "src\FluentCassandra.csproj", "{EAA32600-3C2A-4B34-B9B2-5764F280FCE3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCassandra.Sandbox", "test\FluentCassandra.Sandbox\FluentCassandra.Sandbox.csproj", "{DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}"
Expand Down
14 changes: 6 additions & 8 deletions src/CassandraContext.cs
Expand Up @@ -371,24 +371,22 @@ public TResult ExecuteOperation<TResult>(Operation<TResult> action, bool? throwO
if (WasDisposed)
throw new ObjectDisposedException(GetType().FullName);

var localSession = _session == null;
var session = _session;
if (session == null)
session = new CassandraSession(ConnectionBuilder);
if (_session == null)
_session = new CassandraSession(ConnectionBuilder);

action.Context = this;

try
{
var result = session.ExecuteOperation(action, throwOnError ?? ThrowErrors);
LastError = session.LastError;
var result = _session.ExecuteOperation(action, throwOnError ?? ThrowErrors);
LastError = _session.LastError;

return result;
}
finally
{
if (localSession && session != null)
session.Dispose();
if (_session != null)
_session.CloseClient();
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/CassandraSession.cs
Expand Up @@ -117,6 +117,15 @@ internal CassandraClientWrapper GetClient(bool setKeyspace = true, bool? setCqlV
return new CassandraClientWrapper(_connection.Client);
}


internal void CloseClient()
{
if (_connection != null)
{
ConnectionProvider.Close(_connection);
}
}

/// <summary>
///
/// </summary>
Expand Down

0 comments on commit 79db9aa

Please sign in to comment.