Permalink
Browse files

added the new types introduced in Cassandra 1.0.0

  • Loading branch information...
nberardi committed Jan 29, 2012
1 parent 3bca32c commit 2b76325c61c66894650a15f5a0e88a1a754a754f
Showing with 1,308 additions and 586 deletions.
  1. BIN lib/Ionic.Zip.dll
  2. BIN lib/Ionic.Zip.shadow
  3. BIN lib/LINQPad.exe
  4. +2 −2 src/Connections/ConnectionBuilder.cs
  5. +19 −0 src/FluentCassandra.csproj
  6. BIN src/FluentCassandra.snk
  7. +27 −2 src/FluentColumn.cs
  8. +2 −2 src/FluentColumnFamily.cs
  9. +2 −2 src/FluentSuperColumn.cs
  10. +2 −2 src/FluentSuperColumnFamily.cs
  11. +1 −1 src/Operations/CassandraIndexClauseBuilder.cs
  12. +1 −1 src/Operations/ExecuteCqlQuery.cs
  13. +4 −4 src/Operations/Helper.cs
  14. +1 −1 src/Operations/MultiGetColumnFamilySlice.cs
  15. +1 −1 src/Operations/MultiGetSuperColumnFamilySlice.cs
  16. +96 −0 src/Types/BooleanType.cs
  17. +42 −0 src/Types/BooleanTypeConverter.cs
  18. +44 −7 src/Types/CassandraType.cs
  19. +1 −1 src/Types/CassandraTypeConverter.cs
  20. +7 −7 src/Types/CassandraTypeExtensions.cs
  21. +2 −2 src/Types/CompositeType.cs
  22. +1 −1 src/Types/CompositeTypeConverter.cs
  23. +104 −0 src/Types/DateType.cs
  24. +104 −0 src/Types/DateTypeConverter.cs
  25. +96 −0 src/Types/DecimalType.cs
  26. +42 −0 src/Types/DecimalTypeConverter.cs
  27. +96 −0 src/Types/DoubleType.cs
  28. +42 −0 src/Types/DoubleTypeConverter.cs
  29. +2 −2 src/Types/DynamicCompositeType.cs
  30. +1 −1 src/Types/DynamicCompositeTypeConverter.cs
  31. +96 −0 src/Types/FloatType.cs
  32. +42 −0 src/Types/FloatTypeConverter.cs
  33. +96 −0 src/Types/Int32Type.cs
  34. +42 −0 src/Types/Int32TypeConverter.cs
  35. +3 −1 test/FluentCassandra.Tests/Linq/LinqToCassandraTests.cs
  36. +0 −6 utility/FluentCassandra.LinqPad/App.xaml
  37. +0 −30 utility/FluentCassandra.LinqPad/CassandraConectionDialog.xaml.cs
  38. +6 −43 utility/FluentCassandra.LinqPad/CassandraConnectionInfo.cs
  39. +44 −0 utility/FluentCassandra.LinqPad/CassandraContext.cs
  40. +0 −102 utility/FluentCassandra.LinqPad/CassandraDriver.cs
  41. +0 −78 utility/FluentCassandra.LinqPad/CassandraDriverContext.cs
  42. +117 −0 utility/FluentCassandra.LinqPad/CassandraStaticDriver.cs
  43. +17 −17 utility/FluentCassandra.LinqPad/{CassandraConectionDialog.xaml → ConnectionDialog.xaml}
  44. +34 −0 utility/FluentCassandra.LinqPad/ConnectionDialog.xaml.cs
  45. +1 −1 utility/FluentCassandra.LinqPad/DevDeploy.bat
  46. +19 −35 utility/FluentCassandra.LinqPad/FluentCassandra.LinqPad.csproj
  47. BIN utility/FluentCassandra.LinqPad/FluentCassandra.snk
  48. +1 −0 utility/FluentCassandra.LinqPad/README.txt
  49. +0 −125 utility/FluentCassandra.LinqPad/RavenLinqpadDriver.csproj
  50. +0 −13 utility/FluentCassandra.LinqPad/Utility.cs
  51. +0 −34 utility/FluentCassandra.LinqPad/ViewModel/MainViewModel.cs
  52. +0 −58 utility/FluentCassandra.LinqPad/ViewModel/ViewModelLocator.cs
  53. +48 −0 utility/FluentCassandra.LinqPad/package for release.linq
  54. +0 −4 utility/FluentCassandra.LinqPad/packages.config
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -319,11 +319,11 @@ private string GetConnectionString()
b.AppendFormat(format, "Keyspace", Keyspace);
b.AppendFormat(format, "Server", String.Join(",", Servers));
- b.AppendFormat(format, "Connection Timeout", ConnectionTimeout);
+ b.AppendFormat(format, "Connection Timeout", Convert.ToInt32(ConnectionTimeout.TotalSeconds));
b.AppendFormat(format, "Pooling", Pooling);
b.AppendFormat(format, "Min Pool Size", MinPoolSize);
b.AppendFormat(format, "Max Pool Size", MaxPoolSize);
- b.AppendFormat(format, "Connection Lifetime", ConnectionLifetime);
+ b.AppendFormat(format, "Connection Lifetime", Convert.ToInt32(ConnectionLifetime.TotalSeconds));
b.AppendFormat(format, "Connection Type", ConnectionType);
b.AppendFormat(format, "Buffer Size", BufferSize);
View
@@ -39,6 +39,12 @@
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
+ <PropertyGroup>
+ <SignAssembly>true</SignAssembly>
+ </PropertyGroup>
+ <PropertyGroup>
+ <AssemblyOriginatorKeyFile>FluentCassandra.snk</AssemblyOriginatorKeyFile>
+ </PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
@@ -258,6 +264,18 @@
</Compile>
<Compile Include="Types\CompositeTypeConverter.cs" />
<Compile Include="Types\CompositeType`1.cs" />
+ <Compile Include="Types\BooleanType.cs" />
+ <Compile Include="Types\BooleanTypeConverter.cs" />
+ <Compile Include="Types\DateType.cs" />
+ <Compile Include="Types\DateTypeConverter.cs" />
+ <Compile Include="Types\Int32Type.cs" />
+ <Compile Include="Types\Int32TypeConverter.cs" />
+ <Compile Include="Types\FloatType.cs" />
+ <Compile Include="Types\FloatTypeConverter.cs" />
+ <Compile Include="Types\DoubleType.cs" />
+ <Compile Include="Types\DoubleTypeConverter.cs" />
+ <Compile Include="Types\DecimalType.cs" />
+ <Compile Include="Types\DecimalTypeConverter.cs" />
<Compile Include="Types\DynamicCompositeType.cs" />
<Compile Include="Types\DynamicCompositeTypeConverter.cs" />
<Compile Include="Types\CassandraTypeExtensions.cs" />
@@ -287,6 +305,7 @@
<None Include="FluentCassandra.nuspec">
<SubType>Designer</SubType>
</None>
+ <None Include="FluentCassandra.snk" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
View
Binary file not shown.
View
@@ -19,6 +19,7 @@ public FluentColumn()
{
ColumnTimestamp = DateTimeOffset.UtcNow;
ColumnSecondsUntilDeleted = null;
+ ColumnTimeUntilDeleted = null;
}
/// <summary>
@@ -72,13 +73,37 @@ internal set
get { return _ttl; }
set
{
- if (value.HasValue && value <= 0)
- throw new CassandraException("ColumnSecondsUntilDeleted needs to be set to a postive value that is greater than zero");
+ if (value.HasValue && value < 1)
+ throw new CassandraException("ColumnSecondsUntilDeleted needs to be set to a postive value that is greater than zero.");
_ttl = value;
}
}
+ /// <summary>
+ ///
+ /// </summary>
+ public TimeSpan? ColumnTimeUntilDeleted
+ {
+ get
+ {
+ if (ColumnSecondsUntilDeleted.HasValue)
+ return TimeSpan.FromSeconds(ColumnSecondsUntilDeleted.Value);
+
+ return null;
+ }
+ set
+ {
+ if (value.HasValue && value.Value < TimeSpan.FromSeconds(1))
+ throw new CassandraException("ColumnTimeUntilDeleted needs to be set to a postive TimeSpan that is greater than or equal to 1 second.");
+
+ if (value.HasValue)
+ ColumnSecondsUntilDeleted = Convert.ToInt32(value.Value.TotalSeconds);
+
+ ColumnSecondsUntilDeleted = null;
+ }
+ }
+
/// <summary>
/// Gets the path.
/// </summary>
@@ -150,15 +150,15 @@ public override bool TrySetColumn(object name, object value)
mutationType = MutationType.Added;
col = new FluentColumn<CompareWith>();
- ((FluentColumn<CompareWith>)col).ColumnName = CassandraType.GetType<CompareWith>(name);
+ ((FluentColumn<CompareWith>)col).ColumnName = CassandraType.GetTypeFromObject<CompareWith>(name);
_columns.SupressChangeNotification = true;
_columns.Add(col);
_columns.SupressChangeNotification = false;
}
// set the column value
- col.ColumnValue = CassandraType.GetType<BytesType>(value);
+ col.ColumnValue = CassandraType.GetTypeFromObject<BytesType>(value);
// notify the tracker that the column has changed
OnColumnMutated(mutationType, col);
View
@@ -143,15 +143,15 @@ public override bool TrySetColumn(object name, object value)
mutationType = MutationType.Added;
col = new FluentColumn<CompareSubcolumnWith>();
- ((FluentColumn<CompareSubcolumnWith>)col).ColumnName = CassandraType.GetType<CompareSubcolumnWith>(name);
+ ((FluentColumn<CompareSubcolumnWith>)col).ColumnName = CassandraType.GetTypeFromObject<CompareSubcolumnWith>(name);
_columns.SupressChangeNotification = true;
_columns.Add(col);
_columns.SupressChangeNotification = false;
}
// set the column value
- col.ColumnValue = CassandraType.GetType<BytesType>(value);
+ col.ColumnValue = CassandraType.GetTypeFromObject<BytesType>(value);
// notify the tracker that the column has changed
OnColumnMutated(mutationType, col);
@@ -109,7 +109,7 @@ public FluentColumnParent GetSelf()
public override bool TryGetColumn(object name, out object result)
{
var col = Columns.FirstOrDefault(c => c.ColumnName == name);
- result = (col == null) ? CreateSuperColumn(CassandraType.GetType<CompareWith>(name)) : col;
+ result = (col == null) ? CreateSuperColumn(CassandraType.GetTypeFromObject<CompareWith>(name)) : col;
return true;
}
@@ -129,7 +129,7 @@ public override bool TrySetColumn(object name, object value)
var mutationType = col == null ? MutationType.Added : MutationType.Changed;
col = (FluentSuperColumn<CompareWith, CompareSubcolumnWith>)value;
- ((FluentSuperColumn<CompareWith, CompareSubcolumnWith>)col).ColumnName = CassandraType.GetType<CompareWith>(name);
+ ((FluentSuperColumn<CompareWith, CompareSubcolumnWith>)col).ColumnName = CassandraType.GetTypeFromObject<CompareWith>(name);
int index = Columns.IndexOf(col);
@@ -118,7 +118,7 @@ private static Cassandra.IndexExpression VisitRelationalExpression(BinaryExpress
Cassandra.IndexExpression indexExpression;
var columnName = GetColumnName(exp.Left);
- var value = CassandraType.GetType<BytesType>(Expression.Lambda(exp.Right).Compile().DynamicInvoke());
+ var value = CassandraType.GetTypeFromObject<BytesType>(Expression.Lambda(exp.Right).Compile().DynamicInvoke());
indexExpression = new Cassandra.IndexExpression {
Column_name = columnName,
@@ -53,7 +53,7 @@ private IEnumerable<ICqlRow<CompareWith>> GetRows(Apache.Cassandra.CqlResult res
var familyName = TryGetFamilyName();
foreach (var row in result.Rows)
yield return new FluentColumnFamily<CompareWith>(
- CassandraType.FromBigEndian<BytesType>(row.Key),
+ CassandraType.GetTypeFromDatabaseValue<BytesType>(row.Key),
familyName,
GetColumns(row));
}
View
@@ -110,7 +110,7 @@ public static byte[] TryToBigEndian(this CassandraType value)
public static long ToTimestamp(this DateTimeOffset dt)
{
// this was changed from .NET Ticks to the Unix Epoch to be compatible with other cassandra libraries
- return Convert.ToInt64((DateTimeOffset.UtcNow - UnixStart).TotalMilliseconds);
+ return Convert.ToInt64((dt - UnixStart).TotalMilliseconds);
}
public static IFluentBaseColumn<CompareWith> ConvertToFluentBaseColumn<CompareWith, CompareSubcolumnWith>(ColumnOrSuperColumn col)
@@ -134,8 +134,8 @@ public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>
{
var fcol = new FluentColumn<CompareWith> {
- ColumnName = CassandraType.FromBigEndian<CompareWith>(col.Name),
- ColumnValue = CassandraType.FromBigEndian<BytesType>(col.Value),
+ ColumnName = CassandraType.GetTypeFromDatabaseValue<CompareWith>(col.Name),
+ ColumnValue = CassandraType.GetTypeFromDatabaseValue<BytesType>(col.Value),
ColumnTimestamp = new DateTimeOffset(col.Timestamp, TimeSpan.Zero),
};
@@ -150,7 +150,7 @@ public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>
where CompareSubcolumnWith : CassandraType
{
var superCol = new FluentSuperColumn<CompareWith, CompareSubcolumnWith> {
- ColumnName = CassandraType.FromBigEndian<CompareWith>(col.Name)
+ ColumnName = CassandraType.GetTypeFromDatabaseValue<CompareWith>(col.Name)
};
foreach (var xcol in col.Columns)
@@ -35,7 +35,7 @@ public override IEnumerable<IFluentColumnFamily<CompareWith>> Execute()
foreach (var result in output)
{
- var key = CassandraType.FromBigEndian<BytesType>(result.Key);
+ var key = CassandraType.GetTypeFromDatabaseValue<BytesType>(result.Key);
var r = new FluentColumnFamily<CompareWith>(key, ColumnFamily.FamilyName, result.Value.Select(col => {
return Helper.ConvertColumnToFluentColumn<CompareWith>(col.Column);
@@ -36,7 +36,7 @@ public class MultiGetSuperColumnFamilySlice<CompareWith, CompareSubcolumnWith> :
foreach (var result in output)
{
- var key = CassandraType.FromBigEndian<BytesType>(result.Key);
+ var key = CassandraType.GetTypeFromDatabaseValue<BytesType>(result.Key);
var superColumns = result.Value.Select(col => {
var superCol = Helper.ConvertSuperColumnToFluentSuperColumn<CompareWith, CompareSubcolumnWith>(col.Super_column);
View
@@ -0,0 +1,96 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class BooleanType : CassandraType
+ {
+ private static readonly BooleanTypeConverter Converter = new BooleanTypeConverter();
+
+ #region Implimentation
+
+ public override object GetValue(Type type)
+ {
+ return GetValue(_value, type, Converter);
+ }
+
+ public override void SetValue(object obj)
+ {
+ _value = SetValue(obj, Converter);
+ }
+
+ public override byte[] ToBigEndian()
+ {
+ return Converter.ToBigEndian(_value);
+ }
+
+ public override void SetValueFromBigEndian(byte[] value)
+ {
+ _value = Converter.FromBigEndian(value);
+ }
+
+ protected override TypeCode TypeCode
+ {
+ get { return TypeCode.String; }
+ }
+
+ public override string ToString()
+ {
+ return _value.ToString();
+ }
+
+ #endregion
+
+ private bool _value;
+
+ #region Equality
+
+ public override bool Equals(object obj)
+ {
+ if (obj is BooleanType)
+ return _value == ((BooleanType)obj)._value;
+
+ return _value == CassandraType.GetValue<bool>(obj, Converter);
+ }
+
+ public override int GetHashCode()
+ {
+ return _value.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ public static implicit operator bool(BooleanType type)
+ {
+ return type._value;
+ }
+
+ public static implicit operator BooleanType(bool o)
+ {
+ return new BooleanType {
+ _value = o
+ };
+ }
+
+ public static implicit operator BooleanType(byte[] o) { return ConvertFrom(o); }
+ public static implicit operator byte[](BooleanType o) { return ConvertTo<byte[]>(o); }
+
+ private static T ConvertTo<T>(BooleanType type)
+ {
+ if (type == null)
+ return default(T);
+
+ return type.GetValue<T>();
+ }
+
+ private static BooleanType ConvertFrom(object o)
+ {
+ var type = new BooleanType();
+ type.SetValue(o);
+ return type;
+ }
+
+ #endregion
+ }
+}
@@ -0,0 +1,42 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ internal class BooleanTypeConverter : CassandraTypeConverter<bool>
+ {
+ public override bool CanConvertFrom(Type sourceType)
+ {
+ if (Type.GetTypeCode(sourceType) != TypeCode.Object)
+ return true;
+
+ return sourceType == typeof(byte[]);
+ }
+
+ public override bool CanConvertTo(Type destinationType)
+ {
+ if (Type.GetTypeCode(destinationType) != TypeCode.Object)
+ return true;
+
+ return destinationType == typeof(byte[]);
+ }
+
+ public override bool ConvertFrom(object value)
+ {
+ if (value is byte[])
+ return ((byte[])value).FromBytes<bool>();
+
+ return (bool)Convert.ChangeType(value, typeof(bool));
+ }
+
+ public override object ConvertTo(bool value, Type destinationType)
+ {
+ if (!(value is string))
+ return null;
+
+ if (destinationType == typeof(byte[]))
+ return value.ToBytes();
+
+ return Convert.ChangeType(value, destinationType);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 2b76325

Please sign in to comment.