Skip to content
This repository
Browse code

moved around a couple things

  • Loading branch information...
commit 3be9d2172c06ea59af1c9d8524c8dde28300ab40 1 parent fc335e7
Nick Berardi authored September 24, 2012
67  src/FluentColumnFamily.cs
@@ -80,18 +80,8 @@ public CassandraObject Key
80 80
 		/// <returns></returns>
81 81
 		public CassandraObject this[CassandraObject columnName]
82 82
 		{
83  
-			get
84  
-			{
85  
-				object value;
86  
-				if (!TryGetColumn(columnName, out value))
87  
-					throw new CassandraException(String.Format("Column, {0}, could not be found.", columnName));
88  
-
89  
-				return (CassandraObject)value;
90  
-			}
91  
-			set
92  
-			{
93  
-				TrySetColumn(columnName, value);
94  
-			}
  83
+			get { return GetColumnValue(columnName); }
  84
+			set { SetColumn(columnName, value); }
95 85
 		}
96 86
 
97 87
 		/// <summary>
@@ -145,35 +135,6 @@ public override IList<FluentColumn> Columns
145 135
 		{
146 136
 			get { return _columns; }
147 137
 		}
148  
-	    
149  
-        public override void RemoveColumn(object name)
150  
-        {
151  
-            FluentColumn col = Columns.FirstOrDefault(c => c.ColumnName == name);
152  
-
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 138
 
178 139
 	    /// <summary>
179 140
 		/// Gets the path.
@@ -278,9 +239,31 @@ public override bool TrySetColumn(object name, object value)
278 239
 			return true;
279 240
 		}
280 241
 
  242
+		public override bool TryRemoveColumn(object name)
  243
+		{
  244
+			var col = Columns.FirstOrDefault(c => c.ColumnName == name);
  245
+
  246
+			if (col != null) {
  247
+				Columns.Remove(col);
  248
+				return true;
  249
+			}
  250
+
  251
+			var schema = GetColumnSchema(name);
  252
+			var mutationType = MutationType.Removed;
  253
+
  254
+			col = new FluentColumn(schema);
  255
+			col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
  256
+			col.SetParent(GetSelf());
  257
+
  258
+			// notify the tracker that the column has changed
  259
+			OnColumnMutated(mutationType, col);
  260
+
  261
+			return true;
  262
+		}
  263
+
281 264
 		public override string ToString()
282 265
 		{
283 266
 			return String.Format("{0} - {1}", FamilyName, Key);
284 267
 		}
285 268
 	}
286  
-}
  269
+}
10  src/FluentCqlRow.cs
@@ -95,6 +95,11 @@ public override bool TrySetColumn(object name, object value)
95 95
 			throw new NotSupportedException();
96 96
 		}
97 97
 
  98
+		public override bool TryRemoveColumn(object name)
  99
+	    {
  100
+            throw new NotSupportedException();
  101
+	    }
  102
+
98 103
 		public string FamilyName
99 104
 		{
100 105
 			get;
@@ -112,11 +117,6 @@ public override IList<FluentColumn> Columns
112 117
 			get { return _columns; }
113 118
 		}
114 119
 
115  
-	    public override void RemoveColumn(object name)
116  
-	    {
117  
-            throw new NotSupportedException();
118  
-	    }
119  
-
120 120
 	    public CassandraObject this[CassandraObject columnName]
