Permalink
Browse files

fixed a bug dealing with mutations

  • Loading branch information...
1 parent f77d3d9 commit fae0bc5b96573ebe152dfdaf93e3b9c607fce7b6 @nberardi nberardi committed May 14, 2010
@@ -84,8 +84,7 @@ private static void Main(string[] args)
comments[GuidGenerator.GenerateTimeBasedGuid()] = comment;
comments[GuidGenerator.GenerateTimeBasedGuid()] = comment2;
- db.Attach(comment);
- db.Attach(comment2);
+ db.Attach(comments);
db.SaveChanges();
}
@@ -19,7 +19,7 @@ public void Parent_Set()
var actual = new FluentSuperColumn<AsciiType, AsciiType>();
// assert
- Assert.AreSame(actual, actual.GetParent().SuperColumn);
+ Assert.AreSame(actual, actual.GetPath().SuperColumn);
}
[TestMethod]
@@ -187,7 +187,8 @@ public void BatchMutate(IEnumerable<FluentMutation> tracker)
var columnsNeedingDeleted = columnFamily
.Where(m => m.Type == MutationType.Removed && m.Column.GetParent().SuperColumn == null);
- columnFamilyMutations.Add(ObjectHelper.CreateDeletedColumnMutation(columnsNeedingDeleted));
+ if (columnsNeedingDeleted.Count() > 0)
+ columnFamilyMutations.Add(ObjectHelper.CreateDeletedColumnMutation(columnsNeedingDeleted));
keyMutations.Add(columnFamily.Key, columnFamilyMutations);
}
@@ -15,7 +15,7 @@ public class FluentColumn<CompareWith> : IFluentColumn<CompareWith>
{
private BytesType _value;
private FluentColumnParent _parent;
- private IFluentColumnFamily<CompareWith> _family;
+ private IFluentBaseColumnFamily _family;
public FluentColumn()
{
@@ -49,7 +49,7 @@ public DateTimeOffset Timestamp
/// <summary>
///
/// </summary>
- public IFluentColumnFamily<CompareWith> Family
+ public IFluentBaseColumnFamily Family
{
get
{
@@ -87,8 +87,6 @@ public FluentColumnParent GetParent()
CassandraType IFluentBaseColumn.Name { get { return Name; } }
- IFluentBaseColumnFamily IFluentBaseColumn.Family { get { return Family; } }
-
void IFluentBaseColumn.SetParent(FluentColumnParent parent)
{
UpdateParent(parent);
@@ -13,7 +13,6 @@ public class FluentColumnFamily<CompareWith> : FluentRecord<IFluentColumn<Compar
where CompareWith : CassandraType
{
private FluentColumnList<IFluentColumn<CompareWith>> _columns;
- private FluentColumnParent _self;
/// <summary>
///
@@ -25,8 +24,7 @@ public FluentColumnFamily(string key, string columnFamily)
Key = key;
FamilyName = columnFamily;
- _self = new FluentColumnParent(this, null);
- _columns = new FluentColumnList<IFluentColumn<CompareWith>>(_self);
+ _columns = new FluentColumnList<IFluentColumn<CompareWith>>(GetSelf());
}
/// <summary>
@@ -40,8 +38,7 @@ internal FluentColumnFamily(string key, string columnFamily, IEnumerable<IFluent
Key = key;
FamilyName = columnFamily;
- _self = new FluentColumnParent(this, null);
- _columns = new FluentColumnList<IFluentColumn<CompareWith>>(_self, columns);
+ _columns = new FluentColumnList<IFluentColumn<CompareWith>>(GetSelf(), columns);
}
/// <summary>
@@ -82,7 +79,7 @@ public override IList<IFluentColumn<CompareWith>> Columns
/// <returns></returns>
public FluentColumnPath GetPath()
{
- return new FluentColumnPath(_self, null);
+ return new FluentColumnPath(this, null, null);
}
/// <summary>
@@ -91,7 +88,7 @@ public FluentColumnPath GetPath()
/// <returns></returns>
public FluentColumnParent GetSelf()
{
- return _self;
+ return new FluentColumnParent(this, null);
}
/// <summary>
@@ -136,6 +136,18 @@ public IFluentMutationTracker MutationTracker
private set;
}
+ protected void ResetMutation()
+ {
+ MutationTracker.Clear();
+ }
+
+ protected void ResetMutationAndAddAllColumns()
+ {
+ ResetMutation();
+ foreach (var col in Columns)
+ MutationTracker.ColumnMutated(MutationType.Added, col);
+ }
+
#endregion
}
}
@@ -16,17 +16,14 @@ public class FluentSuperColumn<CompareWith, CompareSubcolumnWith> : FluentRecord
where CompareWith : CassandraType
where CompareSubcolumnWith : CassandraType
{
- private IFluentSuperColumnFamily<CompareWith, CompareSubcolumnWith> _family;
private FluentColumnList<IFluentColumn<CompareSubcolumnWith>> _columns;
- private FluentColumnParent _parent;
/// <summary>
///
/// </summary>
public FluentSuperColumn()
{
- _parent = new FluentColumnParent(null, this);
- _columns = new FluentColumnList<IFluentColumn<CompareSubcolumnWith>>(_parent);
+ _columns = new FluentColumnList<IFluentColumn<CompareSubcolumnWith>>(GetPath());
}
/// <summary>
@@ -35,8 +32,7 @@ public FluentSuperColumn()
/// <param name="columns"></param>
internal FluentSuperColumn(IEnumerable<IFluentColumn<CompareSubcolumnWith>> columns)
{
- _parent = new FluentColumnParent(null, this);
- _columns = new FluentColumnList<IFluentColumn<CompareSubcolumnWith>>(_parent, columns);
+ _columns = new FluentColumnList<IFluentColumn<CompareSubcolumnWith>>(GetPath(), columns);
}
/// <summary>
@@ -66,18 +62,8 @@ public override IList<IFluentColumn<CompareSubcolumnWith>> Columns
/// </summary>
public IFluentSuperColumnFamily<CompareWith, CompareSubcolumnWith> Family
{
- get
- {
- if (_family == null && _parent != null)
- _family = _parent.ColumnFamily as IFluentSuperColumnFamily<CompareWith, CompareSubcolumnWith>;
-
- return _family;
- }
- internal set
- {
- _family = value;
- UpdateParent(GetParent());
- }
+ get;
+ internal set;
}
/// <summary>
@@ -86,7 +72,7 @@ internal set
/// <returns></returns>
public FluentColumnPath GetPath()
{
- return new FluentColumnPath(_parent, null);
+ return new FluentColumnPath(Family, this, null);
}
/// <summary>
@@ -95,7 +81,7 @@ public FluentColumnPath GetPath()
/// <returns></returns>
public FluentColumnParent GetParent()
{
- return _parent;
+ return new FluentColumnParent(Family, null);
}
/// <summary>
@@ -164,12 +150,15 @@ void IFluentBaseColumn.SetParent(FluentColumnParent parent)
private void UpdateParent(FluentColumnParent parent)
{
- _parent = parent;
- _columns.Parent = parent;
+ Family = parent.ColumnFamily as IFluentSuperColumnFamily<CompareWith, CompareSubcolumnWith>;
+
+ var columnParent = GetPath();
+ _columns.Parent = columnParent;
- var columnParent = new FluentColumnParent(Family, this);
foreach (var col in Columns)
col.SetParent(columnParent);
+
+ ResetMutationAndAddAllColumns();
}
#endregion
@@ -14,7 +14,6 @@ public class FluentSuperColumnFamily<CompareWith, CompareSubcolumnWith> : Fluent
where CompareSubcolumnWith : CassandraType
{
private FluentColumnList<IFluentSuperColumn<CompareWith, CompareSubcolumnWith>> _columns;
- private FluentColumnParent _self;
/// <summary>
///
@@ -26,8 +25,7 @@ public FluentSuperColumnFamily(string key, string columnFamily)
Key = key;
FamilyName = columnFamily;
- _self = new FluentColumnParent(this, null);
- _columns = new FluentColumnList<IFluentSuperColumn<CompareWith, CompareSubcolumnWith>>(_self);
+ _columns = new FluentColumnList<IFluentSuperColumn<CompareWith, CompareSubcolumnWith>>(GetSelf());
}
@@ -42,8 +40,7 @@ internal FluentSuperColumnFamily(string key, string columnFamily, IEnumerable<IF
Key = key;
FamilyName = columnFamily;
- _self = new FluentColumnParent(this, null);
- _columns = new FluentColumnList<IFluentSuperColumn<CompareWith, CompareSubcolumnWith>>(_self, columns);
+ _columns = new FluentColumnList<IFluentSuperColumn<CompareWith, CompareSubcolumnWith>>(GetSelf(), columns);
}
/// <summary>
@@ -84,7 +81,7 @@ internal FluentSuperColumnFamily(string key, string columnFamily, IEnumerable<IF
/// <returns></returns>
public FluentColumnPath GetPath()
{
- return new FluentColumnPath(_self, null);
+ return new FluentColumnPath(this, null, null);
}
/// <summary>
@@ -93,8 +90,9 @@ public FluentColumnPath GetPath()
/// <returns></returns>
public FluentColumnParent GetSelf()
{
- return _self;
+ return new FluentColumnParent(this, null);
}
+
/// <summary>
///
/// </summary>
@@ -6,6 +6,5 @@ namespace FluentCassandra
public interface IFluentColumn<CompareWith> : IFluentColumn, IFluentBaseColumn<CompareWith>
where CompareWith : CassandraType
{
- new IFluentColumnFamily<CompareWith> Family { get; }
}
}
@@ -86,7 +86,7 @@ public static Mutation CreateDeletedColumnMutation(IEnumerable<FluentMutation> m
/// <returns></returns>
public static Mutation CreateDeletedSuperColumnMutation(IEnumerable<FluentMutation> mutation)
{
- var superColumn = mutation.Select(m => m.Column.GetParent().SuperColumn.Name).FirstOrDefault();
+ var superColumn = mutation.Select(m => m.Column.GetPath().SuperColumn.Name).FirstOrDefault();
var columnNames = mutation.Select(m => m.Column.Name).ToList();
var deletion = new Deletion {
@@ -31,7 +31,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, System.Global
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
- if (!(value is string))
+ if (!(value is Guid))
return null;
if (destinationType == typeof(byte[]))
@@ -31,11 +31,11 @@ public override object ConvertFrom(ITypeDescriptorContext context, System.Global
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
- if (!(value is string))
+ if (!(value is Guid))
return null;
if (destinationType == typeof(byte[]))
- return new Guid((byte[])value);
+ return ((Guid)value).ToByteArray();
if (destinationType == typeof(Guid))
return (Guid)value;

0 comments on commit fae0bc5

Please sign in to comment.