private static object BuildOperation <TResult>(CassandraQuerySetup setup, CassandraSlicePredicate predicate, IDictionary <string, object> calls) { if (calls.ContainsKey("CountColumnsByKey")) { return(new MultiGetColumnCount(setup.Keys, setup.SuperColumnName, predicate)); } if (calls.ContainsKey("CountColumns")) { return(new ColumnCount(setup.Keys.First(), setup.SuperColumnName, predicate)); } var forSuperColumn = typeof(TResult) == typeof(FluentSuperColumnFamily); if (!forSuperColumn && setup.SuperColumnName != null) { throw new CassandraException("'ForSuperColumn' can only be used on a super column family."); } if (forSuperColumn) { if (setup.IndexClause != null) { var indexClause = new CassandraIndexClause(setup.StartKey, setup.ColumnCount, setup.IndexClause); return(new GetSuperColumnFamilyIndexedSlices(indexClause, predicate)); } else if (setup.Keys.Count() > 0) { return(new MultiGetSuperColumnFamilySlice(setup.Keys, setup.SuperColumnName, predicate)); } else { var keyRange = new CassandraKeyRange(setup.StartKey, setup.EndKey, setup.StartToken, setup.EndToken, setup.KeyCount); return(new GetSuperColumnFamilyRangeSlices(keyRange, setup.SuperColumnName, predicate)); } } else { if (setup.IndexClause != null) { var indexClause = new CassandraIndexClause(setup.StartKey, setup.KeyCount, setup.IndexClause); return(new GetColumnFamilyIndexedSlices(indexClause, predicate)); } else if (setup.Keys.Count() > 0) { return(new MultiGetColumnFamilySlice(setup.Keys, predicate)); } else { var keyRange = new CassandraKeyRange(setup.StartKey, setup.EndKey, setup.StartToken, setup.EndToken, setup.KeyCount); return(new GetColumnFamilyRangeSlices(keyRange, predicate)); } } }
private static CassandraSlicePredicate BuildSlicePredicate(CassandraQuerySetup setup) { if (setup.Columns.Count() > 0) return new CassandraColumnSlicePredicate(setup.Columns); return new CassandraRangeSlicePredicate( setup.StartColumn, setup.EndColumn, setup.Reverse, setup.ColumnCount); }
internal CassandraSlicePredicateQuery(CassandraQuerySetup <TResult, CompareWith> setup, BaseCassandraColumnFamily family, Expression expression) { Setup = setup; Family = family; Expression = expression; if (Expression == null) { Expression = Expression.Constant(this); } }
private static CassandraQuerySetup BuildQuerySetup(IDictionary<string, object> calls) { var setup = new CassandraQuerySetup(); object keyCount; if (calls.TryGetValue("TakeKeys", out keyCount)) setup.KeyCount = (int)keyCount; object columnCount; if (calls.TryGetValue("TakeColumns", out columnCount)) setup.ColumnCount = (int)columnCount; object keys; if (calls.TryGetValue("FetchKeys", out keys)) setup.Keys = (CassandraObject[])keys; object columns; if (calls.TryGetValue("FetchColumns", out columns)) setup.Columns = (CassandraObject[])columns; object startKey; if (calls.TryGetValue("StartWithKey", out startKey)) setup.StartKey = (CassandraObject)startKey; object endKey; if (calls.TryGetValue("TakeUntilKey", out endKey)) setup.EndKey = (CassandraObject)endKey; object startColumn; if (calls.TryGetValue("StartWithColumn", out startColumn)) setup.StartColumn = (CassandraObject)startColumn; object endColumn; if (calls.TryGetValue("TakeUntilColumn", out endColumn)) setup.EndColumn = (CassandraObject)endColumn; object startToken; if (calls.TryGetValue("StartWithToken", out startToken)) setup.StartToken = (string)startToken; object endToken; if (calls.TryGetValue("TakeUntilToken", out endToken)) setup.EndToken = (string)endToken; object superColumnName; if (calls.TryGetValue("ForSuperColumn", out superColumnName)) setup.SuperColumnName = (CassandraObject)superColumnName; object indexClause; if (calls.TryGetValue("Where", out indexClause)) setup.IndexClause = (Expression<Func<IFluentRecordExpression, bool>>)indexClause; setup.Reverse = calls.ContainsKey("ReverseColumns"); if (calls.ContainsKey("CountColumnsByKey") && setup.Columns.Count() > 0) throw new CassandraException("'FetchKeys' must contain at least one key when being used with 'CountColumnsByKey'"); if (calls.ContainsKey("CountColumns") && setup.Columns.Count() > 1) throw new CassandraException("'FetchKeys' must contain only one key when being used with 'CountColumns'"); return setup; }