121 121
 		{
122 122
 			get
92  src/FluentRecord.cs
@@ -9,7 +9,7 @@ namespace FluentCassandra
9 9
 	/// <summary>
10 10
 	/// 
11 11
 	/// </summary>
12  
-	/// <typeparam name="T">A type that impliments <see cref="IFluentColumn"/>.</typeparam>
  12
+	/// <typeparam name="T">A type that implements <see cref="IFluentColumn"/>.</typeparam>
13 13
 	public abstract class FluentRecord<T> : DynamicObject, IFluentRecord, INotifyPropertyChanged, IEnumerable<IFluentBaseColumn>, ILoadable
14 14
 		where T : IFluentBaseColumn
15 15
 	{
@@ -27,6 +27,53 @@ public FluentRecord()
27 27
 		/// </summary>
28 28
 		public abstract IList<T> Columns { get; }
29 29
 
  30
+		public T GetColumn(object name)
  31
+		{
  32
+			var col = Columns.FirstOrDefault(c => c.ColumnName == name);
  33
+
  34
+			if (col == null)
  35
+				return default(T);
  36
+
  37
+			return col;
  38
+		}
  39
+
  40
+		public bool SetColumn(object name, object value)
  41
+		{
  42
+			return TrySetColumn(name, value);
  43
+		}
  44
+
  45
+		public bool RemoveColumn(object name)
  46
+		{
  47
+			return TryRemoveColumn(name);
  48
+		}
  49
+
  50
+		/// <summary>
  51
+		/// 
  52
+		/// </summary>
  53
+		/// <param name="name"></param>
  54
+		/// <param name="result"></param>
  55
+		/// <returns></returns>
  56
+		[EditorBrowsable(EditorBrowsableState.Never)]
  57
+		public abstract bool TryGetColumn(object name, out object result);
  58
+
  59
+		/// <summary>
  60
+		/// 
  61
+		/// </summary>
  62
+		/// <param name="name"></param>
  63
+		/// <param name="value"></param>
  64
+		/// <returns></returns>
  65
+		[EditorBrowsable(EditorBrowsableState.Never)]
  66
+		public abstract bool TrySetColumn(object name, object value);
  67
+
  68
+
  69
+		/// 
  70
+		/// </summary>
  71
+		/// <param name="name"></param>
  72
+		/// <param name="value"></param>
  73
+		/// <returns></returns>
  74
+		[EditorBrowsable(EditorBrowsableState.Never)]
  75
+		public abstract bool TryRemoveColumn(object name);
  76
+
30 77
 		/// <summary>
31 78
 		/// 
32 79
 		/// </summary>
@@ -66,15 +113,6 @@ public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out ob
66 113
 		/// <summary>
67 114
 		/// 
68 115
 		/// </summary>
69  
-		/// <param name="name"></param>
70  
-		/// <param name="result"></param>
71  
-		/// <returns></returns>
72  
-		[EditorBrowsable(EditorBrowsableState.Never)]
73  
-		public abstract bool TryGetColumn(object name, out object result);
74  
-
75  
-		/// <summary>
76  
-		/// 
77  
-		/// </summary>
78 116
 		/// <param name="binder"></param>
79 117
 		/// <param name="value"></param>
80 118
 		/// <returns></returns>
@@ -105,7 +143,24 @@ public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object
105 143
 		/// <param name="value"></param>
106 144
 		/// <returns></returns>
107 145
 		[EditorBrowsable(EditorBrowsableState.Never)]
108  
-		public abstract bool TrySetColumn(object name, object value);
  146
+		public override bool TryDeleteMember(DeleteMemberBinder binder)
  147
+		{
  148
+			return TryRemoveColumn(binder.Name);
  149
+		}
  150
+
  151
+		/// <summary>
  152
+		/// 
  153
+		/// </summary>
  154
+		/// <param name="binder"></param>
  155
+		/// <param name="indexes"></param>
  156
+		/// <param name="value"></param>
  157
+		/// <returns></returns>
  158
+		[EditorBrowsable(EditorBrowsableState.Never)]
  159
+		public override bool TryDeleteIndex(DeleteIndexBinder binder, object[] indexes)
  160
+		{
  161
+			object index0 = indexes[0];
  162
+			return TryRemoveColumn(index0);
  163
+		}
109 164
 
110 165
 		protected bool SuppressMutationTracking { get; private set; }
111 166
 
@@ -170,21 +225,6 @@ public IFluentMutationTracker MutationTracker
170 225
 			private set;
171 226
 		}
172 227
 
173  
-	    public abstract void RemoveColumn(object name);
174  
-
175  
-		public bool TryRemoveColumn(object name)
176  
-		{
177  
-			var col = Columns.FirstOrDefault(c => c.ColumnName == name);
178  
-
179  
-			if (col != null)
180  
-			{
181  
-			    Columns.Remove(col);
182  
-			    return true;
183  
-			}
184  
-
185  
-		    return false;
186  
-		}
187  
-
188 228
 		#endregion
189 229
 	}
190 230
 }
