Permalink
Browse files

Removed the concept of a 'local session'. If a session is passed in,

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...
1 parent 4423a23 commit 79db9aa6a9b6ba94d4544c4ff6850ccd60a33276 @eplowe eplowe committed Nov 15, 2012
Showing with 16 additions and 9 deletions.
  1. +1 −1 FluentCassandra.sln
  2. +6 −8 src/CassandraContext.cs
  3. +9 −0 src/CassandraSession.cs
View
2 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}"
View
14 src/CassandraContext.cs
@@ -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();
}
}
View
9 src/CassandraSession.cs
@@ -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>

0 comments on commit 79db9aa

Please sign in to comment.