Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleaned up the object conventions and also implimented the use of sch…

…ema caching for super column families also
  • Loading branch information...
commit fdc415ce4c93df3cf349fb6226286293f28290b0 1 parent 862aa3c
@nberardi nberardi authored
View
19 src/CassandraColumnFamily.cs
@@ -22,19 +22,14 @@ public CassandraColumnFamily(CassandraContext context, string columnFamily)
public partial class CassandraColumnFamily : BaseCassandraColumnFamily
{
private CassandraColumnFamilySchema _cachedSchema;
- private ObjectSerializerConventions _conventions;
public CassandraColumnFamily(CassandraContext context, string columnFamily)
- : base(context, columnFamily)
- {
- _conventions = new ObjectSerializerConventions();
- }
+ : base(context, columnFamily) { }
public CassandraColumnFamily(CassandraContext context, CassandraColumnFamilySchema schema)
: base(context, schema.FamilyName)
{
_cachedSchema = schema;
- _conventions = new ObjectSerializerConventions();
}
public FluentColumnFamily CreateRecord(CassandraObject key)
@@ -45,18 +40,6 @@ public FluentColumnFamily CreateRecord(CassandraObject key)
return new FluentColumnFamily(key, FamilyName, GetSchema());
}
- public ObjectSerializerConventions ObjectConventions
- {
- get { return _conventions; }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
-
- _conventions = value;
- }
- }
-
public override CassandraColumnFamilySchema GetSchema()
{
var schema = Context.Keyspace.GetColumnFamilySchema(FamilyName);
View
20 src/CassandraContext.cs
@@ -75,13 +75,13 @@ public CassandraContext(IConnectionBuilder connectionBuilder)
/// <returns></returns>
public CassandraColumnFamily GetColumnFamily(string columnFamily)
{
- if(Keyspace != null)
- {
- CassandraColumnFamilySchema schema = Keyspace.GetColumnFamilySchemaFromCacheOnly(columnFamily);
+ if(Keyspace != null)
+ {
+ var schema = Keyspace.GetColumnFamilySchema(columnFamily);
- if(schema != null)
- return new CassandraColumnFamily(this, schema);
- }
+ if(schema != null)
+ return new CassandraColumnFamily(this, schema);
+ }
return new CassandraColumnFamily(this, columnFamily);
}
@@ -93,6 +93,14 @@ public CassandraColumnFamily GetColumnFamily(string columnFamily)
/// <returns></returns>
public CassandraSuperColumnFamily GetSuperColumnFamily(string columnFamily)
{
+ if (Keyspace != null)
+ {
+ var schema = Keyspace.GetColumnFamilySchema(columnFamily);
+
+ if (schema != null)
+ return new CassandraSuperColumnFamily(this, schema);
+ }
+
return new CassandraSuperColumnFamily(this, columnFamily);
}
View
13 src/CassandraKeyspace.cs
@@ -115,19 +115,14 @@ public KsDef GetDescription()
}));
}
- public CassandraColumnFamilySchema GetColumnFamilySchema(string columnFamily)
+ public CassandraColumnFamilySchema GetColumnFamilySchema(string columnFamily, bool onlyCheckCache = false)
{
+ if (onlyCheckCache && _cachedSchema == null)
+ return null;
+
return GetSchema().ColumnFamilies.FirstOrDefault(cf => cf.FamilyName == columnFamily);
}
- internal CassandraColumnFamilySchema GetColumnFamilySchemaFromCacheOnly(string columnFamily)
- {
- if (_cachedSchema == null)
- return null;
-
- return GetColumnFamilySchema(columnFamily);
- }
-
public bool ColumnFamilyExists(string columnFamilyName)
{
return GetSchema().ColumnFamilies.Any(cf => String.Equals(cf.FamilyName, columnFamilyName, StringComparison.OrdinalIgnoreCase));
View
9 src/CassandraSuperColumnFamily.cs
@@ -27,6 +27,12 @@ public class CassandraSuperColumnFamily : BaseCassandraColumnFamily
public CassandraSuperColumnFamily(CassandraContext context, string columnFamily)
: base(context, columnFamily) { }
+ public CassandraSuperColumnFamily(CassandraContext context, CassandraColumnFamilySchema schema)
+ : base(context, schema.FamilyName)
+ {
+ _cachedSchema = schema;
+ }
+
public FluentSuperColumnFamily CreateRecord(CassandraObject key)
{
if (key.GetValue<byte[]>().Length == 0)
@@ -49,9 +55,6 @@ public override CassandraColumnFamilySchema GetSchema()
public override void SetSchema(CassandraColumnFamilySchema schema)
{
- if (schema == null)
- schema = new CassandraColumnFamilySchema { FamilyName = FamilyName };
-
_cachedSchema = schema;
}
View
1  src/FluentCassandra.csproj
@@ -127,7 +127,6 @@
<Compile Include="CassandraCqlRowSchema.cs" />
<Compile Include="FluentCqlRow.cs" />
<Compile Include="ILoadable.cs" />
- <Compile Include="ObjectSerializer\ObjectSerializerConventions.cs" />
<Compile Include="System\DateTimePrecise.cs" />
<Compile Include="FluentCassandraException.cs" />
<Compile Include="FluentColumn.cs">
View
2  src/Linq/CqlObjectQuery.cs
@@ -61,7 +61,7 @@ public IEnumerator<T> GetEnumerator()
var serializer = ObjectSerializerFactory.Get(typeof(T));
return serializer
- .Deserialize(fluentObjects, _family.ObjectConventions)
+ .Deserialize(fluentObjects)
.OfType<T>()
.GetEnumerator();
}
View
6 src/ObjectSerializer/IObjectSerializer.cs
@@ -7,9 +7,9 @@ namespace FluentCassandra.ObjectSerializer
{
public interface IObjectSerializer
{
- Func<ICqlRow, ObjectSerializerConventions, object> GenerateRowDeserializer();
+ Func<ICqlRow, object> GenerateRowDeserializer();
- object Deserialize(ICqlRow row, ObjectSerializerConventions conventions = null);
- IEnumerable<object> Deserialize(IEnumerable<ICqlRow> rows, ObjectSerializerConventions conventions = null);
+ object Deserialize(ICqlRow row);
+ IEnumerable<object> Deserialize(IEnumerable<ICqlRow> rows);
}
}
View
10 src/ObjectSerializer/ObjectSerializerConventions.cs
@@ -1,10 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace FluentCassandra.ObjectSerializer
-{
- public class ObjectSerializerConventions
- {
- }
-}
View
24 src/ObjectSerializer/ReflectionObjectSerializer.cs
@@ -15,7 +15,7 @@ public ReflectionObjectSerializer(Type type)
_type = type;
}
- private object FrameworkTypeRowDeserializer(ICqlRow row, ObjectSerializerConventions conventions)
+ private object FrameworkTypeRowDeserializer(ICqlRow row)
{
if (row.Columns.Count > 0)
return Convert.ChangeType(row.Columns[0].ColumnValue, _type);
@@ -23,7 +23,7 @@ private object FrameworkTypeRowDeserializer(ICqlRow row, ObjectSerializerConvent
return Convert.ChangeType(row.Key, _type);
}
- private object AnonymousRowDeserializer(ICqlRow row, ObjectSerializerConventions conventions)
+ private object AnonymousRowDeserializer(ICqlRow row)
{
var props = _type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
var args = new List<object>();
@@ -39,13 +39,13 @@ private object AnonymousRowDeserializer(ICqlRow row, ObjectSerializerConventions
return Activator.CreateInstance(_type, args.ToArray());
}
- private object RowDeserializer(ICqlRow row, ObjectSerializerConventions conventions)
+ private object RowDeserializer(ICqlRow row)
{
if (Type.GetTypeCode(_type) != TypeCode.Object)
- return FrameworkTypeRowDeserializer(row, conventions);
+ return FrameworkTypeRowDeserializer(row);
if (_type.Name.Contains("AnonymousType"))
- return AnonymousRowDeserializer(row, conventions);
+ return AnonymousRowDeserializer(row);
var obj = Activator.CreateInstance(_type);
@@ -60,27 +60,23 @@ private object RowDeserializer(ICqlRow row, ObjectSerializerConventions conventi
return obj;
}
- public Func<ICqlRow, ObjectSerializerConventions, object> GenerateRowDeserializer()
+ public Func<ICqlRow, object> GenerateRowDeserializer()
{
return RowDeserializer;
}
- public object Deserialize(ICqlRow row, ObjectSerializerConventions conventions = null)
+ public object Deserialize(ICqlRow row)
{
- conventions = conventions ?? new ObjectSerializerConventions();
-
var func = GenerateRowDeserializer();
- return func(row, conventions);
+ return func(row);
}
- public IEnumerable<object> Deserialize(IEnumerable<ICqlRow> rows, ObjectSerializerConventions conventions = null)
+ public IEnumerable<object> Deserialize(IEnumerable<ICqlRow> rows)
{
- conventions = conventions ?? new ObjectSerializerConventions();
-
var func = GenerateRowDeserializer();
foreach (var row in rows)
- yield return func(row, conventions);
+ yield return func(row);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.