Permalink
Browse files

CQL Query working

  • Loading branch information...
nberardi committed May 10, 2012
1 parent 66c1fd6 commit cc32376a1680870db0869094f82cbd9a52f81347
Showing with 143 additions and 5 deletions.
  1. +1 −0 src/FluentCassandra.csproj
  2. +120 −0 src/Linq/CqlObjectQuery.cs
  3. +22 −5 src/Linq/CqlObjectQueryProvider.cs
@@ -150,6 +150,7 @@
<Compile Include="IFluentBaseColumn.cs" />
<Compile Include="CassandraColumnFamilyOperations.cs" />
<Compile Include="IFluentRecordExpression.cs" />
+ <Compile Include="Linq\CqlObjectQuery.cs" />
<Compile Include="ObjectSerializer\IObjectSerializer.cs" />
<Compile Include="ObjectSerializer\ObjectSerializerConventions.cs" />
<Compile Include="Linq\CqlObjectQueryProvider.cs" />
View
@@ -0,0 +1,120 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using FluentCassandra.ObjectSerializer;
+
+namespace FluentCassandra.Linq
+{
+ public class CqlObjectQuery<T> : IQueryable, IQueryable<T>
+ {
+ private readonly Expression _expression;
+ private readonly IQueryProvider _provider;
+ private readonly CassandraColumnFamily _family;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CqlQuery&lt;T&gt;"/> class.
+ /// </summary>
+ /// <param name="expression">The expression.</param>
+ /// <param name="provider">The provider.</param>
+ public CqlObjectQuery(Expression expression, IQueryProvider provider, CassandraColumnFamily family)
+ {
+ _expression = expression;
+ _provider = provider;
+ _family = family;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public CassandraColumnFamily Family
+ {
+ get { return _family; }
+ }
+
+ #region IEnumerable Members
+
+ /// <summary>
+ /// Returns an enumerator that iterates through a collection.
+ /// </summary>
+ /// <returns>
+ /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
+ /// </returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ #endregion
+
+ #region IEnumerable<ICqlRow> Members
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public IEnumerator<T> GetEnumerator()
+ {
+ var result = CqlQueryEvaluator.GetCql(Expression);
+ var fluentObjects = _family.Cql(result);
+
+ var serializer = ObjectSerializerFactory.Get(typeof(T));
+ return serializer
+ .Deserialize(fluentObjects, _family.ObjectConventions)
+ .OfType<T>()
+ .GetEnumerator();
+ }
+
+ #endregion
+
+ #region IQueryable Members
+
+ /// <summary>
+ /// Gets the type of the element(s) that are returned when the expression tree associated with this instance of <see cref="T:System.Linq.IQueryable"/> is executed.
+ /// </summary>
+ /// <value></value>
+ /// <returns>
+ /// A <see cref="T:System.Type"/> that represents the type of the element(s) that are returned when the expression tree associated with this object is executed.
+ /// </returns>
+ public virtual Type ElementType
+ {
+ get { return typeof(T); }
+ }
+
+ /// <summary>
+ /// Gets the expression tree that is associated with the instance of <see cref="T:System.Linq.IQueryable"/>.
+ /// </summary>
+ /// <value></value>
+ /// <returns>
+ /// The <see cref="T:System.Linq.Expressions.Expression"/> that is associated with this instance of <see cref="T:System.Linq.IQueryable"/>.
+ /// </returns>
+ public Expression Expression
+ {
+ get { return _expression; }
+ }
+
+ /// <summary>
+ /// Gets the query provider that is associated with this data source.
+ /// </summary>
+ /// <value></value>
+ /// <returns>
+ /// The <see cref="T:System.Linq.IQueryProvider"/> that is associated with this data source.
+ /// </returns>
+ public IQueryProvider Provider
+ {
+ get { return _provider; }
+ }
+
+ #endregion
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public override string ToString()
+ {
+ return CqlQueryEvaluator.GetCql(Expression);
+ }
+ }
+}
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@@ -14,6 +15,12 @@ public CqlObjectQueryProvider(CassandraColumnFamily family)
_family = family;
}
+ public CqlObjectQuery<T> ToQuery()
+ {
+ var queryable = (IQueryable)this;
+ return new CqlObjectQuery<T>(queryable.Expression, this, _family);
+ }
+
#region IQueryable Members
/// <summary>
@@ -57,18 +64,28 @@ IQueryProvider IQueryable.Provider
#region IEnumerable Members
- public System.Collections.IEnumerator GetEnumerator()
+ /// <summary>
+ /// Returns an enumerator that iterates through a collection.
+ /// </summary>
+ /// <returns>
+ /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
+ /// </returns>
+ IEnumerator IEnumerable.GetEnumerator()
{
- throw new NotImplementedException();
+ return ToQuery().GetEnumerator();
}
#endregion
- #region IEnumerable<T> Members
+ #region IEnumerable<ICqlRow> Members
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
- throw new NotImplementedException();
+ return ToQuery().GetEnumerator();
}
#endregion
@@ -77,7 +94,7 @@ IEnumerator<T> IEnumerable<T>.GetEnumerator()
public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
{
- throw new NotImplementedException();
+ return new CqlObjectQuery<TElement>(expression, this, _family);
}
public IQueryable CreateQuery(Expression expression)

0 comments on commit cc32376

Please sign in to comment.