Skip to content
This repository
Newer
Older
100644 166 lines (141 sloc) 4.217 kb
1adec35a »
2010-04-17 connections now are object oriented, and basic keyspace and column fa…
1 using System;
2 using System.Collections.Generic;
b9d2f58b »
2012-02-01 all tests pass after most recent changes
3 using System.Diagnostics;
1adec35a »
2010-04-17 connections now are object oriented, and basic keyspace and column fa…
4 using System.Linq;
5 using Apache.Cassandra;
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
6 using FluentCassandra.Operations;
b9d2f58b »
2012-02-01 all tests pass after most recent changes
7 using FluentCassandra.Types;
1adec35a »
2010-04-17 connections now are object oriented, and basic keyspace and column fa…
8
9 namespace FluentCassandra
10 {
11 public class CassandraKeyspace
12 {
13 private readonly string _keyspaceName;
bfe118e1 »
2012-05-25 got rid of the CassandraSession.Current since it was an anti-pattern …
14 private readonly CassandraContext _context;
15
4526a65b »
2012-02-06 some much needed refactoring of the schema
16 private CassandraKeyspaceSchema _cachedSchema;
1adec35a »
2010-04-17 connections now are object oriented, and basic keyspace and column fa…
17
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
18 public CassandraKeyspace(string keyspaceName, CassandraContext context)
fc725a6f »
2012-02-11 fixed issues discovered while running sandbox
19 {
20 if (keyspaceName == null)
21 throw new ArgumentNullException("keyspaceName");
22
23 _keyspaceName = keyspaceName;
24 _context = context;
25 }
4526a65b »
2012-02-06 some much needed refactoring of the schema
26
27 public CassandraKeyspace(CassandraKeyspaceSchema schema, CassandraContext context)
1adec35a »
2010-04-17 connections now are object oriented, and basic keyspace and column fa…
28 {
4526a65b »
2012-02-06 some much needed refactoring of the schema
29 if (schema == null)
30 throw new ArgumentNullException("schema");
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
31
4526a65b »
2012-02-06 some much needed refactoring of the schema
32 if (schema.Name == null)
33 throw new ArgumentException("Must specify the keyspace name.");
34
35 _keyspaceName = schema.Name;
36 _cachedSchema = schema;
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
37 _context = context;
1adec35a »
2010-04-17 connections now are object oriented, and basic keyspace and column fa…
38 }
39
40 /// <summary>
41 ///
42 /// </summary>
43 public string KeyspaceName
44 {
45 get { return _keyspaceName; }
46 }
1651f02d »
2010-08-13 added descriptive opperations so that you can query the server for in…
47
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
48 /// <summary>
49 ///
50 /// </summary>
51 /// <returns></returns>
8c2e9f55 »
2012-01-13 composite types are now working
52 public override string ToString()
53 {
54 return KeyspaceName;
55 }
56
b9d2f58b »
2012-02-01 all tests pass after most recent changes
57 public void TryCreateSelf()
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
58 {
d5764600 »
2012-02-07 made the type system more robus to support parsing of complex types f…
59 var schema = GetSchema();
60
61 try
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
62 {
ea9226f5 »
2012-05-24 added support for CQL 3 and selecting the CQL version
63 string result = _context.AddKeyspace(schema);
d5764600 »
2012-02-07 made the type system more robus to support parsing of complex types f…
64 Debug.WriteLine(result, "keyspace setup");
65 }
3b61e2b5 »
2012-05-24 moved from the obsolete property replication_factor on the KsDef obje…
66 catch(Exception exc)
d5764600 »
2012-02-07 made the type system more robus to support parsing of complex types f…
67 {
bfe118e1 »
2012-05-25 got rid of the CassandraSession.Current since it was an anti-pattern …
68 if (_context.ThrowErrors)
69 throw exc;
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
70 }
71 }
72
4526a65b »
2012-02-06 some much needed refactoring of the schema
73 public void TryCreateColumnFamily(CassandraColumnFamilySchema schema)
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
74 {
b9d2f58b »
2012-02-01 all tests pass after most recent changes
75 try
76 {
ea9226f5 »
2012-05-24 added support for CQL 3 and selecting the CQL version
77 schema.KeyspaceName = KeyspaceName;
4526a65b »
2012-02-06 some much needed refactoring of the schema
78
ea9226f5 »
2012-05-24 added support for CQL 3 and selecting the CQL version
79 string result = _context.AddColumnFamily(schema);
4526a65b »
2012-02-06 some much needed refactoring of the schema
80 Debug.WriteLine(result, "column family setup");
b9d2f58b »
2012-02-01 all tests pass after most recent changes
81 }
3b61e2b5 »
2012-05-24 moved from the obsolete property replication_factor on the KsDef obje…
82 catch (Exception exc)
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
83 {
bfe118e1 »
2012-05-25 got rid of the CassandraSession.Current since it was an anti-pattern …
84 if (_context.ThrowErrors)
85 throw exc;
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
86 }
87 }
88
4526a65b »
2012-02-06 some much needed refactoring of the schema
89 [Obsolete("Use \"TryCreateColumnFamily\" class with out generic type")]
90 public void TryCreateColumnFamily<CompareWith>(string columnFamilyName)
d5764600 »
2012-02-07 made the type system more robus to support parsing of complex types f…
91 where CompareWith : CassandraObject
4526a65b »
2012-02-06 some much needed refactoring of the schema
92 {
93 TryCreateColumnFamily(new CassandraColumnFamilySchema {
94 ColumnNameType = typeof(CompareWith),
95 FamilyName = columnFamilyName
96 });
97 }
98
99 [Obsolete("Use \"TryCreateColumnFamily\" class with out generic type")]
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
100 public void TryCreateColumnFamily<CompareWith, CompareSubcolumnWith>(string columnFamilyName)
d5764600 »
2012-02-07 made the type system more robus to support parsing of complex types f…
101 where CompareWith : CassandraObject
102 where CompareSubcolumnWith : CassandraObject
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
103 {
4526a65b »
2012-02-06 some much needed refactoring of the schema
104 TryCreateColumnFamily(new CassandraColumnFamilySchema(type: ColumnType.Super) {
105 ColumnNameType = typeof(CompareWith),
106 SuperColumnNameType = typeof(CompareSubcolumnWith),
107 FamilyName = columnFamilyName
108 });
21aa083b »
2011-11-16 updated sandbox program to be broken up into logical parts
109 }
110
4526a65b »
2012-02-06 some much needed refactoring of the schema
111 public KsDef GetDescription()
7ba4ce5c »
2010-10-12 added support for a couple more features that were added to the clien…
112 {
4526a65b »
2012-02-06 some much needed refactoring of the schema
113 return _context.ExecuteOperation(new SimpleOperation<Apache.Cassandra.KsDef>(ctx => {
114 return ctx.Session.GetClient().describe_keyspace(KeyspaceName);
115 }));
116 }
117
118 public CassandraColumnFamilySchema GetColumnFamilySchema(string columnFamily)
119 {
120 return GetSchema().ColumnFamilies.FirstOrDefault(cf => cf.FamilyName == columnFamily);
7ba4ce5c »
2010-10-12 added support for a couple more features that were added to the clien…
121 }
122
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
123 public bool ColumnFamilyExists(string columnFamilyName)
ce017c8f »
2010-09-05 all tests working for 0.7
124 {
ff16fb51 »
2012-06-06 supporting key aliases in CQL
125 return GetSchema().ColumnFamilies.Any(cf => String.Equals(cf.FamilyName, columnFamilyName, StringComparison.OrdinalIgnoreCase));
7ba4ce5c »
2010-10-12 added support for a couple more features that were added to the clien…
126 }
127
fc725a6f »
2012-02-11 fixed issues discovered while running sandbox
128 public void ClearCachedKeyspaceSchema()
7ba4ce5c »
2010-10-12 added support for a couple more features that were added to the clien…
129 {
4526a65b »
2012-02-06 some much needed refactoring of the schema
130 _cachedSchema = null;
ce017c8f »
2010-09-05 all tests working for 0.7
131 }
132
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
133 #region Cassandra Keyspace Server Operations
ce017c8f »
2010-09-05 all tests working for 0.7
134
4526a65b »
2012-02-06 some much needed refactoring of the schema
135 public CassandraKeyspaceSchema GetSchema()
1651f02d »
2010-08-13 added descriptive opperations so that you can query the server for in…
136 {
4526a65b »
2012-02-06 some much needed refactoring of the schema
137 if (_cachedSchema == null)
fc725a6f »
2012-02-11 fixed issues discovered while running sandbox
138 try
139 {
140 _cachedSchema = new CassandraKeyspaceSchema(_context.ExecuteOperation(new SimpleOperation<Apache.Cassandra.KsDef>(ctx => {
141 return ctx.Session.GetClient().describe_keyspace(KeyspaceName);
142 })));
143 }
ff16fb51 »
2012-06-06 supporting key aliases in CQL
144 catch (CassandraOperationException exc)
fc725a6f »
2012-02-11 fixed issues discovered while running sandbox
145 {
ff16fb51 »
2012-06-06 supporting key aliases in CQL
146 Debug.WriteLine(exc);
fc725a6f »
2012-02-11 fixed issues discovered while running sandbox
147 _cachedSchema = new CassandraKeyspaceSchema {
148 Name = KeyspaceName
149 };
150 }
1651f02d »
2010-08-13 added descriptive opperations so that you can query the server for in…
151
4526a65b »
2012-02-06 some much needed refactoring of the schema
152 return _cachedSchema;
1651f02d »
2010-08-13 added descriptive opperations so that you can query the server for in…
153 }
154
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
155 public IEnumerable<CassandraTokenRange> DescribeRing()
1651f02d »
2010-08-13 added descriptive opperations so that you can query the server for in…
156 {
3254baf2 »
2012-01-31 cleaned up session, context, and keyspace objects
157 return _context.ExecuteOperation(new SimpleOperation<IEnumerable<CassandraTokenRange>>(ctx => {
158 var tokenRanges = ctx.Session.GetClient(setKeyspace: false).describe_ring(KeyspaceName);
159 return tokenRanges.Select(tr => new CassandraTokenRange(tr.Start_token, tr.End_token, tr.Endpoints));
160 }));
1651f02d »
2010-08-13 added descriptive opperations so that you can query the server for in…
161 }
162
163 #endregion
1adec35a »
2010-04-17 connections now are object oriented, and basic keyspace and column fa…
164 }
165 }
Something went wrong with that request. Please try again.