Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allows for RemoveColumn to delete columns not fetched

  • Loading branch information...
commit 88bd95bc9425d07e746814ac3d27a7df18b49c6c 1 parent 0a195d6
@gillotte gillotte authored
View
54 src/FluentColumnFamily.cs
@@ -145,8 +145,37 @@ public override IList<FluentColumn> Columns
{
get { return _columns; }
}
+
+ public override void RemoveColumn(object name)
+ {
+ FluentColumn col = Columns.FirstOrDefault(c => c.ColumnName == name);
- /// <summary>
+ if (col != null)
+ {
+ Columns.Remove(col);
+ }
+ else
+ {
+ var cfSchema = GetSchema();
+ var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
+
+ if (schema != null)
+ {
+ col = new FluentColumn(schema);
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
+ }
+ else
+ {
+ col = new FluentColumn();
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
+ }
+
+ col.SetParent(GetSelf());
+ MutationTracker.ColumnMutated(MutationType.Removed, col);
+ }
+ }
+
+ /// <summary>
/// Gets the path.
/// </summary>
/// <returns></returns>
@@ -249,29 +278,6 @@ public override bool TrySetColumn(object name, object value)
return true;
}
- public void DeleteColumn(object name)
- {
- var cfSchema = GetSchema();
- var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
-
- if(schema != null)
- {
- FluentColumn col = new FluentColumn(schema);
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
- col.SetParent(GetSelf());
-
- MutationTracker.ColumnMutated(MutationType.Removed, col);
- }
- else
- {
- FluentColumn col = new FluentColumn();
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
- col.SetParent(GetSelf());
-
- MutationTracker.ColumnMutated(MutationType.Removed, col);
- }
- }
-
public override string ToString()
{
return String.Format("{0} - {1}", FamilyName, Key);
View
7 src/FluentCqlRow.cs
@@ -112,7 +112,12 @@ public override IList<FluentColumn> Columns
get { return _columns; }
}
- public CassandraObject this[CassandraObject columnName]
+ public override void RemoveColumn(object name)
+ {
+ throw new NotSupportedException();
+ }
+
+ public CassandraObject this[CassandraObject columnName]
{
get
{
View
11 src/FluentRecord.cs
@@ -170,12 +170,19 @@ public IFluentMutationTracker MutationTracker
private set;
}
- public void RemoveColumn(object name)
+ public abstract void RemoveColumn(object name);
+
+ public bool TryRemoveColumn(object name)
{
var col = Columns.FirstOrDefault(c => c.ColumnName == name);
if (col != null)
- Columns.Remove(col);
+ {
+ Columns.Remove(col);
+ return true;
+ }
+
+ return false;
}
protected void ResetMutation()
View
30 src/FluentSuperColumn.cs
@@ -87,7 +87,35 @@ public override IList<FluentColumn> Columns
get { return _columns; }
}
- /// <summary>
+ public override void RemoveColumn(object name)
+ {
+ FluentColumn col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col != null)
+ {
+ Columns.Remove(col);
+ }
+ else
+ {
+ var schema = GetColumnSchema(name);
+
+ if (schema != null)
+ {
+ col = new FluentColumn(schema);
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
+ }
+ else
+ {
+ col = new FluentColumn();
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
+ }
+
+ col.SetParent(GetPath());
+ MutationTracker.ColumnMutated(MutationType.Removed, col);
+ }
+ }
+
+ /// <summary>
///
/// </summary>
public FluentSuperColumnFamily Family
View
31 src/FluentSuperColumnFamily.cs
@@ -130,7 +130,36 @@ public override IList<FluentSuperColumn> Columns
get { return _columns; }
}
- /// <summary>
+ public override void RemoveColumn(object name)
+ {
+ var col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col != null)
+ {
+ Columns.Remove(col);
+ }
+ else
+ {
+ var cfSchema = GetSchema();
+ var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
+
+ if (schema != null)
+ {
+ col = new FluentSuperColumn(schema);
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
+ }
+ else
+ {
+ col = new FluentSuperColumn();
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
+ }
+
+ col.SetParent(GetSelf());
+ MutationTracker.ColumnMutated(MutationType.Removed, col);
+ }
+ }
+
+ /// <summary>
///
/// </summary>
public CassandraColumnFamilySchema GetSchema()
Please sign in to comment.
Something went wrong with that request. Please try again.