public static Row CreateRow(IDictionary <string, object> valueMap)
        {
            var columns   = new List <CqlColumn>();
            var rowValues = new List <byte[]>();

            foreach (var kv in valueMap)
            {
                if (kv.Value != null)
                {
                    IColumnInfo typeInfo;
                    var         typeCode = TypeCodec.GetColumnTypeCodeInfo(kv.Value.GetType(), out typeInfo);
                    columns.Add(new CqlColumn()
                    {
                        Name = kv.Key, TypeCode = typeCode, TypeInfo = typeInfo
                    });
                }
                else
                {
                    columns.Add(new CqlColumn()
                    {
                        Name = kv.Key, TypeCode = ColumnTypeCode.Text
                    });
                }
                rowValues.Add(TypeCodec.Encode(2, kv.Value));
            }
            var i = 0;

            return(new Row(2, rowValues.ToArray(), columns.ToArray(), valueMap.ToDictionary(kv => kv.Key, kv => i++)));
        }
Beispiel #2
0
        private static string GetTypeString(PocoColumn column)
        {
            IColumnInfo typeInfo;
            var         typeCode = TypeCodec.GetColumnTypeCodeInfo(column.ColumnType, out typeInfo);

            return(GetTypeString(typeCode, typeInfo));
        }
Beispiel #3
0
        private static string GetTypeString(PocoColumn column)
        {
            if (column.IsCounter)
            {
                return("counter");
            }
            IColumnInfo typeInfo;
            var         typeCode = TypeCodec.GetColumnTypeCodeInfo(column.ColumnType, out typeInfo);
            var         typeName = GetTypeString(column, typeCode, typeInfo);

            if (column.IsStatic)
            {
                return(typeName + " static");
            }
            return(typeName);
        }
Beispiel #4
0
        /// <summary>
        /// Returns a RowSet with 1 column
        /// </summary>
        public static RowSet GetSingleColumnRowSet <T>(string columnName, T[] values)
        {
            var         rs = new RowSet();
            IColumnInfo typeInfo;
            var         typeCode = TypeCodec.GetColumnTypeCodeInfo(typeof(T), out typeInfo);

            rs.Columns = new[]
            {
                new CqlColumn {
                    Name = columnName, TypeCode = typeCode, TypeInfo = typeInfo, Type = typeof(T), Index = 0
                }
            };
            var columnIndexes = rs.Columns.ToDictionary(c => c.Name, c => c.Index);

            foreach (var v in values)
            {
                var row = new Row(new object[] { v }, rs.Columns, columnIndexes);
                rs.AddRow(row);
            }
            return(rs);
        }
Beispiel #5
0
        public static RowSet CreateMultipleValuesRowSet <T>(string[] columnNames, T[] genericValues, int rowLength = 1)
        {
            var rs = new RowSet();

            rs.Columns = new CqlColumn[columnNames.Length];
            for (var i = 0; i < columnNames.Length; i++)
            {
                IColumnInfo typeInfo;
                var         type = typeof(T);
                if (type == typeof(Object))
                {
                    //Try to guess by value
                    if (genericValues[i] == null)
                    {
                        throw new Exception("Test data could not be generated, value at index " + i + " could not be encoded");
                    }
                    type = genericValues[i].GetType();
                }
                var typeCode = TypeCodec.GetColumnTypeCodeInfo(type, out typeInfo);
                rs.Columns[i] =
                    new CqlColumn {
                    Name = columnNames[i], TypeCode = typeCode, TypeInfo = typeInfo, Type = typeof(T), Index = i
                };
            }
            var columnIndexes = rs.Columns.ToDictionary(c => c.Name, c => c.Index);

            for (var i = 0; i < rowLength; i++)
            {
                var values = genericValues
                             .Select(v => (object)v)
                             .ToArray();
                var row = new Row(values, rs.Columns, columnIndexes);
                rs.AddRow(row);
            }
            return(rs);
        }