Browse files

only in Cassandra does TTL mean Seconds Until Deleted

  • Loading branch information...
1 parent a427c04 commit dc0875fbe84de5a8b283f59591aaa2a03ea86035 @nberardi nberardi committed Jan 27, 2012
View
6 src/CassandraColumnFamilyOperations.cs
@@ -41,7 +41,7 @@ public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareW
var columnName = path.Column.ColumnName;
var columnValue = path.Column.ColumnValue;
var timestamp = path.Column.ColumnTimestamp;
- var timeToLive = path.Column.ColumnTimeToLive;
+ var timeToLive = path.Column.ColumnSecondsUntilDeleted;
var op = new InsertColumn(key, columnName, columnValue, timestamp, timeToLive);
family.ExecuteOperation(op);
@@ -50,10 +50,10 @@ public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareW
public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, BytesType key, CompareWith columnName, BytesType columnValue)
where CompareWith : CassandraType
{
- InsertColumn<CompareWith>(family, key, columnName, columnValue, DateTimeOffset.UtcNow, 1);
+ InsertColumn<CompareWith>(family, key, columnName, columnValue, DateTimeOffset.UtcNow, null);
}
- public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, BytesType key, CompareWith columnName, BytesType columnValue, DateTimeOffset timestamp, int timeToLive)
+ public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, BytesType key, CompareWith columnName, BytesType columnValue, DateTimeOffset timestamp, int? timeToLive)
where CompareWith : CassandraType
{
var op = new InsertColumn(key, columnName, columnValue, timestamp, timeToLive);
View
6 src/CassandraSuperColumnFamilyOperations.cs
@@ -61,7 +61,7 @@ public static class CassandraSuperColumnFamilyOperations
var name = path.Column.ColumnName;
var value = path.Column.ColumnValue;
var timestamp = path.Column.ColumnTimestamp;
- var timeToLive = path.Column.ColumnTimeToLive;
+ var timeToLive = path.Column.ColumnSecondsUntilDeleted;
var op = new InsertColumn(key, superColumnName, name, value, timestamp, timeToLive);
family.ExecuteOperation(op);
@@ -71,10 +71,10 @@ public static class CassandraSuperColumnFamilyOperations
where CompareWith : CassandraType
where CompareSubcolumnWith : CassandraType
{
- InsertColumn<CompareWith, CompareSubcolumnWith>(family, key, superColumnName, name, value, DateTimeOffset.UtcNow, 1);
+ InsertColumn<CompareWith, CompareSubcolumnWith>(family, key, superColumnName, name, value, DateTimeOffset.UtcNow, null);
}
- public static void InsertColumn<CompareWith, CompareSubcolumnWith>(this CassandraSuperColumnFamily<CompareWith, CompareSubcolumnWith> family, BytesType key, CompareWith superColumnName, CompareSubcolumnWith name, BytesType value, DateTimeOffset timestamp, int timeToLive)
+ public static void InsertColumn<CompareWith, CompareSubcolumnWith>(this CassandraSuperColumnFamily<CompareWith, CompareSubcolumnWith> family, BytesType key, CompareWith superColumnName, CompareSubcolumnWith name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
where CompareWith : CassandraType
where CompareSubcolumnWith : CassandraType
{
View
15 src/FluentColumn.cs
@@ -13,11 +13,12 @@ public class FluentColumn<CompareWith> : IFluentColumn<CompareWith>
private BytesType _value;
private FluentColumnParent _parent;
private IFluentBaseColumnFamily _family;
+ private int? _ttl;
public FluentColumn()
{
ColumnTimestamp = DateTimeOffset.UtcNow;
- ColumnTimeToLive = 1;
+ ColumnSecondsUntilDeleted = null;
}
/// <summary>
@@ -66,10 +67,16 @@ internal set
/// <summary>
///
/// </summary>
- public int ColumnTimeToLive
+ public int? ColumnSecondsUntilDeleted
{
- get;
- 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");
+
+ _ttl = value;
+ }
}
/// <summary>
View
2 src/IFluentColumn.cs
@@ -7,6 +7,6 @@ public interface IFluentColumn : IFluentBaseColumn
{
BytesType ColumnValue { get; set; }
DateTimeOffset ColumnTimestamp { get; }
- int ColumnTimeToLive { get; set; }
+ int? ColumnSecondsUntilDeleted { get; set; }
}
}
View
2 src/Operations/CassandraColumn.cs
@@ -9,6 +9,6 @@ public class CassandraColumn
public CassandraType Name { get; set; }
public BytesType Value { get; set; }
public DateTimeOffset Timestamp { get; set; }
- public int Ttl { get; set; }
+ public int? Ttl { get; set; }
}
}
View
16 src/Operations/Helper.cs
@@ -79,12 +79,16 @@ public static SlicePredicate CreateSlicePredicate(CassandraSlicePredicate predic
public static Column CreateColumn(CassandraColumn column)
{
- return new Column {
+ var ccol = new Column {
Name = column.Name.TryToBigEndian(),
Value = column.Value.TryToBigEndian(),
- Ttl = column.Ttl,
Timestamp = column.Timestamp.ToTimestamp()
};
+
+ if (column.Ttl.HasValue && column.Ttl.Value > 0)
+ ccol.Ttl = column.Ttl.Value;
+
+ return ccol;
}
public static CounterColumn CreateCounterColumn(CassandraCounterColumn column)
@@ -129,12 +133,16 @@ public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>
where CompareWith : CassandraType
{
- return new FluentColumn<CompareWith> {
+ var fcol = new FluentColumn<CompareWith> {
ColumnName = CassandraType.FromBigEndian<CompareWith>(col.Name),
ColumnValue = CassandraType.FromBigEndian<BytesType>(col.Value),
ColumnTimestamp = new DateTimeOffset(col.Timestamp, TimeSpan.Zero),
- ColumnTimeToLive = col.Ttl
};
+
+ if (col.__isset.ttl)
+ fcol.ColumnSecondsUntilDeleted = col.Ttl;
+
+ return fcol;
}
public static FluentSuperColumn<CompareWith, CompareSubcolumnWith> ConvertSuperColumnToFluentSuperColumn<CompareWith, CompareSubcolumnWith>(SuperColumn col)
View
6 src/Operations/InsertColumn.cs
@@ -17,7 +17,7 @@ public class InsertColumn : ColumnFamilyOperation<Void>
public BytesType ColumnValue { get; private set; }
- public int TimeToLive { get; private set; }
+ public int? TimeToLive { get; private set; }
public DateTimeOffset Timestamp { get; private set; }
@@ -51,7 +51,7 @@ public override Void Execute()
#endregion
- public InsertColumn(BytesType key, CassandraType name, BytesType value, DateTimeOffset timestamp, int timeToLive)
+ public InsertColumn(BytesType key, CassandraType name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
{
Key = key;
ColumnName = name;
@@ -60,7 +60,7 @@ public InsertColumn(BytesType key, CassandraType name, BytesType value, DateTime
TimeToLive = timeToLive;
}
- public InsertColumn(BytesType key, CassandraType superColumnName, CassandraType name, BytesType value, DateTimeOffset timestamp, int timeToLive)
+ public InsertColumn(BytesType key, CassandraType superColumnName, CassandraType name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
{
Key = key;
SuperColumnName = superColumnName;
View
3 test/FluentCassandra.Tests/TypesToDatabase/AsciiTypeTest.cs
@@ -1,8 +1,7 @@
using System;
using System.Linq;
-using System.Threading;
-using NUnit.Framework;
using FluentCassandra.Types;
+using NUnit.Framework;
namespace FluentCassandra.TypesToDatabase
{

0 comments on commit dc0875f

Please sign in to comment.