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;
        }
        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);
        }
        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);
        }
Exemple #4
0
        /// <summary>
        ///Make sure that the given column path is a SuperColumn in the DB, Throws an exception if it's not.
        /// </summary>
        /// <param name="columnPath"></param>
        void AssertSuperColumnPath(ColumnPath columnPath)
        //throws InvalidRequestException
        {
            var cf = columnPath.ColumnFamily;
            IDictionary <string, string> cfdefine;

            if ((cfdefine = Description[cf]) != null &&
                cfdefine[CF_TYPE].Equals(CF_TYPE_SUPER) &&
                columnPath.SuperColumn != null)
            {
                return;
            }
            throw new InvalidRequestException(
                      "Invalid super column or super column family does not exist: " + cf, null);
        }
        //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);
        }
        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);
        }
Exemple #7
0
        /// <summary>
        /// Make sure that if the given column path was a Column. Throws an InvalidRequestException if not.
        /// </summary>
        /// <param name="columnPath">if either the column family does not exist or that it's type does not match (super)..</param>
        void AssertColumnPath(ColumnPath columnPath)
        //throws InvalidRequestException
        {
            string cf = columnPath.ColumnFamily;
            IDictionary <string, string> cfdefine;

            if (!Description.ContainsKey(cf))
            {
                throw new InvalidRequestException("The specified column family does not exist: " + cf, null);
            }

            cfdefine = Description[cf];

            if (cfdefine[CF_TYPE].Equals(CF_TYPE_STANDARD) && columnPath.Column != null)
            {
                return;                 // if the column family is a standard column
            }
            else if (cfdefine[CF_TYPE].Equals(CF_TYPE_SUPER) && columnPath.SuperColumn != null && columnPath.Column != null)
            {
                // if the column family is a super column and also give the super_column name
                return;
            }
        }
 public SuperColumn GetSuperColumn(string key, ColumnPath columnPath)
 {
     return GetSuperColumn(key, columnPath, false, Int32.MaxValue);
 }
Exemple #9
0
 public static Apache.Cassandra.ColumnPath ToThrift(this ColumnPath path)
 {
     return(new Apache.Cassandra.ColumnPath(path.ColumnFamily, path.SuperColumn, path.Column));
 }
        //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;
        }
 public SuperColumn GetSuperColumn(string key, ColumnPath columnPath)
 {
     return(GetSuperColumn(key, columnPath, false, Int32.MaxValue));
 }
        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);
        }
 public void Insert(string key, ColumnPath columnPath, string value)
 {
     Insert(key, columnPath, value.UTF());
 }
 public IDictionary <string, SuperColumn> MultigetSuperColumn(IList <string> keys, ColumnPath columnPath)
 {
     return(MultigetSuperColumn(keys, columnPath, false, Int32.MaxValue));
 }
        public IDictionary <string, SuperColumn> MultigetSuperColumn(IList <string> keys, ColumnPath columnPath, bool reversed, int size)
        {
            AssertSuperColumnPath(columnPath);

            var result = new Dictionary <string, SuperColumn>();

            // only can get supercolumn by multigetSuperSlice
            var clp    = new ColumnParent(columnPath.ColumnFamily, columnPath.SuperColumn);
            var sr     = new SliceRange(reversed, size);
            var sp     = new SlicePredicate(sr);
            var sclist = MultigetSuperSlice(keys, clp, sp);

            if (sclist == null || sclist.Count == 0)
            {
                return(result);
            }

            foreach (var sc in sclist)
            {
                if (sc.Value.Count > 0)
                {
                    result.Add(sc.Key, sc.Value[0]);
                }
            }

            return(result);
        }
 public void Insert(string key, ColumnPath columnPath, string value)
 {
     Insert(key, columnPath, value.UTF());
 }
        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;
        }
 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);
 }
        public IDictionary<string, SuperColumn> MultigetSuperColumn(IList<string> keys, ColumnPath columnPath, bool reversed, int size)
        {
            AssertSuperColumnPath(columnPath);

            var result = new Dictionary<string, SuperColumn>();

            // only can get supercolumn by multigetSuperSlice
            var clp = new ColumnParent(columnPath.ColumnFamily, columnPath.SuperColumn);
            var sr = new SliceRange(reversed, size);
            var sp = new SlicePredicate(sr);
            var sclist = MultigetSuperSlice(keys, clp, sp);

            if (sclist == null || sclist.Count == 0)
                return result;

            foreach (var sc in sclist)
                if (sc.Value.Count > 0)
                    result.Add(sc.Key, sc.Value[0]);

            return result;
        }
 public IDictionary<string, SuperColumn> MultigetSuperColumn(IList<string> keys, ColumnPath columnPath)
 {
     return MultigetSuperColumn(keys, columnPath, false, Int32.MaxValue);
 }