Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 128 lines (105 sloc) 2.666 kb
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentCassandra.Linq;
using FluentCassandra.Types;

namespace FluentCassandra
{
public class FluentCqlRow : FluentRecord<FluentColumn>, ICqlRow
{
private readonly IList<FluentColumn> _columns;
private CassandraCqlRowSchema _schema;

internal FluentCqlRow(CassandraObject key, string columnFamily, CassandraCqlRowSchema schema, IEnumerable<FluentColumn> columns)
{
SetSchema(schema);

Key = key;
FamilyName = columnFamily;

_columns = new List<FluentColumn>(columns);
}

/// <summary>
///
/// </summary>
public CassandraCqlRowSchema GetSchema()
{
return _schema;
}

/// <summary>
///
/// </summary>
/// <param name="schema"></param>
public void SetSchema(CassandraCqlRowSchema schema)
{
_schema = schema;
}

/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="result"></param>
/// <returns></returns>
private CassandraObject GetColumnValue(object name)
{
var col = Columns.FirstOrDefault(c => c.ColumnName == name);

if (col == null)
return NullType.Value;

var schema = GetColumnSchema(name);
return col.ColumnValue.GetValue(schema.ValueType);
}

/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private CassandraColumnSchema GetColumnSchema(object name)
{
var col = Columns.FirstOrDefault(c => c.ColumnName == name);

if (col != null)
return col.GetSchema();

var schema = GetSchema();
var colSchema = schema.Columns.FirstOrDefault(c => c.Name == name);

if (colSchema != null)
return colSchema;

return new CassandraColumnSchema { NameType = schema.DefaultColumnNameType, ValueType = typeof(BytesType) };
}

/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="result"></param>
/// <returns></returns>
public override bool TryGetColumn(object name, out object result)
{
result = GetColumnValue(name);

return true;
}

public override bool TrySetColumn(object name, object value)
{
throw new NotSupportedException();
}

public string FamilyName
{
get;
private set;
}

public CassandraObject Key
{
get;
private set;
}

public override IList<FluentColumn> Columns
{
get { return _columns; }
}

public CassandraObject this[CassandraObject columnName]
{
get
{
var value = GetColumnValue(columnName);

if (value is NullType)
throw new CassandraException(String.Format("Column, {0}, could not be found.", columnName));

return value;
}
}
}
}
Something went wrong with that request. Please try again.