Skip to content
This repository
Browse code

Allows for RemoveColumn to delete columns not fetched

  • Loading branch information...
commit 88bd95bc9425d07e746814ac3d27a7df18b49c6c 1 parent 0a195d6
gillotte authored September 09, 2012
54  src/FluentColumnFamily.cs
@@ -145,8 +145,37 @@ public override IList<FluentColumn> Columns
145 145
 		{
146 146
 			get { return _columns; }
147 147
 		}
  148
+	    
  149
+        public override void RemoveColumn(object name)
  150
+        {
  151
+            FluentColumn col = Columns.FirstOrDefault(c => c.ColumnName == name);
148 152
 
149  
-		/// <summary>
  153
+            if (col != null)
  154
+            {
  155
+                Columns.Remove(col);
  156
+            }
  157
+            else
  158
+            {
  159
+                var cfSchema = GetSchema();
  160
+                var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
  161
+
  162
+                if (schema != null)
  163
+                {
  164
+                    col = new FluentColumn(schema);
  165
+                    col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
  166
+                }
  167
+                else
  168
+                {
  169
+                    col = new FluentColumn();
  170
+                    col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
  171
+                }
  172
+
  173
+                col.SetParent(GetSelf());
  174
+                MutationTracker.ColumnMutated(MutationType.Removed, col);
  175
+            }
  176
+        }
  177
+
  178
+	    /// <summary>
150 179
 		/// Gets the path.
151 180
 		/// </summary>
152 181
 		/// <returns></returns>
@@ -249,29 +278,6 @@ public override bool TrySetColumn(object name, object value)
249 278
 			return true;
250 279
 		}
251 280
 
252  
-        public void DeleteColumn(object name)
253  
-        {
254  
-            var cfSchema = GetSchema();
255  
-            var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
256  
-
257  
-            if(schema != null)
258  
-            {
259  
-                FluentColumn col = new FluentColumn(schema);
260  
-                col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
261  
-                col.SetParent(GetSelf());
262  
-
263  
-                MutationTracker.ColumnMutated(MutationType.Removed, col);
264  
-            }
265  
-            else
266  
-            {
267  
-                FluentColumn col = new FluentColumn();
268  
-                col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
269  
-                col.SetParent(GetSelf());
270  
-
271  
-                MutationTracker.ColumnMutated(MutationType.Removed, col);
272  
-            }
273  
-        }
274  
-
275 281
 		public override string ToString()
276 282
 		{
277 283
 			return String.Format("{0} - {1}", FamilyName, Key);
7  src/FluentCqlRow.cs
@@ -112,7 +112,12 @@ public override IList<FluentColumn> Columns
112 112
 			get { return _columns; }
113 113
 		}
114 114
 
115  
-		public CassandraObject this[CassandraObject columnName]
  115
+	    public override void RemoveColumn(object name)
  116
+	    {
  117
+            throw new NotSupportedException();
  118
+	    }
  119
+
  120
+	    public CassandraObject this[CassandraObject columnName]
116 121
 		{
117 122
 			get
118 123
 			{
11  src/FluentRecord.cs
@@ -170,12 +170,19 @@ public IFluentMutationTracker MutationTracker
170 170
 			private set;
171 171
 		}
172 172
 
173  
-		public void RemoveColumn(object name)
  173
+	    public abstract void RemoveColumn(object name);
  174
+
  175
+		public bool TryRemoveColumn(object name)
174 176
 		{
175 177
 			var col = Columns.FirstOrDefault(c => c.ColumnName == name);
176 178
 
177 179
 			if (col != null)
178  
-				Columns.Remove(col);
  180
+			{
  181
+			    Columns.Remove(col);
  182
+			    return true;
  183
+			}
  184
+
  185
+		    return false;
179 186
 		}
180 187
 
181 188
 		protected void ResetMutation()
30  src/FluentSuperColumn.cs
@@ -87,7 +87,35 @@ public override IList<FluentColumn> Columns
87 87
 			get { return _columns; }
88 88
 		}
89 89
 
90  
-		/// <summary>
  90
+        public override void RemoveColumn(object name)
  91
+        {
  92
+            FluentColumn col = Columns.FirstOrDefault(c => c.ColumnName == name);
  93
+
  94
+            if (col != null)
  95
+            {
  96
+                Columns.Remove(col);
  97
+            }
  98
+            else
  99
+            {                
  100
+                var schema = GetColumnSchema(name);
  101
+
  102
+                if (schema != null)
  103
+                {
  104
+                    col = new FluentColumn(schema);
  105
+                    col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
  106
+                }
  107
+                else
  108
+                {
  109
+                    col = new FluentColumn();
  110
+                    col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
  111
+                }
  112
+
  113
+                col.SetParent(GetPath());
  114
+                MutationTracker.ColumnMutated(MutationType.Removed, col);
  115
+            }
  116
+        }
  117
+
  118
+	    /// <summary>
91 119
 		/// 
92 120
 		/// </summary>
93 121
 		public FluentSuperColumnFamily Family
31  src/FluentSuperColumnFamily.cs
@@ -130,7 +130,36 @@ public override IList<FluentSuperColumn> Columns
130 130
 			get { return _columns; }
131 131
 		}
132 132
 
133  
-		/// <summary>
  133
+        public override void RemoveColumn(object name)
  134
+        {
  135
+            var col = Columns.FirstOrDefault(c => c.ColumnName == name);
  136
+
  137
+            if (col != null)
  138
+            {
  139
+                Columns.Remove(col);
  140
+            }
  141
+            else
  142
+            {
  143
+                var cfSchema = GetSchema();
  144
+                var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
  145
+
  146
+                if (schema != null)
  147
+                {
  148
+                    col = new FluentSuperColumn(schema);
  149
+                    col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
  150
+                }
  151
+                else
  152
+                {
  153
+                    col = new FluentSuperColumn();
  154
+                    col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
  155
+                }
  156
+
  157
+                col.SetParent(GetSelf());
  158
+                MutationTracker.ColumnMutated(MutationType.Removed, col);
  159
+            }
  160
+        }
  161
+
  162
+	    /// <summary>
134 163
 		/// 
135 164
 		/// </summary>
136 165
 		public CassandraColumnFamilySchema GetSchema()

0 notes on commit 88bd95b

Please sign in to comment.
Something went wrong with that request. Please try again.