Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
looking at implicit conversions of most common mapping types for asci…
Browse files Browse the repository at this point in the history
…i, utf8, long, bytes, lexicaluuid and timeuuid, make the column family more durrable
  • Loading branch information
Nick Berardi committed Apr 27, 2010
1 parent 12cd243 commit 309fe13
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 172 deletions.
16 changes: 8 additions & 8 deletions FluentCassandra/FluentCassandra.csproj
Expand Up @@ -74,8 +74,8 @@
<Compile Include="Apache\Cassandra\TimedOutException.cs" />
<Compile Include="Apache\Cassandra\TokenRange.cs" />
<Compile Include="Apache\Cassandra\UnavailableException.cs" />
<Compile Include="TypeConverters\AsciiType.cs" />
<Compile Include="TypeConverters\BinaryConverter.cs" />
<Compile Include="Types\AsciiType.cs" />
<Compile Include="Types\BinaryConverter.cs" />
<Compile Include="CassandraColumnFamily.cs" />
<Compile Include="CassandraContext.cs" />
<Compile Include="CassandraKeyRange.cs" />
Expand Down Expand Up @@ -105,11 +105,11 @@
<Compile Include="FluentColumnList`1.cs" />
<Compile Include="FluentColumnParent.cs" />
<Compile Include="FluentColumnPath.cs" />
<Compile Include="TypeConverters\BytesType.cs" />
<Compile Include="Types\BytesType.cs" />
<Compile Include="IFluentColumnFamily.cs" />
<Compile Include="IFluentRecord.cs" />
<Compile Include="TypeConverters\CassandraType.cs" />
<Compile Include="TypeConverters\LexicalUUIDType.cs" />
<Compile Include="Types\CassandraType.cs" />
<Compile Include="Types\LexicalUUIDType.cs" />
<Compile Include="ObjectHelper.cs" />
<Compile Include="FluentRecord.cs" />
<Compile Include="FluentSuperColumn.cs" />
Expand All @@ -128,7 +128,7 @@
<Compile Include="MutationType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BinaryHelper.cs" />
<Compile Include="TypeConverters\LongType.cs" />
<Compile Include="Types\LongType.cs" />
<Compile Include="Thrift\Collections\THashSet.cs" />
<Compile Include="Thrift\Protocol\TBase.cs" />
<Compile Include="Thrift\Protocol\TBinaryProtocol.cs" />
Expand Down Expand Up @@ -159,8 +159,8 @@
<Compile Include="Thrift\Transport\TTransport.cs" />
<Compile Include="Thrift\Transport\TTransportException.cs" />
<Compile Include="Thrift\Transport\TTransportFactory.cs" />
<Compile Include="TypeConverters\TimeUUIDType.cs" />
<Compile Include="TypeConverters\UTF8Type.cs" />
<Compile Include="Types\TimeUUIDType.cs" />
<Compile Include="Types\UTF8Type.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Thrift\Collections\.svn\all-wcprops" />
Expand Down
41 changes: 0 additions & 41 deletions FluentCassandra/TypeConverters/AsciiType.cs

This file was deleted.

41 changes: 0 additions & 41 deletions FluentCassandra/TypeConverters/BytesType.cs

This file was deleted.

41 changes: 0 additions & 41 deletions FluentCassandra/TypeConverters/LongType.cs

This file was deleted.

41 changes: 0 additions & 41 deletions FluentCassandra/TypeConverters/UTF8Type.cs

This file was deleted.

