This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
MultiGetSuperColumnSlice.cs
68 lines (58 loc) · 1.9 KB
/
MultiGetSuperColumnSlice.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
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using Apache.Cassandra;
using FluentCassandra.Types;
namespace FluentCassandra.Operations
{
public class MultiGetSuperColumnSlice<CompareWith, CompareSubcolumnWith> : QueryableColumnFamilyOperation<IFluentSuperColumn<CompareWith, CompareSubcolumnWith>>
where CompareWith : CassandraType
where CompareSubcolumnWith : CassandraType
{
/*
* map<string,list<ColumnOrSuperColumn>> multiget_slice(keyspace, keys, column_parent, predicate, consistency_level)
*/
public List<BytesType> Keys { get; private set; }
public CassandraType SuperColumnName { get; private set; }
public override IEnumerable<IFluentSuperColumn<CompareWith, CompareSubcolumnWith>> Execute()
{
CassandraSession _localSession = null;
if (CassandraSession.Current == null)
_localSession = new CassandraSession();
try
{
var parent = new ColumnParent {
Column_family = ColumnFamily.FamilyName
};
if (SuperColumnName != null)
parent.Super_column = SuperColumnName;
var output = CassandraSession.Current.GetClient().multiget_slice(
Keys.ToByteArrayList(),
parent,
SlicePredicate.CreateSlicePredicate(),
CassandraSession.Current.ReadConsistency
);
foreach (var result in output)
{
var r = new FluentSuperColumn<CompareWith, CompareSubcolumnWith>(result.Value.Select(col => {
return Helper.ConvertColumnToFluentColumn<CompareSubcolumnWith>(col.Column);
}));
ColumnFamily.Context.Attach(r);
r.MutationTracker.Clear();
yield return r;
}
}
finally
{
if (_localSession != null)
_localSession.Dispose();
}
}
public MultiGetSuperColumnSlice(IEnumerable<BytesType> keys, CassandraType superColumnName, CassandraSlicePredicate columnSlicePredicate)
{
Keys = keys.ToList();
SuperColumnName = superColumnName;
SlicePredicate = columnSlicePredicate;
}
}
}