Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 199 lines (173 sloc) 3.981 kb
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
1 using System;
a47e07d @nberardi have a new outlook on how columns should be structured, to support the m...
nberardi authored
2 using FluentCassandra.Types;
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
3
4 namespace FluentCassandra
5 {
2f86912 @nberardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
6 [Obsolete("Use \"FluentColumn\" class with out generic type")]
7 public class FluentColumn<CompareWith> : FluentColumn
d576460 @nberardi made the type system more robus to support parsing of complex types from...
nberardi authored
8 where CompareWith : CassandraObject
2f86912 @nberardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
9 {
10 public FluentColumn()
11 : base(new CassandraColumnSchema {
12 NameType = typeof(CompareWith),
13 ValueType = typeof(BytesType)
14 }) { }
15 }
16
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
17 /// <summary>
18 ///
19 /// </summary>
20 /// <typeparam name="T"></typeparam>
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
21 public class FluentColumn : IFluentBaseColumn
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
22 {
d576460 @nberardi made the type system more robus to support parsing of complex types from...
nberardi authored
23 private CassandraObject _name;
24 private CassandraObject _value;
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
25
cdf0b73 @nberardi added tests to make sure everything works correctly in the type conversi...
nberardi authored
26 private FluentColumnParent _parent;
fae0bc5 @nberardi fixed a bug dealing with mutations
nberardi authored
27 private IFluentBaseColumnFamily _family;
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
28 private CassandraColumnSchema _schema;
dc0875f @nberardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
29 private int? _ttl;
a47e07d @nberardi have a new outlook on how columns should be structured, to support the m...
nberardi authored
30
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
31 public FluentColumn(CassandraColumnSchema schema = null)
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
32 {
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
33 SetSchema(schema);
34
a19e80c @nberardi added commenting to the demo
nberardi authored
35 ColumnTimestamp = DateTimeOffset.UtcNow;
dc0875f @nberardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
36 ColumnSecondsUntilDeleted = null;
2b76325 @nberardi added the new types introduced in Cassandra 1.0.0
nberardi authored
37 ColumnTimeUntilDeleted = null;
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
38 }
39
0999b21 @nberardi added prelim support for SuperColumn
nberardi authored
40 /// <summary>
41 /// The column name.
42 /// </summary>
d576460 @nberardi made the type system more robus to support parsing of complex types from...
nberardi authored
43 public CassandraObject ColumnName
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
44 {
45 get { return _name; }
46 set
47 {
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
48 _name = value.GetValue(GetSchema().NameType);
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
49 ColumnTimestamp = DateTimeOffset.UtcNow;
50 }
51 }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
52
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
53 /// <summary>
54 ///
55 /// </summary>
d576460 @nberardi made the type system more robus to support parsing of complex types from...
nberardi authored
56 public CassandraObject ColumnValue
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
57 {
2db6327 @nberardi going through some changes to make the interface the objects more useful...
nberardi authored
58 get { return _value; }
59 set
60 {
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
61 _value = value.GetValue(GetSchema().ValueType);
a19e80c @nberardi added commenting to the demo
nberardi authored
62 ColumnTimestamp = DateTimeOffset.UtcNow;
2db6327 @nberardi going through some changes to make the interface the objects more useful...
nberardi authored
63 }
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
64 }
65
0999b21 @nberardi added prelim support for SuperColumn
nberardi authored
66 /// <summary>
67 /// The column timestamp.
68 /// </summary>
a19e80c @nberardi added commenting to the demo
nberardi authored
69 public DateTimeOffset ColumnTimestamp
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
70 {
71 get;
72 internal set;
73 }
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
74
0999b21 @nberardi added prelim support for SuperColumn
nberardi authored
75 /// <summary>
f784bbc @nberardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
76 ///
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
77 /// </summary>
fae0bc5 @nberardi fixed a bug dealing with mutations
nberardi authored
78 public IFluentBaseColumnFamily Family
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
79 {
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
80 get
81 {
82 if (_family == null && _parent != null)
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
83 _family = _parent.ColumnFamily;
f77d3d9 @nberardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
84
85 return _family;
86 }
f784bbc @nberardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
87 internal set
88 {
89 _family = value;
90 UpdateParent(GetParent());
91 }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
92 }
93
94 /// <summary>
ce017c8 @nberardi all tests working for 0.7
nberardi authored
95 ///
96 /// </summary>
dc0875f @nberardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
97 public int? ColumnSecondsUntilDeleted
ce017c8 @nberardi all tests working for 0.7
nberardi authored
98 {
dc0875f @nberardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
99 get { return _ttl; }
100 set
101 {
2b76325 @nberardi added the new types introduced in Cassandra 1.0.0
nberardi authored
102 if (value.HasValue && value < 1)
103 throw new CassandraException("ColumnSecondsUntilDeleted needs to be set to a postive value that is greater than zero.");
dc0875f @nberardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
104
105 _ttl = value;
106 }
ce017c8 @nberardi all tests working for 0.7
nberardi authored
107 }
108
109 /// <summary>
2b76325 @nberardi added the new types introduced in Cassandra 1.0.0
nberardi authored
110 ///
111 /// </summary>
112 public TimeSpan? ColumnTimeUntilDeleted
113 {
114 get
115 {
116 if (ColumnSecondsUntilDeleted.HasValue)
117 return TimeSpan.FromSeconds(ColumnSecondsUntilDeleted.Value);
118
119 return null;
120 }
121 set
122 {
123 if (value.HasValue && value.Value < TimeSpan.FromSeconds(1))
124 throw new CassandraException("ColumnTimeUntilDeleted needs to be set to a postive TimeSpan that is greater than or equal to 1 second.");
125
126 if (value.HasValue)
127 ColumnSecondsUntilDeleted = Convert.ToInt32(value.Value.TotalSeconds);
5b513eb @nberardi corrected some spaces to tab issues and made sure the tests worked from ...
nberardi authored
128 else
129 ColumnSecondsUntilDeleted = null;
2b76325 @nberardi added the new types introduced in Cassandra 1.0.0
nberardi authored
130 }
131 }
132
133 /// <summary>
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
134 ///
135 /// </summary>
136 public CassandraColumnSchema GetSchema()
137 {
138 if (_schema == null)
139 _schema = new CassandraColumnSchema { Name = ColumnName, ValueType = ColumnValue.GetType() };
140
141 return _schema;
142 }
143
144 /// <summary>
145 ///
146 /// </summary>
147 /// <param name="schema"></param>
148 public void SetSchema(CassandraColumnSchema schema)
149 {
150 if (schema == null)
10617e5 @nberardi all tests now pass
nberardi authored
151 schema = new CassandraColumnSchema();
152
153 if (_name != null)
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
154 _name = _name.GetValue(schema.NameType);
10617e5 @nberardi all tests now pass
nberardi authored
155
156 if (_value != null)
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
157 _value = _value.GetValue(schema.ValueType);
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
158
159 _schema = schema;
160 }
161
162 /// <summary>
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
163 /// Gets the path.
164 /// </summary>
165 /// <returns></returns>
166 public FluentColumnPath GetPath()
167 {
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
168 return new FluentColumnPath(_parent, this);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
169 }
170
171 /// <summary>
172 /// Gets the parent.
173 /// </summary>
174 /// <returns></returns>
175 public FluentColumnParent GetParent()
176 {
cdf0b73 @nberardi added tests to make sure everything works correctly in the type conversi...
nberardi authored
177 return _parent;
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
178 }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
179
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
180 /// <summary>
181 ///
182 /// </summary>
183 /// <param name="parent"></param>
184 public void SetParent(FluentColumnParent parent)
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
185 {
f784bbc @nberardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
186 UpdateParent(parent);
187 }
188
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
189 /// <summary>
190 ///
191 /// </summary>
192 /// <param name="parent"></param>
f784bbc @nberardi making some real progress slowly rebuilding project with new cassandra t...
nberardi authored
193 private void UpdateParent(FluentColumnParent parent)
194 {
cdf0b73 @nberardi added tests to make sure everything works correctly in the type conversi...
nberardi authored
195 _parent = parent;
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
196 }
e3e35a2 @nberardi basic column_family is working in sandbox
nberardi authored
197 }
198 }
Something went wrong with that request. Please try again.