This repository has been archived by the owner on May 25, 2021. It is now read-only.
/
GetColumnFamilyRangeSlices.cs
66 lines (57 loc) · 1.75 KB
/
GetColumnFamilyRangeSlices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Linq;
using Apache.Cassandra;
using FluentCassandra.Types;
namespace FluentCassandra.Operations
{
public class GetColumnFamilyRangeSlices<CompareWith> : QueryableColumnFamilyOperation<IFluentColumnFamily<CompareWith>>
where CompareWith : CassandraType
{
/*
* list<KeySlice> get_range_slices(keyspace, column_parent, predicate, range, consistency_level)
*/
public CassandraKeyRange KeyRange { get; private set; }
public override IEnumerable<IFluentColumnFamily<CompareWith>> Execute()
{
return GetFamilies(ColumnFamily);
}
private IEnumerable<IFluentColumnFamily<CompareWith>> GetFamilies(BaseCassandraColumnFamily columnFamily)
{
CassandraSession _localSession = null;
if (CassandraSession.Current == null)
_localSession = new CassandraSession();
try
{
var parent = new ColumnParent {
Column_family = columnFamily.FamilyName
};
var output = CassandraSession.Current.GetClient().get_range_slices(
parent,
SlicePredicate.CreateSlicePredicate(),
KeyRange.CreateKeyRange(),
CassandraSession.Current.ReadConsistency
);
foreach (var result in output)
{
var r = new FluentColumnFamily<CompareWith>(result.Key, columnFamily.FamilyName, result.Columns.Select(col => {
return Helper.ConvertColumnToFluentColumn<CompareWith>(col.Column);
}));
columnFamily.Context.Attach(r);
r.MutationTracker.Clear();
yield return r;
}
}
finally
{
if (_localSession != null)
_localSession.Dispose();
}
}
public GetColumnFamilyRangeSlices(CassandraKeyRange keyRange, CassandraSlicePredicate columnSlicePredicate)
{
KeyRange = keyRange;
SlicePredicate = columnSlicePredicate;
}
}
}