Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 114 lines (88 sloc) 3.469 kB
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
4 using Apache.Cassandra;
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
5 using FluentCassandra.Types;
6
7 namespace FluentCassandra
8 {
9 public class CassandraColumnFamilySchema
10 {
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
11 public static readonly AsciiType DefaultKeyName = "KEY";
ff16fb5 @nberardi supporting key aliases in CQL
nberardi authored
12 public static readonly CassandraType DefaultKeyNameType = CassandraType.AsciiType;
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
13
a9597c9 @nberardi refactored a couple of schema related changes
nberardi authored
14 private readonly CfDef _def;
ab8b19f @nberardi Cassandra uses Java's BigDecimal object to store and create these val…
nberardi authored
15
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
16 public CassandraColumnFamilySchema(CfDef def)
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
17 {
ab8b19f @nberardi Cassandra uses Java's BigDecimal object to store and create these val…
nberardi authored
18 _def = def;
19
ea9226f @nberardi added support for CQL 3 and selecting the CQL version
nberardi authored
20 KeyspaceName = def.Keyspace;
21
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
22 var familyType = ColumnType.Standard;
23 Enum.TryParse<ColumnType>(def.Column_type, out familyType);
24
ff16fb5 @nberardi supporting key aliases in CQL
nberardi authored
25 var defaultKeyValueType = CassandraType.GetCassandraType(def.Key_validation_class);
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
26 var defaultColumnValueType = CassandraType.GetCassandraType(def.Default_validation_class);
ff16fb5 @nberardi supporting key aliases in CQL
nberardi authored
27
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
28 CassandraType columnNameType, superColumnNameType;
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
29
30 if (familyType == ColumnType.Super)
31 {
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
32 superColumnNameType = CassandraType.GetCassandraType(def.Comparator_type);
33 columnNameType = CassandraType.GetCassandraType(def.Subcomparator_type);
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
34 }
35 else
36 {
37 superColumnNameType = null;
f3bc872 @nberardi moved around some methods because they were on the wrong object
nberardi authored
38 columnNameType = CassandraType.GetCassandraType(def.Comparator_type);
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
39 }
40
41 FamilyType = familyType;
42 FamilyName = def.Name;
43 FamilyDescription = def.Comment;
44
ff16fb5 @nberardi supporting key aliases in CQL
nberardi authored
45 KeyName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(def.Key_alias, DefaultKeyNameType);
a9597c9 @nberardi refactored a couple of schema related changes
nberardi authored
46 KeyValueType = defaultKeyValueType;
ff16fb5 @nberardi supporting key aliases in CQL
nberardi authored
47
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
48 SuperColumnNameType = superColumnNameType;
49 ColumnNameType = columnNameType;
50 DefaultColumnValueType = defaultColumnValueType;
51
52 Columns = def.Column_metadata.Select(col => new CassandraColumnSchema(col, columnNameType)).ToList();
53 }
54
55 public CassandraColumnFamilySchema(string name = null, ColumnType type = ColumnType.Standard)
56 {
57 FamilyType = type;
58 FamilyName = name;
59 FamilyDescription = null;
10617e5 @nberardi all tests now pass
nberardi authored
60
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
61 KeyName = DefaultKeyName;
a9597c9 @nberardi refactored a couple of schema related changes
nberardi authored
62 KeyValueType = CassandraType.BytesType;
ff16fb5 @nberardi supporting key aliases in CQL
nberardi authored
63
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
64 SuperColumnNameType = type == ColumnType.Super ? CassandraType.BytesType : null;
65 ColumnNameType = CassandraType.BytesType;
66 DefaultColumnValueType = CassandraType.BytesType;
10617e5 @nberardi all tests now pass
nberardi authored
67
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
68 Columns = new List<CassandraColumnSchema>();
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
69 }
70
ea9226f @nberardi added support for CQL 3 and selecting the CQL version
nberardi authored
71 internal string KeyspaceName { get; set; }
72
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
73 public ColumnType FamilyType { get; set; }
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
74 public string FamilyName { get; set; }
4526a65 @nberardi some much needed refactoring of the schema
nberardi authored
75 public string FamilyDescription { get; set; }
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
76
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
77 public CassandraObject KeyName { get; set; }
a9597c9 @nberardi refactored a couple of schema related changes
nberardi authored
78 public CassandraType KeyValueType { get; set; }
ff16fb5 @nberardi supporting key aliases in CQL
nberardi authored
79
d576460 @nberardi made the type system more robus to support parsing of complex types f…
nberardi authored
80 public CassandraType SuperColumnNameType { get; set; }
81 public CassandraType ColumnNameType { get; set; }
82 public CassandraType DefaultColumnValueType { get; set; }
e1b11ad @nberardi [breaking change] with recent changes in the Cassandra API and the ne…
nberardi authored
83
84 public IList<CassandraColumnSchema> Columns { get; set; }
ea9226f @nberardi added support for CQL 3 and selecting the CQL version
nberardi authored
85
86 public static implicit operator CfDef(CassandraColumnFamilySchema schema)
87 {
88 var def = new CfDef {
89 Keyspace = schema.KeyspaceName,
90 Name = schema.FamilyName,
91 Comment = schema.FamilyDescription,
92 Column_type = schema.FamilyType.ToString(),
93 Key_alias = schema.KeyName.ToBigEndian(),
a9597c9 @nberardi refactored a couple of schema related changes
nberardi authored
94 Key_validation_class = schema.KeyValueType.DatabaseType,
ea9226f @nberardi added support for CQL 3 and selecting the CQL version
nberardi authored
95 Comparator_type = schema.ColumnNameType.DatabaseType,
96 Default_validation_class = schema.DefaultColumnValueType.DatabaseType
97 };
98
99 if (schema.FamilyType == ColumnType.Super)
100 {
101 def.Comparator_type = schema.SuperColumnNameType.DatabaseType;
102 def.Subcomparator_type = schema.ColumnNameType.DatabaseType;
103 }
104
105 return def;
106 }
107
108 public static implicit operator CassandraColumnFamilySchema(CfDef def)
109 {
110 return new CassandraColumnFamilySchema(def);
111 }
b9d2f58 @nberardi all tests pass after most recent changes
nberardi authored
112 }
113 }
Something went wrong with that request. Please try again.