Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added support for counter column

  • Loading branch information...
commit ac522e76162d1ca9856cc16e2c14e062d224820c 1 parent 700a50a
@nberardi nberardi authored
View
6 src/CassandraColumnFamilyOperations.cs
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
-using FluentCassandra.Types;
-using FluentCassandra.Operations;
using System.Linq.Expressions;
using FluentCassandra.Linq;
+using FluentCassandra.Operations;
+using FluentCassandra.Types;
namespace FluentCassandra
{
@@ -58,7 +58,7 @@ public static void InsertColumn(this CassandraColumnFamily family, CassandraObje
#region AddColumn
- public static void InsertColumn(this CassandraColumnFamily family, CassandraObject key, CassandraObject columnName, long columnValue)
+ public static void InsertCounterColumn(this CassandraColumnFamily family, CassandraObject key, CassandraObject columnName, long columnValue)
{
var op = new AddColumn(key, columnName, columnValue);
family.ExecuteOperation(op);
View
3  src/CassandraContext.cs
@@ -312,6 +312,9 @@ public CassandraSession OpenSession()
/// <returns></returns>
public TResult ExecuteOperation<TResult>(Operation<TResult> action, bool? throwOnError = null)
{
+ if (WasDisposed)
+ throw new ObjectDisposedException(GetType().FullName);
+
if (!throwOnError.HasValue)
throwOnError = ThrowErrors;
View
6 src/CassandraSession.cs
@@ -137,12 +137,14 @@ public void Login(string username, string password)
/// <returns></returns>
public TResult ExecuteOperation<TResult>(Operation<TResult> action, bool? throwOnError = null)
{
+ if (WasDisposed)
+ throw new ObjectDisposedException(GetType().FullName);
+
if (!throwOnError.HasValue)
throwOnError = ThrowErrors;
- action.Session = this;
-
LastError = null;
+ action.Session = this;
TResult result;
bool success = action.TryExecute(out result);
View
5 src/CassandraSuperColumnFamilyOperations.cs
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
-using FluentCassandra.Types;
using FluentCassandra.Operations;
-using System.Linq.Expressions;
+using FluentCassandra.Types;
namespace FluentCassandra
{
@@ -70,7 +69,7 @@ public static void InsertColumn(this CassandraSuperColumnFamily family, Cassandr
#region AddColumn
- public static void InsertColumn(this CassandraSuperColumnFamily family, CassandraObject key, CassandraObject superColumnName, CassandraObject columnName, long columnValue)
+ public static void InsertCounterColumn(this CassandraSuperColumnFamily family, CassandraObject key, CassandraObject superColumnName, CassandraObject columnName, long columnValue)
{
var op = new AddColumn(key, superColumnName, columnName, columnValue);
family.ExecuteOperation(op);
View
4 src/FluentCassandra.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -131,6 +131,7 @@
<Compile Include="FluentColumnPath.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="FluentCounterColumn.cs" />
<Compile Include="FluentMutation.cs">
<SubType>Code</SubType>
</Compile>
@@ -255,6 +256,7 @@
<Compile Include="Types\CompositeType`1.cs" />
<Compile Include="Types\BooleanType.cs" />
<Compile Include="Types\BooleanTypeConverter.cs" />
+ <Compile Include="Types\CounterColumnType.cs" />
<Compile Include="Types\DateType.cs" />
<Compile Include="Types\DateTypeConverter.cs" />
<Compile Include="Types\Int32Type.cs" />
View
2  src/FluentColumnFamily.cs
@@ -150,7 +150,7 @@ public override IList<FluentColumn> Columns
/// <returns></returns>
public FluentColumnPath GetPath()
{
- return new FluentColumnPath(this, null, null);
+ return new FluentColumnPath(this, null, (FluentColumn)null);
}
/// <summary>
View
11 src/FluentColumnPath.cs
@@ -7,12 +7,23 @@ public class FluentColumnPath : FluentColumnParent
public FluentColumnPath(FluentColumnParent parent, FluentColumn column)
: this (parent.ColumnFamily, parent.SuperColumn, column) { }
+ public FluentColumnPath(FluentColumnParent parent, FluentCounterColumn column)
+ : this(parent.ColumnFamily, parent.SuperColumn, column) { }
+
public FluentColumnPath(IFluentBaseColumnFamily columnFamily, FluentSuperColumn superColumn, FluentColumn column)
: base(columnFamily, superColumn)
{
Column = column;
}
+ public FluentColumnPath(IFluentBaseColumnFamily columnFamily, FluentSuperColumn superColumn, FluentCounterColumn column)
+ : base(columnFamily, superColumn)
+ {
+ CounterColumn = column;
+ }
+
public FluentColumn Column { get; set; }
+
+ public FluentCounterColumn CounterColumn { get; set; }
}
}
View
18 src/FluentCounterColumn.cs
@@ -0,0 +1,18 @@
+using System;
+using FluentCassandra.Types;
+
+namespace FluentCassandra
+{
+ public class FluentCounterColumn : FluentColumn
+ {
+ public FluentCounterColumn(CassandraColumnSchema schema = null)
+ : base(schema)
+ {
+ schema = GetSchema();
+ schema.ValueType = CassandraType.ColumnCounterType;
+
+ // ensure value type is set to column counter type
+ SetSchema(schema);
+ }
+ }
+}
View
2  src/FluentSuperColumn.cs
@@ -153,7 +153,7 @@ public void SetSchema(CassandraColumnSchema schema)
/// <returns></returns>
public FluentColumnPath GetPath()
{
- return new FluentColumnPath(Family, this, null);
+ return new FluentColumnPath(Family, this, (FluentColumn)null);
}
/// <summary>
View
2  src/FluentSuperColumnFamily.cs
@@ -139,7 +139,7 @@ public void SetSchema(CassandraColumnFamilySchema schema)
/// <returns></returns>
public FluentColumnPath GetPath()
{
- return new FluentColumnPath(this, null, null);
+ return new FluentColumnPath(this, null, (FluentColumn)null);
}
/// <summary>
View
51 src/Operations/Helper.cs
@@ -146,13 +146,60 @@ public static IFluentBaseColumn ConvertToFluentBaseColumn(ColumnOrSuperColumn co
else if (col.Column != null)
return ConvertColumnToFluentColumn(col.Column, schema);
else if (col.Counter_super_column != null)
- throw new NotSupportedException("Reading CounterSuperColumns isn't supported yet.");
+ return ConvertColumnToFluentCounterColumn(col.Counter_column, schema);
else if (col.Counter_column != null)
- throw new NotSupportedException("Reading CounterSuperColumns isn't supported yet.");
+ return ConvertSuperColumnToFluentCounterSuperColumn(col.Counter_super_column, schema);
else
return null;
}
+ public static FluentSuperColumn ConvertSuperColumnToFluentCounterSuperColumn(CounterSuperColumn col, CassandraColumnFamilySchema schema = null)
+ {
+ var superColSchema = new CassandraColumnSchema {
+ Name = col.Name
+ };
+
+ if (schema != null)
+ superColSchema = new CassandraColumnSchema {
+ NameType = schema.SuperColumnNameType,
+ Name = col.Name,
+ ValueType = schema.ColumnNameType
+ };
+
+ var superCol = new FluentSuperColumn(superColSchema) {
+ ColumnName = CassandraObject.GetTypeFromDatabaseValue(col.Name, superColSchema.NameType)
+ };
+
+ foreach (var xcol in col.Columns)
+ superCol.Columns.Add(ConvertColumnToFluentCounterColumn(xcol, schema));
+
+ return superCol;
+ }
+
+ public static FluentCounterColumn ConvertColumnToFluentCounterColumn(CounterColumn col, CassandraColumnFamilySchema schema = null)
+ {
+ var colSchema = new CassandraColumnSchema();
+
+ if (schema != null)
+ {
+ colSchema = schema.Columns.Where(x => x.Name == col.Name).FirstOrDefault();
+
+ if (colSchema == null)
+ {
+ colSchema = new CassandraColumnSchema();
+ colSchema.NameType = schema.ColumnNameType;
+ colSchema.ValueType = schema.DefaultColumnValueType;
+ }
+ }
+
+ var fcol = new FluentCounterColumn(colSchema) {
+ ColumnName = CassandraObject.GetTypeFromDatabaseValue(col.Name, colSchema.NameType),
+ ColumnValue = col.Value
+ };
+
+ return fcol;
+ }
+
public static FluentColumn ConvertColumnToFluentColumn(Column col, CassandraColumnFamilySchema schema = null)
{
var colSchema = new CassandraColumnSchema();
View
3  src/Types/CassandraType.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Numerics;
namespace FluentCassandra.Types
@@ -22,6 +20,7 @@ public sealed class CassandraType
public static readonly CassandraType TimeUUIDType = new CassandraType("org.apache.cassandra.db.marshal.TimeUUIDType");
public static readonly CassandraType UTF8Type = new CassandraType("org.apache.cassandra.db.marshal.UTF8Type");
public static readonly CassandraType UUIDType = new CassandraType("org.apache.cassandra.db.marshal.UUIDType");
+ public static readonly CassandraType ColumnCounterType = new CassandraType("org.apache.cassandra.db.marshal.ColumnCounterType");
private readonly string _dbType;
private Type _type;
View
8 src/Types/CounterColumnType.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class CounterColumnType : LongType
+ {
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.