Permalink
Browse files

did some clean up in the schema

  • Loading branch information...
1 parent 7e3deb8 commit 6183a731a6a31355c63d9b5a3d1bc309040251ec @nberardi nberardi committed Jan 5, 2013
Showing with 62 additions and 20 deletions.
  1. +19 −3 src/FluentColumn.cs
  2. +7 −4 src/FluentColumnFamily.cs
  3. +8 −5 src/FluentCqlRow.cs
  4. +27 −7 src/FluentSuperColumn.cs
  5. +1 −1 src/FluentSuperColumnFamily.cs
View
22 src/FluentColumn.cs
@@ -10,7 +10,7 @@ public class FluentColumn<CompareWith> : FluentColumn
public FluentColumn()
: base(new CassandraColumnSchema {
NameType = typeof(CompareWith),
- ValueType = typeof(BytesType)
+ ValueType = CassandraType.BytesType
}) { }
}
@@ -135,8 +135,24 @@ internal set
/// </summary>
public CassandraColumnSchema GetSchema()
{
- if (_schema == null)
- _schema = new CassandraColumnSchema { Name = ColumnName, ValueType = ColumnValue.GetType() };
+ if (_schema == null) {
+ var nameType = CassandraType.BytesType;
+ var valueType = CassandraType.BytesType;
+
+ if (_name != null)
+ nameType = _name.GetCassandraType();
+
+ if (_value != null)
+ valueType = _value.GetCassandraType();
+
+ _schema = new CassandraColumnSchema {
+ NameType = nameType,
+ ValueType = valueType
+ };
+
+ if (_name != null)
+ _schema.Name = _name;
+ }
return _schema;
}
View
11 src/FluentColumnFamily.cs
@@ -12,7 +12,7 @@ public class FluentColumnFamily<CompareWith> : FluentColumnFamily
public FluentColumnFamily(CassandraObject key, string columnFamily)
: base(key, columnFamily, new CassandraColumnFamilySchema {
FamilyName = columnFamily,
- KeyValueType = typeof(BytesType),
+ KeyValueType = CassandraType.BytesType,
ColumnNameType = typeof(CompareWith)
}) { }
}
@@ -90,7 +90,7 @@ public CassandraObject Key
public CassandraColumnFamilySchema GetSchema()
{
if (_schema == null)
- _schema = new CassandraColumnFamilySchema { FamilyName = FamilyName };
+ _schema = new CassandraColumnFamilySchema(name: FamilyName);
return _schema;
}
@@ -102,7 +102,7 @@ public CassandraColumnFamilySchema GetSchema()
public void SetSchema(CassandraColumnFamilySchema schema)
{
if (schema == null)
- schema = new CassandraColumnFamilySchema { FamilyName = FamilyName };
+ schema = new CassandraColumnFamilySchema(name: FamilyName);
_schema = schema;
}
@@ -189,7 +189,10 @@ private CassandraColumnSchema GetColumnSchema(object name)
if (colSchema != null)
return colSchema;
- return new CassandraColumnSchema { NameType = schema.ColumnNameType, ValueType = schema.DefaultColumnValueType ?? typeof(BytesType) };
+ return new CassandraColumnSchema {
+ NameType = schema.ColumnNameType,
+ ValueType = schema.DefaultColumnValueType
+ };
}
/// <summary>
View
13 src/FluentCqlRow.cs
@@ -74,7 +74,10 @@ private CassandraColumnSchema GetColumnSchema(object name)
if (colSchema != null)
return colSchema;
- return new CassandraColumnSchema { NameType = schema.DefaultColumnNameType, ValueType = typeof(BytesType) };
+ return new CassandraColumnSchema {
+ NameType = schema.DefaultColumnNameType,
+ ValueType = schema.DefaultColumnValueType
+ };
}
/// <summary>
@@ -96,9 +99,9 @@ public override bool TrySetColumn(object name, object value)
}
public override bool TryRemoveColumn(object name)
- {
- throw new NotSupportedException();
- }
+ {
+ throw new NotSupportedException();
+ }
public string FamilyName
{
@@ -117,7 +120,7 @@ public override IList<FluentColumn> Columns
get { return _columns; }
}
- public CassandraObject this[CassandraObject columnName]
+ public CassandraObject this[CassandraObject columnName]
{
get
{
View
34 src/FluentSuperColumn.cs
@@ -132,8 +132,21 @@ internal set
/// </summary>
public CassandraColumnSchema GetSchema()
{
- if (_schema == null)
- _schema = new CassandraColumnSchema { Name = ColumnName, ValueType = typeof(BytesType) };
+ if (_schema == null) {
+ var nameType = CassandraType.BytesType;
+ var valueType = CassandraType.BytesType;
+
+ if (_name != null)
+ nameType = _name.GetCassandraType();
+
+ _schema = new CassandraColumnSchema {
+ NameType = nameType,
+ ValueType = valueType
+ };
+
+ if (_name != null)
+ _schema.Name = _name;
+ }
return _schema;
}
@@ -145,7 +158,10 @@ public CassandraColumnSchema GetSchema()
public void SetSchema(CassandraColumnSchema schema)
{
if (schema == null)
- schema = new CassandraColumnSchema { Name = ColumnName, ValueType = typeof(BytesType) };
+ schema = new CassandraColumnSchema();
+
+ if (_name != null)
+ _name = _name.GetValue(schema.NameType);
_schema = schema;
}
@@ -193,13 +209,17 @@ private CassandraObject GetColumnValue(object name)
private CassandraColumnSchema GetColumnSchema(object name)
{
var schema = GetSchema();
- var valueType = CassandraType.BytesType;
- if (Family != null)
- valueType = Family.GetSchema().DefaultColumnValueType;
+ // the following two variables are correct, because the value type of a super column is the name type of the children column
+ // and the default value type is the families value type
+ var nameType = schema.ValueType;
+ var valueType = (Family != null) ? Family.GetSchema().DefaultColumnValueType : CassandraType.BytesType;
// mock up a fake schema to send to the fluent column
- return new CassandraColumnSchema { NameType = schema.ValueType, ValueType = valueType };
+ var colSchema = new CassandraColumnSchema { NameType = nameType, ValueType = valueType };
+ colSchema.Name = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
+
+ return colSchema;
}
/// <summary>
View
2 src/FluentSuperColumnFamily.cs
@@ -13,7 +13,7 @@ public class FluentSuperColumnFamily<CompareWith, CompareSubcolumnWith> : Fluent
public FluentSuperColumnFamily(CassandraObject key, string columnFamily)
: base(key, columnFamily, new CassandraColumnFamilySchema {
FamilyName = columnFamily,
- KeyValueType = typeof(BytesType),
+ KeyValueType = CassandraType.BytesType,
SuperColumnNameType = typeof(CompareWith),
ColumnNameType = typeof(CompareSubcolumnWith)
}) { }

0 comments on commit 6183a73

Please sign in to comment.