Permalink
Browse files

finished changes to work with new CQL in Cassandra 1.2

  • Loading branch information...
1 parent 13f5db5 commit bfa48acca3caa7e91b5bb0683be15f9f9b1d1e22 @nberardi nberardi committed Jan 3, 2013
View
@@ -318,20 +318,20 @@ public void SaveChanges(IFluentRecord record)
///
/// </summary>
/// <param name="cqlQuery"></param>
- public IEnumerable<ICqlRow> ExecuteQuery(UTF8Type cqlQuery)
+ public IEnumerable<ICqlRow> ExecuteQuery(UTF8Type cqlQuery, string cqlVersion = CqlVersion.ConnectionDefault)
{
- var op = new ExecuteCqlQuery(cqlQuery);
+ var op = new ExecuteCqlQuery(cqlQuery, cqlVersion);
return ExecuteOperation(op);
}
/// <summary>
///
/// </summary>
/// <param name="cqlQuery"></param>
- public void TryExecuteNonQuery(UTF8Type cqlQuery)
+ public void TryExecuteNonQuery(UTF8Type cqlQuery, string cqlVersion = CqlVersion.ConnectionDefault)
{
try {
- ExecuteNonQuery(cqlQuery);
+ ExecuteNonQuery(cqlQuery, cqlVersion);
} catch (Exception exc) {
Debug.WriteLine(exc);
}
@@ -341,19 +341,19 @@ public void TryExecuteNonQuery(UTF8Type cqlQuery)
///
/// </summary>
/// <param name="cqlQuery"></param>
- public void ExecuteNonQuery(UTF8Type cqlQuery)
+ public void ExecuteNonQuery(UTF8Type cqlQuery, string cqlVersion = CqlVersion.ConnectionDefault)
{
- var op = new ExecuteCqlNonQuery(cqlQuery);
+ var op = new ExecuteCqlNonQuery(cqlQuery, cqlVersion);
ExecuteOperation(op);
}
/// <summary>
- /// The last error that occured during the execution of an operation.
+ /// The last error that occurred during the execution of an operation.
/// </summary>
public CassandraException LastError { get; private set; }
/// <summary>
- /// Indicates if errors should be thrown when occuring on operation.
+ /// Indicates if errors should be thrown when occurring on operation.
/// </summary>
public bool ThrowErrors { get; set; }
@@ -178,6 +178,7 @@ public void SetKeyspace(string keyspace)
///
/// </summary>
/// <param name="cqlVersion"></param>
+ [Obsolete("This will be retired soon, please pass the CQL version through the Execute method.", error: false)]
public void SetCqlVersion(string cqlVersion)
{
CheckWasDisposed();
@@ -37,7 +37,7 @@ public ConnectionBuilder(string keyspace, string host, int port = Server.Default
ConnectionString = GetConnectionString();
}
- public ConnectionBuilder(string keyspace, Server server, bool pooling = false, int minPoolSize = 0, int maxPoolSize = 100, int maxRetries = 0, int serverPollingInterval = 30, int connectionLifetime = 0, ConnectionType connectionType = ConnectionType.Framed, int bufferSize = 1024, ConsistencyLevel read = ConsistencyLevel.QUORUM, ConsistencyLevel write = ConsistencyLevel.QUORUM, string cqlVersion = FluentCassandra.Connections.CqlVersion.ServerDefault, bool compressCqlQueries = true, string username = null, string password = null)
+ public ConnectionBuilder(string keyspace, Server server, bool pooling = false, int minPoolSize = 0, int maxPoolSize = 100, int maxRetries = 0, int serverPollingInterval = 30, int connectionLifetime = 0, ConnectionType connectionType = ConnectionType.Framed, int bufferSize = 1024, ConsistencyLevel read = ConsistencyLevel.QUORUM, ConsistencyLevel write = ConsistencyLevel.QUORUM, string cqlVersion = FluentCassandra.Connections.CqlVersion.Edge, bool compressCqlQueries = true, string username = null, string password = null)
eplowe
eplowe Jan 7, 2013 Contributor

@nberardi Seems like the first constructor for ConnectionBuilder is using:

string cqlVersion = FluentCassandra.Connections.CqlVersion.ServerDefault

That's why you saw the commit come over on my fork.

{
Keyspace = keyspace;
Servers = new List<Server>() { server };
@@ -311,7 +311,7 @@ private void InitializeConnectionString(string connectionString)
if (!pairs.ContainsKey("CQL Version"))
{
- CqlVersion = FluentCassandra.Connections.CqlVersion.ServerDefault;
+ CqlVersion = FluentCassandra.Connections.CqlVersion.Edge;
}
else
{
@@ -3,12 +3,14 @@
namespace FluentCassandra.Connections
{
- public sealed class CqlVersion
+ public static class CqlVersion
{
- public const string Cql2 = "2.0.0";
+ public const string Cql = "0.8.0";
public const string Cql3 = "3.0.0";
+ public const string Edge = Cql3;
+ public const string ConnectionDefault = null;
+ [Obsolete("This is no longer supported, please use ConnectionDefault", error: true)]
public const string ServerDefault = null;
- public const string Edge = Cql3;
}
}
@@ -12,6 +12,8 @@ public interface IConnection : IDisposable
Cassandra.Client Client { get; }
void SetKeyspace(string keyspace);
+
+ [Obsolete("This will be retired soon, please pass the CQL version through the Execute method.", error: false)]
void SetCqlVersion(string cqlVersion);
void Open();
@@ -8,30 +8,46 @@ namespace FluentCassandra.Operations
public class ExecuteCqlNonQuery : Operation<Void>
{
public UTF8Type CqlQuery { get; private set; }
-
- public bool CompressCqlQuery { get; private set; }
+ public string CqlVersion { get; private set; }
public override Void Execute()
{
Debug.Write(CqlQuery.ToString(), "query");
byte[] query = CqlQuery;
bool isCqlQueryCompressed = query.Length > 200 && Session.ConnectionBuilder.CompressCqlQueries;
- // it doesn't make sense to compress queryies that are really small
+ // it doesn't make sense to compress queries that are really small
if (isCqlQueryCompressed)
query = Helper.ZlibCompress(query);
- var result = Session.GetClient().execute_cql_query(
- query,
- isCqlQueryCompressed ? Apache.Cassandra.Compression.GZIP : Apache.Cassandra.Compression.NONE
- );
+ if (CqlVersion == FluentCassandra.Connections.CqlVersion.ConnectionDefault)
+ CqlVersion = Session.ConnectionBuilder.CqlVersion;
+
+ switch(CqlVersion) {
+ case FluentCassandra.Connections.CqlVersion.Cql:
+ Session.GetClient().execute_cql_query(
+ query,
+ isCqlQueryCompressed ? Apache.Cassandra.Compression.GZIP : Apache.Cassandra.Compression.NONE);
+ break;
+
+ case FluentCassandra.Connections.CqlVersion.Cql3:
+ Session.GetClient().execute_cql3_query(
+ query,
+ isCqlQueryCompressed ? Apache.Cassandra.Compression.GZIP : Apache.Cassandra.Compression.NONE,
+ Session.WriteConsistency);
+ break;
+
+ default:
+ throw new FluentCassandraException(CqlVersion + " is not a valid CQL version.");
+ }
return new Void();
}
- public ExecuteCqlNonQuery(UTF8Type cqlQuery)
+ public ExecuteCqlNonQuery(UTF8Type cqlQuery, string cqlVersion)
{
CqlQuery = cqlQuery;
+ CqlVersion = cqlVersion;
}
}
}
@@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
+using FluentCassandra.Apache.Cassandra;
using FluentCassandra.Linq;
using FluentCassandra.Types;
@@ -13,6 +14,7 @@ public class ExecuteCqlQuery : ColumnFamilyOperation<IEnumerable<ICqlRow>>
private static readonly Regex ColumnFamilyNameExpression = new Regex(@"FROM\s+(?<name>\w+)");
public UTF8Type CqlQuery { get; private set; }
+ public string CqlVersion { get; private set; }
private string TryGetFamilyName()
{
@@ -34,14 +36,32 @@ public override IEnumerable<ICqlRow> Execute()
byte[] query = CqlQuery;
bool isCqlQueryCompressed = query.Length > 200 && Session.ConnectionBuilder.CompressCqlQueries;
- // it doesn't make sense to compress queryies that are really small
+ // it doesn't make sense to compress queries that are really small
if (isCqlQueryCompressed)
query = Helper.ZlibCompress(query);
- var result = Session.GetClient().execute_cql_query(
- query,
- isCqlQueryCompressed ? Apache.Cassandra.Compression.GZIP : Apache.Cassandra.Compression.NONE
- );
+ if (CqlVersion == FluentCassandra.Connections.CqlVersion.ConnectionDefault)
+ CqlVersion = Session.ConnectionBuilder.CqlVersion;
+
+ var result = (CqlResult)null;
+
+ switch (CqlVersion) {
+ case FluentCassandra.Connections.CqlVersion.Cql:
+ result = Session.GetClient().execute_cql_query(
+ query,
+ isCqlQueryCompressed ? Apache.Cassandra.Compression.GZIP : Apache.Cassandra.Compression.NONE);
+ break;
+
+ case FluentCassandra.Connections.CqlVersion.Cql3:
+ result = Session.GetClient().execute_cql3_query(
+ query,
+ isCqlQueryCompressed ? Apache.Cassandra.Compression.GZIP : Apache.Cassandra.Compression.NONE,
+ Session.ReadConsistency);
+ break;
+
+ default:
+ throw new FluentCassandraException(CqlVersion + " is not a valid CQL version.");
+ }
return GetRows(result);
}
@@ -78,9 +98,10 @@ private IEnumerable<FluentColumn> GetColumns(Apache.Cassandra.CqlRow row, Cassan
return list;
}
- public ExecuteCqlQuery(UTF8Type cqlQuery)
+ public ExecuteCqlQuery(UTF8Type cqlQuery, string cqlVersion)
{
CqlQuery = cqlQuery;
+ CqlVersion = cqlVersion;
}
}
}
@@ -21,10 +21,10 @@ public void Dispose()
}
[Fact]
- public void Test_Cql2()
+ public void Test_Cql()
{
var connBuilder = _db.ConnectionBuilder;
- connBuilder = new ConnectionBuilder(connBuilder.Keyspace, connBuilder.Servers[0], cqlVersion: CqlVersion.Cql2);
+ connBuilder = new ConnectionBuilder(connBuilder.Keyspace, connBuilder.Servers[0], cqlVersion: CqlVersion.Cql);
var db = new CassandraContext(connBuilder);
// arrange

0 comments on commit bfa48ac

Please sign in to comment.