Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 235 lines (197 sloc) 5.802 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,
16 KeyType = 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());
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
41
118573f @nberardi All tests for columns and families are passing.
nberardi authored
42 }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
43
44 /// <summary>
45 ///
46 /// </summary>
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
47 /// <param name="key"></param>
48 /// <param name="columnFamily"></param>
49 /// <param name="columns"></param>
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
50 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
51 {
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
52 SetSchema(schema);
53
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
54 Key = key;
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
55 FamilyName = columnFamily;
56
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
57 _columns = new FluentColumnList<FluentSuperColumn>(GetSelf(), columns);
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
58 }
59
60 /// <summary>
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
61 /// The column name.
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
62 /// </summary>
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
63 public CassandraObject Key
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
64 {
65 get { return _key; }
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
66 set { _key = value.GetValue(GetSchema().KeyType); }
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
67 }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
68
69 /// <summary>
70 ///
71 /// </summary>
72 public string FamilyName { get; set; }
73
74 /// <summary>
75 ///
76 /// </summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
77 public ColumnType ColumnType { get { return ColumnType.Standard; } }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
78
79 /// <summary>
80 ///
81 /// </summary>
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pr…
nberardi authored
82 /// <returns></returns>
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
83 public FluentSuperColumn CreateSuperColumn()
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pr…
nberardi authored
84 {
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
85 var col = new FluentSuperColumn(GetColumnSchema(null));
86 col.SetParent(GetSelf());
87
88 return col;
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pr…
nberardi authored
89 }
90
91 /// <summary>
92 ///
93 /// </summary>
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
94 /// <returns></returns>
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
95 public FluentSuperColumn CreateSuperColumn(CassandraObject name)
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
96 {
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
97 var col = new FluentSuperColumn(GetColumnSchema(name)) {
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
98 ColumnName = name
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
99 };
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
100 col.SetParent(GetSelf());
101
102 return col;
3cf9974 @nberardi added support to allow nullables in response to issue #2
nberardi authored
103 }
104
105 /// <summary>
106 ///
107 /// </summary>
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
108 public override IList<FluentSuperColumn> Columns
118573f @nberardi All tests for columns and families are passing.
nberardi authored
109 {
110 get { return _columns; }
111 }
a47e07d @nberardi have a new outlook on how columns should be structured, to support th…
nberardi authored
112
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
113 /// <summary>
114 ///
115 /// </summary>
10617e5 @nberardi all tests now pass
nberardi authored
116 public CassandraColumnFamilySchema GetSchema()
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
117 {
118 if (_schema == null)
10617e5 @nberardi all tests now pass
nberardi authored
119 _schema = new CassandraColumnFamilySchema { FamilyName = FamilyName };
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
120
121 return _schema;
122 }
123
124 /// <summary>
125 ///
126 /// </summary>
127 /// <param name="schema"></param>
10617e5 @nberardi all tests now pass
nberardi authored
128 public void SetSchema(CassandraColumnFamilySchema schema)
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
129 {
130 if (schema == null)
10617e5 @nberardi all tests now pass
nberardi authored
131 schema = new CassandraColumnFamilySchema { FamilyName = FamilyName };
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
132
133 _schema = schema;
134 }
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
135
a47e07d @nberardi have a new outlook on how columns should be structured, to support th…
nberardi authored
136 /// <summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
137 /// Gets the path.
a47e07d @nberardi have a new outlook on how columns should be structured, to support th…
nberardi authored
138 /// </summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
139 /// <returns></returns>
140 public FluentColumnPath GetPath()
141 {
ac522e7 @nberardi added support for counter column
nberardi authored
142 return new FluentColumnPath(this, null, (FluentColumn)null);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
143 }
2345b66 @nberardi did a little clean up of the DynamicObject method, still need to supp…
nberardi authored
144
145 /// <summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
146 /// Gets the parent.
147 /// </summary>
148 /// <returns></returns>
149 public FluentColumnParent GetSelf()
150 {
fae0bc5 @nberardi fixed a bug dealing with mutations
nberardi authored
151 return new FluentColumnParent(this, null);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
152 }
fae0bc5 @nberardi fixed a bug dealing with mutations
nberardi authored
153
118573f @nberardi All tests for columns and families are passing.
nberardi authored
154 /// <summary>
2345b66 @nberardi did a little clean up of the DynamicObject method, still need to supp…
nberardi authored
155 ///
156 /// </summary>
157 /// <param name="name"></param>
158 /// <param name="result"></param>
159 /// <returns></returns>
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
160 private FluentSuperColumn GetColumnValue(object name)
161 {
162 var col = Columns.FirstOrDefault(c => c.ColumnName == name);
163 return col;
164 }
165
166 /// <summary>
167 ///
168 /// </summary>
169 /// <param name="name"></param>
170 /// <returns></returns>
171 private CassandraColumnSchema GetColumnSchema(object name)
172 {
173 var schema = GetSchema();
174
175 // mock up a fake schema to send to the fluent column
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
176 var colSchema = new CassandraColumnSchema {
177 NameType = schema.SuperColumnNameType,
178 ValueType = schema.DefaultColumnValueType
179 };
180
181 if (name != null)
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
182 colSchema.Name = CassandraObject.GetCassandraObjectFromObject(name, schema.SuperColumnNameType);
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
183
184 return colSchema;
2f86912 @nberardi all tests now compile, so the new genericless types have been provide…
nberardi authored
185 }
186
187 /// <summary>
188 ///
189 /// </summary>
190 /// <param name="name"></param>
191 /// <param name="result"></param>
192 /// <returns></returns>
12cd243 @nberardi it compiles with the new type changes, but still needs more testing t…
nberardi authored
193 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
194 {
10617e5 @nberardi all tests now pass
nberardi authored
195 var col = GetColumnValue(name);
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
196 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
197
e4efc4c @nberardi added support for session based configurations, as well as dynamic pr…
nberardi authored
198 return true;
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
199 }
200
201 /// <summary>
202 ///
203 /// </summary>
204 /// <param name="binder"></param>
205 /// <param name="value"></param>
206 /// <returns></returns>
12cd243 @nberardi it compiles with the new type changes, but still needs more testing t…
nberardi authored
207 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
208 {
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
209 if (!(value is FluentSuperColumn))
210 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
211
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
212 var schema = GetSchema();
10617e5 @nberardi all tests now pass
nberardi authored
213 var col = GetColumnValue(name);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
214 var mutationType = col == null ? MutationType.Added : MutationType.Changed;
215
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
216 col = (FluentSuperColumn)value;
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
217 col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.SuperColumnNameType);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
218
8f81f56 @nberardi fixed a couple issues with Fluent Super Column use, check out the san…
nberardi authored
219 int index = Columns.IndexOf(col);
220
118573f @nberardi All tests for columns and families are passing.
nberardi authored
221 _columns.SupressChangeNotification = true;
8f81f56 @nberardi fixed a couple issues with Fluent Super Column use, check out the san…
nberardi authored
222 if (index < 0)
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
223 Columns.Add(col);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
224 else
225 Columns.Insert(index, col);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
226 _columns.SupressChangeNotification = false;
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
227
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
228 // notify the tracker that the column has changed
229 OnColumnMutated(mutationType, col);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
230
231 return true;
232 }
233 }
234 }
Something went wrong with that request. Please try again.