79 changes: 79 additions & 0 deletions FluentCassandra/Types/AsciiType.cs
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace FluentCassandra.Types
{
public class AsciiType : CassandraType
{
public override TypeConverter TypeConverter
{
get { return new StringConverter(); }
}

public string GetObject(byte[] bytes)
{
return GetObject<string>(bytes);
}

public override object GetObject(byte[] bytes, Type type)
{
var converter = this.TypeConverter;

if (!converter.CanConvertTo(type))
throw new NotSupportedException(type + " is not supported for string serialization.");

return converter.ConvertTo(bytes, type);
}

public override byte[] GetBytes(object obj)
{
var converter = this.TypeConverter;

if (!converter.CanConvertFrom(obj.GetType()))
throw new NotSupportedException(obj.GetType() + " is not supported for string serialization.");

return (byte[])converter.ConvertFrom(obj);
}

private string _value;

public static implicit operator byte[](AsciiType type)
{
return type.GetBytes(type._value);
}

public static implicit operator string(AsciiType type)
{
return type._value;
}

public static implicit operator AsciiType(byte o) { return Convert(o); }
public static implicit operator AsciiType(sbyte o) { return Convert(o); }
public static implicit operator AsciiType(short o) { return Convert(o); }
public static implicit operator AsciiType(ushort o) { return Convert(o); }
public static implicit operator AsciiType(int o) { return Convert(o); }
public static implicit operator AsciiType(uint o) { return Convert(o); }
public static implicit operator AsciiType(long o) { return Convert(o); }
public static implicit operator AsciiType(ulong o) { return Convert(o); }
public static implicit operator AsciiType(float o) { return Convert(o); }
public static implicit operator AsciiType(double o) { return Convert(o); }
public static implicit operator AsciiType(decimal o) { return Convert(o); }
public static implicit operator AsciiType(bool o) { return Convert(o); }
public static implicit operator AsciiType(string o) { return Convert(o); }
public static implicit operator AsciiType(char o) { return Convert(o); }
public static implicit operator AsciiType(Guid o) { return Convert(o); }
public static implicit operator AsciiType(DateTime o) { return Convert(o); }
public static implicit operator AsciiType(DateTimeOffset o) { return Convert(o); }

private static AsciiType Convert(object o)
{
var type = new AsciiType();
type._value = o.ToString();

return type;
}
}
}
79 changes: 79 additions & 0 deletions FluentCassandra/Types/BytesType.cs
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace FluentCassandra.Types
{
public class BytesType : CassandraType
{
public override TypeConverter TypeConverter
{
get { return new BinaryConverter(); }
}

public byte[] GetObject(byte[] bytes)
{
return bytes;
}

public override object GetObject(byte[] bytes, Type type)
{
var converter = this.TypeConverter;

if (!converter.CanConvertTo(type))
throw new NotSupportedException(type + " is not supported for binary serialization.");

return converter.ConvertTo(bytes, type);
}

public override byte[] GetBytes(object obj)
{
var converter = this.TypeConverter;

if (!converter.CanConvertFrom(obj.GetType()))
throw new NotSupportedException(obj.GetType() + " is not supported for binary serialization.");

return (byte[])converter.ConvertFrom(obj);
}

private byte[] _value;

public static implicit operator byte[](BytesType type)
{
return type._value;
}

public static implicit operator BytesType(byte[] s)
{
return new BytesType { _value = s };
}

public static implicit operator BytesType(byte o) { return Convert(o); }
public static implicit operator BytesType(sbyte o) { return Convert(o); }
public static implicit operator BytesType(short o) { return Convert(o); }
public static implicit operator BytesType(ushort o) { return Convert(o); }
public static implicit operator BytesType(int o) { return Convert(o); }
public static implicit operator BytesType(uint o) { return Convert(o); }
public static implicit operator BytesType(long o) { return Convert(o); }
public static implicit operator BytesType(ulong o) { return Convert(o); }
public static implicit operator BytesType(float o) { return Convert(o); }
public static implicit operator BytesType(double o) { return Convert(o); }
public static implicit operator BytesType(decimal o) { return Convert(o); }
public static implicit operator BytesType(bool o) { return Convert(o); }
public static implicit operator BytesType(string o) { return Convert(o); }
public static implicit operator BytesType(char o) { return Convert(o); }
public static implicit operator BytesType(Guid o) { return Convert(o); }
public static implicit operator BytesType(DateTime o) { return Convert(o); }
public static implicit operator BytesType(DateTimeOffset o) { return Convert(o); }

private static BytesType Convert(object o)
{
var type = new BytesType();
type._value = type.GetBytes(o);

return type;
}
}
}
Expand Up @@ -37,5 +37,22 @@ public override byte[] GetBytes(object obj)

return (byte[])converter.ConvertFrom(obj);
}

private Guid _value;

public static implicit operator byte[](LexicalUUIDType type)
{
return type.GetBytes(type._value);
}

public static implicit operator Guid(LexicalUUIDType type)
{
return type._value;
}

public static implicit operator LexicalUUIDType(Guid s)
{
return new LexicalUUIDType { _value = s };
}
}
}

0 comments on commit 309fe13

Please sign in to comment.