Example #1
0
        public Column GetColumn(string key, ColumnPath columnPath)
        {
            AssertColumnPath(columnPath);

            var op = new Operation <Column>(ClientCounter.READ_FAIL);

            op.Handler = client =>
            {
                try
                {
                    var cosc = client.get(Name, key, columnPath.ToThrift(), ConsistencyLevel.ToThrift());
                    return(cosc == null ? null : cosc.Column.ToModel());
                }
                catch (Apache.Cassandra.NotFoundException ex)
                {
                    op.Error = new NotFoundException("Column Not Found: key: " + key + ", " + columnPath.ToString(), ex);
                }
                return(null);
            };

            OperateWithFailover(op);

            if (op.HasError)
            {
                throw op.Error;
            }
            return(op.Result);
        }
Example #2
0
        public int GetCount(string key, ColumnParent columnParent)
        {
            var op = new Operation <int>(ClientCounter.READ_FAIL,
                                         client =>
            {
                return(client.get_count(Name, key, columnParent.ToThrift(), ConsistencyLevel.ToThrift()));
            });

            OperateWithFailover(op);
            return(op.Result);
        }
Example #3
0
        public void Remove(string key, ColumnPath columnPath)
        {
            var op = new VoidOperation(ClientCounter.WRITE_FAIL,
                                       client =>
            {
                client.remove(Name, key, columnPath.ToThrift(), Util.UnixTimestamp, ConsistencyLevel.ToThrift());
            }
                                       );

            OperateWithFailover(op);
        }
Example #4
0
        public IEnumerable <SuperColumn> GetSuperSlice(string key, ColumnParent columnParent, SlicePredicate predicate)
        {
            var op = new Operation <IEnumerable <SuperColumn> >(ClientCounter.READ_FAIL,
                                                                client =>
            {
                return(client.get_slice(Name, key, columnParent.ToThrift(), predicate.ToThrift(), ConsistencyLevel.ToThrift())
                       .Transform(c => c.Super_column.ToModel()));
            });

            OperateWithFailover(op);
            return(op.Result);
        }
Example #5
0
        //Override
        public SuperColumn GetSuperColumn(string key, ColumnPath columnPath, bool reversed, int size)
        {
            AssertSuperColumnPath(columnPath);

            var sliceRange = new Apache.Cassandra.SliceRange(reversed, size);

            var op = new Operation <SuperColumn>(ClientCounter.READ_FAIL,
                                                 client =>
            {
                var columnParent = new Apache.Cassandra.ColumnParent(columnPath.ColumnFamily, columnPath.SuperColumn);
                var predicate    = new Apache.Cassandra.SlicePredicate(null, sliceRange);
                var data         = client.get_slice(Name, key, columnParent, predicate, ConsistencyLevel.ToThrift());
                return(new SuperColumn(columnPath.SuperColumn, GetColumnList(data)));
            });

            OperateWithFailover(op);
            return(op.Result);
        }
Example #6
0
        public void BatchInsert(string key, IDictionary <string, IList <Column> > columnMap, IDictionary <string, IList <SuperColumn> > superColumnMap)
        {
            if (columnMap == null && superColumnMap == null)
            {
                throw new Exception("columnMap and SuperColumnMap can not be null at same time");
            }

            var cfmap = new Dictionary <string, List <Apache.Cassandra.ColumnOrSuperColumn> >();

            if (columnMap != null)
            {
                foreach (var map in columnMap)
                {
                    cfmap.Add(map.Key, GetSoscList(map.Value));
                }
            }

            if (superColumnMap != null)
            {
                foreach (var map in superColumnMap)
                {
                    cfmap.Add(map.Key, GetSoscSuperList(map.Value));
                }
            }

            var op = new VoidOperation(ClientCounter.WRITE_FAIL,
                                       client => client.batch_insert(Name, key, cfmap, ConsistencyLevel.ToThrift())
                                       );

            OperateWithFailover(op);
        }
Example #7
0
        public void Insert(string key, ColumnPath columnPath, byte[] value)
        {
            AssertColumnPath(columnPath);

            var op = new VoidOperation(ClientCounter.WRITE_FAIL,
                                       client =>
            {
                client.insert(Name, key, columnPath.ToThrift(), value, Util.UnixTimestamp, ConsistencyLevel.ToThrift());
            });

            OperateWithFailover(op);
        }
Example #8
0
        public IDictionary <string, IList <SuperColumn> > GetSuperRangeSlice(ColumnParent columnParent, SlicePredicate predicate, string start, string finish, int count)
        {
            var op = new Operation <IDictionary <string, IList <SuperColumn> > >(ClientCounter.READ_FAIL,
                                                                                 client =>
            {
                var result    = new Dictionary <string, IList <SuperColumn> >();
                var keySlices = client.get_range_slice(Name, columnParent.ToThrift(), predicate.ToThrift(), start, finish, count, ConsistencyLevel.ToThrift());
                if (keySlices == null || keySlices.Count == 0)
                {
                    return(result);
                }

                foreach (var entry in keySlices.Transform(entry => new { entry.Key, Columns = GetSuperColumnList(entry.Columns) }))
                {
                    result.Add(entry.Key, entry.Columns);
                }

                return(result);
            }
                                                                                 );

            OperateWithFailover(op);
            return(op.Result);
        }
Example #9
0
        public IDictionary <string, IList <SuperColumn> > MultigetSuperSlice(IList <string> keys, ColumnParent columnParent, SlicePredicate predicate)
        {
            var op = new Operation <IDictionary <string, IList <SuperColumn> > >(ClientCounter.READ_FAIL,
                                                                                 client =>
            {
                var result = new Dictionary <string, IList <SuperColumn> >();
                var cfmap  = client.multiget_slice(Name, new List <string>(keys), columnParent.ToThrift(), predicate.ToThrift(), ConsistencyLevel.ToThrift());

                if (string.IsNullOrEmpty(columnParent.SuperColumn))
                {
                    foreach (var entry in cfmap.Transform(m => new { m.Key, List = GetSuperColumnList(m.Value) }))
                    {
                        result.Add(entry.Key, entry.List);
                    }
                }
                else
                {
                    foreach (var entry in cfmap.Transform(m =>
                                                          new
                    {
                        m.Key,
                        List = new List <SuperColumn>
                        {
                            new SuperColumn(columnParent.SuperColumn, GetColumnList(m.Value))
                        }
                    }))
                    {
                        result.Add(entry.Key, entry.List);
                    }
                }
                return(result);
            }
                                                                                 );

            OperateWithFailover(op);
            return(op.Result);
        }
Example #10
0
        public IDictionary <string, Column> MultigetColumn(IList <string> keys, ColumnPath columnPath)
        {
            AssertColumnPath(columnPath);

            var op = new Operation <IDictionary <string, Column> >(ClientCounter.READ_FAIL,
                                                                   client =>
            {
                var result = new Dictionary <string, Column>();

                var cfmap = client.multiget(Name, new List <string>(keys), columnPath.ToThrift(), ConsistencyLevel.ToThrift());

                foreach (var entry in cfmap.Transform(entry => new { entry.Key, Column = entry.Value.Column.ToModel() }))
                {
                    result.Add(entry.Key, entry.Column);
                }

                return(result);
            });

            OperateWithFailover(op);
            return(op.Result);
        }