/// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool TrySetColumn(object name, object value)
        {
            var col          = Columns.FirstOrDefault(c => c.ColumnName == name);
            var mutationType = MutationType.Changed;

            // if column doesn't exisit create it and add it to the columns
            if (col == null)
            {
                mutationType = MutationType.Added;

                col = new FluentColumn <CompareWith>();
                ((FluentColumn <CompareWith>)col).ColumnName = CassandraType.GetType <CompareWith>(name);

                _columns.SupressChangeNotification = true;
                _columns.Add(col);
                _columns.SupressChangeNotification = false;
            }

            // set the column value
            col.ColumnValue = CassandraType.GetType <BytesType>(value);

            // notify the tracker that the column has changed
            OnColumnMutated(mutationType, col);

            return(true);
        }
        private static Cassandra.IndexExpression VisitRelationalExpression(BinaryExpression exp)
        {
            Cassandra.IndexExpression indexExpression;

            var columnName = GetColumnName(exp.Left);
            var value      = CassandraType.GetType <BytesType>(Expression.Lambda(exp.Right).Compile().DynamicInvoke());

            indexExpression = new Cassandra.IndexExpression {
                Column_name = columnName,
                Value       = value
            };

            switch (exp.NodeType)
            {
            case ExpressionType.Equal: indexExpression.Op = Cassandra.IndexOperator.EQ; break;

            case ExpressionType.GreaterThan: indexExpression.Op = Cassandra.IndexOperator.GT; break;

            case ExpressionType.GreaterThanOrEqual: indexExpression.Op = Cassandra.IndexOperator.GTE; break;

            case ExpressionType.LessThan: indexExpression.Op = Cassandra.IndexOperator.LT; break;

            case ExpressionType.LessThanOrEqual: indexExpression.Op = Cassandra.IndexOperator.LTE; break;

            default:
                throw new NotSupportedException(exp.NodeType.ToString() + " is not a supported relational criteria.");
            }

            return(indexExpression);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetColumn(object name, out object result)
        {
            var col = Columns.FirstOrDefault(c => c.ColumnName == name);

            result = (col == null) ? CreateSuperColumn(CassandraType.GetType <CompareWith>(name)) : col;

            return(true);
        }
Пример #4
0
 public static FluentColumn <CompareWith> ConvertColumnToFluentColumn <CompareWith>(Column col)
     where CompareWith : CassandraType
 {
     return(new FluentColumn <CompareWith> {
         ColumnName = CassandraType.GetType <CompareWith>(col.Name),
         ColumnValue = col.Value,
         ColumnTimestamp = new DateTimeOffset(col.Timestamp, TimeSpan.Zero),
         ColumnTimeToLive = col.Ttl
     });
 }
Пример #5
0
        public static FluentSuperColumn <CompareWith, CompareSubcolumnWith> ConvertSuperColumnToFluentSuperColumn <CompareWith, CompareSubcolumnWith>(SuperColumn col)
            where CompareWith : CassandraType
            where CompareSubcolumnWith : CassandraType
        {
            var superCol = new FluentSuperColumn <CompareWith, CompareSubcolumnWith> {
                ColumnName = CassandraType.GetType <CompareWith>(col.Name)
            };

            foreach (var xcol in col.Columns)
            {
                superCol.Columns.Add(ConvertColumnToFluentColumn <CompareSubcolumnWith>(xcol));
            }

            return(superCol);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool TrySetColumn(object name, object value)
        {
            if (!(value is FluentSuperColumn <CompareWith, CompareSubcolumnWith>))
            {
                throw new ArgumentException("Value must be of type " + typeof(FluentSuperColumn <CompareWith, CompareSubcolumnWith>) + ", because this column family is of type Super.", "value");
            }

            var col          = Columns.FirstOrDefault(c => c.ColumnName == name);
            var mutationType = col == null ? MutationType.Added : MutationType.Changed;

            col = (FluentSuperColumn <CompareWith, CompareSubcolumnWith>)value;
            ((FluentSuperColumn <CompareWith, CompareSubcolumnWith>)col).ColumnName = CassandraType.GetType <CompareWith>(name);

            int index = Columns.IndexOf(col);

            _columns.SupressChangeNotification = true;
            if (index < 0)
            {
                Columns.Add(col);
            }
            else
            {
                Columns.Insert(index, col);
            }
            _columns.SupressChangeNotification = false;

            // notify the tracker that the column has changed
            OnColumnMutated(mutationType, col);

            return(true);
        }