Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 283 lines (237 sloc) 6.914 kB
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
a47e07d @nberardi have a new outlook on how columns should be structured, to support th…
nberardi authored
4 using FluentCassandra.Types;
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
5
6 namespace FluentCassandra
7 {
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
8 [Obsolete("Use \"FluentSuperColumn\" class with out generic type")]
9 public class FluentSuperColumnFamily<CompareWith, CompareSubcolumnWith> : FluentSuperColumnFamily
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
10 where CompareWith : CassandraObject
11 where CompareSubcolumnWith : CassandraObject
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
12 {
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
13 public FluentSuperColumnFamily(CassandraObject key, string columnFamily)
10617e5 @nberardi all tests now pass
nberardi authored
14 : base(key, columnFamily, new CassandraColumnFamilySchema {
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
15 FamilyName = columnFamily,
a9597c9 @nberardi refactored a couple of schema related changes
nberardi authored
16 KeyValueType = typeof(BytesType),
10617e5 @nberardi all tests now pass
nberardi authored
17 SuperColumnNameType = typeof(CompareWith),
18 ColumnNameType = typeof(CompareSubcolumnWith)
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
19 }) { }
20 }
21
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
22 public class FluentSuperColumnFamily : FluentRecord<FluentSuperColumn>, IFluentBaseColumnFamily
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
23 {
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
24 private CassandraObject _key;
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
25 private FluentColumnList<FluentSuperColumn> _columns;
10617e5 @nberardi all tests now pass
nberardi authored
26 private CassandraColumnFamilySchema _schema;
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
27
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
28 /// <summary>
29 ///
30 /// </summary>
31 /// <param name="key"></param>
32 /// <param name="columnFamily"></param>
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
33 public FluentSuperColumnFamily(CassandraObject key, string columnFamily, CassandraColumnFamilySchema schema = null)
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
34 {
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
35 SetSchema(schema);
36
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
37 Key = key;
7858cfe @nberardi did a little renaming
nberardi authored
38 FamilyName = columnFamily;
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
39
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
40 _columns = new FluentColumnList<FluentSuperColumn>(GetSelf());
118573f @nberardi All tests for columns and families are passing.
nberardi authored
41 }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
42
43 /// <summary>
44 ///
45 /// </summary>
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
46 /// <param name="key"></param>
47 /// <param name="columnFamily"></param>
48 /// <param name="columns"></param>
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
49 internal FluentSuperColumnFamily(CassandraObject key, string columnFamily, CassandraColumnFamilySchema schema, IEnumerable<FluentSuperColumn> columns)
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
50 {
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
51 SetSchema(schema);
52
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
53 Key = key;
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
54 FamilyName = columnFamily;
55
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
56 _columns = new FluentColumnList<FluentSuperColumn>(GetSelf(), columns);
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
57 }
58
59 /// <summary>
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
60 /// The column name.
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
61 /// </summary>
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
62 public CassandraObject Key
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
63 {
64 get { return _key; }
a9597c9 @nberardi refactored a couple of schema related changes
nberardi authored
65 set { _key = value.GetValue(GetSchema().KeyValueType); }
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
66 }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
67
68 /// <summary>
69 ///
70 /// </summary>
71 public string FamilyName { get; set; }
72
73 /// <summary>
74 ///
75 /// </summary>
98a0d47 @nberardi Fluent ColumnType in super column was being returned as Standard, ins…
nberardi authored
76 public ColumnType ColumnType { get { return ColumnType.Super; } }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
77
78 /// <summary>
79 ///
80 /// </summary>
6a1efba @nberardi thanks to Igor for pointing out I didn't consistantly impliment Super…
nberardi authored
81 /// <param name="columnName"></param>
82 /// <returns></returns>
83 public FluentSuperColumn this[CassandraObject columnName]
84 {
85 get
86 {
87 object value;
88 if (!TryGetColumn(columnName, out value))
89 throw new CassandraException(String.Format("Super Column, {0}, could not be found.", columnName));
90
91 return (FluentSuperColumn)value;
92 }
93 set
94 {
95 TrySetColumn(columnName, value);
96 }
97 }
98
99 /// <summary>
100 ///
101 /// </summary>
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pr…
nberardi authored
102 /// <returns></returns>
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
103 public FluentSuperColumn CreateSuperColumn()
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pr…
nberardi authored
104 {
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
105 var col = new FluentSuperColumn(GetColumnSchema(null));
106 col.SetParent(GetSelf());
107
108 return col;
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pr…
nberardi authored
109 }
110
111 /// <summary>
112 ///
113 /// </summary>
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
114 /// <returns></returns>
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
115 public FluentSuperColumn CreateSuperColumn(CassandraObject name)
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
116 {
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
117 var col = new FluentSuperColumn(GetColumnSchema(name)) {
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
118 ColumnName = name
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
119 };
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
120 col.SetParent(GetSelf());
121
122 return col;
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
123 }
124
125 /// <summary>
126 ///
127 /// </summary>
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
128 public override IList<FluentSuperColumn> Columns
118573f @nberardi All tests for columns and families are passing.
nberardi authored
129 {
130 get { return _columns; }
131 }
a47e07d @nberardi have a new outlook on how columns should be structured, to support th…
nberardi authored
132
88bd95b @gillotte Allows for RemoveColumn to delete columns not fetched
gillotte authored
133 /// <summary>
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
134 ///
135 /// </summary>
10617e5 @nberardi all tests now pass
nberardi authored
136 public CassandraColumnFamilySchema GetSchema()
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
137 {
138 if (_schema == null)
10617e5 @nberardi all tests now pass
nberardi authored
139 _schema = new CassandraColumnFamilySchema { FamilyName = FamilyName };
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
140
141 return _schema;
142 }
143
144 /// <summary>
145 ///
146 /// </summary>
147 /// <param name="schema"></param>
10617e5 @nberardi all tests now pass
nberardi authored
148 public void SetSchema(CassandraColumnFamilySchema schema)
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
149 {
150 if (schema == null)
10617e5 @nberardi all tests now pass
nberardi authored
151 schema = new CassandraColumnFamilySchema { FamilyName = FamilyName };
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
152
153 _schema = schema;
154 }
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
155
a47e07d @nberardi have a new outlook on how columns should be structured, to support th…
nberardi authored
156 /// <summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
157 /// Gets the path.
a47e07d @nberardi have a new outlook on how columns should be structured, to support th…
nberardi authored
158 /// </summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
159 /// <returns></returns>
160 public FluentColumnPath GetPath()
161 {
ac522e7 @nberardi added support for counter column
nberardi authored
162 return new FluentColumnPath(this, null, (FluentColumn)null);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
163 }
2345b66 @nberardi did a little clean up of the DynamicObject method, still need to supp…
nberardi authored
164
165 /// <summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
166 /// Gets the parent.
167 /// </summary>
168 /// <returns></returns>
169 public FluentColumnParent GetSelf()
170 {
fae0bc5 @nberardi fixed a bug dealing with mutations
nberardi authored
171 return new FluentColumnParent(this, null);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
172 }
fae0bc5 @nberardi fixed a bug dealing with mutations
nberardi authored
173
118573f @nberardi All tests for columns and families are passing.
nberardi authored
174 /// <summary>
2345b66 @nberardi did a little clean up of the DynamicObject method, still need to supp…
nberardi authored
175 ///
176 /// </summary>
177 /// <param name="name"></param>
178 /// <param name="result"></param>
179 /// <returns></returns>
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
180 private FluentSuperColumn GetColumnValue(object name)
181 {
182 var col = Columns.FirstOrDefault(c => c.ColumnName == name);
183 return col;
184 }
185
186 /// <summary>
187 ///
188 /// </summary>
189 /// <param name="name"></param>
190 /// <returns></returns>
191 private CassandraColumnSchema GetColumnSchema(object name)
192 {
193 var schema = GetSchema();
194
195 // mock up a fake schema to send to the fluent column
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
196 var colSchema = new CassandraColumnSchema {
197 NameType = schema.SuperColumnNameType,
198 ValueType = schema.DefaultColumnValueType
199 };
200
201 if (name != null)
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
202 colSchema.Name = CassandraObject.GetCassandraObjectFromObject(name, schema.SuperColumnNameType);
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
203
204 return colSchema;
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
205 }
206
207 /// <summary>
208 ///
209 /// </summary>
210 /// <param name="name"></param>
211 /// <param name="result"></param>
212 /// <returns></returns>
12cd243 @nberardi it compiles with the new type changes, but still needs more testing t…
nberardi authored
213 public override bool TryGetColumn(object name, out object result)
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
214 {
10617e5 @nberardi all tests now pass
nberardi authored
215 var col = GetColumnValue(name);
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
216 result = (col == null) ? CreateSuperColumn(CassandraObject.GetCassandraObjectFromObject(name)) : col;
7b7ddf8 @nberardi fixed a couple tests for the release of 0.7.0 of Cassandra
nberardi authored
217
e4efc4c @nberardi added support for session based configurations, as well as dynamic pr…
nberardi authored
218 return true;
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
219 }
220
221 /// <summary>
222 ///
223 /// </summary>
224 /// <param name="binder"></param>
225 /// <param name="value"></param>
226 /// <returns></returns>
12cd243 @nberardi it compiles with the new type changes, but still needs more testing t…
nberardi authored
227 public override bool TrySetColumn(object name, object value)
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
228 {
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
229 if (!(value is FluentSuperColumn))
230 throw new ArgumentException("Value must be of type " + typeof(FluentSuperColumn) + ", because this column family is of type Super.", "value");
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
231
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
232 var schema = GetSchema();
10617e5 @nberardi all tests now pass
nberardi authored
233 var col = GetColumnValue(name);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
234 var mutationType = col == null ? MutationType.Added : MutationType.Changed;
235
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
236 col = (FluentSuperColumn)value;
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
237 col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.SuperColumnNameType);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
238
8f81f56 @nberardi fixed a couple issues with Fluent Super Column use, check out the san…
nberardi authored
239 int index = Columns.IndexOf(col);
240
118573f @nberardi All tests for columns and families are passing.
nberardi authored
241 _columns.SupressChangeNotification = true;
8f81f56 @nberardi fixed a couple issues with Fluent Super Column use, check out the san…
nberardi authored
242 if (index < 0)
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
243 Columns.Add(col);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
244 else
245 Columns.Insert(index, col);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
246 _columns.SupressChangeNotification = false;
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
247
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
248 // notify the tracker that the column has changed
249 OnColumnMutated(mutationType, col);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
250
251 return true;
252 }
2c77dfc @nberardi refactored mutation handling to better handle super columns which fix…
nberardi authored
253
3be9d21 @nberardi moved around a couple things
nberardi authored
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
2c77dfc @nberardi refactored mutation handling to better handle super columns which fix…
nberardi authored
277 public override string ToString()
278 {
279 return String.Format("{0} - {1}", FamilyName, Key);
280 }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
281 }
282 }
Something went wrong with that request. Please try again.