53  src/FluentSuperColumn.cs
@@ -87,34 +87,6 @@ public override IList<FluentColumn> Columns
87 87
 			get { return _columns; }
88 88
 		}
89 89
 
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 90
 	    /// <summary>
119 91
 		/// 
120 92
 		/// </summary>
@@ -254,7 +226,7 @@ public override bool TrySetColumn(object name, object value)
254 226
 			var col = Columns.FirstOrDefault(c => c.ColumnName == name);
255 227
 			var mutationType = MutationType.Changed;
256 228
 
257  
-			// if column doesn't exisit create it and add it to the columns
  229
+			// if column doesn't exist create it and add it to the columns
258 230
 			if (col == null)
259 231
 			{
260 232
 				var schema = GetColumnSchema(name);
@@ -277,6 +249,29 @@ public override bool TrySetColumn(object name, object value)
277 249
 			return true;
278 250
 		}
279 251
 
  252
+		public override bool TryRemoveColumn(object name)
  253
+		{
  254
+			var col = Columns.FirstOrDefault(c => c.ColumnName == name);
  255
+
  256
+			if (col != null)
  257
+			{
  258
+				Columns.Remove(col);
  259
+				return true;
  260
+			}
  261
+
  262
+			var schema = GetColumnSchema(name);
  263
+			var mutationType = MutationType.Removed;
  264
+
  265
+			col = new FluentColumn(schema);
  266
+			col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
  267
+			col.SetParent(GetPath());
  268
+
  269
+			// notify the tracker that the column has changed
  270
+			OnColumnMutated(mutationType, col);
  271
+
  272
+			return true;
  273
+		}
  274
+
280 275
 		public void SetParent(FluentColumnParent parent)
281 276
 		{
282 277
 			UpdateParent(parent);
52  src/FluentSuperColumnFamily.cs
@@ -130,35 +130,6 @@ public override IList<FluentSuperColumn> Columns
130 130
 			get { return _columns; }
131 131
 		}
132 132
 
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 133
 	    /// <summary>
163 134
 		/// 
164 135
 		/// </summary>
@@ -280,6 +251,29 @@ public override bool TrySetColumn(object name, object value)
280 251
 			return true;
281 252
 		}
282 253
 
  254
+		public override bool TryRemoveColumn(object name)
  255
+		{
  256
+			var col = Columns.FirstOrDefault(c => c.ColumnName == name);
  257
+
  258
+			if (col != null)
  259
+			{
  260
+				Columns.Remove(col);
  261
+				return true;
  262
+			}
  263
+
  264
+			var schema = GetColumnSchema(name);
  265
+			var mutationType = MutationType.Removed;
  266
+
  267
+			col = new FluentSuperColumn(schema);
  268
+			col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
  269
+			col.SetParent(GetSelf());
  270
+
  271
+			// notify the tracker that the column has changed
  272
+			OnColumnMutated(mutationType, col);
  273
+
  274
+			return true;
  275
+		}
  276
+
283 277
 		public override string ToString()
284 278
 		{
285 279
 			return String.Format("{0} - {1}", FamilyName, Key);
13  src/Types/CassandraObject.cs
@@ -207,16 +207,13 @@ public static CassandraObject GetCassandraObjectFromDatabaseByteArray(byte[] val
207 207
 			return GetCassandraObjectFromDatabaseByteArray(value, cassandraType);
208 208
 		}
209 209
 
210  
-		public static CassandraObject GetCassandraObjectFromObject(object obj)
  210
+		public static CassandraObject GetCassandraObjectFromObject(object obj, CassandraType cassandraType = null)
211 211
 		{
212  
-			var sourceType = obj.GetType();
213  
-			var cassandraType = CassandraType.GetCassandraType(sourceType);
  212
+			if (cassandraType == null) {
  213
+				var sourceType = obj.GetType();
  214
+				cassandraType = CassandraType.GetCassandraType(sourceType);
  215
+			}
214 216
 
215  
-			return GetCassandraObjectFromObject(obj, cassandraType);
216  
-		}
217  
-
218  
-		public static CassandraObject GetCassandraObjectFromObject(object obj, CassandraType cassandraType)
219  
-		{
220 217
 			if (obj == null)
221 218
 				return null;
222 219
 

0 notes on commit 3be9d21

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