Permalink
Browse files

added prelim support for SuperColumn

  • Loading branch information...
1 parent a7e66af commit 0999b2197523405d7046c1c964f12ce70bb12647 @nberardi nberardi committed Apr 18, 2010
@@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using Apache.Cassandra;
+using FluentCassandra.Configuration;
+using System.Collections;
namespace FluentCassandra
{
@@ -35,34 +37,70 @@ protected Cassandra.Client GetClient()
///
/// </summary>
/// <param name="record"></param>
- public void Insert(FluentColumnFamily record)
+ /// <param name="superColumnName"></param>
+ /// <returns></returns>
+ public int ColumnCount(FluentColumnFamily record, string superColumnName = null)
{
- Insert(record.ColumnFamily, record.Key, record);
+ return ColumnCount(record.Key, record.ColumnFamily, superColumnName);
}
/// <summary>
///
/// </summary>
- /// <param name="columnFamily"></param>
/// <param name="key"></param>
+ /// <param name="columnFamily"></param>
+ /// <param name="superColumnName"></param>
+ /// <returns></returns>
+ public int ColumnCount(string key, string columnFamily, string superColumnName)
+ {
+ var parent = new ColumnParent {
+ Column_family = columnFamily
+ };
+
+ if (!String.IsNullOrWhiteSpace(superColumnName))
+ parent.Super_column = superColumnName.GetBytes();
+
+ return GetClient().get_count(
+ _keyspace.KeyspaceName,
+ key,
+ parent,
+ ConsistencyLevel.ONE
+ );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
/// <param name="record"></param>
- public void Insert(string columnFamily, string key, FluentColumnFamily record)
+ public void Insert(FluentColumnFamily record)
{
- var utf8 = Encoding.UTF8;
+ Insert(record.Key, record.ColumnFamily, record);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="key"></param>
+ /// <param name="columnFamily"></param>
+ /// <param name="record"></param>
+ public void Insert(string key, string columnFamily, IEnumerable<FluentColumnPath<string>> record)
+ {
foreach (var col in record)
{
var path = new ColumnPath {
- Column_family = columnFamily,
- Column = col.NameBytes
+ Column_family = col.ColumnFamily.ColumnFamily,
+ Column = col.Column.NameBytes
};
+ if (col.SuperColumn != null)
+ path.Super_column = col.SuperColumn.NameBytes;
+
GetClient().insert(
_keyspace.KeyspaceName,
key,
path,
- col.ValueBytes,
- col.Timestamp.Ticks,
+ col.Column.ValueBytes,
+ col.Column.Timestamp.Ticks,
ConsistencyLevel.ONE
);
}
@@ -73,9 +111,10 @@ public void Insert(string columnFamily, string key, FluentColumnFamily record)
/// </summary>
/// <param name="record"></param>
/// <param name="columnName"></param>
- public void Remove(FluentColumnFamily record, string columnName = null)
+ /// <param name="superColumnName"></param>
+ public void Remove(FluentColumnFamily record, string superColumnName = null, string columnName = null)
{
- Remove(record.ColumnFamily, record.Key, columnName);
+ Remove(record.Key, record.ColumnFamily, superColumnName, columnName);
}
/// <summary>
@@ -84,15 +123,17 @@ public void Remove(FluentColumnFamily record, string columnName = null)
/// <param name="columnFamily"></param>
/// <param name="key"></param>
/// <param name="columnName"></param>
- public void Remove(string columnFamily, string key, string columnName = null)
+ public void Remove(string key, string columnFamily, string superColumnName, string columnName)
{
- var utf8 = Encoding.UTF8;
var path = new ColumnPath {
Column_family = columnFamily
};
+ if (!String.IsNullOrWhiteSpace(superColumnName))
+ path.Super_column = superColumnName.GetBytes();
+
if (!String.IsNullOrWhiteSpace(columnName))
- path.Column = FluentColumn<string>.GetBytes(columnName);
+ path.Column = columnName.GetBytes();
GetClient().remove(
_keyspace.KeyspaceName,
@@ -47,6 +47,16 @@ public FluentColumnFamily PrepareColumnFamily(T obj)
return record;
}
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="obj"></param>
+ /// <returns></returns>
+ public int ColumnCount(T obj)
+ {
+ return ColumnCount(PrepareColumnFamily(obj));
+ }
+
/// <summary>
///
/// </summary>
@@ -58,77 +58,5 @@ public CassandraColumnFamily<T> GetColumnFamily<T>()
{
return new CassandraColumnFamily<T>(this, _connection);
}
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="record"></param>
- public void Insert(FluentColumnFamily record)
- {
- Insert(record.ColumnFamily, record.Key, record);
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="columnFamily"></param>
- /// <param name="key"></param>
- /// <param name="record"></param>
- public void Insert(string columnFamily, string key, FluentColumnFamily record)
- {
- var utf8 = Encoding.UTF8;
-
- foreach (var col in record)
- {
- var path = new ColumnPath {
- Column_family = columnFamily,
- Column = col.NameBytes
- };
-
- _connection.Client.insert(
- _keyspaceName,
- key,
- path,
- col.ValueBytes,
- col.Timestamp.Ticks,
- ConsistencyLevel.ONE
- );
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="record"></param>
- /// <param name="columnName"></param>
- public void Remove(FluentColumnFamily record, string columnName = null)
- {
- Remove(record.ColumnFamily, record.Key, columnName);
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="columnFamily"></param>
- /// <param name="key"></param>
- /// <param name="columnName"></param>
- public void Remove(string columnFamily, string key, string columnName = null)
- {
- var utf8 = Encoding.UTF8;
- var path = new ColumnPath {
- Column_family = columnFamily
- };
-
- if (!String.IsNullOrWhiteSpace(columnName))
- path.Column = FluentColumn<string>.GetBytes(columnName);
-
- _connection.Client.remove(
- _keyspaceName,
- key,
- path,
- DateTimeOffset.UtcNow.Ticks,
- ConsistencyLevel.ONE
- );
- }
}
}
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FluentCassandra
+{
+ public enum ColumnType
+ {
+ Normal,
+ Super
+ }
+}
@@ -11,6 +11,11 @@ public class CassandraTypeConfiguration<T> : ITypeSetConfiguration<T>, ITypeGetC
private IKeyMapping _key;
private readonly IDictionary<string, IPropertMapping> _properties = new Dictionary<string, IPropertMapping>();
+ public CassandraTypeConfiguration()
+ {
+ ColumnType = ColumnType.Normal;
+ }
+
/// <summary>
///
/// </summary>
@@ -37,6 +42,12 @@ public string ColumnFamily
private set;
}
+ public ColumnType ColumnType
+ {
+ get;
+ private set;
+ }
+
/// <summary>
///
/// </summary>
@@ -47,6 +58,16 @@ public void UseColumnFamily(string columnFamily)
CassandraConfiguration.FireTypeChangedEvent(typeof(T));
}
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="type"></param>
+ public void UseColumnType(ColumnType type)
+ {
+ ColumnType = type;
+ CassandraConfiguration.FireTypeChangedEvent(typeof(T));
+ }
+
/// <summary>
///
/// </summary>
@@ -27,12 +27,27 @@ public interface ITypeGetConfiguration<T> : ITypeConfiguration
///
/// </summary>
string ColumnFamily { get; }
+
+ /// <summary>
+ ///
+ /// </summary>
+ ColumnType ColumnType { get; }
}
public interface ITypeSetConfiguration<T> : ITypeConfiguration
{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="columnFamily"></param>
void UseColumnFamily(string columnFamily);
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="columnType"></param>
+ void UseColumnType(ColumnType columnType);
+
/// <summary>
///
/// </summary>
@@ -83,6 +83,7 @@
<Compile Include="Configuration\CassandraConfigurationMap.cs" />
<Compile Include="Configuration\CassandraTypeConfiguration.cs" />
<Compile Include="Configuration\CassandraConfigurationContainer.cs" />
+ <Compile Include="ColumnType.cs" />
<Compile Include="Configuration\IPropertyMapping.cs" />
<Compile Include="Configuration\ITypeConfiguration.cs" />
<Compile Include="Configuration\KeyMappingExpression.cs" />
@@ -97,12 +98,16 @@
<Compile Include="Connection\Server.cs" />
<Compile Include="FluentColumn.cs" />
<Compile Include="FluentColumnFamily.cs" />
+ <Compile Include="FluentColumnParent.cs" />
+ <Compile Include="FluentColumnPath.cs" />
+ <Compile Include="FluentSuperColumn.cs" />
<Compile Include="GuidGenerator.cs" />
<Compile Include="Connection\IConnection.cs" />
<Compile Include="Connection\IConnectionProvider.cs" />
<Compile Include="IFluentColumn.cs" />
<Compile Include="IHideObjectMembers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="SerializationHelper.cs" />
<Compile Include="Thrift\Collections\THashSet.cs" />
<Compile Include="Thrift\Protocol\TBase.cs" />
<Compile Include="Thrift\Protocol\TBinaryProtocol.cs" />
Oops, something went wrong.

0 comments on commit 0999b21

Please sign in to comment.