Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 313 lines (260 sloc) 7.29 kb
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
a47e07d Nick Berardi have a new outlook on how columns should be structured, to support the m...
nberardi authored
4 using FluentCassandra.Types;
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
5
6 namespace FluentCassandra
7 {
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
8 [Obsolete("Use \"FluentSuperColumn\" class with out generic type")]
9 public class FluentSuperColumn<CompareWith, CompareSubcolumnWith> : FluentSuperColumn
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
10 where CompareWith : CassandraObject
11 where CompareSubcolumnWith : CassandraObject
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
12 {
13 public FluentSuperColumn()
14 : base(new CassandraColumnSchema {
15 NameType = typeof(CompareWith),
16 ValueType = typeof(CompareSubcolumnWith)
17 }) { }
18 }
19
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
20 /// <summary>
21 ///
22 /// </summary>
23 /// <typeparam name="T"></typeparam>
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
24 public class FluentSuperColumn : FluentRecord<FluentColumn>, IFluentBaseColumn, IFluentRecordExpression
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
25 {
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
26 private CassandraObject _name;
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
27 private FluentColumnParent _parent;
28 private FluentSuperColumnFamily _family;
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
29 private FluentColumnList<FluentColumn> _columns;
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
30 private CassandraColumnSchema _schema;
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
31
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
32 /// <summary>
33 ///
34 /// </summary>
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
35 public FluentSuperColumn(CassandraColumnSchema schema = null)
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
36 {
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
37 SetSchema(schema);
38
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
39 _columns = new FluentColumnList<FluentColumn>(GetPath());
d7df425 Nick Berardi reformatted the GetSlice a little to return the column family instead of...
nberardi authored
40 }
41
42 /// <summary>
43 ///
44 /// </summary>
45 /// <param name="columns"></param>
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
46 internal FluentSuperColumn(CassandraColumnSchema schema, IEnumerable<FluentColumn> columns)
d7df425 Nick Berardi reformatted the GetSlice a little to return the column family instead of...
nberardi authored
47 {
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
48 SetSchema(schema);
49
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
50 _columns = new FluentColumnList<FluentColumn>(GetPath(), columns);
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
51 }
52
12cd243 Nick Berardi it compiles with the new type changes, but still needs more testing to m...
nberardi authored
53 /// <summary>
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
54 /// The column name.
12cd243 Nick Berardi it compiles with the new type changes, but still needs more testing to m...
nberardi authored
55 /// </summary>
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
56 public CassandraObject ColumnName
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
57 {
58 get { return _name; }
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
59 set { _name = value.GetValue(GetSchema().NameType); }
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
60 }
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
61
62 /// <summary>
f77d3d9 Nick Berardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
63 ///
64 /// </summary>
65 /// <returns></returns>
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
66 public FluentColumn CreateColumn()
f77d3d9 Nick Berardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
67 {
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
68 return new FluentColumn(GetColumnSchema(""));
69 }
70
71 /// <summary>
72 ///
73 /// </summary>
74 /// <returns></returns>
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
75 public FluentColumn CreateColumn(CassandraObject name)
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
76 {
77 return new FluentColumn(GetColumnSchema(name)) {
78 ColumnName = name
79 };
f77d3d9 Nick Berardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
80 }
81
82 /// <summary>
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
83 /// The columns in the super column.
84 /// </summary>
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
85 public override IList<FluentColumn> Columns
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
86 {
87 get { return _columns; }
88 }
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
89
88bd95b gillotte Allows for RemoveColumn to delete columns not fetched
gillotte authored
90 /// <summary>
88be638 Nick Berardi did some clean up and Get is now supported for a single column
nberardi authored
91 ///
92 /// </summary>
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
93 public FluentSuperColumnFamily Family
88be638 Nick Berardi did some clean up and Get is now supported for a single column
nberardi authored
94 {
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
95 get
96 {
97 if (_family == null && _parent != null)
98 _family = _parent.ColumnFamily as FluentSuperColumnFamily;
99
100 return _family;
101 }
102 internal set
103 {
104 _family = value;
105 UpdateParent(GetParent());
106 }
88be638 Nick Berardi did some clean up and Get is now supported for a single column
nberardi authored
107 }
108
109 /// <summary>
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
110 ///
111 /// </summary>
112 /// <param name="columnName"></param>
113 /// <returns></returns>
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
114 public CassandraObject this[CassandraObject columnName]
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
115 {
116 get
117 {
6a1efba Nick Berardi thanks to Igor for pointing out I didn't consistantly impliment Super Co...
nberardi authored
118 object value;
119 if (!TryGetColumn(columnName, out value))
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
120 throw new CassandraException(String.Format("Column, {0}, could not be found.", columnName));
121
6a1efba Nick Berardi thanks to Igor for pointing out I didn't consistantly impliment Super Co...
nberardi authored
122 return (CassandraObject)value;
123 }
124 set
125 {
126 TrySetColumn(columnName, value);
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
127 }
128 }
129
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
130 /// <summary>
131 ///
132 /// </summary>
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
133 public CassandraColumnSchema GetSchema()
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
134 {
135 if (_schema == null)
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
136 _schema = new CassandraColumnSchema { Name = ColumnName, ValueType = typeof(BytesType) };
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
137
138 return _schema;
139 }
140
141 /// <summary>
142 ///
143 /// </summary>
144 /// <param name="schema"></param>
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
145 public void SetSchema(CassandraColumnSchema schema)
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
146 {
147 if (schema == null)
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
148 schema = new CassandraColumnSchema { Name = ColumnName, ValueType = typeof(BytesType) };
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
149
150 _schema = schema;
151 }
b9d2f58 Nick Berardi all tests pass after most recent changes
nberardi authored
152
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
153 /// <summary>
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
154 /// Gets the path.
88be638 Nick Berardi did some clean up and Get is now supported for a single column
nberardi authored
155 /// </summary>
156 /// <returns></returns>
157 public FluentColumnPath GetPath()
158 {
ac522e7 Nick Berardi added support for counter column
nberardi authored
159 return new FluentColumnPath(Family, this, (FluentColumn)null);
88be638 Nick Berardi did some clean up and Get is now supported for a single column
nberardi authored
160 }
161
162 /// <summary>
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
163 /// Gets the parent.
88be638 Nick Berardi did some clean up and Get is now supported for a single column
nberardi authored
164 /// </summary>
165 /// <returns></returns>
166 public FluentColumnParent GetParent()
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
167 {
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
168 return _parent ?? new FluentColumnParent(Family, this);
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
169 }
170
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
171 /// <summary>
172 ///
173 /// </summary>
174 /// <param name="name"></param>
175 /// <param name="result"></param>
176 /// <returns></returns>
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
177 private CassandraObject GetColumnValue(object name)
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
178 {
179 var col = Columns.FirstOrDefault(c => c.ColumnName == name);
180
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
181 if (col == null)
182 return NullType.Value;
183
184 var schema = GetColumnSchema(name);
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
185 return col.ColumnValue.GetValue(schema.ValueType);
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
186 }
187
188 /// <summary>
189 ///
190 /// </summary>
191 /// <param name="name"></param>
192 /// <returns></returns>
193 private CassandraColumnSchema GetColumnSchema(object name)
194 {
195 var schema = GetSchema();
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
196 var valueType = CassandraType.BytesType;
197
198 if (Family != null)
199 valueType = Family.GetSchema().DefaultColumnValueType;
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
200
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
201 // mock up a fake schema to send to the fluent column
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
202 return new CassandraColumnSchema { NameType = schema.ValueType, ValueType = valueType };
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
203 }
204
205 /// <summary>
206 ///
207 /// </summary>
208 /// <param name="name"></param>
209 /// <param name="result"></param>
210 /// <returns></returns>
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
211 public override bool TryGetColumn(object name, out object result)
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
212 {
441d12f Nick Berardi finished support for IndexExpression and added a couple tests to verify ...
nberardi authored
213 result = GetColumnValue(name);
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
214
6a1efba Nick Berardi thanks to Igor for pointing out I didn't consistantly impliment Super Co...
nberardi authored
215 return !(result is NullType);
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
216 }
217
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
218 /// <summary>
219 ///
220 /// </summary>
221 /// <param name="name"></param>
222 /// <param name="value"></param>
223 /// <returns></returns>
224 public override bool TrySetColumn(object name, object value)
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
225 {
a19e80c Nick Berardi added commenting to the demo
nberardi authored
226 var col = Columns.FirstOrDefault(c => c.ColumnName == name);
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
227 var mutationType = MutationType.Changed;
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
228
3be9d21 Nick Berardi moved around a couple things
nberardi authored
229 // if column doesn't exist create it and add it to the columns
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
230 if (col == null)
231 {
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
232 var schema = GetColumnSchema(name);
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
233 mutationType = MutationType.Added;
234
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
235 col = new FluentColumn(schema);
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
236 col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
237
118573f Nick Berardi All tests for columns and families are passing.
nberardi authored
238 _columns.SupressChangeNotification = true;
239 _columns.Add(col);
240 _columns.SupressChangeNotification = false;
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
241 }
242
243 // set the column value
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
244 col.ColumnValue = CassandraObject.GetCassandraObjectFromObject(value);
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
245
246 // notify the tracker that the column has changed
247 OnColumnMutated(mutationType, col);
248
249 return true;
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
250 }
251
3be9d21 Nick Berardi moved around a couple things
nberardi authored
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
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
275 public void SetParent(FluentColumnParent parent)
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
276 {
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
277 UpdateParent(parent);
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
278 }
279
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
280 private void UpdateParent(FluentColumnParent parent)
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
281 {
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
282 if (!(parent.ColumnFamily is FluentSuperColumnFamily))
283 throw new ArgumentException("ColumnFamily must be of type FluentSuperColumnFamily.", "parent");
284
285 _parent = parent;
fae0bc5 Nick Berardi fixed a bug dealing with mutations
nberardi authored
286
287 var columnParent = GetPath();
288 _columns.Parent = columnParent;
f77d3d9 Nick Berardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
289
f784bbc Nick Berardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
290 foreach (var col in Columns)
f77d3d9 Nick Berardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
291 col.SetParent(columnParent);
fae0bc5 Nick Berardi fixed a bug dealing with mutations
nberardi authored
292
24ea521 Nick Berardi fixed up some issues I had with one off methods for reseting the mutatio...
nberardi authored
293 if (!SuppressMutationTracking) {
294 MutationTracker.Clear();
295
296 foreach (var col in Columns)
297 MutationTracker.ColumnMutated(MutationType.Added, col);
298 }
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
299 }
300
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
301 #region IFluentBaseColumn Members
302
303 IFluentBaseColumnFamily IFluentBaseColumn.Family { get { return Family; } }
304
237dfa2 Nick Berardi able to pull back dynamic objects, still working on casting of them
nberardi authored
305 #endregion
2c77dfc Nick Berardi refactored mutation handling to better handle super columns which fixed ...
nberardi authored
306
307 public override string ToString()
308 {
309 return String.Format("{0} = {1} columns", ColumnName, Columns.Count);
310 }
0999b21 Nick Berardi added prelim support for SuperColumn
nberardi authored
311 }
312 }
Something went wrong with that request. Please try again.